Gentoo Archives: gentoo-commits

From: "Gordon Malm (gengor)" <gengor@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1483 - in hardened/2.6/tags: . 2.6.27-6
Date: Sat, 24 Jan 2009 20:37:03
Message-Id: E1LQpED-0003yD-3A@stork.gentoo.org
1 Author: gengor
2 Date: 2009-01-24 20:35:40 +0000 (Sat, 24 Jan 2009)
3 New Revision: 1483
4
5 Added:
6 hardened/2.6/tags/2.6.27-6/
7 hardened/2.6/tags/2.6.27-6/0000_README
8 hardened/2.6/tags/2.6.27-6/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
9 hardened/2.6/tags/2.6.27-6/4421_grsec-remove-localversion-grsec.patch
10 hardened/2.6/tags/2.6.27-6/4422_grsec-mute-warnings.patch
11 hardened/2.6/tags/2.6.27-6/4425_grsec-pax-without-grsec.patch
12 hardened/2.6/tags/2.6.27-6/4430_grsec-kconfig-default-gids.patch
13 hardened/2.6/tags/2.6.27-6/4435_grsec-kconfig-gentoo.patch
14 hardened/2.6/tags/2.6.27-6/4440_selinux-avc_audit-log-curr_ip.patch
15 hardened/2.6/tags/2.6.27-6/4445_disable-compat_vdso.patch
16 hardened/2.6/tags/2.6.27-6/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
17 hardened/2.6/tags/2.6.27-6/4455_pax-2.6.27.10-test29-to-test30.patch
18 hardened/2.6/tags/2.6.27-6/4460_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
19 Log:
20 Add hardened-extras 2.6.27-6 tag
21
22 Added: hardened/2.6/tags/2.6.27-6/0000_README
23 ===================================================================
24 --- hardened/2.6/tags/2.6.27-6/0000_README (rev 0)
25 +++ hardened/2.6/tags/2.6.27-6/0000_README 2009-01-24 20:35:40 UTC (rev 1483)
26 @@ -0,0 +1,54 @@
27 +README
28 +-----------------------------------------------------------------------------
29 +
30 +Individual Patch Descriptions:
31 +-----------------------------------------------------------------------------
32 +Patch: 4420_grsec-2.1.12-2.6.27.10-200812271347.patch
33 +From: http://www.grsecurity.net
34 +Desc: hardened-sources base patch from upstream grsecurity
35 +
36 +Patch: 4421_grsec-remove-localversion-grsec.patch
37 +From: Kerin Millar <kerframil@×××××.com>
38 +Desc: Removes grsecurity's localversion-grsec file
39 +
40 +Patch: 4422_grsec-mute-warnings.patch
41 +From: Alexander Gabert <gaberta@××××××××.de>
42 + Gordon Malm <gengor@g.o>
43 +Desc: Removes verbose compile warning settings from grsecurity, restores
44 + mainline Linux kernel behavior
45 +
46 +Patch: 4425_grsec-pax-without-grsec.patch
47 +From: Gordon Malm <gengor@g.o>
48 +Desc: Allows PaX features to be selected without enabling GRKERNSEC
49 +
50 +Patch: 4430_grsec-kconfig-default-gids.patch
51 +From: Kerin Millar <kerframil@×××××.com>
52 +Desc: Sets sane(r) default GIDs on various grsecurity group-dependent
53 + features
54 +
55 +Patch: 4435_grsec-kconfig-gentoo.patch
56 +From: Gordon Malm <gengor@g.o>
57 + Kerin Millar <kerframil@×××××.com>
58 +Desc: Adds Hardened Gentoo [server/workstation] security levels, sets
59 + Hardened Gentoo [workstation] as default
60 +
61 +Patch: 4440_selinux-avc_audit-log-curr_ip.patch
62 +From: Gordon Malm <gengor@g.o>
63 +Desc: Configurable option to add src IP address to SELinux log messages
64 +
65 +Patch: 4445_disable-compat_vdso.patch
66 +From: Gordon Malm <gengor@g.o>
67 + Kerin Millar <kerframil@×××××.com>
68 +Desc: Disables VDSO_COMPAT operation completely
69 +
70 +Patch: 4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
71 +From: Gordon Malm <gengor@g.o>
72 +Desc: Add offender's IP to PAX_REFCOUNT log messages if it is available
73 +
74 +Patch: 4455_pax-2.6.27.10-test29-to-test30.patch
75 +From: Gordon Malm <gengor@g.o>
76 +Desc: Adds PaX changes from pax-2.6.26.11-test30
77 +
78 +Patch: 4460_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
79 +From: Gordon Malm <gengor@g.o>
80 +Desc: Revert RLIMIT_STACK false-positives-avoidance change in PaX
81
82 Added: hardened/2.6/tags/2.6.27-6/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
83 ===================================================================
84 --- hardened/2.6/tags/2.6.27-6/4420_grsec-2.1.12-2.6.27.10-200812271347.patch (rev 0)
85 +++ hardened/2.6/tags/2.6.27-6/4420_grsec-2.1.12-2.6.27.10-200812271347.patch 2009-01-24 20:35:40 UTC (rev 1483)
86 @@ -0,0 +1,37200 @@
87 + !
88 + -~*~-
89 + /!\
90 + /%;@\
91 + o/@,%\o
92 + /%;`@,\
93 + o/@'%',\o
94 + '^^^N^^^`
95 +
96 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/elf.h linux-2.6.27.10/arch/alpha/include/asm/elf.h
97 +--- linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
98 ++++ linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
99 +@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
100 +
101 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
102 +
103 ++#ifdef CONFIG_PAX_ASLR
104 ++#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
105 ++
106 ++#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
107 ++#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
108 ++#endif
109 ++
110 + /* $0 is set by ld.so to a pointer to a function which might be
111 + registered using atexit. This provides a mean for the dynamic
112 + linker to call DT_FINI functions for shared libraries that have
113 +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
114 +--- linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
115 ++++ linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
116 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
117 + D(10) KM_IRQ1,
118 + D(11) KM_SOFTIRQ0,
119 + D(12) KM_SOFTIRQ1,
120 +-D(13) KM_TYPE_NR
121 ++D(13) KM_CLEARPAGE,
122 ++D(14) KM_TYPE_NR
123 + };
124 +
125 + #undef D
126 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/pgtable.h linux-2.6.27.10/arch/alpha/include/asm/pgtable.h
127 +--- linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
128 ++++ linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
129 +@@ -101,6 +101,17 @@ struct vm_area_struct;
130 + #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
131 + #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
132 + #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
133 ++
134 ++#ifdef CONFIG_PAX_PAGEEXEC
135 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
136 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
137 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
138 ++#else
139 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
140 ++# define PAGE_COPY_NOEXEC PAGE_COPY
141 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
142 ++#endif
143 ++
144 + #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
145 +
146 + #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
147 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/module.c linux-2.6.27.10/arch/alpha/kernel/module.c
148 +--- linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
149 ++++ linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
150 +@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
151 +
152 + /* The small sections were sorted to the end of the segment.
153 + The following should definitely cover them. */
154 +- gp = (u64)me->module_core + me->core_size - 0x8000;
155 ++ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
156 + got = sechdrs[me->arch.gotsecindex].sh_addr;
157 +
158 + for (i = 0; i < n; i++) {
159 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/osf_sys.c linux-2.6.27.10/arch/alpha/kernel/osf_sys.c
160 +--- linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-07 12:55:34.000000000 -0500
161 ++++ linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-18 03:38:43.000000000 -0500
162 +@@ -1232,6 +1232,10 @@ arch_get_unmapped_area(struct file *filp
163 + merely specific addresses, but regions of memory -- perhaps
164 + this feature should be incorporated into all ports? */
165 +
166 ++#ifdef CONFIG_PAX_RANDMMAP
167 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
168 ++#endif
169 ++
170 + if (addr) {
171 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
172 + if (addr != (unsigned long) -ENOMEM)
173 +@@ -1239,8 +1243,8 @@ arch_get_unmapped_area(struct file *filp
174 + }
175 +
176 + /* Next, try allocating at TASK_UNMAPPED_BASE. */
177 +- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
178 +- len, limit);
179 ++ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
180 ++
181 + if (addr != (unsigned long) -ENOMEM)
182 + return addr;
183 +
184 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/ptrace.c linux-2.6.27.10/arch/alpha/kernel/ptrace.c
185 +--- linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
186 ++++ linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-18 03:38:43.000000000 -0500
187 +@@ -15,6 +15,7 @@
188 + #include <linux/slab.h>
189 + #include <linux/security.h>
190 + #include <linux/signal.h>
191 ++#include <linux/grsecurity.h>
192 +
193 + #include <asm/uaccess.h>
194 + #include <asm/pgtable.h>
195 +@@ -266,6 +267,9 @@ long arch_ptrace(struct task_struct *chi
196 + size_t copied;
197 + long ret;
198 +
199 ++ if (gr_handle_ptrace(child, request))
200 ++ return -EPERM;
201 ++
202 + switch (request) {
203 + /* When I and D space are separate, these will need to be fixed. */
204 + case PTRACE_PEEKTEXT: /* read word at location addr. */
205 +diff -urNp linux-2.6.27.10/arch/alpha/mm/fault.c linux-2.6.27.10/arch/alpha/mm/fault.c
206 +--- linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
207 ++++ linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
208 +@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
209 + __reload_thread(pcb);
210 + }
211 +
212 ++#ifdef CONFIG_PAX_PAGEEXEC
213 ++/*
214 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
215 ++ *
216 ++ * returns 1 when task should be killed
217 ++ * 2 when patched PLT trampoline was detected
218 ++ * 3 when unpatched PLT trampoline was detected
219 ++ */
220 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
221 ++{
222 ++
223 ++#ifdef CONFIG_PAX_EMUPLT
224 ++ int err;
225 ++
226 ++ do { /* PaX: patched PLT emulation #1 */
227 ++ unsigned int ldah, ldq, jmp;
228 ++
229 ++ err = get_user(ldah, (unsigned int *)regs->pc);
230 ++ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
231 ++ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
232 ++
233 ++ if (err)
234 ++ break;
235 ++
236 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
237 ++ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
238 ++ jmp == 0x6BFB0000U)
239 ++ {
240 ++ unsigned long r27, addr;
241 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
242 ++ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
243 ++
244 ++ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
245 ++ err = get_user(r27, (unsigned long *)addr);
246 ++ if (err)
247 ++ break;
248 ++
249 ++ regs->r27 = r27;
250 ++ regs->pc = r27;
251 ++ return 2;
252 ++ }
253 ++ } while (0);
254 ++
255 ++ do { /* PaX: patched PLT emulation #2 */
256 ++ unsigned int ldah, lda, br;
257 ++
258 ++ err = get_user(ldah, (unsigned int *)regs->pc);
259 ++ err |= get_user(lda, (unsigned int *)(regs->pc+4));
260 ++ err |= get_user(br, (unsigned int *)(regs->pc+8));
261 ++
262 ++ if (err)
263 ++ break;
264 ++
265 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
266 ++ (lda & 0xFFFF0000U) == 0xA77B0000U &&
267 ++ (br & 0xFFE00000U) == 0xC3E00000U)
268 ++ {
269 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
270 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
271 ++ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
272 ++
273 ++ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
274 ++ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
275 ++ return 2;
276 ++ }
277 ++ } while (0);
278 ++
279 ++ do { /* PaX: unpatched PLT emulation */
280 ++ unsigned int br;
281 ++
282 ++ err = get_user(br, (unsigned int *)regs->pc);
283 ++
284 ++ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
285 ++ unsigned int br2, ldq, nop, jmp;
286 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
287 ++
288 ++ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
289 ++ err = get_user(br2, (unsigned int *)addr);
290 ++ err |= get_user(ldq, (unsigned int *)(addr+4));
291 ++ err |= get_user(nop, (unsigned int *)(addr+8));
292 ++ err |= get_user(jmp, (unsigned int *)(addr+12));
293 ++ err |= get_user(resolver, (unsigned long *)(addr+16));
294 ++
295 ++ if (err)
296 ++ break;
297 ++
298 ++ if (br2 == 0xC3600000U &&
299 ++ ldq == 0xA77B000CU &&
300 ++ nop == 0x47FF041FU &&
301 ++ jmp == 0x6B7B0000U)
302 ++ {
303 ++ regs->r28 = regs->pc+4;
304 ++ regs->r27 = addr+16;
305 ++ regs->pc = resolver;
306 ++ return 3;
307 ++ }
308 ++ }
309 ++ } while (0);
310 ++#endif
311 ++
312 ++ return 1;
313 ++}
314 ++
315 ++void pax_report_insns(void *pc, void *sp)
316 ++{
317 ++ unsigned long i;
318 ++
319 ++ printk(KERN_ERR "PAX: bytes at PC: ");
320 ++ for (i = 0; i < 5; i++) {
321 ++ unsigned int c;
322 ++ if (get_user(c, (unsigned int *)pc+i))
323 ++ printk(KERN_CONT "???????? ");
324 ++ else
325 ++ printk(KERN_CONT "%08x ", c);
326 ++ }
327 ++ printk("\n");
328 ++}
329 ++#endif
330 +
331 + /*
332 + * This routine handles page faults. It determines the address,
333 +@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
334 + good_area:
335 + si_code = SEGV_ACCERR;
336 + if (cause < 0) {
337 +- if (!(vma->vm_flags & VM_EXEC))
338 ++ if (!(vma->vm_flags & VM_EXEC)) {
339 ++
340 ++#ifdef CONFIG_PAX_PAGEEXEC
341 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
342 ++ goto bad_area;
343 ++
344 ++ up_read(&mm->mmap_sem);
345 ++ switch (pax_handle_fetch_fault(regs)) {
346 ++
347 ++#ifdef CONFIG_PAX_EMUPLT
348 ++ case 2:
349 ++ case 3:
350 ++ return;
351 ++#endif
352 ++
353 ++ }
354 ++ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
355 ++ do_group_exit(SIGKILL);
356 ++#else
357 + goto bad_area;
358 ++#endif
359 ++
360 ++ }
361 + } else if (!cause) {
362 + /* Allow reads even for write-only mappings */
363 + if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
364 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/elf.h linux-2.6.27.10/arch/arm/include/asm/elf.h
365 +--- linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
366 ++++ linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
367 +@@ -87,7 +87,14 @@ extern char elf_platform[];
368 + the loader. We need to make sure that it is out of the way of the program
369 + that it will "exec", and that there is sufficient room for the brk. */
370 +
371 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
372 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
373 ++
374 ++#ifdef CONFIG_PAX_ASLR
375 ++#define PAX_ELF_ET_DYN_BASE 0x00008000UL
376 ++
377 ++#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
378 ++#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
379 ++#endif
380 +
381 + /* When the program starts, a1 contains a pointer to a function to be
382 + registered with atexit, as per the SVR4 ABI. A value of 0 means we
383 +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
384 +--- linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
385 ++++ linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
386 +@@ -18,6 +18,7 @@ enum km_type {
387 + KM_IRQ1,
388 + KM_SOFTIRQ0,
389 + KM_SOFTIRQ1,
390 ++ KM_CLEARPAGE,
391 + KM_TYPE_NR
392 + };
393 +
394 +diff -urNp linux-2.6.27.10/arch/arm/mm/mmap.c linux-2.6.27.10/arch/arm/mm/mmap.c
395 +--- linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
396 ++++ linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
397 +@@ -60,6 +60,10 @@ arch_get_unmapped_area(struct file *filp
398 + if (len > TASK_SIZE)
399 + return -ENOMEM;
400 +
401 ++#ifdef CONFIG_PAX_RANDMMAP
402 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
403 ++#endif
404 ++
405 + if (addr) {
406 + if (do_align)
407 + addr = COLOUR_ALIGN(addr, pgoff);
408 +@@ -72,10 +76,10 @@ arch_get_unmapped_area(struct file *filp
409 + return addr;
410 + }
411 + if (len > mm->cached_hole_size) {
412 +- start_addr = addr = mm->free_area_cache;
413 ++ start_addr = addr = mm->free_area_cache;
414 + } else {
415 +- start_addr = addr = TASK_UNMAPPED_BASE;
416 +- mm->cached_hole_size = 0;
417 ++ start_addr = addr = mm->mmap_base;
418 ++ mm->cached_hole_size = 0;
419 + }
420 +
421 + full_search:
422 +@@ -91,8 +95,8 @@ full_search:
423 + * Start a new search - just in case we missed
424 + * some holes.
425 + */
426 +- if (start_addr != TASK_UNMAPPED_BASE) {
427 +- start_addr = addr = TASK_UNMAPPED_BASE;
428 ++ if (start_addr != mm->mmap_base) {
429 ++ start_addr = addr = mm->mmap_base;
430 + mm->cached_hole_size = 0;
431 + goto full_search;
432 + }
433 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/elf.h linux-2.6.27.10/arch/avr32/include/asm/elf.h
434 +--- linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
435 ++++ linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
436 +@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
437 + the loader. We need to make sure that it is out of the way of the program
438 + that it will "exec", and that there is sufficient room for the brk. */
439 +
440 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
441 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
442 +
443 ++#ifdef CONFIG_PAX_ASLR
444 ++#define PAX_ELF_ET_DYN_BASE 0x00001000UL
445 ++
446 ++#define PAX_DELTA_MMAP_LEN 15
447 ++#define PAX_DELTA_STACK_LEN 15
448 ++#endif
449 +
450 + /* This yields a mask that user programs can use to figure out what
451 + instruction set this CPU supports. This could be done in user space,
452 +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
453 +--- linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
454 ++++ linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
455 +@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
456 + D(11) KM_IRQ1,
457 + D(12) KM_SOFTIRQ0,
458 + D(13) KM_SOFTIRQ1,
459 +-D(14) KM_TYPE_NR
460 ++D(14) KM_CLEARPAGE,
461 ++D(15) KM_TYPE_NR
462 + };
463 +
464 + #undef D
465 +diff -urNp linux-2.6.27.10/arch/avr32/mm/fault.c linux-2.6.27.10/arch/avr32/mm/fault.c
466 +--- linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
467 ++++ linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
468 +@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
469 +
470 + int exception_trace = 1;
471 +
472 ++#ifdef CONFIG_PAX_PAGEEXEC
473 ++void pax_report_insns(void *pc, void *sp)
474 ++{
475 ++ unsigned long i;
476 ++
477 ++ printk(KERN_ERR "PAX: bytes at PC: ");
478 ++ for (i = 0; i < 20; i++) {
479 ++ unsigned char c;
480 ++ if (get_user(c, (unsigned char *)pc+i))
481 ++ printk(KERN_CONT "???????? ");
482 ++ else
483 ++ printk(KERN_CONT "%02x ", c);
484 ++ }
485 ++ printk("\n");
486 ++}
487 ++#endif
488 ++
489 + /*
490 + * This routine handles page faults. It determines the address and the
491 + * problem, and then passes it off to one of the appropriate routines.
492 +@@ -157,6 +174,16 @@ bad_area:
493 + up_read(&mm->mmap_sem);
494 +
495 + if (user_mode(regs)) {
496 ++
497 ++#ifdef CONFIG_PAX_PAGEEXEC
498 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
499 ++ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
500 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
501 ++ do_group_exit(SIGKILL);
502 ++ }
503 ++ }
504 ++#endif
505 ++
506 + if (exception_trace && printk_ratelimit())
507 + printk("%s%s[%d]: segfault at %08lx pc %08lx "
508 + "sp %08lx ecr %lu\n",
509 +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
510 +--- linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
511 ++++ linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
512 +@@ -15,6 +15,7 @@ enum km_type {
513 + KM_IRQ1,
514 + KM_SOFTIRQ0,
515 + KM_SOFTIRQ1,
516 ++ KM_CLEARPAGE,
517 + KM_TYPE_NR
518 + };
519 +
520 +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
521 +--- linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
522 ++++ linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
523 +@@ -15,6 +15,7 @@ enum km_type {
524 + KM_IRQ1,
525 + KM_SOFTIRQ0,
526 + KM_SOFTIRQ1,
527 ++ KM_CLEARPAGE,
528 + KM_TYPE_NR
529 + };
530 +
531 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c
532 +--- linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-07 12:55:34.000000000 -0500
533 ++++ linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-18 03:38:43.000000000 -0500
534 +@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
535 +
536 + #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
537 +
538 ++#ifdef CONFIG_PAX_ASLR
539 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
540 ++
541 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
542 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
543 ++#endif
544 ++
545 + /* Ugly but avoids duplication */
546 + #include "../../../fs/binfmt_elf.c"
547 +
548 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/ia32priv.h linux-2.6.27.10/arch/ia64/ia32/ia32priv.h
549 +--- linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-07 12:55:34.000000000 -0500
550 ++++ linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-18 03:38:43.000000000 -0500
551 +@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
552 + #define ELF_DATA ELFDATA2LSB
553 + #define ELF_ARCH EM_386
554 +
555 +-#define IA32_STACK_TOP IA32_PAGE_OFFSET
556 ++#ifdef CONFIG_PAX_RANDUSTACK
557 ++#define __IA32_DELTA_STACK (current->mm->delta_stack)
558 ++#else
559 ++#define __IA32_DELTA_STACK 0UL
560 ++#endif
561 ++
562 ++#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
563 ++
564 + #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
565 + #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
566 +
567 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/elf.h linux-2.6.27.10/arch/ia64/include/asm/elf.h
568 +--- linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
569 ++++ linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
570 +@@ -43,6 +43,13 @@
571 + */
572 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
573 +
574 ++#ifdef CONFIG_PAX_ASLR
575 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
576 ++
577 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
578 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
579 ++#endif
580 ++
581 + #define PT_IA_64_UNWIND 0x70000001
582 +
583 + /* IA-64 relocations: */
584 +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
585 +--- linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
586 ++++ linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
587 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
588 + D(10) KM_IRQ1,
589 + D(11) KM_SOFTIRQ0,
590 + D(12) KM_SOFTIRQ1,
591 +-D(13) KM_TYPE_NR
592 ++D(13) KM_CLEARPAGE,
593 ++D(14) KM_TYPE_NR
594 + };
595 +
596 + #undef D
597 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/pgtable.h linux-2.6.27.10/arch/ia64/include/asm/pgtable.h
598 +--- linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
599 ++++ linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
600 +@@ -143,6 +143,17 @@
601 + #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
602 + #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
603 + #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
604 ++
605 ++#ifdef CONFIG_PAX_PAGEEXEC
606 ++# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
607 ++# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
608 ++# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
609 ++#else
610 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
611 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
612 ++# define PAGE_COPY_NOEXEC PAGE_COPY
613 ++#endif
614 ++
615 + #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
616 + #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
617 + #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
618 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/module.c linux-2.6.27.10/arch/ia64/kernel/module.c
619 +--- linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
620 ++++ linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
621 +@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
622 + void
623 + module_free (struct module *mod, void *module_region)
624 + {
625 +- if (mod && mod->arch.init_unw_table &&
626 +- module_region == mod->module_init) {
627 ++ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
628 + unw_remove_unwind_table(mod->arch.init_unw_table);
629 + mod->arch.init_unw_table = NULL;
630 + }
631 +@@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
632 + }
633 +
634 + static inline int
635 ++in_init_rx (const struct module *mod, uint64_t addr)
636 ++{
637 ++ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
638 ++}
639 ++
640 ++static inline int
641 ++in_init_rw (const struct module *mod, uint64_t addr)
642 ++{
643 ++ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
644 ++}
645 ++
646 ++static inline int
647 + in_init (const struct module *mod, uint64_t addr)
648 + {
649 +- return addr - (uint64_t) mod->module_init < mod->init_size;
650 ++ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
651 ++}
652 ++
653 ++static inline int
654 ++in_core_rx (const struct module *mod, uint64_t addr)
655 ++{
656 ++ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
657 ++}
658 ++
659 ++static inline int
660 ++in_core_rw (const struct module *mod, uint64_t addr)
661 ++{
662 ++ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
663 + }
664 +
665 + static inline int
666 + in_core (const struct module *mod, uint64_t addr)
667 + {
668 +- return addr - (uint64_t) mod->module_core < mod->core_size;
669 ++ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
670 + }
671 +
672 + static inline int
673 +@@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_
674 + break;
675 +
676 + case RV_BDREL:
677 +- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
678 ++ if (in_init_rx(mod, val))
679 ++ val -= (uint64_t) mod->module_init_rx;
680 ++ else if (in_init_rw(mod, val))
681 ++ val -= (uint64_t) mod->module_init_rw;
682 ++ else if (in_core_rx(mod, val))
683 ++ val -= (uint64_t) mod->module_core_rx;
684 ++ else if (in_core_rw(mod, val))
685 ++ val -= (uint64_t) mod->module_core_rw;
686 + break;
687 +
688 + case RV_LTV:
689 +@@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
690 + * addresses have been selected...
691 + */
692 + uint64_t gp;
693 +- if (mod->core_size > MAX_LTOFF)
694 ++ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
695 + /*
696 + * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
697 + * at the end of the module.
698 + */
699 +- gp = mod->core_size - MAX_LTOFF / 2;
700 ++ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
701 + else
702 +- gp = mod->core_size / 2;
703 +- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
704 ++ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
705 ++ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
706 + mod->arch.gp = gp;
707 + DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
708 + }
709 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c
710 +--- linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-07 12:55:34.000000000 -0500
711 ++++ linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-18 03:38:43.000000000 -0500
712 +@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
713 + if (REGION_NUMBER(addr) == RGN_HPAGE)
714 + addr = 0;
715 + #endif
716 ++
717 ++#ifdef CONFIG_PAX_RANDMMAP
718 ++ if ((mm->pax_flags & MF_PAX_RANDMMAP) && addr && filp)
719 ++ addr = mm->free_area_cache;
720 ++ else
721 ++#endif
722 ++
723 + if (!addr)
724 + addr = mm->free_area_cache;
725 +
726 +@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
727 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
728 + /* At this point: (!vma || addr < vma->vm_end). */
729 + if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
730 +- if (start_addr != TASK_UNMAPPED_BASE) {
731 ++ if (start_addr != mm->mmap_base) {
732 + /* Start a new search --- just in case we missed some holes. */
733 +- addr = TASK_UNMAPPED_BASE;
734 ++ addr = mm->mmap_base;
735 + goto full_search;
736 + }
737 + return -ENOMEM;
738 +diff -urNp linux-2.6.27.10/arch/ia64/mm/fault.c linux-2.6.27.10/arch/ia64/mm/fault.c
739 +--- linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
740 ++++ linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
741 +@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
742 + return pte_present(pte);
743 + }
744 +
745 ++#ifdef CONFIG_PAX_PAGEEXEC
746 ++void pax_report_insns(void *pc, void *sp)
747 ++{
748 ++ unsigned long i;
749 ++
750 ++ printk(KERN_ERR "PAX: bytes at PC: ");
751 ++ for (i = 0; i < 8; i++) {
752 ++ unsigned int c;
753 ++ if (get_user(c, (unsigned int *)pc+i))
754 ++ printk(KERN_CONT "???????? ");
755 ++ else
756 ++ printk(KERN_CONT "%08x ", c);
757 ++ }
758 ++ printk("\n");
759 ++}
760 ++#endif
761 ++
762 + void __kprobes
763 + ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
764 + {
765 +@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
766 + mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
767 + | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
768 +
769 +- if ((vma->vm_flags & mask) != mask)
770 ++ if ((vma->vm_flags & mask) != mask) {
771 ++
772 ++#ifdef CONFIG_PAX_PAGEEXEC
773 ++ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
774 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
775 ++ goto bad_area;
776 ++
777 ++ up_read(&mm->mmap_sem);
778 ++ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
779 ++ do_group_exit(SIGKILL);
780 ++ }
781 ++#endif
782 ++
783 + goto bad_area;
784 +
785 ++ }
786 ++
787 + survive:
788 + /*
789 + * If for any reason at all we couldn't handle the fault, make
790 +diff -urNp linux-2.6.27.10/arch/ia64/mm/init.c linux-2.6.27.10/arch/ia64/mm/init.c
791 +--- linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-07 12:55:34.000000000 -0500
792 ++++ linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-18 03:38:43.000000000 -0500
793 +@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
794 + vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
795 + vma->vm_end = vma->vm_start + PAGE_SIZE;
796 + vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
797 ++
798 ++#ifdef CONFIG_PAX_PAGEEXEC
799 ++ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
800 ++ vma->vm_flags &= ~VM_EXEC;
801 ++
802 ++#ifdef CONFIG_PAX_MPROTECT
803 ++ if (current->mm->pax_flags & MF_PAX_MPROTECT)
804 ++ vma->vm_flags &= ~VM_MAYEXEC;
805 ++#endif
806 ++
807 ++ }
808 ++#endif
809 ++
810 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
811 + down_write(&current->mm->mmap_sem);
812 + if (insert_vm_struct(current->mm, vma)) {
813 +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
814 +--- linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
815 ++++ linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
816 +@@ -15,6 +15,7 @@ enum km_type {
817 + KM_IRQ1,
818 + KM_SOFTIRQ0,
819 + KM_SOFTIRQ1,
820 ++ KM_CLEARPAGE,
821 + KM_TYPE_NR
822 + };
823 +
824 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c
825 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-07 12:55:34.000000000 -0500
826 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-18 03:38:43.000000000 -0500
827 +@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
828 + #undef ELF_ET_DYN_BASE
829 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
830 +
831 ++#ifdef CONFIG_PAX_ASLR
832 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
833 ++
834 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
835 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
836 ++#endif
837 ++
838 + #include <asm/processor.h>
839 + #include <linux/module.h>
840 + #include <linux/elfcore.h>
841 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c
842 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-07 12:55:34.000000000 -0500
843 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-18 03:38:43.000000000 -0500
844 +@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
845 + #undef ELF_ET_DYN_BASE
846 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
847 +
848 ++#ifdef CONFIG_PAX_ASLR
849 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
850 ++
851 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
852 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
853 ++#endif
854 ++
855 + #include <asm/processor.h>
856 + #include <linux/module.h>
857 + #include <linux/elfcore.h>
858 +diff -urNp linux-2.6.27.10/arch/mips/kernel/process.c linux-2.6.27.10/arch/mips/kernel/process.c
859 +--- linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-07 12:55:34.000000000 -0500
860 ++++ linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-18 03:38:43.000000000 -0500
861 +@@ -458,15 +458,3 @@ unsigned long get_wchan(struct task_stru
862 + out:
863 + return pc;
864 + }
865 +-
866 +-/*
867 +- * Don't forget that the stack pointer must be aligned on a 8 bytes
868 +- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
869 +- */
870 +-unsigned long arch_align_stack(unsigned long sp)
871 +-{
872 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
873 +- sp -= get_random_int() & ~PAGE_MASK;
874 +-
875 +- return sp & ALMASK;
876 +-}
877 +diff -urNp linux-2.6.27.10/arch/mips/kernel/syscall.c linux-2.6.27.10/arch/mips/kernel/syscall.c
878 +--- linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-07 12:55:34.000000000 -0500
879 ++++ linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-18 03:38:43.000000000 -0500
880 +@@ -100,6 +100,11 @@ unsigned long arch_get_unmapped_area(str
881 + do_color_align = 0;
882 + if (filp || (flags & MAP_SHARED))
883 + do_color_align = 1;
884 ++
885 ++#ifdef CONFIG_PAX_RANDMMAP
886 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
887 ++#endif
888 ++
889 + if (addr) {
890 + if (do_color_align)
891 + addr = COLOUR_ALIGN(addr, pgoff);
892 +@@ -110,7 +115,7 @@ unsigned long arch_get_unmapped_area(str
893 + (!vmm || addr + len <= vmm->vm_start))
894 + return addr;
895 + }
896 +- addr = TASK_UNMAPPED_BASE;
897 ++ addr = current->mm->mmap_base;
898 + if (do_color_align)
899 + addr = COLOUR_ALIGN(addr, pgoff);
900 + else
901 +diff -urNp linux-2.6.27.10/arch/mips/mm/fault.c linux-2.6.27.10/arch/mips/mm/fault.c
902 +--- linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
903 ++++ linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
904 +@@ -26,6 +26,23 @@
905 + #include <asm/ptrace.h>
906 + #include <asm/highmem.h> /* For VMALLOC_END */
907 +
908 ++#ifdef CONFIG_PAX_PAGEEXEC
909 ++void pax_report_insns(void *pc)
910 ++{
911 ++ unsigned long i;
912 ++
913 ++ printk(KERN_ERR "PAX: bytes at PC: ");
914 ++ for (i = 0; i < 5; i++) {
915 ++ unsigned int c;
916 ++ if (get_user(c, (unsigned int *)pc+i))
917 ++ printk(KERN_CONT "???????? ");
918 ++ else
919 ++ printk(KERN_CONT "%08x ", c);
920 ++ }
921 ++ printk("\n");
922 ++}
923 ++#endif
924 ++
925 + /*
926 + * This routine handles page faults. It determines the address,
927 + * and the problem, and then passes it off to one of the appropriate
928 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/module.c linux-2.6.27.10/arch/parisc/kernel/module.c
929 +--- linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
930 ++++ linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
931 +@@ -75,16 +75,38 @@
932 +
933 + /* three functions to determine where in the module core
934 + * or init pieces the location is */
935 ++static inline int in_init_rx(struct module *me, void *loc)
936 ++{
937 ++ return (loc >= me->module_init_rx &&
938 ++ loc < (me->module_init_rx + me->init_size_rx));
939 ++}
940 ++
941 ++static inline int in_init_rw(struct module *me, void *loc)
942 ++{
943 ++ return (loc >= me->module_init_rw &&
944 ++ loc < (me->module_init_rw + me->init_size_rw));
945 ++}
946 ++
947 + static inline int in_init(struct module *me, void *loc)
948 + {
949 +- return (loc >= me->module_init &&
950 +- loc <= (me->module_init + me->init_size));
951 ++ return in_init_rx(me, loc) || in_init_rw(me, loc);
952 ++}
953 ++
954 ++static inline int in_core_rx(struct module *me, void *loc)
955 ++{
956 ++ return (loc >= me->module_core_rx &&
957 ++ loc < (me->module_core_rx + me->core_size_rx));
958 ++}
959 ++
960 ++static inline int in_core_rw(struct module *me, void *loc)
961 ++{
962 ++ return (loc >= me->module_core_rw &&
963 ++ loc < (me->module_core_rw + me->core_size_rw));
964 + }
965 +
966 + static inline int in_core(struct module *me, void *loc)
967 + {
968 +- return (loc >= me->module_core &&
969 +- loc <= (me->module_core + me->core_size));
970 ++ return in_core_rx(me, loc) || in_core_rw(me, loc);
971 + }
972 +
973 + static inline int in_local(struct module *me, void *loc)
974 +@@ -298,21 +320,21 @@ int module_frob_arch_sections(CONST Elf_
975 + }
976 +
977 + /* align things a bit */
978 +- me->core_size = ALIGN(me->core_size, 16);
979 +- me->arch.got_offset = me->core_size;
980 +- me->core_size += gots * sizeof(struct got_entry);
981 +-
982 +- me->core_size = ALIGN(me->core_size, 16);
983 +- me->arch.fdesc_offset = me->core_size;
984 +- me->core_size += fdescs * sizeof(Elf_Fdesc);
985 +-
986 +- me->core_size = ALIGN(me->core_size, 16);
987 +- me->arch.stub_offset = me->core_size;
988 +- me->core_size += stubs * sizeof(struct stub_entry);
989 +-
990 +- me->init_size = ALIGN(me->init_size, 16);
991 +- me->arch.init_stub_offset = me->init_size;
992 +- me->init_size += init_stubs * sizeof(struct stub_entry);
993 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
994 ++ me->arch.got_offset = me->core_size_rw;
995 ++ me->core_size_rw += gots * sizeof(struct got_entry);
996 ++
997 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
998 ++ me->arch.fdesc_offset = me->core_size_rw;
999 ++ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1000 ++
1001 ++ me->core_size_rx = ALIGN(me->core_size_rx, 16);
1002 ++ me->arch.stub_offset = me->core_size_rx;
1003 ++ me->core_size_rx += stubs * sizeof(struct stub_entry);
1004 ++
1005 ++ me->init_size_rx = ALIGN(me->init_size_rx, 16);
1006 ++ me->arch.init_stub_offset = me->init_size_rx;
1007 ++ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
1008 +
1009 + me->arch.got_max = gots;
1010 + me->arch.fdesc_max = fdescs;
1011 +@@ -332,7 +354,7 @@ static Elf64_Word get_got(struct module
1012 +
1013 + BUG_ON(value == 0);
1014 +
1015 +- got = me->module_core + me->arch.got_offset;
1016 ++ got = me->module_core_rw + me->arch.got_offset;
1017 + for (i = 0; got[i].addr; i++)
1018 + if (got[i].addr == value)
1019 + goto out;
1020 +@@ -350,7 +372,7 @@ static Elf64_Word get_got(struct module
1021 + #ifdef CONFIG_64BIT
1022 + static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1023 + {
1024 +- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1025 ++ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1026 +
1027 + if (!value) {
1028 + printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1029 +@@ -368,7 +390,7 @@ static Elf_Addr get_fdesc(struct module
1030 +
1031 + /* Create new one */
1032 + fdesc->addr = value;
1033 +- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1034 ++ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1035 + return (Elf_Addr)fdesc;
1036 + }
1037 + #endif /* CONFIG_64BIT */
1038 +@@ -388,12 +410,12 @@ static Elf_Addr get_stub(struct module *
1039 + if(init_section) {
1040 + i = me->arch.init_stub_count++;
1041 + BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
1042 +- stub = me->module_init + me->arch.init_stub_offset +
1043 ++ stub = me->module_init_rx + me->arch.init_stub_offset +
1044 + i * sizeof(struct stub_entry);
1045 + } else {
1046 + i = me->arch.stub_count++;
1047 + BUG_ON(me->arch.stub_count > me->arch.stub_max);
1048 +- stub = me->module_core + me->arch.stub_offset +
1049 ++ stub = me->module_core_rx + me->arch.stub_offset +
1050 + i * sizeof(struct stub_entry);
1051 + }
1052 +
1053 +@@ -761,7 +783,7 @@ register_unwind_table(struct module *me,
1054 +
1055 + table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1056 + end = table + sechdrs[me->arch.unwind_section].sh_size;
1057 +- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1058 ++ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1059 +
1060 + DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1061 + me->arch.unwind_section, table, end, gp);
1062 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c
1063 +--- linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-07 12:55:34.000000000 -0500
1064 ++++ linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-18 03:38:43.000000000 -0500
1065 +@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1066 + if (flags & MAP_FIXED)
1067 + return addr;
1068 + if (!addr)
1069 +- addr = TASK_UNMAPPED_BASE;
1070 ++ addr = current->mm->mmap_base;
1071 +
1072 + if (filp) {
1073 + addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1074 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/traps.c linux-2.6.27.10/arch/parisc/kernel/traps.c
1075 +--- linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:36.000000000 -0500
1076 ++++ linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:46.000000000 -0500
1077 +@@ -731,9 +731,7 @@ void handle_interruption(int code, struc
1078 +
1079 + down_read(&current->mm->mmap_sem);
1080 + vma = find_vma(current->mm,regs->iaoq[0]);
1081 +- if (vma && (regs->iaoq[0] >= vma->vm_start)
1082 +- && (vma->vm_flags & VM_EXEC)) {
1083 +-
1084 ++ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1085 + fault_address = regs->iaoq[0];
1086 + fault_space = regs->iasq[0];
1087 +
1088 +diff -urNp linux-2.6.27.10/arch/parisc/mm/fault.c linux-2.6.27.10/arch/parisc/mm/fault.c
1089 +--- linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1090 ++++ linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1091 +@@ -16,6 +16,7 @@
1092 + #include <linux/sched.h>
1093 + #include <linux/interrupt.h>
1094 + #include <linux/module.h>
1095 ++#include <linux/unistd.h>
1096 +
1097 + #include <asm/uaccess.h>
1098 + #include <asm/traps.h>
1099 +@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1100 + static unsigned long
1101 + parisc_acctyp(unsigned long code, unsigned int inst)
1102 + {
1103 +- if (code == 6 || code == 16)
1104 ++ if (code == 6 || code == 7 || code == 16)
1105 + return VM_EXEC;
1106 +
1107 + switch (inst & 0xf0000000) {
1108 +@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
1109 + }
1110 + #endif
1111 +
1112 ++#ifdef CONFIG_PAX_PAGEEXEC
1113 ++/*
1114 ++ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1115 ++ *
1116 ++ * returns 1 when task should be killed
1117 ++ * 2 when rt_sigreturn trampoline was detected
1118 ++ * 3 when unpatched PLT trampoline was detected
1119 ++ */
1120 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1121 ++{
1122 ++
1123 ++#ifdef CONFIG_PAX_EMUPLT
1124 ++ int err;
1125 ++
1126 ++ do { /* PaX: unpatched PLT emulation */
1127 ++ unsigned int bl, depwi;
1128 ++
1129 ++ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1130 ++ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1131 ++
1132 ++ if (err)
1133 ++ break;
1134 ++
1135 ++ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1136 ++ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1137 ++
1138 ++ err = get_user(ldw, (unsigned int *)addr);
1139 ++ err |= get_user(bv, (unsigned int *)(addr+4));
1140 ++ err |= get_user(ldw2, (unsigned int *)(addr+8));
1141 ++
1142 ++ if (err)
1143 ++ break;
1144 ++
1145 ++ if (ldw == 0x0E801096U &&
1146 ++ bv == 0xEAC0C000U &&
1147 ++ ldw2 == 0x0E881095U)
1148 ++ {
1149 ++ unsigned int resolver, map;
1150 ++
1151 ++ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1152 ++ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1153 ++ if (err)
1154 ++ break;
1155 ++
1156 ++ regs->gr[20] = instruction_pointer(regs)+8;
1157 ++ regs->gr[21] = map;
1158 ++ regs->gr[22] = resolver;
1159 ++ regs->iaoq[0] = resolver | 3UL;
1160 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1161 ++ return 3;
1162 ++ }
1163 ++ }
1164 ++ } while (0);
1165 ++#endif
1166 ++
1167 ++#ifdef CONFIG_PAX_EMUTRAMP
1168 ++
1169 ++#ifndef CONFIG_PAX_EMUSIGRT
1170 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1171 ++ return 1;
1172 ++#endif
1173 ++
1174 ++ do { /* PaX: rt_sigreturn emulation */
1175 ++ unsigned int ldi1, ldi2, bel, nop;
1176 ++
1177 ++ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1178 ++ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1179 ++ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1180 ++ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1181 ++
1182 ++ if (err)
1183 ++ break;
1184 ++
1185 ++ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1186 ++ ldi2 == 0x3414015AU &&
1187 ++ bel == 0xE4008200U &&
1188 ++ nop == 0x08000240U)
1189 ++ {
1190 ++ regs->gr[25] = (ldi1 & 2) >> 1;
1191 ++ regs->gr[20] = __NR_rt_sigreturn;
1192 ++ regs->gr[31] = regs->iaoq[1] + 16;
1193 ++ regs->sr[0] = regs->iasq[1];
1194 ++ regs->iaoq[0] = 0x100UL;
1195 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1196 ++ regs->iasq[0] = regs->sr[2];
1197 ++ regs->iasq[1] = regs->sr[2];
1198 ++ return 2;
1199 ++ }
1200 ++ } while (0);
1201 ++#endif
1202 ++
1203 ++ return 1;
1204 ++}
1205 ++
1206 ++void pax_report_insns(void *pc, void *sp)
1207 ++{
1208 ++ unsigned long i;
1209 ++
1210 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1211 ++ for (i = 0; i < 5; i++) {
1212 ++ unsigned int c;
1213 ++ if (get_user(c, (unsigned int *)pc+i))
1214 ++ printk(KERN_CONT "???????? ");
1215 ++ else
1216 ++ printk(KERN_CONT "%08x ", c);
1217 ++ }
1218 ++ printk("\n");
1219 ++}
1220 ++#endif
1221 ++
1222 + void do_page_fault(struct pt_regs *regs, unsigned long code,
1223 + unsigned long address)
1224 + {
1225 +@@ -165,8 +276,33 @@ good_area:
1226 +
1227 + acc_type = parisc_acctyp(code,regs->iir);
1228 +
1229 +- if ((vma->vm_flags & acc_type) != acc_type)
1230 ++ if ((vma->vm_flags & acc_type) != acc_type) {
1231 ++
1232 ++#ifdef CONFIG_PAX_PAGEEXEC
1233 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1234 ++ (address & ~3UL) == instruction_pointer(regs))
1235 ++ {
1236 ++ up_read(&mm->mmap_sem);
1237 ++ switch (pax_handle_fetch_fault(regs)) {
1238 ++
1239 ++#ifdef CONFIG_PAX_EMUPLT
1240 ++ case 3:
1241 ++ return;
1242 ++#endif
1243 ++
1244 ++#ifdef CONFIG_PAX_EMUTRAMP
1245 ++ case 2:
1246 ++ return;
1247 ++#endif
1248 ++
1249 ++ }
1250 ++ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1251 ++ do_group_exit(SIGKILL);
1252 ++ }
1253 ++#endif
1254 ++
1255 + goto bad_area;
1256 ++ }
1257 +
1258 + /*
1259 + * If for any reason at all we couldn't handle the fault, make
1260 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/elf.h linux-2.6.27.10/arch/powerpc/include/asm/elf.h
1261 +--- linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
1262 ++++ linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
1263 +@@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
1264 +
1265 + #define ELF_ET_DYN_BASE (0x20000000)
1266 +
1267 ++#ifdef CONFIG_PAX_ASLR
1268 ++#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
1269 ++
1270 ++#ifdef __powerpc64__
1271 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1272 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1273 ++#else
1274 ++#define PAX_DELTA_MMAP_LEN 15
1275 ++#define PAX_DELTA_STACK_LEN 15
1276 ++#endif
1277 ++#endif
1278 ++
1279 + /*
1280 + * Our registers are always unsigned longs, whether we're a 32 bit
1281 + * process or 64 bit, on either a 64 bit or 32 bit kernel.
1282 +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
1283 +--- linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1284 ++++ linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1285 +@@ -26,6 +26,7 @@ enum km_type {
1286 + KM_SOFTIRQ1,
1287 + KM_PPC_SYNC_PAGE,
1288 + KM_PPC_SYNC_ICACHE,
1289 ++ KM_CLEARPAGE,
1290 + KM_TYPE_NR
1291 + };
1292 +
1293 +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
1294 +--- linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-07 12:55:34.000000000 -0500
1295 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-18 03:39:50.000000000 -0500
1296 +@@ -170,15 +170,18 @@ do { \
1297 + * stack by default, so in the absense of a PT_GNU_STACK program header
1298 + * we turn execute permission off.
1299 + */
1300 +-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1301 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1302 ++#define VM_STACK_DEFAULT_FLAGS32 \
1303 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1304 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1305 +
1306 + #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1307 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1308 +
1309 ++#ifndef CONFIG_PAX_PAGEEXEC
1310 + #define VM_STACK_DEFAULT_FLAGS \
1311 + (test_thread_flag(TIF_32BIT) ? \
1312 + VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
1313 ++#endif
1314 +
1315 + #include <asm-generic/page.h>
1316 +
1317 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page.h linux-2.6.27.10/arch/powerpc/include/asm/page.h
1318 +--- linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-07 12:55:34.000000000 -0500
1319 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-18 03:39:50.000000000 -0500
1320 +@@ -100,8 +100,9 @@ extern phys_addr_t kernstart_addr;
1321 + * and needs to be executable. This means the whole heap ends
1322 + * up being executable.
1323 + */
1324 +-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1325 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1326 ++#define VM_DATA_DEFAULT_FLAGS32 \
1327 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1328 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1329 +
1330 + #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1331 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1332 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/module_32.c linux-2.6.27.10/arch/powerpc/kernel/module_32.c
1333 +--- linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
1334 ++++ linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-18 03:38:43.000000000 -0500
1335 +@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr
1336 + me->arch.core_plt_section = i;
1337 + }
1338 + if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
1339 +- printk("Module doesn't contain .plt or .init.plt sections.\n");
1340 ++ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
1341 + return -ENOEXEC;
1342 + }
1343 +
1344 +@@ -199,11 +199,16 @@ static uint32_t do_plt_call(void *locati
1345 +
1346 + DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
1347 + /* Init, or core PLT? */
1348 +- if (location >= mod->module_core
1349 +- && location < mod->module_core + mod->core_size)
1350 ++ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
1351 ++ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
1352 + entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
1353 +- else
1354 ++ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
1355 ++ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
1356 + entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
1357 ++ else {
1358 ++ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
1359 ++ return ~0UL;
1360 ++ }
1361 +
1362 + /* Find this entry, or if that fails, the next avail. entry */
1363 + while (entry->jump[0]) {
1364 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_32.c linux-2.6.27.10/arch/powerpc/kernel/signal_32.c
1365 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
1366 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-18 03:38:43.000000000 -0500
1367 +@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
1368 + /* Save user registers on the stack */
1369 + frame = &rt_sf->uc.uc_mcontext;
1370 + addr = frame;
1371 +- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
1372 ++ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1373 + if (save_user_regs(regs, frame, 0))
1374 + goto badframe;
1375 + regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
1376 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_64.c linux-2.6.27.10/arch/powerpc/kernel/signal_64.c
1377 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
1378 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-18 03:38:43.000000000 -0500
1379 +@@ -434,7 +434,7 @@ int handle_rt_signal64(int signr, struct
1380 + current->thread.fpscr.val = 0;
1381 +
1382 + /* Set up to return from userspace. */
1383 +- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
1384 ++ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1385 + regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
1386 + } else {
1387 + err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
1388 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/vdso.c linux-2.6.27.10/arch/powerpc/kernel/vdso.c
1389 +--- linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-07 12:55:34.000000000 -0500
1390 ++++ linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-18 03:38:43.000000000 -0500
1391 +@@ -212,7 +212,7 @@ int arch_setup_additional_pages(struct l
1392 + vdso_base = VDSO32_MBASE;
1393 + #endif
1394 +
1395 +- current->mm->context.vdso_base = 0;
1396 ++ current->mm->context.vdso_base = ~0UL;
1397 +
1398 + /* vDSO has a problem and was disabled, just don't "enable" it for the
1399 + * process
1400 +@@ -229,7 +229,7 @@ int arch_setup_additional_pages(struct l
1401 + */
1402 + down_write(&mm->mmap_sem);
1403 + vdso_base = get_unmapped_area(NULL, vdso_base,
1404 +- vdso_pages << PAGE_SHIFT, 0, 0);
1405 ++ vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
1406 + if (IS_ERR_VALUE(vdso_base)) {
1407 + rc = vdso_base;
1408 + goto fail_mmapsem;
1409 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/fault.c linux-2.6.27.10/arch/powerpc/mm/fault.c
1410 +--- linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1411 ++++ linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1412 +@@ -29,6 +29,10 @@
1413 + #include <linux/module.h>
1414 + #include <linux/kprobes.h>
1415 + #include <linux/kdebug.h>
1416 ++#include <linux/slab.h>
1417 ++#include <linux/pagemap.h>
1418 ++#include <linux/compiler.h>
1419 ++#include <linux/unistd.h>
1420 +
1421 + #include <asm/page.h>
1422 + #include <asm/pgtable.h>
1423 +@@ -62,6 +66,363 @@ static inline int notify_page_fault(stru
1424 + }
1425 + #endif
1426 +
1427 ++#ifdef CONFIG_PAX_EMUSIGRT
1428 ++void pax_syscall_close(struct vm_area_struct *vma)
1429 ++{
1430 ++ vma->vm_mm->call_syscall = 0UL;
1431 ++}
1432 ++
1433 ++static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1434 ++{
1435 ++ unsigned int *kaddr;
1436 ++
1437 ++ vmf->page = alloc_page(GFP_HIGHUSER);
1438 ++ if (!vmf->page)
1439 ++ return VM_FAULT_OOM;
1440 ++
1441 ++ kaddr = kmap(vmf->page);
1442 ++ memset(kaddr, 0, PAGE_SIZE);
1443 ++ kaddr[0] = 0x44000002U; /* sc */
1444 ++ __flush_dcache_icache(kaddr);
1445 ++ kunmap(vmf->page);
1446 ++ return VM_FAULT_MAJOR;
1447 ++}
1448 ++
1449 ++static struct vm_operations_struct pax_vm_ops = {
1450 ++ .close = pax_syscall_close,
1451 ++ .fault = pax_syscall_fault
1452 ++};
1453 ++
1454 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
1455 ++{
1456 ++ int ret;
1457 ++
1458 ++ vma->vm_mm = current->mm;
1459 ++ vma->vm_start = addr;
1460 ++ vma->vm_end = addr + PAGE_SIZE;
1461 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
1462 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1463 ++ vma->vm_ops = &pax_vm_ops;
1464 ++
1465 ++ ret = insert_vm_struct(current->mm, vma);
1466 ++ if (ret)
1467 ++ return ret;
1468 ++
1469 ++ ++current->mm->total_vm;
1470 ++ return 0;
1471 ++}
1472 ++#endif
1473 ++
1474 ++#ifdef CONFIG_PAX_PAGEEXEC
1475 ++/*
1476 ++ * PaX: decide what to do with offenders (regs->nip = fault address)
1477 ++ *
1478 ++ * returns 1 when task should be killed
1479 ++ * 2 when patched GOT trampoline was detected
1480 ++ * 3 when patched PLT trampoline was detected
1481 ++ * 4 when unpatched PLT trampoline was detected
1482 ++ * 5 when sigreturn trampoline was detected
1483 ++ * 6 when rt_sigreturn trampoline was detected
1484 ++ */
1485 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1486 ++{
1487 ++
1488 ++#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
1489 ++ int err;
1490 ++#endif
1491 ++
1492 ++#ifdef CONFIG_PAX_EMUPLT
1493 ++ do { /* PaX: patched GOT emulation */
1494 ++ unsigned int blrl;
1495 ++
1496 ++ err = get_user(blrl, (unsigned int *)regs->nip);
1497 ++
1498 ++ if (!err && blrl == 0x4E800021U) {
1499 ++ unsigned long temp = regs->nip;
1500 ++
1501 ++ regs->nip = regs->link & 0xFFFFFFFCUL;
1502 ++ regs->link = temp + 4UL;
1503 ++ return 2;
1504 ++ }
1505 ++ } while (0);
1506 ++
1507 ++ do { /* PaX: patched PLT emulation #1 */
1508 ++ unsigned int b;
1509 ++
1510 ++ err = get_user(b, (unsigned int *)regs->nip);
1511 ++
1512 ++ if (!err && (b & 0xFC000003U) == 0x48000000U) {
1513 ++ regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
1514 ++ return 3;
1515 ++ }
1516 ++ } while (0);
1517 ++
1518 ++ do { /* PaX: unpatched PLT emulation #1 */
1519 ++ unsigned int li, b;
1520 ++
1521 ++ err = get_user(li, (unsigned int *)regs->nip);
1522 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1523 ++
1524 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1525 ++ unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1526 ++ unsigned long addr = b | 0xFC000000UL;
1527 ++
1528 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1529 ++ err = get_user(rlwinm, (unsigned int *)addr);
1530 ++ err |= get_user(add, (unsigned int *)(addr+4));
1531 ++ err |= get_user(li2, (unsigned int *)(addr+8));
1532 ++ err |= get_user(addis2, (unsigned int *)(addr+12));
1533 ++ err |= get_user(mtctr, (unsigned int *)(addr+16));
1534 ++ err |= get_user(li3, (unsigned int *)(addr+20));
1535 ++ err |= get_user(addis3, (unsigned int *)(addr+24));
1536 ++ err |= get_user(bctr, (unsigned int *)(addr+28));
1537 ++
1538 ++ if (err)
1539 ++ break;
1540 ++
1541 ++ if (rlwinm == 0x556C083CU &&
1542 ++ add == 0x7D6C5A14U &&
1543 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1544 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1545 ++ mtctr == 0x7D8903A6U &&
1546 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1547 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1548 ++ bctr == 0x4E800420U)
1549 ++ {
1550 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1551 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1552 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1553 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1554 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1555 ++ regs->nip = regs->ctr;
1556 ++ return 4;
1557 ++ }
1558 ++ }
1559 ++ } while (0);
1560 ++
1561 ++#if 0
1562 ++ do { /* PaX: unpatched PLT emulation #2 */
1563 ++ unsigned int lis, lwzu, b, bctr;
1564 ++
1565 ++ err = get_user(lis, (unsigned int *)regs->nip);
1566 ++ err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
1567 ++ err |= get_user(b, (unsigned int *)(regs->nip+8));
1568 ++ err |= get_user(bctr, (unsigned int *)(regs->nip+12));
1569 ++
1570 ++ if (err)
1571 ++ break;
1572 ++
1573 ++ if ((lis & 0xFFFF0000U) == 0x39600000U &&
1574 ++ (lwzu & 0xU) == 0xU &&
1575 ++ (b & 0xFC000003U) == 0x48000000U &&
1576 ++ bctr == 0x4E800420U)
1577 ++ {
1578 ++ unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1579 ++ unsigned long addr = b | 0xFC000000UL;
1580 ++
1581 ++ addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1582 ++ err = get_user(addis, (unsigned int *)addr);
1583 ++ err |= get_user(addi, (unsigned int *)(addr+4));
1584 ++ err |= get_user(rlwinm, (unsigned int *)(addr+8));
1585 ++ err |= get_user(add, (unsigned int *)(addr+12));
1586 ++ err |= get_user(li2, (unsigned int *)(addr+16));
1587 ++ err |= get_user(addis2, (unsigned int *)(addr+20));
1588 ++ err |= get_user(mtctr, (unsigned int *)(addr+24));
1589 ++ err |= get_user(li3, (unsigned int *)(addr+28));
1590 ++ err |= get_user(addis3, (unsigned int *)(addr+32));
1591 ++ err |= get_user(bctr, (unsigned int *)(addr+36));
1592 ++
1593 ++ if (err)
1594 ++ break;
1595 ++
1596 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1597 ++ (addi & 0xFFFF0000U) == 0x396B0000U &&
1598 ++ rlwinm == 0x556C083CU &&
1599 ++ add == 0x7D6C5A14U &&
1600 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1601 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1602 ++ mtctr == 0x7D8903A6U &&
1603 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1604 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1605 ++ bctr == 0x4E800420U)
1606 ++ {
1607 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1608 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1609 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1610 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1611 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1612 ++ regs->nip = regs->ctr;
1613 ++ return 4;
1614 ++ }
1615 ++ }
1616 ++ } while (0);
1617 ++#endif
1618 ++
1619 ++ do { /* PaX: unpatched PLT emulation #3 */
1620 ++ unsigned int li, b;
1621 ++
1622 ++ err = get_user(li, (unsigned int *)regs->nip);
1623 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1624 ++
1625 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1626 ++ unsigned int addis, lwz, mtctr, bctr;
1627 ++ unsigned long addr = b | 0xFC000000UL;
1628 ++
1629 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1630 ++ err = get_user(addis, (unsigned int *)addr);
1631 ++ err |= get_user(lwz, (unsigned int *)(addr+4));
1632 ++ err |= get_user(mtctr, (unsigned int *)(addr+8));
1633 ++ err |= get_user(bctr, (unsigned int *)(addr+12));
1634 ++
1635 ++ if (err)
1636 ++ break;
1637 ++
1638 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1639 ++ (lwz & 0xFFFF0000U) == 0x816B0000U &&
1640 ++ mtctr == 0x7D6903A6U &&
1641 ++ bctr == 0x4E800420U)
1642 ++ {
1643 ++ unsigned int r11;
1644 ++
1645 ++ addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1646 ++ addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1647 ++
1648 ++ err = get_user(r11, (unsigned int *)addr);
1649 ++ if (err)
1650 ++ break;
1651 ++
1652 ++ regs->gpr[PT_R11] = r11;
1653 ++ regs->ctr = r11;
1654 ++ regs->nip = r11;
1655 ++ return 4;
1656 ++ }
1657 ++ }
1658 ++ } while (0);
1659 ++#endif
1660 ++
1661 ++#ifdef CONFIG_PAX_EMUSIGRT
1662 ++ do { /* PaX: sigreturn emulation */
1663 ++ unsigned int li, sc;
1664 ++
1665 ++ err = get_user(li, (unsigned int *)regs->nip);
1666 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1667 ++
1668 ++ if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
1669 ++ struct vm_area_struct *vma;
1670 ++ unsigned long call_syscall;
1671 ++
1672 ++ down_read(&current->mm->mmap_sem);
1673 ++ call_syscall = current->mm->call_syscall;
1674 ++ up_read(&current->mm->mmap_sem);
1675 ++ if (likely(call_syscall))
1676 ++ goto emulate;
1677 ++
1678 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1679 ++
1680 ++ down_write(&current->mm->mmap_sem);
1681 ++ if (current->mm->call_syscall) {
1682 ++ call_syscall = current->mm->call_syscall;
1683 ++ up_write(&current->mm->mmap_sem);
1684 ++ if (vma)
1685 ++ kmem_cache_free(vm_area_cachep, vma);
1686 ++ goto emulate;
1687 ++ }
1688 ++
1689 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1690 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1691 ++ up_write(&current->mm->mmap_sem);
1692 ++ if (vma)
1693 ++ kmem_cache_free(vm_area_cachep, vma);
1694 ++ return 1;
1695 ++ }
1696 ++
1697 ++ if (pax_insert_vma(vma, call_syscall)) {
1698 ++ up_write(&current->mm->mmap_sem);
1699 ++ kmem_cache_free(vm_area_cachep, vma);
1700 ++ return 1;
1701 ++ }
1702 ++
1703 ++ current->mm->call_syscall = call_syscall;
1704 ++ up_write(&current->mm->mmap_sem);
1705 ++
1706 ++emulate:
1707 ++ regs->gpr[PT_R0] = __NR_sigreturn;
1708 ++ regs->nip = call_syscall;
1709 ++ return 5;
1710 ++ }
1711 ++ } while (0);
1712 ++
1713 ++ do { /* PaX: rt_sigreturn emulation */
1714 ++ unsigned int li, sc;
1715 ++
1716 ++ err = get_user(li, (unsigned int *)regs->nip);
1717 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1718 ++
1719 ++ if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
1720 ++ struct vm_area_struct *vma;
1721 ++ unsigned int call_syscall;
1722 ++
1723 ++ down_read(&current->mm->mmap_sem);
1724 ++ call_syscall = current->mm->call_syscall;
1725 ++ up_read(&current->mm->mmap_sem);
1726 ++ if (likely(call_syscall))
1727 ++ goto rt_emulate;
1728 ++
1729 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1730 ++
1731 ++ down_write(&current->mm->mmap_sem);
1732 ++ if (current->mm->call_syscall) {
1733 ++ call_syscall = current->mm->call_syscall;
1734 ++ up_write(&current->mm->mmap_sem);
1735 ++ if (vma)
1736 ++ kmem_cache_free(vm_area_cachep, vma);
1737 ++ goto rt_emulate;
1738 ++ }
1739 ++
1740 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1741 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1742 ++ up_write(&current->mm->mmap_sem);
1743 ++ if (vma)
1744 ++ kmem_cache_free(vm_area_cachep, vma);
1745 ++ return 1;
1746 ++ }
1747 ++
1748 ++ if (pax_insert_vma(vma, call_syscall)) {
1749 ++ up_write(&current->mm->mmap_sem);
1750 ++ kmem_cache_free(vm_area_cachep, vma);
1751 ++ return 1;
1752 ++ }
1753 ++
1754 ++ current->mm->call_syscall = call_syscall;
1755 ++ up_write(&current->mm->mmap_sem);
1756 ++
1757 ++rt_emulate:
1758 ++ regs->gpr[PT_R0] = __NR_rt_sigreturn;
1759 ++ regs->nip = call_syscall;
1760 ++ return 6;
1761 ++ }
1762 ++ } while (0);
1763 ++#endif
1764 ++
1765 ++ return 1;
1766 ++}
1767 ++
1768 ++void pax_report_insns(void *pc, void *sp)
1769 ++{
1770 ++ unsigned long i;
1771 ++
1772 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1773 ++ for (i = 0; i < 5; i++) {
1774 ++ unsigned int c;
1775 ++ if (get_user(c, (unsigned int *)pc+i))
1776 ++ printk(KERN_CONT "???????? ");
1777 ++ else
1778 ++ printk(KERN_CONT "%08x ", c);
1779 ++ }
1780 ++ printk("\n");
1781 ++}
1782 ++#endif
1783 ++
1784 + /*
1785 + * Check whether the instruction at regs->nip is a store using
1786 + * an update addressing form which will update r1.
1787 +@@ -132,7 +493,7 @@ int __kprobes do_page_fault(struct pt_re
1788 + * indicate errors in DSISR but can validly be set in SRR1.
1789 + */
1790 + if (trap == 0x400)
1791 +- error_code &= 0x48200000;
1792 ++ error_code &= 0x58200000;
1793 + else
1794 + is_write = error_code & DSISR_ISSTORE;
1795 + #else
1796 +@@ -331,6 +692,37 @@ bad_area:
1797 + bad_area_nosemaphore:
1798 + /* User mode accesses cause a SIGSEGV */
1799 + if (user_mode(regs)) {
1800 ++
1801 ++#ifdef CONFIG_PAX_PAGEEXEC
1802 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1803 ++#ifdef CONFIG_PPC64
1804 ++ if (is_exec && (error_code & DSISR_PROTFAULT)) {
1805 ++#else
1806 ++ if (is_exec && regs->nip == address) {
1807 ++#endif
1808 ++ switch (pax_handle_fetch_fault(regs)) {
1809 ++
1810 ++#ifdef CONFIG_PAX_EMUPLT
1811 ++ case 2:
1812 ++ case 3:
1813 ++ case 4:
1814 ++ return 0;
1815 ++#endif
1816 ++
1817 ++#ifdef CONFIG_PAX_EMUSIGRT
1818 ++ case 5:
1819 ++ case 6:
1820 ++ return 0;
1821 ++#endif
1822 ++
1823 ++ }
1824 ++
1825 ++ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
1826 ++ do_group_exit(SIGKILL);
1827 ++ }
1828 ++ }
1829 ++#endif
1830 ++
1831 + _exception(SIGSEGV, regs, code, address);
1832 + return 0;
1833 + }
1834 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/mmap.c linux-2.6.27.10/arch/powerpc/mm/mmap.c
1835 +--- linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
1836 ++++ linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
1837 +@@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str
1838 + */
1839 + if (mmap_is_legacy()) {
1840 + mm->mmap_base = TASK_UNMAPPED_BASE;
1841 ++
1842 ++#ifdef CONFIG_PAX_RANDMMAP
1843 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1844 ++ mm->mmap_base += mm->delta_mmap;
1845 ++#endif
1846 ++
1847 + mm->get_unmapped_area = arch_get_unmapped_area;
1848 + mm->unmap_area = arch_unmap_area;
1849 + } else {
1850 + mm->mmap_base = mmap_base();
1851 ++
1852 ++#ifdef CONFIG_PAX_RANDMMAP
1853 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1854 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1855 ++#endif
1856 ++
1857 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1858 + mm->unmap_area = arch_unmap_area_topdown;
1859 + }
1860 +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
1861 +--- linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1862 ++++ linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1863 +@@ -16,6 +16,7 @@ enum km_type {
1864 + KM_IRQ1,
1865 + KM_SOFTIRQ0,
1866 + KM_SOFTIRQ1,
1867 ++ KM_CLEARPAGE,
1868 + KM_TYPE_NR
1869 + };
1870 +
1871 +diff -urNp linux-2.6.27.10/arch/s390/kernel/module.c linux-2.6.27.10/arch/s390/kernel/module.c
1872 +--- linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
1873 ++++ linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
1874 +@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
1875 +
1876 + /* Increase core size by size of got & plt and set start
1877 + offsets for got and plt. */
1878 +- me->core_size = ALIGN(me->core_size, 4);
1879 +- me->arch.got_offset = me->core_size;
1880 +- me->core_size += me->arch.got_size;
1881 +- me->arch.plt_offset = me->core_size;
1882 +- me->core_size += me->arch.plt_size;
1883 ++ me->core_size_rw = ALIGN(me->core_size_rw, 4);
1884 ++ me->arch.got_offset = me->core_size_rw;
1885 ++ me->core_size_rw += me->arch.got_size;
1886 ++ me->arch.plt_offset = me->core_size_rx;
1887 ++ me->core_size_rx += me->arch.plt_size;
1888 + return 0;
1889 + }
1890 +
1891 +@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1892 + if (info->got_initialized == 0) {
1893 + Elf_Addr *gotent;
1894 +
1895 +- gotent = me->module_core + me->arch.got_offset +
1896 ++ gotent = me->module_core_rw + me->arch.got_offset +
1897 + info->got_offset;
1898 + *gotent = val;
1899 + info->got_initialized = 1;
1900 +@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1901 + else if (r_type == R_390_GOTENT ||
1902 + r_type == R_390_GOTPLTENT)
1903 + *(unsigned int *) loc =
1904 +- (val + (Elf_Addr) me->module_core - loc) >> 1;
1905 ++ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
1906 + else if (r_type == R_390_GOT64 ||
1907 + r_type == R_390_GOTPLT64)
1908 + *(unsigned long *) loc = val;
1909 +@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1910 + case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
1911 + if (info->plt_initialized == 0) {
1912 + unsigned int *ip;
1913 +- ip = me->module_core + me->arch.plt_offset +
1914 ++ ip = me->module_core_rx + me->arch.plt_offset +
1915 + info->plt_offset;
1916 + #ifndef CONFIG_64BIT
1917 + ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
1918 +@@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1919 + val = me->arch.plt_offset - me->arch.got_offset +
1920 + info->plt_offset + rela->r_addend;
1921 + else
1922 +- val = (Elf_Addr) me->module_core +
1923 ++ val = (Elf_Addr) me->module_core_rx +
1924 + me->arch.plt_offset + info->plt_offset +
1925 + rela->r_addend - loc;
1926 + if (r_type == R_390_PLT16DBL)
1927 +@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1928 + case R_390_GOTOFF32: /* 32 bit offset to GOT. */
1929 + case R_390_GOTOFF64: /* 64 bit offset to GOT. */
1930 + val = val + rela->r_addend -
1931 +- ((Elf_Addr) me->module_core + me->arch.got_offset);
1932 ++ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
1933 + if (r_type == R_390_GOTOFF16)
1934 + *(unsigned short *) loc = val;
1935 + else if (r_type == R_390_GOTOFF32)
1936 +@@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1937 + break;
1938 + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
1939 + case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
1940 +- val = (Elf_Addr) me->module_core + me->arch.got_offset +
1941 ++ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
1942 + rela->r_addend - loc;
1943 + if (r_type == R_390_GOTPC)
1944 + *(unsigned int *) loc = val;
1945 +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
1946 +--- linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1947 ++++ linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1948 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
1949 + D(10) KM_IRQ1,
1950 + D(11) KM_SOFTIRQ0,
1951 + D(12) KM_SOFTIRQ1,
1952 +-D(13) KM_TYPE_NR
1953 ++D(13) KM_CLEARPAGE,
1954 ++D(14) KM_TYPE_NR
1955 + };
1956 +
1957 + #undef D
1958 +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
1959 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-07 12:55:34.000000000 -0500
1960 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-18 03:39:50.000000000 -0500
1961 +@@ -119,6 +119,13 @@ typedef struct {
1962 +
1963 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
1964 +
1965 ++#ifdef CONFIG_PAX_ASLR
1966 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
1967 ++
1968 ++#define PAX_DELTA_MMAP_LEN 16
1969 ++#define PAX_DELTA_STACK_LEN 16
1970 ++#endif
1971 ++
1972 + /* This yields a mask that user programs can use to figure out what
1973 + instruction set this cpu supports. This can NOT be done in userspace
1974 + on Sparc. */
1975 +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
1976 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-07 12:55:34.000000000 -0500
1977 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-18 03:39:50.000000000 -0500
1978 +@@ -163,6 +163,12 @@ typedef struct {
1979 + #define ELF_ET_DYN_BASE 0x0000010000000000UL
1980 + #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
1981 +
1982 ++#ifdef CONFIG_PAX_ASLR
1983 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
1984 ++
1985 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 )
1986 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 )
1987 ++#endif
1988 +
1989 + /* This yields a mask that user programs can use to figure out what
1990 + instruction set this cpu supports. */
1991 +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
1992 +--- linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1993 ++++ linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1994 +@@ -19,6 +19,7 @@ enum km_type {
1995 + KM_IRQ1,
1996 + KM_SOFTIRQ0,
1997 + KM_SOFTIRQ1,
1998 ++ KM_CLEARPAGE,
1999 + KM_TYPE_NR
2000 + };
2001 +
2002 +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
2003 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
2004 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-18 03:39:50.000000000 -0500
2005 +@@ -47,6 +47,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
2006 + BTFIXUPDEF_INT(page_none)
2007 + BTFIXUPDEF_INT(page_copy)
2008 + BTFIXUPDEF_INT(page_readonly)
2009 ++
2010 ++#ifdef CONFIG_PAX_PAGEEXEC
2011 ++BTFIXUPDEF_INT(page_shared_noexec)
2012 ++BTFIXUPDEF_INT(page_copy_noexec)
2013 ++BTFIXUPDEF_INT(page_readonly_noexec)
2014 ++#endif
2015 ++
2016 + BTFIXUPDEF_INT(page_kernel)
2017 +
2018 + #define PMD_SHIFT SUN4C_PMD_SHIFT
2019 +@@ -68,6 +75,16 @@ extern pgprot_t PAGE_SHARED;
2020 + #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
2021 + #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
2022 +
2023 ++#ifdef CONFIG_PAX_PAGEEXEC
2024 ++extern pgprot_t PAGE_SHARED_NOEXEC;
2025 ++# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
2026 ++# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
2027 ++#else
2028 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2029 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2030 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2031 ++#endif
2032 ++
2033 + extern unsigned long page_kernel;
2034 +
2035 + #ifdef MODULE
2036 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h
2037 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-07 12:55:34.000000000 -0500
2038 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-18 03:39:50.000000000 -0500
2039 +@@ -115,6 +115,13 @@
2040 + SRMMU_EXEC | SRMMU_REF)
2041 + #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
2042 + SRMMU_EXEC | SRMMU_REF)
2043 ++
2044 ++#ifdef CONFIG_PAX_PAGEEXEC
2045 ++#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
2046 ++#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2047 ++#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2048 ++#endif
2049 ++
2050 + #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
2051 + SRMMU_DIRTY | SRMMU_REF)
2052 +
2053 +diff -urNp linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c
2054 +--- linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2055 ++++ linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2056 +@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
2057 + if (ARCH_SUN4C_SUN4 && len > 0x20000000)
2058 + return -ENOMEM;
2059 + if (!addr)
2060 +- addr = TASK_UNMAPPED_BASE;
2061 ++ addr = current->mm->mmap_base;
2062 +
2063 + if (flags & MAP_SHARED)
2064 + addr = COLOUR_ALIGN(addr);
2065 +diff -urNp linux-2.6.27.10/arch/sparc/Makefile linux-2.6.27.10/arch/sparc/Makefile
2066 +--- linux-2.6.27.10/arch/sparc/Makefile 2008-11-07 12:55:34.000000000 -0500
2067 ++++ linux-2.6.27.10/arch/sparc/Makefile 2008-11-18 03:38:43.000000000 -0500
2068 +@@ -37,7 +37,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
2069 + # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
2070 + INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
2071 + CORE_Y := $(core-y)
2072 +-CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
2073 ++CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
2074 + CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
2075 + DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
2076 + NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
2077 +diff -urNp linux-2.6.27.10/arch/sparc/mm/fault.c linux-2.6.27.10/arch/sparc/mm/fault.c
2078 +--- linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2079 ++++ linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2080 +@@ -21,6 +21,9 @@
2081 + #include <linux/interrupt.h>
2082 + #include <linux/module.h>
2083 + #include <linux/kdebug.h>
2084 ++#include <linux/slab.h>
2085 ++#include <linux/pagemap.h>
2086 ++#include <linux/compiler.h>
2087 +
2088 + #include <asm/system.h>
2089 + #include <asm/page.h>
2090 +@@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str
2091 + return safe_compute_effective_address(regs, insn);
2092 + }
2093 +
2094 ++#ifdef CONFIG_PAX_PAGEEXEC
2095 ++void pax_emuplt_close(struct vm_area_struct *vma)
2096 ++{
2097 ++ vma->vm_mm->call_dl_resolve = 0UL;
2098 ++}
2099 ++
2100 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2101 ++{
2102 ++ unsigned int *kaddr;
2103 ++
2104 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2105 ++ if (!vmf->page)
2106 ++ return VM_FAULT_OOM;
2107 ++
2108 ++ kaddr = kmap(vmf->page);
2109 ++ memset(kaddr, 0, PAGE_SIZE);
2110 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2111 ++ flush_dcache_page(vmf->page);
2112 ++ kunmap(vmf->page);
2113 ++ return VM_FAULT_MAJOR;
2114 ++}
2115 ++
2116 ++static struct vm_operations_struct pax_vm_ops = {
2117 ++ .close = pax_emuplt_close,
2118 ++ .fault = pax_emuplt_fault
2119 ++};
2120 ++
2121 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2122 ++{
2123 ++ int ret;
2124 ++
2125 ++ vma->vm_mm = current->mm;
2126 ++ vma->vm_start = addr;
2127 ++ vma->vm_end = addr + PAGE_SIZE;
2128 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2129 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2130 ++ vma->vm_ops = &pax_vm_ops;
2131 ++
2132 ++ ret = insert_vm_struct(current->mm, vma);
2133 ++ if (ret)
2134 ++ return ret;
2135 ++
2136 ++ ++current->mm->total_vm;
2137 ++ return 0;
2138 ++}
2139 ++
2140 ++/*
2141 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
2142 ++ *
2143 ++ * returns 1 when task should be killed
2144 ++ * 2 when patched PLT trampoline was detected
2145 ++ * 3 when unpatched PLT trampoline was detected
2146 ++ */
2147 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2148 ++{
2149 ++
2150 ++#ifdef CONFIG_PAX_EMUPLT
2151 ++ int err;
2152 ++
2153 ++ do { /* PaX: patched PLT emulation #1 */
2154 ++ unsigned int sethi1, sethi2, jmpl;
2155 ++
2156 ++ err = get_user(sethi1, (unsigned int *)regs->pc);
2157 ++ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
2158 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
2159 ++
2160 ++ if (err)
2161 ++ break;
2162 ++
2163 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2164 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2165 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2166 ++ {
2167 ++ unsigned int addr;
2168 ++
2169 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2170 ++ addr = regs->u_regs[UREG_G1];
2171 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2172 ++ regs->pc = addr;
2173 ++ regs->npc = addr+4;
2174 ++ return 2;
2175 ++ }
2176 ++ } while (0);
2177 ++
2178 ++ { /* PaX: patched PLT emulation #2 */
2179 ++ unsigned int ba;
2180 ++
2181 ++ err = get_user(ba, (unsigned int *)regs->pc);
2182 ++
2183 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2184 ++ unsigned int addr;
2185 ++
2186 ++ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2187 ++ regs->pc = addr;
2188 ++ regs->npc = addr+4;
2189 ++ return 2;
2190 ++ }
2191 ++ }
2192 ++
2193 ++ do { /* PaX: patched PLT emulation #3 */
2194 ++ unsigned int sethi, jmpl, nop;
2195 ++
2196 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2197 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
2198 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2199 ++
2200 ++ if (err)
2201 ++ break;
2202 ++
2203 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2204 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2205 ++ nop == 0x01000000U)
2206 ++ {
2207 ++ unsigned int addr;
2208 ++
2209 ++ addr = (sethi & 0x003FFFFFU) << 10;
2210 ++ regs->u_regs[UREG_G1] = addr;
2211 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2212 ++ regs->pc = addr;
2213 ++ regs->npc = addr+4;
2214 ++ return 2;
2215 ++ }
2216 ++ } while (0);
2217 ++
2218 ++ do { /* PaX: unpatched PLT emulation step 1 */
2219 ++ unsigned int sethi, ba, nop;
2220 ++
2221 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2222 ++ err |= get_user(ba, (unsigned int *)(regs->pc+4));
2223 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2224 ++
2225 ++ if (err)
2226 ++ break;
2227 ++
2228 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2229 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2230 ++ nop == 0x01000000U)
2231 ++ {
2232 ++ unsigned int addr, save, call;
2233 ++
2234 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2235 ++ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2236 ++ else
2237 ++ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
2238 ++
2239 ++ err = get_user(save, (unsigned int *)addr);
2240 ++ err |= get_user(call, (unsigned int *)(addr+4));
2241 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2242 ++ if (err)
2243 ++ break;
2244 ++
2245 ++ if (save == 0x9DE3BFA8U &&
2246 ++ (call & 0xC0000000U) == 0x40000000U &&
2247 ++ nop == 0x01000000U)
2248 ++ {
2249 ++ struct vm_area_struct *vma;
2250 ++ unsigned long call_dl_resolve;
2251 ++
2252 ++ down_read(&current->mm->mmap_sem);
2253 ++ call_dl_resolve = current->mm->call_dl_resolve;
2254 ++ up_read(&current->mm->mmap_sem);
2255 ++ if (likely(call_dl_resolve))
2256 ++ goto emulate;
2257 ++
2258 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2259 ++
2260 ++ down_write(&current->mm->mmap_sem);
2261 ++ if (current->mm->call_dl_resolve) {
2262 ++ call_dl_resolve = current->mm->call_dl_resolve;
2263 ++ up_write(&current->mm->mmap_sem);
2264 ++ if (vma)
2265 ++ kmem_cache_free(vm_area_cachep, vma);
2266 ++ goto emulate;
2267 ++ }
2268 ++
2269 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2270 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2271 ++ up_write(&current->mm->mmap_sem);
2272 ++ if (vma)
2273 ++ kmem_cache_free(vm_area_cachep, vma);
2274 ++ return 1;
2275 ++ }
2276 ++
2277 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2278 ++ up_write(&current->mm->mmap_sem);
2279 ++ kmem_cache_free(vm_area_cachep, vma);
2280 ++ return 1;
2281 ++ }
2282 ++
2283 ++ current->mm->call_dl_resolve = call_dl_resolve;
2284 ++ up_write(&current->mm->mmap_sem);
2285 ++
2286 ++emulate:
2287 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2288 ++ regs->pc = call_dl_resolve;
2289 ++ regs->npc = addr+4;
2290 ++ return 3;
2291 ++ }
2292 ++ }
2293 ++ } while (0);
2294 ++
2295 ++ do { /* PaX: unpatched PLT emulation step 2 */
2296 ++ unsigned int save, call, nop;
2297 ++
2298 ++ err = get_user(save, (unsigned int *)(regs->pc-4));
2299 ++ err |= get_user(call, (unsigned int *)regs->pc);
2300 ++ err |= get_user(nop, (unsigned int *)(regs->pc+4));
2301 ++ if (err)
2302 ++ break;
2303 ++
2304 ++ if (save == 0x9DE3BFA8U &&
2305 ++ (call & 0xC0000000U) == 0x40000000U &&
2306 ++ nop == 0x01000000U)
2307 ++ {
2308 ++ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
2309 ++
2310 ++ regs->u_regs[UREG_RETPC] = regs->pc;
2311 ++ regs->pc = dl_resolve;
2312 ++ regs->npc = dl_resolve+4;
2313 ++ return 3;
2314 ++ }
2315 ++ } while (0);
2316 ++#endif
2317 ++
2318 ++ return 1;
2319 ++}
2320 ++
2321 ++void pax_report_insns(void *pc, void *sp)
2322 ++{
2323 ++ unsigned long i;
2324 ++
2325 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2326 ++ for (i = 0; i < 5; i++) {
2327 ++ unsigned int c;
2328 ++ if (get_user(c, (unsigned int *)pc+i))
2329 ++ printk(KERN_CONT "???????? ");
2330 ++ else
2331 ++ printk(KERN_CONT "%08x ", c);
2332 ++ }
2333 ++ printk("\n");
2334 ++}
2335 ++#endif
2336 ++
2337 + asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
2338 + unsigned long address)
2339 + {
2340 +@@ -231,6 +477,24 @@ good_area:
2341 + if(!(vma->vm_flags & VM_WRITE))
2342 + goto bad_area;
2343 + } else {
2344 ++
2345 ++#ifdef CONFIG_PAX_PAGEEXEC
2346 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
2347 ++ up_read(&mm->mmap_sem);
2348 ++ switch (pax_handle_fetch_fault(regs)) {
2349 ++
2350 ++#ifdef CONFIG_PAX_EMUPLT
2351 ++ case 2:
2352 ++ case 3:
2353 ++ return;
2354 ++#endif
2355 ++
2356 ++ }
2357 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
2358 ++ do_group_exit(SIGKILL);
2359 ++ }
2360 ++#endif
2361 ++
2362 + /* Allow reads even for write-only mappings */
2363 + if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
2364 + goto bad_area;
2365 +diff -urNp linux-2.6.27.10/arch/sparc/mm/init.c linux-2.6.27.10/arch/sparc/mm/init.c
2366 +--- linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-07 12:55:34.000000000 -0500
2367 ++++ linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-18 03:38:43.000000000 -0500
2368 +@@ -312,6 +312,9 @@ extern void device_scan(void);
2369 + pgprot_t PAGE_SHARED __read_mostly;
2370 + EXPORT_SYMBOL(PAGE_SHARED);
2371 +
2372 ++pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
2373 ++EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
2374 ++
2375 + void __init paging_init(void)
2376 + {
2377 + switch(sparc_cpu_model) {
2378 +@@ -337,17 +340,17 @@ void __init paging_init(void)
2379 +
2380 + /* Initialize the protection map with non-constant, MMU dependent values. */
2381 + protection_map[0] = PAGE_NONE;
2382 +- protection_map[1] = PAGE_READONLY;
2383 +- protection_map[2] = PAGE_COPY;
2384 +- protection_map[3] = PAGE_COPY;
2385 ++ protection_map[1] = PAGE_READONLY_NOEXEC;
2386 ++ protection_map[2] = PAGE_COPY_NOEXEC;
2387 ++ protection_map[3] = PAGE_COPY_NOEXEC;
2388 + protection_map[4] = PAGE_READONLY;
2389 + protection_map[5] = PAGE_READONLY;
2390 + protection_map[6] = PAGE_COPY;
2391 + protection_map[7] = PAGE_COPY;
2392 + protection_map[8] = PAGE_NONE;
2393 +- protection_map[9] = PAGE_READONLY;
2394 +- protection_map[10] = PAGE_SHARED;
2395 +- protection_map[11] = PAGE_SHARED;
2396 ++ protection_map[9] = PAGE_READONLY_NOEXEC;
2397 ++ protection_map[10] = PAGE_SHARED_NOEXEC;
2398 ++ protection_map[11] = PAGE_SHARED_NOEXEC;
2399 + protection_map[12] = PAGE_READONLY;
2400 + protection_map[13] = PAGE_READONLY;
2401 + protection_map[14] = PAGE_SHARED;
2402 +diff -urNp linux-2.6.27.10/arch/sparc/mm/srmmu.c linux-2.6.27.10/arch/sparc/mm/srmmu.c
2403 +--- linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-07 12:55:34.000000000 -0500
2404 ++++ linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-18 03:38:43.000000000 -0500
2405 +@@ -2163,6 +2163,13 @@ void __init ld_mmu_srmmu(void)
2406 + PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
2407 + BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2408 + BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2409 ++
2410 ++#ifdef CONFIG_PAX_PAGEEXEC
2411 ++ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
2412 ++ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
2413 ++ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
2414 ++#endif
2415 ++
2416 + BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2417 + page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2418 +
2419 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/Makefile linux-2.6.27.10/arch/sparc64/kernel/Makefile
2420 +--- linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-07 12:55:34.000000000 -0500
2421 ++++ linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-18 03:38:43.000000000 -0500
2422 +@@ -3,7 +3,7 @@
2423 + #
2424 +
2425 + EXTRA_AFLAGS := -ansi
2426 +-EXTRA_CFLAGS := -Werror
2427 ++#EXTRA_CFLAGS := -Werror
2428 +
2429 + extra-y := head.o init_task.o vmlinux.lds
2430 +
2431 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c
2432 +--- linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2433 ++++ linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2434 +@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
2435 + /* We do not accept a shared mapping if it would violate
2436 + * cache aliasing constraints.
2437 + */
2438 +- if ((flags & MAP_SHARED) &&
2439 ++ if ((filp || (flags & MAP_SHARED)) &&
2440 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2441 + return -EINVAL;
2442 + return addr;
2443 +@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
2444 + if (filp || (flags & MAP_SHARED))
2445 + do_color_align = 1;
2446 +
2447 ++#ifdef CONFIG_PAX_RANDMMAP
2448 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
2449 ++#endif
2450 ++
2451 + if (addr) {
2452 + if (do_color_align)
2453 + addr = COLOUR_ALIGN(addr, pgoff);
2454 +@@ -152,9 +156,9 @@ unsigned long arch_get_unmapped_area(str
2455 + }
2456 +
2457 + if (len > mm->cached_hole_size) {
2458 +- start_addr = addr = mm->free_area_cache;
2459 ++ start_addr = addr = mm->free_area_cache;
2460 + } else {
2461 +- start_addr = addr = TASK_UNMAPPED_BASE;
2462 ++ start_addr = addr = mm->mmap_base;
2463 + mm->cached_hole_size = 0;
2464 + }
2465 +
2466 +@@ -174,8 +178,8 @@ full_search:
2467 + vma = find_vma(mm, VA_EXCLUDE_END);
2468 + }
2469 + if (unlikely(task_size < addr)) {
2470 +- if (start_addr != TASK_UNMAPPED_BASE) {
2471 +- start_addr = addr = TASK_UNMAPPED_BASE;
2472 ++ if (start_addr != mm->mmap_base) {
2473 ++ start_addr = addr = mm->mmap_base;
2474 + mm->cached_hole_size = 0;
2475 + goto full_search;
2476 + }
2477 +@@ -215,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
2478 + /* We do not accept a shared mapping if it would violate
2479 + * cache aliasing constraints.
2480 + */
2481 +- if ((flags & MAP_SHARED) &&
2482 ++ if ((filp || (flags & MAP_SHARED)) &&
2483 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2484 + return -EINVAL;
2485 + return addr;
2486 +@@ -378,6 +382,12 @@ void arch_pick_mmap_layout(struct mm_str
2487 + current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
2488 + sysctl_legacy_va_layout) {
2489 + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2490 ++
2491 ++#ifdef CONFIG_PAX_RANDMMAP
2492 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2493 ++ mm->mmap_base += mm->delta_mmap;
2494 ++#endif
2495 ++
2496 + mm->get_unmapped_area = arch_get_unmapped_area;
2497 + mm->unmap_area = arch_unmap_area;
2498 + } else {
2499 +@@ -392,6 +402,12 @@ void arch_pick_mmap_layout(struct mm_str
2500 + gap = (task_size / 6 * 5);
2501 +
2502 + mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
2503 ++
2504 ++#ifdef CONFIG_PAX_RANDMMAP
2505 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2506 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2507 ++#endif
2508 ++
2509 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2510 + mm->unmap_area = arch_unmap_area_topdown;
2511 + }
2512 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/fault.c linux-2.6.27.10/arch/sparc64/mm/fault.c
2513 +--- linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2514 ++++ linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2515 +@@ -19,6 +19,9 @@
2516 + #include <linux/interrupt.h>
2517 + #include <linux/kprobes.h>
2518 + #include <linux/kdebug.h>
2519 ++#include <linux/slab.h>
2520 ++#include <linux/pagemap.h>
2521 ++#include <linux/compiler.h>
2522 +
2523 + #include <asm/page.h>
2524 + #include <asm/pgtable.h>
2525 +@@ -261,6 +264,367 @@ cannot_handle:
2526 + unhandled_fault (address, current, regs);
2527 + }
2528 +
2529 ++#ifdef CONFIG_PAX_PAGEEXEC
2530 ++#ifdef CONFIG_PAX_EMUPLT
2531 ++static void pax_emuplt_close(struct vm_area_struct *vma)
2532 ++{
2533 ++ vma->vm_mm->call_dl_resolve = 0UL;
2534 ++}
2535 ++
2536 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2537 ++{
2538 ++ unsigned int *kaddr;
2539 ++
2540 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2541 ++ if (!vmf->page)
2542 ++ return VM_FAULT_OOM;
2543 ++
2544 ++ kaddr = kmap(vmf->page);
2545 ++ memset(kaddr, 0, PAGE_SIZE);
2546 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2547 ++ flush_dcache_page(vmf->page);
2548 ++ kunmap(vmf->page);
2549 ++ return VM_FAULT_MAJOR;
2550 ++}
2551 ++
2552 ++static struct vm_operations_struct pax_vm_ops = {
2553 ++ .close = pax_emuplt_close,
2554 ++ .fault = pax_emuplt_fault
2555 ++};
2556 ++
2557 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2558 ++{
2559 ++ int ret;
2560 ++
2561 ++ vma->vm_mm = current->mm;
2562 ++ vma->vm_start = addr;
2563 ++ vma->vm_end = addr + PAGE_SIZE;
2564 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2565 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2566 ++ vma->vm_ops = &pax_vm_ops;
2567 ++
2568 ++ ret = insert_vm_struct(current->mm, vma);
2569 ++ if (ret)
2570 ++ return ret;
2571 ++
2572 ++ ++current->mm->total_vm;
2573 ++ return 0;
2574 ++}
2575 ++#endif
2576 ++
2577 ++/*
2578 ++ * PaX: decide what to do with offenders (regs->tpc = fault address)
2579 ++ *
2580 ++ * returns 1 when task should be killed
2581 ++ * 2 when patched PLT trampoline was detected
2582 ++ * 3 when unpatched PLT trampoline was detected
2583 ++ */
2584 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2585 ++{
2586 ++
2587 ++#ifdef CONFIG_PAX_EMUPLT
2588 ++ int err;
2589 ++
2590 ++ do { /* PaX: patched PLT emulation #1 */
2591 ++ unsigned int sethi1, sethi2, jmpl;
2592 ++
2593 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2594 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2595 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
2596 ++
2597 ++ if (err)
2598 ++ break;
2599 ++
2600 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2601 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2602 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2603 ++ {
2604 ++ unsigned long addr;
2605 ++
2606 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2607 ++ addr = regs->u_regs[UREG_G1];
2608 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2609 ++ regs->tpc = addr;
2610 ++ regs->tnpc = addr+4;
2611 ++ return 2;
2612 ++ }
2613 ++ } while (0);
2614 ++
2615 ++ { /* PaX: patched PLT emulation #2 */
2616 ++ unsigned int ba;
2617 ++
2618 ++ err = get_user(ba, (unsigned int *)regs->tpc);
2619 ++
2620 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2621 ++ unsigned long addr;
2622 ++
2623 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2624 ++ regs->tpc = addr;
2625 ++ regs->tnpc = addr+4;
2626 ++ return 2;
2627 ++ }
2628 ++ }
2629 ++
2630 ++ do { /* PaX: patched PLT emulation #3 */
2631 ++ unsigned int sethi, jmpl, nop;
2632 ++
2633 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2634 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
2635 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2636 ++
2637 ++ if (err)
2638 ++ break;
2639 ++
2640 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2641 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2642 ++ nop == 0x01000000U)
2643 ++ {
2644 ++ unsigned long addr;
2645 ++
2646 ++ addr = (sethi & 0x003FFFFFU) << 10;
2647 ++ regs->u_regs[UREG_G1] = addr;
2648 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2649 ++ regs->tpc = addr;
2650 ++ regs->tnpc = addr+4;
2651 ++ return 2;
2652 ++ }
2653 ++ } while (0);
2654 ++
2655 ++ do { /* PaX: patched PLT emulation #4 */
2656 ++ unsigned int mov1, call, mov2;
2657 ++
2658 ++ err = get_user(mov1, (unsigned int *)regs->tpc);
2659 ++ err |= get_user(call, (unsigned int *)(regs->tpc+4));
2660 ++ err |= get_user(mov2, (unsigned int *)(regs->tpc+8));
2661 ++
2662 ++ if (err)
2663 ++ break;
2664 ++
2665 ++ if (mov1 == 0x8210000FU &&
2666 ++ (call & 0xC0000000U) == 0x40000000U &&
2667 ++ mov2 == 0x9E100001U)
2668 ++ {
2669 ++ unsigned long addr;
2670 ++
2671 ++ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
2672 ++ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2673 ++ regs->tpc = addr;
2674 ++ regs->tnpc = addr+4;
2675 ++ return 2;
2676 ++ }
2677 ++ } while (0);
2678 ++
2679 ++ do { /* PaX: patched PLT emulation #5 */
2680 ++ unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop;
2681 ++
2682 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2683 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2684 ++ err |= get_user(or1, (unsigned int *)(regs->tpc+8));
2685 ++ err |= get_user(or2, (unsigned int *)(regs->tpc+12));
2686 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+16));
2687 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
2688 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
2689 ++
2690 ++ if (err)
2691 ++ break;
2692 ++
2693 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2694 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2695 ++ (or1 & 0xFFFFE000U) == 0x82106000U &&
2696 ++ (or2 & 0xFFFFE000U) == 0x8A116000U &&
2697 ++ sllx == 0x83287020 &&
2698 ++ jmpl == 0x81C04005U &&
2699 ++ nop == 0x01000000U)
2700 ++ {
2701 ++ unsigned long addr;
2702 ++
2703 ++ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
2704 ++ regs->u_regs[UREG_G1] <<= 32;
2705 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
2706 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2707 ++ regs->tpc = addr;
2708 ++ regs->tnpc = addr+4;
2709 ++ return 2;
2710 ++ }
2711 ++ } while (0);
2712 ++
2713 ++ do { /* PaX: patched PLT emulation #6 */
2714 ++ unsigned int sethi1, sethi2, sllx, or, jmpl, nop;
2715 ++
2716 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2717 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2718 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+8));
2719 ++ err |= get_user(or, (unsigned int *)(regs->tpc+12));
2720 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+16));
2721 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+20));
2722 ++
2723 ++ if (err)
2724 ++ break;
2725 ++
2726 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2727 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2728 ++ sllx == 0x83287020 &&
2729 ++ (or & 0xFFFFE000U) == 0x8A116000U &&
2730 ++ jmpl == 0x81C04005U &&
2731 ++ nop == 0x01000000U)
2732 ++ {
2733 ++ unsigned long addr;
2734 ++
2735 ++ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
2736 ++ regs->u_regs[UREG_G1] <<= 32;
2737 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
2738 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2739 ++ regs->tpc = addr;
2740 ++ regs->tnpc = addr+4;
2741 ++ return 2;
2742 ++ }
2743 ++ } while (0);
2744 ++
2745 ++ do { /* PaX: patched PLT emulation #7 */
2746 ++ unsigned int sethi, ba, nop;
2747 ++
2748 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2749 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2750 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2751 ++
2752 ++ if (err)
2753 ++ break;
2754 ++
2755 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2756 ++ (ba & 0xFFF00000U) == 0x30600000U &&
2757 ++ nop == 0x01000000U)
2758 ++ {
2759 ++ unsigned long addr;
2760 ++
2761 ++ addr = (sethi & 0x003FFFFFU) << 10;
2762 ++ regs->u_regs[UREG_G1] = addr;
2763 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2764 ++ regs->tpc = addr;
2765 ++ regs->tnpc = addr+4;
2766 ++ return 2;
2767 ++ }
2768 ++ } while (0);
2769 ++
2770 ++ do { /* PaX: unpatched PLT emulation step 1 */
2771 ++ unsigned int sethi, ba, nop;
2772 ++
2773 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2774 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2775 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2776 ++
2777 ++ if (err)
2778 ++ break;
2779 ++
2780 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2781 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2782 ++ nop == 0x01000000U)
2783 ++ {
2784 ++ unsigned long addr;
2785 ++ unsigned int save, call;
2786 ++
2787 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2788 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2789 ++ else
2790 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2791 ++
2792 ++ err = get_user(save, (unsigned int *)addr);
2793 ++ err |= get_user(call, (unsigned int *)(addr+4));
2794 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2795 ++ if (err)
2796 ++ break;
2797 ++
2798 ++ if (save == 0x9DE3BFA8U &&
2799 ++ (call & 0xC0000000U) == 0x40000000U &&
2800 ++ nop == 0x01000000U)
2801 ++ {
2802 ++ struct vm_area_struct *vma;
2803 ++ unsigned long call_dl_resolve;
2804 ++
2805 ++ down_read(&current->mm->mmap_sem);
2806 ++ call_dl_resolve = current->mm->call_dl_resolve;
2807 ++ up_read(&current->mm->mmap_sem);
2808 ++ if (likely(call_dl_resolve))
2809 ++ goto emulate;
2810 ++
2811 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2812 ++
2813 ++ down_write(&current->mm->mmap_sem);
2814 ++ if (current->mm->call_dl_resolve) {
2815 ++ call_dl_resolve = current->mm->call_dl_resolve;
2816 ++ up_write(&current->mm->mmap_sem);
2817 ++ if (vma)
2818 ++ kmem_cache_free(vm_area_cachep, vma);
2819 ++ goto emulate;
2820 ++ }
2821 ++
2822 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2823 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2824 ++ up_write(&current->mm->mmap_sem);
2825 ++ if (vma)
2826 ++ kmem_cache_free(vm_area_cachep, vma);
2827 ++ return 1;
2828 ++ }
2829 ++
2830 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2831 ++ up_write(&current->mm->mmap_sem);
2832 ++ kmem_cache_free(vm_area_cachep, vma);
2833 ++ return 1;
2834 ++ }
2835 ++
2836 ++ current->mm->call_dl_resolve = call_dl_resolve;
2837 ++ up_write(&current->mm->mmap_sem);
2838 ++
2839 ++emulate:
2840 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2841 ++ regs->tpc = call_dl_resolve;
2842 ++ regs->tnpc = addr+4;
2843 ++ return 3;
2844 ++ }
2845 ++ }
2846 ++ } while (0);
2847 ++
2848 ++ do { /* PaX: unpatched PLT emulation step 2 */
2849 ++ unsigned int save, call, nop;
2850 ++
2851 ++ err = get_user(save, (unsigned int *)(regs->tpc-4));
2852 ++ err |= get_user(call, (unsigned int *)regs->tpc);
2853 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
2854 ++ if (err)
2855 ++ break;
2856 ++
2857 ++ if (save == 0x9DE3BFA8U &&
2858 ++ (call & 0xC0000000U) == 0x40000000U &&
2859 ++ nop == 0x01000000U)
2860 ++ {
2861 ++ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2862 ++
2863 ++ regs->u_regs[UREG_RETPC] = regs->tpc;
2864 ++ regs->tpc = dl_resolve;
2865 ++ regs->tnpc = dl_resolve+4;
2866 ++ return 3;
2867 ++ }
2868 ++ } while (0);
2869 ++#endif
2870 ++
2871 ++ return 1;
2872 ++}
2873 ++
2874 ++void pax_report_insns(void *pc, void *sp)
2875 ++{
2876 ++ unsigned long i;
2877 ++
2878 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2879 ++ for (i = 0; i < 5; i++) {
2880 ++ unsigned int c;
2881 ++ if (get_user(c, (unsigned int *)pc+i))
2882 ++ printk(KERN_CONT "???????? ");
2883 ++ else
2884 ++ printk(KERN_CONT "%08x ", c);
2885 ++ }
2886 ++ printk("\n");
2887 ++}
2888 ++#endif
2889 ++
2890 + asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
2891 + {
2892 + struct mm_struct *mm = current->mm;
2893 +@@ -302,8 +666,10 @@ asmlinkage void __kprobes do_sparc64_fau
2894 + goto intr_or_no_mm;
2895 +
2896 + if (test_thread_flag(TIF_32BIT)) {
2897 +- if (!(regs->tstate & TSTATE_PRIV))
2898 ++ if (!(regs->tstate & TSTATE_PRIV)) {
2899 + regs->tpc &= 0xffffffff;
2900 ++ regs->tnpc &= 0xffffffff;
2901 ++ }
2902 + address &= 0xffffffff;
2903 + }
2904 +
2905 +@@ -320,6 +686,29 @@ asmlinkage void __kprobes do_sparc64_fau
2906 + if (!vma)
2907 + goto bad_area;
2908 +
2909 ++#ifdef CONFIG_PAX_PAGEEXEC
2910 ++ /* PaX: detect ITLB misses on non-exec pages */
2911 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
2912 ++ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
2913 ++ {
2914 ++ if (address != regs->tpc)
2915 ++ goto good_area;
2916 ++
2917 ++ up_read(&mm->mmap_sem);
2918 ++ switch (pax_handle_fetch_fault(regs)) {
2919 ++
2920 ++#ifdef CONFIG_PAX_EMUPLT
2921 ++ case 2:
2922 ++ case 3:
2923 ++ return;
2924 ++#endif
2925 ++
2926 ++ }
2927 ++ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
2928 ++ do_group_exit(SIGKILL);
2929 ++ }
2930 ++#endif
2931 ++
2932 + /* Pure DTLB misses do not tell us whether the fault causing
2933 + * load/store/atomic was a write or not, it only says that there
2934 + * was no match. So in such a case we (carefully) read the
2935 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/Makefile linux-2.6.27.10/arch/sparc64/mm/Makefile
2936 +--- linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-07 12:55:34.000000000 -0500
2937 ++++ linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-18 03:38:43.000000000 -0500
2938 +@@ -2,7 +2,7 @@
2939 + #
2940 +
2941 + EXTRA_AFLAGS := -ansi
2942 +-EXTRA_CFLAGS := -Werror
2943 ++#EXTRA_CFLAGS := -Werror
2944 +
2945 + obj-y := ultra.o tlb.o tsb.o fault.o init.o generic.o
2946 +
2947 +diff -urNp linux-2.6.27.10/arch/um/sys-i386/syscalls.c linux-2.6.27.10/arch/um/sys-i386/syscalls.c
2948 +--- linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-07 12:55:34.000000000 -0500
2949 ++++ linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-18 03:38:43.000000000 -0500
2950 +@@ -10,6 +10,21 @@
2951 + #include "asm/uaccess.h"
2952 + #include "asm/unistd.h"
2953 +
2954 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
2955 ++{
2956 ++ unsigned long pax_task_size = TASK_SIZE;
2957 ++
2958 ++#ifdef CONFIG_PAX_SEGMEXEC
2959 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
2960 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
2961 ++#endif
2962 ++
2963 ++ if (len > pax_task_size || addr > pax_task_size - len)
2964 ++ return -EINVAL;
2965 ++
2966 ++ return 0;
2967 ++}
2968 ++
2969 + /*
2970 + * Perform the select(nd, in, out, ex, tv) and mmap() system
2971 + * calls. Linux/i386 didn't use to be able to handle more than
2972 +diff -urNp linux-2.6.27.10/arch/x86/boot/bitops.h linux-2.6.27.10/arch/x86/boot/bitops.h
2973 +--- linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-07 12:55:34.000000000 -0500
2974 ++++ linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-18 03:38:44.000000000 -0500
2975 +@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
2976 + u8 v;
2977 + const u32 *p = (const u32 *)addr;
2978 +
2979 +- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
2980 ++ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
2981 + return v;
2982 + }
2983 +
2984 +@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
2985 +
2986 + static inline void set_bit(int nr, void *addr)
2987 + {
2988 +- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
2989 ++ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
2990 + }
2991 +
2992 + #endif /* BOOT_BITOPS_H */
2993 +diff -urNp linux-2.6.27.10/arch/x86/boot/boot.h linux-2.6.27.10/arch/x86/boot/boot.h
2994 +--- linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-07 12:55:34.000000000 -0500
2995 ++++ linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-18 03:38:44.000000000 -0500
2996 +@@ -80,7 +80,7 @@ static inline void io_delay(void)
2997 + static inline u16 ds(void)
2998 + {
2999 + u16 seg;
3000 +- asm("movw %%ds,%0" : "=rm" (seg));
3001 ++ asm volatile("movw %%ds,%0" : "=rm" (seg));
3002 + return seg;
3003 + }
3004 +
3005 +@@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t
3006 + static inline int memcmp(const void *s1, const void *s2, size_t len)
3007 + {
3008 + u8 diff;
3009 +- asm("repe; cmpsb; setnz %0"
3010 ++ asm volatile("repe; cmpsb; setnz %0"
3011 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
3012 + return diff;
3013 + }
3014 +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
3015 +--- linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-07 12:55:34.000000000 -0500
3016 ++++ linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-18 03:38:44.000000000 -0500
3017 +@@ -70,7 +70,7 @@ startup_32:
3018 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
3019 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
3020 + #else
3021 +- movl $LOAD_PHYSICAL_ADDR, %ebx
3022 ++ movl $____LOAD_PHYSICAL_ADDR, %ebx
3023 + #endif
3024 +
3025 + /* Replace the compressed data size with the uncompressed size */
3026 +@@ -105,7 +105,7 @@ startup_32:
3027 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
3028 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
3029 + #else
3030 +- movl $LOAD_PHYSICAL_ADDR, %ebp
3031 ++ movl $____LOAD_PHYSICAL_ADDR, %ebp
3032 + #endif
3033 +
3034 + /*
3035 +@@ -159,16 +159,15 @@ relocated:
3036 + * and where it was actually loaded.
3037 + */
3038 + movl %ebp, %ebx
3039 +- subl $LOAD_PHYSICAL_ADDR, %ebx
3040 ++ subl $____LOAD_PHYSICAL_ADDR, %ebx
3041 + jz 2f /* Nothing to be done if loaded at compiled addr. */
3042 + /*
3043 + * Process relocations.
3044 + */
3045 +
3046 + 1: subl $4, %edi
3047 +- movl 0(%edi), %ecx
3048 +- testl %ecx, %ecx
3049 +- jz 2f
3050 ++ movl (%edi), %ecx
3051 ++ jecxz 2f
3052 + addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
3053 + jmp 1b
3054 + 2:
3055 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/misc.c linux-2.6.27.10/arch/x86/boot/compressed/misc.c
3056 +--- linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-07 12:55:34.000000000 -0500
3057 ++++ linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-18 03:38:44.000000000 -0500
3058 +@@ -371,7 +371,7 @@ static void parse_elf(void *output)
3059 + case PT_LOAD:
3060 + #ifdef CONFIG_RELOCATABLE
3061 + dest = output;
3062 +- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
3063 ++ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
3064 + #else
3065 + dest = (void *)(phdr->p_paddr);
3066 + #endif
3067 +@@ -423,7 +423,7 @@ asmlinkage void decompress_kernel(void *
3068 + if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))
3069 + error("Destination address too large");
3070 + #ifndef CONFIG_RELOCATABLE
3071 +- if ((u32)output != LOAD_PHYSICAL_ADDR)
3072 ++ if ((u32)output != ____LOAD_PHYSICAL_ADDR)
3073 + error("Wrong destination address");
3074 + #endif
3075 + #endif
3076 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/relocs.c linux-2.6.27.10/arch/x86/boot/compressed/relocs.c
3077 +--- linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-07 12:55:34.000000000 -0500
3078 ++++ linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-18 03:38:44.000000000 -0500
3079 +@@ -10,8 +10,11 @@
3080 + #define USE_BSD
3081 + #include <endian.h>
3082 +
3083 ++#include "../../../../include/linux/autoconf.h"
3084 ++
3085 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
3086 + static Elf32_Ehdr ehdr;
3087 ++static Elf32_Phdr *phdr;
3088 + static unsigned long reloc_count, reloc_idx;
3089 + static unsigned long *relocs;
3090 +
3091 +@@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp)
3092 + }
3093 + }
3094 +
3095 ++static void read_phdrs(FILE *fp)
3096 ++{
3097 ++ int i;
3098 ++
3099 ++ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
3100 ++ if (!phdr) {
3101 ++ die("Unable to allocate %d program headers\n",
3102 ++ ehdr.e_phnum);
3103 ++ }
3104 ++ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
3105 ++ die("Seek to %d failed: %s\n",
3106 ++ ehdr.e_phoff, strerror(errno));
3107 ++ }
3108 ++ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
3109 ++ die("Cannot read ELF program headers: %s\n",
3110 ++ strerror(errno));
3111 ++ }
3112 ++ for(i = 0; i < ehdr.e_phnum; i++) {
3113 ++ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
3114 ++ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
3115 ++ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
3116 ++ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
3117 ++ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
3118 ++ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
3119 ++ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
3120 ++ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
3121 ++ }
3122 ++
3123 ++}
3124 ++
3125 + static void read_shdrs(FILE *fp)
3126 + {
3127 + int i;
3128 +@@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp)
3129 + static void read_relocs(FILE *fp)
3130 + {
3131 + int i,j;
3132 ++ uint32_t base;
3133 ++
3134 + for (i = 0; i < ehdr.e_shnum; i++) {
3135 + struct section *sec = &secs[i];
3136 + if (sec->shdr.sh_type != SHT_REL) {
3137 +@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
3138 + die("Cannot read symbol table: %s\n",
3139 + strerror(errno));
3140 + }
3141 ++ base = 0;
3142 ++ for (j = 0; j < ehdr.e_phnum; j++) {
3143 ++ if (phdr[j].p_type != PT_LOAD )
3144 ++ continue;
3145 ++ 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)
3146 ++ continue;
3147 ++ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
3148 ++ break;
3149 ++ }
3150 + for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
3151 + Elf32_Rel *rel = &sec->reltab[j];
3152 +- rel->r_offset = elf32_to_cpu(rel->r_offset);
3153 ++ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
3154 + rel->r_info = elf32_to_cpu(rel->r_info);
3155 + }
3156 + }
3157 +@@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El
3158 + if (sym->st_shndx == SHN_ABS) {
3159 + continue;
3160 + }
3161 ++ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
3162 ++ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10))
3163 ++ continue;
3164 ++#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
3165 ++ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
3166 ++ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
3167 ++ continue;
3168 ++ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
3169 ++ continue;
3170 ++ if (!strcmp(sec_name(sym->st_shndx), ".text.head")) {
3171 ++ if (strcmp(sym_name(sym_strtab, sym), "__init_end") &&
3172 ++ strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET"))
3173 ++ continue;
3174 ++ }
3175 ++ if (!strcmp(sec_name(sym->st_shndx), ".text"))
3176 ++ continue;
3177 ++#endif
3178 + if (r_type == R_386_PC32) {
3179 + /* PC relative relocations don't need to be adjusted */
3180 + }
3181 +@@ -631,6 +692,7 @@ int main(int argc, char **argv)
3182 + fname, strerror(errno));
3183 + }
3184 + read_ehdr(fp);
3185 ++ read_phdrs(fp);
3186 + read_shdrs(fp);
3187 + read_strtabs(fp);
3188 + read_symtabs(fp);
3189 +diff -urNp linux-2.6.27.10/arch/x86/boot/cpucheck.c linux-2.6.27.10/arch/x86/boot/cpucheck.c
3190 +--- linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-07 12:55:34.000000000 -0500
3191 ++++ linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-18 03:38:44.000000000 -0500
3192 +@@ -74,7 +74,7 @@ static int has_fpu(void)
3193 + u16 fcw = -1, fsw = -1;
3194 + u32 cr0;
3195 +
3196 +- asm("movl %%cr0,%0" : "=r" (cr0));
3197 ++ asm volatile("movl %%cr0,%0" : "=r" (cr0));
3198 + if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
3199 + cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
3200 + asm volatile("movl %0,%%cr0" : : "r" (cr0));
3201 +@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
3202 + {
3203 + u32 f0, f1;
3204 +
3205 +- asm("pushfl ; "
3206 ++ asm volatile("pushfl ; "
3207 + "pushfl ; "
3208 + "popl %0 ; "
3209 + "movl %0,%1 ; "
3210 +@@ -115,7 +115,7 @@ static void get_flags(void)
3211 + set_bit(X86_FEATURE_FPU, cpu.flags);
3212 +
3213 + if (has_eflag(X86_EFLAGS_ID)) {
3214 +- asm("cpuid"
3215 ++ asm volatile("cpuid"
3216 + : "=a" (max_intel_level),
3217 + "=b" (cpu_vendor[0]),
3218 + "=d" (cpu_vendor[1]),
3219 +@@ -124,7 +124,7 @@ static void get_flags(void)
3220 +
3221 + if (max_intel_level >= 0x00000001 &&
3222 + max_intel_level <= 0x0000ffff) {
3223 +- asm("cpuid"
3224 ++ asm volatile("cpuid"
3225 + : "=a" (tfms),
3226 + "=c" (cpu.flags[4]),
3227 + "=d" (cpu.flags[0])
3228 +@@ -136,7 +136,7 @@ static void get_flags(void)
3229 + cpu.model += ((tfms >> 16) & 0xf) << 4;
3230 + }
3231 +
3232 +- asm("cpuid"
3233 ++ asm volatile("cpuid"
3234 + : "=a" (max_amd_level)
3235 + : "a" (0x80000000)
3236 + : "ebx", "ecx", "edx");
3237 +@@ -144,7 +144,7 @@ static void get_flags(void)
3238 + if (max_amd_level >= 0x80000001 &&
3239 + max_amd_level <= 0x8000ffff) {
3240 + u32 eax = 0x80000001;
3241 +- asm("cpuid"
3242 ++ asm volatile("cpuid"
3243 + : "+a" (eax),
3244 + "=c" (cpu.flags[6]),
3245 + "=d" (cpu.flags[1])
3246 +@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3247 + u32 ecx = MSR_K7_HWCR;
3248 + u32 eax, edx;
3249 +
3250 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3251 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3252 + eax &= ~(1 << 15);
3253 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3254 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3255 +
3256 + get_flags(); /* Make sure it really did something */
3257 + err = check_flags();
3258 +@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3259 + u32 ecx = MSR_VIA_FCR;
3260 + u32 eax, edx;
3261 +
3262 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3263 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3264 + eax |= (1<<1)|(1<<7);
3265 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3266 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3267 +
3268 + set_bit(X86_FEATURE_CX8, cpu.flags);
3269 + err = check_flags();
3270 +@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
3271 + u32 eax, edx;
3272 + u32 level = 1;
3273 +
3274 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3275 +- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3276 +- asm("cpuid"
3277 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3278 ++ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3279 ++ asm volatile("cpuid"
3280 + : "+a" (level), "=d" (cpu.flags[0])
3281 + : : "ecx", "ebx");
3282 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3283 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3284 +
3285 + err = check_flags();
3286 + }
3287 +diff -urNp linux-2.6.27.10/arch/x86/boot/edd.c linux-2.6.27.10/arch/x86/boot/edd.c
3288 +--- linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-07 12:55:34.000000000 -0500
3289 ++++ linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-18 03:38:44.000000000 -0500
3290 +@@ -76,7 +76,7 @@ static int get_edd_info(u8 devno, struct
3291 + ax = 0x4100;
3292 + bx = EDDMAGIC1;
3293 + dx = devno;
3294 +- asm("pushfl; stc; int $0x13; setc %%al; popfl"
3295 ++ asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
3296 + : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
3297 + : : "esi", "edi");
3298 +
3299 +@@ -95,7 +95,7 @@ static int get_edd_info(u8 devno, struct
3300 + ei->params.length = sizeof(ei->params);
3301 + ax = 0x4800;
3302 + dx = devno;
3303 +- asm("pushfl; int $0x13; popfl"
3304 ++ asm volatile("pushfl; int $0x13; popfl"
3305 + : "+a" (ax), "+d" (dx), "=m" (ei->params)
3306 + : "S" (&ei->params)
3307 + : "ebx", "ecx", "edi");
3308 +@@ -106,7 +106,7 @@ static int get_edd_info(u8 devno, struct
3309 + ax = 0x0800;
3310 + dx = devno;
3311 + di = 0;
3312 +- asm("pushw %%es; "
3313 ++ asm volatile("pushw %%es; "
3314 + "movw %%di,%%es; "
3315 + "pushfl; stc; int $0x13; setc %%al; popfl; "
3316 + "popw %%es"
3317 +diff -urNp linux-2.6.27.10/arch/x86/boot/main.c linux-2.6.27.10/arch/x86/boot/main.c
3318 +--- linux-2.6.27.10/arch/x86/boot/main.c 2008-11-07 12:55:34.000000000 -0500
3319 ++++ linux-2.6.27.10/arch/x86/boot/main.c 2008-11-18 03:38:44.000000000 -0500
3320 +@@ -78,7 +78,7 @@ static void query_ist(void)
3321 + if (cpu.level < 6)
3322 + return;
3323 +
3324 +- asm("int $0x15"
3325 ++ asm volatile("int $0x15"
3326 + : "=a" (boot_params.ist_info.signature),
3327 + "=b" (boot_params.ist_info.command),
3328 + "=c" (boot_params.ist_info.event),
3329 +diff -urNp linux-2.6.27.10/arch/x86/boot/mca.c linux-2.6.27.10/arch/x86/boot/mca.c
3330 +--- linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-07 12:55:34.000000000 -0500
3331 ++++ linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-18 03:38:44.000000000 -0500
3332 +@@ -19,7 +19,7 @@ int query_mca(void)
3333 + u8 err;
3334 + u16 es, bx, len;
3335 +
3336 +- asm("pushw %%es ; "
3337 ++ asm volatile("pushw %%es ; "
3338 + "int $0x15 ; "
3339 + "setc %0 ; "
3340 + "movw %%es, %1 ; "
3341 +diff -urNp linux-2.6.27.10/arch/x86/boot/memory.c linux-2.6.27.10/arch/x86/boot/memory.c
3342 +--- linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-07 12:55:34.000000000 -0500
3343 ++++ linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-18 03:38:44.000000000 -0500
3344 +@@ -30,7 +30,7 @@ static int detect_memory_e820(void)
3345 + /* Important: %edx is clobbered by some BIOSes,
3346 + so it must be either used for the error output
3347 + or explicitly marked clobbered. */
3348 +- asm("int $0x15; setc %0"
3349 ++ asm volatile("int $0x15; setc %0"
3350 + : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
3351 + "=m" (*desc)
3352 + : "D" (desc), "d" (SMAP), "a" (0xe820));
3353 +@@ -65,7 +65,7 @@ static int detect_memory_e801(void)
3354 +
3355 + bx = cx = dx = 0;
3356 + ax = 0xe801;
3357 +- asm("stc; int $0x15; setc %0"
3358 ++ asm volatile("stc; int $0x15; setc %0"
3359 + : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
3360 +
3361 + if (err)
3362 +@@ -95,7 +95,7 @@ static int detect_memory_88(void)
3363 + u8 err;
3364 +
3365 + ax = 0x8800;
3366 +- asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3367 ++ asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3368 +
3369 + boot_params.screen_info.ext_mem_k = ax;
3370 +
3371 +diff -urNp linux-2.6.27.10/arch/x86/boot/video.c linux-2.6.27.10/arch/x86/boot/video.c
3372 +--- linux-2.6.27.10/arch/x86/boot/video.c 2008-11-07 12:55:34.000000000 -0500
3373 ++++ linux-2.6.27.10/arch/x86/boot/video.c 2008-11-18 03:38:44.000000000 -0500
3374 +@@ -23,7 +23,7 @@ static void store_cursor_position(void)
3375 +
3376 + ax = 0x0300;
3377 + bx = 0;
3378 +- asm(INT10
3379 ++ asm volatile(INT10
3380 + : "=d" (curpos), "+a" (ax), "+b" (bx)
3381 + : : "ecx", "esi", "edi");
3382 +
3383 +@@ -38,7 +38,7 @@ static void store_video_mode(void)
3384 + /* N.B.: the saving of the video page here is a bit silly,
3385 + since we pretty much assume page 0 everywhere. */
3386 + ax = 0x0f00;
3387 +- asm(INT10
3388 ++ asm volatile(INT10
3389 + : "+a" (ax), "=b" (page)
3390 + : : "ecx", "edx", "esi", "edi");
3391 +
3392 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vesa.c linux-2.6.27.10/arch/x86/boot/video-vesa.c
3393 +--- linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-07 12:55:34.000000000 -0500
3394 ++++ linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-18 03:38:44.000000000 -0500
3395 +@@ -41,7 +41,7 @@ static int vesa_probe(void)
3396 +
3397 + ax = 0x4f00;
3398 + di = (size_t)&vginfo;
3399 +- asm(INT10
3400 ++ asm volatile(INT10
3401 + : "+a" (ax), "+D" (di), "=m" (vginfo)
3402 + : : "ebx", "ecx", "edx", "esi");
3403 +
3404 +@@ -68,7 +68,7 @@ static int vesa_probe(void)
3405 + ax = 0x4f01;
3406 + cx = mode;
3407 + di = (size_t)&vminfo;
3408 +- asm(INT10
3409 ++ asm volatile(INT10
3410 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3411 + : : "ebx", "edx", "esi");
3412 +
3413 +@@ -123,7 +123,7 @@ static int vesa_set_mode(struct mode_inf
3414 + ax = 0x4f01;
3415 + cx = vesa_mode;
3416 + di = (size_t)&vminfo;
3417 +- asm(INT10
3418 ++ asm volatile(INT10
3419 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3420 + : : "ebx", "edx", "esi");
3421 +
3422 +@@ -203,19 +203,20 @@ static void vesa_dac_set_8bits(void)
3423 + /* Save the VESA protected mode info */
3424 + static void vesa_store_pm_info(void)
3425 + {
3426 +- u16 ax, bx, di, es;
3427 ++ u16 ax, bx, cx, di, es;
3428 +
3429 + ax = 0x4f0a;
3430 +- bx = di = 0;
3431 +- asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3432 +- : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
3433 +- : : "ecx", "esi");
3434 ++ bx = cx = di = 0;
3435 ++ asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3436 ++ : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
3437 ++ : : "esi");
3438 +
3439 + if (ax != 0x004f)
3440 + return;
3441 +
3442 + boot_params.screen_info.vesapm_seg = es;
3443 + boot_params.screen_info.vesapm_off = di;
3444 ++ boot_params.screen_info.vesapm_size = cx;
3445 + }
3446 +
3447 + /*
3448 +@@ -269,7 +270,7 @@ void vesa_store_edid(void)
3449 + /* Note: The VBE DDC spec is different from the main VESA spec;
3450 + we genuinely have to assume all registers are destroyed here. */
3451 +
3452 +- asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3453 ++ asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3454 + : "+a" (ax), "+b" (bx)
3455 + : "c" (cx), "D" (di)
3456 + : "esi");
3457 +@@ -285,7 +286,7 @@ void vesa_store_edid(void)
3458 + cx = 0; /* Controller 0 */
3459 + dx = 0; /* EDID block number */
3460 + di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
3461 +- asm(INT10
3462 ++ asm volatile(INT10
3463 + : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
3464 + : "c" (cx), "D" (di)
3465 + : "esi");
3466 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vga.c linux-2.6.27.10/arch/x86/boot/video-vga.c
3467 +--- linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-07 12:55:34.000000000 -0500
3468 ++++ linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-18 03:38:44.000000000 -0500
3469 +@@ -225,7 +225,7 @@ static int vga_probe(void)
3470 + };
3471 + u8 vga_flag;
3472 +
3473 +- asm(INT10
3474 ++ asm volatile(INT10
3475 + : "=b" (ega_bx)
3476 + : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
3477 + : "ecx", "edx", "esi", "edi");
3478 +@@ -237,7 +237,7 @@ static int vga_probe(void)
3479 + /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
3480 + if ((u8)ega_bx != 0x10) {
3481 + /* EGA/VGA */
3482 +- asm(INT10
3483 ++ asm volatile(INT10
3484 + : "=a" (vga_flag)
3485 + : "a" (0x1a00)
3486 + : "ebx", "ecx", "edx", "esi", "edi");
3487 +diff -urNp linux-2.6.27.10/arch/x86/boot/voyager.c linux-2.6.27.10/arch/x86/boot/voyager.c
3488 +--- linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-07 12:55:34.000000000 -0500
3489 ++++ linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-18 03:38:44.000000000 -0500
3490 +@@ -23,7 +23,7 @@ int query_voyager(void)
3491 +
3492 + data_ptr[0] = 0xff; /* Flag on config not found(?) */
3493 +
3494 +- asm("pushw %%es ; "
3495 ++ asm volatile("pushw %%es ; "
3496 + "int $0x15 ; "
3497 + "setc %0 ; "
3498 + "movw %%es, %1 ; "
3499 +diff -urNp linux-2.6.27.10/arch/x86/ia32/ia32_signal.c linux-2.6.27.10/arch/x86/ia32/ia32_signal.c
3500 +--- linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-07 12:55:34.000000000 -0500
3501 ++++ linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-18 03:38:44.000000000 -0500
3502 +@@ -535,6 +535,7 @@ int ia32_setup_rt_frame(int sig, struct
3503 + __NR_ia32_rt_sigreturn,
3504 + 0x80cd,
3505 + 0,
3506 ++ 0
3507 + };
3508 +
3509 + frame = get_sigframe(ka, regs, sizeof(*frame));
3510 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig linux-2.6.27.10/arch/x86/Kconfig
3511 +--- linux-2.6.27.10/arch/x86/Kconfig 2008-11-17 20:03:30.000000000 -0500
3512 ++++ linux-2.6.27.10/arch/x86/Kconfig 2008-11-18 03:38:44.000000000 -0500
3513 +@@ -912,7 +912,7 @@ config PAGE_OFFSET
3514 + hex
3515 + default 0xB0000000 if VMSPLIT_3G_OPT
3516 + default 0x80000000 if VMSPLIT_2G
3517 +- default 0x78000000 if VMSPLIT_2G_OPT
3518 ++ default 0x70000000 if VMSPLIT_2G_OPT
3519 + default 0x40000000 if VMSPLIT_1G
3520 + default 0xC0000000
3521 + depends on X86_32
3522 +@@ -1293,8 +1293,7 @@ config KEXEC_JUMP
3523 + config PHYSICAL_START
3524 + hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
3525 + default "0x1000000" if X86_NUMAQ
3526 +- default "0x200000" if X86_64
3527 +- default "0x100000"
3528 ++ default "0x200000"
3529 + help
3530 + This gives the physical address where the kernel is loaded.
3531 +
3532 +@@ -1386,9 +1385,9 @@ config HOTPLUG_CPU
3533 + suspend.
3534 +
3535 + config COMPAT_VDSO
3536 +- def_bool y
3537 ++ def_bool n
3538 + prompt "Compat VDSO support"
3539 +- depends on X86_32 || IA32_EMULATION
3540 ++ depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
3541 + help
3542 + Map the 32-bit VDSO to the predictable old-style address too.
3543 + ---help---
3544 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.cpu linux-2.6.27.10/arch/x86/Kconfig.cpu
3545 +--- linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-07 12:55:34.000000000 -0500
3546 ++++ linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-18 03:38:44.000000000 -0500
3547 +@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
3548 +
3549 + config X86_F00F_BUG
3550 + def_bool y
3551 +- depends on M586MMX || M586TSC || M586 || M486 || M386
3552 ++ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
3553 +
3554 + config X86_WP_WORKS_OK
3555 + def_bool y
3556 +@@ -360,7 +360,7 @@ config X86_POPAD_OK
3557 +
3558 + config X86_ALIGNMENT_16
3559 + def_bool y
3560 +- depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3561 ++ depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3562 +
3563 + config X86_INTEL_USERCOPY
3564 + def_bool y
3565 +@@ -406,7 +406,7 @@ config X86_CMPXCHG64
3566 + # generates cmov.
3567 + config X86_CMOV
3568 + def_bool y
3569 +- depends on (MK7 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3570 ++ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3571 +
3572 + config X86_MINIMUM_CPU_FAMILY
3573 + int
3574 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.debug linux-2.6.27.10/arch/x86/Kconfig.debug
3575 +--- linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-07 12:55:34.000000000 -0500
3576 ++++ linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-18 03:38:44.000000000 -0500
3577 +@@ -94,7 +94,7 @@ config X86_PTDUMP
3578 + config DEBUG_RODATA
3579 + bool "Write protect kernel read-only data structures"
3580 + default y
3581 +- depends on DEBUG_KERNEL
3582 ++ depends on DEBUG_KERNEL && BROKEN
3583 + help
3584 + Mark the kernel read-only data as write-protected in the pagetables,
3585 + in order to catch accidental (and incorrect) writes to such const
3586 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/boot.c linux-2.6.27.10/arch/x86/kernel/acpi/boot.c
3587 +--- linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:36.000000000 -0500
3588 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:46.000000000 -0500
3589 +@@ -1640,7 +1640,7 @@ static struct dmi_system_id __initdata a
3590 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
3591 + },
3592 + },
3593 +- {}
3594 ++ { NULL, NULL, {{0, NULL}}, NULL}
3595 + };
3596 +
3597 + /*
3598 +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
3599 +--- linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-07 12:55:34.000000000 -0500
3600 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-18 03:38:44.000000000 -0500
3601 +@@ -104,7 +104,7 @@ _start:
3602 + movl %eax, %ecx
3603 + orl %edx, %ecx
3604 + jz 1f
3605 +- movl $0xc0000080, %ecx
3606 ++ mov $MSR_EFER, %ecx
3607 + wrmsr
3608 + 1:
3609 +
3610 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c
3611 +--- linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-07 12:55:34.000000000 -0500
3612 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-18 11:45:34.000000000 -0500
3613 +@@ -37,6 +37,10 @@ int acpi_save_state_mem(void)
3614 + {
3615 + struct wakeup_header *header;
3616 +
3617 ++#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC)
3618 ++ unsigned long cr0;
3619 ++#endif
3620 ++
3621 + if (!acpi_realmode) {
3622 + printk(KERN_ERR "Could not allocate memory during boot, "
3623 + "S3 disabled\n");
3624 +@@ -99,8 +103,18 @@ int acpi_save_state_mem(void)
3625 + header->trampoline_segment = setup_trampoline() >> 4;
3626 + #ifdef CONFIG_SMP
3627 + stack_start.sp = temp_stack + 4096;
3628 ++
3629 ++#ifdef CONFIG_PAX_KERNEXEC
3630 ++ pax_open_kernel(cr0);
3631 ++#endif
3632 ++
3633 + early_gdt_descr.address =
3634 + (unsigned long)get_cpu_gdt_table(smp_processor_id());
3635 ++
3636 ++#ifdef CONFIG_PAX_KERNEXEC
3637 ++ pax_close_kernel(cr0);
3638 ++#endif
3639 ++
3640 + #endif
3641 + initial_code = (unsigned long)wakeup_long64;
3642 + saved_magic = 0x123456789abcdef0;
3643 +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
3644 +--- linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-07 12:55:34.000000000 -0500
3645 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-18 03:38:44.000000000 -0500
3646 +@@ -30,13 +30,11 @@ wakeup_pmode_return:
3647 + # and restore the stack ... but you need gdt for this to work
3648 + movl saved_context_esp, %esp
3649 +
3650 +- movl %cs:saved_magic, %eax
3651 +- cmpl $0x12345678, %eax
3652 ++ cmpl $0x12345678, saved_magic
3653 + jne bogus_magic
3654 +
3655 + # jump to place where we left off
3656 +- movl saved_eip, %eax
3657 +- jmp *%eax
3658 ++ jmp *(saved_eip)
3659 +
3660 + bogus_magic:
3661 + jmp bogus_magic
3662 +diff -urNp linux-2.6.27.10/arch/x86/kernel/alternative.c linux-2.6.27.10/arch/x86/kernel/alternative.c
3663 +--- linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-07 12:55:34.000000000 -0500
3664 ++++ linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-18 03:38:44.000000000 -0500
3665 +@@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc
3666 +
3667 + BUG_ON(p->len > MAX_PATCH_LEN);
3668 + /* prep the buffer with the original instructions */
3669 +- memcpy(insnbuf, p->instr, p->len);
3670 ++ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
3671 + used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
3672 + (unsigned long)p->instr, p->len);
3673 +
3674 +@@ -473,11 +473,26 @@ void __init alternative_instructions(voi
3675 + * instructions. And on the local CPU you need to be protected again NMI or MCE
3676 + * handlers seeing an inconsistent instruction while you patch.
3677 + */
3678 +-void *text_poke_early(void *addr, const void *opcode, size_t len)
3679 ++void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len)
3680 + {
3681 + unsigned long flags;
3682 ++
3683 ++#ifdef CONFIG_PAX_KERNEXEC
3684 ++ unsigned long cr0;
3685 ++#endif
3686 ++
3687 + local_irq_save(flags);
3688 +- memcpy(addr, opcode, len);
3689 ++
3690 ++#ifdef CONFIG_PAX_KERNEXEC
3691 ++ pax_open_kernel(cr0);
3692 ++#endif
3693 ++
3694 ++ memcpy(ktla_ktva(addr), opcode, len);
3695 ++
3696 ++#ifdef CONFIG_PAX_KERNEXEC
3697 ++ pax_close_kernel(cr0);
3698 ++#endif
3699 ++
3700 + local_irq_restore(flags);
3701 + sync_core();
3702 + /* Could also do a CLFLUSH here to speed up CPU recovery; but
3703 +@@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const
3704 + */
3705 + void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
3706 + {
3707 +- unsigned long flags;
3708 +- char *vaddr;
3709 +- int nr_pages = 2;
3710 ++ unsigned char *vaddr = ktla_ktva(addr);
3711 + struct page *pages[2];
3712 +- int i;
3713 ++ size_t i;
3714 ++
3715 ++ if (!core_kernel_text((unsigned long)addr)
3716 +
3717 +- if (!core_kernel_text((unsigned long)addr)) {
3718 +- pages[0] = vmalloc_to_page(addr);
3719 +- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
3720 ++#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
3721 ++ && (vaddr < MODULES_VADDR || MODULES_END < vaddr)
3722 ++#endif
3723 ++
3724 ++ ) {
3725 ++ pages[0] = vmalloc_to_page(vaddr);
3726 ++ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
3727 + } else {
3728 +- pages[0] = virt_to_page(addr);
3729 ++ pages[0] = virt_to_page(vaddr);
3730 + WARN_ON(!PageReserved(pages[0]));
3731 +- pages[1] = virt_to_page(addr + PAGE_SIZE);
3732 ++ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
3733 + }
3734 + BUG_ON(!pages[0]);
3735 +- if (!pages[1])
3736 +- nr_pages = 1;
3737 +- vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
3738 +- BUG_ON(!vaddr);
3739 +- local_irq_save(flags);
3740 +- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
3741 +- local_irq_restore(flags);
3742 +- vunmap(vaddr);
3743 +- sync_core();
3744 +- /* Could also do a CLFLUSH here to speed up CPU recovery; but
3745 +- that causes hangs on some VIA CPUs. */
3746 ++ text_poke_early(addr, opcode, len);
3747 + for (i = 0; i < len; i++)
3748 +- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
3749 ++ BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]);
3750 + return addr;
3751 + }
3752 +diff -urNp linux-2.6.27.10/arch/x86/kernel/apm_32.c linux-2.6.27.10/arch/x86/kernel/apm_32.c
3753 +--- linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-07 12:55:34.000000000 -0500
3754 ++++ linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-18 03:38:44.000000000 -0500
3755 +@@ -408,7 +408,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq
3756 + static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
3757 + static struct apm_user *user_list;
3758 + static DEFINE_SPINLOCK(user_list_lock);
3759 +-static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
3760 ++static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } };
3761 +
3762 + static const char driver_version[] = "1.16ac"; /* no spaces */
3763 +
3764 +@@ -603,19 +603,42 @@ static u8 apm_bios_call(u32 func, u32 eb
3765 + struct desc_struct save_desc_40;
3766 + struct desc_struct *gdt;
3767 +
3768 ++#ifdef CONFIG_PAX_KERNEXEC
3769 ++ unsigned long cr0;
3770 ++#endif
3771 ++
3772 + cpus = apm_save_cpus();
3773 +
3774 + cpu = get_cpu();
3775 + gdt = get_cpu_gdt_table(cpu);
3776 + save_desc_40 = gdt[0x40 / 8];
3777 ++
3778 ++#ifdef CONFIG_PAX_KERNEXEC
3779 ++ pax_open_kernel(cr0);
3780 ++#endif
3781 ++
3782 + gdt[0x40 / 8] = bad_bios_desc;
3783 +
3784 ++#ifdef CONFIG_PAX_KERNEXEC
3785 ++ pax_close_kernel(cr0);
3786 ++#endif
3787 ++
3788 + apm_irq_save(flags);
3789 + APM_DO_SAVE_SEGS;
3790 + apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
3791 + APM_DO_RESTORE_SEGS;
3792 + apm_irq_restore(flags);
3793 ++
3794 ++#ifdef CONFIG_PAX_KERNEXEC
3795 ++ pax_open_kernel(cr0);
3796 ++#endif
3797 ++
3798 + gdt[0x40 / 8] = save_desc_40;
3799 ++
3800 ++#ifdef CONFIG_PAX_KERNEXEC
3801 ++ pax_close_kernel(cr0);
3802 ++#endif
3803 ++
3804 + put_cpu();
3805 + apm_restore_cpus(cpus);
3806 +
3807 +@@ -646,19 +669,42 @@ static u8 apm_bios_call_simple(u32 func,
3808 + struct desc_struct save_desc_40;
3809 + struct desc_struct *gdt;
3810 +
3811 ++#ifdef CONFIG_PAX_KERNEXEC
3812 ++ unsigned long cr0;
3813 ++#endif
3814 ++
3815 + cpus = apm_save_cpus();
3816 +
3817 + cpu = get_cpu();
3818 + gdt = get_cpu_gdt_table(cpu);
3819 + save_desc_40 = gdt[0x40 / 8];
3820 ++
3821 ++#ifdef CONFIG_PAX_KERNEXEC
3822 ++ pax_open_kernel(cr0);
3823 ++#endif
3824 ++
3825 + gdt[0x40 / 8] = bad_bios_desc;
3826 +
3827 ++#ifdef CONFIG_PAX_KERNEXEC
3828 ++ pax_close_kernel(cr0);
3829 ++#endif
3830 ++
3831 + apm_irq_save(flags);
3832 + APM_DO_SAVE_SEGS;
3833 + error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
3834 + APM_DO_RESTORE_SEGS;
3835 + apm_irq_restore(flags);
3836 ++
3837 ++#ifdef CONFIG_PAX_KERNEXEC
3838 ++ pax_open_kernel(cr0);
3839 ++#endif
3840 ++
3841 + gdt[0x40 / 8] = save_desc_40;
3842 ++
3843 ++#ifdef CONFIG_PAX_KERNEXEC
3844 ++ pax_close_kernel(cr0);
3845 ++#endif
3846 ++
3847 + put_cpu();
3848 + apm_restore_cpus(cpus);
3849 + return error;
3850 +@@ -930,7 +976,7 @@ recalc:
3851 +
3852 + static void apm_power_off(void)
3853 + {
3854 +- unsigned char po_bios_call[] = {
3855 ++ const unsigned char po_bios_call[] = {
3856 + 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
3857 + 0x8e, 0xd0, /* movw ax,ss */
3858 + 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
3859 +@@ -1877,7 +1923,10 @@ static const struct file_operations apm_
3860 + static struct miscdevice apm_device = {
3861 + APM_MINOR_DEV,
3862 + "apm_bios",
3863 +- &apm_bios_fops
3864 ++ &apm_bios_fops,
3865 ++ {NULL, NULL},
3866 ++ NULL,
3867 ++ NULL
3868 + };
3869 +
3870 +
3871 +@@ -2198,7 +2247,7 @@ static struct dmi_system_id __initdata a
3872 + { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
3873 + },
3874 +
3875 +- { }
3876 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
3877 + };
3878 +
3879 + /*
3880 +@@ -2216,6 +2265,10 @@ static int __init apm_init(void)
3881 + struct desc_struct *gdt;
3882 + int err;
3883 +
3884 ++#ifdef CONFIG_PAX_KERNEXEC
3885 ++ unsigned long cr0;
3886 ++#endif
3887 ++
3888 + dmi_check_system(apm_dmi_table);
3889 +
3890 + if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) {
3891 +@@ -2289,9 +2342,18 @@ static int __init apm_init(void)
3892 + * This is for buggy BIOS's that refer to (real mode) segment 0x40
3893 + * even though they are called in protected mode.
3894 + */
3895 ++
3896 ++#ifdef CONFIG_PAX_KERNEXEC
3897 ++ pax_open_kernel(cr0);
3898 ++#endif
3899 ++
3900 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
3901 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
3902 +
3903 ++#ifdef CONFIG_PAX_KERNEXEC
3904 ++ pax_close_kernel(cr0);
3905 ++#endif
3906 ++
3907 + /*
3908 + * Set up the long jump entry point to the APM BIOS, which is called
3909 + * from inline assembly.
3910 +@@ -2310,6 +2372,11 @@ static int __init apm_init(void)
3911 + * code to that CPU.
3912 + */
3913 + gdt = get_cpu_gdt_table(0);
3914 ++
3915 ++#ifdef CONFIG_PAX_KERNEXEC
3916 ++ pax_open_kernel(cr0);
3917 ++#endif
3918 ++
3919 + set_base(gdt[APM_CS >> 3],
3920 + __va((unsigned long)apm_info.bios.cseg << 4));
3921 + set_base(gdt[APM_CS_16 >> 3],
3922 +@@ -2317,6 +2384,10 @@ static int __init apm_init(void)
3923 + set_base(gdt[APM_DS >> 3],
3924 + __va((unsigned long)apm_info.bios.dseg << 4));
3925 +
3926 ++#ifdef CONFIG_PAX_KERNEXEC
3927 ++ pax_close_kernel(cr0);
3928 ++#endif
3929 ++
3930 + proc_create("apm", 0, NULL, &apm_file_ops);
3931 +
3932 + kapmd_task = kthread_create(apm, NULL, "kapmd");
3933 +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
3934 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-07 12:55:34.000000000 -0500
3935 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-18 03:38:44.000000000 -0500
3936 +@@ -100,6 +100,7 @@ void foo(void)
3937 + DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
3938 + DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
3939 + DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
3940 ++ DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE);
3941 +
3942 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
3943 +
3944 +@@ -113,6 +114,7 @@ void foo(void)
3945 + OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
3946 + OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
3947 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
3948 ++ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
3949 + #endif
3950 +
3951 + #ifdef CONFIG_XEN
3952 +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
3953 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-07 12:55:34.000000000 -0500
3954 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-18 03:38:44.000000000 -0500
3955 +@@ -122,6 +122,7 @@ int main(void)
3956 + ENTRY(cr8);
3957 + BLANK();
3958 + #undef ENTRY
3959 ++ DEFINE(TSS_size, sizeof(struct tss_struct));
3960 + DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
3961 + BLANK();
3962 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
3963 +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
3964 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-07 12:55:34.000000000 -0500
3965 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-18 03:38:44.000000000 -0500
3966 +@@ -37,22 +37,6 @@
3967 +
3968 + #include "cpu.h"
3969 +
3970 +-/* We need valid kernel segments for data and code in long mode too
3971 +- * IRET will check the segment types kkeil 2000/10/28
3972 +- * Also sysret mandates a special GDT layout
3973 +- */
3974 +-/* The TLS descriptors are currently at a different place compared to i386.
3975 +- Hopefully nobody expects them at a fixed place (Wine?) */
3976 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
3977 +- [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
3978 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
3979 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
3980 +- [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
3981 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
3982 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
3983 +-} };
3984 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
3985 +-
3986 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
3987 +
3988 + /* Current gdt points %fs at the "master" per-cpu area: after this,
3989 +@@ -457,15 +441,13 @@ cpumask_t cpu_initialized __cpuinitdata
3990 + struct x8664_pda **_cpu_pda __read_mostly;
3991 + EXPORT_SYMBOL(_cpu_pda);
3992 +
3993 +-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
3994 ++struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table };
3995 +
3996 + char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
3997 +
3998 + unsigned long __supported_pte_mask __read_mostly = ~0UL;
3999 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
4000 +
4001 +-static int do_not_nx __cpuinitdata;
4002 +-
4003 + /* noexec=on|off
4004 + Control non executable mappings for 64bit processes.
4005 +
4006 +@@ -478,9 +460,7 @@ static int __init nonx_setup(char *str)
4007 + return -EINVAL;
4008 + if (!strncmp(str, "on", 2)) {
4009 + __supported_pte_mask |= _PAGE_NX;
4010 +- do_not_nx = 0;
4011 + } else if (!strncmp(str, "off", 3)) {
4012 +- do_not_nx = 1;
4013 + __supported_pte_mask &= ~_PAGE_NX;
4014 + }
4015 + return 0;
4016 +@@ -576,7 +556,7 @@ void __cpuinit check_efer(void)
4017 + unsigned long efer;
4018 +
4019 + rdmsrl(MSR_EFER, efer);
4020 +- if (!(efer & EFER_NX) || do_not_nx)
4021 ++ if (!(efer & EFER_NX))
4022 + __supported_pte_mask &= ~_PAGE_NX;
4023 + }
4024 +
4025 +@@ -598,7 +578,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist
4026 + void __cpuinit cpu_init(void)
4027 + {
4028 + int cpu = stack_smp_processor_id();
4029 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4030 ++ struct tss_struct *t = init_tss + cpu;
4031 + struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
4032 + unsigned long v;
4033 + char *estacks = NULL;
4034 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common.c linux-2.6.27.10/arch/x86/kernel/cpu/common.c
4035 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-07 12:55:34.000000000 -0500
4036 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-18 03:38:44.000000000 -0500
4037 +@@ -4,7 +4,6 @@
4038 + #include <linux/smp.h>
4039 + #include <linux/module.h>
4040 + #include <linux/percpu.h>
4041 +-#include <linux/bootmem.h>
4042 + #include <asm/processor.h>
4043 + #include <asm/i387.h>
4044 + #include <asm/msr.h>
4045 +@@ -22,42 +21,6 @@
4046 +
4047 + #include "cpu.h"
4048 +
4049 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
4050 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
4051 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
4052 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
4053 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
4054 +- /*
4055 +- * Segments used for calling PnP BIOS have byte granularity.
4056 +- * They code segments and data segments have fixed 64k limits,
4057 +- * the transfer segment sizes are set at run time.
4058 +- */
4059 +- /* 32-bit code */
4060 +- [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
4061 +- /* 16-bit code */
4062 +- [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
4063 +- /* 16-bit data */
4064 +- [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
4065 +- /* 16-bit data */
4066 +- [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
4067 +- /* 16-bit data */
4068 +- [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
4069 +- /*
4070 +- * The APM segments have byte granularity and their bases
4071 +- * are set at run time. All have 64k limits.
4072 +- */
4073 +- /* 32-bit code */
4074 +- [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
4075 +- /* 16-bit code */
4076 +- [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
4077 +- /* data */
4078 +- [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
4079 +-
4080 +- [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
4081 +- [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
4082 +-} };
4083 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
4084 +-
4085 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
4086 +
4087 + static int cachesize_override __cpuinitdata = -1;
4088 +@@ -493,6 +456,10 @@ static void __cpuinit identify_cpu(struc
4089 + * we do "generic changes."
4090 + */
4091 +
4092 ++#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4093 ++ setup_clear_cpu_cap(X86_FEATURE_SEP);
4094 ++#endif
4095 ++
4096 + /* If the model name is still unset, do table lookup. */
4097 + if (!c->x86_model_id[0]) {
4098 + char *p;
4099 +@@ -629,7 +596,7 @@ static __init int setup_disablecpuid(cha
4100 + }
4101 + __setup("clearcpuid=", setup_disablecpuid);
4102 +
4103 +-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
4104 ++cpumask_t cpu_initialized = CPU_MASK_NONE;
4105 +
4106 + void __init early_cpu_init(void)
4107 + {
4108 +@@ -658,7 +625,7 @@ void switch_to_new_gdt(void)
4109 + {
4110 + struct desc_ptr gdt_descr;
4111 +
4112 +- gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
4113 ++ gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id());
4114 + gdt_descr.size = GDT_SIZE - 1;
4115 + load_gdt(&gdt_descr);
4116 + asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory");
4117 +@@ -674,7 +641,7 @@ void __cpuinit cpu_init(void)
4118 + {
4119 + int cpu = smp_processor_id();
4120 + struct task_struct *curr = current;
4121 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4122 ++ struct tss_struct *t = init_tss + cpu;
4123 + struct thread_struct *thread = &curr->thread;
4124 +
4125 + if (cpu_test_and_set(cpu, cpu_initialized)) {
4126 +@@ -729,7 +696,7 @@ void __cpuinit cpu_init(void)
4127 + }
4128 +
4129 + #ifdef CONFIG_HOTPLUG_CPU
4130 +-void __cpuinit cpu_uninit(void)
4131 ++void cpu_uninit(void)
4132 + {
4133 + int cpu = raw_smp_processor_id();
4134 + cpu_clear(cpu, cpu_initialized);
4135 +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
4136 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-07 12:55:34.000000000 -0500
4137 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-18 03:38:44.000000000 -0500
4138 +@@ -560,7 +560,7 @@ static const struct dmi_system_id sw_any
4139 + DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
4140 + },
4141 + },
4142 +- { }
4143 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
4144 + };
4145 + #endif
4146 +
4147 +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
4148 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-07 12:55:34.000000000 -0500
4149 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-18 03:38:44.000000000 -0500
4150 +@@ -225,7 +225,7 @@ static struct cpu_model models[] =
4151 + { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
4152 + { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
4153 +
4154 +- { NULL, }
4155 ++ { NULL, NULL, 0, NULL}
4156 + };
4157 + #undef _BANIAS
4158 + #undef BANIAS
4159 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/intel.c linux-2.6.27.10/arch/x86/kernel/cpu/intel.c
4160 +--- linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-07 12:55:34.000000000 -0500
4161 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-18 03:38:44.000000000 -0500
4162 +@@ -107,7 +107,7 @@ static void __cpuinit trap_init_f00f_bug
4163 + * Update the IDT descriptor and reload the IDT so that
4164 + * it uses the read-only mapped virtual address.
4165 + */
4166 +- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
4167 ++ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
4168 + load_idt(&idt_descr);
4169 + }
4170 + #endif
4171 +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
4172 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-07 12:55:34.000000000 -0500
4173 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-18 03:38:44.000000000 -0500
4174 +@@ -681,6 +681,7 @@ static struct miscdevice mce_log_device
4175 + MISC_MCELOG_MINOR,
4176 + "mcelog",
4177 + &mce_chrdev_ops,
4178 ++ {NULL, NULL}, NULL, NULL
4179 + };
4180 +
4181 + static unsigned long old_cr4 __initdata;
4182 +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
4183 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-07 12:55:34.000000000 -0500
4184 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-18 03:38:44.000000000 -0500
4185 +@@ -31,11 +31,11 @@ static struct fixed_range_block fixed_ra
4186 + { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */
4187 + { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */
4188 + { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */
4189 +- {}
4190 ++ { 0, 0 }
4191 + };
4192 +
4193 + static unsigned long smp_changes_mask;
4194 +-static struct mtrr_state mtrr_state = {};
4195 ++static struct mtrr_state mtrr_state;
4196 + static int mtrr_state_set;
4197 + u64 mtrr_tom2;
4198 +
4199 +diff -urNp linux-2.6.27.10/arch/x86/kernel/crash.c linux-2.6.27.10/arch/x86/kernel/crash.c
4200 +--- linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-07 12:55:34.000000000 -0500
4201 ++++ linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-18 03:38:44.000000000 -0500
4202 +@@ -59,7 +59,7 @@ static int crash_nmi_callback(struct not
4203 + local_irq_disable();
4204 +
4205 + #ifdef CONFIG_X86_32
4206 +- if (!user_mode_vm(regs)) {
4207 ++ if (!user_mode(regs)) {
4208 + crash_fixup_ss_esp(&fixed_regs, regs);
4209 + regs = &fixed_regs;
4210 + }
4211 +diff -urNp linux-2.6.27.10/arch/x86/kernel/doublefault_32.c linux-2.6.27.10/arch/x86/kernel/doublefault_32.c
4212 +--- linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-07 12:55:34.000000000 -0500
4213 ++++ linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-18 03:38:44.000000000 -0500
4214 +@@ -11,7 +11,7 @@
4215 +
4216 + #define DOUBLEFAULT_STACKSIZE (1024)
4217 + static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
4218 +-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
4219 ++#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
4220 +
4221 + #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
4222 +
4223 +@@ -21,7 +21,7 @@ static void doublefault_fn(void)
4224 + unsigned long gdt, tss;
4225 +
4226 + store_gdt(&gdt_desc);
4227 +- gdt = gdt_desc.address;
4228 ++ gdt = (unsigned long)gdt_desc.address;
4229 +
4230 + printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
4231 +
4232 +@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach
4233 + /* 0x2 bit is always set */
4234 + .flags = X86_EFLAGS_SF | 0x2,
4235 + .sp = STACK_START,
4236 +- .es = __USER_DS,
4237 ++ .es = __KERNEL_DS,
4238 + .cs = __KERNEL_CS,
4239 + .ss = __KERNEL_DS,
4240 +- .ds = __USER_DS,
4241 ++ .ds = __KERNEL_DS,
4242 + .fs = __KERNEL_PERCPU,
4243 +
4244 + .__cr3 = __pa(swapper_pg_dir)
4245 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_32.c linux-2.6.27.10/arch/x86/kernel/efi_32.c
4246 +--- linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-07 12:55:34.000000000 -0500
4247 ++++ linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-18 03:38:44.000000000 -0500
4248 +@@ -38,70 +38,38 @@
4249 + */
4250 +
4251 + static unsigned long efi_rt_eflags;
4252 +-static pgd_t efi_bak_pg_dir_pointer[2];
4253 ++static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
4254 +
4255 +-void efi_call_phys_prelog(void)
4256 ++void __init efi_call_phys_prelog(void)
4257 + {
4258 +- unsigned long cr4;
4259 +- unsigned long temp;
4260 + struct desc_ptr gdt_descr;
4261 +
4262 + local_irq_save(efi_rt_eflags);
4263 +
4264 +- /*
4265 +- * If I don't have PAE, I should just duplicate two entries in page
4266 +- * directory. If I have PAE, I just need to duplicate one entry in
4267 +- * page directory.
4268 +- */
4269 +- cr4 = read_cr4_safe();
4270 +
4271 +- if (cr4 & X86_CR4_PAE) {
4272 +- efi_bak_pg_dir_pointer[0].pgd =
4273 +- swapper_pg_dir[pgd_index(0)].pgd;
4274 +- swapper_pg_dir[0].pgd =
4275 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4276 +- } else {
4277 +- efi_bak_pg_dir_pointer[0].pgd =
4278 +- swapper_pg_dir[pgd_index(0)].pgd;
4279 +- efi_bak_pg_dir_pointer[1].pgd =
4280 +- swapper_pg_dir[pgd_index(0x400000)].pgd;
4281 +- swapper_pg_dir[pgd_index(0)].pgd =
4282 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4283 +- temp = PAGE_OFFSET + 0x400000;
4284 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4285 +- swapper_pg_dir[pgd_index(temp)].pgd;
4286 +- }
4287 ++ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
4288 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
4289 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
4290 +
4291 + /*
4292 + * After the lock is released, the original page table is restored.
4293 + */
4294 + __flush_tlb_all();
4295 +
4296 +- gdt_descr.address = __pa(get_cpu_gdt_table(0));
4297 ++ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
4298 + gdt_descr.size = GDT_SIZE - 1;
4299 + load_gdt(&gdt_descr);
4300 + }
4301 +
4302 +-void efi_call_phys_epilog(void)
4303 ++void __init efi_call_phys_epilog(void)
4304 + {
4305 +- unsigned long cr4;
4306 + struct desc_ptr gdt_descr;
4307 +
4308 +- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
4309 ++ gdt_descr.address = get_cpu_gdt_table(0);
4310 + gdt_descr.size = GDT_SIZE - 1;
4311 + load_gdt(&gdt_descr);
4312 +
4313 +- cr4 = read_cr4_safe();
4314 +-
4315 +- if (cr4 & X86_CR4_PAE) {
4316 +- swapper_pg_dir[pgd_index(0)].pgd =
4317 +- efi_bak_pg_dir_pointer[0].pgd;
4318 +- } else {
4319 +- swapper_pg_dir[pgd_index(0)].pgd =
4320 +- efi_bak_pg_dir_pointer[0].pgd;
4321 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4322 +- efi_bak_pg_dir_pointer[1].pgd;
4323 +- }
4324 ++ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
4325 +
4326 + /*
4327 + * After the lock is released, the original page table is restored.
4328 +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
4329 +--- linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-07 12:55:34.000000000 -0500
4330 ++++ linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-18 03:38:44.000000000 -0500
4331 +@@ -6,6 +6,7 @@
4332 + */
4333 +
4334 + #include <linux/linkage.h>
4335 ++#include <linux/init.h>
4336 + #include <asm/page.h>
4337 +
4338 + /*
4339 +@@ -20,7 +21,7 @@
4340 + * service functions will comply with gcc calling convention, too.
4341 + */
4342 +
4343 +-.text
4344 ++__INIT
4345 + ENTRY(efi_call_phys)
4346 + /*
4347 + * 0. The function can only be called in Linux kernel. So CS has been
4348 +@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
4349 + * The mapping of lower virtual memory has been created in prelog and
4350 + * epilog.
4351 + */
4352 +- movl $1f, %edx
4353 +- subl $__PAGE_OFFSET, %edx
4354 +- jmp *%edx
4355 ++ jmp 1f-__PAGE_OFFSET
4356 + 1:
4357 +
4358 + /*
4359 +@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
4360 + * parameter 2, ..., param n. To make things easy, we save the return
4361 + * address of efi_call_phys in a global variable.
4362 + */
4363 +- popl %edx
4364 +- movl %edx, saved_return_addr
4365 +- /* get the function pointer into ECX*/
4366 +- popl %ecx
4367 +- movl %ecx, efi_rt_function_ptr
4368 +- movl $2f, %edx
4369 +- subl $__PAGE_OFFSET, %edx
4370 +- pushl %edx
4371 ++ popl (saved_return_addr)
4372 ++ popl (efi_rt_function_ptr)
4373 +
4374 + /*
4375 + * 3. Clear PG bit in %CR0.
4376 +@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
4377 + /*
4378 + * 5. Call the physical function.
4379 + */
4380 +- jmp *%ecx
4381 ++ call *(efi_rt_function_ptr-__PAGE_OFFSET)
4382 +
4383 +-2:
4384 + /*
4385 + * 6. After EFI runtime service returns, control will return to
4386 + * following instruction. We'd better readjust stack pointer first.
4387 +@@ -88,34 +80,27 @@ ENTRY(efi_call_phys)
4388 + movl %cr0, %edx
4389 + orl $0x80000000, %edx
4390 + movl %edx, %cr0
4391 +- jmp 1f
4392 +-1:
4393 ++
4394 + /*
4395 + * 8. Now restore the virtual mode from flat mode by
4396 + * adding EIP with PAGE_OFFSET.
4397 + */
4398 +- movl $1f, %edx
4399 +- jmp *%edx
4400 ++ jmp 1f+__PAGE_OFFSET
4401 + 1:
4402 +
4403 + /*
4404 + * 9. Balance the stack. And because EAX contain the return value,
4405 + * we'd better not clobber it.
4406 + */
4407 +- leal efi_rt_function_ptr, %edx
4408 +- movl (%edx), %ecx
4409 +- pushl %ecx
4410 ++ pushl (efi_rt_function_ptr)
4411 +
4412 + /*
4413 +- * 10. Push the saved return address onto the stack and return.
4414 ++ * 10. Return to the saved return address.
4415 + */
4416 +- leal saved_return_addr, %edx
4417 +- movl (%edx), %ecx
4418 +- pushl %ecx
4419 +- ret
4420 ++ jmpl *(saved_return_addr)
4421 + .previous
4422 +
4423 +-.data
4424 ++__INITDATA
4425 + saved_return_addr:
4426 + .long 0
4427 + efi_rt_function_ptr:
4428 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_32.S linux-2.6.27.10/arch/x86/kernel/entry_32.S
4429 +--- linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-07 12:55:34.000000000 -0500
4430 ++++ linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-18 03:38:44.000000000 -0500
4431 +@@ -101,7 +101,7 @@
4432 + #define resume_userspace_sig resume_userspace
4433 + #endif
4434 +
4435 +-#define SAVE_ALL \
4436 ++#define __SAVE_ALL(_DS) \
4437 + cld; \
4438 + pushl %fs; \
4439 + CFI_ADJUST_CFA_OFFSET 4;\
4440 +@@ -133,12 +133,26 @@
4441 + pushl %ebx; \
4442 + CFI_ADJUST_CFA_OFFSET 4;\
4443 + CFI_REL_OFFSET ebx, 0;\
4444 +- movl $(__USER_DS), %edx; \
4445 ++ movl $(_DS), %edx; \
4446 + movl %edx, %ds; \
4447 + movl %edx, %es; \
4448 + movl $(__KERNEL_PERCPU), %edx; \
4449 + movl %edx, %fs
4450 +
4451 ++#ifdef CONFIG_PAX_KERNEXEC
4452 ++#define SAVE_ALL \
4453 ++ __SAVE_ALL(__KERNEL_DS); \
4454 ++ GET_CR0_INTO_EDX; \
4455 ++ movl %edx, %esi; \
4456 ++ orl $X86_CR0_WP, %edx; \
4457 ++ xorl %edx, %esi; \
4458 ++ SET_CR0_FROM_EDX
4459 ++#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4460 ++#define SAVE_ALL __SAVE_ALL(__KERNEL_DS)
4461 ++#else
4462 ++#define SAVE_ALL __SAVE_ALL(__USER_DS)
4463 ++#endif
4464 ++
4465 + #define RESTORE_INT_REGS \
4466 + popl %ebx; \
4467 + CFI_ADJUST_CFA_OFFSET -4;\
4468 +@@ -229,6 +243,11 @@ ENTRY(ret_from_fork)
4469 + CFI_ADJUST_CFA_OFFSET 4
4470 + popfl
4471 + CFI_ADJUST_CFA_OFFSET -4
4472 ++
4473 ++#ifdef CONFIG_PAX_KERNEXEC
4474 ++ xorl %esi, %esi
4475 ++#endif
4476 ++
4477 + jmp syscall_exit
4478 + CFI_ENDPROC
4479 + END(ret_from_fork)
4480 +@@ -252,7 +271,17 @@ check_userspace:
4481 + movb PT_CS(%esp), %al
4482 + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
4483 + cmpl $USER_RPL, %eax
4484 ++
4485 ++#ifdef CONFIG_PAX_KERNEXEC
4486 ++ jae resume_userspace
4487 ++
4488 ++ GET_CR0_INTO_EDX
4489 ++ xorl %esi, %edx
4490 ++ SET_CR0_FROM_EDX
4491 ++ jmp resume_kernel
4492 ++#else
4493 + jb resume_kernel # not returning to v8086 or userspace
4494 ++#endif
4495 +
4496 + ENTRY(resume_userspace)
4497 + LOCKDEP_SYS_EXIT
4498 +@@ -314,10 +343,9 @@ sysenter_past_esp:
4499 + /*CFI_REL_OFFSET cs, 0*/
4500 + /*
4501 + * Push current_thread_info()->sysenter_return to the stack.
4502 +- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
4503 +- * pushed above; +8 corresponds to copy_thread's esp0 setting.
4504 + */
4505 +- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
4506 ++ GET_THREAD_INFO(%ebp)
4507 ++ pushl TI_sysenter_return(%ebp)
4508 + CFI_ADJUST_CFA_OFFSET 4
4509 + CFI_REL_OFFSET eip, 0
4510 +
4511 +@@ -330,9 +358,17 @@ sysenter_past_esp:
4512 + * Load the potential sixth argument from user stack.
4513 + * Careful about security.
4514 + */
4515 ++ movl PT_OLDESP(%esp),%ebp
4516 ++
4517 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4518 ++ mov PT_OLDSS(%esp),%ds
4519 ++1: movl %ds:(%ebp),%ebp
4520 ++#else
4521 + cmpl $__PAGE_OFFSET-3,%ebp
4522 + jae syscall_fault
4523 + 1: movl (%ebp),%ebp
4524 ++#endif
4525 ++
4526 + movl %ebp,PT_EBP(%esp)
4527 + .section __ex_table,"a"
4528 + .align 4
4529 +@@ -356,12 +392,23 @@ sysenter_do_call:
4530 + testw $_TIF_ALLWORK_MASK, %cx
4531 + jne sysexit_audit
4532 + sysenter_exit:
4533 ++
4534 ++#ifdef CONFIG_PAX_RANDKSTACK
4535 ++ pushl %eax
4536 ++ CFI_ADJUST_CFA_OFFSET 4
4537 ++ call pax_randomize_kstack
4538 ++ popl %eax
4539 ++ CFI_ADJUST_CFA_OFFSET -4
4540 ++#endif
4541 ++
4542 + /* if something modifies registers it must also disable sysexit */
4543 + movl PT_EIP(%esp), %edx
4544 + movl PT_OLDESP(%esp), %ecx
4545 + xorl %ebp,%ebp
4546 + TRACE_IRQS_ON
4547 + 1: mov PT_FS(%esp), %fs
4548 ++2: mov PT_DS(%esp), %ds
4549 ++3: mov PT_ES(%esp), %es
4550 + ENABLE_INTERRUPTS_SYSEXIT
4551 +
4552 + #ifdef CONFIG_AUDITSYSCALL
4553 +@@ -404,11 +451,17 @@ sysexit_audit:
4554 +
4555 + CFI_ENDPROC
4556 + .pushsection .fixup,"ax"
4557 +-2: movl $0,PT_FS(%esp)
4558 ++4: movl $0,PT_FS(%esp)
4559 ++ jmp 1b
4560 ++5: movl $0,PT_DS(%esp)
4561 ++ jmp 1b
4562 ++6: movl $0,PT_ES(%esp)
4563 + jmp 1b
4564 + .section __ex_table,"a"
4565 + .align 4
4566 +- .long 1b,2b
4567 ++ .long 1b,4b
4568 ++ .long 2b,5b
4569 ++ .long 3b,6b
4570 + .popsection
4571 + ENDPROC(ia32_sysenter_target)
4572 +
4573 +@@ -438,6 +491,10 @@ syscall_exit:
4574 + testw $_TIF_ALLWORK_MASK, %cx # current->work
4575 + jne syscall_exit_work
4576 +
4577 ++#ifdef CONFIG_PAX_RANDKSTACK
4578 ++ call pax_randomize_kstack
4579 ++#endif
4580 ++
4581 + restore_all:
4582 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
4583 + # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
4584 +@@ -531,25 +588,19 @@ work_resched:
4585 +
4586 + work_notifysig: # deal with pending signals and
4587 + # notify-resume requests
4588 ++ movl %esp, %eax
4589 + #ifdef CONFIG_VM86
4590 + testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
4591 +- movl %esp, %eax
4592 +- jne work_notifysig_v86 # returning to kernel-space or
4593 ++ jz 1f # returning to kernel-space or
4594 + # vm86-space
4595 +- xorl %edx, %edx
4596 +- call do_notify_resume
4597 +- jmp resume_userspace_sig
4598 +
4599 +- ALIGN
4600 +-work_notifysig_v86:
4601 + pushl %ecx # save ti_flags for do_notify_resume
4602 + CFI_ADJUST_CFA_OFFSET 4
4603 + call save_v86_state # %eax contains pt_regs pointer
4604 + popl %ecx
4605 + CFI_ADJUST_CFA_OFFSET -4
4606 + movl %eax, %esp
4607 +-#else
4608 +- movl %esp, %eax
4609 ++1:
4610 + #endif
4611 + xorl %edx, %edx
4612 + call do_notify_resume
4613 +@@ -595,17 +646,24 @@ syscall_badsys:
4614 + END(syscall_badsys)
4615 + CFI_ENDPROC
4616 +
4617 +-#define FIXUP_ESPFIX_STACK \
4618 +- /* since we are on a wrong stack, we cant make it a C code :( */ \
4619 +- PER_CPU(gdt_page, %ebx); \
4620 +- GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
4621 +- addl %esp, %eax; \
4622 +- pushl $__KERNEL_DS; \
4623 +- CFI_ADJUST_CFA_OFFSET 4; \
4624 +- pushl %eax; \
4625 +- CFI_ADJUST_CFA_OFFSET 4; \
4626 +- lss (%esp), %esp; \
4627 ++.macro FIXUP_ESPFIX_STACK
4628 ++ /* since we are on a wrong stack, we cant make it a C code :( */
4629 ++#ifdef CONFIG_SMP
4630 ++ movl PER_CPU_VAR(cpu_number), %ebx;
4631 ++ shll $PAGE_SHIFT_asm, %ebx;
4632 ++ addl $cpu_gdt_table, %ebx;
4633 ++#else
4634 ++ movl $cpu_gdt_table, %ebx;
4635 ++#endif
4636 ++ GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah);
4637 ++ addl %esp, %eax;
4638 ++ pushl $__KERNEL_DS;
4639 ++ CFI_ADJUST_CFA_OFFSET 4;
4640 ++ pushl %eax;
4641 ++ CFI_ADJUST_CFA_OFFSET 4;
4642 ++ lss (%esp), %esp;
4643 + CFI_ADJUST_CFA_OFFSET -8;
4644 ++.endm
4645 + #define UNWIND_ESPFIX_STACK \
4646 + movl %ss, %eax; \
4647 + /* see if on espfix stack */ \
4648 +@@ -622,7 +680,7 @@ END(syscall_badsys)
4649 + * Build the entry stubs and pointer table with
4650 + * some assembler magic.
4651 + */
4652 +-.section .rodata,"a"
4653 ++.section .rodata,"a",@progbits
4654 + ENTRY(interrupt)
4655 + .text
4656 +
4657 +@@ -722,12 +780,21 @@ error_code:
4658 + popl %ecx
4659 + CFI_ADJUST_CFA_OFFSET -4
4660 + /*CFI_REGISTER es, ecx*/
4661 ++
4662 ++#ifdef CONFIG_PAX_KERNEXEC
4663 ++ GET_CR0_INTO_EDX
4664 ++ movl %edx, %esi
4665 ++ orl $X86_CR0_WP, %edx
4666 ++ xorl %edx, %esi
4667 ++ SET_CR0_FROM_EDX
4668 ++#endif
4669 ++
4670 + movl PT_FS(%esp), %edi # get the function address
4671 + movl PT_ORIG_EAX(%esp), %edx # get the error code
4672 + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
4673 + mov %ecx, PT_FS(%esp)
4674 + /*CFI_REL_OFFSET fs, ES*/
4675 +- movl $(__USER_DS), %ecx
4676 ++ movl $(__KERNEL_DS), %ecx
4677 + movl %ecx, %ds
4678 + movl %ecx, %es
4679 + movl %esp,%eax # pt_regs pointer
4680 +@@ -861,6 +928,13 @@ nmi_stack_correct:
4681 + xorl %edx,%edx # zero error code
4682 + movl %esp,%eax # pt_regs pointer
4683 + call do_nmi
4684 ++
4685 ++#ifdef CONFIG_PAX_KERNEXEC
4686 ++ GET_CR0_INTO_EDX
4687 ++ xorl %esi, %edx
4688 ++ SET_CR0_FROM_EDX
4689 ++#endif
4690 ++
4691 + jmp restore_nocheck_notrace
4692 + CFI_ENDPROC
4693 +
4694 +@@ -901,6 +975,13 @@ nmi_espfix_stack:
4695 + FIXUP_ESPFIX_STACK # %eax == %esp
4696 + xorl %edx,%edx # zero error code
4697 + call do_nmi
4698 ++
4699 ++#ifdef CONFIG_PAX_KERNEXEC
4700 ++ GET_CR0_INTO_EDX
4701 ++ xorl %esi, %edx
4702 ++ SET_CR0_FROM_EDX
4703 ++#endif
4704 ++
4705 + RESTORE_REGS
4706 + lss 12+4(%esp), %esp # back to espfix stack
4707 + CFI_ADJUST_CFA_OFFSET -24
4708 +@@ -1226,7 +1307,6 @@ END(mcount)
4709 + #endif /* CONFIG_DYNAMIC_FTRACE */
4710 + #endif /* CONFIG_FTRACE */
4711 +
4712 +-.section .rodata,"a"
4713 + #include "syscall_table_32.S"
4714 +
4715 + syscall_table_size=(.-sys_call_table)
4716 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_64.S linux-2.6.27.10/arch/x86/kernel/entry_64.S
4717 +--- linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-07 12:55:34.000000000 -0500
4718 ++++ linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-18 03:38:44.000000000 -0500
4719 +@@ -930,17 +930,18 @@ END(spurious_interrupt)
4720 + xorl %ebx,%ebx
4721 + 1:
4722 + .if \ist
4723 +- movq %gs:pda_data_offset, %rbp
4724 ++ imul $TSS_size, %gs:pda_cpunumber, %ebp
4725 ++ lea init_tss(%rbp), %rbp
4726 + .endif
4727 + movq %rsp,%rdi
4728 + movq ORIG_RAX(%rsp),%rsi
4729 + movq $-1,ORIG_RAX(%rsp)
4730 + .if \ist
4731 +- subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4732 ++ subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4733 + .endif
4734 + call \sym
4735 + .if \ist
4736 +- addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4737 ++ addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4738 + .endif
4739 + DISABLE_INTERRUPTS(CLBR_NONE)
4740 + .if \irqtrace
4741 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ftrace.c linux-2.6.27.10/arch/x86/kernel/ftrace.c
4742 +--- linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-11-07 12:55:34.000000000 -0500
4743 ++++ linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-12-10 22:28:27.000000000 -0500
4744 +@@ -103,9 +103,9 @@ notrace int ftrace_update_ftrace_func(ft
4745 + unsigned char old[MCOUNT_INSN_SIZE], *new;
4746 + int ret;
4747 +
4748 +- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
4749 ++ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
4750 + new = ftrace_call_replace(ip, (unsigned long)func);
4751 +- ret = ftrace_modify_code(ip, old, new);
4752 ++ ret = ftrace_modify_code(ktla_ktva(ip), old, new);
4753 +
4754 + return ret;
4755 + }
4756 +@@ -120,9 +120,9 @@ notrace int ftrace_mcount_set(unsigned l
4757 + * Replace the mcount stub with a pointer to the
4758 + * ip recorder function.
4759 + */
4760 +- memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
4761 ++ memcpy(old, ktla_ktva(mcount_call), MCOUNT_INSN_SIZE);
4762 + new = ftrace_call_replace(ip, *addr);
4763 +- *addr = ftrace_modify_code(ip, old, new);
4764 ++ *addr = ftrace_modify_code(ktla_ktva(ip), old, new);
4765 +
4766 + return 0;
4767 + }
4768 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head32.c linux-2.6.27.10/arch/x86/kernel/head32.c
4769 +--- linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-07 12:55:34.000000000 -0500
4770 ++++ linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-18 03:38:44.000000000 -0500
4771 +@@ -12,10 +12,11 @@
4772 + #include <asm/sections.h>
4773 + #include <asm/e820.h>
4774 + #include <asm/bios_ebda.h>
4775 ++#include <asm/boot.h>
4776 +
4777 + void __init i386_start_kernel(void)
4778 + {
4779 +- reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
4780 ++ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS");
4781 +
4782 + #ifdef CONFIG_BLK_DEV_INITRD
4783 + /* Reserve INITRD */
4784 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_32.S linux-2.6.27.10/arch/x86/kernel/head_32.S
4785 +--- linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-07 12:55:34.000000000 -0500
4786 ++++ linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-18 03:38:44.000000000 -0500
4787 +@@ -19,6 +19,7 @@
4788 + #include <asm/asm-offsets.h>
4789 + #include <asm/setup.h>
4790 + #include <asm/processor-flags.h>
4791 ++#include <asm/msr-index.h>
4792 +
4793 + /* Physical address */
4794 + #define pa(X) ((X) - __PAGE_OFFSET)
4795 +@@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
4796 + LOW_PAGES = LOW_PAGES + 0x1000000
4797 + #endif
4798 +
4799 +-#if PTRS_PER_PMD > 1
4800 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
4801 +-#else
4802 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
4803 +-#endif
4804 ++PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE)
4805 + BOOTBITMAP_SIZE = LOW_PAGES / 8
4806 + ALLOCATOR_SLOP = 4
4807 +
4808 + INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
4809 +
4810 + /*
4811 ++ * Real beginning of normal "text" segment
4812 ++ */
4813 ++ENTRY(stext)
4814 ++ENTRY(_stext)
4815 ++
4816 ++.section .text.startup,"ax",@progbits
4817 ++ ljmp $(__BOOT_CS),$phys_startup_32
4818 ++
4819 ++/*
4820 + * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
4821 + * %esi points to the real-mode code as a 32-bit pointer.
4822 + * CS and DS must be 4 GB flat segments, but we don't depend on
4823 +@@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE +
4824 + * can.
4825 + */
4826 + .section .text.head,"ax",@progbits
4827 ++
4828 ++#ifdef CONFIG_PAX_KERNEXEC
4829 ++/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
4830 ++.fill 4096,1,0xcc
4831 ++#endif
4832 ++
4833 + ENTRY(startup_32)
4834 + /* test KEEP_SEGMENTS flag to see if the bootloader is asking
4835 + us to not reload segments */
4836 +@@ -99,6 +111,56 @@ ENTRY(startup_32)
4837 + movl %eax,%gs
4838 + 2:
4839 +
4840 ++ movl $pa(cpu_gdt_table),%edi
4841 ++ movl $__per_cpu_start,%eax
4842 ++ movw %ax,__KERNEL_PERCPU + 2(%edi)
4843 ++ rorl $16,%eax
4844 ++ movb %al,__KERNEL_PERCPU + 4(%edi)
4845 ++ movb %ah,__KERNEL_PERCPU + 7(%edi)
4846 ++ movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax
4847 ++ subl $__per_cpu_start,%eax
4848 ++ movw %ax,__KERNEL_PERCPU + 0(%edi)
4849 ++
4850 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4851 ++ /* check for VMware */
4852 ++ movl $0x564d5868,%eax
4853 ++ xorl %ebx,%ebx
4854 ++ movl $0xa,%ecx
4855 ++ movl $0x5658,%edx
4856 ++ in (%dx),%eax
4857 ++ cmpl $0x564d5868,%ebx
4858 ++ jz 2f
4859 ++
4860 ++ movl $NR_CPUS,%ecx
4861 ++ movl $pa(cpu_gdt_table),%edi
4862 ++1:
4863 ++ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
4864 ++ addl $PAGE_SIZE_asm,%edi
4865 ++ loop 1b
4866 ++2:
4867 ++#endif
4868 ++
4869 ++#ifdef CONFIG_PAX_KERNEXEC
4870 ++ movl $pa(boot_gdt),%edi
4871 ++ movl $KERNEL_TEXT_OFFSET,%eax
4872 ++ movw %ax,__BOOT_CS + 2(%edi)
4873 ++ rorl $16,%eax
4874 ++ movb %al,__BOOT_CS + 4(%edi)
4875 ++ movb %ah,__BOOT_CS + 7(%edi)
4876 ++ rorl $16,%eax
4877 ++
4878 ++ movl $NR_CPUS,%ecx
4879 ++ movl $pa(cpu_gdt_table),%edi
4880 ++1:
4881 ++ movw %ax,__KERNEL_CS + 2(%edi)
4882 ++ rorl $16,%eax
4883 ++ movb %al,__KERNEL_CS + 4(%edi)
4884 ++ movb %ah,__KERNEL_CS + 7(%edi)
4885 ++ rorl $16,%eax
4886 ++ addl $PAGE_SIZE_asm,%edi
4887 ++ loop 1b
4888 ++#endif
4889 ++
4890 + /*
4891 + * Clear BSS first so that there are no surprises...
4892 + */
4893 +@@ -142,9 +204,7 @@ ENTRY(startup_32)
4894 + cmpl $num_subarch_entries, %eax
4895 + jae bad_subarch
4896 +
4897 +- movl pa(subarch_entries)(,%eax,4), %eax
4898 +- subl $__PAGE_OFFSET, %eax
4899 +- jmp *%eax
4900 ++ jmp *pa(subarch_entries)(,%eax,4)
4901 +
4902 + bad_subarch:
4903 + WEAK(lguest_entry)
4904 +@@ -156,9 +216,9 @@ WEAK(xen_entry)
4905 + __INITDATA
4906 +
4907 + subarch_entries:
4908 +- .long default_entry /* normal x86/PC */
4909 +- .long lguest_entry /* lguest hypervisor */
4910 +- .long xen_entry /* Xen hypervisor */
4911 ++ .long pa(default_entry) /* normal x86/PC */
4912 ++ .long pa(lguest_entry) /* lguest hypervisor */
4913 ++ .long pa(xen_entry) /* Xen hypervisor */
4914 + num_subarch_entries = (. - subarch_entries) / 4
4915 + .previous
4916 + #endif /* CONFIG_PARAVIRT */
4917 +@@ -172,7 +232,7 @@ num_subarch_entries = (. - subarch_entri
4918 + *
4919 + * Note that the stack is not yet set up!
4920 + */
4921 +-#define PTE_ATTR 0x007 /* PRESENT+RW+USER */
4922 ++#define PTE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
4923 + #define PDE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
4924 + #define PGD_ATTR 0x001 /* PRESENT (no other attributes) */
4925 +
4926 +@@ -224,8 +284,7 @@ default_entry:
4927 + movl %eax, pa(max_pfn_mapped)
4928 +
4929 + /* Do early initialization of the fixmap area */
4930 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
4931 +- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
4932 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
4933 + #else /* Not PAE */
4934 +
4935 + page_pde_offset = (__PAGE_OFFSET >> 20);
4936 +@@ -257,8 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
4937 + movl %eax, pa(max_pfn_mapped)
4938 +
4939 + /* Do early initialization of the fixmap area */
4940 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
4941 +- movl %eax,pa(swapper_pg_dir+0xffc)
4942 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_dir+0xffc)
4943 + #endif
4944 + jmp 3f
4945 + /*
4946 +@@ -322,13 +380,16 @@ ENTRY(startup_32_smp)
4947 + jnc 6f
4948 +
4949 + /* Setup EFER (Extended Feature Enable Register) */
4950 +- movl $0xc0000080, %ecx
4951 ++ movl $MSR_EFER, %ecx
4952 + rdmsr
4953 +
4954 + btsl $11, %eax
4955 + /* Make changes effective */
4956 + wrmsr
4957 +
4958 ++ btsl $63-32,pa(__supported_pte_mask+4)
4959 ++ movl $1,pa(nx_enabled)
4960 ++
4961 + 6:
4962 +
4963 + /*
4964 +@@ -354,9 +415,7 @@ ENTRY(startup_32_smp)
4965 +
4966 + #ifdef CONFIG_SMP
4967 + cmpb $0, ready
4968 +- jz 1f /* Initial CPU cleans BSS */
4969 +- jmp checkCPUtype
4970 +-1:
4971 ++ jnz checkCPUtype /* Initial CPU cleans BSS */
4972 + #endif /* CONFIG_SMP */
4973 +
4974 + /*
4975 +@@ -433,12 +492,12 @@ is386: movl $2,%ecx # set MP
4976 + ljmp $(__KERNEL_CS),$1f
4977 + 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
4978 + movl %eax,%ss # after changing gdt.
4979 +- movl %eax,%fs # gets reset once there's real percpu
4980 +-
4981 +- movl $(__USER_DS),%eax # DS/ES contains default USER segment
4982 + movl %eax,%ds
4983 + movl %eax,%es
4984 +
4985 ++ movl $(__KERNEL_PERCPU), %eax
4986 ++ movl %eax,%fs # set this cpu's percpu
4987 ++
4988 + xorl %eax,%eax # Clear GS and LDT
4989 + movl %eax,%gs
4990 + lldt %ax
4991 +@@ -448,12 +507,6 @@ is386: movl $2,%ecx # set MP
4992 + #ifdef CONFIG_SMP
4993 + movb ready, %cl
4994 + movb $1, ready
4995 +- cmpb $0,%cl # the first CPU calls start_kernel
4996 +- je 1f
4997 +- movl $(__KERNEL_PERCPU), %eax
4998 +- movl %eax,%fs # set this cpu's percpu
4999 +- movl (stack_start), %esp
5000 +-1:
5001 + #endif /* CONFIG_SMP */
5002 + jmp *(initial_code)
5003 +
5004 +@@ -539,15 +592,15 @@ early_page_fault:
5005 + jmp early_fault
5006 +
5007 + early_fault:
5008 +- cld
5009 + #ifdef CONFIG_PRINTK
5010 ++ cmpl $2,%ss:early_recursion_flag
5011 ++ je hlt_loop
5012 ++ incl %ss:early_recursion_flag
5013 ++ cld
5014 + pusha
5015 + movl $(__KERNEL_DS),%eax
5016 + movl %eax,%ds
5017 + movl %eax,%es
5018 +- cmpl $2,early_recursion_flag
5019 +- je hlt_loop
5020 +- incl early_recursion_flag
5021 + movl %cr2,%eax
5022 + pushl %eax
5023 + pushl %edx /* trapno */
5024 +@@ -557,8 +610,8 @@ early_fault:
5025 + #else
5026 + call printk
5027 + #endif
5028 +-#endif
5029 + call dump_stack
5030 ++#endif
5031 + hlt_loop:
5032 + hlt
5033 + jmp hlt_loop
5034 +@@ -566,8 +619,11 @@ hlt_loop:
5035 + /* This is the default interrupt "handler" :-) */
5036 + ALIGN
5037 + ignore_int:
5038 +- cld
5039 + #ifdef CONFIG_PRINTK
5040 ++ cmpl $2,%ss:early_recursion_flag
5041 ++ je hlt_loop
5042 ++ incl %ss:early_recursion_flag
5043 ++ cld
5044 + pushl %eax
5045 + pushl %ecx
5046 + pushl %edx
5047 +@@ -576,9 +632,6 @@ ignore_int:
5048 + movl $(__KERNEL_DS),%eax
5049 + movl %eax,%ds
5050 + movl %eax,%es
5051 +- cmpl $2,early_recursion_flag
5052 +- je hlt_loop
5053 +- incl early_recursion_flag
5054 + pushl 16(%esp)
5055 + pushl 24(%esp)
5056 + pushl 32(%esp)
5057 +@@ -603,36 +656,41 @@ ignore_int:
5058 + ENTRY(initial_code)
5059 + .long i386_start_kernel
5060 +
5061 +-.section .text
5062 +-/*
5063 +- * Real beginning of normal "text" segment
5064 +- */
5065 +-ENTRY(stext)
5066 +-ENTRY(_stext)
5067 +-
5068 + /*
5069 + * BSS section
5070 + */
5071 +-.section ".bss.page_aligned","wa"
5072 +- .align PAGE_SIZE_asm
5073 + #ifdef CONFIG_X86_PAE
5074 ++.section .swapper_pg_pmd,"a",@progbits
5075 + swapper_pg_pmd:
5076 + .fill 1024*KPMDS,4,0
5077 + #else
5078 ++.section .swapper_pg_dir,"a",@progbits
5079 + ENTRY(swapper_pg_dir)
5080 + .fill 1024,4,0
5081 + #endif
5082 + swapper_pg_fixmap:
5083 + .fill 1024,4,0
5084 ++
5085 ++.section .empty_zero_page,"a",@progbits
5086 + ENTRY(empty_zero_page)
5087 + .fill 4096,1,0
5088 ++
5089 ++/*
5090 ++ * The IDT has to be page-aligned to simplify the Pentium
5091 ++ * F0 0F bug workaround.. We have a special link segment
5092 ++ * for this.
5093 ++ */
5094 ++.section .idt,"a",@progbits
5095 ++ENTRY(idt_table)
5096 ++ .fill 256,8,0
5097 ++
5098 + /*
5099 + * This starts the data section.
5100 + */
5101 ++.data
5102 ++
5103 + #ifdef CONFIG_X86_PAE
5104 +-.section ".data.page_aligned","wa"
5105 +- /* Page-aligned for the benefit of paravirt? */
5106 +- .align PAGE_SIZE_asm
5107 ++.section .swapper_pg_dir,"a",@progbits
5108 + ENTRY(swapper_pg_dir)
5109 + .long pa(swapper_pg_pmd+PGD_ATTR),0 /* low identity map */
5110 + # if KPMDS == 3
5111 +@@ -655,11 +713,12 @@ ENTRY(swapper_pg_dir)
5112 +
5113 + .data
5114 + ENTRY(stack_start)
5115 +- .long init_thread_union+THREAD_SIZE
5116 ++ .long init_thread_union+THREAD_SIZE-8
5117 + .long __BOOT_DS
5118 +
5119 + ready: .byte 0
5120 +
5121 ++.section .rodata,"a",@progbits
5122 + early_recursion_flag:
5123 + .long 0
5124 +
5125 +@@ -695,7 +754,7 @@ fault_msg:
5126 + .word 0 # 32 bit align gdt_desc.address
5127 + boot_gdt_descr:
5128 + .word __BOOT_DS+7
5129 +- .long boot_gdt - __PAGE_OFFSET
5130 ++ .long pa(boot_gdt)
5131 +
5132 + .word 0 # 32-bit align idt_desc.address
5133 + idt_descr:
5134 +@@ -706,7 +765,7 @@ idt_descr:
5135 + .word 0 # 32 bit align gdt_desc.address
5136 + ENTRY(early_gdt_descr)
5137 + .word GDT_ENTRIES*8-1
5138 +- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
5139 ++ .long cpu_gdt_table /* Overwritten for secondary CPUs */
5140 +
5141 + /*
5142 + * The boot_gdt must mirror the equivalent in setup.S and is
5143 +@@ -715,5 +774,59 @@ ENTRY(early_gdt_descr)
5144 + .align L1_CACHE_BYTES
5145 + ENTRY(boot_gdt)
5146 + .fill GDT_ENTRY_BOOT_CS,8,0
5147 +- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
5148 +- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
5149 ++ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
5150 ++ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
5151 ++
5152 ++ .align PAGE_SIZE_asm
5153 ++ENTRY(cpu_gdt_table)
5154 ++ .rept NR_CPUS
5155 ++ .quad 0x0000000000000000 /* NULL descriptor */
5156 ++ .quad 0x0000000000000000 /* 0x0b reserved */
5157 ++ .quad 0x0000000000000000 /* 0x13 reserved */
5158 ++ .quad 0x0000000000000000 /* 0x1b reserved */
5159 ++ .quad 0x0000000000000000 /* 0x20 unused */
5160 ++ .quad 0x0000000000000000 /* 0x28 unused */
5161 ++ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
5162 ++ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
5163 ++ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
5164 ++ .quad 0x0000000000000000 /* 0x4b reserved */
5165 ++ .quad 0x0000000000000000 /* 0x53 reserved */
5166 ++ .quad 0x0000000000000000 /* 0x5b reserved */
5167 ++
5168 ++ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
5169 ++ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
5170 ++ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
5171 ++ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
5172 ++
5173 ++ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
5174 ++ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
5175 ++
5176 ++ /*
5177 ++ * Segments used for calling PnP BIOS have byte granularity.
5178 ++ * The code segments and data segments have fixed 64k limits,
5179 ++ * the transfer segment sizes are set at run time.
5180 ++ */
5181 ++ .quad 0x00409b000000ffff /* 0x90 32-bit code */
5182 ++ .quad 0x00009b000000ffff /* 0x98 16-bit code */
5183 ++ .quad 0x000093000000ffff /* 0xa0 16-bit data */
5184 ++ .quad 0x0000930000000000 /* 0xa8 16-bit data */
5185 ++ .quad 0x0000930000000000 /* 0xb0 16-bit data */
5186 ++
5187 ++ /*
5188 ++ * The APM segments have byte granularity and their bases
5189 ++ * are set at run time. All have 64k limits.
5190 ++ */
5191 ++ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
5192 ++ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
5193 ++ .quad 0x004093000000ffff /* 0xc8 APM DS data */
5194 ++
5195 ++ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
5196 ++ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
5197 ++ .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */
5198 ++ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */
5199 ++ .quad 0x0000000000000000 /* 0xf0 - unused */
5200 ++ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
5201 ++
5202 ++ /* Be sure this is zeroed to avoid false validations in Xen */
5203 ++ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
5204 ++ .endr
5205 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head64.c linux-2.6.27.10/arch/x86/kernel/head64.c
5206 +--- linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-07 12:55:34.000000000 -0500
5207 ++++ linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-18 03:38:44.000000000 -0500
5208 +@@ -93,6 +93,8 @@ void __init x86_64_start_kernel(char * r
5209 + /* clear bss before set_intr_gate with early_idt_handler */
5210 + clear_bss();
5211 +
5212 ++ x86_64_init_pda();
5213 ++
5214 + /* Make NULL pointers segfault */
5215 + zap_identity_mappings();
5216 +
5217 +@@ -110,8 +112,6 @@ void __init x86_64_start_kernel(char * r
5218 +
5219 + early_printk("Kernel alive\n");
5220 +
5221 +- x86_64_init_pda();
5222 +-
5223 + early_printk("Kernel really alive\n");
5224 +
5225 + x86_64_start_reservations(real_mode_data);
5226 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_64.S linux-2.6.27.10/arch/x86/kernel/head_64.S
5227 +--- linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-07 12:55:34.000000000 -0500
5228 ++++ linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-18 03:38:44.000000000 -0500
5229 +@@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
5230 + L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
5231 + L4_START_KERNEL = pgd_index(__START_KERNEL_map)
5232 + L3_START_KERNEL = pud_index(__START_KERNEL_map)
5233 ++L4_VMALLOC_START = pgd_index(VMALLOC_START)
5234 ++L3_VMALLOC_START = pud_index(VMALLOC_START)
5235 ++L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
5236 ++L3_VMEMMAP_START = pud_index(VMEMMAP_START)
5237 +
5238 + .text
5239 + .section .text.head
5240 +@@ -85,14 +89,17 @@ startup_64:
5241 + */
5242 + addq %rbp, init_level4_pgt + 0(%rip)
5243 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
5244 ++ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
5245 ++ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
5246 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
5247 +
5248 + addq %rbp, level3_ident_pgt + 0(%rip)
5249 +
5250 +- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
5251 +- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
5252 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
5253 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
5254 +
5255 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
5256 ++ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
5257 +
5258 + /* Add an Identity mapping if I am above 1G */
5259 + leaq _text(%rip), %rdi
5260 +@@ -187,6 +194,10 @@ ENTRY(secondary_startup_64)
5261 + btl $20,%edi /* No Execute supported? */
5262 + jnc 1f
5263 + btsl $_EFER_NX, %eax
5264 ++ leaq init_level4_pgt(%rip), %rdi
5265 ++ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
5266 ++ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
5267 ++ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
5268 + 1: wrmsr /* Make changes effective */
5269 +
5270 + /* Setup cr0 */
5271 +@@ -257,16 +268,16 @@ ENTRY(secondary_startup_64)
5272 + .align 8
5273 + ENTRY(initial_code)
5274 + .quad x86_64_start_kernel
5275 +- __FINITDATA
5276 +
5277 + ENTRY(stack_start)
5278 + .quad init_thread_union+THREAD_SIZE-8
5279 + .word 0
5280 ++ __FINITDATA
5281 +
5282 + bad_address:
5283 + jmp bad_address
5284 +
5285 +- .section ".init.text","ax"
5286 ++ __INIT
5287 + #ifdef CONFIG_EARLY_PRINTK
5288 + .globl early_idt_handlers
5289 + early_idt_handlers:
5290 +@@ -311,18 +322,23 @@ ENTRY(early_idt_handler)
5291 + #endif /* EARLY_PRINTK */
5292 + 1: hlt
5293 + jmp 1b
5294 ++ .previous
5295 +
5296 + #ifdef CONFIG_EARLY_PRINTK
5297 ++ __INITDATA
5298 + early_recursion_flag:
5299 + .long 0
5300 ++ .previous
5301 +
5302 ++ .section .rodata,"a",@progbits
5303 + early_idt_msg:
5304 + .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
5305 + early_idt_ripmsg:
5306 + .asciz "RIP %s\n"
5307 +-#endif /* CONFIG_EARLY_PRINTK */
5308 + .previous
5309 ++#endif /* CONFIG_EARLY_PRINTK */
5310 +
5311 ++ .section .rodata,"a",@progbits
5312 + .balign PAGE_SIZE
5313 +
5314 + #define NEXT_PAGE(name) \
5315 +@@ -347,6 +363,10 @@ NEXT_PAGE(init_level4_pgt)
5316 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5317 + .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
5318 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5319 ++ .org init_level4_pgt + L4_VMALLOC_START*8, 0
5320 ++ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
5321 ++ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
5322 ++ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
5323 + .org init_level4_pgt + L4_START_KERNEL*8, 0
5324 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
5325 + .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
5326 +@@ -355,6 +375,12 @@ NEXT_PAGE(level3_ident_pgt)
5327 + .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5328 + .fill 511,8,0
5329 +
5330 ++NEXT_PAGE(level3_vmalloc_pgt)
5331 ++ .fill 512,8,0
5332 ++
5333 ++NEXT_PAGE(level3_vmemmap_pgt)
5334 ++ .fill 512,8,0
5335 ++
5336 + NEXT_PAGE(level3_kernel_pgt)
5337 + .fill L3_START_KERNEL,8,0
5338 + /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
5339 +@@ -364,12 +390,16 @@ NEXT_PAGE(level3_kernel_pgt)
5340 + NEXT_PAGE(level2_fixmap_pgt)
5341 + .fill 506,8,0
5342 + .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
5343 +- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
5344 +- .fill 5,8,0
5345 ++ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
5346 ++ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
5347 ++ .fill 4,8,0
5348 +
5349 + NEXT_PAGE(level1_fixmap_pgt)
5350 + .fill 512,8,0
5351 +
5352 ++NEXT_PAGE(level1_vsyscall_pgt)
5353 ++ .fill 512,8,0
5354 ++
5355 + NEXT_PAGE(level2_ident_pgt)
5356 + /* Since I easily can, map the first 1G.
5357 + * Don't set NX because code runs from these pages.
5358 +@@ -396,19 +426,39 @@ NEXT_PAGE(level2_spare_pgt)
5359 + #undef PMDS
5360 + #undef NEXT_PAGE
5361 +
5362 +- .data
5363 ++ .align PAGE_SIZE
5364 ++ENTRY(cpu_gdt_table)
5365 ++ .rept NR_CPUS
5366 ++ .quad 0x0000000000000000 /* NULL descriptor */
5367 ++ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
5368 ++ .quad 0x00af9b000000ffff /* __KERNEL_CS */
5369 ++ .quad 0x00cf93000000ffff /* __KERNEL_DS */
5370 ++ .quad 0x00cffb000000ffff /* __USER32_CS */
5371 ++ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
5372 ++ .quad 0x00affb000000ffff /* __USER_CS */
5373 ++ .quad 0x0 /* unused */
5374 ++ .quad 0,0 /* TSS */
5375 ++ .quad 0,0 /* LDT */
5376 ++ .quad 0,0,0 /* three TLS descriptors */
5377 ++ .quad 0x0000f40000000000 /* node/CPU stored in limit */
5378 ++ /* asm/segment.h:GDT_ENTRIES must match this */
5379 ++
5380 ++ /* zero the remaining page */
5381 ++ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
5382 ++ .endr
5383 ++
5384 + .align 16
5385 + .globl early_gdt_descr
5386 + early_gdt_descr:
5387 + .word GDT_ENTRIES*8-1
5388 +- .quad per_cpu__gdt_page
5389 ++ .quad cpu_gdt_table
5390 +
5391 + ENTRY(phys_base)
5392 + /* This must match the first entry in level2_kernel_pgt */
5393 + .quad 0x0000000000000000
5394 +
5395 + #include "../../x86/xen/xen-head.S"
5396 +-
5397 ++
5398 + .section .bss, "aw", @nobits
5399 + .align L1_CACHE_BYTES
5400 + ENTRY(idt_table)
5401 +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
5402 +--- linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-07 12:55:34.000000000 -0500
5403 ++++ linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-18 03:38:44.000000000 -0500
5404 +@@ -10,8 +10,12 @@
5405 + EXPORT_SYMBOL(mcount);
5406 + #endif
5407 +
5408 ++EXPORT_SYMBOL_GPL(cpu_gdt_table);
5409 ++
5410 + /* Networking helper routines. */
5411 + EXPORT_SYMBOL(csum_partial_copy_generic);
5412 ++EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
5413 ++EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
5414 +
5415 + EXPORT_SYMBOL(__get_user_1);
5416 + EXPORT_SYMBOL(__get_user_2);
5417 +@@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr);
5418 +
5419 + EXPORT_SYMBOL(csum_partial);
5420 + EXPORT_SYMBOL(empty_zero_page);
5421 ++
5422 ++#ifdef CONFIG_PAX_KERNEXEC
5423 ++EXPORT_SYMBOL(KERNEL_TEXT_OFFSET);
5424 ++#endif
5425 +diff -urNp linux-2.6.27.10/arch/x86/kernel/init_task.c linux-2.6.27.10/arch/x86/kernel/init_task.c
5426 +--- linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-07 12:55:34.000000000 -0500
5427 ++++ linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-18 03:38:44.000000000 -0500
5428 +@@ -42,5 +42,5 @@ EXPORT_SYMBOL(init_task);
5429 + * section. Since TSS's are completely CPU-local, we want them
5430 + * on exact cacheline boundaries, to eliminate cacheline ping-pong.
5431 + */
5432 +-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
5433 +-
5434 ++struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
5435 ++EXPORT_SYMBOL(init_tss);
5436 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ioport.c linux-2.6.27.10/arch/x86/kernel/ioport.c
5437 +--- linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-07 12:55:34.000000000 -0500
5438 ++++ linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-18 03:38:44.000000000 -0500
5439 +@@ -14,6 +14,7 @@
5440 + #include <linux/slab.h>
5441 + #include <linux/thread_info.h>
5442 + #include <linux/syscalls.h>
5443 ++#include <linux/grsecurity.h>
5444 +
5445 + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
5446 + static void set_bitmap(unsigned long *bitmap, unsigned int base,
5447 +@@ -40,6 +41,12 @@ asmlinkage long sys_ioperm(unsigned long
5448 +
5449 + if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
5450 + return -EINVAL;
5451 ++#ifdef CONFIG_GRKERNSEC_IO
5452 ++ if (turn_on) {
5453 ++ gr_handle_ioperm();
5454 ++ return -EPERM;
5455 ++ }
5456 ++#endif
5457 + if (turn_on && !capable(CAP_SYS_RAWIO))
5458 + return -EPERM;
5459 +
5460 +@@ -66,7 +73,7 @@ asmlinkage long sys_ioperm(unsigned long
5461 + * because the ->io_bitmap_max value must match the bitmap
5462 + * contents:
5463 + */
5464 +- tss = &per_cpu(init_tss, get_cpu());
5465 ++ tss = init_tss + get_cpu();
5466 +
5467 + set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
5468 +
5469 +@@ -121,8 +128,13 @@ static int do_iopl(unsigned int level, s
5470 + return -EINVAL;
5471 + /* Trying to gain more privileges? */
5472 + if (level > old) {
5473 ++#ifdef CONFIG_GRKERNSEC_IO
5474 ++ gr_handle_iopl();
5475 ++ return -EPERM;
5476 ++#else
5477 + if (!capable(CAP_SYS_RAWIO))
5478 + return -EPERM;
5479 ++#endif
5480 + }
5481 + regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
5482 +
5483 +diff -urNp linux-2.6.27.10/arch/x86/kernel/irq_32.c linux-2.6.27.10/arch/x86/kernel/irq_32.c
5484 +--- linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-07 12:55:34.000000000 -0500
5485 ++++ linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-18 03:38:44.000000000 -0500
5486 +@@ -116,7 +116,7 @@ execute_on_irq_stack(int overflow, struc
5487 + return 0;
5488 +
5489 + /* build the stack frame on the IRQ stack */
5490 +- isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
5491 ++ isp = (u32 *) ((char*)irqctx + sizeof(*irqctx) - 8);
5492 + irqctx->tinfo.task = curctx->tinfo.task;
5493 + irqctx->tinfo.previous_esp = current_stack_pointer;
5494 +
5495 +@@ -197,7 +197,7 @@ asmlinkage void do_softirq(void)
5496 + irqctx->tinfo.previous_esp = current_stack_pointer;
5497 +
5498 + /* build the stack frame on the softirq stack */
5499 +- isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
5500 ++ isp = (u32*) ((char*)irqctx + sizeof(*irqctx) - 8);
5501 +
5502 + call_on_stack(__do_softirq, isp);
5503 + /*
5504 +diff -urNp linux-2.6.27.10/arch/x86/kernel/kprobes.c linux-2.6.27.10/arch/x86/kernel/kprobes.c
5505 +--- linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
5506 ++++ linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-18 04:48:35.000000000 -0500
5507 +@@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f
5508 + char op;
5509 + s32 raddr;
5510 + } __attribute__((packed)) * jop;
5511 +- jop = (struct __arch_jmp_op *)from;
5512 ++
5513 ++#ifdef CONFIG_PAX_KERNEXEC
5514 ++ unsigned long cr0;
5515 ++#endif
5516 ++
5517 ++ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
5518 ++
5519 ++#ifdef CONFIG_PAX_KERNEXEC
5520 ++ pax_open_kernel(cr0);
5521 ++#endif
5522 ++
5523 + jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
5524 + jop->op = RELATIVEJUMP_INSTRUCTION;
5525 ++
5526 ++#ifdef CONFIG_PAX_KERNEXEC
5527 ++ pax_close_kernel(cr0);
5528 ++#endif
5529 ++
5530 + }
5531 +
5532 + /*
5533 +@@ -342,16 +357,29 @@ static void __kprobes fix_riprel(struct
5534 +
5535 + static void __kprobes arch_copy_kprobe(struct kprobe *p)
5536 + {
5537 +- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5538 ++
5539 ++#ifdef CONFIG_PAX_KERNEXEC
5540 ++ unsigned long cr0;
5541 ++#endif
5542 ++
5543 ++#ifdef CONFIG_PAX_KERNEXEC
5544 ++ pax_open_kernel(cr0);
5545 ++#endif
5546 ++
5547 ++ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5548 ++
5549 ++#ifdef CONFIG_PAX_KERNEXEC
5550 ++ pax_close_kernel(cr0);
5551 ++#endif
5552 +
5553 + fix_riprel(p);
5554 +
5555 +- if (can_boost(p->addr))
5556 ++ if (can_boost(ktla_ktva(p->addr)))
5557 + p->ainsn.boostable = 0;
5558 + else
5559 + p->ainsn.boostable = -1;
5560 +
5561 +- p->opcode = *p->addr;
5562 ++ p->opcode = *(ktla_ktva(p->addr));
5563 + }
5564 +
5565 + int __kprobes arch_prepare_kprobe(struct kprobe *p)
5566 +@@ -428,7 +456,7 @@ static void __kprobes prepare_singlestep
5567 + if (p->opcode == BREAKPOINT_INSTRUCTION)
5568 + regs->ip = (unsigned long)p->addr;
5569 + else
5570 +- regs->ip = (unsigned long)p->ainsn.insn;
5571 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5572 + }
5573 +
5574 + void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
5575 +@@ -449,7 +477,7 @@ static void __kprobes setup_singlestep(s
5576 + if (p->ainsn.boostable == 1 && !p->post_handler) {
5577 + /* Boost up -- we can execute copied instructions directly */
5578 + reset_current_kprobe();
5579 +- regs->ip = (unsigned long)p->ainsn.insn;
5580 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5581 + preempt_enable_no_resched();
5582 + return;
5583 + }
5584 +@@ -519,7 +547,7 @@ static int __kprobes kprobe_handler(stru
5585 + struct kprobe_ctlblk *kcb;
5586 +
5587 + addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
5588 +- if (*addr != BREAKPOINT_INSTRUCTION) {
5589 ++ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
5590 + /*
5591 + * The breakpoint instruction was removed right
5592 + * after we hit it. Another cpu has removed
5593 +@@ -770,7 +798,7 @@ static void __kprobes resume_execution(s
5594 + struct pt_regs *regs, struct kprobe_ctlblk *kcb)
5595 + {
5596 + unsigned long *tos = stack_addr(regs);
5597 +- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
5598 ++ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
5599 + unsigned long orig_ip = (unsigned long)p->addr;
5600 + kprobe_opcode_t *insn = p->ainsn.insn;
5601 +
5602 +@@ -953,7 +981,7 @@ int __kprobes kprobe_exceptions_notify(s
5603 + struct die_args *args = data;
5604 + int ret = NOTIFY_DONE;
5605 +
5606 +- if (args->regs && user_mode_vm(args->regs))
5607 ++ if (args->regs && user_mode(args->regs))
5608 + return ret;
5609 +
5610 + switch (val) {
5611 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ldt.c linux-2.6.27.10/arch/x86/kernel/ldt.c
5612 +--- linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-07 12:55:34.000000000 -0500
5613 ++++ linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-18 03:38:44.000000000 -0500
5614 +@@ -63,13 +63,13 @@ static int alloc_ldt(mm_context_t *pc, i
5615 + if (reload) {
5616 + #ifdef CONFIG_SMP
5617 + preempt_disable();
5618 +- load_LDT(pc);
5619 ++ load_LDT_nolock(pc);
5620 + if (!cpus_equal(current->mm->cpu_vm_mask,
5621 + cpumask_of_cpu(smp_processor_id())))
5622 + smp_call_function(flush_ldt, current->mm, 1);
5623 + preempt_enable();
5624 + #else
5625 +- load_LDT(pc);
5626 ++ load_LDT_nolock(pc);
5627 + #endif
5628 + }
5629 + if (oldsize) {
5630 +@@ -108,6 +108,24 @@ int init_new_context(struct task_struct
5631 + retval = copy_ldt(&mm->context, &old_mm->context);
5632 + mutex_unlock(&old_mm->context.lock);
5633 + }
5634 ++
5635 ++ if (tsk == current) {
5636 ++ mm->context.vdso = ~0UL;
5637 ++
5638 ++#ifdef CONFIG_X86_32
5639 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
5640 ++ mm->context.user_cs_base = 0UL;
5641 ++ mm->context.user_cs_limit = ~0UL;
5642 ++
5643 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
5644 ++ cpus_clear(mm->context.cpu_user_cs_mask);
5645 ++#endif
5646 ++
5647 ++#endif
5648 ++#endif
5649 ++
5650 ++ }
5651 ++
5652 + return retval;
5653 + }
5654 +
5655 +@@ -221,6 +239,13 @@ static int write_ldt(void __user *ptr, u
5656 + }
5657 + }
5658 +
5659 ++#ifdef CONFIG_PAX_SEGMEXEC
5660 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
5661 ++ error = -EINVAL;
5662 ++ goto out_unlock;
5663 ++ }
5664 ++#endif
5665 ++
5666 + fill_ldt(&ldt, &ldt_info);
5667 + if (oldmode)
5668 + ldt.avl = 0;
5669 +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
5670 +--- linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-07 12:55:34.000000000 -0500
5671 ++++ linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-18 03:38:44.000000000 -0500
5672 +@@ -34,7 +34,7 @@ static u32 kexec_pmd1[1024] PAGE_ALIGNED
5673 + static u32 kexec_pte0[1024] PAGE_ALIGNED;
5674 + static u32 kexec_pte1[1024] PAGE_ALIGNED;
5675 +
5676 +-static void set_idt(void *newidt, __u16 limit)
5677 ++static void set_idt(struct desc_struct *newidt, __u16 limit)
5678 + {
5679 + struct desc_ptr curidt;
5680 +
5681 +@@ -46,7 +46,7 @@ static void set_idt(void *newidt, __u16
5682 + }
5683 +
5684 +
5685 +-static void set_gdt(void *newgdt, __u16 limit)
5686 ++static void set_gdt(struct desc_struct *newgdt, __u16 limit)
5687 + {
5688 + struct desc_ptr curgdt;
5689 +
5690 +@@ -145,7 +145,7 @@ void machine_kexec(struct kimage *image)
5691 + }
5692 +
5693 + control_page = page_address(image->control_code_page);
5694 +- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
5695 ++ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
5696 +
5697 + relocate_kernel_ptr = control_page;
5698 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
5699 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_32.c linux-2.6.27.10/arch/x86/kernel/module_32.c
5700 +--- linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
5701 ++++ linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-18 03:38:44.000000000 -0500
5702 +@@ -23,6 +23,9 @@
5703 + #include <linux/kernel.h>
5704 + #include <linux/bug.h>
5705 +
5706 ++#include <asm/desc.h>
5707 ++#include <asm/pgtable.h>
5708 ++
5709 + #if 0
5710 + #define DEBUGP printk
5711 + #else
5712 +@@ -33,9 +36,31 @@ void *module_alloc(unsigned long size)
5713 + {
5714 + if (size == 0)
5715 + return NULL;
5716 ++
5717 ++#ifdef CONFIG_PAX_KERNEXEC
5718 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
5719 ++#else
5720 + return vmalloc_exec(size);
5721 ++#endif
5722 ++
5723 + }
5724 +
5725 ++#ifdef CONFIG_PAX_KERNEXEC
5726 ++void *module_alloc_exec(unsigned long size)
5727 ++{
5728 ++ struct vm_struct *area;
5729 ++
5730 ++ if (size == 0)
5731 ++ return NULL;
5732 ++
5733 ++ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END);
5734 ++ if (area)
5735 ++ return area->addr;
5736 ++
5737 ++ return NULL;
5738 ++}
5739 ++EXPORT_SYMBOL(module_alloc_exec);
5740 ++#endif
5741 +
5742 + /* Free memory returned from module_alloc */
5743 + void module_free(struct module *mod, void *module_region)
5744 +@@ -45,6 +70,45 @@ void module_free(struct module *mod, voi
5745 + table entries. */
5746 + }
5747 +
5748 ++#ifdef CONFIG_PAX_KERNEXEC
5749 ++void module_free_exec(struct module *mod, void *module_region)
5750 ++{
5751 ++ struct vm_struct **p, *tmp;
5752 ++
5753 ++ if (!module_region)
5754 ++ return;
5755 ++
5756 ++ if ((PAGE_SIZE-1) & (unsigned long)module_region) {
5757 ++ printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region);
5758 ++ WARN_ON(1);
5759 ++ return;
5760 ++ }
5761 ++
5762 ++ write_lock(&vmlist_lock);
5763 ++ for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next)
5764 ++ if (tmp->addr == module_region)
5765 ++ break;
5766 ++
5767 ++ if (tmp) {
5768 ++ unsigned long cr0;
5769 ++
5770 ++ pax_open_kernel(cr0);
5771 ++ memset(tmp->addr, 0xCC, tmp->size);
5772 ++ pax_close_kernel(cr0);
5773 ++
5774 ++ *p = tmp->next;
5775 ++ kfree(tmp);
5776 ++ }
5777 ++ write_unlock(&vmlist_lock);
5778 ++
5779 ++ if (!tmp) {
5780 ++ printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n",
5781 ++ module_region);
5782 ++ WARN_ON(1);
5783 ++ }
5784 ++}
5785 ++#endif
5786 ++
5787 + /* We don't need anything special. */
5788 + int module_frob_arch_sections(Elf_Ehdr *hdr,
5789 + Elf_Shdr *sechdrs,
5790 +@@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5791 + unsigned int i;
5792 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
5793 + Elf32_Sym *sym;
5794 +- uint32_t *location;
5795 ++ uint32_t *plocation, location;
5796 ++
5797 ++#ifdef CONFIG_PAX_KERNEXEC
5798 ++ unsigned long cr0;
5799 ++#endif
5800 +
5801 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5802 + sechdrs[relsec].sh_info);
5803 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
5804 + /* This is where to make the change */
5805 +- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
5806 +- + rel[i].r_offset;
5807 ++ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
5808 ++ location = (uint32_t)plocation;
5809 ++ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
5810 ++ plocation = ktla_ktva((void *)plocation);
5811 + /* This is the symbol it is referring to. Note that all
5812 + undefined symbols have been resolved. */
5813 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
5814 +@@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5815 +
5816 + switch (ELF32_R_TYPE(rel[i].r_info)) {
5817 + case R_386_32:
5818 ++
5819 ++#ifdef CONFIG_PAX_KERNEXEC
5820 ++ pax_open_kernel(cr0);
5821 ++#endif
5822 ++
5823 + /* We add the value into the location given */
5824 +- *location += sym->st_value;
5825 ++ *plocation += sym->st_value;
5826 ++
5827 ++#ifdef CONFIG_PAX_KERNEXEC
5828 ++ pax_close_kernel(cr0);
5829 ++#endif
5830 ++
5831 + break;
5832 + case R_386_PC32:
5833 ++
5834 ++#ifdef CONFIG_PAX_KERNEXEC
5835 ++ pax_open_kernel(cr0);
5836 ++#endif
5837 ++
5838 + /* Add the value, subtract its postition */
5839 +- *location += sym->st_value - (uint32_t)location;
5840 ++ *plocation += sym->st_value - location;
5841 ++
5842 ++#ifdef CONFIG_PAX_KERNEXEC
5843 ++ pax_close_kernel(cr0);
5844 ++#endif
5845 ++
5846 + break;
5847 + default:
5848 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
5849 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_64.c linux-2.6.27.10/arch/x86/kernel/module_64.c
5850 +--- linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-07 12:55:34.000000000 -0500
5851 ++++ linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-18 03:38:44.000000000 -0500
5852 +@@ -40,7 +40,7 @@ void module_free(struct module *mod, voi
5853 + table entries. */
5854 + }
5855 +
5856 +-void *module_alloc(unsigned long size)
5857 ++static void *__module_alloc(unsigned long size, pgprot_t prot)
5858 + {
5859 + struct vm_struct *area;
5860 +
5861 +@@ -54,8 +54,31 @@ void *module_alloc(unsigned long size)
5862 + if (!area)
5863 + return NULL;
5864 +
5865 +- return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
5866 ++ return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot);
5867 ++}
5868 ++
5869 ++#ifdef CONFIG_PAX_KERNEXEC
5870 ++void *module_alloc(unsigned long size)
5871 ++{
5872 ++ return __module_alloc(size, PAGE_KERNEL);
5873 ++}
5874 ++
5875 ++void module_free_exec(struct module *mod, void *module_region)
5876 ++{
5877 ++ module_free(mod, module_region);
5878 ++}
5879 ++
5880 ++void *module_alloc_exec(unsigned long size)
5881 ++{
5882 ++ return __module_alloc(size, PAGE_KERNEL_RX);
5883 + }
5884 ++#else
5885 ++void *module_alloc(unsigned long size)
5886 ++{
5887 ++ return __module_alloc(size, PAGE_KERNEL_EXEC);
5888 ++}
5889 ++#endif
5890 ++
5891 + #endif
5892 +
5893 + /* We don't need anything special. */
5894 +@@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
5895 + Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
5896 + Elf64_Sym *sym;
5897 + void *loc;
5898 +- u64 val;
5899 ++ u64 val;
5900 ++
5901 ++#ifdef CONFIG_PAX_KERNEXEC
5902 ++ unsigned long cr0;
5903 ++#endif
5904 +
5905 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5906 + sechdrs[relsec].sh_info);
5907 +@@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd
5908 + case R_X86_64_NONE:
5909 + break;
5910 + case R_X86_64_64:
5911 ++
5912 ++#ifdef CONFIG_PAX_KERNEXEC
5913 ++ pax_open_kernel(cr0);
5914 ++#endif
5915 ++
5916 + *(u64 *)loc = val;
5917 ++
5918 ++#ifdef CONFIG_PAX_KERNEXEC
5919 ++ pax_close_kernel(cr0);
5920 ++#endif
5921 ++
5922 + break;
5923 + case R_X86_64_32:
5924 ++
5925 ++#ifdef CONFIG_PAX_KERNEXEC
5926 ++ pax_open_kernel(cr0);
5927 ++#endif
5928 ++
5929 + *(u32 *)loc = val;
5930 ++
5931 ++#ifdef CONFIG_PAX_KERNEXEC
5932 ++ pax_close_kernel(cr0);
5933 ++#endif
5934 ++
5935 + if (val != *(u32 *)loc)
5936 + goto overflow;
5937 + break;
5938 + case R_X86_64_32S:
5939 ++
5940 ++#ifdef CONFIG_PAX_KERNEXEC
5941 ++ pax_open_kernel(cr0);
5942 ++#endif
5943 ++
5944 + *(s32 *)loc = val;
5945 ++
5946 ++#ifdef CONFIG_PAX_KERNEXEC
5947 ++ pax_close_kernel(cr0);
5948 ++#endif
5949 ++
5950 + if ((s64)val != *(s32 *)loc)
5951 + goto overflow;
5952 + break;
5953 + case R_X86_64_PC32:
5954 + val -= (u64)loc;
5955 ++
5956 ++#ifdef CONFIG_PAX_KERNEXEC
5957 ++ pax_open_kernel(cr0);
5958 ++#endif
5959 ++
5960 + *(u32 *)loc = val;
5961 ++
5962 ++#ifdef CONFIG_PAX_KERNEXEC
5963 ++ pax_close_kernel(cr0);
5964 ++#endif
5965 ++
5966 + #if 0
5967 + if ((s64)val != *(s32 *)loc)
5968 + goto overflow;
5969 +diff -urNp linux-2.6.27.10/arch/x86/kernel/paravirt.c linux-2.6.27.10/arch/x86/kernel/paravirt.c
5970 +--- linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-07 12:55:34.000000000 -0500
5971 ++++ linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-18 03:38:44.000000000 -0500
5972 +@@ -44,7 +44,7 @@ void _paravirt_nop(void)
5973 + {
5974 + }
5975 +
5976 +-static void __init default_banner(void)
5977 ++static void default_banner(void)
5978 + {
5979 + printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
5980 + pv_info.name);
5981 +@@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn
5982 + if (insn_len > len || start == NULL)
5983 + insn_len = len;
5984 + else
5985 +- memcpy(insnbuf, start, insn_len);
5986 ++ memcpy(insnbuf, ktla_ktva(start), insn_len);
5987 +
5988 + return insn_len;
5989 + }
5990 +@@ -279,21 +279,21 @@ void __init paravirt_use_bytelocks(void)
5991 + #endif
5992 + }
5993 +
5994 +-struct pv_info pv_info = {
5995 ++struct pv_info pv_info __read_only = {
5996 + .name = "bare hardware",
5997 + .paravirt_enabled = 0,
5998 + .kernel_rpl = 0,
5999 + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
6000 + };
6001 +
6002 +-struct pv_init_ops pv_init_ops = {
6003 ++struct pv_init_ops pv_init_ops __read_only = {
6004 + .patch = native_patch,
6005 + .banner = default_banner,
6006 + .arch_setup = paravirt_nop,
6007 + .memory_setup = machine_specific_memory_setup,
6008 + };
6009 +
6010 +-struct pv_time_ops pv_time_ops = {
6011 ++struct pv_time_ops pv_time_ops __read_only = {
6012 + .time_init = hpet_time_init,
6013 + .get_wallclock = native_get_wallclock,
6014 + .set_wallclock = native_set_wallclock,
6015 +@@ -301,7 +301,7 @@ struct pv_time_ops pv_time_ops = {
6016 + .get_tsc_khz = native_calibrate_tsc,
6017 + };
6018 +
6019 +-struct pv_irq_ops pv_irq_ops = {
6020 ++struct pv_irq_ops pv_irq_ops __read_only = {
6021 + .init_IRQ = native_init_IRQ,
6022 + .save_fl = native_save_fl,
6023 + .restore_fl = native_restore_fl,
6024 +@@ -314,7 +314,7 @@ struct pv_irq_ops pv_irq_ops = {
6025 + #endif
6026 + };
6027 +
6028 +-struct pv_cpu_ops pv_cpu_ops = {
6029 ++struct pv_cpu_ops pv_cpu_ops __read_only = {
6030 + .cpuid = native_cpuid,
6031 + .get_debugreg = native_get_debugreg,
6032 + .set_debugreg = native_set_debugreg,
6033 +@@ -371,7 +371,7 @@ struct pv_cpu_ops pv_cpu_ops = {
6034 + },
6035 + };
6036 +
6037 +-struct pv_apic_ops pv_apic_ops = {
6038 ++struct pv_apic_ops pv_apic_ops __read_only = {
6039 + #ifdef CONFIG_X86_LOCAL_APIC
6040 + .apic_write = native_apic_write,
6041 + .apic_read = native_apic_read,
6042 +@@ -381,7 +381,7 @@ struct pv_apic_ops pv_apic_ops = {
6043 + #endif
6044 + };
6045 +
6046 +-struct pv_mmu_ops pv_mmu_ops = {
6047 ++struct pv_mmu_ops pv_mmu_ops __read_only = {
6048 + #ifndef CONFIG_X86_64
6049 + .pagetable_setup_start = native_pagetable_setup_start,
6050 + .pagetable_setup_done = native_pagetable_setup_done,
6051 +@@ -461,7 +461,7 @@ struct pv_mmu_ops pv_mmu_ops = {
6052 + .set_fixmap = native_set_fixmap,
6053 + };
6054 +
6055 +-struct pv_lock_ops pv_lock_ops = {
6056 ++struct pv_lock_ops pv_lock_ops __read_only = {
6057 + #ifdef CONFIG_SMP
6058 + .spin_is_locked = __ticket_spin_is_locked,
6059 + .spin_is_contended = __ticket_spin_is_contended,
6060 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_32.c linux-2.6.27.10/arch/x86/kernel/process_32.c
6061 +--- linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-07 12:55:34.000000000 -0500
6062 ++++ linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-18 03:38:44.000000000 -0500
6063 +@@ -62,8 +62,10 @@ asmlinkage void ret_from_fork(void) __as
6064 + DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
6065 + EXPORT_PER_CPU_SYMBOL(current_task);
6066 +
6067 ++#ifdef CONFIG_SMP
6068 + DEFINE_PER_CPU(int, cpu_number);
6069 + EXPORT_PER_CPU_SYMBOL(cpu_number);
6070 ++#endif
6071 +
6072 + /*
6073 + * Return saved PC of a blocked thread.
6074 +@@ -71,6 +73,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
6075 + unsigned long thread_saved_pc(struct task_struct *tsk)
6076 + {
6077 + return ((unsigned long *)tsk->thread.sp)[3];
6078 ++//XXX return tsk->thread.eip;
6079 + }
6080 +
6081 + #ifdef CONFIG_HOTPLUG_CPU
6082 +@@ -162,7 +165,7 @@ void __show_registers(struct pt_regs *re
6083 + unsigned long sp;
6084 + unsigned short ss, gs;
6085 +
6086 +- if (user_mode_vm(regs)) {
6087 ++ if (user_mode(regs)) {
6088 + sp = regs->sp;
6089 + ss = regs->ss & 0xffff;
6090 + savesegment(gs, gs);
6091 +@@ -239,8 +242,8 @@ int kernel_thread(int (*fn)(void *), voi
6092 + regs.bx = (unsigned long) fn;
6093 + regs.dx = (unsigned long) arg;
6094 +
6095 +- regs.ds = __USER_DS;
6096 +- regs.es = __USER_DS;
6097 ++ regs.ds = __KERNEL_DS;
6098 ++ regs.es = __KERNEL_DS;
6099 + regs.fs = __KERNEL_PERCPU;
6100 + regs.orig_ax = -1;
6101 + regs.ip = (unsigned long) kernel_thread_helper;
6102 +@@ -262,7 +265,7 @@ void exit_thread(void)
6103 + struct task_struct *tsk = current;
6104 + struct thread_struct *t = &tsk->thread;
6105 + int cpu = get_cpu();
6106 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6107 ++ struct tss_struct *tss = init_tss + cpu;
6108 +
6109 + kfree(t->io_bitmap_ptr);
6110 + t->io_bitmap_ptr = NULL;
6111 +@@ -283,6 +286,7 @@ void flush_thread(void)
6112 + {
6113 + struct task_struct *tsk = current;
6114 +
6115 ++ loadsegment(gs, 0);
6116 + tsk->thread.debugreg0 = 0;
6117 + tsk->thread.debugreg1 = 0;
6118 + tsk->thread.debugreg2 = 0;
6119 +@@ -322,7 +326,7 @@ int copy_thread(int nr, unsigned long cl
6120 + struct task_struct *tsk;
6121 + int err;
6122 +
6123 +- childregs = task_pt_regs(p);
6124 ++ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
6125 + *childregs = *regs;
6126 + childregs->ax = 0;
6127 + childregs->sp = sp;
6128 +@@ -351,6 +355,7 @@ int copy_thread(int nr, unsigned long cl
6129 + * Set a new TLS for the child thread?
6130 + */
6131 + if (clone_flags & CLONE_SETTLS)
6132 ++//XXX needs set_fs()?
6133 + err = do_set_thread_area(p, -1,
6134 + (struct user_desc __user *)childregs->si, 0);
6135 +
6136 +@@ -550,7 +555,7 @@ struct task_struct * __switch_to(struct
6137 + struct thread_struct *prev = &prev_p->thread,
6138 + *next = &next_p->thread;
6139 + int cpu = smp_processor_id();
6140 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6141 ++ struct tss_struct *tss = init_tss + cpu;
6142 +
6143 + /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
6144 +
6145 +@@ -578,6 +583,11 @@ struct task_struct * __switch_to(struct
6146 + */
6147 + savesegment(gs, prev->gs);
6148 +
6149 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
6150 ++ if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit))
6151 ++ __set_fs(task_thread_info(next_p)->addr_limit, cpu);
6152 ++#endif
6153 ++
6154 + /*
6155 + * Load the per-thread Thread-Local Storage descriptor.
6156 + */
6157 +@@ -716,15 +726,27 @@ unsigned long get_wchan(struct task_stru
6158 + return 0;
6159 + }
6160 +
6161 +-unsigned long arch_align_stack(unsigned long sp)
6162 ++#ifdef CONFIG_PAX_RANDKSTACK
6163 ++asmlinkage void pax_randomize_kstack(void)
6164 + {
6165 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6166 +- sp -= get_random_int() % 8192;
6167 +- return sp & ~0xf;
6168 +-}
6169 ++ struct thread_struct *thread = &current->thread;
6170 ++ unsigned long time;
6171 +
6172 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6173 +-{
6174 +- unsigned long range_end = mm->brk + 0x02000000;
6175 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6176 ++ if (!randomize_va_space)
6177 ++ return;
6178 ++
6179 ++ rdtscl(time);
6180 ++
6181 ++ /* P4 seems to return a 0 LSB, ignore it */
6182 ++#ifdef CONFIG_MPENTIUM4
6183 ++ time &= 0x1EUL;
6184 ++ time <<= 2;
6185 ++#else
6186 ++ time &= 0xFUL;
6187 ++ time <<= 3;
6188 ++#endif
6189 ++
6190 ++ thread->sp0 ^= time;
6191 ++ load_sp0(init_tss + smp_processor_id(), thread);
6192 + }
6193 ++#endif
6194 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_64.c linux-2.6.27.10/arch/x86/kernel/process_64.c
6195 +--- linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-07 12:55:34.000000000 -0500
6196 ++++ linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-18 03:38:44.000000000 -0500
6197 +@@ -119,6 +119,8 @@ static inline void play_dead(void)
6198 + void cpu_idle(void)
6199 + {
6200 + current_thread_info()->status |= TS_POLLING;
6201 ++ current->stack_canary = pax_get_random_long();
6202 ++ write_pda(stack_canary, current->stack_canary);
6203 + /* endless idle loop with no priority at all */
6204 + while (1) {
6205 + tick_nohz_stop_sched_tick(1);
6206 +@@ -228,7 +230,7 @@ void exit_thread(void)
6207 + struct thread_struct *t = &me->thread;
6208 +
6209 + if (me->thread.io_bitmap_ptr) {
6210 +- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
6211 ++ struct tss_struct *tss = init_tss + get_cpu();
6212 +
6213 + kfree(t->io_bitmap_ptr);
6214 + t->io_bitmap_ptr = NULL;
6215 +@@ -541,7 +543,7 @@ __switch_to(struct task_struct *prev_p,
6216 + struct thread_struct *prev = &prev_p->thread;
6217 + struct thread_struct *next = &next_p->thread;
6218 + int cpu = smp_processor_id();
6219 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6220 ++ struct tss_struct *tss = init_tss + cpu;
6221 + unsigned fsindex, gsindex;
6222 +
6223 + /* we're going to use this soon, after a few expensive things */
6224 +@@ -630,7 +632,6 @@ __switch_to(struct task_struct *prev_p,
6225 + (unsigned long)task_stack_page(next_p) +
6226 + THREAD_SIZE - PDA_STACKOFFSET);
6227 + #ifdef CONFIG_CC_STACKPROTECTOR
6228 +- write_pda(stack_canary, next_p->stack_canary);
6229 + /*
6230 + * Build time only check to make sure the stack_canary is at
6231 + * offset 40 in the pda; this is a gcc ABI requirement
6232 +@@ -729,12 +730,11 @@ unsigned long get_wchan(struct task_stru
6233 + if (!p || p == current || p->state==TASK_RUNNING)
6234 + return 0;
6235 + stack = (unsigned long)task_stack_page(p);
6236 +- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
6237 ++ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
6238 + return 0;
6239 + fp = *(u64 *)(p->thread.sp);
6240 + do {
6241 +- if (fp < (unsigned long)stack ||
6242 +- fp >= (unsigned long)stack+THREAD_SIZE)
6243 ++ if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
6244 + return 0;
6245 + ip = *(u64 *)(fp+8);
6246 + if (!in_sched_functions(ip))
6247 +@@ -844,16 +844,3 @@ long sys_arch_prctl(int code, unsigned l
6248 + {
6249 + return do_arch_prctl(current, code, addr);
6250 + }
6251 +-
6252 +-unsigned long arch_align_stack(unsigned long sp)
6253 +-{
6254 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6255 +- sp -= get_random_int() % 8192;
6256 +- return sp & ~0xf;
6257 +-}
6258 +-
6259 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6260 +-{
6261 +- unsigned long range_end = mm->brk + 0x02000000;
6262 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6263 +-}
6264 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ptrace.c linux-2.6.27.10/arch/x86/kernel/ptrace.c
6265 +--- linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
6266 ++++ linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-18 03:38:44.000000000 -0500
6267 +@@ -1369,7 +1369,7 @@ void send_sigtrap(struct task_struct *ts
6268 + info.si_code = TRAP_BRKPT;
6269 +
6270 + /* User-mode ip? */
6271 +- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
6272 ++ info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL;
6273 +
6274 + /* Send us the fake SIGTRAP */
6275 + force_sig_info(SIGTRAP, &info, tsk);
6276 +diff -urNp linux-2.6.27.10/arch/x86/kernel/reboot.c linux-2.6.27.10/arch/x86/kernel/reboot.c
6277 +--- linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-07 12:55:34.000000000 -0500
6278 ++++ linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-18 03:38:44.000000000 -0500
6279 +@@ -28,7 +28,7 @@ void (*pm_power_off)(void);
6280 + EXPORT_SYMBOL(pm_power_off);
6281 +
6282 + static const struct desc_ptr no_idt = {};
6283 +-static int reboot_mode;
6284 ++static unsigned short reboot_mode;
6285 + enum reboot_type reboot_type = BOOT_KBD;
6286 + int reboot_force;
6287 +
6288 +@@ -193,7 +193,7 @@ static struct dmi_system_id __initdata r
6289 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
6290 + },
6291 + },
6292 +- { }
6293 ++ { NULL, NULL, {{0, NULL}}, NULL}
6294 + };
6295 +
6296 + static int __init reboot_init(void)
6297 +@@ -209,12 +209,12 @@ core_initcall(reboot_init);
6298 + controller to pulse the CPU reset line, which is more thorough, but
6299 + doesn't work with at least one type of 486 motherboard. It is easy
6300 + to stop this code working; hence the copious comments. */
6301 +-static const unsigned long long
6302 +-real_mode_gdt_entries [3] =
6303 ++static struct desc_struct
6304 ++real_mode_gdt_entries [3] __read_only =
6305 + {
6306 +- 0x0000000000000000ULL, /* Null descriptor */
6307 +- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
6308 +- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
6309 ++ {{{0x00000000, 0x00000000}}}, /* Null descriptor */
6310 ++ {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */
6311 ++ {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */
6312 + };
6313 +
6314 + static const struct desc_ptr
6315 +@@ -263,7 +263,7 @@ static const unsigned char jump_to_bios
6316 + * specified by the code and length parameters.
6317 + * We assume that length will aways be less that 100!
6318 + */
6319 +-void machine_real_restart(const unsigned char *code, int length)
6320 ++void machine_real_restart(const unsigned char *code, unsigned int length)
6321 + {
6322 + local_irq_disable();
6323 +
6324 +@@ -283,8 +283,8 @@ void machine_real_restart(const unsigned
6325 + /* Remap the kernel at virtual address zero, as well as offset zero
6326 + from the kernel segment. This assumes the kernel segment starts at
6327 + virtual address PAGE_OFFSET. */
6328 +- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6329 +- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
6330 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6331 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
6332 +
6333 + /*
6334 + * Use `swapper_pg_dir' as our page directory.
6335 +@@ -296,16 +296,15 @@ void machine_real_restart(const unsigned
6336 + boot)". This seems like a fairly standard thing that gets set by
6337 + REBOOT.COM programs, and the previous reset routine did this
6338 + too. */
6339 +- *((unsigned short *)0x472) = reboot_mode;
6340 ++ *(unsigned short *)(__va(0x472)) = reboot_mode;
6341 +
6342 + /* For the switch to real mode, copy some code to low memory. It has
6343 + to be in the first 64k because it is running in 16-bit mode, and it
6344 + has to have the same physical and virtual address, because it turns
6345 + off paging. Copy it near the end of the first page, out of the way
6346 + of BIOS variables. */
6347 +- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
6348 +- real_mode_switch, sizeof (real_mode_switch));
6349 +- memcpy((void *)(0x1000 - 100), code, length);
6350 ++ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
6351 ++ memcpy(__va(0x1000 - 100), code, length);
6352 +
6353 + /* Set up the IDT for real mode. */
6354 + load_idt(&real_mode_idt);
6355 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup.c linux-2.6.27.10/arch/x86/kernel/setup.c
6356 +--- linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:11.000000000 -0500
6357 ++++ linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:21.000000000 -0500
6358 +@@ -578,6 +578,7 @@ static struct x86_quirks default_x86_qui
6359 +
6360 + struct x86_quirks *x86_quirks __initdata = &default_x86_quirks;
6361 +
6362 ++#ifdef CONFIG_X86_RESERVE_LOW_64K
6363 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
6364 + {
6365 + printk(KERN_NOTICE
6366 +@@ -589,6 +590,7 @@ static int __init dmi_low_memory_corrupt
6367 +
6368 + return 0;
6369 + }
6370 ++#endif
6371 +
6372 + /* List of systems that have known low memory corruption BIOS problems */
6373 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
6374 +@@ -685,8 +687,8 @@ void __init setup_arch(char **cmdline_p)
6375 +
6376 + if (!boot_params.hdr.root_flags)
6377 + root_mountflags &= ~MS_RDONLY;
6378 +- init_mm.start_code = (unsigned long) _text;
6379 +- init_mm.end_code = (unsigned long) _etext;
6380 ++ init_mm.start_code = ktla_ktva((unsigned long) _text);
6381 ++ init_mm.end_code = ktla_ktva((unsigned long) _etext);
6382 + init_mm.end_data = (unsigned long) _edata;
6383 + #ifdef CONFIG_X86_32
6384 + init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
6385 +@@ -694,9 +696,9 @@ void __init setup_arch(char **cmdline_p)
6386 + init_mm.brk = (unsigned long) &_end;
6387 + #endif
6388 +
6389 +- code_resource.start = virt_to_phys(_text);
6390 +- code_resource.end = virt_to_phys(_etext)-1;
6391 +- data_resource.start = virt_to_phys(_etext);
6392 ++ code_resource.start = virt_to_phys(ktla_ktva(_text));
6393 ++ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
6394 ++ data_resource.start = virt_to_phys(_data);
6395 + data_resource.end = virt_to_phys(_edata)-1;
6396 + bss_resource.start = virt_to_phys(&__bss_start);
6397 + bss_resource.end = virt_to_phys(&__bss_stop)-1;
6398 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup_percpu.c linux-2.6.27.10/arch/x86/kernel/setup_percpu.c
6399 +--- linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-07 12:55:34.000000000 -0500
6400 ++++ linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-18 03:38:44.000000000 -0500
6401 +@@ -166,7 +166,11 @@ void __init setup_per_cpu_areas(void)
6402 + else
6403 + ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
6404 + #endif
6405 ++#ifdef CONFIG_X86_32
6406 ++ __per_cpu_offset[cpu] = ptr - __per_cpu_start;
6407 ++#else
6408 + per_cpu_offset(cpu) = ptr - __per_cpu_start;
6409 ++#endif
6410 + memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
6411 +
6412 + }
6413 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_32.c linux-2.6.27.10/arch/x86/kernel/signal_32.c
6414 +--- linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
6415 ++++ linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-18 03:38:44.000000000 -0500
6416 +@@ -378,9 +378,9 @@ setup_frame(int sig, struct k_sigaction
6417 + }
6418 +
6419 + if (current->mm->context.vdso)
6420 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6421 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6422 + else
6423 +- restorer = &frame->retcode;
6424 ++ restorer = (void __user *)&frame->retcode;
6425 + if (ka->sa.sa_flags & SA_RESTORER)
6426 + restorer = ka->sa.sa_restorer;
6427 +
6428 +@@ -460,7 +460,7 @@ static int setup_rt_frame(int sig, struc
6429 + goto give_sigsegv;
6430 +
6431 + /* Set up to return from userspace. */
6432 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6433 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6434 + if (ka->sa.sa_flags & SA_RESTORER)
6435 + restorer = ka->sa.sa_restorer;
6436 + err |= __put_user(restorer, &frame->pretcode);
6437 +@@ -590,7 +590,7 @@ static void do_signal(struct pt_regs *re
6438 + * X86_32: vm86 regs switched out by assembly code before reaching
6439 + * here, so testing against kernel CS suffices.
6440 + */
6441 +- if (!user_mode(regs))
6442 ++ if (!user_mode_novm(regs))
6443 + return;
6444 +
6445 + if (current_thread_info()->status & TS_RESTORE_SIGMASK)
6446 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_64.c linux-2.6.27.10/arch/x86/kernel/signal_64.c
6447 +--- linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
6448 ++++ linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-18 03:38:44.000000000 -0500
6449 +@@ -312,8 +312,8 @@ static int setup_rt_frame(int sig, struc
6450 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
6451 + err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
6452 + if (sizeof(*set) == 16) {
6453 +- __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6454 +- __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6455 ++ err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6456 ++ err |= __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6457 + } else
6458 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
6459 +
6460 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpboot.c linux-2.6.27.10/arch/x86/kernel/smpboot.c
6461 +--- linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:11.000000000 -0500
6462 ++++ linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:21.000000000 -0500
6463 +@@ -814,6 +814,11 @@ static int __cpuinit do_boot_cpu(int api
6464 + .cpu = cpu,
6465 + .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
6466 + };
6467 ++
6468 ++#ifdef CONFIG_PAX_KERNEXEC
6469 ++ unsigned long cr0;
6470 ++#endif
6471 ++
6472 + INIT_WORK(&c_idle.work, do_fork_idle);
6473 +
6474 + #ifdef CONFIG_X86_64
6475 +@@ -864,7 +869,17 @@ do_rest:
6476 + cpu_pda(cpu)->pcurrent = c_idle.idle;
6477 + clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
6478 + #endif
6479 ++
6480 ++#ifdef CONFIG_PAX_KERNEXEC
6481 ++ pax_open_kernel(cr0);
6482 ++#endif
6483 ++
6484 + early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
6485 ++
6486 ++#ifdef CONFIG_PAX_KERNEXEC
6487 ++ pax_close_kernel(cr0);
6488 ++#endif
6489 ++
6490 + initial_code = (unsigned long)start_secondary;
6491 + stack_start.sp = (void *) c_idle.idle->thread.sp;
6492 +
6493 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpcommon.c linux-2.6.27.10/arch/x86/kernel/smpcommon.c
6494 +--- linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-07 12:55:34.000000000 -0500
6495 ++++ linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-18 03:38:44.000000000 -0500
6496 +@@ -3,9 +3,10 @@
6497 + */
6498 + #include <linux/module.h>
6499 + #include <asm/smp.h>
6500 ++#include <asm/sections.h>
6501 +
6502 + #ifdef CONFIG_X86_32
6503 +-DEFINE_PER_CPU(unsigned long, this_cpu_off);
6504 ++DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start;
6505 + EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6506 +
6507 + /*
6508 +@@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6509 + */
6510 + __cpuinit void init_gdt(int cpu)
6511 + {
6512 +- struct desc_struct gdt;
6513 ++ struct desc_struct d, *gdt = get_cpu_gdt_table(cpu);
6514 ++ unsigned long base, limit;
6515 +
6516 +- pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF,
6517 +- 0x2 | DESCTYPE_S, 0x8);
6518 +- gdt.s = 1;
6519 ++ base = per_cpu_offset(cpu);
6520 ++ limit = PERCPU_ENOUGH_ROOM - 1;
6521 ++ if (limit < 64*1024)
6522 ++ pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4);
6523 ++ else
6524 ++ pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC);
6525 +
6526 +- write_gdt_entry(get_cpu_gdt_table(cpu),
6527 +- GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
6528 ++ write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
6529 +
6530 +- per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
6531 ++ per_cpu(this_cpu_off, cpu) = base;
6532 + per_cpu(cpu_number, cpu) = cpu;
6533 + }
6534 + #endif
6535 +diff -urNp linux-2.6.27.10/arch/x86/kernel/step.c linux-2.6.27.10/arch/x86/kernel/step.c
6536 +--- linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-07 12:55:34.000000000 -0500
6537 ++++ linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-18 03:38:44.000000000 -0500
6538 +@@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc
6539 + * and APM bios ones we just ignore here.
6540 + */
6541 + if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) {
6542 +- u32 *desc;
6543 ++ struct desc_struct *desc;
6544 + unsigned long base;
6545 +
6546 +- seg &= ~7UL;
6547 ++ seg >>= 3;
6548 +
6549 + mutex_lock(&child->mm->context.lock);
6550 +- if (unlikely((seg >> 3) >= child->mm->context.size))
6551 +- addr = -1L; /* bogus selector, access would fault */
6552 ++ if (unlikely(seg >= child->mm->context.size))
6553 ++ addr = -EINVAL;
6554 + else {
6555 +- desc = child->mm->context.ldt + seg;
6556 +- base = ((desc[0] >> 16) |
6557 +- ((desc[1] & 0xff) << 16) |
6558 +- (desc[1] & 0xff000000));
6559 ++ desc = &child->mm->context.ldt[seg];
6560 ++ base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000);
6561 +
6562 + /* 16-bit code segment? */
6563 +- if (!((desc[1] >> 22) & 1))
6564 ++ if (!((desc->b >> 22) & 1))
6565 + addr &= 0xffff;
6566 + addr += base;
6567 + }
6568 +@@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t
6569 + unsigned char opcode[15];
6570 + unsigned long addr = convert_ip_to_linear(child, regs);
6571 +
6572 ++ if (addr == -EINVAL)
6573 ++ return 0;
6574 ++
6575 + copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
6576 + for (i = 0; i < copied; i++) {
6577 + switch (opcode[i]) {
6578 +@@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t
6579 +
6580 + #ifdef CONFIG_X86_64
6581 + case 0x40 ... 0x4f:
6582 +- if (regs->cs != __USER_CS)
6583 ++ if ((regs->cs & 0xffff) != __USER_CS)
6584 + /* 32-bit mode: register increment */
6585 + return 0;
6586 + /* 64-bit mode: REX prefix */
6587 +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
6588 +--- linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-07 12:55:34.000000000 -0500
6589 ++++ linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-18 03:38:44.000000000 -0500
6590 +@@ -1,3 +1,4 @@
6591 ++.section .rodata,"a",@progbits
6592 + ENTRY(sys_call_table)
6593 + .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
6594 + .long sys_exit
6595 +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
6596 +--- linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-07 12:55:34.000000000 -0500
6597 ++++ linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-18 03:38:44.000000000 -0500
6598 +@@ -22,6 +22,21 @@
6599 + #include <linux/uaccess.h>
6600 + #include <linux/unistd.h>
6601 +
6602 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6603 ++{
6604 ++ unsigned long pax_task_size = TASK_SIZE;
6605 ++
6606 ++#ifdef CONFIG_PAX_SEGMEXEC
6607 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6608 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6609 ++#endif
6610 ++
6611 ++ if (len > pax_task_size || addr > pax_task_size - len)
6612 ++ return -EINVAL;
6613 ++
6614 ++ return 0;
6615 ++}
6616 ++
6617 + asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
6618 + unsigned long prot, unsigned long flags,
6619 + unsigned long fd, unsigned long pgoff)
6620 +@@ -81,6 +96,205 @@ out:
6621 + return err;
6622 + }
6623 +
6624 ++unsigned long
6625 ++arch_get_unmapped_area(struct file *filp, unsigned long addr,
6626 ++ unsigned long len, unsigned long pgoff, unsigned long flags)
6627 ++{
6628 ++ struct mm_struct *mm = current->mm;
6629 ++ struct vm_area_struct *vma;
6630 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
6631 ++
6632 ++#ifdef CONFIG_PAX_SEGMEXEC
6633 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6634 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6635 ++#endif
6636 ++
6637 ++ if (len > pax_task_size)
6638 ++ return -ENOMEM;
6639 ++
6640 ++ if (flags & MAP_FIXED)
6641 ++ return addr;
6642 ++
6643 ++#ifdef CONFIG_PAX_RANDMMAP
6644 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6645 ++#endif
6646 ++
6647 ++ if (addr) {
6648 ++ addr = PAGE_ALIGN(addr);
6649 ++ vma = find_vma(mm, addr);
6650 ++ if (pax_task_size - len >= addr &&
6651 ++ (!vma || addr + len <= vma->vm_start))
6652 ++ return addr;
6653 ++ }
6654 ++ if (len > mm->cached_hole_size) {
6655 ++ start_addr = addr = mm->free_area_cache;
6656 ++ } else {
6657 ++ start_addr = addr = mm->mmap_base;
6658 ++ mm->cached_hole_size = 0;
6659 ++ }
6660 ++
6661 ++#ifdef CONFIG_PAX_PAGEEXEC
6662 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
6663 ++ start_addr = 0x00110000UL;
6664 ++
6665 ++#ifdef CONFIG_PAX_RANDMMAP
6666 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6667 ++ start_addr += mm->delta_mmap & 0x03FFF000UL;
6668 ++#endif
6669 ++
6670 ++ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
6671 ++ start_addr = addr = mm->mmap_base;
6672 ++ else
6673 ++ addr = start_addr;
6674 ++ }
6675 ++#endif
6676 ++
6677 ++full_search:
6678 ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
6679 ++ /* At this point: (!vma || addr < vma->vm_end). */
6680 ++ if (pax_task_size - len < addr) {
6681 ++ /*
6682 ++ * Start a new search - just in case we missed
6683 ++ * some holes.
6684 ++ */
6685 ++ if (start_addr != mm->mmap_base) {
6686 ++ start_addr = addr = mm->mmap_base;
6687 ++ mm->cached_hole_size = 0;
6688 ++ goto full_search;
6689 ++ }
6690 ++ return -ENOMEM;
6691 ++ }
6692 ++ if (!vma || addr + len <= vma->vm_start) {
6693 ++ /*
6694 ++ * Remember the place where we stopped the search:
6695 ++ */
6696 ++ mm->free_area_cache = addr + len;
6697 ++ return addr;
6698 ++ }
6699 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6700 ++ mm->cached_hole_size = vma->vm_start - addr;
6701 ++ addr = vma->vm_end;
6702 ++ if (mm->start_brk <= addr && addr < mm->mmap_base) {
6703 ++ start_addr = addr = mm->mmap_base;
6704 ++ mm->cached_hole_size = 0;
6705 ++ goto full_search;
6706 ++ }
6707 ++ }
6708 ++}
6709 ++
6710 ++unsigned long
6711 ++arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6712 ++ const unsigned long len, const unsigned long pgoff,
6713 ++ const unsigned long flags)
6714 ++{
6715 ++ struct vm_area_struct *vma;
6716 ++ struct mm_struct *mm = current->mm;
6717 ++ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
6718 ++
6719 ++#ifdef CONFIG_PAX_SEGMEXEC
6720 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6721 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6722 ++#endif
6723 ++
6724 ++ /* requested length too big for entire address space */
6725 ++ if (len > pax_task_size)
6726 ++ return -ENOMEM;
6727 ++
6728 ++ if (flags & MAP_FIXED)
6729 ++ return addr;
6730 ++
6731 ++#ifdef CONFIG_PAX_PAGEEXEC
6732 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
6733 ++ goto bottomup;
6734 ++#endif
6735 ++
6736 ++#ifdef CONFIG_PAX_RANDMMAP
6737 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6738 ++#endif
6739 ++
6740 ++ /* requesting a specific address */
6741 ++ if (addr) {
6742 ++ addr = PAGE_ALIGN(addr);
6743 ++ vma = find_vma(mm, addr);
6744 ++ if (pax_task_size - len >= addr &&
6745 ++ (!vma || addr + len <= vma->vm_start))
6746 ++ return addr;
6747 ++ }
6748 ++
6749 ++ /* check if free_area_cache is useful for us */
6750 ++ if (len <= mm->cached_hole_size) {
6751 ++ mm->cached_hole_size = 0;
6752 ++ mm->free_area_cache = mm->mmap_base;
6753 ++ }
6754 ++
6755 ++ /* either no address requested or can't fit in requested address hole */
6756 ++ addr = mm->free_area_cache;
6757 ++
6758 ++ /* make sure it can fit in the remaining address space */
6759 ++ if (addr > len) {
6760 ++ vma = find_vma(mm, addr-len);
6761 ++ if (!vma || addr <= vma->vm_start)
6762 ++ /* remember the address as a hint for next time */
6763 ++ return (mm->free_area_cache = addr-len);
6764 ++ }
6765 ++
6766 ++ if (mm->mmap_base < len)
6767 ++ goto bottomup;
6768 ++
6769 ++ addr = mm->mmap_base-len;
6770 ++
6771 ++ do {
6772 ++ /*
6773 ++ * Lookup failure means no vma is above this address,
6774 ++ * else if new region fits below vma->vm_start,
6775 ++ * return with success:
6776 ++ */
6777 ++ vma = find_vma(mm, addr);
6778 ++ if (!vma || addr+len <= vma->vm_start)
6779 ++ /* remember the address as a hint for next time */
6780 ++ return (mm->free_area_cache = addr);
6781 ++
6782 ++ /* remember the largest hole we saw so far */
6783 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6784 ++ mm->cached_hole_size = vma->vm_start - addr;
6785 ++
6786 ++ /* try just below the current vma->vm_start */
6787 ++ addr = vma->vm_start-len;
6788 ++ } while (len < vma->vm_start);
6789 ++
6790 ++bottomup:
6791 ++ /*
6792 ++ * A failed mmap() very likely causes application failure,
6793 ++ * so fall back to the bottom-up function here. This scenario
6794 ++ * can happen with large stack limits and large mmap()
6795 ++ * allocations.
6796 ++ */
6797 ++
6798 ++#ifdef CONFIG_PAX_SEGMEXEC
6799 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6800 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
6801 ++ else
6802 ++#endif
6803 ++
6804 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6805 ++
6806 ++#ifdef CONFIG_PAX_RANDMMAP
6807 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6808 ++ mm->mmap_base += mm->delta_mmap;
6809 ++#endif
6810 ++
6811 ++ mm->free_area_cache = mm->mmap_base;
6812 ++ mm->cached_hole_size = ~0UL;
6813 ++ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6814 ++ /*
6815 ++ * Restore the topdown base:
6816 ++ */
6817 ++ mm->mmap_base = base;
6818 ++ mm->free_area_cache = base;
6819 ++ mm->cached_hole_size = ~0UL;
6820 ++
6821 ++ return addr;
6822 ++}
6823 +
6824 + struct sel_arg_struct {
6825 + unsigned long n;
6826 +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
6827 +--- linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-07 12:55:34.000000000 -0500
6828 ++++ linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-18 03:38:44.000000000 -0500
6829 +@@ -45,8 +45,8 @@ out:
6830 + return error;
6831 + }
6832 +
6833 +-static void find_start_end(unsigned long flags, unsigned long *begin,
6834 +- unsigned long *end)
6835 ++static void find_start_end(struct mm_struct *mm, unsigned long flags,
6836 ++ unsigned long *begin, unsigned long *end)
6837 + {
6838 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
6839 + unsigned long new_begin;
6840 +@@ -65,7 +65,7 @@ static void find_start_end(unsigned long
6841 + *begin = new_begin;
6842 + }
6843 + } else {
6844 +- *begin = TASK_UNMAPPED_BASE;
6845 ++ *begin = mm->mmap_base;
6846 + *end = TASK_SIZE;
6847 + }
6848 + }
6849 +@@ -82,11 +82,15 @@ arch_get_unmapped_area(struct file *filp
6850 + if (flags & MAP_FIXED)
6851 + return addr;
6852 +
6853 +- find_start_end(flags, &begin, &end);
6854 ++ find_start_end(mm, flags, &begin, &end);
6855 +
6856 + if (len > end)
6857 + return -ENOMEM;
6858 +
6859 ++#ifdef CONFIG_PAX_RANDMMAP
6860 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6861 ++#endif
6862 ++
6863 + if (addr) {
6864 + addr = PAGE_ALIGN(addr);
6865 + vma = find_vma(mm, addr);
6866 +@@ -141,7 +145,7 @@ arch_get_unmapped_area_topdown(struct fi
6867 + {
6868 + struct vm_area_struct *vma;
6869 + struct mm_struct *mm = current->mm;
6870 +- unsigned long addr = addr0;
6871 ++ unsigned long base = mm->mmap_base, addr = addr0;
6872 +
6873 + /* requested length too big for entire address space */
6874 + if (len > TASK_SIZE)
6875 +@@ -154,6 +158,10 @@ arch_get_unmapped_area_topdown(struct fi
6876 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
6877 + goto bottomup;
6878 +
6879 ++#ifdef CONFIG_PAX_RANDMMAP
6880 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6881 ++#endif
6882 ++
6883 + /* requesting a specific address */
6884 + if (addr) {
6885 + addr = PAGE_ALIGN(addr);
6886 +@@ -211,13 +219,21 @@ bottomup:
6887 + * can happen with large stack limits and large mmap()
6888 + * allocations.
6889 + */
6890 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6891 ++
6892 ++#ifdef CONFIG_PAX_RANDMMAP
6893 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6894 ++ mm->mmap_base += mm->delta_mmap;
6895 ++#endif
6896 ++
6897 ++ mm->free_area_cache = mm->mmap_base;
6898 + mm->cached_hole_size = ~0UL;
6899 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
6900 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6901 + /*
6902 + * Restore the topdown base:
6903 + */
6904 +- mm->free_area_cache = mm->mmap_base;
6905 ++ mm->mmap_base = base;
6906 ++ mm->free_area_cache = base;
6907 + mm->cached_hole_size = ~0UL;
6908 +
6909 + return addr;
6910 +diff -urNp linux-2.6.27.10/arch/x86/kernel/time_32.c linux-2.6.27.10/arch/x86/kernel/time_32.c
6911 +--- linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-07 12:55:34.000000000 -0500
6912 ++++ linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-18 03:38:44.000000000 -0500
6913 +@@ -49,20 +49,30 @@ unsigned long profile_pc(struct pt_regs
6914 + if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs) &&
6915 + in_lock_functions(pc)) {
6916 + #ifdef CONFIG_FRAME_POINTER
6917 +- return *(unsigned long *)(regs->bp + 4);
6918 ++ return ktla_ktva(*(unsigned long *)(regs->bp + 4));
6919 + #else
6920 + unsigned long *sp = (unsigned long *)&regs->sp;
6921 +
6922 + /* Return address is either directly at stack pointer
6923 + or above a saved flags. Eflags has bits 22-31 zero,
6924 + kernel addresses don't. */
6925 ++
6926 ++#ifdef CONFIG_PAX_KERNEXEC
6927 ++ return ktla_ktva(sp[0]);
6928 ++#else
6929 + if (sp[0] >> 22)
6930 + return sp[0];
6931 + if (sp[1] >> 22)
6932 + return sp[1];
6933 + #endif
6934 ++
6935 ++#endif
6936 + }
6937 + #endif
6938 ++
6939 ++ if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs))
6940 ++ pc = ktla_ktva(pc);
6941 ++
6942 + return pc;
6943 + }
6944 + EXPORT_SYMBOL(profile_pc);
6945 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tlb_32.c linux-2.6.27.10/arch/x86/kernel/tlb_32.c
6946 +--- linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-07 12:55:34.000000000 -0500
6947 ++++ linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-18 03:38:44.000000000 -0500
6948 +@@ -5,7 +5,7 @@
6949 + #include <asm/tlbflush.h>
6950 +
6951 + DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate)
6952 +- ____cacheline_aligned = { &init_mm, 0, };
6953 ++ ____cacheline_aligned = { &init_mm, 0, {0} };
6954 +
6955 + /* must come after the send_IPI functions above for inlining */
6956 + #include <mach_ipi.h>
6957 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tls.c linux-2.6.27.10/arch/x86/kernel/tls.c
6958 +--- linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-07 12:55:34.000000000 -0500
6959 ++++ linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-18 03:38:44.000000000 -0500
6960 +@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struc
6961 + if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
6962 + return -EINVAL;
6963 +
6964 ++#ifdef CONFIG_PAX_SEGMEXEC
6965 ++ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
6966 ++ return -EINVAL;
6967 ++#endif
6968 ++
6969 + set_tls_desc(p, idx, &info, 1);
6970 +
6971 + return 0;
6972 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_32.c linux-2.6.27.10/arch/x86/kernel/traps_32.c
6973 +--- linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-11-07 12:55:34.000000000 -0500
6974 ++++ linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-12-10 22:28:27.000000000 -0500
6975 +@@ -70,14 +70,6 @@ asmlinkage int system_call(void);
6976 + /* Do we ignore FPU interrupts ? */
6977 + char ignore_fpu_irq;
6978 +
6979 +-/*
6980 +- * The IDT has to be page-aligned to simplify the Pentium
6981 +- * F0 0F bug workaround.. We have a special link segment
6982 +- * for this.
6983 +- */
6984 +-gate_desc idt_table[256]
6985 +- __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
6986 +-
6987 + int panic_on_unrecovered_nmi;
6988 + int kstack_depth_to_print = 24;
6989 + static unsigned int code_bytes = 64;
6990 +@@ -320,21 +312,22 @@ void show_registers(struct pt_regs *regs
6991 + * When in-kernel, we also print out the stack and code at the
6992 + * time of the fault..
6993 + */
6994 +- if (!user_mode_vm(regs)) {
6995 ++ if (!user_mode(regs)) {
6996 + unsigned int code_prologue = code_bytes * 43 / 64;
6997 + unsigned int code_len = code_bytes;
6998 + unsigned char c;
6999 + u8 *ip;
7000 ++ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
7001 +
7002 + printk("\n" KERN_EMERG "Stack: ");
7003 + show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
7004 +
7005 + printk(KERN_EMERG "Code: ");
7006 +
7007 +- ip = (u8 *)regs->ip - code_prologue;
7008 ++ ip = (u8 *)regs->ip - code_prologue + cs_base;
7009 + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
7010 + /* try starting at EIP */
7011 +- ip = (u8 *)regs->ip;
7012 ++ ip = (u8 *)regs->ip + cs_base;
7013 + code_len = code_len - code_prologue + 1;
7014 + }
7015 + for (i = 0; i < code_len; i++, ip++) {
7016 +@@ -343,7 +336,7 @@ void show_registers(struct pt_regs *regs
7017 + printk(" Bad EIP value.");
7018 + break;
7019 + }
7020 +- if (ip == (u8 *)regs->ip)
7021 ++ if (ip == (u8 *)regs->ip + cs_base)
7022 + printk("<%02x> ", c);
7023 + else
7024 + printk("%02x ", c);
7025 +@@ -356,6 +349,7 @@ int is_valid_bugaddr(unsigned long ip)
7026 + {
7027 + unsigned short ud2;
7028 +
7029 ++ ip = ktla_ktva(ip);
7030 + if (ip < PAGE_OFFSET)
7031 + return 0;
7032 + if (probe_kernel_address((unsigned short *)ip, ud2))
7033 +@@ -469,7 +463,7 @@ void die(const char *str, struct pt_regs
7034 + static inline void
7035 + die_if_kernel(const char *str, struct pt_regs *regs, long err)
7036 + {
7037 +- if (!user_mode_vm(regs))
7038 ++ if (!user_mode(regs))
7039 + die(str, regs, err);
7040 + }
7041 +
7042 +@@ -479,13 +473,13 @@ do_trap(int trapnr, int signr, char *str
7043 + {
7044 + struct task_struct *tsk = current;
7045 +
7046 +- if (regs->flags & X86_VM_MASK) {
7047 ++ if (v8086_mode(regs)) {
7048 + if (vm86)
7049 + goto vm86_trap;
7050 + goto trap_signal;
7051 + }
7052 +
7053 +- if (!user_mode(regs))
7054 ++ if (!user_mode_novm(regs))
7055 + goto kernel_trap;
7056 +
7057 + trap_signal:
7058 +@@ -513,6 +507,12 @@ kernel_trap:
7059 + tsk->thread.trap_no = trapnr;
7060 + die(str, regs, error_code);
7061 + }
7062 ++
7063 ++#ifdef CONFIG_PAX_REFCOUNT
7064 ++ if (trapnr == 4)
7065 ++ pax_report_refcount_overflow(regs);
7066 ++#endif
7067 ++
7068 + return;
7069 +
7070 + vm86_trap:
7071 +@@ -595,7 +595,7 @@ do_general_protection(struct pt_regs *re
7072 + int cpu;
7073 +
7074 + cpu = get_cpu();
7075 +- tss = &per_cpu(init_tss, cpu);
7076 ++ tss = init_tss + cpu;
7077 + thread = &current->thread;
7078 +
7079 + /*
7080 +@@ -627,13 +627,29 @@ do_general_protection(struct pt_regs *re
7081 + }
7082 + put_cpu();
7083 +
7084 +- if (regs->flags & X86_VM_MASK)
7085 ++ if (v8086_mode(regs))
7086 + goto gp_in_vm86;
7087 +
7088 + tsk = current;
7089 +- if (!user_mode(regs))
7090 ++ if (!user_mode_novm(regs))
7091 + goto gp_in_kernel;
7092 +
7093 ++#ifdef CONFIG_PAX_PAGEEXEC
7094 ++ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
7095 ++ struct mm_struct *mm = tsk->mm;
7096 ++ unsigned long limit;
7097 ++
7098 ++ down_write(&mm->mmap_sem);
7099 ++ limit = mm->context.user_cs_limit;
7100 ++ if (limit < TASK_SIZE) {
7101 ++ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
7102 ++ up_write(&mm->mmap_sem);
7103 ++ return;
7104 ++ }
7105 ++ up_write(&mm->mmap_sem);
7106 ++ }
7107 ++#endif
7108 ++
7109 + tsk->thread.error_code = error_code;
7110 + tsk->thread.trap_no = 13;
7111 +
7112 +@@ -664,6 +680,13 @@ gp_in_kernel:
7113 + if (notify_die(DIE_GPF, "general protection fault", regs,
7114 + error_code, 13, SIGSEGV) == NOTIFY_STOP)
7115 + return;
7116 ++
7117 ++#ifdef CONFIG_PAX_KERNEXEC
7118 ++ if ((regs->cs & 0xFFFF) == __KERNEL_CS)
7119 ++ die("PAX: suspicious general protection fault", regs, error_code);
7120 ++ else
7121 ++#endif
7122 ++
7123 + die("general protection fault", regs, error_code);
7124 + }
7125 +
7126 +@@ -766,7 +789,7 @@ void notrace __kprobes die_nmi(char *str
7127 + * If we are in kernel we are probably nested up pretty bad
7128 + * and might aswell get out now while we still can:
7129 + */
7130 +- if (!user_mode_vm(regs)) {
7131 ++ if (!user_mode(regs)) {
7132 + current->thread.trap_no = 2;
7133 + crash_kexec(regs);
7134 + }
7135 +@@ -915,7 +938,7 @@ void __kprobes do_debug(struct pt_regs *
7136 + goto clear_dr7;
7137 + }
7138 +
7139 +- if (regs->flags & X86_VM_MASK)
7140 ++ if (v8086_mode(regs))
7141 + goto debug_vm86;
7142 +
7143 + /* Save debug status register where ptrace can see it */
7144 +@@ -931,7 +954,7 @@ void __kprobes do_debug(struct pt_regs *
7145 + * check for kernel mode by just checking the CPL
7146 + * of CS.
7147 + */
7148 +- if (!user_mode(regs))
7149 ++ if (!user_mode_novm(regs))
7150 + goto clear_TF_reenable;
7151 + }
7152 +
7153 +@@ -1086,7 +1109,7 @@ void do_simd_coprocessor_error(struct pt
7154 + * Handle strange cache flush from user space exception
7155 + * in all other cases. This is undocumented behaviour.
7156 + */
7157 +- if (regs->flags & X86_VM_MASK) {
7158 ++ if (v8086_mode(regs)) {
7159 + handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
7160 + return;
7161 + }
7162 +@@ -1106,19 +1129,14 @@ void do_spurious_interrupt_bug(struct pt
7163 +
7164 + unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
7165 + {
7166 +- struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
7167 + unsigned long base = (kesp - uesp) & -THREAD_SIZE;
7168 + unsigned long new_kesp = kesp - base;
7169 + unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
7170 +- __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
7171 ++ struct desc_struct ss;
7172 +
7173 + /* Set up base for espfix segment */
7174 +- desc &= 0x00f0ff0000000000ULL;
7175 +- desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
7176 +- ((((__u64)base) << 32) & 0xff00000000000000ULL) |
7177 +- ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
7178 +- (lim_pages & 0xffff);
7179 +- *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
7180 ++ pack_descriptor(&ss, base, lim_pages, 0x93, 0xC);
7181 ++ write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S);
7182 +
7183 + return new_kesp;
7184 + }
7185 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_64.c linux-2.6.27.10/arch/x86/kernel/traps_64.c
7186 +--- linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-07 12:55:34.000000000 -0500
7187 ++++ linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-18 03:38:44.000000000 -0500
7188 +@@ -634,6 +634,12 @@ kernel_trap:
7189 + tsk->thread.trap_no = trapnr;
7190 + die(str, regs, error_code);
7191 + }
7192 ++
7193 ++#ifdef CONFIG_PAX_REFCOUNT
7194 ++ if (trapnr == 4)
7195 ++ pax_report_refcount_overflow(regs);
7196 ++#endif
7197 ++
7198 + return;
7199 + }
7200 +
7201 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tsc.c linux-2.6.27.10/arch/x86/kernel/tsc.c
7202 +--- linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-17 20:03:30.000000000 -0500
7203 ++++ linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-18 03:38:44.000000000 -0500
7204 +@@ -554,7 +554,7 @@ static struct dmi_system_id __initdata b
7205 + DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
7206 + },
7207 + },
7208 +- {}
7209 ++ { NULL, NULL, {{0, NULL}}, NULL}
7210 + };
7211 +
7212 + /*
7213 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vm86_32.c linux-2.6.27.10/arch/x86/kernel/vm86_32.c
7214 +--- linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-07 12:55:34.000000000 -0500
7215 ++++ linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-18 03:38:44.000000000 -0500
7216 +@@ -147,7 +147,7 @@ struct pt_regs *save_v86_state(struct ke
7217 + do_exit(SIGSEGV);
7218 + }
7219 +
7220 +- tss = &per_cpu(init_tss, get_cpu());
7221 ++ tss = init_tss + get_cpu();
7222 + current->thread.sp0 = current->thread.saved_sp0;
7223 + current->thread.sysenter_cs = __KERNEL_CS;
7224 + load_sp0(tss, &current->thread);
7225 +@@ -324,7 +324,7 @@ static void do_sys_vm86(struct kernel_vm
7226 + tsk->thread.saved_fs = info->regs32->fs;
7227 + savesegment(gs, tsk->thread.saved_gs);
7228 +
7229 +- tss = &per_cpu(init_tss, get_cpu());
7230 ++ tss = init_tss + get_cpu();
7231 + tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
7232 + if (cpu_has_sep)
7233 + tsk->thread.sysenter_cs = 0;
7234 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmi_32.c linux-2.6.27.10/arch/x86/kernel/vmi_32.c
7235 +--- linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:11.000000000 -0500
7236 ++++ linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:21.000000000 -0500
7237 +@@ -102,18 +102,43 @@ static unsigned patch_internal(int call,
7238 + {
7239 + u64 reloc;
7240 + struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
7241 ++
7242 ++#ifdef CONFIG_PAX_KERNEXEC
7243 ++ unsigned long cr0;
7244 ++#endif
7245 ++
7246 + reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
7247 + switch(rel->type) {
7248 + case VMI_RELOCATION_CALL_REL:
7249 + BUG_ON(len < 5);
7250 ++
7251 ++#ifdef CONFIG_PAX_KERNEXEC
7252 ++ pax_open_kernel(cr0);
7253 ++#endif
7254 ++
7255 + *(char *)insnbuf = MNEM_CALL;
7256 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7257 ++
7258 ++#ifdef CONFIG_PAX_KERNEXEC
7259 ++ pax_close_kernel(cr0);
7260 ++#endif
7261 ++
7262 + return 5;
7263 +
7264 + case VMI_RELOCATION_JUMP_REL:
7265 + BUG_ON(len < 5);
7266 ++
7267 ++#ifdef CONFIG_PAX_KERNEXEC
7268 ++ pax_open_kernel(cr0);
7269 ++#endif
7270 ++
7271 + *(char *)insnbuf = MNEM_JMP;
7272 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7273 ++
7274 ++#ifdef CONFIG_PAX_KERNEXEC
7275 ++ pax_close_kernel(cr0);
7276 ++#endif
7277 ++
7278 + return 5;
7279 +
7280 + case VMI_RELOCATION_NOP:
7281 +@@ -516,14 +541,14 @@ static void vmi_set_pud(pud_t *pudp, pud
7282 +
7283 + static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
7284 + {
7285 +- const pte_t pte = { .pte = 0 };
7286 ++ const pte_t pte = __pte(0ULL);
7287 + vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
7288 + vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
7289 + }
7290 +
7291 + static void vmi_pmd_clear(pmd_t *pmd)
7292 + {
7293 +- const pte_t pte = { .pte = 0 };
7294 ++ const pte_t pte = __pte(0ULL);
7295 + vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD);
7296 + vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
7297 + }
7298 +@@ -552,8 +577,8 @@ vmi_startup_ipi_hook(int phys_apicid, un
7299 + ap.ss = __KERNEL_DS;
7300 + ap.esp = (unsigned long) start_esp;
7301 +
7302 +- ap.ds = __USER_DS;
7303 +- ap.es = __USER_DS;
7304 ++ ap.ds = __KERNEL_DS;
7305 ++ ap.es = __KERNEL_DS;
7306 + ap.fs = __KERNEL_PERCPU;
7307 + ap.gs = 0;
7308 +
7309 +@@ -748,12 +773,20 @@ static inline int __init activate_vmi(vo
7310 + u64 reloc;
7311 + const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc;
7312 +
7313 ++#ifdef CONFIG_PAX_KERNEXEC
7314 ++ unsigned long cr0;
7315 ++#endif
7316 ++
7317 + if (call_vrom_func(vmi_rom, vmi_init) != 0) {
7318 + printk(KERN_ERR "VMI ROM failed to initialize!");
7319 + return 0;
7320 + }
7321 + savesegment(cs, kernel_cs);
7322 +
7323 ++#ifdef CONFIG_PAX_KERNEXEC
7324 ++ pax_open_kernel(cr0);
7325 ++#endif
7326 ++
7327 + pv_info.paravirt_enabled = 1;
7328 + pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK;
7329 + pv_info.name = "vmi";
7330 +@@ -943,6 +976,10 @@ static inline int __init activate_vmi(vo
7331 +
7332 + para_fill(pv_irq_ops.safe_halt, Halt);
7333 +
7334 ++#ifdef CONFIG_PAX_KERNEXEC
7335 ++ pax_close_kernel(cr0);
7336 ++#endif
7337 ++
7338 + /*
7339 + * Alternative instruction rewriting doesn't happen soon enough
7340 + * to convert VMI_IRET to a call instead of a jump; so we have
7341 +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
7342 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-07 12:55:34.000000000 -0500
7343 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-18 03:38:44.000000000 -0500
7344 +@@ -15,6 +15,20 @@
7345 + #include <asm/page.h>
7346 + #include <asm/cache.h>
7347 + #include <asm/boot.h>
7348 ++#include <asm/segment.h>
7349 ++
7350 ++#ifdef CONFIG_X86_PAE
7351 ++#define PMD_SHIFT 21
7352 ++#else
7353 ++#define PMD_SHIFT 22
7354 ++#endif
7355 ++#define PMD_SIZE (1 << PMD_SHIFT)
7356 ++
7357 ++#ifdef CONFIG_PAX_KERNEXEC
7358 ++#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1)))
7359 ++#else
7360 ++#define __KERNEL_TEXT_OFFSET 0
7361 ++#endif
7362 +
7363 + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
7364 + OUTPUT_ARCH(i386)
7365 +@@ -22,81 +36,23 @@ ENTRY(phys_startup_32)
7366 + jiffies = jiffies_64;
7367 +
7368 + PHDRS {
7369 +- text PT_LOAD FLAGS(5); /* R_E */
7370 +- data PT_LOAD FLAGS(7); /* RWE */
7371 +- note PT_NOTE FLAGS(0); /* ___ */
7372 ++ initdata PT_LOAD FLAGS(6); /* RW_ */
7373 ++ percpu PT_LOAD FLAGS(6); /* RW_ */
7374 ++ inittext PT_LOAD FLAGS(5); /* R_E */
7375 ++ text PT_LOAD FLAGS(5); /* R_E */
7376 ++ rodata PT_LOAD FLAGS(4); /* R__ */
7377 ++ data PT_LOAD FLAGS(6); /* RW_ */
7378 ++ note PT_NOTE FLAGS(0); /* ___ */
7379 + }
7380 + SECTIONS
7381 + {
7382 +- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
7383 +- phys_startup_32 = startup_32 - LOAD_OFFSET;
7384 +-
7385 +- .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
7386 +- _text = .; /* Text and read-only data */
7387 +- *(.text.head)
7388 +- } :text = 0x9090
7389 +-
7390 +- /* read-only */
7391 +- .text : AT(ADDR(.text) - LOAD_OFFSET) {
7392 +- . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7393 +- *(.text.page_aligned)
7394 +- TEXT_TEXT
7395 +- SCHED_TEXT
7396 +- LOCK_TEXT
7397 +- KPROBES_TEXT
7398 +- *(.fixup)
7399 +- *(.gnu.warning)
7400 +- _etext = .; /* End of text section */
7401 +- } :text = 0x9090
7402 +-
7403 +- NOTES :text :note
7404 ++ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
7405 +
7406 +- . = ALIGN(16); /* Exception table */
7407 +- __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7408 +- __start___ex_table = .;
7409 +- *(__ex_table)
7410 +- __stop___ex_table = .;
7411 +- } :text = 0x9090
7412 +-
7413 +- RODATA
7414 +-
7415 +- /* writeable */
7416 +- . = ALIGN(PAGE_SIZE);
7417 +- .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7418 +- DATA_DATA
7419 +- CONSTRUCTORS
7420 +- } :data
7421 +-
7422 +- . = ALIGN(PAGE_SIZE);
7423 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7424 +- __nosave_begin = .;
7425 +- *(.data.nosave)
7426 +- . = ALIGN(PAGE_SIZE);
7427 +- __nosave_end = .;
7428 +- }
7429 +-
7430 +- . = ALIGN(PAGE_SIZE);
7431 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7432 +- *(.data.page_aligned)
7433 +- *(.data.idt)
7434 +- }
7435 +-
7436 +- . = ALIGN(32);
7437 +- .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7438 +- *(.data.cacheline_aligned)
7439 +- }
7440 +-
7441 +- /* rarely changed data like cpu maps */
7442 +- . = ALIGN(32);
7443 +- .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7444 +- *(.data.read_mostly)
7445 +- _edata = .; /* End of data section */
7446 +- }
7447 +-
7448 +- . = ALIGN(THREAD_SIZE); /* init_task */
7449 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7450 +- *(.data.init_task)
7451 +- }
7452 ++ .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) {
7453 ++ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET;
7454 ++ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
7455 ++ *(.text.startup)
7456 ++ } :initdata
7457 +
7458 + /* might get freed after init */
7459 + . = ALIGN(PAGE_SIZE);
7460 +@@ -114,14 +70,8 @@ SECTIONS
7461 + . = ALIGN(PAGE_SIZE);
7462 +
7463 + /* will be freed after init */
7464 +- . = ALIGN(PAGE_SIZE); /* Init code and data */
7465 +- .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
7466 +- __init_begin = .;
7467 +- _sinittext = .;
7468 +- INIT_TEXT
7469 +- _einittext = .;
7470 +- }
7471 + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
7472 ++ __init_begin = .;
7473 + INIT_DATA
7474 + }
7475 + . = ALIGN(16);
7476 +@@ -161,11 +111,6 @@ SECTIONS
7477 + *(.parainstructions)
7478 + __parainstructions_end = .;
7479 + }
7480 +- /* .exit.text is discard at runtime, not link time, to deal with references
7481 +- from .altinstructions and .eh_frame */
7482 +- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
7483 +- EXIT_TEXT
7484 +- }
7485 + .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
7486 + EXIT_DATA
7487 + }
7488 +@@ -178,17 +123,136 @@ SECTIONS
7489 + }
7490 + #endif
7491 + . = ALIGN(PAGE_SIZE);
7492 +- .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
7493 +- __per_cpu_start = .;
7494 ++ per_cpu_start = .;
7495 ++ .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) {
7496 ++ __per_cpu_start = . + per_cpu_start;
7497 ++ LONG(0)
7498 + *(.data.percpu)
7499 + *(.data.percpu.shared_aligned)
7500 +- __per_cpu_end = .;
7501 +- }
7502 ++ __per_cpu_end = . + per_cpu_start;
7503 ++ } :percpu
7504 ++ . += per_cpu_start;
7505 + . = ALIGN(PAGE_SIZE);
7506 + /* freed after init ends here */
7507 +
7508 ++ . = ALIGN(PAGE_SIZE); /* Init code and data */
7509 ++ .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7510 ++ _sinittext = .;
7511 ++ INIT_TEXT
7512 ++ _einittext = .;
7513 ++ } :inittext
7514 ++
7515 ++ /* .exit.text is discard at runtime, not link time, to deal with references
7516 ++ from .altinstructions and .eh_frame */
7517 ++ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7518 ++ EXIT_TEXT
7519 ++ }
7520 ++
7521 ++ .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7522 ++ BYTE(0)
7523 ++ . = ALIGN(2*PMD_SIZE) - 1;
7524 ++ }
7525 ++
7526 ++ /* freed after init ends here */
7527 ++
7528 ++ .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7529 ++ __init_end = . + __KERNEL_TEXT_OFFSET;
7530 ++ KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET;
7531 ++ _text = .; /* Text and read-only data */
7532 ++ *(.text.head)
7533 ++ } :text = 0x9090
7534 ++
7535 ++ /* read-only */
7536 ++ .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7537 ++ . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7538 ++ *(.text.page_aligned)
7539 ++ TEXT_TEXT
7540 ++ SCHED_TEXT
7541 ++ LOCK_TEXT
7542 ++ KPROBES_TEXT
7543 ++ *(.fixup)
7544 ++ *(.gnu.warning)
7545 ++ _etext = .; /* End of text section */
7546 ++ } :text = 0x9090
7547 ++
7548 ++ . += __KERNEL_TEXT_OFFSET;
7549 ++
7550 ++ . = ALIGN(4096); /* Exception table */
7551 ++ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7552 ++ __start___ex_table = .;
7553 ++ *(__ex_table)
7554 ++ __stop___ex_table = .;
7555 ++ } :rodata
7556 ++
7557 ++ NOTES :rodata :note
7558 ++
7559 ++ RO_DATA(PAGE_SIZE)
7560 ++
7561 ++ . = ALIGN(PAGE_SIZE);
7562 ++ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
7563 ++ *(.idt)
7564 ++ . = ALIGN(PAGE_SIZE);
7565 ++ *(.empty_zero_page)
7566 ++ *(.swapper_pg_pmd)
7567 ++ *(.swapper_pg_dir)
7568 ++ }
7569 ++
7570 ++#ifdef CONFIG_PAX_KERNEXEC
7571 ++
7572 ++#ifdef CONFIG_MODULES
7573 ++ . = ALIGN(PAGE_SIZE);
7574 ++ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
7575 ++ MODULES_VADDR = .;
7576 ++ BYTE(0)
7577 ++ . += (6 * 1024 * 1024);
7578 ++ . = ALIGN( PMD_SIZE) - 1;
7579 ++ MODULES_END = .;
7580 ++ }
7581 ++#else
7582 ++ . = ALIGN(PMD_SIZE) - 1;
7583 ++#endif
7584 ++
7585 ++#endif
7586 ++
7587 ++ /* writeable */
7588 ++ . = ALIGN(PAGE_SIZE);
7589 ++ .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7590 ++ _data = .;
7591 ++ DATA_DATA
7592 ++ CONSTRUCTORS
7593 ++ } :data
7594 ++
7595 ++ . = ALIGN(PAGE_SIZE);
7596 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7597 ++ __nosave_begin = .;
7598 ++ *(.data.nosave)
7599 ++ . = ALIGN(PAGE_SIZE);
7600 ++ __nosave_end = .;
7601 ++ }
7602 ++
7603 ++ . = ALIGN(PAGE_SIZE);
7604 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7605 ++ *(.data.page_aligned)
7606 ++ }
7607 ++
7608 ++ . = ALIGN(32);
7609 ++ .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7610 ++ *(.data.cacheline_aligned)
7611 ++ }
7612 ++
7613 ++ /* rarely changed data like cpu maps */
7614 ++ . = ALIGN(32);
7615 ++ .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7616 ++ *(.data.read_mostly)
7617 ++ _edata = .; /* End of data section */
7618 ++ }
7619 ++
7620 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7621 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7622 ++ *(.data.init_task)
7623 ++ }
7624 ++
7625 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7626 +- __init_end = .;
7627 + __bss_start = .; /* BSS */
7628 + *(.bss.page_aligned)
7629 + *(.bss)
7630 +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
7631 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-07 12:55:34.000000000 -0500
7632 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-18 03:38:44.000000000 -0500
7633 +@@ -16,7 +16,7 @@ jiffies_64 = jiffies;
7634 + _proxy_pda = 1;
7635 + PHDRS {
7636 + text PT_LOAD FLAGS(5); /* R_E */
7637 +- data PT_LOAD FLAGS(7); /* RWE */
7638 ++ data PT_LOAD FLAGS(6); /* RW_ */
7639 + user PT_LOAD FLAGS(7); /* RWE */
7640 + data.init PT_LOAD FLAGS(7); /* RWE */
7641 + note PT_NOTE FLAGS(0); /* ___ */
7642 +@@ -49,17 +49,20 @@ SECTIONS
7643 + __stop___ex_table = .;
7644 + } :text = 0x9090
7645 +
7646 +- RODATA
7647 ++ RO_DATA(PAGE_SIZE)
7648 +
7649 ++#ifdef CONFIG_PAX_KERNEXEC
7650 ++ . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */
7651 ++#else
7652 + . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
7653 ++#endif
7654 + /* Data */
7655 ++ _data = .;
7656 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
7657 + DATA_DATA
7658 + CONSTRUCTORS
7659 + } :data
7660 +
7661 +- _edata = .; /* End of data section */
7662 +-
7663 + . = ALIGN(PAGE_SIZE);
7664 + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
7665 + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7666 +@@ -70,9 +73,27 @@ SECTIONS
7667 + *(.data.read_mostly)
7668 + }
7669 +
7670 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7671 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7672 ++ *(.data.init_task)
7673 ++ }
7674 ++
7675 ++ . = ALIGN(PAGE_SIZE);
7676 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7677 ++ *(.data.page_aligned)
7678 ++ }
7679 ++
7680 ++ . = ALIGN(PAGE_SIZE);
7681 ++ __nosave_begin = .;
7682 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7683 ++ . = ALIGN(PAGE_SIZE);
7684 ++ __nosave_end = .;
7685 ++
7686 ++ _edata = .; /* End of data section */
7687 ++
7688 + #define VSYSCALL_ADDR (-10*1024*1024)
7689 +-#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7690 +-#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7691 ++#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7692 ++#define VSYSCALL_VIRT_ADDR ((ADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7693 +
7694 + #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
7695 + #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
7696 +@@ -120,23 +141,13 @@ SECTIONS
7697 + #undef VVIRT_OFFSET
7698 + #undef VVIRT
7699 +
7700 +- . = ALIGN(THREAD_SIZE); /* init_task */
7701 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7702 +- *(.data.init_task)
7703 +- }:data.init
7704 +-
7705 +- . = ALIGN(PAGE_SIZE);
7706 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7707 +- *(.data.page_aligned)
7708 +- }
7709 +-
7710 + /* might get freed after init */
7711 + . = ALIGN(PAGE_SIZE);
7712 + __smp_alt_begin = .;
7713 + __smp_locks = .;
7714 + .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
7715 + *(.smp_locks)
7716 +- }
7717 ++ } :data.init
7718 + __smp_locks_end = .;
7719 + . = ALIGN(PAGE_SIZE);
7720 + __smp_alt_end = .;
7721 +@@ -213,16 +224,11 @@ SECTIONS
7722 + . = ALIGN(PAGE_SIZE);
7723 + __init_end = .;
7724 +
7725 +- . = ALIGN(PAGE_SIZE);
7726 +- __nosave_begin = .;
7727 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7728 +- . = ALIGN(PAGE_SIZE);
7729 +- __nosave_end = .;
7730 +-
7731 + __bss_start = .; /* BSS */
7732 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7733 + *(.bss.page_aligned)
7734 + *(.bss)
7735 ++ . = ALIGN(2*1024*1024);
7736 + }
7737 + __bss_stop = .;
7738 +
7739 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c
7740 +--- linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-07 12:55:34.000000000 -0500
7741 ++++ linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-18 03:38:44.000000000 -0500
7742 +@@ -236,13 +236,13 @@ static ctl_table kernel_table2[] = {
7743 + .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
7744 + .mode = 0644,
7745 + .proc_handler = vsyscall_sysctl_change },
7746 +- {}
7747 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7748 + };
7749 +
7750 + static ctl_table kernel_root_table2[] = {
7751 + { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555,
7752 + .child = kernel_table2 },
7753 +- {}
7754 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7755 + };
7756 + #endif
7757 +
7758 +diff -urNp linux-2.6.27.10/arch/x86/kvm/svm.c linux-2.6.27.10/arch/x86/kvm/svm.c
7759 +--- linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-07 12:55:34.000000000 -0500
7760 ++++ linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-18 03:38:44.000000000 -0500
7761 +@@ -1515,7 +1515,19 @@ static void reload_tss(struct kvm_vcpu *
7762 + int cpu = raw_smp_processor_id();
7763 +
7764 + struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
7765 ++
7766 ++#ifdef CONFIG_PAX_KERNEXEC
7767 ++ unsigned long cr0;
7768 ++
7769 ++ pax_open_kernel(cr0);
7770 ++#endif
7771 ++
7772 + svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
7773 ++
7774 ++#ifdef CONFIG_PAX_KERNEXEC
7775 ++ pax_close_kernel(cr0);
7776 ++#endif
7777 ++
7778 + load_TR_desc();
7779 + }
7780 +
7781 +diff -urNp linux-2.6.27.10/arch/x86/kvm/vmx.c linux-2.6.27.10/arch/x86/kvm/vmx.c
7782 +--- linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-07 12:55:34.000000000 -0500
7783 ++++ linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-18 03:38:44.000000000 -0500
7784 +@@ -115,7 +115,7 @@ static struct vmcs_config {
7785 + u32 vmentry_ctrl;
7786 + } vmcs_config;
7787 +
7788 +-struct vmx_capability {
7789 ++static struct vmx_capability {
7790 + u32 ept;
7791 + u32 vpid;
7792 + } vmx_capability;
7793 +@@ -484,9 +484,23 @@ static void reload_tss(void)
7794 + struct descriptor_table gdt;
7795 + struct desc_struct *descs;
7796 +
7797 ++#ifdef CONFIG_PAX_KERNEXEC
7798 ++ unsigned long cr0;
7799 ++#endif
7800 ++
7801 + kvm_get_gdt(&gdt);
7802 + descs = (void *)gdt.base;
7803 ++
7804 ++#ifdef CONFIG_PAX_KERNEXEC
7805 ++ pax_open_kernel(cr0);
7806 ++#endif
7807 ++
7808 + descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
7809 ++
7810 ++#ifdef CONFIG_PAX_KERNEXEC
7811 ++ pax_close_kernel(cr0);
7812 ++#endif
7813 ++
7814 + load_TR_desc();
7815 + }
7816 +
7817 +@@ -3069,7 +3083,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
7818 + (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
7819 + (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)) == 0;
7820 +
7821 +- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
7822 ++ asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS));
7823 + vmx->launched = 1;
7824 +
7825 + intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
7826 +diff -urNp linux-2.6.27.10/arch/x86/kvm/x86.c linux-2.6.27.10/arch/x86/kvm/x86.c
7827 +--- linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-07 12:55:34.000000000 -0500
7828 ++++ linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-18 03:38:44.000000000 -0500
7829 +@@ -63,35 +63,35 @@ static int kvm_dev_ioctl_get_supported_c
7830 + struct kvm_x86_ops *kvm_x86_ops;
7831 +
7832 + struct kvm_stats_debugfs_item debugfs_entries[] = {
7833 +- { "pf_fixed", VCPU_STAT(pf_fixed) },
7834 +- { "pf_guest", VCPU_STAT(pf_guest) },
7835 +- { "tlb_flush", VCPU_STAT(tlb_flush) },
7836 +- { "invlpg", VCPU_STAT(invlpg) },
7837 +- { "exits", VCPU_STAT(exits) },
7838 +- { "io_exits", VCPU_STAT(io_exits) },
7839 +- { "mmio_exits", VCPU_STAT(mmio_exits) },
7840 +- { "signal_exits", VCPU_STAT(signal_exits) },
7841 +- { "irq_window", VCPU_STAT(irq_window_exits) },
7842 +- { "nmi_window", VCPU_STAT(nmi_window_exits) },
7843 +- { "halt_exits", VCPU_STAT(halt_exits) },
7844 +- { "halt_wakeup", VCPU_STAT(halt_wakeup) },
7845 +- { "hypercalls", VCPU_STAT(hypercalls) },
7846 +- { "request_irq", VCPU_STAT(request_irq_exits) },
7847 +- { "irq_exits", VCPU_STAT(irq_exits) },
7848 +- { "host_state_reload", VCPU_STAT(host_state_reload) },
7849 +- { "efer_reload", VCPU_STAT(efer_reload) },
7850 +- { "fpu_reload", VCPU_STAT(fpu_reload) },
7851 +- { "insn_emulation", VCPU_STAT(insn_emulation) },
7852 +- { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
7853 +- { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
7854 +- { "mmu_pte_write", VM_STAT(mmu_pte_write) },
7855 +- { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
7856 +- { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
7857 +- { "mmu_flooded", VM_STAT(mmu_flooded) },
7858 +- { "mmu_recycled", VM_STAT(mmu_recycled) },
7859 +- { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
7860 +- { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
7861 +- { "largepages", VM_STAT(lpages) },
7862 ++ { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
7863 ++ { "pf_guest", VCPU_STAT(pf_guest), NULL },
7864 ++ { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
7865 ++ { "invlpg", VCPU_STAT(invlpg), NULL },
7866 ++ { "exits", VCPU_STAT(exits), NULL },
7867 ++ { "io_exits", VCPU_STAT(io_exits), NULL },
7868 ++ { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
7869 ++ { "signal_exits", VCPU_STAT(signal_exits), NULL },
7870 ++ { "irq_window", VCPU_STAT(irq_window_exits), NULL },
7871 ++ { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
7872 ++ { "halt_exits", VCPU_STAT(halt_exits), NULL },
7873 ++ { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
7874 ++ { "hypercalls", VCPU_STAT(hypercalls), NULL },
7875 ++ { "request_irq", VCPU_STAT(request_irq_exits), NULL },
7876 ++ { "irq_exits", VCPU_STAT(irq_exits), NULL },
7877 ++ { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
7878 ++ { "efer_reload", VCPU_STAT(efer_reload), NULL },
7879 ++ { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
7880 ++ { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
7881 ++ { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
7882 ++ { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
7883 ++ { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
7884 ++ { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
7885 ++ { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
7886 ++ { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
7887 ++ { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
7888 ++ { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
7889 ++ { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
7890 ++ { "largepages", VM_STAT(lpages), NULL },
7891 + { NULL }
7892 + };
7893 +
7894 +@@ -1274,7 +1274,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
7895 + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
7896 + struct kvm_interrupt *irq)
7897 + {
7898 +- if (irq->irq < 0 || irq->irq >= 256)
7899 ++ if (irq->irq >= 256)
7900 + return -EINVAL;
7901 + if (irqchip_in_kernel(vcpu->kvm))
7902 + return -ENXIO;
7903 +diff -urNp linux-2.6.27.10/arch/x86/lib/checksum_32.S linux-2.6.27.10/arch/x86/lib/checksum_32.S
7904 +--- linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-07 12:55:34.000000000 -0500
7905 ++++ linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-18 03:38:44.000000000 -0500
7906 +@@ -28,7 +28,8 @@
7907 + #include <linux/linkage.h>
7908 + #include <asm/dwarf2.h>
7909 + #include <asm/errno.h>
7910 +-
7911 ++#include <asm/segment.h>
7912 ++
7913 + /*
7914 + * computes a partial checksum, e.g. for TCP/UDP fragments
7915 + */
7916 +@@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic (
7917 +
7918 + #define ARGBASE 16
7919 + #define FP 12
7920 +-
7921 +-ENTRY(csum_partial_copy_generic)
7922 ++
7923 ++ENTRY(csum_partial_copy_generic_to_user)
7924 + CFI_STARTPROC
7925 ++ pushl $(__USER_DS)
7926 ++ CFI_ADJUST_CFA_OFFSET 4
7927 ++ popl %es
7928 ++ CFI_ADJUST_CFA_OFFSET -4
7929 ++ jmp csum_partial_copy_generic
7930 ++
7931 ++ENTRY(csum_partial_copy_generic_from_user)
7932 ++ pushl $(__USER_DS)
7933 ++ CFI_ADJUST_CFA_OFFSET 4
7934 ++ popl %ds
7935 ++ CFI_ADJUST_CFA_OFFSET -4
7936 ++
7937 ++ENTRY(csum_partial_copy_generic)
7938 + subl $4,%esp
7939 + CFI_ADJUST_CFA_OFFSET 4
7940 + pushl %edi
7941 +@@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic)
7942 + jmp 4f
7943 + SRC(1: movw (%esi), %bx )
7944 + addl $2, %esi
7945 +-DST( movw %bx, (%edi) )
7946 ++DST( movw %bx, %es:(%edi) )
7947 + addl $2, %edi
7948 + addw %bx, %ax
7949 + adcl $0, %eax
7950 +@@ -343,30 +357,30 @@ DST( movw %bx, (%edi) )
7951 + SRC(1: movl (%esi), %ebx )
7952 + SRC( movl 4(%esi), %edx )
7953 + adcl %ebx, %eax
7954 +-DST( movl %ebx, (%edi) )
7955 ++DST( movl %ebx, %es:(%edi) )
7956 + adcl %edx, %eax
7957 +-DST( movl %edx, 4(%edi) )
7958 ++DST( movl %edx, %es:4(%edi) )
7959 +
7960 + SRC( movl 8(%esi), %ebx )
7961 + SRC( movl 12(%esi), %edx )
7962 + adcl %ebx, %eax
7963 +-DST( movl %ebx, 8(%edi) )
7964 ++DST( movl %ebx, %es:8(%edi) )
7965 + adcl %edx, %eax
7966 +-DST( movl %edx, 12(%edi) )
7967 ++DST( movl %edx, %es:12(%edi) )
7968 +
7969 + SRC( movl 16(%esi), %ebx )
7970 + SRC( movl 20(%esi), %edx )
7971 + adcl %ebx, %eax
7972 +-DST( movl %ebx, 16(%edi) )
7973 ++DST( movl %ebx, %es:16(%edi) )
7974 + adcl %edx, %eax
7975 +-DST( movl %edx, 20(%edi) )
7976 ++DST( movl %edx, %es:20(%edi) )
7977 +
7978 + SRC( movl 24(%esi), %ebx )
7979 + SRC( movl 28(%esi), %edx )
7980 + adcl %ebx, %eax
7981 +-DST( movl %ebx, 24(%edi) )
7982 ++DST( movl %ebx, %es:24(%edi) )
7983 + adcl %edx, %eax
7984 +-DST( movl %edx, 28(%edi) )
7985 ++DST( movl %edx, %es:28(%edi) )
7986 +
7987 + lea 32(%esi), %esi
7988 + lea 32(%edi), %edi
7989 +@@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) )
7990 + shrl $2, %edx # This clears CF
7991 + SRC(3: movl (%esi), %ebx )
7992 + adcl %ebx, %eax
7993 +-DST( movl %ebx, (%edi) )
7994 ++DST( movl %ebx, %es:(%edi) )
7995 + lea 4(%esi), %esi
7996 + lea 4(%edi), %edi
7997 + dec %edx
7998 +@@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) )
7999 + jb 5f
8000 + SRC( movw (%esi), %cx )
8001 + leal 2(%esi), %esi
8002 +-DST( movw %cx, (%edi) )
8003 ++DST( movw %cx, %es:(%edi) )
8004 + leal 2(%edi), %edi
8005 + je 6f
8006 + shll $16,%ecx
8007 + SRC(5: movb (%esi), %cl )
8008 +-DST( movb %cl, (%edi) )
8009 ++DST( movb %cl, %es:(%edi) )
8010 + 6: addl %ecx, %eax
8011 + adcl $0, %eax
8012 + 7:
8013 +@@ -408,7 +422,7 @@ DST( movb %cl, (%edi) )
8014 +
8015 + 6001:
8016 + movl ARGBASE+20(%esp), %ebx # src_err_ptr
8017 +- movl $-EFAULT, (%ebx)
8018 ++ movl $-EFAULT, %ss:(%ebx)
8019 +
8020 + # zero the complete destination - computing the rest
8021 + # is too much work
8022 +@@ -421,11 +435,19 @@ DST( movb %cl, (%edi) )
8023 +
8024 + 6002:
8025 + movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8026 +- movl $-EFAULT,(%ebx)
8027 ++ movl $-EFAULT,%ss:(%ebx)
8028 + jmp 5000b
8029 +
8030 + .previous
8031 +
8032 ++ pushl %ss
8033 ++ CFI_ADJUST_CFA_OFFSET 4
8034 ++ popl %ds
8035 ++ CFI_ADJUST_CFA_OFFSET -4
8036 ++ pushl %ss
8037 ++ CFI_ADJUST_CFA_OFFSET 4
8038 ++ popl %es
8039 ++ CFI_ADJUST_CFA_OFFSET -4
8040 + popl %ebx
8041 + CFI_ADJUST_CFA_OFFSET -4
8042 + CFI_RESTORE ebx
8043 +@@ -439,26 +461,41 @@ DST( movb %cl, (%edi) )
8044 + CFI_ADJUST_CFA_OFFSET -4
8045 + ret
8046 + CFI_ENDPROC
8047 +-ENDPROC(csum_partial_copy_generic)
8048 ++ENDPROC(csum_partial_copy_generic_to_user)
8049 +
8050 + #else
8051 +
8052 + /* Version for PentiumII/PPro */
8053 +
8054 + #define ROUND1(x) \
8055 ++ nop; nop; nop; \
8056 + SRC(movl x(%esi), %ebx ) ; \
8057 + addl %ebx, %eax ; \
8058 +- DST(movl %ebx, x(%edi) ) ;
8059 ++ DST(movl %ebx, %es:x(%edi)) ;
8060 +
8061 + #define ROUND(x) \
8062 ++ nop; nop; nop; \
8063 + SRC(movl x(%esi), %ebx ) ; \
8064 + adcl %ebx, %eax ; \
8065 +- DST(movl %ebx, x(%edi) ) ;
8066 ++ DST(movl %ebx, %es:x(%edi)) ;
8067 +
8068 + #define ARGBASE 12
8069 +-
8070 +-ENTRY(csum_partial_copy_generic)
8071 ++
8072 ++ENTRY(csum_partial_copy_generic_to_user)
8073 + CFI_STARTPROC
8074 ++ pushl $(__USER_DS)
8075 ++ CFI_ADJUST_CFA_OFFSET 4
8076 ++ popl %es
8077 ++ CFI_ADJUST_CFA_OFFSET -4
8078 ++ jmp csum_partial_copy_generic
8079 ++
8080 ++ENTRY(csum_partial_copy_generic_from_user)
8081 ++ pushl $(__USER_DS)
8082 ++ CFI_ADJUST_CFA_OFFSET 4
8083 ++ popl %ds
8084 ++ CFI_ADJUST_CFA_OFFSET -4
8085 ++
8086 ++ENTRY(csum_partial_copy_generic)
8087 + pushl %ebx
8088 + CFI_ADJUST_CFA_OFFSET 4
8089 + CFI_REL_OFFSET ebx, 0
8090 +@@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic)
8091 + subl %ebx, %edi
8092 + lea -1(%esi),%edx
8093 + andl $-32,%edx
8094 +- lea 3f(%ebx,%ebx), %ebx
8095 ++ lea 3f(%ebx,%ebx,2), %ebx
8096 + testl %esi, %esi
8097 + jmp *%ebx
8098 + 1: addl $64,%esi
8099 +@@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic)
8100 + jb 5f
8101 + SRC( movw (%esi), %dx )
8102 + leal 2(%esi), %esi
8103 +-DST( movw %dx, (%edi) )
8104 ++DST( movw %dx, %es:(%edi) )
8105 + leal 2(%edi), %edi
8106 + je 6f
8107 + shll $16,%edx
8108 + 5:
8109 + SRC( movb (%esi), %dl )
8110 +-DST( movb %dl, (%edi) )
8111 ++DST( movb %dl, %es:(%edi) )
8112 + 6: addl %edx, %eax
8113 + adcl $0, %eax
8114 + 7:
8115 + .section .fixup, "ax"
8116 + 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
8117 +- movl $-EFAULT, (%ebx)
8118 ++ movl $-EFAULT, %ss:(%ebx)
8119 + # zero the complete destination (computing the rest is too much work)
8120 + movl ARGBASE+8(%esp),%edi # dst
8121 + movl ARGBASE+12(%esp),%ecx # len
8122 +@@ -523,10 +560,18 @@ DST( movb %dl, (%edi) )
8123 + rep; stosb
8124 + jmp 7b
8125 + 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8126 +- movl $-EFAULT, (%ebx)
8127 ++ movl $-EFAULT, %ss:(%ebx)
8128 + jmp 7b
8129 + .previous
8130 +
8131 ++ pushl %ss
8132 ++ CFI_ADJUST_CFA_OFFSET 4
8133 ++ popl %ds
8134 ++ CFI_ADJUST_CFA_OFFSET -4
8135 ++ pushl %ss
8136 ++ CFI_ADJUST_CFA_OFFSET 4
8137 ++ popl %es
8138 ++ CFI_ADJUST_CFA_OFFSET -4
8139 + popl %esi
8140 + CFI_ADJUST_CFA_OFFSET -4
8141 + CFI_RESTORE esi
8142 +@@ -538,7 +583,7 @@ DST( movb %dl, (%edi) )
8143 + CFI_RESTORE ebx
8144 + ret
8145 + CFI_ENDPROC
8146 +-ENDPROC(csum_partial_copy_generic)
8147 ++ENDPROC(csum_partial_copy_generic_to_user)
8148 +
8149 + #undef ROUND
8150 + #undef ROUND1
8151 +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
8152 +--- linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-07 12:55:34.000000000 -0500
8153 ++++ linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-18 03:38:44.000000000 -0500
8154 +@@ -44,7 +44,7 @@ ENDPROC(clear_page)
8155 +
8156 + #include <asm/cpufeature.h>
8157 +
8158 +- .section .altinstr_replacement,"ax"
8159 ++ .section .altinstr_replacement,"a"
8160 + 1: .byte 0xeb /* jmp <disp8> */
8161 + .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
8162 + 2:
8163 +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
8164 +--- linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-07 12:55:34.000000000 -0500
8165 ++++ linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-18 03:38:44.000000000 -0500
8166 +@@ -104,7 +104,7 @@ ENDPROC(copy_page)
8167 +
8168 + #include <asm/cpufeature.h>
8169 +
8170 +- .section .altinstr_replacement,"ax"
8171 ++ .section .altinstr_replacement,"a"
8172 + 1: .byte 0xeb /* jmp <disp8> */
8173 + .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
8174 + 2:
8175 +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
8176 +--- linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-07 12:55:34.000000000 -0500
8177 ++++ linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-18 03:38:44.000000000 -0500
8178 +@@ -21,7 +21,7 @@
8179 + .byte 0xe9 /* 32bit jump */
8180 + .long \orig-1f /* by default jump to orig */
8181 + 1:
8182 +- .section .altinstr_replacement,"ax"
8183 ++ .section .altinstr_replacement,"a"
8184 + 2: .byte 0xe9 /* near jump with 32bit immediate */
8185 + .long \alt-1b /* offset */ /* or alternatively to alt */
8186 + .previous
8187 +@@ -106,6 +106,8 @@ ENDPROC(__copy_from_user_inatomic)
8188 + ENTRY(bad_from_user)
8189 + bad_from_user:
8190 + CFI_STARTPROC
8191 ++ testl %edx,%edx
8192 ++ js bad_to_user
8193 + movl %edx,%ecx
8194 + xorl %eax,%eax
8195 + rep
8196 +diff -urNp linux-2.6.27.10/arch/x86/lib/getuser.S linux-2.6.27.10/arch/x86/lib/getuser.S
8197 +--- linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-07 12:55:34.000000000 -0500
8198 ++++ linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-18 03:38:44.000000000 -0500
8199 +@@ -33,6 +33,7 @@
8200 + #include <asm/asm-offsets.h>
8201 + #include <asm/thread_info.h>
8202 + #include <asm/asm.h>
8203 ++#include <asm/segment.h>
8204 +
8205 + .text
8206 + ENTRY(__get_user_1)
8207 +@@ -40,7 +41,19 @@ ENTRY(__get_user_1)
8208 + GET_THREAD_INFO(%_ASM_DX)
8209 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8210 + jae bad_get_user
8211 ++
8212 ++#ifdef CONFIG_X86_32
8213 ++ pushl $(__USER_DS)
8214 ++ popl %ds
8215 ++#endif
8216 ++
8217 + 1: movzb (%_ASM_AX),%edx
8218 ++
8219 ++#ifdef CONFIG_X86_32
8220 ++ pushl %ss
8221 ++ pop %ds
8222 ++#endif
8223 ++
8224 + xor %eax,%eax
8225 + ret
8226 + CFI_ENDPROC
8227 +@@ -53,7 +66,19 @@ ENTRY(__get_user_2)
8228 + GET_THREAD_INFO(%_ASM_DX)
8229 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8230 + jae bad_get_user
8231 ++
8232 ++#ifdef CONFIG_X86_32
8233 ++ pushl $(__USER_DS)
8234 ++ popl %ds
8235 ++#endif
8236 ++
8237 + 2: movzwl -1(%_ASM_AX),%edx
8238 ++
8239 ++#ifdef CONFIG_X86_32
8240 ++ pushl %ss
8241 ++ pop %ds
8242 ++#endif
8243 ++
8244 + xor %eax,%eax
8245 + ret
8246 + CFI_ENDPROC
8247 +@@ -66,7 +91,19 @@ ENTRY(__get_user_4)
8248 + GET_THREAD_INFO(%_ASM_DX)
8249 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8250 + jae bad_get_user
8251 ++
8252 ++#ifdef CONFIG_X86_32
8253 ++ pushl $(__USER_DS)
8254 ++ popl %ds
8255 ++#endif
8256 ++
8257 + 3: mov -3(%_ASM_AX),%edx
8258 ++
8259 ++#ifdef CONFIG_X86_32
8260 ++ pushl %ss
8261 ++ pop %ds
8262 ++#endif
8263 ++
8264 + xor %eax,%eax
8265 + ret
8266 + CFI_ENDPROC
8267 +@@ -89,6 +126,12 @@ ENDPROC(__get_user_8)
8268 +
8269 + bad_get_user:
8270 + CFI_STARTPROC
8271 ++
8272 ++#ifdef CONFIG_X86_32
8273 ++ pushl %ss
8274 ++ pop %ds
8275 ++#endif
8276 ++
8277 + xor %edx,%edx
8278 + mov $(-EFAULT),%_ASM_AX
8279 + ret
8280 +diff -urNp linux-2.6.27.10/arch/x86/lib/memcpy_64.S linux-2.6.27.10/arch/x86/lib/memcpy_64.S
8281 +--- linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-07 12:55:34.000000000 -0500
8282 ++++ linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-18 03:38:44.000000000 -0500
8283 +@@ -114,7 +114,7 @@ ENDPROC(__memcpy)
8284 + /* Some CPUs run faster using the string copy instructions.
8285 + It is also a lot simpler. Use this when possible */
8286 +
8287 +- .section .altinstr_replacement,"ax"
8288 ++ .section .altinstr_replacement,"a"
8289 + 1: .byte 0xeb /* jmp <disp8> */
8290 + .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
8291 + 2:
8292 +diff -urNp linux-2.6.27.10/arch/x86/lib/memset_64.S linux-2.6.27.10/arch/x86/lib/memset_64.S
8293 +--- linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-07 12:55:34.000000000 -0500
8294 ++++ linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-18 03:38:44.000000000 -0500
8295 +@@ -118,7 +118,7 @@ ENDPROC(__memset)
8296 +
8297 + #include <asm/cpufeature.h>
8298 +
8299 +- .section .altinstr_replacement,"ax"
8300 ++ .section .altinstr_replacement,"a"
8301 + 1: .byte 0xeb /* jmp <disp8> */
8302 + .byte (memset_c - memset) - (2f - 1b) /* offset */
8303 + 2:
8304 +diff -urNp linux-2.6.27.10/arch/x86/lib/mmx_32.c linux-2.6.27.10/arch/x86/lib/mmx_32.c
8305 +--- linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-07 12:55:34.000000000 -0500
8306 ++++ linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-18 03:38:44.000000000 -0500
8307 +@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
8308 + {
8309 + void *p;
8310 + int i;
8311 ++ unsigned long cr0;
8312 +
8313 + if (unlikely(in_interrupt()))
8314 + return __memcpy(to, from, len);
8315 +@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
8316 + kernel_fpu_begin();
8317 +
8318 + __asm__ __volatile__ (
8319 +- "1: prefetch (%0)\n" /* This set is 28 bytes */
8320 +- " prefetch 64(%0)\n"
8321 +- " prefetch 128(%0)\n"
8322 +- " prefetch 192(%0)\n"
8323 +- " prefetch 256(%0)\n"
8324 ++ "1: prefetch (%1)\n" /* This set is 28 bytes */
8325 ++ " prefetch 64(%1)\n"
8326 ++ " prefetch 128(%1)\n"
8327 ++ " prefetch 192(%1)\n"
8328 ++ " prefetch 256(%1)\n"
8329 + "2: \n"
8330 + ".section .fixup, \"ax\"\n"
8331 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8332 ++ "3: \n"
8333 ++
8334 ++#ifdef CONFIG_PAX_KERNEXEC
8335 ++ " movl %%cr0, %0\n"
8336 ++ " movl %0, %%eax\n"
8337 ++ " andl $0xFFFEFFFF, %%eax\n"
8338 ++ " movl %%eax, %%cr0\n"
8339 ++#endif
8340 ++
8341 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8342 ++
8343 ++#ifdef CONFIG_PAX_KERNEXEC
8344 ++ " movl %0, %%cr0\n"
8345 ++#endif
8346 ++
8347 + " jmp 2b\n"
8348 + ".previous\n"
8349 + _ASM_EXTABLE(1b, 3b)
8350 +- : : "r" (from));
8351 ++ : "=&r" (cr0) : "r" (from) : "ax");
8352 +
8353 + for ( ; i > 5; i--) {
8354 + __asm__ __volatile__ (
8355 +- "1: prefetch 320(%0)\n"
8356 +- "2: movq (%0), %%mm0\n"
8357 +- " movq 8(%0), %%mm1\n"
8358 +- " movq 16(%0), %%mm2\n"
8359 +- " movq 24(%0), %%mm3\n"
8360 +- " movq %%mm0, (%1)\n"
8361 +- " movq %%mm1, 8(%1)\n"
8362 +- " movq %%mm2, 16(%1)\n"
8363 +- " movq %%mm3, 24(%1)\n"
8364 +- " movq 32(%0), %%mm0\n"
8365 +- " movq 40(%0), %%mm1\n"
8366 +- " movq 48(%0), %%mm2\n"
8367 +- " movq 56(%0), %%mm3\n"
8368 +- " movq %%mm0, 32(%1)\n"
8369 +- " movq %%mm1, 40(%1)\n"
8370 +- " movq %%mm2, 48(%1)\n"
8371 +- " movq %%mm3, 56(%1)\n"
8372 ++ "1: prefetch 320(%1)\n"
8373 ++ "2: movq (%1), %%mm0\n"
8374 ++ " movq 8(%1), %%mm1\n"
8375 ++ " movq 16(%1), %%mm2\n"
8376 ++ " movq 24(%1), %%mm3\n"
8377 ++ " movq %%mm0, (%2)\n"
8378 ++ " movq %%mm1, 8(%2)\n"
8379 ++ " movq %%mm2, 16(%2)\n"
8380 ++ " movq %%mm3, 24(%2)\n"
8381 ++ " movq 32(%1), %%mm0\n"
8382 ++ " movq 40(%1), %%mm1\n"
8383 ++ " movq 48(%1), %%mm2\n"
8384 ++ " movq 56(%1), %%mm3\n"
8385 ++ " movq %%mm0, 32(%2)\n"
8386 ++ " movq %%mm1, 40(%2)\n"
8387 ++ " movq %%mm2, 48(%2)\n"
8388 ++ " movq %%mm3, 56(%2)\n"
8389 + ".section .fixup, \"ax\"\n"
8390 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8391 ++ "3:\n"
8392 ++
8393 ++#ifdef CONFIG_PAX_KERNEXEC
8394 ++ " movl %%cr0, %0\n"
8395 ++ " movl %0, %%eax\n"
8396 ++ " andl $0xFFFEFFFF, %%eax\n"
8397 ++ " movl %%eax, %%cr0\n"
8398 ++#endif
8399 ++
8400 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8401 ++
8402 ++#ifdef CONFIG_PAX_KERNEXEC
8403 ++ " movl %0, %%cr0\n"
8404 ++#endif
8405 ++
8406 + " jmp 2b\n"
8407 + ".previous\n"
8408 + _ASM_EXTABLE(1b, 3b)
8409 +- : : "r" (from), "r" (to) : "memory");
8410 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8411 +
8412 + from += 64;
8413 + to += 64;
8414 +@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
8415 + static void fast_copy_page(void *to, void *from)
8416 + {
8417 + int i;
8418 ++ unsigned long cr0;
8419 +
8420 + kernel_fpu_begin();
8421 +
8422 +@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
8423 + * but that is for later. -AV
8424 + */
8425 + __asm__ __volatile__(
8426 +- "1: prefetch (%0)\n"
8427 +- " prefetch 64(%0)\n"
8428 +- " prefetch 128(%0)\n"
8429 +- " prefetch 192(%0)\n"
8430 +- " prefetch 256(%0)\n"
8431 ++ "1: prefetch (%1)\n"
8432 ++ " prefetch 64(%1)\n"
8433 ++ " prefetch 128(%1)\n"
8434 ++ " prefetch 192(%1)\n"
8435 ++ " prefetch 256(%1)\n"
8436 + "2: \n"
8437 + ".section .fixup, \"ax\"\n"
8438 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8439 ++ "3: \n"
8440 ++
8441 ++#ifdef CONFIG_PAX_KERNEXEC
8442 ++ " movl %%cr0, %0\n"
8443 ++ " movl %0, %%eax\n"
8444 ++ " andl $0xFFFEFFFF, %%eax\n"
8445 ++ " movl %%eax, %%cr0\n"
8446 ++#endif
8447 ++
8448 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8449 ++
8450 ++#ifdef CONFIG_PAX_KERNEXEC
8451 ++ " movl %0, %%cr0\n"
8452 ++#endif
8453 ++
8454 + " jmp 2b\n"
8455 + ".previous\n"
8456 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8457 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8458 +
8459 + for (i = 0; i < (4096-320)/64; i++) {
8460 + __asm__ __volatile__ (
8461 +- "1: prefetch 320(%0)\n"
8462 +- "2: movq (%0), %%mm0\n"
8463 +- " movntq %%mm0, (%1)\n"
8464 +- " movq 8(%0), %%mm1\n"
8465 +- " movntq %%mm1, 8(%1)\n"
8466 +- " movq 16(%0), %%mm2\n"
8467 +- " movntq %%mm2, 16(%1)\n"
8468 +- " movq 24(%0), %%mm3\n"
8469 +- " movntq %%mm3, 24(%1)\n"
8470 +- " movq 32(%0), %%mm4\n"
8471 +- " movntq %%mm4, 32(%1)\n"
8472 +- " movq 40(%0), %%mm5\n"
8473 +- " movntq %%mm5, 40(%1)\n"
8474 +- " movq 48(%0), %%mm6\n"
8475 +- " movntq %%mm6, 48(%1)\n"
8476 +- " movq 56(%0), %%mm7\n"
8477 +- " movntq %%mm7, 56(%1)\n"
8478 ++ "1: prefetch 320(%1)\n"
8479 ++ "2: movq (%1), %%mm0\n"
8480 ++ " movntq %%mm0, (%2)\n"
8481 ++ " movq 8(%1), %%mm1\n"
8482 ++ " movntq %%mm1, 8(%2)\n"
8483 ++ " movq 16(%1), %%mm2\n"
8484 ++ " movntq %%mm2, 16(%2)\n"
8485 ++ " movq 24(%1), %%mm3\n"
8486 ++ " movntq %%mm3, 24(%2)\n"
8487 ++ " movq 32(%1), %%mm4\n"
8488 ++ " movntq %%mm4, 32(%2)\n"
8489 ++ " movq 40(%1), %%mm5\n"
8490 ++ " movntq %%mm5, 40(%2)\n"
8491 ++ " movq 48(%1), %%mm6\n"
8492 ++ " movntq %%mm6, 48(%2)\n"
8493 ++ " movq 56(%1), %%mm7\n"
8494 ++ " movntq %%mm7, 56(%2)\n"
8495 + ".section .fixup, \"ax\"\n"
8496 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8497 ++ "3:\n"
8498 ++
8499 ++#ifdef CONFIG_PAX_KERNEXEC
8500 ++ " movl %%cr0, %0\n"
8501 ++ " movl %0, %%eax\n"
8502 ++ " andl $0xFFFEFFFF, %%eax\n"
8503 ++ " movl %%eax, %%cr0\n"
8504 ++#endif
8505 ++
8506 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8507 ++
8508 ++#ifdef CONFIG_PAX_KERNEXEC
8509 ++ " movl %0, %%cr0\n"
8510 ++#endif
8511 ++
8512 + " jmp 2b\n"
8513 + ".previous\n"
8514 +- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
8515 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8516 +
8517 + from += 64;
8518 + to += 64;
8519 +@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
8520 + static void fast_copy_page(void *to, void *from)
8521 + {
8522 + int i;
8523 ++ unsigned long cr0;
8524 +
8525 + kernel_fpu_begin();
8526 +
8527 + __asm__ __volatile__ (
8528 +- "1: prefetch (%0)\n"
8529 +- " prefetch 64(%0)\n"
8530 +- " prefetch 128(%0)\n"
8531 +- " prefetch 192(%0)\n"
8532 +- " prefetch 256(%0)\n"
8533 ++ "1: prefetch (%1)\n"
8534 ++ " prefetch 64(%1)\n"
8535 ++ " prefetch 128(%1)\n"
8536 ++ " prefetch 192(%1)\n"
8537 ++ " prefetch 256(%1)\n"
8538 + "2: \n"
8539 + ".section .fixup, \"ax\"\n"
8540 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8541 ++ "3: \n"
8542 ++
8543 ++#ifdef CONFIG_PAX_KERNEXEC
8544 ++ " movl %%cr0, %0\n"
8545 ++ " movl %0, %%eax\n"
8546 ++ " andl $0xFFFEFFFF, %%eax\n"
8547 ++ " movl %%eax, %%cr0\n"
8548 ++#endif
8549 ++
8550 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8551 ++
8552 ++#ifdef CONFIG_PAX_KERNEXEC
8553 ++ " movl %0, %%cr0\n"
8554 ++#endif
8555 ++
8556 + " jmp 2b\n"
8557 + ".previous\n"
8558 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8559 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8560 +
8561 + for (i = 0; i < 4096/64; i++) {
8562 + __asm__ __volatile__ (
8563 +- "1: prefetch 320(%0)\n"
8564 +- "2: movq (%0), %%mm0\n"
8565 +- " movq 8(%0), %%mm1\n"
8566 +- " movq 16(%0), %%mm2\n"
8567 +- " movq 24(%0), %%mm3\n"
8568 +- " movq %%mm0, (%1)\n"
8569 +- " movq %%mm1, 8(%1)\n"
8570 +- " movq %%mm2, 16(%1)\n"
8571 +- " movq %%mm3, 24(%1)\n"
8572 +- " movq 32(%0), %%mm0\n"
8573 +- " movq 40(%0), %%mm1\n"
8574 +- " movq 48(%0), %%mm2\n"
8575 +- " movq 56(%0), %%mm3\n"
8576 +- " movq %%mm0, 32(%1)\n"
8577 +- " movq %%mm1, 40(%1)\n"
8578 +- " movq %%mm2, 48(%1)\n"
8579 +- " movq %%mm3, 56(%1)\n"
8580 ++ "1: prefetch 320(%1)\n"
8581 ++ "2: movq (%1), %%mm0\n"
8582 ++ " movq 8(%1), %%mm1\n"
8583 ++ " movq 16(%1), %%mm2\n"
8584 ++ " movq 24(%1), %%mm3\n"
8585 ++ " movq %%mm0, (%2)\n"
8586 ++ " movq %%mm1, 8(%2)\n"
8587 ++ " movq %%mm2, 16(%2)\n"
8588 ++ " movq %%mm3, 24(%2)\n"
8589 ++ " movq 32(%1), %%mm0\n"
8590 ++ " movq 40(%1), %%mm1\n"
8591 ++ " movq 48(%1), %%mm2\n"
8592 ++ " movq 56(%1), %%mm3\n"
8593 ++ " movq %%mm0, 32(%2)\n"
8594 ++ " movq %%mm1, 40(%2)\n"
8595 ++ " movq %%mm2, 48(%2)\n"
8596 ++ " movq %%mm3, 56(%2)\n"
8597 + ".section .fixup, \"ax\"\n"
8598 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8599 ++ "3:\n"
8600 ++
8601 ++#ifdef CONFIG_PAX_KERNEXEC
8602 ++ " movl %%cr0, %0\n"
8603 ++ " movl %0, %%eax\n"
8604 ++ " andl $0xFFFEFFFF, %%eax\n"
8605 ++ " movl %%eax, %%cr0\n"
8606 ++#endif
8607 ++
8608 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8609 ++
8610 ++#ifdef CONFIG_PAX_KERNEXEC
8611 ++ " movl %0, %%cr0\n"
8612 ++#endif
8613 ++
8614 + " jmp 2b\n"
8615 + ".previous\n"
8616 + _ASM_EXTABLE(1b, 3b)
8617 +- : : "r" (from), "r" (to) : "memory");
8618 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8619 +
8620 + from += 64;
8621 + to += 64;
8622 +diff -urNp linux-2.6.27.10/arch/x86/lib/putuser.S linux-2.6.27.10/arch/x86/lib/putuser.S
8623 +--- linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-07 12:55:34.000000000 -0500
8624 ++++ linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-18 03:38:44.000000000 -0500
8625 +@@ -15,6 +15,7 @@
8626 + #include <asm/thread_info.h>
8627 + #include <asm/errno.h>
8628 + #include <asm/asm.h>
8629 ++#include <asm/segment.h>
8630 +
8631 +
8632 + /*
8633 +@@ -39,7 +40,19 @@ ENTRY(__put_user_1)
8634 + ENTER
8635 + cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
8636 + jae bad_put_user
8637 ++
8638 ++#ifdef CONFIG_X86_32
8639 ++ pushl $(__USER_DS)
8640 ++ popl %ds
8641 ++#endif
8642 ++
8643 + 1: movb %al,(%_ASM_CX)
8644 ++
8645 ++#ifdef CONFIG_X86_32
8646 ++ pushl %ss
8647 ++ popl %ds
8648 ++#endif
8649 ++
8650 + xor %eax,%eax
8651 + EXIT
8652 + ENDPROC(__put_user_1)
8653 +@@ -50,7 +63,19 @@ ENTRY(__put_user_2)
8654 + sub $1,%_ASM_BX
8655 + cmp %_ASM_BX,%_ASM_CX
8656 + jae bad_put_user
8657 ++
8658 ++#ifdef CONFIG_X86_32
8659 ++ pushl $(__USER_DS)
8660 ++ popl %ds
8661 ++#endif
8662 ++
8663 + 2: movw %ax,(%_ASM_CX)
8664 ++
8665 ++#ifdef CONFIG_X86_32
8666 ++ pushl %ss
8667 ++ popl %ds
8668 ++#endif
8669 ++
8670 + xor %eax,%eax
8671 + EXIT
8672 + ENDPROC(__put_user_2)
8673 +@@ -61,7 +86,19 @@ ENTRY(__put_user_4)
8674 + sub $3,%_ASM_BX
8675 + cmp %_ASM_BX,%_ASM_CX
8676 + jae bad_put_user
8677 ++
8678 ++#ifdef CONFIG_X86_32
8679 ++ pushl $(__USER_DS)
8680 ++ popl %ds
8681 ++#endif
8682 ++
8683 + 3: movl %eax,(%_ASM_CX)
8684 ++
8685 ++#ifdef CONFIG_X86_32
8686 ++ pushl %ss
8687 ++ popl %ds
8688 ++#endif
8689 ++
8690 + xor %eax,%eax
8691 + EXIT
8692 + ENDPROC(__put_user_4)
8693 +@@ -72,16 +109,34 @@ ENTRY(__put_user_8)
8694 + sub $7,%_ASM_BX
8695 + cmp %_ASM_BX,%_ASM_CX
8696 + jae bad_put_user
8697 ++
8698 ++#ifdef CONFIG_X86_32
8699 ++ pushl $(__USER_DS)
8700 ++ popl %ds
8701 ++#endif
8702 ++
8703 + 4: mov %_ASM_AX,(%_ASM_CX)
8704 + #ifdef CONFIG_X86_32
8705 + 5: movl %edx,4(%_ASM_CX)
8706 + #endif
8707 ++
8708 ++#ifdef CONFIG_X86_32
8709 ++ pushl %ss
8710 ++ popl %ds
8711 ++#endif
8712 ++
8713 + xor %eax,%eax
8714 + EXIT
8715 + ENDPROC(__put_user_8)
8716 +
8717 + bad_put_user:
8718 + CFI_STARTPROC
8719 ++
8720 ++#ifdef CONFIG_X86_32
8721 ++ pushl %ss
8722 ++ popl %ds
8723 ++#endif
8724 ++
8725 + movl $-EFAULT,%eax
8726 + EXIT
8727 + END(bad_put_user)
8728 +diff -urNp linux-2.6.27.10/arch/x86/lib/usercopy_32.c linux-2.6.27.10/arch/x86/lib/usercopy_32.c
8729 +--- linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-07 12:55:34.000000000 -0500
8730 ++++ linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-18 03:38:44.000000000 -0500
8731 +@@ -29,31 +29,38 @@ static inline int __movsl_is_ok(unsigned
8732 + * Copy a null terminated string from userspace.
8733 + */
8734 +
8735 +-#define __do_strncpy_from_user(dst, src, count, res) \
8736 +-do { \
8737 +- int __d0, __d1, __d2; \
8738 +- might_sleep(); \
8739 +- __asm__ __volatile__( \
8740 +- " testl %1,%1\n" \
8741 +- " jz 2f\n" \
8742 +- "0: lodsb\n" \
8743 +- " stosb\n" \
8744 +- " testb %%al,%%al\n" \
8745 +- " jz 1f\n" \
8746 +- " decl %1\n" \
8747 +- " jnz 0b\n" \
8748 +- "1: subl %1,%0\n" \
8749 +- "2:\n" \
8750 +- ".section .fixup,\"ax\"\n" \
8751 +- "3: movl %5,%0\n" \
8752 +- " jmp 2b\n" \
8753 +- ".previous\n" \
8754 +- _ASM_EXTABLE(0b,3b) \
8755 +- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
8756 +- "=&D" (__d2) \
8757 +- : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
8758 +- : "memory"); \
8759 +-} while (0)
8760 ++static long __do_strncpy_from_user(char *dst, const char __user *src, long count)
8761 ++{
8762 ++ int __d0, __d1, __d2;
8763 ++ long res = -EFAULT;
8764 ++
8765 ++ might_sleep();
8766 ++ __asm__ __volatile__(
8767 ++ " movw %w10,%%ds\n"
8768 ++ " testl %1,%1\n"
8769 ++ " jz 2f\n"
8770 ++ "0: lodsb\n"
8771 ++ " stosb\n"
8772 ++ " testb %%al,%%al\n"
8773 ++ " jz 1f\n"
8774 ++ " decl %1\n"
8775 ++ " jnz 0b\n"
8776 ++ "1: subl %1,%0\n"
8777 ++ "2:\n"
8778 ++ " pushl %%ss\n"
8779 ++ " popl %%ds\n"
8780 ++ ".section .fixup,\"ax\"\n"
8781 ++ "3: movl %5,%0\n"
8782 ++ " jmp 2b\n"
8783 ++ ".previous\n"
8784 ++ _ASM_EXTABLE(0b,3b)
8785 ++ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),
8786 ++ "=&D" (__d2)
8787 ++ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst),
8788 ++ "r"(__USER_DS)
8789 ++ : "memory");
8790 ++ return res;
8791 ++}
8792 +
8793 + /**
8794 + * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
8795 +@@ -78,9 +85,7 @@ do { \
8796 + long
8797 + __strncpy_from_user(char *dst, const char __user *src, long count)
8798 + {
8799 +- long res;
8800 +- __do_strncpy_from_user(dst, src, count, res);
8801 +- return res;
8802 ++ return __do_strncpy_from_user(dst, src, count);
8803 + }
8804 + EXPORT_SYMBOL(__strncpy_from_user);
8805 +
8806 +@@ -107,7 +112,7 @@ strncpy_from_user(char *dst, const char
8807 + {
8808 + long res = -EFAULT;
8809 + if (access_ok(VERIFY_READ, src, 1))
8810 +- __do_strncpy_from_user(dst, src, count, res);
8811 ++ res = __do_strncpy_from_user(dst, src, count);
8812 + return res;
8813 + }
8814 + EXPORT_SYMBOL(strncpy_from_user);
8815 +@@ -116,24 +121,30 @@ EXPORT_SYMBOL(strncpy_from_user);
8816 + * Zero Userspace
8817 + */
8818 +
8819 +-#define __do_clear_user(addr,size) \
8820 +-do { \
8821 +- int __d0; \
8822 +- might_sleep(); \
8823 +- __asm__ __volatile__( \
8824 +- "0: rep; stosl\n" \
8825 +- " movl %2,%0\n" \
8826 +- "1: rep; stosb\n" \
8827 +- "2:\n" \
8828 +- ".section .fixup,\"ax\"\n" \
8829 +- "3: lea 0(%2,%0,4),%0\n" \
8830 +- " jmp 2b\n" \
8831 +- ".previous\n" \
8832 +- _ASM_EXTABLE(0b,3b) \
8833 +- _ASM_EXTABLE(1b,2b) \
8834 +- : "=&c"(size), "=&D" (__d0) \
8835 +- : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
8836 +-} while (0)
8837 ++static unsigned long __do_clear_user(void __user *addr, unsigned long size)
8838 ++{
8839 ++ int __d0;
8840 ++
8841 ++ might_sleep();
8842 ++ __asm__ __volatile__(
8843 ++ " movw %w6,%%es\n"
8844 ++ "0: rep; stosl\n"
8845 ++ " movl %2,%0\n"
8846 ++ "1: rep; stosb\n"
8847 ++ "2:\n"
8848 ++ " pushl %%ss\n"
8849 ++ " popl %%es\n"
8850 ++ ".section .fixup,\"ax\"\n"
8851 ++ "3: lea 0(%2,%0,4),%0\n"
8852 ++ " jmp 2b\n"
8853 ++ ".previous\n"
8854 ++ _ASM_EXTABLE(0b,3b)
8855 ++ _ASM_EXTABLE(1b,2b)
8856 ++ : "=&c"(size), "=&D" (__d0)
8857 ++ : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0),
8858 ++ "r"(__USER_DS));
8859 ++ return size;
8860 ++}
8861 +
8862 + /**
8863 + * clear_user: - Zero a block of memory in user space.
8864 +@@ -150,7 +161,7 @@ clear_user(void __user *to, unsigned lon
8865 + {
8866 + might_sleep();
8867 + if (access_ok(VERIFY_WRITE, to, n))
8868 +- __do_clear_user(to, n);
8869 ++ n = __do_clear_user(to, n);
8870 + return n;
8871 + }
8872 + EXPORT_SYMBOL(clear_user);
8873 +@@ -169,8 +180,7 @@ EXPORT_SYMBOL(clear_user);
8874 + unsigned long
8875 + __clear_user(void __user *to, unsigned long n)
8876 + {
8877 +- __do_clear_user(to, n);
8878 +- return n;
8879 ++ return __do_clear_user(to, n);
8880 + }
8881 + EXPORT_SYMBOL(__clear_user);
8882 +
8883 +@@ -193,14 +203,17 @@ long strnlen_user(const char __user *s,
8884 + might_sleep();
8885 +
8886 + __asm__ __volatile__(
8887 ++ " movw %w8,%%es\n"
8888 + " testl %0, %0\n"
8889 + " jz 3f\n"
8890 +- " andl %0,%%ecx\n"
8891 ++ " movl %0,%%ecx\n"
8892 + "0: repne; scasb\n"
8893 + " setne %%al\n"
8894 + " subl %%ecx,%0\n"
8895 + " addl %0,%%eax\n"
8896 + "1:\n"
8897 ++ " pushl %%ss\n"
8898 ++ " popl %%es\n"
8899 + ".section .fixup,\"ax\"\n"
8900 + "2: xorl %%eax,%%eax\n"
8901 + " jmp 1b\n"
8902 +@@ -212,7 +225,7 @@ long strnlen_user(const char __user *s,
8903 + " .long 0b,2b\n"
8904 + ".previous"
8905 + :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
8906 +- :"0" (n), "1" (s), "2" (0), "3" (mask)
8907 ++ :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS)
8908 + :"cc");
8909 + return res & mask;
8910 + }
8911 +@@ -220,10 +233,11 @@ EXPORT_SYMBOL(strnlen_user);
8912 +
8913 + #ifdef CONFIG_X86_INTEL_USERCOPY
8914 + static unsigned long
8915 +-__copy_user_intel(void __user *to, const void *from, unsigned long size)
8916 ++__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
8917 + {
8918 + int d0, d1;
8919 + __asm__ __volatile__(
8920 ++ " movw %w6, %%es\n"
8921 + " .align 2,0x90\n"
8922 + "1: movl 32(%4), %%eax\n"
8923 + " cmpl $67, %0\n"
8924 +@@ -232,36 +246,36 @@ __copy_user_intel(void __user *to, const
8925 + " .align 2,0x90\n"
8926 + "3: movl 0(%4), %%eax\n"
8927 + "4: movl 4(%4), %%edx\n"
8928 +- "5: movl %%eax, 0(%3)\n"
8929 +- "6: movl %%edx, 4(%3)\n"
8930 ++ "5: movl %%eax, %%es:0(%3)\n"
8931 ++ "6: movl %%edx, %%es:4(%3)\n"
8932 + "7: movl 8(%4), %%eax\n"
8933 + "8: movl 12(%4),%%edx\n"
8934 +- "9: movl %%eax, 8(%3)\n"
8935 +- "10: movl %%edx, 12(%3)\n"
8936 ++ "9: movl %%eax, %%es:8(%3)\n"
8937 ++ "10: movl %%edx, %%es:12(%3)\n"
8938 + "11: movl 16(%4), %%eax\n"
8939 + "12: movl 20(%4), %%edx\n"
8940 +- "13: movl %%eax, 16(%3)\n"
8941 +- "14: movl %%edx, 20(%3)\n"
8942 ++ "13: movl %%eax, %%es:16(%3)\n"
8943 ++ "14: movl %%edx, %%es:20(%3)\n"
8944 + "15: movl 24(%4), %%eax\n"
8945 + "16: movl 28(%4), %%edx\n"
8946 +- "17: movl %%eax, 24(%3)\n"
8947 +- "18: movl %%edx, 28(%3)\n"
8948 ++ "17: movl %%eax, %%es:24(%3)\n"
8949 ++ "18: movl %%edx, %%es:28(%3)\n"
8950 + "19: movl 32(%4), %%eax\n"
8951 + "20: movl 36(%4), %%edx\n"
8952 +- "21: movl %%eax, 32(%3)\n"
8953 +- "22: movl %%edx, 36(%3)\n"
8954 ++ "21: movl %%eax, %%es:32(%3)\n"
8955 ++ "22: movl %%edx, %%es:36(%3)\n"
8956 + "23: movl 40(%4), %%eax\n"
8957 + "24: movl 44(%4), %%edx\n"
8958 +- "25: movl %%eax, 40(%3)\n"
8959 +- "26: movl %%edx, 44(%3)\n"
8960 ++ "25: movl %%eax, %%es:40(%3)\n"
8961 ++ "26: movl %%edx, %%es:44(%3)\n"
8962 + "27: movl 48(%4), %%eax\n"
8963 + "28: movl 52(%4), %%edx\n"
8964 +- "29: movl %%eax, 48(%3)\n"
8965 +- "30: movl %%edx, 52(%3)\n"
8966 ++ "29: movl %%eax, %%es:48(%3)\n"
8967 ++ "30: movl %%edx, %%es:52(%3)\n"
8968 + "31: movl 56(%4), %%eax\n"
8969 + "32: movl 60(%4), %%edx\n"
8970 +- "33: movl %%eax, 56(%3)\n"
8971 +- "34: movl %%edx, 60(%3)\n"
8972 ++ "33: movl %%eax, %%es:56(%3)\n"
8973 ++ "34: movl %%edx, %%es:60(%3)\n"
8974 + " addl $-64, %0\n"
8975 + " addl $64, %4\n"
8976 + " addl $64, %3\n"
8977 +@@ -275,6 +289,8 @@ __copy_user_intel(void __user *to, const
8978 + "36: movl %%eax, %0\n"
8979 + "37: rep; movsb\n"
8980 + "100:\n"
8981 ++ " pushl %%ss\n"
8982 ++ " popl %%es\n"
8983 + ".section .fixup,\"ax\"\n"
8984 + "101: lea 0(%%eax,%0,4),%0\n"
8985 + " jmp 100b\n"
8986 +@@ -321,7 +337,117 @@ __copy_user_intel(void __user *to, const
8987 + " .long 99b,101b\n"
8988 + ".previous"
8989 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
8990 +- : "1"(to), "2"(from), "0"(size)
8991 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
8992 ++ : "eax", "edx", "memory");
8993 ++ return size;
8994 ++}
8995 ++
8996 ++static unsigned long
8997 ++__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
8998 ++{
8999 ++ int d0, d1;
9000 ++ __asm__ __volatile__(
9001 ++ " movw %w6, %%ds\n"
9002 ++ " .align 2,0x90\n"
9003 ++ "1: movl 32(%4), %%eax\n"
9004 ++ " cmpl $67, %0\n"
9005 ++ " jbe 3f\n"
9006 ++ "2: movl 64(%4), %%eax\n"
9007 ++ " .align 2,0x90\n"
9008 ++ "3: movl 0(%4), %%eax\n"
9009 ++ "4: movl 4(%4), %%edx\n"
9010 ++ "5: movl %%eax, %%es:0(%3)\n"
9011 ++ "6: movl %%edx, %%es:4(%3)\n"
9012 ++ "7: movl 8(%4), %%eax\n"
9013 ++ "8: movl 12(%4),%%edx\n"
9014 ++ "9: movl %%eax, %%es:8(%3)\n"
9015 ++ "10: movl %%edx, %%es:12(%3)\n"
9016 ++ "11: movl 16(%4), %%eax\n"
9017 ++ "12: movl 20(%4), %%edx\n"
9018 ++ "13: movl %%eax, %%es:16(%3)\n"
9019 ++ "14: movl %%edx, %%es:20(%3)\n"
9020 ++ "15: movl 24(%4), %%eax\n"
9021 ++ "16: movl 28(%4), %%edx\n"
9022 ++ "17: movl %%eax, %%es:24(%3)\n"
9023 ++ "18: movl %%edx, %%es:28(%3)\n"
9024 ++ "19: movl 32(%4), %%eax\n"
9025 ++ "20: movl 36(%4), %%edx\n"
9026 ++ "21: movl %%eax, %%es:32(%3)\n"
9027 ++ "22: movl %%edx, %%es:36(%3)\n"
9028 ++ "23: movl 40(%4), %%eax\n"
9029 ++ "24: movl 44(%4), %%edx\n"
9030 ++ "25: movl %%eax, %%es:40(%3)\n"
9031 ++ "26: movl %%edx, %%es:44(%3)\n"
9032 ++ "27: movl 48(%4), %%eax\n"
9033 ++ "28: movl 52(%4), %%edx\n"
9034 ++ "29: movl %%eax, %%es:48(%3)\n"
9035 ++ "30: movl %%edx, %%es:52(%3)\n"
9036 ++ "31: movl 56(%4), %%eax\n"
9037 ++ "32: movl 60(%4), %%edx\n"
9038 ++ "33: movl %%eax, %%es:56(%3)\n"
9039 ++ "34: movl %%edx, %%es:60(%3)\n"
9040 ++ " addl $-64, %0\n"
9041 ++ " addl $64, %4\n"
9042 ++ " addl $64, %3\n"
9043 ++ " cmpl $63, %0\n"
9044 ++ " ja 1b\n"
9045 ++ "35: movl %0, %%eax\n"
9046 ++ " shrl $2, %0\n"
9047 ++ " andl $3, %%eax\n"
9048 ++ " cld\n"
9049 ++ "99: rep; movsl\n"
9050 ++ "36: movl %%eax, %0\n"
9051 ++ "37: rep; movsb\n"
9052 ++ "100:\n"
9053 ++ " pushl %%ss\n"
9054 ++ " popl %%ds\n"
9055 ++ ".section .fixup,\"ax\"\n"
9056 ++ "101: lea 0(%%eax,%0,4),%0\n"
9057 ++ " jmp 100b\n"
9058 ++ ".previous\n"
9059 ++ ".section __ex_table,\"a\"\n"
9060 ++ " .align 4\n"
9061 ++ " .long 1b,100b\n"
9062 ++ " .long 2b,100b\n"
9063 ++ " .long 3b,100b\n"
9064 ++ " .long 4b,100b\n"
9065 ++ " .long 5b,100b\n"
9066 ++ " .long 6b,100b\n"
9067 ++ " .long 7b,100b\n"
9068 ++ " .long 8b,100b\n"
9069 ++ " .long 9b,100b\n"
9070 ++ " .long 10b,100b\n"
9071 ++ " .long 11b,100b\n"
9072 ++ " .long 12b,100b\n"
9073 ++ " .long 13b,100b\n"
9074 ++ " .long 14b,100b\n"
9075 ++ " .long 15b,100b\n"
9076 ++ " .long 16b,100b\n"
9077 ++ " .long 17b,100b\n"
9078 ++ " .long 18b,100b\n"
9079 ++ " .long 19b,100b\n"
9080 ++ " .long 20b,100b\n"
9081 ++ " .long 21b,100b\n"
9082 ++ " .long 22b,100b\n"
9083 ++ " .long 23b,100b\n"
9084 ++ " .long 24b,100b\n"
9085 ++ " .long 25b,100b\n"
9086 ++ " .long 26b,100b\n"
9087 ++ " .long 27b,100b\n"
9088 ++ " .long 28b,100b\n"
9089 ++ " .long 29b,100b\n"
9090 ++ " .long 30b,100b\n"
9091 ++ " .long 31b,100b\n"
9092 ++ " .long 32b,100b\n"
9093 ++ " .long 33b,100b\n"
9094 ++ " .long 34b,100b\n"
9095 ++ " .long 35b,100b\n"
9096 ++ " .long 36b,100b\n"
9097 ++ " .long 37b,100b\n"
9098 ++ " .long 99b,101b\n"
9099 ++ ".previous"
9100 ++ : "=&c"(size), "=&D" (d0), "=&S" (d1)
9101 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9102 + : "eax", "edx", "memory");
9103 + return size;
9104 + }
9105 +@@ -331,6 +457,7 @@ __copy_user_zeroing_intel(void *to, cons
9106 + {
9107 + int d0, d1;
9108 + __asm__ __volatile__(
9109 ++ " movw %w6, %%ds\n"
9110 + " .align 2,0x90\n"
9111 + "0: movl 32(%4), %%eax\n"
9112 + " cmpl $67, %0\n"
9113 +@@ -339,36 +466,36 @@ __copy_user_zeroing_intel(void *to, cons
9114 + " .align 2,0x90\n"
9115 + "2: movl 0(%4), %%eax\n"
9116 + "21: movl 4(%4), %%edx\n"
9117 +- " movl %%eax, 0(%3)\n"
9118 +- " movl %%edx, 4(%3)\n"
9119 ++ " movl %%eax, %%es:0(%3)\n"
9120 ++ " movl %%edx, %%es:4(%3)\n"
9121 + "3: movl 8(%4), %%eax\n"
9122 + "31: movl 12(%4),%%edx\n"
9123 +- " movl %%eax, 8(%3)\n"
9124 +- " movl %%edx, 12(%3)\n"
9125 ++ " movl %%eax, %%es:8(%3)\n"
9126 ++ " movl %%edx, %%es:12(%3)\n"
9127 + "4: movl 16(%4), %%eax\n"
9128 + "41: movl 20(%4), %%edx\n"
9129 +- " movl %%eax, 16(%3)\n"
9130 +- " movl %%edx, 20(%3)\n"
9131 ++ " movl %%eax, %%es:16(%3)\n"
9132 ++ " movl %%edx, %%es:20(%3)\n"
9133 + "10: movl 24(%4), %%eax\n"
9134 + "51: movl 28(%4), %%edx\n"
9135 +- " movl %%eax, 24(%3)\n"
9136 +- " movl %%edx, 28(%3)\n"
9137 ++ " movl %%eax, %%es:24(%3)\n"
9138 ++ " movl %%edx, %%es:28(%3)\n"
9139 + "11: movl 32(%4), %%eax\n"
9140 + "61: movl 36(%4), %%edx\n"
9141 +- " movl %%eax, 32(%3)\n"
9142 +- " movl %%edx, 36(%3)\n"
9143 ++ " movl %%eax, %%es:32(%3)\n"
9144 ++ " movl %%edx, %%es:36(%3)\n"
9145 + "12: movl 40(%4), %%eax\n"
9146 + "71: movl 44(%4), %%edx\n"
9147 +- " movl %%eax, 40(%3)\n"
9148 +- " movl %%edx, 44(%3)\n"
9149 ++ " movl %%eax, %%es:40(%3)\n"
9150 ++ " movl %%edx, %%es:44(%3)\n"
9151 + "13: movl 48(%4), %%eax\n"
9152 + "81: movl 52(%4), %%edx\n"
9153 +- " movl %%eax, 48(%3)\n"
9154 +- " movl %%edx, 52(%3)\n"
9155 ++ " movl %%eax, %%es:48(%3)\n"
9156 ++ " movl %%edx, %%es:52(%3)\n"
9157 + "14: movl 56(%4), %%eax\n"
9158 + "91: movl 60(%4), %%edx\n"
9159 +- " movl %%eax, 56(%3)\n"
9160 +- " movl %%edx, 60(%3)\n"
9161 ++ " movl %%eax, %%es:56(%3)\n"
9162 ++ " movl %%edx, %%es:60(%3)\n"
9163 + " addl $-64, %0\n"
9164 + " addl $64, %4\n"
9165 + " addl $64, %3\n"
9166 +@@ -382,6 +509,8 @@ __copy_user_zeroing_intel(void *to, cons
9167 + " movl %%eax,%0\n"
9168 + "7: rep; movsb\n"
9169 + "8:\n"
9170 ++ " pushl %%ss\n"
9171 ++ " popl %%ds\n"
9172 + ".section .fixup,\"ax\"\n"
9173 + "9: lea 0(%%eax,%0,4),%0\n"
9174 + "16: pushl %0\n"
9175 +@@ -416,7 +545,7 @@ __copy_user_zeroing_intel(void *to, cons
9176 + " .long 7b,16b\n"
9177 + ".previous"
9178 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9179 +- : "1"(to), "2"(from), "0"(size)
9180 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9181 + : "eax", "edx", "memory");
9182 + return size;
9183 + }
9184 +@@ -432,6 +561,7 @@ static unsigned long __copy_user_zeroing
9185 + int d0, d1;
9186 +
9187 + __asm__ __volatile__(
9188 ++ " movw %w6, %%ds\n"
9189 + " .align 2,0x90\n"
9190 + "0: movl 32(%4), %%eax\n"
9191 + " cmpl $67, %0\n"
9192 +@@ -440,36 +570,36 @@ static unsigned long __copy_user_zeroing
9193 + " .align 2,0x90\n"
9194 + "2: movl 0(%4), %%eax\n"
9195 + "21: movl 4(%4), %%edx\n"
9196 +- " movnti %%eax, 0(%3)\n"
9197 +- " movnti %%edx, 4(%3)\n"
9198 ++ " movnti %%eax, %%es:0(%3)\n"
9199 ++ " movnti %%edx, %%es:4(%3)\n"
9200 + "3: movl 8(%4), %%eax\n"
9201 + "31: movl 12(%4),%%edx\n"
9202 +- " movnti %%eax, 8(%3)\n"
9203 +- " movnti %%edx, 12(%3)\n"
9204 ++ " movnti %%eax, %%es:8(%3)\n"
9205 ++ " movnti %%edx, %%es:12(%3)\n"
9206 + "4: movl 16(%4), %%eax\n"
9207 + "41: movl 20(%4), %%edx\n"
9208 +- " movnti %%eax, 16(%3)\n"
9209 +- " movnti %%edx, 20(%3)\n"
9210 ++ " movnti %%eax, %%es:16(%3)\n"
9211 ++ " movnti %%edx, %%es:20(%3)\n"
9212 + "10: movl 24(%4), %%eax\n"
9213 + "51: movl 28(%4), %%edx\n"
9214 +- " movnti %%eax, 24(%3)\n"
9215 +- " movnti %%edx, 28(%3)\n"
9216 ++ " movnti %%eax, %%es:24(%3)\n"
9217 ++ " movnti %%edx, %%es:28(%3)\n"
9218 + "11: movl 32(%4), %%eax\n"
9219 + "61: movl 36(%4), %%edx\n"
9220 +- " movnti %%eax, 32(%3)\n"
9221 +- " movnti %%edx, 36(%3)\n"
9222 ++ " movnti %%eax, %%es:32(%3)\n"
9223 ++ " movnti %%edx, %%es:36(%3)\n"
9224 + "12: movl 40(%4), %%eax\n"
9225 + "71: movl 44(%4), %%edx\n"
9226 +- " movnti %%eax, 40(%3)\n"
9227 +- " movnti %%edx, 44(%3)\n"
9228 ++ " movnti %%eax, %%es:40(%3)\n"
9229 ++ " movnti %%edx, %%es:44(%3)\n"
9230 + "13: movl 48(%4), %%eax\n"
9231 + "81: movl 52(%4), %%edx\n"
9232 +- " movnti %%eax, 48(%3)\n"
9233 +- " movnti %%edx, 52(%3)\n"
9234 ++ " movnti %%eax, %%es:48(%3)\n"
9235 ++ " movnti %%edx, %%es:52(%3)\n"
9236 + "14: movl 56(%4), %%eax\n"
9237 + "91: movl 60(%4), %%edx\n"
9238 +- " movnti %%eax, 56(%3)\n"
9239 +- " movnti %%edx, 60(%3)\n"
9240 ++ " movnti %%eax, %%es:56(%3)\n"
9241 ++ " movnti %%edx, %%es:60(%3)\n"
9242 + " addl $-64, %0\n"
9243 + " addl $64, %4\n"
9244 + " addl $64, %3\n"
9245 +@@ -484,6 +614,8 @@ static unsigned long __copy_user_zeroing
9246 + " movl %%eax,%0\n"
9247 + "7: rep; movsb\n"
9248 + "8:\n"
9249 ++ " pushl %%ss\n"
9250 ++ " popl %%ds\n"
9251 + ".section .fixup,\"ax\"\n"
9252 + "9: lea 0(%%eax,%0,4),%0\n"
9253 + "16: pushl %0\n"
9254 +@@ -518,7 +650,7 @@ static unsigned long __copy_user_zeroing
9255 + " .long 7b,16b\n"
9256 + ".previous"
9257 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9258 +- : "1"(to), "2"(from), "0"(size)
9259 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9260 + : "eax", "edx", "memory");
9261 + return size;
9262 + }
9263 +@@ -529,6 +661,7 @@ static unsigned long __copy_user_intel_n
9264 + int d0, d1;
9265 +
9266 + __asm__ __volatile__(
9267 ++ " movw %w6, %%ds\n"
9268 + " .align 2,0x90\n"
9269 + "0: movl 32(%4), %%eax\n"
9270 + " cmpl $67, %0\n"
9271 +@@ -537,36 +670,36 @@ static unsigned long __copy_user_intel_n
9272 + " .align 2,0x90\n"
9273 + "2: movl 0(%4), %%eax\n"
9274 + "21: movl 4(%4), %%edx\n"
9275 +- " movnti %%eax, 0(%3)\n"
9276 +- " movnti %%edx, 4(%3)\n"
9277 ++ " movnti %%eax, %%es:0(%3)\n"
9278 ++ " movnti %%edx, %%es:4(%3)\n"
9279 + "3: movl 8(%4), %%eax\n"
9280 + "31: movl 12(%4),%%edx\n"
9281 +- " movnti %%eax, 8(%3)\n"
9282 +- " movnti %%edx, 12(%3)\n"
9283 ++ " movnti %%eax, %%es:8(%3)\n"
9284 ++ " movnti %%edx, %%es:12(%3)\n"
9285 + "4: movl 16(%4), %%eax\n"
9286 + "41: movl 20(%4), %%edx\n"
9287 +- " movnti %%eax, 16(%3)\n"
9288 +- " movnti %%edx, 20(%3)\n"
9289 ++ " movnti %%eax, %%es:16(%3)\n"
9290 ++ " movnti %%edx, %%es:20(%3)\n"
9291 + "10: movl 24(%4), %%eax\n"
9292 + "51: movl 28(%4), %%edx\n"
9293 +- " movnti %%eax, 24(%3)\n"
9294 +- " movnti %%edx, 28(%3)\n"
9295 ++ " movnti %%eax, %%es:24(%3)\n"
9296 ++ " movnti %%edx, %%es:28(%3)\n"
9297 + "11: movl 32(%4), %%eax\n"
9298 + "61: movl 36(%4), %%edx\n"
9299 +- " movnti %%eax, 32(%3)\n"
9300 +- " movnti %%edx, 36(%3)\n"
9301 ++ " movnti %%eax, %%es:32(%3)\n"
9302 ++ " movnti %%edx, %%es:36(%3)\n"
9303 + "12: movl 40(%4), %%eax\n"
9304 + "71: movl 44(%4), %%edx\n"
9305 +- " movnti %%eax, 40(%3)\n"
9306 +- " movnti %%edx, 44(%3)\n"
9307 ++ " movnti %%eax, %%es:40(%3)\n"
9308 ++ " movnti %%edx, %%es:44(%3)\n"
9309 + "13: movl 48(%4), %%eax\n"
9310 + "81: movl 52(%4), %%edx\n"
9311 +- " movnti %%eax, 48(%3)\n"
9312 +- " movnti %%edx, 52(%3)\n"
9313 ++ " movnti %%eax, %%es:48(%3)\n"
9314 ++ " movnti %%edx, %%es:52(%3)\n"
9315 + "14: movl 56(%4), %%eax\n"
9316 + "91: movl 60(%4), %%edx\n"
9317 +- " movnti %%eax, 56(%3)\n"
9318 +- " movnti %%edx, 60(%3)\n"
9319 ++ " movnti %%eax, %%es:56(%3)\n"
9320 ++ " movnti %%edx, %%es:60(%3)\n"
9321 + " addl $-64, %0\n"
9322 + " addl $64, %4\n"
9323 + " addl $64, %3\n"
9324 +@@ -581,6 +714,8 @@ static unsigned long __copy_user_intel_n
9325 + " movl %%eax,%0\n"
9326 + "7: rep; movsb\n"
9327 + "8:\n"
9328 ++ " pushl %%ss\n"
9329 ++ " popl %%ds\n"
9330 + ".section .fixup,\"ax\"\n"
9331 + "9: lea 0(%%eax,%0,4),%0\n"
9332 + "16: jmp 8b\n"
9333 +@@ -609,7 +744,7 @@ static unsigned long __copy_user_intel_n
9334 + " .long 7b,16b\n"
9335 + ".previous"
9336 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9337 +- : "1"(to), "2"(from), "0"(size)
9338 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9339 + : "eax", "edx", "memory");
9340 + return size;
9341 + }
9342 +@@ -622,90 +757,146 @@ static unsigned long __copy_user_intel_n
9343 + */
9344 + unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
9345 + unsigned long size);
9346 +-unsigned long __copy_user_intel(void __user *to, const void *from,
9347 ++unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
9348 ++ unsigned long size);
9349 ++unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
9350 + unsigned long size);
9351 + unsigned long __copy_user_zeroing_intel_nocache(void *to,
9352 + const void __user *from, unsigned long size);
9353 + #endif /* CONFIG_X86_INTEL_USERCOPY */
9354 +
9355 + /* Generic arbitrary sized copy. */
9356 +-#define __copy_user(to, from, size) \
9357 +-do { \
9358 +- int __d0, __d1, __d2; \
9359 +- __asm__ __volatile__( \
9360 +- " cmp $7,%0\n" \
9361 +- " jbe 1f\n" \
9362 +- " movl %1,%0\n" \
9363 +- " negl %0\n" \
9364 +- " andl $7,%0\n" \
9365 +- " subl %0,%3\n" \
9366 +- "4: rep; movsb\n" \
9367 +- " movl %3,%0\n" \
9368 +- " shrl $2,%0\n" \
9369 +- " andl $3,%3\n" \
9370 +- " .align 2,0x90\n" \
9371 +- "0: rep; movsl\n" \
9372 +- " movl %3,%0\n" \
9373 +- "1: rep; movsb\n" \
9374 +- "2:\n" \
9375 +- ".section .fixup,\"ax\"\n" \
9376 +- "5: addl %3,%0\n" \
9377 +- " jmp 2b\n" \
9378 +- "3: lea 0(%3,%0,4),%0\n" \
9379 +- " jmp 2b\n" \
9380 +- ".previous\n" \
9381 +- ".section __ex_table,\"a\"\n" \
9382 +- " .align 4\n" \
9383 +- " .long 4b,5b\n" \
9384 +- " .long 0b,3b\n" \
9385 +- " .long 1b,2b\n" \
9386 +- ".previous" \
9387 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
9388 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
9389 +- : "memory"); \
9390 +-} while (0)
9391 +-
9392 +-#define __copy_user_zeroing(to, from, size) \
9393 +-do { \
9394 +- int __d0, __d1, __d2; \
9395 +- __asm__ __volatile__( \
9396 +- " cmp $7,%0\n" \
9397 +- " jbe 1f\n" \
9398 +- " movl %1,%0\n" \
9399 +- " negl %0\n" \
9400 +- " andl $7,%0\n" \
9401 +- " subl %0,%3\n" \
9402 +- "4: rep; movsb\n" \
9403 +- " movl %3,%0\n" \
9404 +- " shrl $2,%0\n" \
9405 +- " andl $3,%3\n" \
9406 +- " .align 2,0x90\n" \
9407 +- "0: rep; movsl\n" \
9408 +- " movl %3,%0\n" \
9409 +- "1: rep; movsb\n" \
9410 +- "2:\n" \
9411 +- ".section .fixup,\"ax\"\n" \
9412 +- "5: addl %3,%0\n" \
9413 +- " jmp 6f\n" \
9414 +- "3: lea 0(%3,%0,4),%0\n" \
9415 +- "6: pushl %0\n" \
9416 +- " pushl %%eax\n" \
9417 +- " xorl %%eax,%%eax\n" \
9418 +- " rep; stosb\n" \
9419 +- " popl %%eax\n" \
9420 +- " popl %0\n" \
9421 +- " jmp 2b\n" \
9422 +- ".previous\n" \
9423 +- ".section __ex_table,\"a\"\n" \
9424 +- " .align 4\n" \
9425 +- " .long 4b,5b\n" \
9426 +- " .long 0b,3b\n" \
9427 +- " .long 1b,6b\n" \
9428 +- ".previous" \
9429 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
9430 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
9431 +- : "memory"); \
9432 +-} while (0)
9433 ++static unsigned long
9434 ++__generic_copy_to_user(void __user *to, const void *from, unsigned long size)
9435 ++{
9436 ++ int __d0, __d1, __d2;
9437 ++
9438 ++ __asm__ __volatile__(
9439 ++ " movw %w8,%%es\n"
9440 ++ " cmp $7,%0\n"
9441 ++ " jbe 1f\n"
9442 ++ " movl %1,%0\n"
9443 ++ " negl %0\n"
9444 ++ " andl $7,%0\n"
9445 ++ " subl %0,%3\n"
9446 ++ "4: rep; movsb\n"
9447 ++ " movl %3,%0\n"
9448 ++ " shrl $2,%0\n"
9449 ++ " andl $3,%3\n"
9450 ++ " .align 2,0x90\n"
9451 ++ "0: rep; movsl\n"
9452 ++ " movl %3,%0\n"
9453 ++ "1: rep; movsb\n"
9454 ++ "2:\n"
9455 ++ " pushl %%ss\n"
9456 ++ " popl %%es\n"
9457 ++ ".section .fixup,\"ax\"\n"
9458 ++ "5: addl %3,%0\n"
9459 ++ " jmp 2b\n"
9460 ++ "3: lea 0(%3,%0,4),%0\n"
9461 ++ " jmp 2b\n"
9462 ++ ".previous\n"
9463 ++ ".section __ex_table,\"a\"\n"
9464 ++ " .align 4\n"
9465 ++ " .long 4b,5b\n"
9466 ++ " .long 0b,3b\n"
9467 ++ " .long 1b,2b\n"
9468 ++ ".previous"
9469 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9470 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9471 ++ : "memory");
9472 ++ return size;
9473 ++}
9474 ++
9475 ++static unsigned long
9476 ++__generic_copy_from_user(void *to, const void __user *from, unsigned long size)
9477 ++{
9478 ++ int __d0, __d1, __d2;
9479 ++
9480 ++ __asm__ __volatile__(
9481 ++ " movw %w8,%%ds\n"
9482 ++ " cmp $7,%0\n"
9483 ++ " jbe 1f\n"
9484 ++ " movl %1,%0\n"
9485 ++ " negl %0\n"
9486 ++ " andl $7,%0\n"
9487 ++ " subl %0,%3\n"
9488 ++ "4: rep; movsb\n"
9489 ++ " movl %3,%0\n"
9490 ++ " shrl $2,%0\n"
9491 ++ " andl $3,%3\n"
9492 ++ " .align 2,0x90\n"
9493 ++ "0: rep; movsl\n"
9494 ++ " movl %3,%0\n"
9495 ++ "1: rep; movsb\n"
9496 ++ "2:\n"
9497 ++ " pushl %%ss\n"
9498 ++ " popl %%ds\n"
9499 ++ ".section .fixup,\"ax\"\n"
9500 ++ "5: addl %3,%0\n"
9501 ++ " jmp 2b\n"
9502 ++ "3: lea 0(%3,%0,4),%0\n"
9503 ++ " jmp 2b\n"
9504 ++ ".previous\n"
9505 ++ ".section __ex_table,\"a\"\n"
9506 ++ " .align 4\n"
9507 ++ " .long 4b,5b\n"
9508 ++ " .long 0b,3b\n"
9509 ++ " .long 1b,2b\n"
9510 ++ ".previous"
9511 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9512 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9513 ++ : "memory");
9514 ++ return size;
9515 ++}
9516 ++
9517 ++static unsigned long
9518 ++__copy_user_zeroing(void *to, const void __user *from, unsigned long size)
9519 ++{
9520 ++ int __d0, __d1, __d2;
9521 ++
9522 ++ __asm__ __volatile__(
9523 ++ " movw %w8,%%ds\n"
9524 ++ " cmp $7,%0\n"
9525 ++ " jbe 1f\n"
9526 ++ " movl %1,%0\n"
9527 ++ " negl %0\n"
9528 ++ " andl $7,%0\n"
9529 ++ " subl %0,%3\n"
9530 ++ "4: rep; movsb\n"
9531 ++ " movl %3,%0\n"
9532 ++ " shrl $2,%0\n"
9533 ++ " andl $3,%3\n"
9534 ++ " .align 2,0x90\n"
9535 ++ "0: rep; movsl\n"
9536 ++ " movl %3,%0\n"
9537 ++ "1: rep; movsb\n"
9538 ++ "2:\n"
9539 ++ " pushl %%ss\n"
9540 ++ " popl %%ds\n"
9541 ++ ".section .fixup,\"ax\"\n"
9542 ++ "5: addl %3,%0\n"
9543 ++ " jmp 6f\n"
9544 ++ "3: lea 0(%3,%0,4),%0\n"
9545 ++ "6: pushl %0\n"
9546 ++ " pushl %%eax\n"
9547 ++ " xorl %%eax,%%eax\n"
9548 ++ " rep; stosb\n"
9549 ++ " popl %%eax\n"
9550 ++ " popl %0\n"
9551 ++ " jmp 2b\n"
9552 ++ ".previous\n"
9553 ++ ".section __ex_table,\"a\"\n"
9554 ++ " .align 4\n"
9555 ++ " .long 4b,5b\n"
9556 ++ " .long 0b,3b\n"
9557 ++ " .long 1b,6b\n"
9558 ++ ".previous"
9559 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9560 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9561 ++ : "memory");
9562 ++ return size;
9563 ++}
9564 +
9565 + unsigned long __copy_to_user_ll(void __user *to, const void *from,
9566 + unsigned long n)
9567 +@@ -768,9 +959,9 @@ survive:
9568 + }
9569 + #endif
9570 + if (movsl_is_ok(to, from, n))
9571 +- __copy_user(to, from, n);
9572 ++ n = __generic_copy_to_user(to, from, n);
9573 + else
9574 +- n = __copy_user_intel(to, from, n);
9575 ++ n = __generic_copy_to_user_intel(to, from, n);
9576 + return n;
9577 + }
9578 + EXPORT_SYMBOL(__copy_to_user_ll);
9579 +@@ -779,7 +970,7 @@ unsigned long __copy_from_user_ll(void *
9580 + unsigned long n)
9581 + {
9582 + if (movsl_is_ok(to, from, n))
9583 +- __copy_user_zeroing(to, from, n);
9584 ++ n = __copy_user_zeroing(to, from, n);
9585 + else
9586 + n = __copy_user_zeroing_intel(to, from, n);
9587 + return n;
9588 +@@ -790,10 +981,9 @@ unsigned long __copy_from_user_ll_nozero
9589 + unsigned long n)
9590 + {
9591 + if (movsl_is_ok(to, from, n))
9592 +- __copy_user(to, from, n);
9593 ++ n = __generic_copy_from_user(to, from, n);
9594 + else
9595 +- n = __copy_user_intel((void __user *)to,
9596 +- (const void *)from, n);
9597 ++ n = __generic_copy_from_user_intel(to, from, n);
9598 + return n;
9599 + }
9600 + EXPORT_SYMBOL(__copy_from_user_ll_nozero);
9601 +@@ -802,12 +992,12 @@ unsigned long __copy_from_user_ll_nocach
9602 + unsigned long n)
9603 + {
9604 + #ifdef CONFIG_X86_INTEL_USERCOPY
9605 +- if (n > 64 && cpu_has_xmm2)
9606 ++ if ( n > 64 && cpu_has_xmm2)
9607 + n = __copy_user_zeroing_intel_nocache(to, from, n);
9608 + else
9609 +- __copy_user_zeroing(to, from, n);
9610 ++ n = __copy_user_zeroing(to, from, n);
9611 + #else
9612 +- __copy_user_zeroing(to, from, n);
9613 ++ n = __copy_user_zeroing(to, from, n);
9614 + #endif
9615 + return n;
9616 + }
9617 +@@ -817,12 +1007,12 @@ unsigned long __copy_from_user_ll_nocach
9618 + unsigned long n)
9619 + {
9620 + #ifdef CONFIG_X86_INTEL_USERCOPY
9621 +- if (n > 64 && cpu_has_xmm2)
9622 ++ if ( n > 64 && cpu_has_xmm2)
9623 + n = __copy_user_intel_nocache(to, from, n);
9624 + else
9625 +- __copy_user(to, from, n);
9626 ++ n = __generic_copy_from_user(to, from, n);
9627 + #else
9628 +- __copy_user(to, from, n);
9629 ++ n = __generic_copy_from_user(to, from, n);
9630 + #endif
9631 + return n;
9632 + }
9633 +@@ -871,8 +1061,35 @@ copy_from_user(void *to, const void __us
9634 + {
9635 + if (access_ok(VERIFY_READ, from, n))
9636 + n = __copy_from_user(to, from, n);
9637 +- else
9638 ++ else if ((long)n > 0)
9639 + memset(to, 0, n);
9640 + return n;
9641 + }
9642 + EXPORT_SYMBOL(copy_from_user);
9643 ++
9644 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
9645 ++void __set_fs(mm_segment_t x, int cpu)
9646 ++{
9647 ++ unsigned long limit = x.seg;
9648 ++ struct desc_struct d;
9649 ++
9650 ++ current_thread_info()->addr_limit = x;
9651 ++ if (likely(limit))
9652 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
9653 ++ pack_descriptor(&d, 0UL, limit, 0xF3, 0xC);
9654 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S);
9655 ++}
9656 ++
9657 ++void set_fs(mm_segment_t x)
9658 ++{
9659 ++ __set_fs(x, get_cpu());
9660 ++ put_cpu_no_resched();
9661 ++}
9662 ++#else
9663 ++void set_fs(mm_segment_t x)
9664 ++{
9665 ++ current_thread_info()->addr_limit = x;
9666 ++}
9667 ++#endif
9668 ++
9669 ++EXPORT_SYMBOL(set_fs);
9670 +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
9671 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-07 12:55:34.000000000 -0500
9672 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-18 03:38:44.000000000 -0500
9673 +@@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg
9674 + __u8 cmos[4];
9675 + ClickMap_t *map;
9676 + unsigned long map_addr;
9677 +- unsigned long old;
9678 ++ pte_t old;
9679 +
9680 + if (region >= CLICK_ENTRIES) {
9681 + printk("Voyager: Illegal ClickMap region %d\n", region);
9682 +@@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg
9683 +
9684 + /* steal page 0 for this */
9685 + old = pg0[0];
9686 +- pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9687 ++ pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9688 + local_flush_tlb();
9689 + /* now clear everything out but page 0 */
9690 + map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
9691 +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
9692 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-07 12:55:34.000000000 -0500
9693 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-18 03:38:44.000000000 -0500
9694 +@@ -510,6 +510,10 @@ static void __init do_boot_cpu(__u8 cpu)
9695 + __u32 *hijack_vector;
9696 + __u32 start_phys_address = setup_trampoline();
9697 +
9698 ++#ifdef CONFIG_PAX_KERNEXEC
9699 ++ unsigned long cr0;
9700 ++#endif
9701 ++
9702 + /* There's a clever trick to this: The linux trampoline is
9703 + * compiled to begin at absolute location zero, so make the
9704 + * address zero but have the data segment selector compensate
9705 +@@ -529,7 +533,17 @@ static void __init do_boot_cpu(__u8 cpu)
9706 +
9707 + init_gdt(cpu);
9708 + per_cpu(current_task, cpu) = idle;
9709 +- early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
9710 ++
9711 ++#ifdef CONFIG_PAX_KERNEXEC
9712 ++ pax_open_kernel(cr0);
9713 ++#endif
9714 ++
9715 ++ early_gdt_descr.address = get_cpu_gdt_table(cpu);
9716 ++
9717 ++#ifdef CONFIG_PAX_KERNEXEC
9718 ++ pax_close_kernel(cr0);
9719 ++#endif
9720 ++
9721 + irq_ctx_init(cpu);
9722 +
9723 + /* Note: Don't modify initial ss override */
9724 +@@ -1141,7 +1155,7 @@ void smp_local_timer_interrupt(void)
9725 + per_cpu(prof_counter, cpu);
9726 + }
9727 +
9728 +- update_process_times(user_mode_vm(get_irq_regs()));
9729 ++ update_process_times(user_mode(get_irq_regs()));
9730 + }
9731 +
9732 + if (((1 << cpu) & voyager_extended_vic_processors) == 0)
9733 +diff -urNp linux-2.6.27.10/arch/x86/Makefile linux-2.6.27.10/arch/x86/Makefile
9734 +--- linux-2.6.27.10/arch/x86/Makefile 2008-11-07 12:55:34.000000000 -0500
9735 ++++ linux-2.6.27.10/arch/x86/Makefile 2008-11-18 03:38:44.000000000 -0500
9736 +@@ -232,3 +232,12 @@ endef
9737 + CLEAN_FILES += arch/x86/boot/fdimage \
9738 + arch/x86/boot/image.iso \
9739 + arch/x86/boot/mtools.conf
9740 ++
9741 ++define OLD_LD
9742 ++
9743 ++*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9744 ++*** Please upgrade your binutils to 2.18 or newer
9745 ++endef
9746 ++
9747 ++archprepare:
9748 ++ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
9749 +diff -urNp linux-2.6.27.10/arch/x86/mm/discontig_32.c linux-2.6.27.10/arch/x86/mm/discontig_32.c
9750 +--- linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:36.000000000 -0500
9751 ++++ linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:46.000000000 -0500
9752 +@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
9753 + }
9754 + #endif
9755 +
9756 +-extern unsigned long find_max_low_pfn(void);
9757 + extern unsigned long highend_pfn, highstart_pfn;
9758 +
9759 + #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
9760 +diff -urNp linux-2.6.27.10/arch/x86/mm/extable.c linux-2.6.27.10/arch/x86/mm/extable.c
9761 +--- linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-07 12:55:34.000000000 -0500
9762 ++++ linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-18 03:38:44.000000000 -0500
9763 +@@ -1,14 +1,62 @@
9764 + #include <linux/module.h>
9765 + #include <linux/spinlock.h>
9766 ++#include <linux/sort.h>
9767 + #include <asm/uaccess.h>
9768 +
9769 ++/*
9770 ++ * The exception table needs to be sorted so that the binary
9771 ++ * search that we use to find entries in it works properly.
9772 ++ * This is used both for the kernel exception table and for
9773 ++ * the exception tables of modules that get loaded.
9774 ++ */
9775 ++static int cmp_ex(const void *a, const void *b)
9776 ++{
9777 ++ const struct exception_table_entry *x = a, *y = b;
9778 ++
9779 ++ /* avoid overflow */
9780 ++ if (x->insn > y->insn)
9781 ++ return 1;
9782 ++ if (x->insn < y->insn)
9783 ++ return -1;
9784 ++ return 0;
9785 ++}
9786 ++
9787 ++static void swap_ex(void *a, void *b, int size)
9788 ++{
9789 ++ struct exception_table_entry t, *x = a, *y = b;
9790 ++
9791 ++#ifdef CONFIG_PAX_KERNEXEC
9792 ++ unsigned long cr0;
9793 ++#endif
9794 ++
9795 ++ t = *x;
9796 ++
9797 ++#ifdef CONFIG_PAX_KERNEXEC
9798 ++ pax_open_kernel(cr0);
9799 ++#endif
9800 ++
9801 ++ *x = *y;
9802 ++ *y = t;
9803 ++
9804 ++#ifdef CONFIG_PAX_KERNEXEC
9805 ++ pax_close_kernel(cr0);
9806 ++#endif
9807 ++
9808 ++}
9809 ++
9810 ++void sort_extable(struct exception_table_entry *start,
9811 ++ struct exception_table_entry *finish)
9812 ++{
9813 ++ sort(start, finish - start, sizeof(struct exception_table_entry),
9814 ++ cmp_ex, swap_ex);
9815 ++}
9816 +
9817 + int fixup_exception(struct pt_regs *regs)
9818 + {
9819 + const struct exception_table_entry *fixup;
9820 +
9821 + #ifdef CONFIG_PNPBIOS
9822 +- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
9823 ++ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
9824 + extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
9825 + extern u32 pnp_bios_is_utter_crap;
9826 + pnp_bios_is_utter_crap = 1;
9827 +diff -urNp linux-2.6.27.10/arch/x86/mm/fault.c linux-2.6.27.10/arch/x86/mm/fault.c
9828 +--- linux-2.6.27.10/arch/x86/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
9829 ++++ linux-2.6.27.10/arch/x86/mm/fault.c 2008-12-10 22:28:27.000000000 -0500
9830 +@@ -26,6 +26,8 @@
9831 + #include <linux/kprobes.h>
9832 + #include <linux/uaccess.h>
9833 + #include <linux/kdebug.h>
9834 ++#include <linux/unistd.h>
9835 ++#include <linux/compiler.h>
9836 +
9837 + #include <asm/system.h>
9838 + #include <asm/desc.h>
9839 +@@ -66,7 +68,7 @@ static inline int notify_page_fault(stru
9840 + int ret = 0;
9841 +
9842 + /* kprobe_running() needs smp_processor_id() */
9843 +- if (!user_mode_vm(regs)) {
9844 ++ if (!user_mode(regs)) {
9845 + preempt_disable();
9846 + if (kprobe_running() && kprobe_fault_handler(regs, 14))
9847 + ret = 1;
9848 +@@ -264,6 +266,30 @@ bad:
9849 + #endif
9850 + }
9851 +
9852 ++#ifdef CONFIG_PAX_EMUTRAMP
9853 ++static int pax_handle_fetch_fault(struct pt_regs *regs);
9854 ++#endif
9855 ++
9856 ++#ifdef CONFIG_PAX_PAGEEXEC
9857 ++static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
9858 ++{
9859 ++ pgd_t *pgd;
9860 ++ pud_t *pud;
9861 ++ pmd_t *pmd;
9862 ++
9863 ++ pgd = pgd_offset(mm, address);
9864 ++ if (!pgd_present(*pgd))
9865 ++ return NULL;
9866 ++ pud = pud_offset(pgd, address);
9867 ++ if (!pud_present(*pud))
9868 ++ return NULL;
9869 ++ pmd = pmd_offset(pud, address);
9870 ++ if (!pmd_present(*pmd))
9871 ++ return NULL;
9872 ++ return pmd;
9873 ++}
9874 ++#endif
9875 ++
9876 + #ifdef CONFIG_X86_32
9877 + static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
9878 + {
9879 +@@ -350,7 +376,7 @@ static int is_errata93(struct pt_regs *r
9880 + static int is_errata100(struct pt_regs *regs, unsigned long address)
9881 + {
9882 + #ifdef CONFIG_X86_64
9883 +- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
9884 ++ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) &&
9885 + (address >> 32))
9886 + return 1;
9887 + #endif
9888 +@@ -387,14 +413,31 @@ static void show_fault_oops(struct pt_re
9889 + #endif
9890 +
9891 + #ifdef CONFIG_X86_PAE
9892 +- if (error_code & PF_INSTR) {
9893 ++ if (nx_enabled && (error_code & PF_INSTR)) {
9894 + unsigned int level;
9895 + pte_t *pte = lookup_address(address, &level);
9896 +
9897 + if (pte && pte_present(*pte) && !pte_exec(*pte))
9898 + printk(KERN_CRIT "kernel tried to execute "
9899 + "NX-protected page - exploit attempt? "
9900 +- "(uid: %d)\n", current->uid);
9901 ++ "(uid: %d, task: %s, pid: %d)\n",
9902 ++ current->uid, current->comm, task_pid_nr(current));
9903 ++ }
9904 ++#endif
9905 ++
9906 ++#ifdef CONFIG_PAX_KERNEXEC
9907 ++#ifdef CONFIG_MODULES
9908 ++ if (init_mm.start_code <= address && address < (unsigned long)MODULES_END)
9909 ++#else
9910 ++ if (init_mm.start_code <= address && address < init_mm.end_code)
9911 ++#endif
9912 ++ {
9913 ++ if (current->signal->curr_ip)
9914 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
9915 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
9916 ++ else
9917 ++ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
9918 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
9919 + }
9920 + #endif
9921 +
9922 +@@ -586,13 +629,22 @@ void __kprobes do_page_fault(struct pt_r
9923 + struct task_struct *tsk;
9924 + struct mm_struct *mm;
9925 + struct vm_area_struct *vma;
9926 +- unsigned long address;
9927 + int write, si_code;
9928 + int fault;
9929 + #ifdef CONFIG_X86_64
9930 + unsigned long flags;
9931 + #endif
9932 +
9933 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9934 ++ pte_t *pte;
9935 ++ pmd_t *pmd;
9936 ++ spinlock_t *ptl;
9937 ++ unsigned char pte_mask;
9938 ++#endif
9939 ++
9940 ++ /* get the address */
9941 ++ const unsigned long address = read_cr2();
9942 ++
9943 + /*
9944 + * We can fault from pretty much anywhere, with unknown IRQ state.
9945 + */
9946 +@@ -602,9 +654,6 @@ void __kprobes do_page_fault(struct pt_r
9947 + mm = tsk->mm;
9948 + prefetchw(&mm->mmap_sem);
9949 +
9950 +- /* get the address */
9951 +- address = read_cr2();
9952 +-
9953 + si_code = SEGV_MAPERR;
9954 +
9955 + if (notify_page_fault(regs))
9956 +@@ -657,7 +706,7 @@ void __kprobes do_page_fault(struct pt_r
9957 + * atomic region then we must not take the fault.
9958 + */
9959 + if (in_atomic() || !mm)
9960 +- goto bad_area_nosemaphore;
9961 ++ goto bad_area_nopax;
9962 + #else /* CONFIG_X86_64 */
9963 + if (likely(regs->flags & X86_EFLAGS_IF))
9964 + local_irq_enable();
9965 +@@ -670,13 +719,13 @@ void __kprobes do_page_fault(struct pt_r
9966 + * atomic region then we must not take the fault.
9967 + */
9968 + if (unlikely(in_atomic() || !mm))
9969 +- goto bad_area_nosemaphore;
9970 ++ goto bad_area_nopax;
9971 +
9972 + /*
9973 + * User-mode registers count as a user access even for any
9974 + * potential system fault or CPU buglet.
9975 + */
9976 +- if (user_mode_vm(regs))
9977 ++ if (user_mode(regs))
9978 + error_code |= PF_USER;
9979 + again:
9980 + #endif
9981 +@@ -698,10 +747,104 @@ again:
9982 + if (!down_read_trylock(&mm->mmap_sem)) {
9983 + if ((error_code & PF_USER) == 0 &&
9984 + !search_exception_tables(regs->ip))
9985 +- goto bad_area_nosemaphore;
9986 ++ goto bad_area_nopax;
9987 + down_read(&mm->mmap_sem);
9988 + }
9989 +
9990 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9991 ++ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
9992 ++ !(mm->pax_flags & MF_PAX_PAGEEXEC))
9993 ++ goto not_pax_fault;
9994 ++
9995 ++ /* PaX: it's our fault, let's handle it if we can */
9996 ++
9997 ++ /* PaX: take a look at read faults before acquiring any locks */
9998 ++ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
9999 ++ /* instruction fetch attempt from a protected page in user mode */
10000 ++ up_read(&mm->mmap_sem);
10001 ++
10002 ++#ifdef CONFIG_PAX_EMUTRAMP
10003 ++ switch (pax_handle_fetch_fault(regs)) {
10004 ++ case 2:
10005 ++ return;
10006 ++ }
10007 ++#endif
10008 ++
10009 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10010 ++ do_group_exit(SIGKILL);
10011 ++ }
10012 ++
10013 ++ pmd = pax_get_pmd(mm, address);
10014 ++ if (unlikely(!pmd))
10015 ++ goto not_pax_fault;
10016 ++
10017 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
10018 ++ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
10019 ++ pte_unmap_unlock(pte, ptl);
10020 ++ goto not_pax_fault;
10021 ++ }
10022 ++
10023 ++ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
10024 ++ /* write attempt to a protected page in user mode */
10025 ++ pte_unmap_unlock(pte, ptl);
10026 ++ goto not_pax_fault;
10027 ++ }
10028 ++
10029 ++#ifdef CONFIG_SMP
10030 ++ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
10031 ++#else
10032 ++ if (likely(address > get_limit(regs->cs)))
10033 ++#endif
10034 ++ {
10035 ++ set_pte(pte, pte_mkread(*pte));
10036 ++ __flush_tlb_one(address);
10037 ++ pte_unmap_unlock(pte, ptl);
10038 ++ up_read(&mm->mmap_sem);
10039 ++ return;
10040 ++ }
10041 ++
10042 ++ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
10043 ++
10044 ++ /*
10045 ++ * PaX: fill DTLB with user rights and retry
10046 ++ */
10047 ++ __asm__ __volatile__ (
10048 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10049 ++ "movw %w4,%%es\n"
10050 ++#endif
10051 ++ "orb %2,(%1)\n"
10052 ++#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
10053 ++/*
10054 ++ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
10055 ++ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
10056 ++ * page fault when examined during a TLB load attempt. this is true not only
10057 ++ * for PTEs holding a non-present entry but also present entries that will
10058 ++ * raise a page fault (such as those set up by PaX, or the copy-on-write
10059 ++ * mechanism). in effect it means that we do *not* need to flush the TLBs
10060 ++ * for our target pages since their PTEs are simply not in the TLBs at all.
10061 ++
10062 ++ * the best thing in omitting it is that we gain around 15-20% speed in the
10063 ++ * fast path of the page fault handler and can get rid of tracing since we
10064 ++ * can no longer flush unintended entries.
10065 ++ */
10066 ++ "invlpg (%0)\n"
10067 ++#endif
10068 ++ "testb $0,%%es:(%0)\n"
10069 ++ "xorb %3,(%1)\n"
10070 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10071 ++ "pushl %%ss\n"
10072 ++ "popl %%es\n"
10073 ++#endif
10074 ++ :
10075 ++ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS)
10076 ++ : "memory", "cc");
10077 ++ pte_unmap_unlock(pte, ptl);
10078 ++ up_read(&mm->mmap_sem);
10079 ++ return;
10080 ++
10081 ++not_pax_fault:
10082 ++#endif
10083 ++
10084 + vma = find_vma(mm, address);
10085 + if (!vma)
10086 + goto bad_area;
10087 +@@ -709,16 +852,20 @@ again:
10088 + goto good_area;
10089 + if (!(vma->vm_flags & VM_GROWSDOWN))
10090 + goto bad_area;
10091 +- if (error_code & PF_USER) {
10092 +- /*
10093 +- * Accessing the stack below %sp is always a bug.
10094 +- * The large cushion allows instructions like enter
10095 +- * and pusha to work. ("enter $65535,$31" pushes
10096 +- * 32 pointers and then decrements %sp by 65535.)
10097 +- */
10098 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10099 +- goto bad_area;
10100 +- }
10101 ++ /*
10102 ++ * Accessing the stack below %sp is always a bug.
10103 ++ * The large cushion allows instructions like enter
10104 ++ * and pusha to work. ("enter $65535,$31" pushes
10105 ++ * 32 pointers and then decrements %sp by 65535.)
10106 ++ */
10107 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10108 ++ goto bad_area;
10109 ++
10110 ++#ifdef CONFIG_PAX_SEGMEXEC
10111 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)
10112 ++ goto bad_area;
10113 ++#endif
10114 ++
10115 + if (expand_stack(vma, address))
10116 + goto bad_area;
10117 + /*
10118 +@@ -728,6 +875,8 @@ again:
10119 + good_area:
10120 + si_code = SEGV_ACCERR;
10121 + write = 0;
10122 ++ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
10123 ++ goto bad_area;
10124 + switch (error_code & (PF_PROT|PF_WRITE)) {
10125 + default: /* 3: write, present */
10126 + /* fall through */
10127 +@@ -785,6 +934,54 @@ bad_area:
10128 + up_read(&mm->mmap_sem);
10129 +
10130 + bad_area_nosemaphore:
10131 ++
10132 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10133 ++ if (mm && (error_code & PF_USER)) {
10134 ++ unsigned long ip = regs->ip;
10135 ++
10136 ++ if (v8086_mode(regs))
10137 ++ ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff);
10138 ++
10139 ++ /*
10140 ++ * It's possible to have interrupts off here.
10141 ++ */
10142 ++ local_irq_enable();
10143 ++
10144 ++#ifdef CONFIG_PAX_PAGEEXEC
10145 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
10146 ++ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) {
10147 ++
10148 ++#ifdef CONFIG_PAX_EMUTRAMP
10149 ++ switch (pax_handle_fetch_fault(regs)) {
10150 ++ case 2:
10151 ++ return;
10152 ++ }
10153 ++#endif
10154 ++
10155 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10156 ++ do_group_exit(SIGKILL);
10157 ++ }
10158 ++#endif
10159 ++
10160 ++#ifdef CONFIG_PAX_SEGMEXEC
10161 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) {
10162 ++
10163 ++#ifdef CONFIG_PAX_EMUTRAMP
10164 ++ switch (pax_handle_fetch_fault(regs)) {
10165 ++ case 2:
10166 ++ return;
10167 ++ }
10168 ++#endif
10169 ++
10170 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10171 ++ do_group_exit(SIGKILL);
10172 ++ }
10173 ++#endif
10174 ++
10175 ++ }
10176 ++#endif
10177 ++
10178 ++bad_area_nopax:
10179 + /* User mode accesses just cause a SIGSEGV */
10180 + if (error_code & PF_USER) {
10181 + /*
10182 +@@ -863,7 +1060,7 @@ no_context:
10183 + #ifdef CONFIG_X86_32
10184 + die("Oops", regs, error_code);
10185 + bust_spinlocks(0);
10186 +- do_exit(SIGKILL);
10187 ++ do_group_exit(SIGKILL);
10188 + #else
10189 + if (__die("Oops", regs, error_code))
10190 + regs = NULL;
10191 +@@ -877,17 +1074,17 @@ no_context:
10192 + * us unable to handle the page fault gracefully.
10193 + */
10194 + out_of_memory:
10195 +- up_read(&mm->mmap_sem);
10196 + if (is_global_init(tsk)) {
10197 + yield();
10198 + #ifdef CONFIG_X86_32
10199 +- down_read(&mm->mmap_sem);
10200 + goto survive;
10201 + #else
10202 ++ up_read(&mm->mmap_sem);
10203 + goto again;
10204 + #endif
10205 + }
10206 +
10207 ++ up_read(&mm->mmap_sem);
10208 + printk("VM: killing process %s\n", tsk->comm);
10209 + if (error_code & PF_USER)
10210 + do_group_exit(SIGKILL);
10211 +@@ -959,3 +1156,174 @@ void vmalloc_sync_all(void)
10212 + }
10213 + #endif
10214 + }
10215 ++
10216 ++#ifdef CONFIG_PAX_EMUTRAMP
10217 ++static int pax_handle_fetch_fault_32(struct pt_regs *regs)
10218 ++{
10219 ++ int err;
10220 ++
10221 ++ do { /* PaX: gcc trampoline emulation #1 */
10222 ++ unsigned char mov1, mov2;
10223 ++ unsigned short jmp;
10224 ++ unsigned int addr1, addr2;
10225 ++
10226 ++#ifdef CONFIG_X86_64
10227 ++ if ((regs->ip + 11) >> 32)
10228 ++ break;
10229 ++#endif
10230 ++
10231 ++ err = get_user(mov1, (unsigned char __user *)regs->ip);
10232 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10233 ++ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
10234 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10235 ++ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
10236 ++
10237 ++ if (err)
10238 ++ break;
10239 ++
10240 ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
10241 ++ regs->cx = addr1;
10242 ++ regs->ax = addr2;
10243 ++ regs->ip = addr2;
10244 ++ return 2;
10245 ++ }
10246 ++ } while (0);
10247 ++
10248 ++ do { /* PaX: gcc trampoline emulation #2 */
10249 ++ unsigned char mov, jmp;
10250 ++ unsigned int addr1, addr2;
10251 ++
10252 ++#ifdef CONFIG_X86_64
10253 ++ if ((regs->ip + 9) >> 32)
10254 ++ break;
10255 ++#endif
10256 ++
10257 ++ err = get_user(mov, (unsigned char __user *)regs->ip);
10258 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10259 ++ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
10260 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10261 ++
10262 ++ if (err)
10263 ++ break;
10264 ++
10265 ++ if (mov == 0xB9 && jmp == 0xE9) {
10266 ++ regs->cx = addr1;
10267 ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
10268 ++ return 2;
10269 ++ }
10270 ++ } while (0);
10271 ++
10272 ++ return 1; /* PaX in action */
10273 ++}
10274 ++
10275 ++#ifdef CONFIG_X86_64
10276 ++static int pax_handle_fetch_fault_64(struct pt_regs *regs)
10277 ++{
10278 ++ int err;
10279 ++
10280 ++ do { /* PaX: gcc trampoline emulation #1 */
10281 ++ unsigned short mov1, mov2, jmp1;
10282 ++ unsigned char jmp2;
10283 ++ unsigned int addr1;
10284 ++ unsigned long addr2;
10285 ++
10286 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10287 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
10288 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
10289 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
10290 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
10291 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
10292 ++
10293 ++ if (err)
10294 ++ break;
10295 ++
10296 ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10297 ++ regs->r11 = addr1;
10298 ++ regs->r10 = addr2;
10299 ++ regs->ip = addr1;
10300 ++ return 2;
10301 ++ }
10302 ++ } while (0);
10303 ++
10304 ++ do { /* PaX: gcc trampoline emulation #2 */
10305 ++ unsigned short mov1, mov2, jmp1;
10306 ++ unsigned char jmp2;
10307 ++ unsigned long addr1, addr2;
10308 ++
10309 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10310 ++ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
10311 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
10312 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
10313 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
10314 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
10315 ++
10316 ++ if (err)
10317 ++ break;
10318 ++
10319 ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10320 ++ regs->r11 = addr1;
10321 ++ regs->r10 = addr2;
10322 ++ regs->ip = addr1;
10323 ++ return 2;
10324 ++ }
10325 ++ } while (0);
10326 ++
10327 ++ return 1; /* PaX in action */
10328 ++}
10329 ++#endif
10330 ++
10331 ++/*
10332 ++ * PaX: decide what to do with offenders (regs->ip = fault address)
10333 ++ *
10334 ++ * returns 1 when task should be killed
10335 ++ * 2 when gcc trampoline was detected
10336 ++ */
10337 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
10338 ++{
10339 ++ if (v8086_mode(regs))
10340 ++ return 1;
10341 ++
10342 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
10343 ++ return 1;
10344 ++
10345 ++#ifdef CONFIG_X86_32
10346 ++ return pax_handle_fetch_fault_32(regs);
10347 ++#else
10348 ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
10349 ++ return pax_handle_fetch_fault_32(regs);
10350 ++ else
10351 ++ return pax_handle_fetch_fault_64(regs);
10352 ++#endif
10353 ++}
10354 ++#endif
10355 ++
10356 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10357 ++void pax_report_insns(void *pc, void *sp)
10358 ++{
10359 ++ long i;
10360 ++
10361 ++ printk(KERN_ERR "PAX: bytes at PC: ");
10362 ++ for (i = 0; i < 20; i++) {
10363 ++ unsigned char c;
10364 ++ if (get_user(c, (unsigned char __user *)pc+i))
10365 ++ printk(KERN_CONT "?? ");
10366 ++ else
10367 ++ printk(KERN_CONT "%02x ", c);
10368 ++ }
10369 ++ printk("\n");
10370 ++
10371 ++ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
10372 ++ for (i = -1; i < 80 / sizeof(long); i++) {
10373 ++ unsigned long c;
10374 ++ if (get_user(c, (unsigned long __user *)sp+i))
10375 ++#ifdef CONFIG_X86_32
10376 ++ printk(KERN_CONT "???????? ");
10377 ++#else
10378 ++ printk(KERN_CONT "???????????????? ");
10379 ++#endif
10380 ++ else
10381 ++ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
10382 ++ }
10383 ++ printk("\n");
10384 ++}
10385 ++#endif
10386 +diff -urNp linux-2.6.27.10/arch/x86/mm/highmem_32.c linux-2.6.27.10/arch/x86/mm/highmem_32.c
10387 +--- linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-07 12:55:34.000000000 -0500
10388 ++++ linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-18 03:38:44.000000000 -0500
10389 +@@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page
10390 + enum fixed_addresses idx;
10391 + unsigned long vaddr;
10392 +
10393 ++#ifdef CONFIG_PAX_KERNEXEC
10394 ++ unsigned long cr0;
10395 ++#endif
10396 ++
10397 + /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
10398 + pagefault_disable();
10399 +
10400 +@@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page
10401 + idx = type + KM_TYPE_NR*smp_processor_id();
10402 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10403 + BUG_ON(!pte_none(*(kmap_pte-idx)));
10404 ++
10405 ++#ifdef CONFIG_PAX_KERNEXEC
10406 ++ pax_open_kernel(cr0);
10407 ++#endif
10408 ++
10409 + set_pte(kmap_pte-idx, mk_pte(page, prot));
10410 ++
10411 ++#ifdef CONFIG_PAX_KERNEXEC
10412 ++ pax_close_kernel(cr0);
10413 ++#endif
10414 ++
10415 + arch_flush_lazy_mmu_mode();
10416 +
10417 + return (void *)vaddr;
10418 +@@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km
10419 + unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
10420 + enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
10421 +
10422 ++#ifdef CONFIG_PAX_KERNEXEC
10423 ++ unsigned long cr0;
10424 ++#endif
10425 ++
10426 + /*
10427 + * Force other mappings to Oops if they'll try to access this pte
10428 + * without first remap it. Keeping stale mappings around is a bad idea
10429 + * also, in case the page changes cacheability attributes or becomes
10430 + * a protected page in a hypervisor.
10431 + */
10432 +- if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
10433 ++ if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) {
10434 ++
10435 ++#ifdef CONFIG_PAX_KERNEXEC
10436 ++ pax_open_kernel(cr0);
10437 ++#endif
10438 ++
10439 + kpte_clear_flush(kmap_pte-idx, vaddr);
10440 +- else {
10441 ++
10442 ++#ifdef CONFIG_PAX_KERNEXEC
10443 ++ pax_close_kernel(cr0);
10444 ++#endif
10445 ++
10446 ++ } else {
10447 + #ifdef CONFIG_DEBUG_HIGHMEM
10448 + BUG_ON(vaddr < PAGE_OFFSET);
10449 + BUG_ON(vaddr >= (unsigned long)high_memory);
10450 +@@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn,
10451 + enum fixed_addresses idx;
10452 + unsigned long vaddr;
10453 +
10454 ++#ifdef CONFIG_PAX_KERNEXEC
10455 ++ unsigned long cr0;
10456 ++#endif
10457 ++
10458 + pagefault_disable();
10459 +
10460 + idx = type + KM_TYPE_NR*smp_processor_id();
10461 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10462 ++
10463 ++#ifdef CONFIG_PAX_KERNEXEC
10464 ++ pax_open_kernel(cr0);
10465 ++#endif
10466 ++
10467 + set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
10468 ++
10469 ++#ifdef CONFIG_PAX_KERNEXEC
10470 ++ pax_close_kernel(cr0);
10471 ++#endif
10472 ++
10473 + arch_flush_lazy_mmu_mode();
10474 +
10475 + return (void*) vaddr;
10476 +diff -urNp linux-2.6.27.10/arch/x86/mm/hugetlbpage.c linux-2.6.27.10/arch/x86/mm/hugetlbpage.c
10477 +--- linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-07 12:55:34.000000000 -0500
10478 ++++ linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-18 03:38:44.000000000 -0500
10479 +@@ -263,13 +263,18 @@ static unsigned long hugetlb_get_unmappe
10480 + struct hstate *h = hstate_file(file);
10481 + struct mm_struct *mm = current->mm;
10482 + struct vm_area_struct *vma;
10483 +- unsigned long start_addr;
10484 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
10485 ++
10486 ++#ifdef CONFIG_PAX_SEGMEXEC
10487 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10488 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10489 ++#endif
10490 +
10491 + if (len > mm->cached_hole_size) {
10492 +- start_addr = mm->free_area_cache;
10493 ++ start_addr = mm->free_area_cache;
10494 + } else {
10495 +- start_addr = TASK_UNMAPPED_BASE;
10496 +- mm->cached_hole_size = 0;
10497 ++ start_addr = mm->mmap_base;
10498 ++ mm->cached_hole_size = 0;
10499 + }
10500 +
10501 + full_search:
10502 +@@ -277,13 +282,13 @@ full_search:
10503 +
10504 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
10505 + /* At this point: (!vma || addr < vma->vm_end). */
10506 +- if (TASK_SIZE - len < addr) {
10507 ++ if (pax_task_size - len < addr) {
10508 + /*
10509 + * Start a new search - just in case we missed
10510 + * some holes.
10511 + */
10512 +- if (start_addr != TASK_UNMAPPED_BASE) {
10513 +- start_addr = TASK_UNMAPPED_BASE;
10514 ++ if (start_addr != mm->mmap_base) {
10515 ++ start_addr = mm->mmap_base;
10516 + mm->cached_hole_size = 0;
10517 + goto full_search;
10518 + }
10519 +@@ -306,9 +311,8 @@ static unsigned long hugetlb_get_unmappe
10520 + struct hstate *h = hstate_file(file);
10521 + struct mm_struct *mm = current->mm;
10522 + struct vm_area_struct *vma, *prev_vma;
10523 +- unsigned long base = mm->mmap_base, addr = addr0;
10524 ++ unsigned long base = mm->mmap_base, addr;
10525 + unsigned long largest_hole = mm->cached_hole_size;
10526 +- int first_time = 1;
10527 +
10528 + /* don't allow allocations above current base */
10529 + if (mm->free_area_cache > base)
10530 +@@ -318,7 +322,7 @@ static unsigned long hugetlb_get_unmappe
10531 + largest_hole = 0;
10532 + mm->free_area_cache = base;
10533 + }
10534 +-try_again:
10535 ++
10536 + /* make sure it can fit in the remaining address space */
10537 + if (mm->free_area_cache < len)
10538 + goto fail;
10539 +@@ -360,22 +364,26 @@ try_again:
10540 +
10541 + fail:
10542 + /*
10543 +- * if hint left us with no space for the requested
10544 +- * mapping then try again:
10545 +- */
10546 +- if (first_time) {
10547 +- mm->free_area_cache = base;
10548 +- largest_hole = 0;
10549 +- first_time = 0;
10550 +- goto try_again;
10551 +- }
10552 +- /*
10553 + * A failed mmap() very likely causes application failure,
10554 + * so fall back to the bottom-up function here. This scenario
10555 + * can happen with large stack limits and large mmap()
10556 + * allocations.
10557 + */
10558 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
10559 ++
10560 ++#ifdef CONFIG_PAX_SEGMEXEC
10561 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10562 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
10563 ++ else
10564 ++#endif
10565 ++
10566 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
10567 ++
10568 ++#ifdef CONFIG_PAX_RANDMMAP
10569 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
10570 ++ mm->mmap_base += mm->delta_mmap;
10571 ++#endif
10572 ++
10573 ++ mm->free_area_cache = mm->mmap_base;
10574 + mm->cached_hole_size = ~0UL;
10575 + addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
10576 + len, pgoff, flags);
10577 +@@ -383,6 +391,7 @@ fail:
10578 + /*
10579 + * Restore the topdown base:
10580 + */
10581 ++ mm->mmap_base = base;
10582 + mm->free_area_cache = base;
10583 + mm->cached_hole_size = ~0UL;
10584 +
10585 +@@ -396,10 +405,17 @@ hugetlb_get_unmapped_area(struct file *f
10586 + struct hstate *h = hstate_file(file);
10587 + struct mm_struct *mm = current->mm;
10588 + struct vm_area_struct *vma;
10589 ++ unsigned long pax_task_size = TASK_SIZE;
10590 +
10591 + if (len & ~huge_page_mask(h))
10592 + return -EINVAL;
10593 +- if (len > TASK_SIZE)
10594 ++
10595 ++#ifdef CONFIG_PAX_SEGMEXEC
10596 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10597 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10598 ++#endif
10599 ++
10600 ++ if (len > pax_task_size)
10601 + return -ENOMEM;
10602 +
10603 + if (flags & MAP_FIXED) {
10604 +@@ -411,7 +427,7 @@ hugetlb_get_unmapped_area(struct file *f
10605 + if (addr) {
10606 + addr = ALIGN(addr, huge_page_size(h));
10607 + vma = find_vma(mm, addr);
10608 +- if (TASK_SIZE - len >= addr &&
10609 ++ if (pax_task_size - len >= addr &&
10610 + (!vma || addr + len <= vma->vm_start))
10611 + return addr;
10612 + }
10613 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_32.c linux-2.6.27.10/arch/x86/mm/init_32.c
10614 +--- linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-07 12:55:34.000000000 -0500
10615 ++++ linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-18 03:38:44.000000000 -0500
10616 +@@ -47,6 +47,7 @@
10617 + #include <asm/paravirt.h>
10618 + #include <asm/setup.h>
10619 + #include <asm/cacheflush.h>
10620 ++#include <asm/desc.h>
10621 +
10622 + unsigned int __VMALLOC_RESERVE = 128 << 20;
10623 +
10624 +@@ -80,35 +81,6 @@ static __init void *alloc_low_page(unsig
10625 + }
10626 +
10627 + /*
10628 +- * Creates a middle page table and puts a pointer to it in the
10629 +- * given global directory entry. This only returns the gd entry
10630 +- * in non-PAE compilation mode, since the middle layer is folded.
10631 +- */
10632 +-static pmd_t * __init one_md_table_init(pgd_t *pgd)
10633 +-{
10634 +- pud_t *pud;
10635 +- pmd_t *pmd_table;
10636 +-
10637 +-#ifdef CONFIG_X86_PAE
10638 +- unsigned long phys;
10639 +- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
10640 +- if (after_init_bootmem)
10641 +- pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
10642 +- else
10643 +- pmd_table = (pmd_t *)alloc_low_page(&phys);
10644 +- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
10645 +- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
10646 +- pud = pud_offset(pgd, 0);
10647 +- BUG_ON(pmd_table != pmd_offset(pud, 0));
10648 +- }
10649 +-#endif
10650 +- pud = pud_offset(pgd, 0);
10651 +- pmd_table = pmd_offset(pud, 0);
10652 +-
10653 +- return pmd_table;
10654 +-}
10655 +-
10656 +-/*
10657 + * Create a page table and place a pointer to it in a middle page
10658 + * directory entry:
10659 + */
10660 +@@ -130,7 +102,11 @@ static pte_t * __init one_page_table_ini
10661 + }
10662 +
10663 + paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
10664 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10665 ++ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
10666 ++#else
10667 + set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
10668 ++#endif
10669 + BUG_ON(page_table != pte_offset_kernel(pmd, 0));
10670 + }
10671 +
10672 +@@ -152,6 +128,7 @@ page_table_range_init(unsigned long star
10673 + int pgd_idx, pmd_idx;
10674 + unsigned long vaddr;
10675 + pgd_t *pgd;
10676 ++ pud_t *pud;
10677 + pmd_t *pmd;
10678 +
10679 + vaddr = start;
10680 +@@ -160,8 +137,13 @@ page_table_range_init(unsigned long star
10681 + pgd = pgd_base + pgd_idx;
10682 +
10683 + for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
10684 +- pmd = one_md_table_init(pgd);
10685 +- pmd = pmd + pmd_index(vaddr);
10686 ++ pud = pud_offset(pgd, vaddr);
10687 ++ pmd = pmd_offset(pud, vaddr);
10688 ++
10689 ++#ifdef CONFIG_X86_PAE
10690 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10691 ++#endif
10692 ++
10693 + for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
10694 + pmd++, pmd_idx++) {
10695 + one_page_table_init(pmd);
10696 +@@ -172,11 +154,23 @@ page_table_range_init(unsigned long star
10697 + }
10698 + }
10699 +
10700 +-static inline int is_kernel_text(unsigned long addr)
10701 ++static inline int is_kernel_text(unsigned long start, unsigned long end)
10702 + {
10703 +- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
10704 +- return 1;
10705 +- return 0;
10706 ++ unsigned long etext;
10707 ++
10708 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
10709 ++ etext = ktva_ktla((unsigned long)&MODULES_END);
10710 ++#else
10711 ++ etext = (unsigned long)&_etext;
10712 ++#endif
10713 ++
10714 ++ if ((start > ktla_ktva(etext) ||
10715 ++ end <= ktla_ktva((unsigned long)_stext)) &&
10716 ++ (start > ktla_ktva((unsigned long)_einittext) ||
10717 ++ end <= ktla_ktva((unsigned long)_sinittext)) &&
10718 ++ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
10719 ++ return 0;
10720 ++ return 1;
10721 + }
10722 +
10723 + /*
10724 +@@ -189,9 +183,10 @@ static void __init kernel_physical_mappi
10725 + unsigned long end_pfn,
10726 + int use_pse)
10727 + {
10728 +- int pgd_idx, pmd_idx, pte_ofs;
10729 ++ unsigned int pgd_idx, pmd_idx, pte_ofs;
10730 + unsigned long pfn;
10731 + pgd_t *pgd;
10732 ++ pud_t *pud;
10733 + pmd_t *pmd;
10734 + pte_t *pte;
10735 + unsigned pages_2m = 0, pages_4k = 0;
10736 +@@ -202,8 +197,13 @@ static void __init kernel_physical_mappi
10737 + pfn = start_pfn;
10738 + pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10739 + pgd = pgd_base + pgd_idx;
10740 +- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
10741 +- pmd = one_md_table_init(pgd);
10742 ++ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
10743 ++ pud = pud_offset(pgd, 0);
10744 ++ pmd = pmd_offset(pud, 0);
10745 ++
10746 ++#ifdef CONFIG_X86_PAE
10747 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10748 ++#endif
10749 +
10750 + if (pfn >= end_pfn)
10751 + continue;
10752 +@@ -215,21 +215,16 @@ static void __init kernel_physical_mappi
10753 + #endif
10754 + for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
10755 + pmd++, pmd_idx++) {
10756 +- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
10757 ++ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
10758 +
10759 + /*
10760 + * Map with big pages if possible, otherwise
10761 + * create normal page tables:
10762 + */
10763 + if (use_pse) {
10764 +- unsigned int addr2;
10765 + pgprot_t prot = PAGE_KERNEL_LARGE;
10766 +
10767 +- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
10768 +- PAGE_OFFSET + PAGE_SIZE-1;
10769 +-
10770 +- if (is_kernel_text(addr) ||
10771 +- is_kernel_text(addr2))
10772 ++ if (is_kernel_text(address, address + PMD_SIZE))
10773 + prot = PAGE_KERNEL_LARGE_EXEC;
10774 +
10775 + pages_2m++;
10776 +@@ -243,10 +238,10 @@ static void __init kernel_physical_mappi
10777 + pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10778 + pte += pte_ofs;
10779 + for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
10780 +- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
10781 ++ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
10782 + pgprot_t prot = PAGE_KERNEL;
10783 +
10784 +- if (is_kernel_text(addr))
10785 ++ if (is_kernel_text(address, address + PAGE_SIZE))
10786 + prot = PAGE_KERNEL_EXEC;
10787 +
10788 + pages_4k++;
10789 +@@ -270,7 +265,9 @@ static void __init kernel_physical_mappi
10790 + */
10791 + int devmem_is_allowed(unsigned long pagenr)
10792 + {
10793 +- if (pagenr <= 256)
10794 ++ if (!pagenr)
10795 ++ return 1;
10796 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
10797 + return 1;
10798 + if (!page_is_ram(pagenr))
10799 + return 1;
10800 +@@ -404,7 +401,7 @@ void __init native_pagetable_setup_start
10801 +
10802 + pud = pud_offset(pgd, va);
10803 + pmd = pmd_offset(pud, va);
10804 +- if (!pmd_present(*pmd))
10805 ++ if (!pmd_present(*pmd) || pmd_huge(*pmd))
10806 + break;
10807 +
10808 + pte = pte_offset_kernel(pmd, va);
10809 +@@ -456,9 +453,7 @@ static void __init early_ioremap_page_ta
10810 +
10811 + static void __init pagetable_init(void)
10812 + {
10813 +- pgd_t *pgd_base = swapper_pg_dir;
10814 +-
10815 +- permanent_kmaps_init(pgd_base);
10816 ++ permanent_kmaps_init(swapper_pg_dir);
10817 + }
10818 +
10819 + #ifdef CONFIG_ACPI_SLEEP
10820 +@@ -466,12 +461,12 @@ static void __init pagetable_init(void)
10821 + * ACPI suspend needs this for resume, because things like the intel-agp
10822 + * driver might have split up a kernel 4MB mapping.
10823 + */
10824 +-char swsusp_pg_dir[PAGE_SIZE]
10825 ++pgd_t swsusp_pg_dir[PTRS_PER_PGD]
10826 + __attribute__ ((aligned(PAGE_SIZE)));
10827 +
10828 + static inline void save_pg_dir(void)
10829 + {
10830 +- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
10831 ++ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
10832 + }
10833 + #else /* !CONFIG_ACPI_SLEEP */
10834 + static inline void save_pg_dir(void)
10835 +@@ -501,13 +496,11 @@ void zap_low_mappings(void)
10836 +
10837 + int nx_enabled;
10838 +
10839 +-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
10840 ++pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
10841 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
10842 +
10843 + #ifdef CONFIG_X86_PAE
10844 +
10845 +-static int disable_nx __initdata;
10846 +-
10847 + /*
10848 + * noexec = on|off
10849 + *
10850 +@@ -516,40 +509,33 @@ static int disable_nx __initdata;
10851 + * on Enable
10852 + * off Disable
10853 + */
10854 ++#if !defined(CONFIG_PAX_PAGEEXEC)
10855 + static int __init noexec_setup(char *str)
10856 + {
10857 + if (!str || !strcmp(str, "on")) {
10858 +- if (cpu_has_nx) {
10859 +- __supported_pte_mask |= _PAGE_NX;
10860 +- disable_nx = 0;
10861 +- }
10862 ++ if (cpu_has_nx)
10863 ++ nx_enabled = 1;
10864 + } else {
10865 +- if (!strcmp(str, "off")) {
10866 +- disable_nx = 1;
10867 +- __supported_pte_mask &= ~_PAGE_NX;
10868 +- } else {
10869 ++ if (!strcmp(str, "off"))
10870 ++ nx_enabled = 0;
10871 ++ else
10872 + return -EINVAL;
10873 +- }
10874 + }
10875 +
10876 + return 0;
10877 + }
10878 + early_param("noexec", noexec_setup);
10879 ++#endif
10880 +
10881 + static void __init set_nx(void)
10882 + {
10883 +- unsigned int v[4], l, h;
10884 +-
10885 +- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
10886 +- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
10887 ++ if (!nx_enabled && cpu_has_nx) {
10888 ++ unsigned l, h;
10889 +
10890 +- if ((v[3] & (1 << 20)) && !disable_nx) {
10891 +- rdmsr(MSR_EFER, l, h);
10892 +- l |= EFER_NX;
10893 +- wrmsr(MSR_EFER, l, h);
10894 +- nx_enabled = 1;
10895 +- __supported_pte_mask |= _PAGE_NX;
10896 +- }
10897 ++ __supported_pte_mask &= ~_PAGE_NX;
10898 ++ rdmsr(MSR_EFER, l, h);
10899 ++ l &= ~EFER_NX;
10900 ++ wrmsr(MSR_EFER, l, h);
10901 + }
10902 + }
10903 + #endif
10904 +@@ -920,7 +906,7 @@ void __init mem_init(void)
10905 + set_highmem_pages_init();
10906 +
10907 + codesize = (unsigned long) &_etext - (unsigned long) &_text;
10908 +- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
10909 ++ datasize = (unsigned long) &_edata - (unsigned long) &_data;
10910 + initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
10911 +
10912 + kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
10913 +@@ -966,10 +952,10 @@ void __init mem_init(void)
10914 + ((unsigned long)&__init_end -
10915 + (unsigned long)&__init_begin) >> 10,
10916 +
10917 +- (unsigned long)&_etext, (unsigned long)&_edata,
10918 +- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
10919 ++ (unsigned long)&_data, (unsigned long)&_edata,
10920 ++ ((unsigned long)&_edata - (unsigned long)&_data) >> 10,
10921 +
10922 +- (unsigned long)&_text, (unsigned long)&_etext,
10923 ++ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
10924 + ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
10925 +
10926 + #ifdef CONFIG_HIGHMEM
10927 +@@ -1099,6 +1085,46 @@ void free_init_pages(char *what, unsigne
10928 +
10929 + void free_initmem(void)
10930 + {
10931 ++
10932 ++#ifdef CONFIG_PAX_KERNEXEC
10933 ++ /* PaX: limit KERNEL_CS to actual size */
10934 ++ unsigned long addr, limit;
10935 ++ struct desc_struct d;
10936 ++ int cpu;
10937 ++ pgd_t *pgd;
10938 ++ pud_t *pud;
10939 ++ pmd_t *pmd;
10940 ++
10941 ++#ifdef CONFIG_MODULES
10942 ++ limit = ktva_ktla((unsigned long)&MODULES_END);
10943 ++#else
10944 ++ limit = (unsigned long)&_etext;
10945 ++#endif
10946 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
10947 ++
10948 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
10949 ++ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
10950 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
10951 ++ }
10952 ++
10953 ++ /* PaX: make KERNEL_CS read-only */
10954 ++ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) {
10955 ++ pgd = pgd_offset_k(addr);
10956 ++ pud = pud_offset(pgd, addr);
10957 ++ pmd = pmd_offset(pud, addr);
10958 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
10959 ++ }
10960 ++#ifdef CONFIG_X86_PAE
10961 ++ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
10962 ++ pgd = pgd_offset_k(addr);
10963 ++ pud = pud_offset(pgd, addr);
10964 ++ pmd = pmd_offset(pud, addr);
10965 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
10966 ++ }
10967 ++#endif
10968 ++ flush_tlb_all();
10969 ++#endif
10970 ++
10971 + free_init_pages("unused kernel memory",
10972 + (unsigned long)(&__init_begin),
10973 + (unsigned long)(&__init_end));
10974 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_64.c linux-2.6.27.10/arch/x86/mm/init_64.c
10975 +--- linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:16:51.000000000 -0500
10976 ++++ linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:13:45.000000000 -0500
10977 +@@ -118,6 +118,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
10978 + pmd_t *pmd;
10979 + pte_t *pte;
10980 +
10981 ++#ifdef CONFIG_PAX_KERNEXEC
10982 ++ unsigned long cr0;
10983 ++#endif
10984 ++
10985 + pud = pud_page + pud_index(vaddr);
10986 + if (pud_none(*pud)) {
10987 + pmd = (pmd_t *) spp_getpage();
10988 +@@ -142,8 +146,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
10989 + if (!pte_none(*pte) && pte_val(new_pte) &&
10990 + pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
10991 + pte_ERROR(*pte);
10992 ++
10993 ++#ifdef CONFIG_PAX_KERNEXEC
10994 ++ pax_open_kernel(cr0);
10995 ++#endif
10996 ++
10997 + set_pte(pte, new_pte);
10998 +
10999 ++#ifdef CONFIG_PAX_KERNEXEC
11000 ++ pax_close_kernel(cr0);
11001 ++#endif
11002 ++
11003 + /*
11004 + * It's enough to flush this one mapping.
11005 + * (PGE mappings get flushed as well)
11006 +@@ -184,14 +197,12 @@ static void __init __init_extra_mapping(
11007 + pgd = pgd_offset_k((unsigned long)__va(phys));
11008 + if (pgd_none(*pgd)) {
11009 + pud = (pud_t *) spp_getpage();
11010 +- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
11011 +- _PAGE_USER));
11012 ++ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
11013 + }
11014 + pud = pud_offset(pgd, (unsigned long)__va(phys));
11015 + if (pud_none(*pud)) {
11016 + pmd = (pmd_t *) spp_getpage();
11017 +- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
11018 +- _PAGE_USER));
11019 ++ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
11020 + }
11021 + pmd = pmd_offset(pud, phys);
11022 + BUG_ON(!pmd_none(*pmd));
11023 +@@ -754,7 +765,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to
11024 + */
11025 + int devmem_is_allowed(unsigned long pagenr)
11026 + {
11027 +- if (pagenr <= 256)
11028 ++ if (!pagenr)
11029 ++ return 1;
11030 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11031 + return 1;
11032 + if (!page_is_ram(pagenr))
11033 + return 1;
11034 +@@ -842,6 +855,39 @@ void free_init_pages(char *what, unsigne
11035 +
11036 + void free_initmem(void)
11037 + {
11038 ++
11039 ++#ifdef CONFIG_PAX_KERNEXEC
11040 ++ unsigned long addr, end;
11041 ++ pgd_t *pgd;
11042 ++ pud_t *pud;
11043 ++ pmd_t *pmd;
11044 ++
11045 ++ /* PaX: make kernel code/rodata read-only, rest non-executable */
11046 ++ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
11047 ++ pgd = pgd_offset_k(addr);
11048 ++ pud = pud_offset(pgd, addr);
11049 ++ pmd = pmd_offset(pud, addr);
11050 ++ if ((unsigned long)_text <= addr && addr < (unsigned long)_data)
11051 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11052 ++ else
11053 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11054 ++ }
11055 ++
11056 ++ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
11057 ++ end = addr + KERNEL_IMAGE_SIZE;
11058 ++ for (; addr < end; addr += PMD_SIZE) {
11059 ++ pgd = pgd_offset_k(addr);
11060 ++ pud = pud_offset(pgd, addr);
11061 ++ pmd = pmd_offset(pud, addr);
11062 ++ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data)))
11063 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11064 ++ else
11065 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11066 ++ }
11067 ++
11068 ++ flush_tlb_all();
11069 ++#endif
11070 ++
11071 + free_init_pages("unused kernel memory",
11072 + (unsigned long)(&__init_begin),
11073 + (unsigned long)(&__init_end));
11074 +@@ -1014,7 +1060,7 @@ int in_gate_area_no_task(unsigned long a
11075 +
11076 + const char *arch_vma_name(struct vm_area_struct *vma)
11077 + {
11078 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11079 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11080 + return "[vdso]";
11081 + if (vma == &gate_vma)
11082 + return "[vsyscall]";
11083 +diff -urNp linux-2.6.27.10/arch/x86/mm/ioremap.c linux-2.6.27.10/arch/x86/mm/ioremap.c
11084 +--- linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-07 12:55:34.000000000 -0500
11085 ++++ linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-18 03:38:44.000000000 -0500
11086 +@@ -63,8 +63,8 @@ int page_is_ram(unsigned long pagenr)
11087 + * Second special case: Some BIOSen report the PC BIOS
11088 + * area (640->1Mb) as ram even though it is not.
11089 + */
11090 +- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
11091 +- pagenr < (BIOS_END >> PAGE_SHIFT))
11092 ++ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
11093 ++ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11094 + return 0;
11095 +
11096 + for (i = 0; i < e820.nr_map; i++) {
11097 +@@ -217,6 +217,8 @@ static void __iomem *__ioremap_caller(re
11098 + break;
11099 + }
11100 +
11101 ++ prot = canon_pgprot(prot);
11102 ++
11103 + /*
11104 + * Ok, go for it..
11105 + */
11106 +diff -urNp linux-2.6.27.10/arch/x86/mm/mmap.c linux-2.6.27.10/arch/x86/mm/mmap.c
11107 +--- linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
11108 ++++ linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-18 03:38:44.000000000 -0500
11109 +@@ -36,7 +36,7 @@
11110 + * Leave an at least ~128 MB hole.
11111 + */
11112 + #define MIN_GAP (128*1024*1024)
11113 +-#define MAX_GAP (TASK_SIZE/6*5)
11114 ++#define MAX_GAP (pax_task_size/6*5)
11115 +
11116 + /*
11117 + * True on X86_32 or when emulating IA32 on X86_64
11118 +@@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void)
11119 + return rnd << PAGE_SHIFT;
11120 + }
11121 +
11122 +-static unsigned long mmap_base(void)
11123 ++static unsigned long mmap_base(struct mm_struct *mm)
11124 + {
11125 + unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
11126 ++ unsigned long pax_task_size = TASK_SIZE;
11127 ++
11128 ++#ifdef CONFIG_PAX_SEGMEXEC
11129 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11130 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11131 ++#endif
11132 +
11133 + if (gap < MIN_GAP)
11134 + gap = MIN_GAP;
11135 + else if (gap > MAX_GAP)
11136 + gap = MAX_GAP;
11137 +
11138 +- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
11139 ++ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
11140 + }
11141 +
11142 + /*
11143 + * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
11144 + * does, but not when emulating X86_32
11145 + */
11146 +-static unsigned long mmap_legacy_base(void)
11147 ++static unsigned long mmap_legacy_base(struct mm_struct *mm)
11148 + {
11149 +- if (mmap_is_ia32())
11150 ++ if (mmap_is_ia32()) {
11151 ++
11152 ++#ifdef CONFIG_PAX_SEGMEXEC
11153 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11154 ++ return SEGMEXEC_TASK_UNMAPPED_BASE;
11155 ++ else
11156 ++#endif
11157 ++
11158 + return TASK_UNMAPPED_BASE;
11159 +- else
11160 ++ } else
11161 + return TASK_UNMAPPED_BASE + mmap_rnd();
11162 + }
11163 +
11164 +@@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo
11165 + void arch_pick_mmap_layout(struct mm_struct *mm)
11166 + {
11167 + if (mmap_is_legacy()) {
11168 +- mm->mmap_base = mmap_legacy_base();
11169 ++ mm->mmap_base = mmap_legacy_base(mm);
11170 ++
11171 ++#ifdef CONFIG_PAX_RANDMMAP
11172 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11173 ++ mm->mmap_base += mm->delta_mmap;
11174 ++#endif
11175 ++
11176 + mm->get_unmapped_area = arch_get_unmapped_area;
11177 + mm->unmap_area = arch_unmap_area;
11178 + } else {
11179 +- mm->mmap_base = mmap_base();
11180 ++ mm->mmap_base = mmap_base(mm);
11181 ++
11182 ++#ifdef CONFIG_PAX_RANDMMAP
11183 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11184 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11185 ++#endif
11186 ++
11187 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11188 + mm->unmap_area = arch_unmap_area_topdown;
11189 + }
11190 +diff -urNp linux-2.6.27.10/arch/x86/mm/pageattr.c linux-2.6.27.10/arch/x86/mm/pageattr.c
11191 +--- linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-07 12:55:34.000000000 -0500
11192 ++++ linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-18 03:38:44.000000000 -0500
11193 +@@ -20,6 +20,7 @@
11194 + #include <asm/pgalloc.h>
11195 + #include <asm/proto.h>
11196 + #include <asm/pat.h>
11197 ++#include <asm/desc.h>
11198 +
11199 + /*
11200 + * The current flushing context - we pass it instead of 5 arguments:
11201 +@@ -213,7 +214,7 @@ static inline pgprot_t static_protection
11202 + * Does not cover __inittext since that is gone later on. On
11203 + * 64bit we do not enforce !NX on the low mapping
11204 + */
11205 +- if (within(address, (unsigned long)_text, (unsigned long)_etext))
11206 ++ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
11207 + pgprot_val(forbidden) |= _PAGE_NX;
11208 +
11209 + /*
11210 +@@ -275,8 +276,20 @@ EXPORT_SYMBOL_GPL(lookup_address);
11211 + */
11212 + static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
11213 + {
11214 ++
11215 ++#ifdef CONFIG_PAX_KERNEXEC
11216 ++ unsigned long cr0;
11217 ++
11218 ++ pax_open_kernel(cr0);
11219 ++#endif
11220 ++
11221 + /* change init_mm */
11222 + set_pte_atomic(kpte, pte);
11223 ++
11224 ++#ifdef CONFIG_PAX_KERNEXEC
11225 ++ pax_close_kernel(cr0);
11226 ++#endif
11227 ++
11228 + #ifdef CONFIG_X86_32
11229 + if (!SHARED_KERNEL_PMD) {
11230 + struct page *page;
11231 +diff -urNp linux-2.6.27.10/arch/x86/mm/pat.c linux-2.6.27.10/arch/x86/mm/pat.c
11232 +--- linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-07 12:55:34.000000000 -0500
11233 ++++ linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-18 03:38:44.000000000 -0500
11234 +@@ -396,7 +396,7 @@ pgprot_t phys_mem_access_prot(struct fil
11235 + return vma_prot;
11236 + }
11237 +
11238 +-#ifdef CONFIG_STRICT_DEVMEM
11239 ++#ifndef CONFIG_STRICT_DEVMEM
11240 + /* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
11241 + static inline int range_is_allowed(unsigned long pfn, unsigned long size)
11242 + {
11243 +diff -urNp linux-2.6.27.10/arch/x86/mm/pgtable_32.c linux-2.6.27.10/arch/x86/mm/pgtable_32.c
11244 +--- linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-07 12:55:34.000000000 -0500
11245 ++++ linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-18 03:38:44.000000000 -0500
11246 +@@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr,
11247 + pmd_t *pmd;
11248 + pte_t *pte;
11249 +
11250 ++#ifdef CONFIG_PAX_KERNEXEC
11251 ++ unsigned long cr0;
11252 ++#endif
11253 ++
11254 + pgd = swapper_pg_dir + pgd_index(vaddr);
11255 + if (pgd_none(*pgd)) {
11256 + BUG();
11257 +@@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr,
11258 + return;
11259 + }
11260 + pte = pte_offset_kernel(pmd, vaddr);
11261 ++
11262 ++#ifdef CONFIG_PAX_KERNEXEC
11263 ++ pax_open_kernel(cr0);
11264 ++#endif
11265 ++
11266 + if (pte_val(pteval))
11267 + set_pte_present(&init_mm, vaddr, pte, pteval);
11268 + else
11269 + pte_clear(&init_mm, vaddr, pte);
11270 +
11271 ++#ifdef CONFIG_PAX_KERNEXEC
11272 ++ pax_close_kernel(cr0);
11273 ++#endif
11274 ++
11275 + /*
11276 + * It's enough to flush this one mapping.
11277 + * (PGE mappings get flushed as well)
11278 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/backtrace.c linux-2.6.27.10/arch/x86/oprofile/backtrace.c
11279 +--- linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-07 12:55:34.000000000 -0500
11280 ++++ linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-18 03:38:44.000000000 -0500
11281 +@@ -37,7 +37,7 @@ static void backtrace_address(void *data
11282 + unsigned int *depth = data;
11283 +
11284 + if ((*depth)--)
11285 +- oprofile_add_trace(addr);
11286 ++ oprofile_add_trace(ktla_ktva(addr));
11287 + }
11288 +
11289 + static struct stacktrace_ops backtrace_ops = {
11290 +@@ -79,7 +79,7 @@ x86_backtrace(struct pt_regs * const reg
11291 + struct frame_head *head = (struct frame_head *)frame_pointer(regs);
11292 + unsigned long stack = kernel_trap_sp(regs);
11293 +
11294 +- if (!user_mode_vm(regs)) {
11295 ++ if (!user_mode(regs)) {
11296 + if (depth)
11297 + dump_trace(NULL, regs, (unsigned long *)stack, 0,
11298 + &backtrace_ops, &depth);
11299 +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
11300 +--- linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-07 12:55:34.000000000 -0500
11301 ++++ linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-18 03:38:44.000000000 -0500
11302 +@@ -47,7 +47,7 @@ static inline void setup_num_counters(vo
11303 + #endif
11304 + }
11305 +
11306 +-static int inline addr_increment(void)
11307 ++static inline int addr_increment(void)
11308 + {
11309 + #ifdef CONFIG_SMP
11310 + return smp_num_siblings == 2 ? 2 : 1;
11311 +diff -urNp linux-2.6.27.10/arch/x86/pci/common.c linux-2.6.27.10/arch/x86/pci/common.c
11312 +--- linux-2.6.27.10/arch/x86/pci/common.c 2008-11-07 12:55:34.000000000 -0500
11313 ++++ linux-2.6.27.10/arch/x86/pci/common.c 2008-11-18 03:38:44.000000000 -0500
11314 +@@ -362,7 +362,7 @@ static struct dmi_system_id __devinitdat
11315 + DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
11316 + },
11317 + },
11318 +- {}
11319 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
11320 + };
11321 +
11322 + void __init dmi_check_pciprobe(void)
11323 +diff -urNp linux-2.6.27.10/arch/x86/pci/fixup.c linux-2.6.27.10/arch/x86/pci/fixup.c
11324 +--- linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-07 12:55:34.000000000 -0500
11325 ++++ linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-18 03:38:44.000000000 -0500
11326 +@@ -365,7 +365,7 @@ static struct dmi_system_id __devinitdat
11327 + DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
11328 + },
11329 + },
11330 +- {}
11331 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11332 + };
11333 +
11334 + /*
11335 +@@ -436,7 +436,7 @@ static struct dmi_system_id __devinitdat
11336 + DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
11337 + },
11338 + },
11339 +- { }
11340 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11341 + };
11342 +
11343 + static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
11344 +diff -urNp linux-2.6.27.10/arch/x86/pci/irq.c linux-2.6.27.10/arch/x86/pci/irq.c
11345 +--- linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-07 12:55:34.000000000 -0500
11346 ++++ linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-18 03:38:44.000000000 -0500
11347 +@@ -544,7 +544,7 @@ static __init int intel_router_probe(str
11348 + static struct pci_device_id __initdata pirq_440gx[] = {
11349 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
11350 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
11351 +- { },
11352 ++ { PCI_DEVICE(0, 0) }
11353 + };
11354 +
11355 + /* 440GX has a proprietary PIRQ router -- don't use it */
11356 +@@ -1131,7 +1131,7 @@ static struct dmi_system_id __initdata p
11357 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
11358 + },
11359 + },
11360 +- { }
11361 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11362 + };
11363 +
11364 + int __init pcibios_irq_init(void)
11365 +diff -urNp linux-2.6.27.10/arch/x86/pci/pcbios.c linux-2.6.27.10/arch/x86/pci/pcbios.c
11366 +--- linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-07 12:55:34.000000000 -0500
11367 ++++ linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-18 03:38:44.000000000 -0500
11368 +@@ -57,50 +57,120 @@ union bios32 {
11369 + static struct {
11370 + unsigned long address;
11371 + unsigned short segment;
11372 +-} bios32_indirect = { 0, __KERNEL_CS };
11373 ++} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
11374 +
11375 + /*
11376 + * Returns the entry point for the given service, NULL on error
11377 + */
11378 +
11379 +-static unsigned long bios32_service(unsigned long service)
11380 ++static unsigned long __devinit bios32_service(unsigned long service)
11381 + {
11382 + unsigned char return_code; /* %al */
11383 + unsigned long address; /* %ebx */
11384 + unsigned long length; /* %ecx */
11385 + unsigned long entry; /* %edx */
11386 + unsigned long flags;
11387 ++ struct desc_struct d, *gdt;
11388 ++
11389 ++#ifdef CONFIG_PAX_KERNEXEC
11390 ++ unsigned long cr0;
11391 ++#endif
11392 +
11393 + local_irq_save(flags);
11394 +- __asm__("lcall *(%%edi); cld"
11395 ++
11396 ++ gdt = get_cpu_gdt_table(smp_processor_id());
11397 ++
11398 ++#ifdef CONFIG_PAX_KERNEXEC
11399 ++ pax_open_kernel(cr0);
11400 ++#endif
11401 ++
11402 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
11403 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11404 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
11405 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11406 ++
11407 ++#ifdef CONFIG_PAX_KERNEXEC
11408 ++ pax_close_kernel(cr0);
11409 ++#endif
11410 ++
11411 ++ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
11412 + : "=a" (return_code),
11413 + "=b" (address),
11414 + "=c" (length),
11415 + "=d" (entry)
11416 + : "0" (service),
11417 + "1" (0),
11418 +- "D" (&bios32_indirect));
11419 ++ "D" (&bios32_indirect),
11420 ++ "r"(__PCIBIOS_DS)
11421 ++ : "memory");
11422 ++
11423 ++#ifdef CONFIG_PAX_KERNEXEC
11424 ++ pax_open_kernel(cr0);
11425 ++#endif
11426 ++
11427 ++ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
11428 ++ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
11429 ++ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
11430 ++ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
11431 ++
11432 ++#ifdef CONFIG_PAX_KERNEXEC
11433 ++ pax_close_kernel(cr0);
11434 ++#endif
11435 ++
11436 + local_irq_restore(flags);
11437 +
11438 + switch (return_code) {
11439 +- case 0:
11440 +- return address + entry;
11441 +- case 0x80: /* Not present */
11442 +- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11443 +- return 0;
11444 +- default: /* Shouldn't happen */
11445 +- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11446 +- service, return_code);
11447 ++ case 0: {
11448 ++ int cpu;
11449 ++ unsigned char flags;
11450 ++
11451 ++ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
11452 ++ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
11453 ++ printk(KERN_WARNING "bios32_service: not valid\n");
11454 + return 0;
11455 ++ }
11456 ++ address = address + PAGE_OFFSET;
11457 ++ length += 16UL; /* some BIOSs underreport this... */
11458 ++ flags = 4;
11459 ++ if (length >= 64*1024*1024) {
11460 ++ length >>= PAGE_SHIFT;
11461 ++ flags |= 8;
11462 ++ }
11463 ++
11464 ++#ifdef CONFIG_PAX_KERNEXEC
11465 ++ pax_open_kernel(cr0);
11466 ++#endif
11467 ++
11468 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
11469 ++ gdt = get_cpu_gdt_table(cpu);
11470 ++ pack_descriptor(&d, address, length, 0x9b, flags);
11471 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11472 ++ pack_descriptor(&d, address, length, 0x93, flags);
11473 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11474 ++ }
11475 ++
11476 ++#ifdef CONFIG_PAX_KERNEXEC
11477 ++ pax_close_kernel(cr0);
11478 ++#endif
11479 ++
11480 ++ return entry;
11481 ++ }
11482 ++ case 0x80: /* Not present */
11483 ++ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11484 ++ return 0;
11485 ++ default: /* Shouldn't happen */
11486 ++ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11487 ++ service, return_code);
11488 ++ return 0;
11489 + }
11490 + }
11491 +
11492 + static struct {
11493 + unsigned long address;
11494 + unsigned short segment;
11495 +-} pci_indirect = { 0, __KERNEL_CS };
11496 ++} pci_indirect __read_only = { 0, __PCIBIOS_CS };
11497 +
11498 +-static int pci_bios_present;
11499 ++static int pci_bios_present __read_only;
11500 +
11501 + static int __devinit check_pcibios(void)
11502 + {
11503 +@@ -109,11 +179,13 @@ static int __devinit check_pcibios(void)
11504 + unsigned long flags, pcibios_entry;
11505 +
11506 + if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
11507 +- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
11508 ++ pci_indirect.address = pcibios_entry;
11509 +
11510 + local_irq_save(flags);
11511 +- __asm__(
11512 +- "lcall *(%%edi); cld\n\t"
11513 ++ __asm__("movw %w6, %%ds\n\t"
11514 ++ "lcall *%%ss:(%%edi); cld\n\t"
11515 ++ "push %%ss\n\t"
11516 ++ "pop %%ds\n\t"
11517 + "jc 1f\n\t"
11518 + "xor %%ah, %%ah\n"
11519 + "1:"
11520 +@@ -122,7 +194,8 @@ static int __devinit check_pcibios(void)
11521 + "=b" (ebx),
11522 + "=c" (ecx)
11523 + : "1" (PCIBIOS_PCI_BIOS_PRESENT),
11524 +- "D" (&pci_indirect)
11525 ++ "D" (&pci_indirect),
11526 ++ "r" (__PCIBIOS_DS)
11527 + : "memory");
11528 + local_irq_restore(flags);
11529 +
11530 +@@ -166,7 +239,10 @@ static int pci_bios_read(unsigned int se
11531 +
11532 + switch (len) {
11533 + case 1:
11534 +- __asm__("lcall *(%%esi); cld\n\t"
11535 ++ __asm__("movw %w6, %%ds\n\t"
11536 ++ "lcall *%%ss:(%%esi); cld\n\t"
11537 ++ "push %%ss\n\t"
11538 ++ "pop %%ds\n\t"
11539 + "jc 1f\n\t"
11540 + "xor %%ah, %%ah\n"
11541 + "1:"
11542 +@@ -175,7 +251,8 @@ static int pci_bios_read(unsigned int se
11543 + : "1" (PCIBIOS_READ_CONFIG_BYTE),
11544 + "b" (bx),
11545 + "D" ((long)reg),
11546 +- "S" (&pci_indirect));
11547 ++ "S" (&pci_indirect),
11548 ++ "r" (__PCIBIOS_DS));
11549 + /*
11550 + * Zero-extend the result beyond 8 bits, do not trust the
11551 + * BIOS having done it:
11552 +@@ -183,7 +260,10 @@ static int pci_bios_read(unsigned int se
11553 + *value &= 0xff;
11554 + break;
11555 + case 2:
11556 +- __asm__("lcall *(%%esi); cld\n\t"
11557 ++ __asm__("movw %w6, %%ds\n\t"
11558 ++ "lcall *%%ss:(%%esi); cld\n\t"
11559 ++ "push %%ss\n\t"
11560 ++ "pop %%ds\n\t"
11561 + "jc 1f\n\t"
11562 + "xor %%ah, %%ah\n"
11563 + "1:"
11564 +@@ -192,7 +272,8 @@ static int pci_bios_read(unsigned int se
11565 + : "1" (PCIBIOS_READ_CONFIG_WORD),
11566 + "b" (bx),
11567 + "D" ((long)reg),
11568 +- "S" (&pci_indirect));
11569 ++ "S" (&pci_indirect),
11570 ++ "r" (__PCIBIOS_DS));
11571 + /*
11572 + * Zero-extend the result beyond 16 bits, do not trust the
11573 + * BIOS having done it:
11574 +@@ -200,7 +281,10 @@ static int pci_bios_read(unsigned int se
11575 + *value &= 0xffff;
11576 + break;
11577 + case 4:
11578 +- __asm__("lcall *(%%esi); cld\n\t"
11579 ++ __asm__("movw %w6, %%ds\n\t"
11580 ++ "lcall *%%ss:(%%esi); cld\n\t"
11581 ++ "push %%ss\n\t"
11582 ++ "pop %%ds\n\t"
11583 + "jc 1f\n\t"
11584 + "xor %%ah, %%ah\n"
11585 + "1:"
11586 +@@ -209,7 +293,8 @@ static int pci_bios_read(unsigned int se
11587 + : "1" (PCIBIOS_READ_CONFIG_DWORD),
11588 + "b" (bx),
11589 + "D" ((long)reg),
11590 +- "S" (&pci_indirect));
11591 ++ "S" (&pci_indirect),
11592 ++ "r" (__PCIBIOS_DS));
11593 + break;
11594 + }
11595 +
11596 +@@ -232,7 +317,10 @@ static int pci_bios_write(unsigned int s
11597 +
11598 + switch (len) {
11599 + case 1:
11600 +- __asm__("lcall *(%%esi); cld\n\t"
11601 ++ __asm__("movw %w6, %%ds\n\t"
11602 ++ "lcall *%%ss:(%%esi); cld\n\t"
11603 ++ "push %%ss\n\t"
11604 ++ "pop %%ds\n\t"
11605 + "jc 1f\n\t"
11606 + "xor %%ah, %%ah\n"
11607 + "1:"
11608 +@@ -241,10 +329,14 @@ static int pci_bios_write(unsigned int s
11609 + "c" (value),
11610 + "b" (bx),
11611 + "D" ((long)reg),
11612 +- "S" (&pci_indirect));
11613 ++ "S" (&pci_indirect),
11614 ++ "r" (__PCIBIOS_DS));
11615 + break;
11616 + case 2:
11617 +- __asm__("lcall *(%%esi); cld\n\t"
11618 ++ __asm__("movw %w6, %%ds\n\t"
11619 ++ "lcall *%%ss:(%%esi); cld\n\t"
11620 ++ "push %%ss\n\t"
11621 ++ "pop %%ds\n\t"
11622 + "jc 1f\n\t"
11623 + "xor %%ah, %%ah\n"
11624 + "1:"
11625 +@@ -253,10 +345,14 @@ static int pci_bios_write(unsigned int s
11626 + "c" (value),
11627 + "b" (bx),
11628 + "D" ((long)reg),
11629 +- "S" (&pci_indirect));
11630 ++ "S" (&pci_indirect),
11631 ++ "r" (__PCIBIOS_DS));
11632 + break;
11633 + case 4:
11634 +- __asm__("lcall *(%%esi); cld\n\t"
11635 ++ __asm__("movw %w6, %%ds\n\t"
11636 ++ "lcall *%%ss:(%%esi); cld\n\t"
11637 ++ "push %%ss\n\t"
11638 ++ "pop %%ds\n\t"
11639 + "jc 1f\n\t"
11640 + "xor %%ah, %%ah\n"
11641 + "1:"
11642 +@@ -265,7 +361,8 @@ static int pci_bios_write(unsigned int s
11643 + "c" (value),
11644 + "b" (bx),
11645 + "D" ((long)reg),
11646 +- "S" (&pci_indirect));
11647 ++ "S" (&pci_indirect),
11648 ++ "r" (__PCIBIOS_DS));
11649 + break;
11650 + }
11651 +
11652 +@@ -369,10 +466,13 @@ struct irq_routing_table * pcibios_get_i
11653 +
11654 + DBG("PCI: Fetching IRQ routing table... ");
11655 + __asm__("push %%es\n\t"
11656 ++ "movw %w8, %%ds\n\t"
11657 + "push %%ds\n\t"
11658 + "pop %%es\n\t"
11659 +- "lcall *(%%esi); cld\n\t"
11660 ++ "lcall *%%ss:(%%esi); cld\n\t"
11661 + "pop %%es\n\t"
11662 ++ "push %%ss\n\t"
11663 ++ "pop %%ds\n"
11664 + "jc 1f\n\t"
11665 + "xor %%ah, %%ah\n"
11666 + "1:"
11667 +@@ -383,7 +483,8 @@ struct irq_routing_table * pcibios_get_i
11668 + "1" (0),
11669 + "D" ((long) &opt),
11670 + "S" (&pci_indirect),
11671 +- "m" (opt)
11672 ++ "m" (opt),
11673 ++ "r" (__PCIBIOS_DS)
11674 + : "memory");
11675 + DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
11676 + if (ret & 0xff00)
11677 +@@ -407,7 +508,10 @@ int pcibios_set_irq_routing(struct pci_d
11678 + {
11679 + int ret;
11680 +
11681 +- __asm__("lcall *(%%esi); cld\n\t"
11682 ++ __asm__("movw %w5, %%ds\n\t"
11683 ++ "lcall *%%ss:(%%esi); cld\n\t"
11684 ++ "push %%ss\n\t"
11685 ++ "pop %%ds\n"
11686 + "jc 1f\n\t"
11687 + "xor %%ah, %%ah\n"
11688 + "1:"
11689 +@@ -415,7 +519,8 @@ int pcibios_set_irq_routing(struct pci_d
11690 + : "0" (PCIBIOS_SET_PCI_HW_INT),
11691 + "b" ((dev->bus->number << 8) | dev->devfn),
11692 + "c" ((irq << 8) | (pin + 10)),
11693 +- "S" (&pci_indirect));
11694 ++ "S" (&pci_indirect),
11695 ++ "r" (__PCIBIOS_DS));
11696 + return !(ret & 0xff00);
11697 + }
11698 + EXPORT_SYMBOL(pcibios_set_irq_routing);
11699 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_32.c linux-2.6.27.10/arch/x86/power/cpu_32.c
11700 +--- linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-07 12:55:34.000000000 -0500
11701 ++++ linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-18 03:38:44.000000000 -0500
11702 +@@ -66,7 +66,7 @@ static void do_fpu_end(void)
11703 + static void fix_processor_context(void)
11704 + {
11705 + int cpu = smp_processor_id();
11706 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11707 ++ struct tss_struct *t = init_tss + cpu;
11708 +
11709 + set_tss_desc(cpu, t); /*
11710 + * This just modifies memory; should not be
11711 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_64.c linux-2.6.27.10/arch/x86/power/cpu_64.c
11712 +--- linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-07 12:55:34.000000000 -0500
11713 ++++ linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-18 03:38:44.000000000 -0500
11714 +@@ -136,7 +136,11 @@ void restore_processor_state(void)
11715 + static void fix_processor_context(void)
11716 + {
11717 + int cpu = smp_processor_id();
11718 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11719 ++ struct tss_struct *t = init_tss + cpu;
11720 ++
11721 ++#ifdef CONFIG_PAX_KERNEXEC
11722 ++ unsigned long cr0;
11723 ++#endif
11724 +
11725 + /*
11726 + * This just modifies memory; should not be necessary. But... This
11727 +@@ -145,8 +149,16 @@ static void fix_processor_context(void)
11728 + */
11729 + set_tss_desc(cpu, t);
11730 +
11731 ++#ifdef CONFIG_PAX_KERNEXEC
11732 ++ pax_open_kernel(cr0);
11733 ++#endif
11734 ++
11735 + get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
11736 +
11737 ++#ifdef CONFIG_PAX_KERNEXEC
11738 ++ pax_close_kernel(cr0);
11739 ++#endif
11740 ++
11741 + syscall_init(); /* This sets MSR_*STAR and related */
11742 + load_TR_desc(); /* This does ltr */
11743 + load_LDT(&current->active_mm->context); /* This does lldt */
11744 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c
11745 +--- linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-07 12:55:34.000000000 -0500
11746 ++++ linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-18 03:38:44.000000000 -0500
11747 +@@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m
11748 + void enable_sep_cpu(void)
11749 + {
11750 + int cpu = get_cpu();
11751 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
11752 ++ struct tss_struct *tss = init_tss + cpu;
11753 +
11754 + if (!boot_cpu_has(X86_FEATURE_SEP)) {
11755 + put_cpu();
11756 +@@ -249,7 +249,7 @@ static int __init gate_vma_init(void)
11757 + gate_vma.vm_start = FIXADDR_USER_START;
11758 + gate_vma.vm_end = FIXADDR_USER_END;
11759 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
11760 +- gate_vma.vm_page_prot = __P101;
11761 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
11762 + /*
11763 + * Make sure the vDSO gets into every core dump.
11764 + * Dumping its contents makes post-mortem fully interpretable later
11765 +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l
11766 + if (compat)
11767 + addr = VDSO_HIGH_BASE;
11768 + else {
11769 +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
11770 ++ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
11771 + if (IS_ERR_VALUE(addr)) {
11772 + ret = addr;
11773 + goto up_fail;
11774 +@@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l
11775 + goto up_fail;
11776 + }
11777 +
11778 +- current->mm->context.vdso = (void *)addr;
11779 ++ current->mm->context.vdso = addr;
11780 + current_thread_info()->sysenter_return =
11781 + VDSO32_SYMBOL(addr, SYSENTER_RETURN);
11782 +
11783 +@@ -384,7 +384,7 @@ static ctl_table abi_table2[] = {
11784 + .mode = 0644,
11785 + .proc_handler = proc_dointvec
11786 + },
11787 +- {}
11788 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11789 + };
11790 +
11791 + static ctl_table abi_root_table2[] = {
11792 +@@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = {
11793 + .mode = 0555,
11794 + .child = abi_table2
11795 + },
11796 +- {}
11797 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11798 + };
11799 +
11800 + static __init int ia32_binfmt_init(void)
11801 +@@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init);
11802 +
11803 + const char *arch_vma_name(struct vm_area_struct *vma)
11804 + {
11805 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11806 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11807 + return "[vdso]";
11808 ++
11809 ++#ifdef CONFIG_PAX_SEGMEXEC
11810 ++ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
11811 ++ return "[vdso]";
11812 ++#endif
11813 ++
11814 + return NULL;
11815 + }
11816 +
11817 +@@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru
11818 + struct mm_struct *mm = tsk->mm;
11819 +
11820 + /* Check to see if this task was created in compat vdso mode */
11821 +- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
11822 ++ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
11823 + return &gate_vma;
11824 + return NULL;
11825 + }
11826 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vma.c linux-2.6.27.10/arch/x86/vdso/vma.c
11827 +--- linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-07 12:55:34.000000000 -0500
11828 ++++ linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-18 03:38:44.000000000 -0500
11829 +@@ -123,7 +123,7 @@ int arch_setup_additional_pages(struct l
11830 + if (ret)
11831 + goto up_fail;
11832 +
11833 +- current->mm->context.vdso = (void *)addr;
11834 ++ current->mm->context.vdso = addr;
11835 + up_fail:
11836 + up_write(&mm->mmap_sem);
11837 + return ret;
11838 +diff -urNp linux-2.6.27.10/arch/x86/xen/enlighten.c linux-2.6.27.10/arch/x86/xen/enlighten.c
11839 +--- linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:37.000000000 -0500
11840 ++++ linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:46.000000000 -0500
11841 +@@ -343,7 +343,7 @@ static void xen_set_ldt(const void *addr
11842 + static void xen_load_gdt(const struct desc_ptr *dtr)
11843 + {
11844 + unsigned long *frames;
11845 +- unsigned long va = dtr->address;
11846 ++ unsigned long va = (unsigned long)dtr->address;
11847 + unsigned int size = dtr->size + 1;
11848 + unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
11849 + int f;
11850 +@@ -358,7 +358,7 @@ static void xen_load_gdt(const struct de
11851 + mcs = xen_mc_entry(sizeof(*frames) * pages);
11852 + frames = mcs.args;
11853 +
11854 +- for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
11855 ++ for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) {
11856 + frames[f] = virt_to_mfn(va);
11857 + make_lowmem_page_readonly((void *)va);
11858 + }
11859 +@@ -467,7 +467,7 @@ static void xen_write_idt_entry(gate_des
11860 +
11861 + preempt_disable();
11862 +
11863 +- start = __get_cpu_var(idt_desc).address;
11864 ++ start = (unsigned long)__get_cpu_var(idt_desc).address;
11865 + end = start + __get_cpu_var(idt_desc).size + 1;
11866 +
11867 + xen_mc_flush();
11868 +@@ -1574,6 +1574,8 @@ static __init pgd_t *xen_setup_kernel_pa
11869 + convert_pfn_mfn(init_level4_pgt);
11870 + convert_pfn_mfn(level3_ident_pgt);
11871 + convert_pfn_mfn(level3_kernel_pgt);
11872 ++ convert_pfn_mfn(level3_vmalloc_pgt);
11873 ++ convert_pfn_mfn(level3_vmemmap_pgt);
11874 +
11875 + l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
11876 + l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
11877 +@@ -1592,9 +1594,12 @@ static __init pgd_t *xen_setup_kernel_pa
11878 + set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
11879 + set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
11880 + set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
11881 ++ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
11882 ++ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
11883 + set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
11884 + set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
11885 + set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
11886 ++ set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
11887 +
11888 + /* Pin down new L4 */
11889 + pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
11890 +diff -urNp linux-2.6.27.10/arch/x86/xen/smp.c linux-2.6.27.10/arch/x86/xen/smp.c
11891 +--- linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-07 12:55:34.000000000 -0500
11892 ++++ linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-18 03:38:44.000000000 -0500
11893 +@@ -170,11 +170,6 @@ static void __init xen_smp_prepare_boot_
11894 + {
11895 + BUG_ON(smp_processor_id() != 0);
11896 + native_smp_prepare_boot_cpu();
11897 +-
11898 +- /* We've switched to the "real" per-cpu gdt, so make sure the
11899 +- old memory can be recycled */
11900 +- make_lowmem_page_readwrite(&per_cpu_var(gdt_page));
11901 +-
11902 + xen_setup_vcpu_info_placement();
11903 + }
11904 +
11905 +@@ -232,8 +227,8 @@ cpu_initialize_context(unsigned int cpu,
11906 + gdt = get_cpu_gdt_table(cpu);
11907 +
11908 + ctxt->flags = VGCF_IN_KERNEL;
11909 +- ctxt->user_regs.ds = __USER_DS;
11910 +- ctxt->user_regs.es = __USER_DS;
11911 ++ ctxt->user_regs.ds = __KERNEL_DS;
11912 ++ ctxt->user_regs.es = __KERNEL_DS;
11913 + ctxt->user_regs.ss = __KERNEL_DS;
11914 + #ifdef CONFIG_X86_32
11915 + ctxt->user_regs.fs = __KERNEL_PERCPU;
11916 +diff -urNp linux-2.6.27.10/crypto/async_tx/async_tx.c linux-2.6.27.10/crypto/async_tx/async_tx.c
11917 +--- linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-07 12:55:34.000000000 -0500
11918 ++++ linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-18 03:38:44.000000000 -0500
11919 +@@ -358,8 +358,8 @@ async_tx_init(void)
11920 + err:
11921 + printk(KERN_ERR "async_tx: initialization failure\n");
11922 +
11923 +- while (--cap >= 0)
11924 +- free_percpu(channel_table[cap]);
11925 ++ while (cap)
11926 ++ free_percpu(channel_table[--cap]);
11927 +
11928 + return 1;
11929 + }
11930 +diff -urNp linux-2.6.27.10/crypto/lrw.c linux-2.6.27.10/crypto/lrw.c
11931 +--- linux-2.6.27.10/crypto/lrw.c 2008-11-07 12:55:34.000000000 -0500
11932 ++++ linux-2.6.27.10/crypto/lrw.c 2008-11-18 03:38:44.000000000 -0500
11933 +@@ -54,7 +54,7 @@ static int setkey(struct crypto_tfm *par
11934 + struct priv *ctx = crypto_tfm_ctx(parent);
11935 + struct crypto_cipher *child = ctx->child;
11936 + int err, i;
11937 +- be128 tmp = { 0 };
11938 ++ be128 tmp = { 0, 0 };
11939 + int bsize = crypto_cipher_blocksize(child);
11940 +
11941 + crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
11942 +diff -urNp linux-2.6.27.10/Documentation/dontdiff linux-2.6.27.10/Documentation/dontdiff
11943 +--- linux-2.6.27.10/Documentation/dontdiff 2008-11-07 12:55:34.000000000 -0500
11944 ++++ linux-2.6.27.10/Documentation/dontdiff 2008-11-18 03:39:50.000000000 -0500
11945 +@@ -3,6 +3,7 @@
11946 + *.bin
11947 + *.cpio
11948 + *.css
11949 ++*.dbg
11950 + *.dvi
11951 + *.eps
11952 + *.fw.gen.S
11953 +@@ -53,9 +54,14 @@ COPYING
11954 + CREDITS
11955 + CVS
11956 + ChangeSet
11957 ++GPATH
11958 ++GRTAGS
11959 ++GSYMS
11960 ++GTAGS
11961 + Image
11962 + Kerntypes
11963 + MODS.txt
11964 ++Module.markers
11965 + Module.symvers
11966 + PENDING
11967 + SCCS
11968 +@@ -66,7 +72,6 @@ aic7*reg_print.c*
11969 + aic7*seq.h*
11970 + aicasm
11971 + aicdb.h*
11972 +-asm
11973 + asm-offsets.h
11974 + asm_offsets.h
11975 + autoconf.h*
11976 +@@ -74,6 +79,7 @@ bbootsect
11977 + bin2c
11978 + binkernel.spec
11979 + bootsect
11980 ++bounds.h
11981 + bsetup
11982 + btfixupprep
11983 + build
11984 +@@ -90,6 +96,7 @@ config_data.gz*
11985 + conmakehash
11986 + consolemap_deftbl.c*
11987 + crc32table.h*
11988 ++cpustr.h
11989 + cscope.*
11990 + defkeymap.c*
11991 + devlist.h*
11992 +@@ -138,6 +145,7 @@ miboot*
11993 + mk_elfconfig
11994 + mkboot
11995 + mkbugboot
11996 ++mkcpustr
11997 + mkdep
11998 + mkprep
11999 + mktables
12000 +@@ -179,16 +187,21 @@ times.h*
12001 + tkparse
12002 + trix_boot.h
12003 + utsrelease.h*
12004 +-vdso.lds
12005 ++vdso*.lds
12006 + version.h*
12007 + vmlinux
12008 + vmlinux-*
12009 + vmlinux.aout
12010 +-vmlinux*.lds*
12011 ++vmlinux.bin.all
12012 ++vmlinux*.lds
12013 ++vmlinux.relocs
12014 + vmlinux*.scr
12015 +-vsyscall.lds
12016 ++vsyscall*.lds
12017 ++wakeup.elf
12018 ++wakeup.lds
12019 + wanxlfw.inc
12020 + uImage
12021 + unifdef
12022 ++utsrelease.h
12023 + zImage*
12024 + zconf.hash.c
12025 +diff -urNp linux-2.6.27.10/drivers/acpi/blacklist.c linux-2.6.27.10/drivers/acpi/blacklist.c
12026 +--- linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-07 12:55:34.000000000 -0500
12027 ++++ linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-18 03:38:44.000000000 -0500
12028 +@@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b
12029 + {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
12030 + "Incorrect _ADR", 1},
12031 +
12032 +- {""}
12033 ++ {"", "", 0, 0, 0, all_versions, 0}
12034 + };
12035 +
12036 + #if CONFIG_ACPI_BLACKLIST_YEAR
12037 +diff -urNp linux-2.6.27.10/drivers/acpi/osl.c linux-2.6.27.10/drivers/acpi/osl.c
12038 +--- linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:16:51.000000000 -0500
12039 ++++ linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:13:45.000000000 -0500
12040 +@@ -494,6 +494,8 @@ acpi_os_read_memory(acpi_physical_addres
12041 + void __iomem *virt_addr;
12042 +
12043 + virt_addr = ioremap(phys_addr, width);
12044 ++ if (!virt_addr)
12045 ++ return AE_NO_MEMORY;
12046 + if (!value)
12047 + value = &dummy;
12048 +
12049 +@@ -522,6 +524,8 @@ acpi_os_write_memory(acpi_physical_addre
12050 + void __iomem *virt_addr;
12051 +
12052 + virt_addr = ioremap(phys_addr, width);
12053 ++ if (!virt_addr)
12054 ++ return AE_NO_MEMORY;
12055 +
12056 + switch (width) {
12057 + case 8:
12058 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_core.c linux-2.6.27.10/drivers/acpi/processor_core.c
12059 +--- linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-07 12:55:34.000000000 -0500
12060 ++++ linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-18 03:38:44.000000000 -0500
12061 +@@ -667,7 +667,7 @@ static int __cpuinit acpi_processor_star
12062 + return 0;
12063 + }
12064 +
12065 +- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
12066 ++ BUG_ON(pr->id >= nr_cpu_ids);
12067 +
12068 + /*
12069 + * Buggy BIOS check
12070 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_idle.c linux-2.6.27.10/drivers/acpi/processor_idle.c
12071 +--- linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-07 12:55:34.000000000 -0500
12072 ++++ linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-18 03:38:44.000000000 -0500
12073 +@@ -182,7 +182,7 @@ static struct dmi_system_id __cpuinitdat
12074 + DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
12075 + DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
12076 + (void *)2},
12077 +- {},
12078 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL},
12079 + };
12080 +
12081 + static inline u32 ticks_elapsed(u32 t1, u32 t2)
12082 +diff -urNp linux-2.6.27.10/drivers/acpi/tables/tbfadt.c linux-2.6.27.10/drivers/acpi/tables/tbfadt.c
12083 +--- linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-07 12:55:34.000000000 -0500
12084 ++++ linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-18 03:38:44.000000000 -0500
12085 +@@ -48,7 +48,7 @@
12086 + ACPI_MODULE_NAME("tbfadt")
12087 +
12088 + /* Local prototypes */
12089 +-static void inline
12090 ++static inline void
12091 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12092 + u8 bit_width, u64 address);
12093 +
12094 +@@ -122,7 +122,7 @@ static struct acpi_fadt_info fadt_info_t
12095 + *
12096 + ******************************************************************************/
12097 +
12098 +-static void inline
12099 ++static inline void
12100 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12101 + u8 bit_width, u64 address)
12102 + {
12103 +diff -urNp linux-2.6.27.10/drivers/ata/ahci.c linux-2.6.27.10/drivers/ata/ahci.c
12104 +--- linux-2.6.27.10/drivers/ata/ahci.c 2008-11-07 12:55:34.000000000 -0500
12105 ++++ linux-2.6.27.10/drivers/ata/ahci.c 2008-11-18 03:38:44.000000000 -0500
12106 +@@ -591,7 +591,7 @@ static const struct pci_device_id ahci_p
12107 + { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
12108 + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
12109 +
12110 +- { } /* terminate list */
12111 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12112 + };
12113 +
12114 +
12115 +diff -urNp linux-2.6.27.10/drivers/ata/ata_piix.c linux-2.6.27.10/drivers/ata/ata_piix.c
12116 +--- linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-07 12:55:34.000000000 -0500
12117 ++++ linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-18 03:38:44.000000000 -0500
12118 +@@ -284,7 +284,7 @@ static const struct pci_device_id piix_p
12119 + /* SATA Controller IDE (PCH) */
12120 + { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
12121 +
12122 +- { } /* terminate list */
12123 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12124 + };
12125 +
12126 + static struct pci_driver piix_pci_driver = {
12127 +@@ -587,7 +587,7 @@ static const struct ich_laptop ich_lapto
12128 + { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
12129 + { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
12130 + /* end marker */
12131 +- { 0, }
12132 ++ { 0, 0, 0 }
12133 + };
12134 +
12135 + /**
12136 +@@ -1143,7 +1143,7 @@ static int piix_broken_suspend(void)
12137 + },
12138 + },
12139 +
12140 +- { } /* terminate list */
12141 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL } /* terminate list */
12142 + };
12143 + static const char *oemstrs[] = {
12144 + "Tecra M3,",
12145 +diff -urNp linux-2.6.27.10/drivers/ata/libata-core.c linux-2.6.27.10/drivers/ata/libata-core.c
12146 +--- linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:11.000000000 -0500
12147 ++++ linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:21.000000000 -0500
12148 +@@ -746,7 +746,7 @@ static const struct ata_xfer_ent {
12149 + { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
12150 + { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
12151 + { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
12152 +- { -1, },
12153 ++ { -1, 0, 0 }
12154 + };
12155 +
12156 + /**
12157 +@@ -2917,7 +2917,7 @@ static const struct ata_timing ata_timin
12158 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
12159 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
12160 +
12161 +- { 0xFF }
12162 ++ { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
12163 + };
12164 +
12165 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
12166 +@@ -4073,7 +4073,7 @@ static const struct ata_blacklist_entry
12167 + { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
12168 +
12169 + /* End Marker */
12170 +- { }
12171 ++ { NULL, NULL, 0 }
12172 + };
12173 +
12174 + static int strn_pattern_cmp(const char *patt, const char *name, int wildchar)
12175 +diff -urNp linux-2.6.27.10/drivers/char/agp/frontend.c linux-2.6.27.10/drivers/char/agp/frontend.c
12176 +--- linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-07 12:55:34.000000000 -0500
12177 ++++ linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-18 03:38:44.000000000 -0500
12178 +@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
12179 + if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
12180 + return -EFAULT;
12181 +
12182 +- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
12183 ++ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
12184 + return -EFAULT;
12185 +
12186 + client = agp_find_client_by_pid(reserve.pid);
12187 +diff -urNp linux-2.6.27.10/drivers/char/agp/intel-agp.c linux-2.6.27.10/drivers/char/agp/intel-agp.c
12188 +--- linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-07 12:55:34.000000000 -0500
12189 ++++ linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-18 03:38:44.000000000 -0500
12190 +@@ -2332,7 +2332,7 @@ static struct pci_device_id agp_intel_pc
12191 + ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
12192 + ID(PCI_DEVICE_ID_INTEL_Q45_HB),
12193 + ID(PCI_DEVICE_ID_INTEL_G45_HB),
12194 +- { }
12195 ++ { 0, 0, 0, 0, 0, 0, 0 }
12196 + };
12197 +
12198 + MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
12199 +diff -urNp linux-2.6.27.10/drivers/char/hpet.c linux-2.6.27.10/drivers/char/hpet.c
12200 +--- linux-2.6.27.10/drivers/char/hpet.c 2008-11-07 12:55:34.000000000 -0500
12201 ++++ linux-2.6.27.10/drivers/char/hpet.c 2008-11-18 03:38:44.000000000 -0500
12202 +@@ -959,7 +959,7 @@ static struct acpi_driver hpet_acpi_driv
12203 + },
12204 + };
12205 +
12206 +-static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
12207 ++static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
12208 +
12209 + static int __init hpet_init(void)
12210 + {
12211 +diff -urNp linux-2.6.27.10/drivers/char/keyboard.c linux-2.6.27.10/drivers/char/keyboard.c
12212 +--- linux-2.6.27.10/drivers/char/keyboard.c 2008-11-07 12:55:34.000000000 -0500
12213 ++++ linux-2.6.27.10/drivers/char/keyboard.c 2008-11-18 03:38:44.000000000 -0500
12214 +@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
12215 + kbd->kbdmode == VC_MEDIUMRAW) &&
12216 + value != KVAL(K_SAK))
12217 + return; /* SAK is allowed even in raw mode */
12218 ++
12219 ++#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
12220 ++ {
12221 ++ void *func = fn_handler[value];
12222 ++ if (func == fn_show_state || func == fn_show_ptregs ||
12223 ++ func == fn_show_mem)
12224 ++ return;
12225 ++ }
12226 ++#endif
12227 ++
12228 + fn_handler[value](vc);
12229 + }
12230 +
12231 +@@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_
12232 + .evbit = { BIT_MASK(EV_SND) },
12233 + },
12234 +
12235 +- { }, /* Terminating entry */
12236 ++ { 0 }, /* Terminating entry */
12237 + };
12238 +
12239 + MODULE_DEVICE_TABLE(input, kbd_ids);
12240 +diff -urNp linux-2.6.27.10/drivers/char/mem.c linux-2.6.27.10/drivers/char/mem.c
12241 +--- linux-2.6.27.10/drivers/char/mem.c 2008-11-07 12:55:34.000000000 -0500
12242 ++++ linux-2.6.27.10/drivers/char/mem.c 2008-11-18 03:38:44.000000000 -0500
12243 +@@ -27,6 +27,7 @@
12244 + #include <linux/splice.h>
12245 + #include <linux/pfn.h>
12246 + #include <linux/smp_lock.h>
12247 ++#include <linux/grsecurity.h>
12248 +
12249 + #include <asm/uaccess.h>
12250 + #include <asm/io.h>
12251 +@@ -35,6 +36,10 @@
12252 + # include <linux/efi.h>
12253 + #endif
12254 +
12255 ++#ifdef CONFIG_GRKERNSEC
12256 ++extern struct file_operations grsec_fops;
12257 ++#endif
12258 ++
12259 + /*
12260 + * Architectures vary in how they handle caching for addresses
12261 + * outside of main memory.
12262 +@@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f
12263 + if (!valid_phys_addr_range(p, count))
12264 + return -EFAULT;
12265 +
12266 ++#ifdef CONFIG_GRKERNSEC_KMEM
12267 ++ gr_handle_mem_write();
12268 ++ return -EPERM;
12269 ++#endif
12270 ++
12271 + written = 0;
12272 +
12273 + #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
12274 +@@ -350,6 +360,11 @@ static int mmap_mem(struct file * file,
12275 + &vma->vm_page_prot))
12276 + return -EINVAL;
12277 +
12278 ++#ifdef CONFIG_GRKERNSEC_KMEM
12279 ++ if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
12280 ++ return -EPERM;
12281 ++#endif
12282 ++
12283 + vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
12284 + size,
12285 + vma->vm_page_prot);
12286 +@@ -588,6 +603,11 @@ static ssize_t write_kmem(struct file *
12287 + ssize_t written;
12288 + char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
12289 +
12290 ++#ifdef CONFIG_GRKERNSEC_KMEM
12291 ++ gr_handle_kmem_write();
12292 ++ return -EPERM;
12293 ++#endif
12294 ++
12295 + if (p < (unsigned long) high_memory) {
12296 +
12297 + wrote = count;
12298 +@@ -791,6 +811,16 @@ static loff_t memory_lseek(struct file *
12299 +
12300 + static int open_port(struct inode * inode, struct file * filp)
12301 + {
12302 ++#ifdef CONFIG_GRKERNSEC_KMEM
12303 ++ gr_handle_open_port();
12304 ++ return -EPERM;
12305 ++#endif
12306 ++
12307 ++ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12308 ++}
12309 ++
12310 ++static int open_mem(struct inode * inode, struct file * filp)
12311 ++{
12312 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12313 + }
12314 +
12315 +@@ -798,7 +828,6 @@ static int open_port(struct inode * inod
12316 + #define full_lseek null_lseek
12317 + #define write_zero write_null
12318 + #define read_full read_zero
12319 +-#define open_mem open_port
12320 + #define open_kmem open_mem
12321 + #define open_oldmem open_mem
12322 +
12323 +@@ -938,6 +967,11 @@ static int memory_open(struct inode * in
12324 + filp->f_op = &oldmem_fops;
12325 + break;
12326 + #endif
12327 ++#ifdef CONFIG_GRKERNSEC
12328 ++ case 13:
12329 ++ filp->f_op = &grsec_fops;
12330 ++ break;
12331 ++#endif
12332 + default:
12333 + unlock_kernel();
12334 + return -ENXIO;
12335 +@@ -974,6 +1008,9 @@ static const struct {
12336 + #ifdef CONFIG_CRASH_DUMP
12337 + {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
12338 + #endif
12339 ++#ifdef CONFIG_GRKERNSEC
12340 ++ {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops},
12341 ++#endif
12342 + };
12343 +
12344 + static struct class *mem_class;
12345 +diff -urNp linux-2.6.27.10/drivers/char/nvram.c linux-2.6.27.10/drivers/char/nvram.c
12346 +--- linux-2.6.27.10/drivers/char/nvram.c 2008-11-07 12:55:34.000000000 -0500
12347 ++++ linux-2.6.27.10/drivers/char/nvram.c 2008-11-18 03:38:44.000000000 -0500
12348 +@@ -433,7 +433,10 @@ static const struct file_operations nvra
12349 + static struct miscdevice nvram_dev = {
12350 + NVRAM_MINOR,
12351 + "nvram",
12352 +- &nvram_fops
12353 ++ &nvram_fops,
12354 ++ {NULL, NULL},
12355 ++ NULL,
12356 ++ NULL
12357 + };
12358 +
12359 + static int __init
12360 +diff -urNp linux-2.6.27.10/drivers/char/random.c linux-2.6.27.10/drivers/char/random.c
12361 +--- linux-2.6.27.10/drivers/char/random.c 2008-11-07 12:55:34.000000000 -0500
12362 ++++ linux-2.6.27.10/drivers/char/random.c 2008-11-18 03:38:44.000000000 -0500
12363 +@@ -249,8 +249,13 @@
12364 + /*
12365 + * Configuration information
12366 + */
12367 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12368 ++#define INPUT_POOL_WORDS 512
12369 ++#define OUTPUT_POOL_WORDS 128
12370 ++#else
12371 + #define INPUT_POOL_WORDS 128
12372 + #define OUTPUT_POOL_WORDS 32
12373 ++#endif
12374 + #define SEC_XFER_SIZE 512
12375 +
12376 + /*
12377 +@@ -287,10 +292,17 @@ static struct poolinfo {
12378 + int poolwords;
12379 + int tap1, tap2, tap3, tap4, tap5;
12380 + } poolinfo_table[] = {
12381 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12382 ++ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
12383 ++ { 512, 411, 308, 208, 104, 1 },
12384 ++ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
12385 ++ { 128, 103, 76, 51, 25, 1 },
12386 ++#else
12387 + /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
12388 + { 128, 103, 76, 51, 25, 1 },
12389 + /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
12390 + { 32, 26, 20, 14, 7, 1 },
12391 ++#endif
12392 + #if 0
12393 + /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
12394 + { 2048, 1638, 1231, 819, 411, 1 },
12395 +@@ -1166,7 +1178,7 @@ EXPORT_SYMBOL(generate_random_uuid);
12396 + #include <linux/sysctl.h>
12397 +
12398 + static int min_read_thresh = 8, min_write_thresh;
12399 +-static int max_read_thresh = INPUT_POOL_WORDS * 32;
12400 ++static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
12401 + static int max_write_thresh = INPUT_POOL_WORDS * 32;
12402 + static char sysctl_bootid[16];
12403 +
12404 +diff -urNp linux-2.6.27.10/drivers/char/tpm/tpm.c linux-2.6.27.10/drivers/char/tpm/tpm.c
12405 +--- linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-07 12:55:34.000000000 -0500
12406 ++++ linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-18 03:38:44.000000000 -0500
12407 +@@ -1037,7 +1037,7 @@ ssize_t tpm_write(struct file *file, con
12408 +
12409 + mutex_lock(&chip->buffer_mutex);
12410 +
12411 +- if (in_size > TPM_BUFSIZE)
12412 ++ if (in_size > (unsigned int)TPM_BUFSIZE)
12413 + in_size = TPM_BUFSIZE;
12414 +
12415 + if (copy_from_user
12416 +diff -urNp linux-2.6.27.10/drivers/char/vt_ioctl.c linux-2.6.27.10/drivers/char/vt_ioctl.c
12417 +--- linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-07 12:55:34.000000000 -0500
12418 ++++ linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-18 03:38:44.000000000 -0500
12419 +@@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
12420 + case KDSKBENT:
12421 + if (!perm)
12422 + return -EPERM;
12423 ++
12424 ++#ifdef CONFIG_GRKERNSEC
12425 ++ if (!capable(CAP_SYS_TTY_CONFIG))
12426 ++ return -EPERM;
12427 ++#endif
12428 ++
12429 + if (!i && v == K_NOSUCHMAP) {
12430 + /* deallocate map */
12431 + key_map = key_maps[s];
12432 +@@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
12433 + goto reterr;
12434 + }
12435 +
12436 ++#ifdef CONFIG_GRKERNSEC
12437 ++ if (!capable(CAP_SYS_TTY_CONFIG)) {
12438 ++ ret = -EPERM;
12439 ++ goto reterr;
12440 ++ }
12441 ++#endif
12442 ++
12443 + q = func_table[i];
12444 + first_free = funcbufptr + (funcbufsize - funcbufleft);
12445 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
12446 +diff -urNp linux-2.6.27.10/drivers/edac/edac_core.h linux-2.6.27.10/drivers/edac/edac_core.h
12447 +--- linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-07 12:55:34.000000000 -0500
12448 ++++ linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-18 03:38:44.000000000 -0500
12449 +@@ -85,11 +85,11 @@ extern int edac_debug_level;
12450 +
12451 + #else /* !CONFIG_EDAC_DEBUG */
12452 +
12453 +-#define debugf0( ... )
12454 +-#define debugf1( ... )
12455 +-#define debugf2( ... )
12456 +-#define debugf3( ... )
12457 +-#define debugf4( ... )
12458 ++#define debugf0( ... ) do {} while (0)
12459 ++#define debugf1( ... ) do {} while (0)
12460 ++#define debugf2( ... ) do {} while (0)
12461 ++#define debugf3( ... ) do {} while (0)
12462 ++#define debugf4( ... ) do {} while (0)
12463 +
12464 + #endif /* !CONFIG_EDAC_DEBUG */
12465 +
12466 +diff -urNp linux-2.6.27.10/drivers/firmware/dmi_scan.c linux-2.6.27.10/drivers/firmware/dmi_scan.c
12467 +--- linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-07 12:55:34.000000000 -0500
12468 ++++ linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-18 03:38:44.000000000 -0500
12469 +@@ -384,11 +384,6 @@ void __init dmi_scan_machine(void)
12470 + }
12471 + }
12472 + else {
12473 +- /*
12474 +- * no iounmap() for that ioremap(); it would be a no-op, but
12475 +- * it's so early in setup that sucker gets confused into doing
12476 +- * what it shouldn't if we actually call it.
12477 +- */
12478 + p = dmi_ioremap(0xF0000, 0x10000);
12479 + if (p == NULL)
12480 + goto out;
12481 +diff -urNp linux-2.6.27.10/drivers/hwmon/fscpos.c linux-2.6.27.10/drivers/hwmon/fscpos.c
12482 +--- linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-07 12:55:34.000000000 -0500
12483 ++++ linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-18 03:38:44.000000000 -0500
12484 +@@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client
12485 + unsigned long v = simple_strtoul(buf, NULL, 10);
12486 +
12487 + /* Range: 0..255 */
12488 +- if (v < 0) v = 0;
12489 + if (v > 255) v = 255;
12490 +
12491 + mutex_lock(&data->update_lock);
12492 +diff -urNp linux-2.6.27.10/drivers/hwmon/k8temp.c linux-2.6.27.10/drivers/hwmon/k8temp.c
12493 +--- linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-07 12:55:34.000000000 -0500
12494 ++++ linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-18 03:38:44.000000000 -0500
12495 +@@ -130,7 +130,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
12496 +
12497 + static struct pci_device_id k8temp_ids[] = {
12498 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
12499 +- { 0 },
12500 ++ { 0, 0, 0, 0, 0, 0, 0 },
12501 + };
12502 +
12503 + MODULE_DEVICE_TABLE(pci, k8temp_ids);
12504 +diff -urNp linux-2.6.27.10/drivers/hwmon/sis5595.c linux-2.6.27.10/drivers/hwmon/sis5595.c
12505 +--- linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-07 12:55:34.000000000 -0500
12506 ++++ linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-18 03:38:44.000000000 -0500
12507 +@@ -698,7 +698,7 @@ static struct sis5595_data *sis5595_upda
12508 +
12509 + static struct pci_device_id sis5595_pci_ids[] = {
12510 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12511 +- { 0, }
12512 ++ { 0, 0, 0, 0, 0, 0, 0 }
12513 + };
12514 +
12515 + MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
12516 +diff -urNp linux-2.6.27.10/drivers/hwmon/via686a.c linux-2.6.27.10/drivers/hwmon/via686a.c
12517 +--- linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-07 12:55:34.000000000 -0500
12518 ++++ linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-18 03:38:44.000000000 -0500
12519 +@@ -768,7 +768,7 @@ static struct via686a_data *via686a_upda
12520 +
12521 + static struct pci_device_id via686a_pci_ids[] = {
12522 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
12523 +- { 0, }
12524 ++ { 0, 0, 0, 0, 0, 0, 0 }
12525 + };
12526 +
12527 + MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
12528 +diff -urNp linux-2.6.27.10/drivers/hwmon/vt8231.c linux-2.6.27.10/drivers/hwmon/vt8231.c
12529 +--- linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-07 12:55:34.000000000 -0500
12530 ++++ linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-18 03:38:44.000000000 -0500
12531 +@@ -698,7 +698,7 @@ static struct platform_driver vt8231_dri
12532 +
12533 + static struct pci_device_id vt8231_pci_ids[] = {
12534 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
12535 +- { 0, }
12536 ++ { 0, 0, 0, 0, 0, 0, 0 }
12537 + };
12538 +
12539 + MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
12540 +diff -urNp linux-2.6.27.10/drivers/hwmon/w83791d.c linux-2.6.27.10/drivers/hwmon/w83791d.c
12541 +--- linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-07 12:55:34.000000000 -0500
12542 ++++ linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-18 03:38:44.000000000 -0500
12543 +@@ -289,8 +289,8 @@ static int w83791d_detect(struct i2c_cli
12544 + struct i2c_board_info *info);
12545 + static int w83791d_remove(struct i2c_client *client);
12546 +
12547 +-static int w83791d_read(struct i2c_client *client, u8 register);
12548 +-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
12549 ++static int w83791d_read(struct i2c_client *client, u8 reg);
12550 ++static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
12551 + static struct w83791d_data *w83791d_update_device(struct device *dev);
12552 +
12553 + #ifdef DEBUG
12554 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c
12555 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-07 12:55:34.000000000 -0500
12556 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-18 03:38:44.000000000 -0500
12557 +@@ -576,7 +576,7 @@ static struct pci_device_id i801_ids[] =
12558 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
12559 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
12560 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
12561 +- { 0, }
12562 ++ { 0, 0, 0, 0, 0, 0, 0 }
12563 + };
12564 +
12565 + MODULE_DEVICE_TABLE (pci, i801_ids);
12566 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c
12567 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-07 12:55:34.000000000 -0500
12568 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-18 03:38:44.000000000 -0500
12569 +@@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat
12570 + .ident = "IBM",
12571 + .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
12572 + },
12573 +- { },
12574 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL },
12575 + };
12576 +
12577 + static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
12578 +@@ -424,7 +424,7 @@ static struct pci_device_id piix4_ids[]
12579 + PCI_DEVICE_ID_SERVERWORKS_CSB6) },
12580 + { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
12581 + PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
12582 +- { 0, }
12583 ++ { 0, 0, 0, 0, 0, 0, 0 }
12584 + };
12585 +
12586 + MODULE_DEVICE_TABLE (pci, piix4_ids);
12587 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c
12588 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-07 12:55:34.000000000 -0500
12589 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-18 03:38:44.000000000 -0500
12590 +@@ -472,7 +472,7 @@ static struct i2c_adapter sis630_adapter
12591 + static struct pci_device_id sis630_ids[] __devinitdata = {
12592 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12593 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
12594 +- { 0, }
12595 ++ { 0, 0, 0, 0, 0, 0, 0 }
12596 + };
12597 +
12598 + MODULE_DEVICE_TABLE (pci, sis630_ids);
12599 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c
12600 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-07 12:55:34.000000000 -0500
12601 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-18 03:38:44.000000000 -0500
12602 +@@ -248,7 +248,7 @@ static struct i2c_adapter sis96x_adapter
12603 +
12604 + static struct pci_device_id sis96x_ids[] = {
12605 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
12606 +- { 0, }
12607 ++ { 0, 0, 0, 0, 0, 0, 0 }
12608 + };
12609 +
12610 + MODULE_DEVICE_TABLE (pci, sis96x_ids);
12611 +diff -urNp linux-2.6.27.10/drivers/ieee1394/dv1394.c linux-2.6.27.10/drivers/ieee1394/dv1394.c
12612 +--- linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-07 12:55:34.000000000 -0500
12613 ++++ linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-18 03:38:44.000000000 -0500
12614 +@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
12615 + based upon DIF section and sequence
12616 + */
12617 +
12618 +-static void inline
12619 ++static inline void
12620 + frame_put_packet (struct frame *f, struct packet *p)
12621 + {
12622 + int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
12623 +@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_c
12624 + /* default SYT offset is 3 cycles */
12625 + init->syt_offset = 3;
12626 +
12627 +- if ( (init->channel > 63) || (init->channel < 0) )
12628 ++ if (init->channel > 63)
12629 + init->channel = 63;
12630 +
12631 + chan_mask = (u64)1 << init->channel;
12632 +@@ -2174,7 +2174,7 @@ static struct ieee1394_device_id dv1394_
12633 + .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
12634 + .version = AVC_SW_VERSION_ENTRY & 0xffffff
12635 + },
12636 +- { }
12637 ++ { 0, 0, 0, 0, 0, 0 }
12638 + };
12639 +
12640 + MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
12641 +diff -urNp linux-2.6.27.10/drivers/ieee1394/eth1394.c linux-2.6.27.10/drivers/ieee1394/eth1394.c
12642 +--- linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-07 12:55:34.000000000 -0500
12643 ++++ linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-18 03:38:44.000000000 -0500
12644 +@@ -451,7 +451,7 @@ static struct ieee1394_device_id eth1394
12645 + .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
12646 + .version = ETHER1394_GASP_VERSION,
12647 + },
12648 +- {}
12649 ++ { 0, 0, 0, 0, 0, 0 }
12650 + };
12651 +
12652 + MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
12653 +diff -urNp linux-2.6.27.10/drivers/ieee1394/hosts.c linux-2.6.27.10/drivers/ieee1394/hosts.c
12654 +--- linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-07 12:55:34.000000000 -0500
12655 ++++ linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-18 03:38:44.000000000 -0500
12656 +@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
12657 + }
12658 +
12659 + static struct hpsb_host_driver dummy_driver = {
12660 ++ .name = "dummy",
12661 + .transmit_packet = dummy_transmit_packet,
12662 + .devctl = dummy_devctl,
12663 + .isoctl = dummy_isoctl
12664 +diff -urNp linux-2.6.27.10/drivers/ieee1394/ohci1394.c linux-2.6.27.10/drivers/ieee1394/ohci1394.c
12665 +--- linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-07 12:55:34.000000000 -0500
12666 ++++ linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-18 03:38:44.000000000 -0500
12667 +@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
12668 + printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
12669 +
12670 + /* Module Parameters */
12671 +-static int phys_dma = 1;
12672 ++static int phys_dma;
12673 + module_param(phys_dma, int, 0444);
12674 +-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
12675 ++MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
12676 +
12677 + static void dma_trm_tasklet(unsigned long data);
12678 + static void dma_trm_reset(struct dma_trm_ctx *d);
12679 +@@ -3437,7 +3437,7 @@ static struct pci_device_id ohci1394_pci
12680 + .subvendor = PCI_ANY_ID,
12681 + .subdevice = PCI_ANY_ID,
12682 + },
12683 +- { 0, },
12684 ++ { 0, 0, 0, 0, 0, 0, 0 },
12685 + };
12686 +
12687 + MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl);
12688 +diff -urNp linux-2.6.27.10/drivers/ieee1394/raw1394.c linux-2.6.27.10/drivers/ieee1394/raw1394.c
12689 +--- linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-07 12:55:34.000000000 -0500
12690 ++++ linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-18 03:38:44.000000000 -0500
12691 +@@ -2968,7 +2968,7 @@ static struct ieee1394_device_id raw1394
12692 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12693 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12694 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
12695 +- {}
12696 ++ { 0, 0, 0, 0, 0, 0 }
12697 + };
12698 +
12699 + MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
12700 +diff -urNp linux-2.6.27.10/drivers/ieee1394/sbp2.c linux-2.6.27.10/drivers/ieee1394/sbp2.c
12701 +--- linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:37.000000000 -0500
12702 ++++ linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:46.000000000 -0500
12703 +@@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id
12704 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12705 + .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
12706 + .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
12707 +- {}
12708 ++ { 0, 0, 0, 0, 0, 0 }
12709 + };
12710 + MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
12711 +
12712 +@@ -2135,7 +2135,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
12713 + MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
12714 + MODULE_LICENSE("GPL");
12715 +
12716 +-static int sbp2_module_init(void)
12717 ++static int __init sbp2_module_init(void)
12718 + {
12719 + int ret;
12720 +
12721 +diff -urNp linux-2.6.27.10/drivers/ieee1394/video1394.c linux-2.6.27.10/drivers/ieee1394/video1394.c
12722 +--- linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-07 12:55:34.000000000 -0500
12723 ++++ linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-18 03:38:44.000000000 -0500
12724 +@@ -893,7 +893,7 @@ static long video1394_ioctl(struct file
12725 + if (unlikely(d == NULL))
12726 + return -EFAULT;
12727 +
12728 +- if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) {
12729 ++ if (unlikely(v.buffer>=d->num_desc - 1)) {
12730 + PRINT(KERN_ERR, ohci->host->id,
12731 + "Buffer %d out of range",v.buffer);
12732 + return -EINVAL;
12733 +@@ -959,7 +959,7 @@ static long video1394_ioctl(struct file
12734 + if (unlikely(d == NULL))
12735 + return -EFAULT;
12736 +
12737 +- if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) {
12738 ++ if (unlikely(v.buffer>d->num_desc - 1)) {
12739 + PRINT(KERN_ERR, ohci->host->id,
12740 + "Buffer %d out of range",v.buffer);
12741 + return -EINVAL;
12742 +@@ -1030,7 +1030,7 @@ static long video1394_ioctl(struct file
12743 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12744 + if (d == NULL) return -EFAULT;
12745 +
12746 +- if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
12747 ++ if (v.buffer>=d->num_desc - 1) {
12748 + PRINT(KERN_ERR, ohci->host->id,
12749 + "Buffer %d out of range",v.buffer);
12750 + return -EINVAL;
12751 +@@ -1137,7 +1137,7 @@ static long video1394_ioctl(struct file
12752 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12753 + if (d == NULL) return -EFAULT;
12754 +
12755 +- if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
12756 ++ if (v.buffer>=d->num_desc-1) {
12757 + PRINT(KERN_ERR, ohci->host->id,
12758 + "Buffer %d out of range",v.buffer);
12759 + return -EINVAL;
12760 +@@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13
12761 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12762 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
12763 + },
12764 +- { }
12765 ++ { 0, 0, 0, 0, 0, 0 }
12766 + };
12767 +
12768 + MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
12769 +diff -urNp linux-2.6.27.10/drivers/input/keyboard/atkbd.c linux-2.6.27.10/drivers/input/keyboard/atkbd.c
12770 +--- linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:37.000000000 -0500
12771 ++++ linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:46.000000000 -0500
12772 +@@ -1148,7 +1148,7 @@ static struct serio_device_id atkbd_seri
12773 + .id = SERIO_ANY,
12774 + .extra = SERIO_ANY,
12775 + },
12776 +- { 0 }
12777 ++ { 0, 0, 0, 0 }
12778 + };
12779 +
12780 + MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
12781 +diff -urNp linux-2.6.27.10/drivers/input/mouse/lifebook.c linux-2.6.27.10/drivers/input/mouse/lifebook.c
12782 +--- linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-07 12:55:34.000000000 -0500
12783 ++++ linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-18 03:38:44.000000000 -0500
12784 +@@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo
12785 + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
12786 + },
12787 + },
12788 +- { }
12789 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
12790 + };
12791 +
12792 + static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
12793 +diff -urNp linux-2.6.27.10/drivers/input/mouse/psmouse-base.c linux-2.6.27.10/drivers/input/mouse/psmouse-base.c
12794 +--- linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-07 12:55:34.000000000 -0500
12795 ++++ linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-18 03:38:44.000000000 -0500
12796 +@@ -1328,7 +1328,7 @@ static struct serio_device_id psmouse_se
12797 + .id = SERIO_ANY,
12798 + .extra = SERIO_ANY,
12799 + },
12800 +- { 0 }
12801 ++ { 0, 0, 0, 0 }
12802 + };
12803 +
12804 + MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
12805 +diff -urNp linux-2.6.27.10/drivers/input/mouse/synaptics.c linux-2.6.27.10/drivers/input/mouse/synaptics.c
12806 +--- linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-07 12:55:34.000000000 -0500
12807 ++++ linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-18 03:38:45.000000000 -0500
12808 +@@ -417,7 +417,7 @@ static void synaptics_process_packet(str
12809 + break;
12810 + case 2:
12811 + if (SYN_MODEL_PEN(priv->model_id))
12812 +- ; /* Nothing, treat a pen as a single finger */
12813 ++ break; /* Nothing, treat a pen as a single finger */
12814 + break;
12815 + case 4 ... 15:
12816 + if (SYN_CAP_PALMDETECT(priv->capabilities))
12817 +@@ -624,7 +624,7 @@ static const struct dmi_system_id toshib
12818 + DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
12819 + },
12820 + },
12821 +- { }
12822 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12823 + };
12824 + #endif
12825 +
12826 +diff -urNp linux-2.6.27.10/drivers/input/mousedev.c linux-2.6.27.10/drivers/input/mousedev.c
12827 +--- linux-2.6.27.10/drivers/input/mousedev.c 2008-11-07 12:55:34.000000000 -0500
12828 ++++ linux-2.6.27.10/drivers/input/mousedev.c 2008-11-18 03:38:45.000000000 -0500
12829 +@@ -1064,7 +1064,7 @@ static struct input_handler mousedev_han
12830 +
12831 + #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
12832 + static struct miscdevice psaux_mouse = {
12833 +- PSMOUSE_MINOR, "psaux", &mousedev_fops
12834 ++ PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
12835 + };
12836 + static int psaux_registered;
12837 + #endif
12838 +diff -urNp linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h
12839 +--- linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:51.000000000 -0500
12840 ++++ linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:00.000000000 -0500
12841 +@@ -143,7 +143,7 @@ static struct dmi_system_id __initdata i
12842 + DMI_MATCH(DMI_PRODUCT_VERSION, "M606"),
12843 + },
12844 + },
12845 +- { }
12846 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12847 + };
12848 +
12849 + /*
12850 +@@ -351,7 +351,7 @@ static struct dmi_system_id __initdata i
12851 + DMI_MATCH(DMI_PRODUCT_NAME, "HEL80I"),
12852 + },
12853 + },
12854 +- { }
12855 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12856 + };
12857 +
12858 + #ifdef CONFIG_PNP
12859 +@@ -363,7 +363,7 @@ static struct dmi_system_id __initdata i
12860 + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
12861 + },
12862 + },
12863 +- { }
12864 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12865 + };
12866 + #endif
12867 +
12868 +@@ -430,7 +430,7 @@ static struct dmi_system_id __initdata i
12869 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
12870 + },
12871 + },
12872 +- { }
12873 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12874 + };
12875 +
12876 + #endif /* CONFIG_X86 */
12877 +diff -urNp linux-2.6.27.10/drivers/input/serio/serio_raw.c linux-2.6.27.10/drivers/input/serio/serio_raw.c
12878 +--- linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-07 12:55:34.000000000 -0500
12879 ++++ linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-18 03:38:45.000000000 -0500
12880 +@@ -373,7 +373,7 @@ static struct serio_device_id serio_raw_
12881 + .id = SERIO_ANY,
12882 + .extra = SERIO_ANY,
12883 + },
12884 +- { 0 }
12885 ++ { 0, 0, 0, 0 }
12886 + };
12887 +
12888 + MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
12889 +diff -urNp linux-2.6.27.10/drivers/md/bitmap.c linux-2.6.27.10/drivers/md/bitmap.c
12890 +--- linux-2.6.27.10/drivers/md/bitmap.c 2008-11-07 12:55:34.000000000 -0500
12891 ++++ linux-2.6.27.10/drivers/md/bitmap.c 2008-11-18 03:38:45.000000000 -0500
12892 +@@ -57,7 +57,7 @@
12893 + # if DEBUG > 0
12894 + # define PRINTK(x...) printk(KERN_DEBUG x)
12895 + # else
12896 +-# define PRINTK(x...)
12897 ++# define PRINTK(x...) do {} while (0)
12898 + # endif
12899 + #endif
12900 +
12901 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2000.c linux-2.6.27.10/drivers/mtd/devices/doc2000.c
12902 +--- linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-07 12:55:34.000000000 -0500
12903 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-18 03:38:45.000000000 -0500
12904 +@@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt
12905 +
12906 + /* The ECC will not be calculated correctly if less than 512 is written */
12907 + /* DBB-
12908 +- if (len != 0x200 && eccbuf)
12909 ++ if (len != 0x200)
12910 + printk(KERN_WARNING
12911 + "ECC needs a full sector write (adr: %lx size %lx)\n",
12912 + (long) to, (long) len);
12913 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2001.c linux-2.6.27.10/drivers/mtd/devices/doc2001.c
12914 +--- linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-07 12:55:34.000000000 -0500
12915 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-18 03:38:45.000000000 -0500
12916 +@@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt
12917 + /* Don't allow read past end of device */
12918 + if (from >= this->totlen)
12919 + return -EINVAL;
12920 ++ if (!len)
12921 ++ return -EINVAL;
12922 +
12923 + /* Don't allow a single read to cross a 512-byte block boundary */
12924 + if (from + len > ((from | 0x1ff) + 1))
12925 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/slram.c linux-2.6.27.10/drivers/mtd/devices/slram.c
12926 +--- linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-07 12:55:34.000000000 -0500
12927 ++++ linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-18 03:38:45.000000000 -0500
12928 +@@ -273,7 +273,7 @@ static int parse_cmdline(char *devname,
12929 + }
12930 + T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
12931 + devname, devstart, devlength);
12932 +- if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
12933 ++ if (devlength % SLRAM_BLK_SZ != 0) {
12934 + E("slram: Illegal start / length parameter.\n");
12935 + return(-EINVAL);
12936 + }
12937 +diff -urNp linux-2.6.27.10/drivers/mtd/ubi/build.c linux-2.6.27.10/drivers/mtd/ubi/build.c
12938 +--- linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-07 12:55:34.000000000 -0500
12939 ++++ linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-18 03:38:45.000000000 -0500
12940 +@@ -1104,7 +1104,7 @@ static int __init bytes_str_to_int(const
12941 + unsigned long result;
12942 +
12943 + result = simple_strtoul(str, &endp, 0);
12944 +- if (str == endp || result < 0) {
12945 ++ if (str == endp) {
12946 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
12947 + str);
12948 + return -EINVAL;
12949 +diff -urNp linux-2.6.27.10/drivers/net/eepro100.c linux-2.6.27.10/drivers/net/eepro100.c
12950 +--- linux-2.6.27.10/drivers/net/eepro100.c 2008-11-07 12:55:34.000000000 -0500
12951 ++++ linux-2.6.27.10/drivers/net/eepro100.c 2008-11-18 03:38:45.000000000 -0500
12952 +@@ -47,7 +47,7 @@ static int rxdmacount /* = 0 */;
12953 + # define rx_align(skb) skb_reserve((skb), 2)
12954 + # define RxFD_ALIGNMENT __attribute__ ((aligned (2), packed))
12955 + #else
12956 +-# define rx_align(skb)
12957 ++# define rx_align(skb) do {} while (0)
12958 + # define RxFD_ALIGNMENT
12959 + #endif
12960 +
12961 +@@ -2334,33 +2334,33 @@ static void __devexit eepro100_remove_on
12962 + }
12963 +
12964 + static struct pci_device_id eepro100_pci_tbl[] = {
12965 +- { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, },
12966 +- { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, },
12967 +- { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, },
12968 +- { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, },
12969 +- { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, },
12970 +- { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, },
12971 +- { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, },
12972 +- { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, },
12973 +- { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, },
12974 +- { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, },
12975 +- { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, },
12976 +- { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, },
12977 +- { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, },
12978 +- { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, },
12979 +- { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, },
12980 +- { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, },
12981 +- { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, },
12982 +- { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, },
12983 +- { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, },
12984 +- { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, },
12985 +- { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, },
12986 +- { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, },
12987 +- { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, },
12988 +- { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, },
12989 +- { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, },
12990 +- { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, },
12991 +- { 0,}
12992 ++ { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12993 ++ { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12994 ++ { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12995 ++ { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12996 ++ { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12997 ++ { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12998 ++ { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12999 ++ { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13000 ++ { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13001 ++ { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13002 ++ { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13003 ++ { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13004 ++ { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13005 ++ { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13006 ++ { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13007 ++ { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13008 ++ { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13009 ++ { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13010 ++ { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13011 ++ { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13012 ++ { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13013 ++ { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13014 ++ { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13015 ++ { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13016 ++ { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13017 ++ { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13018 ++ { 0, 0, 0, 0, 0, 0, 0 }
13019 + };
13020 + MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
13021 +
13022 +diff -urNp linux-2.6.27.10/drivers/net/irda/vlsi_ir.c linux-2.6.27.10/drivers/net/irda/vlsi_ir.c
13023 +--- linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-07 12:55:34.000000000 -0500
13024 ++++ linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-18 03:38:45.000000000 -0500
13025 +@@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s
13026 + /* no race - tx-ring already empty */
13027 + vlsi_set_baud(idev, iobase);
13028 + netif_wake_queue(ndev);
13029 +- }
13030 +- else
13031 +- ;
13032 ++ } else {
13033 + /* keep the speed change pending like it would
13034 + * for any len>0 packet. tx completion interrupt
13035 + * will apply it when the tx ring becomes empty.
13036 + */
13037 ++ }
13038 + spin_unlock_irqrestore(&idev->lock, flags);
13039 + dev_kfree_skb_any(skb);
13040 + return 0;
13041 +diff -urNp linux-2.6.27.10/drivers/net/pcnet32.c linux-2.6.27.10/drivers/net/pcnet32.c
13042 +--- linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-07 12:55:34.000000000 -0500
13043 ++++ linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-18 03:38:45.000000000 -0500
13044 +@@ -78,7 +78,7 @@ static int cards_found;
13045 + /*
13046 + * VLB I/O addresses
13047 + */
13048 +-static unsigned int pcnet32_portlist[] __initdata =
13049 ++static unsigned int pcnet32_portlist[] __devinitdata =
13050 + { 0x300, 0x320, 0x340, 0x360, 0 };
13051 +
13052 + static int pcnet32_debug = 0;
13053 +diff -urNp linux-2.6.27.10/drivers/net/tg3.h linux-2.6.27.10/drivers/net/tg3.h
13054 +--- linux-2.6.27.10/drivers/net/tg3.h 2008-11-07 12:55:34.000000000 -0500
13055 ++++ linux-2.6.27.10/drivers/net/tg3.h 2008-11-18 03:38:45.000000000 -0500
13056 +@@ -102,6 +102,7 @@
13057 + #define CHIPREV_ID_5750_A0 0x4000
13058 + #define CHIPREV_ID_5750_A1 0x4001
13059 + #define CHIPREV_ID_5750_A3 0x4003
13060 ++#define CHIPREV_ID_5750_C1 0x4201
13061 + #define CHIPREV_ID_5750_C2 0x4202
13062 + #define CHIPREV_ID_5752_A0_HW 0x5000
13063 + #define CHIPREV_ID_5752_A0 0x6000
13064 +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
13065 +--- linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-11-17 20:03:30.000000000 -0500
13066 ++++ linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-12-27 13:44:22.000000000 -0500
13067 +@@ -785,7 +785,7 @@ static int iwl3945_send_cmd_sync(struct
13068 + IWL_ERROR("Error: Response NULL in '%s'\n",
13069 + get_cmd_string(cmd->id));
13070 + ret = -EIO;
13071 +- goto out;
13072 ++ goto cancel;
13073 + }
13074 +
13075 + ret = 0;
13076 +diff -urNp linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c
13077 +--- linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-07 12:55:34.000000000 -0500
13078 ++++ linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-18 03:38:45.000000000 -0500
13079 +@@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_
13080 +
13081 + void compaq_nvram_init (void __iomem *rom_start)
13082 + {
13083 ++
13084 ++#ifndef CONFIG_PAX_KERNEXEC
13085 + if (rom_start) {
13086 + compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
13087 + }
13088 ++#endif
13089 ++
13090 + dbg("int15 entry = %p\n", compaq_int15_entry_point);
13091 +
13092 + /* initialize our int15 lock */
13093 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c
13094 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-07 12:55:34.000000000 -0500
13095 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-18 03:38:45.000000000 -0500
13096 +@@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i
13097 + .port_type = PCIE_RC_PORT,
13098 + .service_type = PCIE_PORT_SERVICE_AER,
13099 + },
13100 +- { /* end: all zeroes */ }
13101 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13102 + };
13103 +
13104 + static struct pci_error_handlers aer_error_handlers = {
13105 +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
13106 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-07 12:55:34.000000000 -0500
13107 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-18 03:38:45.000000000 -0500
13108 +@@ -663,7 +663,7 @@ static void aer_isr_one_error(struct pci
13109 + struct aer_err_source *e_src)
13110 + {
13111 + struct device *s_device;
13112 +- struct aer_err_info e_info = {0, 0, 0,};
13113 ++ struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}};
13114 + int i;
13115 + u16 id;
13116 +
13117 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c
13118 +--- linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-07 12:55:34.000000000 -0500
13119 ++++ linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-18 03:38:45.000000000 -0500
13120 +@@ -264,7 +264,7 @@ static void pcie_portdrv_err_resume(stru
13121 + static const struct pci_device_id port_pci_ids[] = { {
13122 + /* handle any PCI-Express port */
13123 + PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
13124 +- }, { /* end: all zeroes */ }
13125 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13126 + };
13127 + MODULE_DEVICE_TABLE(pci, port_pci_ids);
13128 +
13129 +diff -urNp linux-2.6.27.10/drivers/pci/proc.c linux-2.6.27.10/drivers/pci/proc.c
13130 +--- linux-2.6.27.10/drivers/pci/proc.c 2008-11-07 12:55:34.000000000 -0500
13131 ++++ linux-2.6.27.10/drivers/pci/proc.c 2008-11-18 03:38:45.000000000 -0500
13132 +@@ -470,7 +470,16 @@ static const struct file_operations proc
13133 + static int __init pci_proc_init(void)
13134 + {
13135 + struct pci_dev *dev = NULL;
13136 ++
13137 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
13138 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
13139 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
13140 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
13141 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
13142 ++#endif
13143 ++#else
13144 + proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
13145 ++#endif
13146 + proc_create("devices", 0, proc_bus_pci_dir,
13147 + &proc_bus_pci_dev_operations);
13148 + proc_initialized = 1;
13149 +diff -urNp linux-2.6.27.10/drivers/pcmcia/ti113x.h linux-2.6.27.10/drivers/pcmcia/ti113x.h
13150 +--- linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-07 12:55:34.000000000 -0500
13151 ++++ linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-18 03:38:45.000000000 -0500
13152 +@@ -897,7 +897,7 @@ static struct pci_device_id ene_tune_tbl
13153 + DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
13154 + ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
13155 +
13156 +- {}
13157 ++ { 0, 0, 0, 0, 0, 0, 0 }
13158 + };
13159 +
13160 + static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
13161 +diff -urNp linux-2.6.27.10/drivers/pcmcia/yenta_socket.c linux-2.6.27.10/drivers/pcmcia/yenta_socket.c
13162 +--- linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-07 12:55:34.000000000 -0500
13163 ++++ linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-18 03:38:45.000000000 -0500
13164 +@@ -1358,7 +1358,7 @@ static struct pci_device_id yenta_table
13165 +
13166 + /* match any cardbus bridge */
13167 + CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
13168 +- { /* all zeroes */ }
13169 ++ { 0, 0, 0, 0, 0, 0, 0 }
13170 + };
13171 + MODULE_DEVICE_TABLE(pci, yenta_table);
13172 +
13173 +diff -urNp linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c
13174 +--- linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-07 12:55:34.000000000 -0500
13175 ++++ linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-18 03:38:45.000000000 -0500
13176 +@@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr
13177 + set_limit(gdt[(selname) >> 3], size); \
13178 + } while(0)
13179 +
13180 +-static struct desc_struct bad_bios_desc;
13181 ++static struct desc_struct bad_bios_desc __read_only;
13182 +
13183 + /*
13184 + * At some point we want to use this stack frame pointer to unwind
13185 +@@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func
13186 + struct desc_struct save_desc_40;
13187 + int cpu;
13188 +
13189 ++#ifdef CONFIG_PAX_KERNEXEC
13190 ++ unsigned long cr0;
13191 ++#endif
13192 ++
13193 + /*
13194 + * PnP BIOSes are generally not terribly re-entrant.
13195 + * Also, don't rely on them to save everything correctly.
13196 +@@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func
13197 +
13198 + cpu = get_cpu();
13199 + save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
13200 ++
13201 ++#ifdef CONFIG_PAX_KERNEXEC
13202 ++ pax_open_kernel(cr0);
13203 ++#endif
13204 ++
13205 + get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
13206 +
13207 ++#ifdef CONFIG_PAX_KERNEXEC
13208 ++ pax_close_kernel(cr0);
13209 ++#endif
13210 ++
13211 + /* On some boxes IRQ's during PnP BIOS calls are deadly. */
13212 + spin_lock_irqsave(&pnp_bios_lock, flags);
13213 +
13214 +@@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func
13215 + :"memory");
13216 + spin_unlock_irqrestore(&pnp_bios_lock, flags);
13217 +
13218 ++#ifdef CONFIG_PAX_KERNEXEC
13219 ++ pax_open_kernel(cr0);
13220 ++#endif
13221 ++
13222 + get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
13223 ++
13224 ++#ifdef CONFIG_PAX_KERNEXEC
13225 ++ pax_close_kernel(cr0);
13226 ++#endif
13227 ++
13228 + put_cpu();
13229 +
13230 + /* If we get here and this is set then the PnP BIOS faulted on us. */
13231 +@@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n
13232 + return status;
13233 + }
13234 +
13235 +-void pnpbios_calls_init(union pnp_bios_install_struct *header)
13236 ++void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
13237 + {
13238 + int i;
13239 +
13240 ++#ifdef CONFIG_PAX_KERNEXEC
13241 ++ unsigned long cr0;
13242 ++#endif
13243 ++
13244 + spin_lock_init(&pnp_bios_lock);
13245 + pnp_bios_callpoint.offset = header->fields.pm16offset;
13246 + pnp_bios_callpoint.segment = PNP_CS16;
13247 +
13248 ++#ifdef CONFIG_PAX_KERNEXEC
13249 ++ pax_open_kernel(cr0);
13250 ++#endif
13251 ++
13252 + bad_bios_desc.a = 0;
13253 +- bad_bios_desc.b = 0x00409200;
13254 ++ bad_bios_desc.b = 0x00409300;
13255 +
13256 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
13257 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
13258 +@@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i
13259 + set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
13260 + __va(header->fields.pm16dseg));
13261 + }
13262 ++
13263 ++#ifdef CONFIG_PAX_KERNEXEC
13264 ++ pax_close_kernel(cr0);
13265 ++#endif
13266 ++
13267 + }
13268 +diff -urNp linux-2.6.27.10/drivers/pnp/quirks.c linux-2.6.27.10/drivers/pnp/quirks.c
13269 +--- linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:16:51.000000000 -0500
13270 ++++ linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:13:46.000000000 -0500
13271 +@@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = {
13272 + /* PnP resources that might overlap PCI BARs */
13273 + {"PNP0c01", quirk_system_pci_resources},
13274 + {"PNP0c02", quirk_system_pci_resources},
13275 +- {""}
13276 ++ {"", NULL}
13277 + };
13278 +
13279 + void pnp_fixup_device(struct pnp_dev *dev)
13280 +diff -urNp linux-2.6.27.10/drivers/pnp/resource.c linux-2.6.27.10/drivers/pnp/resource.c
13281 +--- linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:16:51.000000000 -0500
13282 ++++ linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:13:46.000000000 -0500
13283 +@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
13284 + return 1;
13285 +
13286 + /* check if the resource is valid */
13287 +- if (*irq < 0 || *irq > 15)
13288 ++ if (*irq > 15)
13289 + return 0;
13290 +
13291 + /* check if the resource is reserved */
13292 +@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
13293 + return 1;
13294 +
13295 + /* check if the resource is valid */
13296 +- if (*dma < 0 || *dma == 4 || *dma > 7)
13297 ++ if (*dma == 4 || *dma > 7)
13298 + return 0;
13299 +
13300 + /* check if the resource is reserved */
13301 +diff -urNp linux-2.6.27.10/drivers/scsi/scsi_logging.h linux-2.6.27.10/drivers/scsi/scsi_logging.h
13302 +--- linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-07 12:55:34.000000000 -0500
13303 ++++ linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-18 03:38:45.000000000 -0500
13304 +@@ -51,7 +51,7 @@ do { \
13305 + } while (0); \
13306 + } while (0)
13307 + #else
13308 +-#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
13309 ++#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
13310 + #endif /* CONFIG_SCSI_LOGGING */
13311 +
13312 + /*
13313 +diff -urNp linux-2.6.27.10/drivers/serial/8250_pci.c linux-2.6.27.10/drivers/serial/8250_pci.c
13314 +--- linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-07 12:55:34.000000000 -0500
13315 ++++ linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-18 03:38:45.000000000 -0500
13316 +@@ -2859,7 +2859,7 @@ static struct pci_device_id serial_pci_t
13317 + PCI_ANY_ID, PCI_ANY_ID,
13318 + PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
13319 + 0xffff00, pbn_default },
13320 +- { 0, }
13321 ++ { 0, 0, 0, 0, 0, 0, 0 }
13322 + };
13323 +
13324 + static struct pci_driver serial_pci_driver = {
13325 +diff -urNp linux-2.6.27.10/drivers/usb/class/cdc-acm.c linux-2.6.27.10/drivers/usb/class/cdc-acm.c
13326 +--- linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:38:40.000000000 -0500
13327 ++++ linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:40:52.000000000 -0500
13328 +@@ -1381,7 +1381,7 @@ static struct usb_device_id acm_ids[] =
13329 + USB_CDC_ACM_PROTO_AT_CDMA) },
13330 +
13331 + /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
13332 +- { }
13333 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13334 + };
13335 +
13336 + MODULE_DEVICE_TABLE (usb, acm_ids);
13337 +diff -urNp linux-2.6.27.10/drivers/usb/class/usblp.c linux-2.6.27.10/drivers/usb/class/usblp.c
13338 +--- linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-07 12:55:34.000000000 -0500
13339 ++++ linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-18 03:38:45.000000000 -0500
13340 +@@ -227,7 +227,7 @@ static const struct quirk_printer_struct
13341 + { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
13342 + { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@×××.de> */
13343 + { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
13344 +- { 0, 0 }
13345 ++ { 0, 0, 0 }
13346 + };
13347 +
13348 + static int usblp_wwait(struct usblp *usblp, int nonblock);
13349 +@@ -1401,7 +1401,7 @@ static struct usb_device_id usblp_ids []
13350 + { USB_INTERFACE_INFO(7, 1, 2) },
13351 + { USB_INTERFACE_INFO(7, 1, 3) },
13352 + { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
13353 +- { } /* Terminating entry */
13354 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13355 + };
13356 +
13357 + MODULE_DEVICE_TABLE (usb, usblp_ids);
13358 +diff -urNp linux-2.6.27.10/drivers/usb/core/hub.c linux-2.6.27.10/drivers/usb/core/hub.c
13359 +--- linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-07 12:55:34.000000000 -0500
13360 ++++ linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-18 03:38:45.000000000 -0500
13361 +@@ -3111,7 +3111,7 @@ static struct usb_device_id hub_id_table
13362 + .bDeviceClass = USB_CLASS_HUB},
13363 + { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
13364 + .bInterfaceClass = USB_CLASS_HUB},
13365 +- { } /* Terminating entry */
13366 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13367 + };
13368 +
13369 + MODULE_DEVICE_TABLE (usb, hub_id_table);
13370 +diff -urNp linux-2.6.27.10/drivers/usb/host/ehci-pci.c linux-2.6.27.10/drivers/usb/host/ehci-pci.c
13371 +--- linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:37.000000000 -0500
13372 ++++ linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:46.000000000 -0500
13373 +@@ -414,7 +414,7 @@ static const struct pci_device_id pci_id
13374 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
13375 + .driver_data = (unsigned long) &ehci_pci_hc_driver,
13376 + },
13377 +- { /* end: all zeroes */ }
13378 ++ { 0, 0, 0, 0, 0, 0, 0 }
13379 + };
13380 + MODULE_DEVICE_TABLE(pci, pci_ids);
13381 +
13382 +diff -urNp linux-2.6.27.10/drivers/usb/host/uhci-hcd.c linux-2.6.27.10/drivers/usb/host/uhci-hcd.c
13383 +--- linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-07 12:55:34.000000000 -0500
13384 ++++ linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-18 03:38:45.000000000 -0500
13385 +@@ -928,7 +928,7 @@ static const struct pci_device_id uhci_p
13386 + /* handle any USB UHCI controller */
13387 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
13388 + .driver_data = (unsigned long) &uhci_driver,
13389 +- }, { /* end: all zeroes */ }
13390 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13391 + };
13392 +
13393 + MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
13394 +diff -urNp linux-2.6.27.10/drivers/usb/storage/debug.h linux-2.6.27.10/drivers/usb/storage/debug.h
13395 +--- linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-07 12:55:34.000000000 -0500
13396 ++++ linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-18 03:38:45.000000000 -0500
13397 +@@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
13398 + #define US_DEBUGPX(x...) printk( x )
13399 + #define US_DEBUG(x) x
13400 + #else
13401 +-#define US_DEBUGP(x...)
13402 +-#define US_DEBUGPX(x...)
13403 +-#define US_DEBUG(x)
13404 ++#define US_DEBUGP(x...) do {} while (0)
13405 ++#define US_DEBUGPX(x...) do {} while (0)
13406 ++#define US_DEBUG(x) do {} while (0)
13407 + #endif
13408 +
13409 + #endif
13410 +diff -urNp linux-2.6.27.10/drivers/usb/storage/usb.c linux-2.6.27.10/drivers/usb/storage/usb.c
13411 +--- linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-07 12:55:34.000000000 -0500
13412 ++++ linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-18 03:38:45.000000000 -0500
13413 +@@ -136,7 +136,7 @@ static struct usb_device_id storage_usb_
13414 + #undef UNUSUAL_DEV
13415 + #undef USUAL_DEV
13416 + /* Terminating entry */
13417 +- { }
13418 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13419 + };
13420 +
13421 + MODULE_DEVICE_TABLE (usb, storage_usb_ids);
13422 +@@ -176,7 +176,7 @@ static struct us_unusual_dev us_unusual_
13423 + # undef USUAL_DEV
13424 +
13425 + /* Terminating entry */
13426 +- { NULL }
13427 ++ { NULL, NULL, 0, 0, NULL }
13428 + };
13429 +
13430 +
13431 +diff -urNp linux-2.6.27.10/drivers/video/fbcmap.c linux-2.6.27.10/drivers/video/fbcmap.c
13432 +--- linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-07 12:55:34.000000000 -0500
13433 ++++ linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-18 03:38:45.000000000 -0500
13434 +@@ -250,8 +250,7 @@ int fb_set_user_cmap(struct fb_cmap_user
13435 + int rc, size = cmap->len * sizeof(u16);
13436 + struct fb_cmap umap;
13437 +
13438 +- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
13439 +- !info->fbops->fb_setcmap))
13440 ++ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap)
13441 + return -EINVAL;
13442 +
13443 + memset(&umap, 0, sizeof(struct fb_cmap));
13444 +diff -urNp linux-2.6.27.10/drivers/video/fbmem.c linux-2.6.27.10/drivers/video/fbmem.c
13445 +--- linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:37.000000000 -0500
13446 ++++ linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:46.000000000 -0500
13447 +@@ -395,7 +395,7 @@ static void fb_do_show_logo(struct fb_in
13448 + image->dx += image->width + 8;
13449 + }
13450 + } else if (rotate == FB_ROTATE_UD) {
13451 +- for (x = 0; x < num && image->dx >= 0; x++) {
13452 ++ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
13453 + info->fbops->fb_imageblit(info, image);
13454 + image->dx -= image->width + 8;
13455 + }
13456 +@@ -407,7 +407,7 @@ static void fb_do_show_logo(struct fb_in
13457 + image->dy += image->height + 8;
13458 + }
13459 + } else if (rotate == FB_ROTATE_CCW) {
13460 +- for (x = 0; x < num && image->dy >= 0; x++) {
13461 ++ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
13462 + info->fbops->fb_imageblit(info, image);
13463 + image->dy -= image->height + 8;
13464 + }
13465 +@@ -1083,7 +1083,7 @@ fb_ioctl(struct inode *inode, struct fil
13466 + return - EFAULT;
13467 + if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
13468 + return -EINVAL;
13469 +- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
13470 ++ if (con2fb.framebuffer >= FB_MAX)
13471 + return -EINVAL;
13472 + #ifdef CONFIG_KMOD
13473 + if (!registered_fb[con2fb.framebuffer])
13474 +diff -urNp linux-2.6.27.10/drivers/video/fbmon.c linux-2.6.27.10/drivers/video/fbmon.c
13475 +--- linux-2.6.27.10/drivers/video/fbmon.c 2008-11-07 12:55:34.000000000 -0500
13476 ++++ linux-2.6.27.10/drivers/video/fbmon.c 2008-11-18 03:38:45.000000000 -0500
13477 +@@ -45,7 +45,7 @@
13478 + #ifdef DEBUG
13479 + #define DPRINTK(fmt, args...) printk(fmt,## args)
13480 + #else
13481 +-#define DPRINTK(fmt, args...)
13482 ++#define DPRINTK(fmt, args...) do {} while (0)
13483 + #endif
13484 +
13485 + #define FBMON_FIX_HEADER 1
13486 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_accel.c linux-2.6.27.10/drivers/video/i810/i810_accel.c
13487 +--- linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-07 12:55:34.000000000 -0500
13488 ++++ linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-18 03:38:45.000000000 -0500
13489 +@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
13490 + }
13491 + }
13492 + printk("ringbuffer lockup!!!\n");
13493 ++ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
13494 + i810_report_error(mmio);
13495 + par->dev_flags |= LOCKUP;
13496 + info->pixmap.scan_align = 1;
13497 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_main.c linux-2.6.27.10/drivers/video/i810/i810_main.c
13498 +--- linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-07 12:55:34.000000000 -0500
13499 ++++ linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-18 03:38:45.000000000 -0500
13500 +@@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
13501 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
13502 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
13503 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
13504 +- { 0 },
13505 ++ { 0, 0, 0, 0, 0, 0, 0 },
13506 + };
13507 +
13508 + static struct pci_driver i810fb_driver = {
13509 +@@ -1509,7 +1509,7 @@ static int i810fb_cursor(struct fb_info
13510 + int size = ((cursor->image.width + 7) >> 3) *
13511 + cursor->image.height;
13512 + int i;
13513 +- u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
13514 ++ u8 *data = kmalloc(64 * 8, GFP_KERNEL);
13515 +
13516 + if (data == NULL)
13517 + return -ENOMEM;
13518 +diff -urNp linux-2.6.27.10/drivers/video/modedb.c linux-2.6.27.10/drivers/video/modedb.c
13519 +--- linux-2.6.27.10/drivers/video/modedb.c 2008-11-07 12:55:34.000000000 -0500
13520 ++++ linux-2.6.27.10/drivers/video/modedb.c 2008-11-18 03:38:45.000000000 -0500
13521 +@@ -38,232 +38,232 @@ static const struct fb_videomode modedb[
13522 + {
13523 + /* 640x400 @ 70 Hz, 31.5 kHz hsync */
13524 + NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
13525 +- 0, FB_VMODE_NONINTERLACED
13526 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13527 + }, {
13528 + /* 640x480 @ 60 Hz, 31.5 kHz hsync */
13529 + NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
13530 +- 0, FB_VMODE_NONINTERLACED
13531 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13532 + }, {
13533 + /* 800x600 @ 56 Hz, 35.15 kHz hsync */
13534 + NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
13535 +- 0, FB_VMODE_NONINTERLACED
13536 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13537 + }, {
13538 + /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
13539 + NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
13540 +- 0, FB_VMODE_INTERLACED
13541 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13542 + }, {
13543 + /* 640x400 @ 85 Hz, 37.86 kHz hsync */
13544 + NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
13545 +- FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13546 ++ FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13547 + }, {
13548 + /* 640x480 @ 72 Hz, 36.5 kHz hsync */
13549 + NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
13550 +- 0, FB_VMODE_NONINTERLACED
13551 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13552 + }, {
13553 + /* 640x480 @ 75 Hz, 37.50 kHz hsync */
13554 + NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
13555 +- 0, FB_VMODE_NONINTERLACED
13556 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13557 + }, {
13558 + /* 800x600 @ 60 Hz, 37.8 kHz hsync */
13559 + NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
13560 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13561 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13562 + }, {
13563 + /* 640x480 @ 85 Hz, 43.27 kHz hsync */
13564 + NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
13565 +- 0, FB_VMODE_NONINTERLACED
13566 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13567 + }, {
13568 + /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
13569 + NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
13570 +- 0, FB_VMODE_INTERLACED
13571 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13572 + }, {
13573 + /* 800x600 @ 72 Hz, 48.0 kHz hsync */
13574 + NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
13575 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13576 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13577 + }, {
13578 + /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
13579 + NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
13580 +- 0, FB_VMODE_NONINTERLACED
13581 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13582 + }, {
13583 + /* 640x480 @ 100 Hz, 53.01 kHz hsync */
13584 + NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
13585 +- 0, FB_VMODE_NONINTERLACED
13586 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13587 + }, {
13588 + /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
13589 + NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
13590 +- 0, FB_VMODE_NONINTERLACED
13591 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13592 + }, {
13593 + /* 800x600 @ 85 Hz, 55.84 kHz hsync */
13594 + NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
13595 +- 0, FB_VMODE_NONINTERLACED
13596 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13597 + }, {
13598 + /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
13599 + NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
13600 +- 0, FB_VMODE_NONINTERLACED
13601 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13602 + }, {
13603 + /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
13604 + NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
13605 +- 0, FB_VMODE_INTERLACED
13606 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13607 + }, {
13608 + /* 800x600 @ 100 Hz, 64.02 kHz hsync */
13609 + NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
13610 +- 0, FB_VMODE_NONINTERLACED
13611 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13612 + }, {
13613 + /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
13614 + NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
13615 +- 0, FB_VMODE_NONINTERLACED
13616 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13617 + }, {
13618 + /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
13619 + NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
13620 +- 0, FB_VMODE_NONINTERLACED
13621 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13622 + }, {
13623 + /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
13624 + NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
13625 +- 0, FB_VMODE_NONINTERLACED
13626 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13627 + }, {
13628 + /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
13629 + NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
13630 +- 0, FB_VMODE_NONINTERLACED
13631 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13632 + }, {
13633 + /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
13634 + NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
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 + /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
13639 + NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
13640 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13641 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13642 + }, {
13643 + /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
13644 + NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
13645 +- 0, FB_VMODE_NONINTERLACED
13646 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13647 + }, {
13648 + /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
13649 + NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
13650 +- 0, FB_VMODE_NONINTERLACED
13651 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13652 + }, {
13653 + /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
13654 + NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
13655 +- 0, FB_VMODE_NONINTERLACED
13656 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13657 + }, {
13658 + /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
13659 + NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
13660 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13661 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13662 + }, {
13663 + /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
13664 + NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
13665 +- 0, FB_VMODE_NONINTERLACED
13666 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13667 + }, {
13668 + /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
13669 + NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
13670 +- 0, FB_VMODE_NONINTERLACED
13671 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13672 + }, {
13673 + /* 1024x768 @ 100Hz, 80.21 kHz hsync */
13674 + NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
13675 +- 0, FB_VMODE_NONINTERLACED
13676 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13677 + }, {
13678 + /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
13679 + NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
13680 +- 0, FB_VMODE_NONINTERLACED
13681 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13682 + }, {
13683 + /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
13684 + NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
13685 +- 0, FB_VMODE_NONINTERLACED
13686 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13687 + }, {
13688 + /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
13689 + NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
13690 +- 0, FB_VMODE_NONINTERLACED
13691 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13692 + }, {
13693 + /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
13694 + NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 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 + /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
13699 + NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
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 + /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
13704 + NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
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 + /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
13709 + NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
13710 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13711 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13712 + }, {
13713 + /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
13714 + NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
13715 +- 0, FB_VMODE_NONINTERLACED
13716 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13717 + }, {
13718 + /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
13719 + NULL, 64, 1800, 1440, 4347, 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 + /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
13724 + NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
13725 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13726 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13727 + }, {
13728 + /* 512x384 @ 78 Hz, 31.50 kHz hsync */
13729 + NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
13730 +- 0, FB_VMODE_NONINTERLACED
13731 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13732 + }, {
13733 + /* 512x384 @ 85 Hz, 34.38 kHz hsync */
13734 + NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
13735 +- 0, FB_VMODE_NONINTERLACED
13736 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13737 + }, {
13738 + /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
13739 + NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
13740 +- 0, FB_VMODE_DOUBLE
13741 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13742 + }, {
13743 + /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
13744 + NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
13745 +- 0, FB_VMODE_DOUBLE
13746 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13747 + }, {
13748 + /* 320x240 @ 72 Hz, 36.5 kHz hsync */
13749 + NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
13750 +- 0, FB_VMODE_DOUBLE
13751 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13752 + }, {
13753 + /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
13754 + NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
13755 +- 0, FB_VMODE_DOUBLE
13756 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13757 + }, {
13758 + /* 400x300 @ 60 Hz, 37.8 kHz hsync */
13759 + NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
13760 +- 0, FB_VMODE_DOUBLE
13761 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13762 + }, {
13763 + /* 400x300 @ 72 Hz, 48.0 kHz hsync */
13764 + NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
13765 +- 0, FB_VMODE_DOUBLE
13766 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13767 + }, {
13768 + /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
13769 + NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
13770 +- 0, FB_VMODE_DOUBLE
13771 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13772 + }, {
13773 + /* 480x300 @ 60 Hz, 37.8 kHz hsync */
13774 + NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
13775 +- 0, FB_VMODE_DOUBLE
13776 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13777 + }, {
13778 + /* 480x300 @ 63 Hz, 39.6 kHz hsync */
13779 + NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
13780 +- 0, FB_VMODE_DOUBLE
13781 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13782 + }, {
13783 + /* 480x300 @ 72 Hz, 48.0 kHz hsync */
13784 + NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
13785 +- 0, FB_VMODE_DOUBLE
13786 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13787 + }, {
13788 + /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
13789 + NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
13790 + FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
13791 +- FB_VMODE_NONINTERLACED
13792 ++ FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13793 + }, {
13794 + /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
13795 + NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
13796 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13797 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13798 + }, {
13799 + /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
13800 + NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
13801 +- 0, FB_VMODE_NONINTERLACED
13802 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13803 + }, {
13804 + /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
13805 + NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
13806 +- 0, FB_VMODE_NONINTERLACED
13807 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13808 + },
13809 + };
13810 +
13811 +diff -urNp linux-2.6.27.10/drivers/video/uvesafb.c linux-2.6.27.10/drivers/video/uvesafb.c
13812 +--- linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-07 12:55:34.000000000 -0500
13813 ++++ linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-18 03:38:45.000000000 -0500
13814 +@@ -18,6 +18,7 @@
13815 + #include <linux/fb.h>
13816 + #include <linux/io.h>
13817 + #include <linux/mutex.h>
13818 ++#include <linux/moduleloader.h>
13819 + #include <video/edid.h>
13820 + #include <video/uvesafb.h>
13821 + #ifdef CONFIG_X86
13822 +@@ -117,7 +118,7 @@ static int uvesafb_helper_start(void)
13823 + NULL,
13824 + };
13825 +
13826 +- return call_usermodehelper(v86d_path, argv, envp, 1);
13827 ++ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
13828 + }
13829 +
13830 + /*
13831 +@@ -569,10 +570,34 @@ static int __devinit uvesafb_vbe_getpmi(
13832 + if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
13833 + par->pmi_setpal = par->ypan = 0;
13834 + } else {
13835 ++
13836 ++#ifdef CONFIG_PAX_KERNEXEC
13837 ++#ifdef CONFIG_MODULES
13838 ++ unsigned long cr0;
13839 ++
13840 ++ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
13841 ++#endif
13842 ++ if (!par->pmi_code) {
13843 ++ par->pmi_setpal = par->ypan = 0;
13844 ++ return 0;
13845 ++ }
13846 ++#endif
13847 ++
13848 + par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
13849 + + task->t.regs.edi);
13850 ++
13851 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13852 ++ pax_open_kernel(cr0);
13853 ++ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
13854 ++ pax_close_kernel(cr0);
13855 ++
13856 ++ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
13857 ++ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
13858 ++#else
13859 + par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
13860 + par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
13861 ++#endif
13862 ++
13863 + printk(KERN_INFO "uvesafb: protected mode interface info at "
13864 + "%04x:%04x\n",
13865 + (u16)task->t.regs.es, (u16)task->t.regs.edi);
13866 +@@ -1827,6 +1852,11 @@ out:
13867 + if (par->vbe_modes)
13868 + kfree(par->vbe_modes);
13869 +
13870 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13871 ++ if (par->pmi_code)
13872 ++ module_free_exec(NULL, par->pmi_code);
13873 ++#endif
13874 ++
13875 + framebuffer_release(info);
13876 + return err;
13877 + }
13878 +@@ -1853,6 +1883,12 @@ static int uvesafb_remove(struct platfor
13879 + kfree(par->vbe_state_orig);
13880 + if (par->vbe_state_saved)
13881 + kfree(par->vbe_state_saved);
13882 ++
13883 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13884 ++ if (par->pmi_code)
13885 ++ module_free_exec(NULL, par->pmi_code);
13886 ++#endif
13887 ++
13888 + }
13889 +
13890 + framebuffer_release(info);
13891 +diff -urNp linux-2.6.27.10/drivers/video/vesafb.c linux-2.6.27.10/drivers/video/vesafb.c
13892 +--- linux-2.6.27.10/drivers/video/vesafb.c 2008-11-07 12:55:34.000000000 -0500
13893 ++++ linux-2.6.27.10/drivers/video/vesafb.c 2008-11-18 03:38:45.000000000 -0500
13894 +@@ -9,6 +9,7 @@
13895 + */
13896 +
13897 + #include <linux/module.h>
13898 ++#include <linux/moduleloader.h>
13899 + #include <linux/kernel.h>
13900 + #include <linux/errno.h>
13901 + #include <linux/string.h>
13902 +@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
13903 + static int vram_total __initdata; /* Set total amount of memory */
13904 + static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
13905 + static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
13906 +-static void (*pmi_start)(void) __read_mostly;
13907 +-static void (*pmi_pal) (void) __read_mostly;
13908 ++static void (*pmi_start)(void) __read_only;
13909 ++static void (*pmi_pal) (void) __read_only;
13910 + static int depth __read_mostly;
13911 + static int vga_compat __read_mostly;
13912 + /* --------------------------------------------------------------------- */
13913 +@@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl
13914 + unsigned int size_vmode;
13915 + unsigned int size_remap;
13916 + unsigned int size_total;
13917 ++ void *pmi_code = NULL;
13918 +
13919 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
13920 + return -ENODEV;
13921 +@@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl
13922 + size_remap = size_total;
13923 + vesafb_fix.smem_len = size_remap;
13924 +
13925 +-#ifndef __i386__
13926 +- screen_info.vesapm_seg = 0;
13927 +-#endif
13928 +-
13929 + if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
13930 + printk(KERN_WARNING
13931 + "vesafb: cannot reserve video memory at 0x%lx\n",
13932 +@@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl
13933 + printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
13934 + vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
13935 +
13936 ++#ifdef __i386__
13937 ++
13938 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13939 ++ pmi_code = module_alloc_exec(screen_info.vesapm_size);
13940 ++ if (!pmi_code)
13941 ++#elif !defined(CONFIG_PAX_KERNEXEC)
13942 ++ if (0)
13943 ++#endif
13944 ++
13945 ++#endif
13946 ++ screen_info.vesapm_seg = 0;
13947 ++
13948 + if (screen_info.vesapm_seg) {
13949 +- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
13950 +- screen_info.vesapm_seg,screen_info.vesapm_off);
13951 ++ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
13952 ++ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
13953 + }
13954 +
13955 + if (screen_info.vesapm_seg < 0xc000)
13956 +@@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl
13957 +
13958 + if (ypan || pmi_setpal) {
13959 + unsigned short *pmi_base;
13960 +- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
13961 +- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
13962 +- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
13963 ++
13964 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13965 ++ unsigned long cr0;
13966 ++#endif
13967 ++
13968 ++ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
13969 ++
13970 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13971 ++ pax_open_kernel(cr0);
13972 ++ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
13973 ++#else
13974 ++ pmi_code = pmi_base;
13975 ++#endif
13976 ++
13977 ++ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
13978 ++ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
13979 ++
13980 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13981 ++ pmi_start = ktva_ktla(pmi_start);
13982 ++ pmi_pal = ktva_ktla(pmi_pal);
13983 ++ pax_close_kernel(cr0);
13984 ++#endif
13985 ++
13986 + printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
13987 + if (pmi_base[3]) {
13988 + printk(KERN_INFO "vesafb: pmi: ports = ");
13989 +@@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl
13990 + info->node, info->fix.id);
13991 + return 0;
13992 + err:
13993 ++
13994 ++#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13995 ++ module_free_exec(NULL, pmi_code);
13996 ++#endif
13997 ++
13998 + if (info->screen_base)
13999 + iounmap(info->screen_base);
14000 + framebuffer_release(info);
14001 +diff -urNp linux-2.6.27.10/fs/9p/vfs_inode.c linux-2.6.27.10/fs/9p/vfs_inode.c
14002 +--- linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-07 12:55:34.000000000 -0500
14003 ++++ linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-18 03:38:45.000000000 -0500
14004 +@@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct
14005 + static void
14006 + v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
14007 + {
14008 +- char *s = nd_get_link(nd);
14009 ++ const char *s = nd_get_link(nd);
14010 +
14011 + P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
14012 + if (!IS_ERR(s))
14013 +diff -urNp linux-2.6.27.10/fs/aio.c linux-2.6.27.10/fs/aio.c
14014 +--- linux-2.6.27.10/fs/aio.c 2008-11-07 12:55:34.000000000 -0500
14015 ++++ linux-2.6.27.10/fs/aio.c 2008-11-18 03:38:45.000000000 -0500
14016 +@@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx
14017 + size += sizeof(struct io_event) * nr_events;
14018 + nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
14019 +
14020 +- if (nr_pages < 0)
14021 ++ if (nr_pages <= 0)
14022 + return -EINVAL;
14023 +
14024 + nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
14025 +diff -urNp linux-2.6.27.10/fs/autofs4/symlink.c linux-2.6.27.10/fs/autofs4/symlink.c
14026 +--- linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-07 12:55:34.000000000 -0500
14027 ++++ linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-18 03:38:45.000000000 -0500
14028 +@@ -15,7 +15,7 @@
14029 + static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
14030 + {
14031 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
14032 +- nd_set_link(nd, (char *)ino->u.symlink);
14033 ++ nd_set_link(nd, ino->u.symlink);
14034 + return NULL;
14035 + }
14036 +
14037 +diff -urNp linux-2.6.27.10/fs/befs/linuxvfs.c linux-2.6.27.10/fs/befs/linuxvfs.c
14038 +--- linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-07 12:55:34.000000000 -0500
14039 ++++ linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-18 03:38:45.000000000 -0500
14040 +@@ -490,7 +490,7 @@ static void befs_put_link(struct dentry
14041 + {
14042 + befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
14043 + if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
14044 +- char *link = nd_get_link(nd);
14045 ++ const char *link = nd_get_link(nd);
14046 + if (!IS_ERR(link))
14047 + kfree(link);
14048 + }
14049 +diff -urNp linux-2.6.27.10/fs/binfmt_aout.c linux-2.6.27.10/fs/binfmt_aout.c
14050 +--- linux-2.6.27.10/fs/binfmt_aout.c 2008-11-07 12:55:34.000000000 -0500
14051 ++++ linux-2.6.27.10/fs/binfmt_aout.c 2008-11-18 03:38:45.000000000 -0500
14052 +@@ -24,6 +24,7 @@
14053 + #include <linux/binfmts.h>
14054 + #include <linux/personality.h>
14055 + #include <linux/init.h>
14056 ++#include <linux/grsecurity.h>
14057 +
14058 + #include <asm/system.h>
14059 + #include <asm/uaccess.h>
14060 +@@ -124,18 +125,22 @@ static int aout_core_dump(long signr, st
14061 + /* If the size of the dump file exceeds the rlimit, then see what would happen
14062 + if we wrote the stack, but not the data area. */
14063 + #ifdef __sparc__
14064 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize + dump.u_ssize, 1);
14065 + if ((dump.u_dsize + dump.u_ssize) > limit)
14066 + dump.u_dsize = 0;
14067 + #else
14068 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
14069 + if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
14070 + dump.u_dsize = 0;
14071 + #endif
14072 +
14073 + /* Make sure we have enough room to write the stack and data areas. */
14074 + #ifdef __sparc__
14075 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize, 1);
14076 + if (dump.u_ssize > limit)
14077 + dump.u_ssize = 0;
14078 + #else
14079 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
14080 + if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
14081 + dump.u_ssize = 0;
14082 + #endif
14083 +@@ -291,6 +296,8 @@ static int load_aout_binary(struct linux
14084 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
14085 + if (rlim >= RLIM_INFINITY)
14086 + rlim = ~0;
14087 ++
14088 ++ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
14089 + if (ex.a_data + ex.a_bss > rlim)
14090 + return -ENOMEM;
14091 +
14092 +@@ -322,6 +329,28 @@ static int load_aout_binary(struct linux
14093 +
14094 + compute_creds(bprm);
14095 + current->flags &= ~PF_FORKNOEXEC;
14096 ++
14097 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14098 ++ current->mm->pax_flags = 0UL;
14099 ++#endif
14100 ++
14101 ++#ifdef CONFIG_PAX_PAGEEXEC
14102 ++ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
14103 ++ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
14104 ++
14105 ++#ifdef CONFIG_PAX_EMUTRAMP
14106 ++ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
14107 ++ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
14108 ++#endif
14109 ++
14110 ++#ifdef CONFIG_PAX_MPROTECT
14111 ++ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
14112 ++ current->mm->pax_flags |= MF_PAX_MPROTECT;
14113 ++#endif
14114 ++
14115 ++ }
14116 ++#endif
14117 ++
14118 + #ifdef __sparc__
14119 + if (N_MAGIC(ex) == NMAGIC) {
14120 + loff_t pos = fd_offset;
14121 +@@ -413,7 +442,7 @@ static int load_aout_binary(struct linux
14122 +
14123 + down_write(&current->mm->mmap_sem);
14124 + error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
14125 +- PROT_READ | PROT_WRITE | PROT_EXEC,
14126 ++ PROT_READ | PROT_WRITE,
14127 + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
14128 + fd_offset + ex.a_text);
14129 + up_write(&current->mm->mmap_sem);
14130 +diff -urNp linux-2.6.27.10/fs/binfmt_elf.c linux-2.6.27.10/fs/binfmt_elf.c
14131 +--- linux-2.6.27.10/fs/binfmt_elf.c 2008-11-07 12:55:34.000000000 -0500
14132 ++++ linux-2.6.27.10/fs/binfmt_elf.c 2008-12-21 00:51:06.000000000 -0500
14133 +@@ -38,10 +38,16 @@
14134 + #include <linux/random.h>
14135 + #include <linux/elf.h>
14136 + #include <linux/utsname.h>
14137 ++#include <linux/grsecurity.h>
14138 ++
14139 + #include <asm/uaccess.h>
14140 + #include <asm/param.h>
14141 + #include <asm/page.h>
14142 +
14143 ++#ifdef CONFIG_PAX_SEGMEXEC
14144 ++#include <asm/desc.h>
14145 ++#endif
14146 ++
14147 + static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
14148 + static int load_elf_library(struct file *);
14149 + static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
14150 +@@ -57,6 +63,10 @@ static int elf_core_dump(long signr, str
14151 + #define elf_core_dump NULL
14152 + #endif
14153 +
14154 ++#ifdef CONFIG_PAX_MPROTECT
14155 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
14156 ++#endif
14157 ++
14158 + #if ELF_EXEC_PAGESIZE > PAGE_SIZE
14159 + #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
14160 + #else
14161 +@@ -76,6 +86,11 @@ static struct linux_binfmt elf_format =
14162 + .load_binary = load_elf_binary,
14163 + .load_shlib = load_elf_library,
14164 + .core_dump = elf_core_dump,
14165 ++
14166 ++#ifdef CONFIG_PAX_MPROTECT
14167 ++ .handle_mprotect= elf_handle_mprotect,
14168 ++#endif
14169 ++
14170 + .min_coredump = ELF_EXEC_PAGESIZE,
14171 + .hasvdso = 1
14172 + };
14173 +@@ -84,6 +99,8 @@ static struct linux_binfmt elf_format =
14174 +
14175 + static int set_brk(unsigned long start, unsigned long end)
14176 + {
14177 ++ unsigned long e = end;
14178 ++
14179 + start = ELF_PAGEALIGN(start);
14180 + end = ELF_PAGEALIGN(end);
14181 + if (end > start) {
14182 +@@ -94,7 +111,7 @@ static int set_brk(unsigned long start,
14183 + if (BAD_ADDR(addr))
14184 + return addr;
14185 + }
14186 +- current->mm->start_brk = current->mm->brk = end;
14187 ++ current->mm->start_brk = current->mm->brk = e;
14188 + return 0;
14189 + }
14190 +
14191 +@@ -380,10 +397,10 @@ static unsigned long load_elf_interp(str
14192 + {
14193 + struct elf_phdr *elf_phdata;
14194 + struct elf_phdr *eppnt;
14195 +- unsigned long load_addr = 0;
14196 ++ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
14197 + int load_addr_set = 0;
14198 + unsigned long last_bss = 0, elf_bss = 0;
14199 +- unsigned long error = ~0UL;
14200 ++ unsigned long error = -EINVAL;
14201 + unsigned long total_size;
14202 + int retval, i, size;
14203 +
14204 +@@ -429,6 +446,11 @@ static unsigned long load_elf_interp(str
14205 + goto out_close;
14206 + }
14207 +
14208 ++#ifdef CONFIG_PAX_SEGMEXEC
14209 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14210 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14211 ++#endif
14212 ++
14213 + eppnt = elf_phdata;
14214 + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
14215 + if (eppnt->p_type == PT_LOAD) {
14216 +@@ -472,8 +494,8 @@ static unsigned long load_elf_interp(str
14217 + k = load_addr + eppnt->p_vaddr;
14218 + if (BAD_ADDR(k) ||
14219 + eppnt->p_filesz > eppnt->p_memsz ||
14220 +- eppnt->p_memsz > TASK_SIZE ||
14221 +- TASK_SIZE - eppnt->p_memsz < k) {
14222 ++ eppnt->p_memsz > pax_task_size ||
14223 ++ pax_task_size - eppnt->p_memsz < k) {
14224 + error = -ENOMEM;
14225 + goto out_close;
14226 + }
14227 +@@ -527,6 +549,177 @@ out:
14228 + return error;
14229 + }
14230 +
14231 ++#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
14232 ++static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
14233 ++{
14234 ++ unsigned long pax_flags = 0UL;
14235 ++
14236 ++#ifdef CONFIG_PAX_PAGEEXEC
14237 ++ if (elf_phdata->p_flags & PF_PAGEEXEC)
14238 ++ pax_flags |= MF_PAX_PAGEEXEC;
14239 ++#endif
14240 ++
14241 ++#ifdef CONFIG_PAX_SEGMEXEC
14242 ++ if (elf_phdata->p_flags & PF_SEGMEXEC)
14243 ++ pax_flags |= MF_PAX_SEGMEXEC;
14244 ++#endif
14245 ++
14246 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14247 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14248 ++ if (nx_enabled)
14249 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14250 ++ else
14251 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14252 ++ }
14253 ++#endif
14254 ++
14255 ++#ifdef CONFIG_PAX_EMUTRAMP
14256 ++ if (elf_phdata->p_flags & PF_EMUTRAMP)
14257 ++ pax_flags |= MF_PAX_EMUTRAMP;
14258 ++#endif
14259 ++
14260 ++#ifdef CONFIG_PAX_MPROTECT
14261 ++ if (elf_phdata->p_flags & PF_MPROTECT)
14262 ++ pax_flags |= MF_PAX_MPROTECT;
14263 ++#endif
14264 ++
14265 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14266 ++ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
14267 ++ pax_flags |= MF_PAX_RANDMMAP;
14268 ++#endif
14269 ++
14270 ++ return pax_flags;
14271 ++}
14272 ++#endif
14273 ++
14274 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14275 ++static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
14276 ++{
14277 ++ unsigned long pax_flags = 0UL;
14278 ++
14279 ++#ifdef CONFIG_PAX_PAGEEXEC
14280 ++ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
14281 ++ pax_flags |= MF_PAX_PAGEEXEC;
14282 ++#endif
14283 ++
14284 ++#ifdef CONFIG_PAX_SEGMEXEC
14285 ++ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
14286 ++ pax_flags |= MF_PAX_SEGMEXEC;
14287 ++#endif
14288 ++
14289 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14290 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14291 ++ if (nx_enabled)
14292 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14293 ++ else
14294 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14295 ++ }
14296 ++#endif
14297 ++
14298 ++#ifdef CONFIG_PAX_EMUTRAMP
14299 ++ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
14300 ++ pax_flags |= MF_PAX_EMUTRAMP;
14301 ++#endif
14302 ++
14303 ++#ifdef CONFIG_PAX_MPROTECT
14304 ++ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
14305 ++ pax_flags |= MF_PAX_MPROTECT;
14306 ++#endif
14307 ++
14308 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14309 ++ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
14310 ++ pax_flags |= MF_PAX_RANDMMAP;
14311 ++#endif
14312 ++
14313 ++ return pax_flags;
14314 ++}
14315 ++#endif
14316 ++
14317 ++#ifdef CONFIG_PAX_EI_PAX
14318 ++static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
14319 ++{
14320 ++ unsigned long pax_flags = 0UL;
14321 ++
14322 ++#ifdef CONFIG_PAX_PAGEEXEC
14323 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
14324 ++ pax_flags |= MF_PAX_PAGEEXEC;
14325 ++#endif
14326 ++
14327 ++#ifdef CONFIG_PAX_SEGMEXEC
14328 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
14329 ++ pax_flags |= MF_PAX_SEGMEXEC;
14330 ++#endif
14331 ++
14332 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14333 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14334 ++ if (nx_enabled)
14335 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14336 ++ else
14337 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14338 ++ }
14339 ++#endif
14340 ++
14341 ++#ifdef CONFIG_PAX_EMUTRAMP
14342 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
14343 ++ pax_flags |= MF_PAX_EMUTRAMP;
14344 ++#endif
14345 ++
14346 ++#ifdef CONFIG_PAX_MPROTECT
14347 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
14348 ++ pax_flags |= MF_PAX_MPROTECT;
14349 ++#endif
14350 ++
14351 ++#ifdef CONFIG_PAX_ASLR
14352 ++ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
14353 ++ pax_flags |= MF_PAX_RANDMMAP;
14354 ++#endif
14355 ++
14356 ++ return pax_flags;
14357 ++}
14358 ++#endif
14359 ++
14360 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14361 ++static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
14362 ++{
14363 ++ unsigned long pax_flags = 0UL;
14364 ++
14365 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14366 ++ unsigned long i;
14367 ++#endif
14368 ++
14369 ++#ifdef CONFIG_PAX_EI_PAX
14370 ++ pax_flags = pax_parse_ei_pax(elf_ex);
14371 ++#endif
14372 ++
14373 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14374 ++ for (i = 0UL; i < elf_ex->e_phnum; i++)
14375 ++ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
14376 ++ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
14377 ++ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
14378 ++ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
14379 ++ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
14380 ++ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
14381 ++ return -EINVAL;
14382 ++
14383 ++#ifdef CONFIG_PAX_SOFTMODE
14384 ++ if (pax_softmode)
14385 ++ pax_flags = pax_parse_softmode(&elf_phdata[i]);
14386 ++ else
14387 ++#endif
14388 ++
14389 ++ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
14390 ++ break;
14391 ++ }
14392 ++#endif
14393 ++
14394 ++ if (0 > pax_check_flags(&pax_flags))
14395 ++ return -EINVAL;
14396 ++
14397 ++ current->mm->pax_flags = pax_flags;
14398 ++ return 0;
14399 ++}
14400 ++#endif
14401 ++
14402 + /*
14403 + * These are the functions used to load ELF style executables and shared
14404 + * libraries. There is no binary dependent code anywhere else.
14405 +@@ -543,6 +736,11 @@ static unsigned long randomize_stack_top
14406 + {
14407 + unsigned int random_variable = 0;
14408 +
14409 ++#ifdef CONFIG_PAX_RANDUSTACK
14410 ++ if (randomize_va_space)
14411 ++ return stack_top - current->mm->delta_stack;
14412 ++#endif
14413 ++
14414 + if ((current->flags & PF_RANDOMIZE) &&
14415 + !(current->personality & ADDR_NO_RANDOMIZE)) {
14416 + random_variable = get_random_int() & STACK_RND_MASK;
14417 +@@ -561,7 +759,7 @@ static int load_elf_binary(struct linux_
14418 + unsigned long load_addr = 0, load_bias = 0;
14419 + int load_addr_set = 0;
14420 + char * elf_interpreter = NULL;
14421 +- unsigned long error;
14422 ++ unsigned long error = 0;
14423 + struct elf_phdr *elf_ppnt, *elf_phdata;
14424 + unsigned long elf_bss, elf_brk;
14425 + int elf_exec_fileno;
14426 +@@ -572,11 +770,11 @@ static int load_elf_binary(struct linux_
14427 + unsigned long start_code, end_code, start_data, end_data;
14428 + unsigned long reloc_func_desc = 0;
14429 + int executable_stack = EXSTACK_DEFAULT;
14430 +- unsigned long def_flags = 0;
14431 + struct {
14432 + struct elfhdr elf_ex;
14433 + struct elfhdr interp_elf_ex;
14434 + } *loc;
14435 ++ unsigned long pax_task_size = TASK_SIZE;
14436 +
14437 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
14438 + if (!loc) {
14439 +@@ -744,11 +942,80 @@ static int load_elf_binary(struct linux_
14440 +
14441 + /* OK, This is the point of no return */
14442 + current->flags &= ~PF_FORKNOEXEC;
14443 +- current->mm->def_flags = def_flags;
14444 ++
14445 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14446 ++ current->mm->pax_flags = 0UL;
14447 ++#endif
14448 ++
14449 ++#ifdef CONFIG_PAX_DLRESOLVE
14450 ++ current->mm->call_dl_resolve = 0UL;
14451 ++#endif
14452 ++
14453 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
14454 ++ current->mm->call_syscall = 0UL;
14455 ++#endif
14456 ++
14457 ++#ifdef CONFIG_PAX_ASLR
14458 ++ current->mm->delta_mmap = 0UL;
14459 ++ current->mm->delta_stack = 0UL;
14460 ++#endif
14461 ++
14462 ++ current->mm->def_flags = 0;
14463 ++
14464 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14465 ++ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
14466 ++ send_sig(SIGKILL, current, 0);
14467 ++ goto out_free_dentry;
14468 ++ }
14469 ++#endif
14470 ++
14471 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
14472 ++ pax_set_initial_flags(bprm);
14473 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
14474 ++ if (pax_set_initial_flags_func)
14475 ++ (pax_set_initial_flags_func)(bprm);
14476 ++#endif
14477 ++
14478 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
14479 ++ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
14480 ++ current->mm->context.user_cs_limit = PAGE_SIZE;
14481 ++ current->mm->def_flags |= VM_PAGEEXEC;
14482 ++ }
14483 ++#endif
14484 ++
14485 ++#ifdef CONFIG_PAX_SEGMEXEC
14486 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
14487 ++ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
14488 ++ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
14489 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14490 ++ }
14491 ++#endif
14492 ++
14493 ++#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
14494 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14495 ++ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
14496 ++ put_cpu_no_resched();
14497 ++ }
14498 ++#endif
14499 ++
14500 ++#ifdef CONFIG_PAX_ASLR
14501 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
14502 ++ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
14503 ++ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
14504 ++ }
14505 ++#endif
14506 +
14507 + /* Do this immediately, since STACK_TOP as used in setup_arg_pages
14508 + may depend on the personality. */
14509 + SET_PERSONALITY(loc->elf_ex, 0);
14510 ++
14511 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14512 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14513 ++ executable_stack = EXSTACK_DISABLE_X;
14514 ++ current->personality &= ~READ_IMPLIES_EXEC;
14515 ++ } else
14516 ++#endif
14517 ++
14518 + if (elf_read_implies_exec(loc->elf_ex, executable_stack))
14519 + current->personality |= READ_IMPLIES_EXEC;
14520 +
14521 +@@ -829,6 +1096,20 @@ static int load_elf_binary(struct linux_
14522 + #else
14523 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
14524 + #endif
14525 ++
14526 ++#ifdef CONFIG_PAX_RANDMMAP
14527 ++ /* PaX: randomize base address at the default exe base if requested */
14528 ++ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
14529 ++#ifdef CONFIG_SPARC64
14530 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
14531 ++#else
14532 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
14533 ++#endif
14534 ++ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
14535 ++ elf_flags |= MAP_FIXED;
14536 ++ }
14537 ++#endif
14538 ++
14539 + }
14540 +
14541 + error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
14542 +@@ -861,9 +1142,9 @@ static int load_elf_binary(struct linux_
14543 + * allowed task size. Note that p_filesz must always be
14544 + * <= p_memsz so it is only necessary to check p_memsz.
14545 + */
14546 +- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14547 +- elf_ppnt->p_memsz > TASK_SIZE ||
14548 +- TASK_SIZE - elf_ppnt->p_memsz < k) {
14549 ++ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14550 ++ elf_ppnt->p_memsz > pax_task_size ||
14551 ++ pax_task_size - elf_ppnt->p_memsz < k) {
14552 + /* set_brk can never work. Avoid overflows. */
14553 + send_sig(SIGKILL, current, 0);
14554 + retval = -EINVAL;
14555 +@@ -891,6 +1172,11 @@ static int load_elf_binary(struct linux_
14556 + start_data += load_bias;
14557 + end_data += load_bias;
14558 +
14559 ++#ifdef CONFIG_PAX_RANDMMAP
14560 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
14561 ++ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
14562 ++#endif
14563 ++
14564 + /* Calling set_brk effectively mmaps the pages that we need
14565 + * for the bss and break sections. We must do this before
14566 + * mapping in the interpreter, to make sure it doesn't wind
14567 +@@ -902,9 +1188,11 @@ static int load_elf_binary(struct linux_
14568 + goto out_free_dentry;
14569 + }
14570 + if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
14571 +- send_sig(SIGSEGV, current, 0);
14572 +- retval = -EFAULT; /* Nobody gets to see this, but.. */
14573 +- goto out_free_dentry;
14574 ++ /*
14575 ++ * This bss-zeroing can fail if the ELF
14576 ++ * file specifies odd protections. So
14577 ++ * we don't check the return value
14578 ++ */
14579 + }
14580 +
14581 + if (elf_interpreter) {
14582 +@@ -1141,8 +1429,10 @@ static int dump_seek(struct file *file,
14583 + unsigned long n = off;
14584 + if (n > PAGE_SIZE)
14585 + n = PAGE_SIZE;
14586 +- if (!dump_write(file, buf, n))
14587 ++ if (!dump_write(file, buf, n)) {
14588 ++ free_page((unsigned long)buf);
14589 + return 0;
14590 ++ }
14591 + off -= n;
14592 + }
14593 + free_page((unsigned long)buf);
14594 +@@ -1154,7 +1444,7 @@ static int dump_seek(struct file *file,
14595 + * Decide what to dump of a segment, part, all or none.
14596 + */
14597 + static unsigned long vma_dump_size(struct vm_area_struct *vma,
14598 +- unsigned long mm_flags)
14599 ++ unsigned long mm_flags, long signr)
14600 + {
14601 + /* The vma can be set up to tell us the answer directly. */
14602 + if (vma->vm_flags & VM_ALWAYSDUMP)
14603 +@@ -1180,7 +1470,7 @@ static unsigned long vma_dump_size(struc
14604 + if (vma->vm_file == NULL)
14605 + return 0;
14606 +
14607 +- if (FILTER(MAPPED_PRIVATE))
14608 ++ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
14609 + goto whole;
14610 +
14611 + /*
14612 +@@ -1266,8 +1556,11 @@ static int writenote(struct memelfnote *
14613 + #undef DUMP_WRITE
14614 +
14615 + #define DUMP_WRITE(addr, nr) \
14616 ++ do { \
14617 ++ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
14618 + if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
14619 +- goto end_coredump;
14620 ++ goto end_coredump; \
14621 ++ } while (0);
14622 + #define DUMP_SEEK(off) \
14623 + if (!dump_seek(file, (off))) \
14624 + goto end_coredump;
14625 +@@ -1973,7 +2266,7 @@ static int elf_core_dump(long signr, str
14626 + phdr.p_offset = offset;
14627 + phdr.p_vaddr = vma->vm_start;
14628 + phdr.p_paddr = 0;
14629 +- phdr.p_filesz = vma_dump_size(vma, mm_flags);
14630 ++ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
14631 + phdr.p_memsz = vma->vm_end - vma->vm_start;
14632 + offset += phdr.p_filesz;
14633 + phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
14634 +@@ -2005,7 +2298,7 @@ static int elf_core_dump(long signr, str
14635 + unsigned long addr;
14636 + unsigned long end;
14637 +
14638 +- end = vma->vm_start + vma_dump_size(vma, mm_flags);
14639 ++ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
14640 +
14641 + for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
14642 + struct page *page;
14643 +@@ -2025,6 +2318,7 @@ static int elf_core_dump(long signr, str
14644 + flush_cache_page(tmp_vma, addr,
14645 + page_to_pfn(page));
14646 + kaddr = kmap(page);
14647 ++ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
14648 + if ((size += PAGE_SIZE) > limit ||
14649 + !dump_write(file, kaddr,
14650 + PAGE_SIZE)) {
14651 +@@ -2055,6 +2349,99 @@ out:
14652 +
14653 + #endif /* USE_ELF_CORE_DUMP */
14654 +
14655 ++#ifdef CONFIG_PAX_MPROTECT
14656 ++/* PaX: non-PIC ELF libraries need relocations on their executable segments
14657 ++ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
14658 ++ * we'll remove VM_MAYWRITE for good on RELRO segments.
14659 ++ *
14660 ++ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
14661 ++ * basis because we want to allow the common case and not the special ones.
14662 ++ */
14663 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
14664 ++{
14665 ++ struct elfhdr elf_h;
14666 ++ struct elf_phdr elf_p;
14667 ++ unsigned long i;
14668 ++ unsigned long oldflags;
14669 ++ bool is_textrel_rw, is_textrel_rx, is_relro;
14670 ++
14671 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
14672 ++ return;
14673 ++
14674 ++ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
14675 ++ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
14676 ++
14677 ++#ifdef CONFIG_PAX_NOELFRELOCS
14678 ++ is_textrel_rw = false;
14679 ++ is_textrel_rx = false;
14680 ++#else
14681 ++ /* possible TEXTREL */
14682 ++ 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);
14683 ++ 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);
14684 ++#endif
14685 ++
14686 ++ /* possible RELRO */
14687 ++ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
14688 ++
14689 ++ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
14690 ++ return;
14691 ++
14692 ++ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
14693 ++ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
14694 ++
14695 ++#ifdef CONFIG_PAX_ETEXECRELOCS
14696 ++ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14697 ++#else
14698 ++ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
14699 ++#endif
14700 ++
14701 ++ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14702 ++ !elf_check_arch(&elf_h) ||
14703 ++ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
14704 ++ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
14705 ++ return;
14706 ++
14707 ++ for (i = 0UL; i < elf_h.e_phnum; i++) {
14708 ++ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
14709 ++ return;
14710 ++ switch (elf_p.p_type) {
14711 ++ case PT_DYNAMIC: {
14712 ++ elf_addr_t dyn_offset = 0UL;
14713 ++ elf_dyn dyn;
14714 ++
14715 ++ if (!is_textrel_rw && !is_textrel_rx)
14716 ++ continue;
14717 ++ dyn_offset = elf_p.p_offset;
14718 ++ i = 0UL;
14719 ++ do {
14720 ++ if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
14721 ++ return;
14722 ++ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
14723 ++ gr_log_textrel(vma);
14724 ++ if (is_textrel_rw)
14725 ++ vma->vm_flags |= VM_MAYWRITE;
14726 ++ else
14727 ++ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
14728 ++ vma->vm_flags &= ~VM_MAYWRITE;
14729 ++ return;
14730 ++ }
14731 ++ i++;
14732 ++ } while (dyn.d_tag != DT_NULL);
14733 ++ return;
14734 ++ }
14735 ++
14736 ++ case PT_GNU_RELRO:
14737 ++ if (!is_relro)
14738 ++ continue;
14739 ++ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) {
14740 ++ vma->vm_flags &= ~VM_MAYWRITE;
14741 ++ }
14742 ++ return;
14743 ++ }
14744 ++ }
14745 ++}
14746 ++#endif
14747 ++
14748 + static int __init init_elf_binfmt(void)
14749 + {
14750 + return register_binfmt(&elf_format);
14751 +diff -urNp linux-2.6.27.10/fs/binfmt_flat.c linux-2.6.27.10/fs/binfmt_flat.c
14752 +--- linux-2.6.27.10/fs/binfmt_flat.c 2008-11-07 12:55:34.000000000 -0500
14753 ++++ linux-2.6.27.10/fs/binfmt_flat.c 2008-11-18 03:38:45.000000000 -0500
14754 +@@ -561,7 +561,9 @@ static int load_flat_file(struct linux_b
14755 + realdatastart = (unsigned long) -ENOMEM;
14756 + printk("Unable to allocate RAM for process data, errno %d\n",
14757 + (int)-realdatastart);
14758 ++ down_write(&current->mm->mmap_sem);
14759 + do_munmap(current->mm, textpos, text_len);
14760 ++ up_write(&current->mm->mmap_sem);
14761 + ret = realdatastart;
14762 + goto err;
14763 + }
14764 +@@ -583,8 +585,10 @@ static int load_flat_file(struct linux_b
14765 + }
14766 + if (result >= (unsigned long)-4096) {
14767 + printk("Unable to read data+bss, errno %d\n", (int)-result);
14768 ++ down_write(&current->mm->mmap_sem);
14769 + do_munmap(current->mm, textpos, text_len);
14770 + do_munmap(current->mm, realdatastart, data_len + extra);
14771 ++ up_write(&current->mm->mmap_sem);
14772 + ret = result;
14773 + goto err;
14774 + }
14775 +@@ -657,8 +661,10 @@ static int load_flat_file(struct linux_b
14776 + }
14777 + if (result >= (unsigned long)-4096) {
14778 + printk("Unable to read code+data+bss, errno %d\n",(int)-result);
14779 ++ down_write(&current->mm->mmap_sem);
14780 + do_munmap(current->mm, textpos, text_len + data_len + extra +
14781 + MAX_SHARED_LIBS * sizeof(unsigned long));
14782 ++ up_write(&current->mm->mmap_sem);
14783 + ret = result;
14784 + goto err;
14785 + }
14786 +diff -urNp linux-2.6.27.10/fs/binfmt_misc.c linux-2.6.27.10/fs/binfmt_misc.c
14787 +--- linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:16:51.000000000 -0500
14788 ++++ linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:13:46.000000000 -0500
14789 +@@ -696,7 +696,7 @@ static int bm_fill_super(struct super_bl
14790 + static struct tree_descr bm_files[] = {
14791 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
14792 + [3] = {"register", &bm_register_operations, S_IWUSR},
14793 +- /* last one */ {""}
14794 ++ /* last one */ {"", NULL, 0}
14795 + };
14796 + int err = simple_fill_super(sb, 0x42494e4d, bm_files);
14797 + if (!err)
14798 +diff -urNp linux-2.6.27.10/fs/bio.c linux-2.6.27.10/fs/bio.c
14799 +--- linux-2.6.27.10/fs/bio.c 2008-11-07 12:55:34.000000000 -0500
14800 ++++ linux-2.6.27.10/fs/bio.c 2008-11-18 03:38:45.000000000 -0500
14801 +@@ -507,7 +507,7 @@ static int __bio_copy_iov(struct bio *bi
14802 +
14803 + while (bv_len && iov_idx < iov_count) {
14804 + unsigned int bytes;
14805 +- char *iov_addr;
14806 ++ char __user *iov_addr;
14807 +
14808 + bytes = min_t(unsigned int,
14809 + iov[iov_idx].iov_len - iov_off, bv_len);
14810 +diff -urNp linux-2.6.27.10/fs/buffer.c linux-2.6.27.10/fs/buffer.c
14811 +--- linux-2.6.27.10/fs/buffer.c 2008-11-07 12:55:34.000000000 -0500
14812 ++++ linux-2.6.27.10/fs/buffer.c 2008-11-18 03:38:45.000000000 -0500
14813 +@@ -41,6 +41,7 @@
14814 + #include <linux/bitops.h>
14815 + #include <linux/mpage.h>
14816 + #include <linux/bit_spinlock.h>
14817 ++#include <linux/grsecurity.h>
14818 +
14819 + static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
14820 +
14821 +@@ -2249,6 +2250,7 @@ int generic_cont_expand_simple(struct in
14822 +
14823 + err = -EFBIG;
14824 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
14825 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1);
14826 + if (limit != RLIM_INFINITY && size > (loff_t)limit) {
14827 + send_sig(SIGXFSZ, current, 0);
14828 + goto out;
14829 +diff -urNp linux-2.6.27.10/fs/cifs/cifs_uniupr.h linux-2.6.27.10/fs/cifs/cifs_uniupr.h
14830 +--- linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-07 12:55:34.000000000 -0500
14831 ++++ linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-18 03:38:45.000000000 -0500
14832 +@@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
14833 + {0x0490, 0x04cc, UniCaseRangeU0490},
14834 + {0x1e00, 0x1ffc, UniCaseRangeU1e00},
14835 + {0xff40, 0xff5a, UniCaseRangeUff40},
14836 +- {0}
14837 ++ {0, 0, NULL}
14838 + };
14839 + #endif
14840 +
14841 +diff -urNp linux-2.6.27.10/fs/cifs/link.c linux-2.6.27.10/fs/cifs/link.c
14842 +--- linux-2.6.27.10/fs/cifs/link.c 2008-11-07 12:55:34.000000000 -0500
14843 ++++ linux-2.6.27.10/fs/cifs/link.c 2008-11-18 03:38:45.000000000 -0500
14844 +@@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c
14845 +
14846 + void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
14847 + {
14848 +- char *p = nd_get_link(nd);
14849 ++ const char *p = nd_get_link(nd);
14850 + if (!IS_ERR(p))
14851 + kfree(p);
14852 + }
14853 +diff -urNp linux-2.6.27.10/fs/compat.c linux-2.6.27.10/fs/compat.c
14854 +--- linux-2.6.27.10/fs/compat.c 2008-11-07 12:55:34.000000000 -0500
14855 ++++ linux-2.6.27.10/fs/compat.c 2008-11-18 03:38:45.000000000 -0500
14856 +@@ -51,6 +51,7 @@
14857 + #include <linux/poll.h>
14858 + #include <linux/mm.h>
14859 + #include <linux/eventpoll.h>
14860 ++#include <linux/grsecurity.h>
14861 +
14862 + #include <asm/uaccess.h>
14863 + #include <asm/mmu_context.h>
14864 +@@ -1298,14 +1299,12 @@ static int compat_copy_strings(int argc,
14865 + if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
14866 + struct page *page;
14867 +
14868 +-#ifdef CONFIG_STACK_GROWSUP
14869 + ret = expand_stack_downwards(bprm->vma, pos);
14870 + if (ret < 0) {
14871 + /* We've exceed the stack rlimit. */
14872 + ret = -E2BIG;
14873 + goto out;
14874 + }
14875 +-#endif
14876 + ret = get_user_pages(current, bprm->mm, pos,
14877 + 1, 1, 1, &page, NULL);
14878 + if (ret <= 0) {
14879 +@@ -1351,6 +1350,11 @@ int compat_do_execve(char * filename,
14880 + compat_uptr_t __user *envp,
14881 + struct pt_regs * regs)
14882 + {
14883 ++#ifdef CONFIG_GRKERNSEC
14884 ++ struct file *old_exec_file;
14885 ++ struct acl_subject_label *old_acl;
14886 ++ struct rlimit old_rlim[RLIM_NLIMITS];
14887 ++#endif
14888 + struct linux_binprm *bprm;
14889 + struct file *file;
14890 + int retval;
14891 +@@ -1371,6 +1375,14 @@ int compat_do_execve(char * filename,
14892 + bprm->filename = filename;
14893 + bprm->interp = filename;
14894 +
14895 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
14896 ++ retval = -EAGAIN;
14897 ++ if (gr_handle_nproc())
14898 ++ goto out_file;
14899 ++ retval = -EACCES;
14900 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
14901 ++ goto out_file;
14902 ++
14903 + retval = bprm_mm_init(bprm);
14904 + if (retval)
14905 + goto out_file;
14906 +@@ -1404,8 +1416,36 @@ int compat_do_execve(char * filename,
14907 + if (retval < 0)
14908 + goto out;
14909 +
14910 ++ if (!gr_tpe_allow(file)) {
14911 ++ retval = -EACCES;
14912 ++ goto out;
14913 ++ }
14914 ++
14915 ++ if (gr_check_crash_exec(file)) {
14916 ++ retval = -EACCES;
14917 ++ goto out;
14918 ++ }
14919 ++
14920 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
14921 ++
14922 ++ gr_handle_exec_args(bprm, (char __user * __user *)argv);
14923 ++
14924 ++#ifdef CONFIG_GRKERNSEC
14925 ++ old_acl = current->acl;
14926 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
14927 ++ old_exec_file = current->exec_file;
14928 ++ get_file(file);
14929 ++ current->exec_file = file;
14930 ++#endif
14931 ++
14932 ++ gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
14933 ++
14934 + retval = search_binary_handler(bprm, regs);
14935 + if (retval >= 0) {
14936 ++#ifdef CONFIG_GRKERNSEC
14937 ++ if (old_exec_file)
14938 ++ fput(old_exec_file);
14939 ++#endif
14940 + /* execve success */
14941 + security_bprm_free(bprm);
14942 + acct_update_integrals(current);
14943 +@@ -1413,6 +1453,13 @@ int compat_do_execve(char * filename,
14944 + return retval;
14945 + }
14946 +
14947 ++#ifdef CONFIG_GRKERNSEC
14948 ++ current->acl = old_acl;
14949 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
14950 ++ fput(current->exec_file);
14951 ++ current->exec_file = old_exec_file;
14952 ++#endif
14953 ++
14954 + out:
14955 + if (bprm->security)
14956 + security_bprm_free(bprm);
14957 +diff -urNp linux-2.6.27.10/fs/compat_ioctl.c linux-2.6.27.10/fs/compat_ioctl.c
14958 +--- linux-2.6.27.10/fs/compat_ioctl.c 2008-11-07 12:55:34.000000000 -0500
14959 ++++ linux-2.6.27.10/fs/compat_ioctl.c 2008-11-18 03:38:45.000000000 -0500
14960 +@@ -1831,15 +1831,15 @@ struct ioctl_trans {
14961 + };
14962 +
14963 + #define HANDLE_IOCTL(cmd,handler) \
14964 +- { (cmd), (ioctl_trans_handler_t)(handler) },
14965 ++ { (cmd), (ioctl_trans_handler_t)(handler), NULL },
14966 +
14967 + /* pointer to compatible structure or no argument */
14968 + #define COMPATIBLE_IOCTL(cmd) \
14969 +- { (cmd), do_ioctl32_pointer },
14970 ++ { (cmd), do_ioctl32_pointer, NULL },
14971 +
14972 + /* argument is an unsigned long integer, not a pointer */
14973 + #define ULONG_IOCTL(cmd) \
14974 +- { (cmd), (ioctl_trans_handler_t)sys_ioctl },
14975 ++ { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL },
14976 +
14977 + /* ioctl should not be warned about even if it's not implemented.
14978 + Valid reasons to use this:
14979 +diff -urNp linux-2.6.27.10/fs/debugfs/inode.c linux-2.6.27.10/fs/debugfs/inode.c
14980 +--- linux-2.6.27.10/fs/debugfs/inode.c 2008-11-07 12:55:34.000000000 -0500
14981 ++++ linux-2.6.27.10/fs/debugfs/inode.c 2008-11-18 03:38:45.000000000 -0500
14982 +@@ -121,7 +121,7 @@ static inline int debugfs_positive(struc
14983 +
14984 + static int debug_fill_super(struct super_block *sb, void *data, int silent)
14985 + {
14986 +- static struct tree_descr debug_files[] = {{""}};
14987 ++ static struct tree_descr debug_files[] = {{"", NULL, 0}};
14988 +
14989 + return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
14990 + }
14991 +diff -urNp linux-2.6.27.10/fs/exec.c linux-2.6.27.10/fs/exec.c
14992 +--- linux-2.6.27.10/fs/exec.c 2008-12-21 01:16:51.000000000 -0500
14993 ++++ linux-2.6.27.10/fs/exec.c 2008-12-21 01:13:46.000000000 -0500
14994 +@@ -50,6 +50,13 @@
14995 + #include <linux/cn_proc.h>
14996 + #include <linux/audit.h>
14997 + #include <linux/tracehook.h>
14998 ++#include <linux/random.h>
14999 ++#include <linux/grsecurity.h>
15000 ++
15001 ++#ifdef CONFIG_PAX_REFCOUNT
15002 ++#include <linux/kallsyms.h>
15003 ++#include <linux/kdebug.h>
15004 ++#endif
15005 +
15006 + #include <asm/uaccess.h>
15007 + #include <asm/mmu_context.h>
15008 +@@ -64,6 +71,11 @@
15009 + #include <linux/a.out.h>
15010 + #endif
15011 +
15012 ++#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
15013 ++void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
15014 ++EXPORT_SYMBOL(pax_set_initial_flags_func);
15015 ++#endif
15016 ++
15017 + int core_uses_pid;
15018 + char core_pattern[CORENAME_MAX_SIZE] = "core";
15019 + int suid_dumpable = 0;
15020 +@@ -172,18 +184,10 @@ static struct page *get_arg_page(struct
15021 + int write)
15022 + {
15023 + struct page *page;
15024 +- int ret;
15025 +
15026 +-#ifdef CONFIG_STACK_GROWSUP
15027 +- if (write) {
15028 +- ret = expand_stack_downwards(bprm->vma, pos);
15029 +- if (ret < 0)
15030 +- return NULL;
15031 +- }
15032 +-#endif
15033 +- ret = get_user_pages(current, bprm->mm, pos,
15034 +- 1, write, 1, &page, NULL);
15035 +- if (ret <= 0)
15036 ++ if (0 > expand_stack_downwards(bprm->vma, pos))
15037 ++ return NULL;
15038 ++ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
15039 + return NULL;
15040 +
15041 + if (write) {
15042 +@@ -256,6 +260,11 @@ static int __bprm_mm_init(struct linux_b
15043 + vma->vm_start = vma->vm_end - PAGE_SIZE;
15044 +
15045 + vma->vm_flags = VM_STACK_FLAGS;
15046 ++
15047 ++#ifdef CONFIG_PAX_SEGMEXEC
15048 ++ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
15049 ++#endif
15050 ++
15051 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
15052 + err = insert_vm_struct(mm, vma);
15053 + if (err) {
15054 +@@ -268,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
15055 +
15056 + bprm->p = vma->vm_end - sizeof(void *);
15057 +
15058 ++#ifdef CONFIG_PAX_RANDUSTACK
15059 ++ if (randomize_va_space)
15060 ++ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
15061 ++#endif
15062 ++
15063 + return 0;
15064 +
15065 + err:
15066 +@@ -391,7 +405,7 @@ static int count(char __user * __user *
15067 + if (!p)
15068 + break;
15069 + argv++;
15070 +- if(++i > max)
15071 ++ if (++i > max)
15072 + return -E2BIG;
15073 + cond_resched();
15074 + }
15075 +@@ -531,6 +545,10 @@ static int shift_arg_pages(struct vm_are
15076 + if (vma != find_vma(mm, new_start))
15077 + return -EFAULT;
15078 +
15079 ++#ifdef CONFIG_PAX_SEGMEXEC
15080 ++ BUG_ON(pax_find_mirror_vma(vma));
15081 ++#endif
15082 ++
15083 + /*
15084 + * cover the whole range: [new_start, old_end)
15085 + */
15086 +@@ -619,6 +637,14 @@ int setup_arg_pages(struct linux_binprm
15087 + bprm->exec -= stack_shift;
15088 +
15089 + down_write(&mm->mmap_sem);
15090 ++
15091 ++ /* Move stack pages down in memory. */
15092 ++ if (stack_shift) {
15093 ++ ret = shift_arg_pages(vma, stack_shift);
15094 ++ if (ret)
15095 ++ goto out_unlock;
15096 ++ }
15097 ++
15098 + vm_flags = VM_STACK_FLAGS;
15099 +
15100 + /*
15101 +@@ -632,21 +658,24 @@ int setup_arg_pages(struct linux_binprm
15102 + vm_flags &= ~VM_EXEC;
15103 + vm_flags |= mm->def_flags;
15104 +
15105 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15106 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
15107 ++ vm_flags &= ~VM_EXEC;
15108 ++
15109 ++#ifdef CONFIG_PAX_MPROTECT
15110 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
15111 ++ vm_flags &= ~VM_MAYEXEC;
15112 ++#endif
15113 ++
15114 ++ }
15115 ++#endif
15116 ++
15117 + ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
15118 + vm_flags);
15119 + if (ret)
15120 + goto out_unlock;
15121 + BUG_ON(prev != vma);
15122 +
15123 +- /* Move stack pages down in memory. */
15124 +- if (stack_shift) {
15125 +- ret = shift_arg_pages(vma, stack_shift);
15126 +- if (ret) {
15127 +- up_write(&mm->mmap_sem);
15128 +- return ret;
15129 +- }
15130 +- }
15131 +-
15132 + #ifdef CONFIG_STACK_GROWSUP
15133 + stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
15134 + #else
15135 +@@ -658,7 +687,7 @@ int setup_arg_pages(struct linux_binprm
15136 +
15137 + out_unlock:
15138 + up_write(&mm->mmap_sem);
15139 +- return 0;
15140 ++ return ret;
15141 + }
15142 + EXPORT_SYMBOL(setup_arg_pages);
15143 +
15144 +@@ -1286,6 +1315,11 @@ int do_execve(char * filename,
15145 + char __user *__user *envp,
15146 + struct pt_regs * regs)
15147 + {
15148 ++#ifdef CONFIG_GRKERNSEC
15149 ++ struct file *old_exec_file;
15150 ++ struct acl_subject_label *old_acl;
15151 ++ struct rlimit old_rlim[RLIM_NLIMITS];
15152 ++#endif
15153 + struct linux_binprm *bprm;
15154 + struct file *file;
15155 + struct files_struct *displaced;
15156 +@@ -1305,6 +1339,20 @@ int do_execve(char * filename,
15157 + if (IS_ERR(file))
15158 + goto out_kfree;
15159 +
15160 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
15161 ++
15162 ++ if (gr_handle_nproc()) {
15163 ++ allow_write_access(file);
15164 ++ fput(file);
15165 ++ return -EAGAIN;
15166 ++ }
15167 ++
15168 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
15169 ++ allow_write_access(file);
15170 ++ fput(file);
15171 ++ return -EACCES;
15172 ++ }
15173 ++
15174 + sched_exec();
15175 +
15176 + bprm->file = file;
15177 +@@ -1344,9 +1392,39 @@ int do_execve(char * filename,
15178 + if (retval < 0)
15179 + goto out;
15180 +
15181 ++ if (!gr_tpe_allow(file)) {
15182 ++ retval = -EACCES;
15183 ++ goto out;
15184 ++ }
15185 ++
15186 ++ if (gr_check_crash_exec(file)) {
15187 ++ retval = -EACCES;
15188 ++ goto out;
15189 ++ }
15190 ++
15191 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
15192 ++
15193 ++ gr_handle_exec_args(bprm, argv);
15194 ++
15195 ++#ifdef CONFIG_GRKERNSEC
15196 ++ old_acl = current->acl;
15197 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
15198 ++ old_exec_file = current->exec_file;
15199 ++ get_file(file);
15200 ++ current->exec_file = file;
15201 ++#endif
15202 ++
15203 ++ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
15204 ++ if (retval < 0)
15205 ++ goto out_fail;
15206 ++
15207 + current->flags &= ~PF_KTHREAD;
15208 + retval = search_binary_handler(bprm,regs);
15209 + if (retval >= 0) {
15210 ++#ifdef CONFIG_GRKERNSEC
15211 ++ if (old_exec_file)
15212 ++ fput(old_exec_file);
15213 ++#endif
15214 + /* execve success */
15215 + security_bprm_free(bprm);
15216 + acct_update_integrals(current);
15217 +@@ -1356,6 +1434,14 @@ int do_execve(char * filename,
15218 + return retval;
15219 + }
15220 +
15221 ++out_fail:
15222 ++#ifdef CONFIG_GRKERNSEC
15223 ++ current->acl = old_acl;
15224 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
15225 ++ fput(current->exec_file);
15226 ++ current->exec_file = old_exec_file;
15227 ++#endif
15228 ++
15229 + out:
15230 + if (bprm->security)
15231 + security_bprm_free(bprm);
15232 +@@ -1519,6 +1605,125 @@ out:
15233 + return ispipe;
15234 + }
15235 +
15236 ++int pax_check_flags(unsigned long *flags)
15237 ++{
15238 ++ int retval = 0;
15239 ++
15240 ++#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
15241 ++ if (*flags & MF_PAX_SEGMEXEC)
15242 ++ {
15243 ++ *flags &= ~MF_PAX_SEGMEXEC;
15244 ++ retval = -EINVAL;
15245 ++ }
15246 ++#endif
15247 ++
15248 ++ if ((*flags & MF_PAX_PAGEEXEC)
15249 ++
15250 ++#ifdef CONFIG_PAX_PAGEEXEC
15251 ++ && (*flags & MF_PAX_SEGMEXEC)
15252 ++#endif
15253 ++
15254 ++ )
15255 ++ {
15256 ++ *flags &= ~MF_PAX_PAGEEXEC;
15257 ++ retval = -EINVAL;
15258 ++ }
15259 ++
15260 ++ if ((*flags & MF_PAX_MPROTECT)
15261 ++
15262 ++#ifdef CONFIG_PAX_MPROTECT
15263 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15264 ++#endif
15265 ++
15266 ++ )
15267 ++ {
15268 ++ *flags &= ~MF_PAX_MPROTECT;
15269 ++ retval = -EINVAL;
15270 ++ }
15271 ++
15272 ++ if ((*flags & MF_PAX_EMUTRAMP)
15273 ++
15274 ++#ifdef CONFIG_PAX_EMUTRAMP
15275 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15276 ++#endif
15277 ++
15278 ++ )
15279 ++ {
15280 ++ *flags &= ~MF_PAX_EMUTRAMP;
15281 ++ retval = -EINVAL;
15282 ++ }
15283 ++
15284 ++ return retval;
15285 ++}
15286 ++
15287 ++EXPORT_SYMBOL(pax_check_flags);
15288 ++
15289 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15290 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
15291 ++{
15292 ++ struct task_struct *tsk = current;
15293 ++ struct mm_struct *mm = current->mm;
15294 ++ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
15295 ++ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
15296 ++ char *path_exec = NULL;
15297 ++ char *path_fault = NULL;
15298 ++ unsigned long start = 0UL, end = 0UL, offset = 0UL;
15299 ++
15300 ++ if (buffer_exec && buffer_fault) {
15301 ++ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
15302 ++
15303 ++ down_read(&mm->mmap_sem);
15304 ++ vma = mm->mmap;
15305 ++ while (vma && (!vma_exec || !vma_fault)) {
15306 ++ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
15307 ++ vma_exec = vma;
15308 ++ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
15309 ++ vma_fault = vma;
15310 ++ vma = vma->vm_next;
15311 ++ }
15312 ++ if (vma_exec) {
15313 ++ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
15314 ++ if (IS_ERR(path_exec))
15315 ++ path_exec = "<path too long>";
15316 ++ }
15317 ++ if (vma_fault) {
15318 ++ start = vma_fault->vm_start;
15319 ++ end = vma_fault->vm_end;
15320 ++ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
15321 ++ if (vma_fault->vm_file) {
15322 ++ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
15323 ++ if (IS_ERR(path_fault))
15324 ++ path_fault = "<path too long>";
15325 ++ } else
15326 ++ path_fault = "<anonymous mapping>";
15327 ++ }
15328 ++ up_read(&mm->mmap_sem);
15329 ++ }
15330 ++ if (tsk->signal->curr_ip)
15331 ++ 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);
15332 ++ else
15333 ++ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
15334 ++ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
15335 ++ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
15336 ++ tsk->uid, tsk->euid, pc, sp);
15337 ++ free_page((unsigned long)buffer_exec);
15338 ++ free_page((unsigned long)buffer_fault);
15339 ++ pax_report_insns(pc, sp);
15340 ++ do_coredump(SIGKILL, SIGKILL, regs);
15341 ++}
15342 ++#endif
15343 ++
15344 ++#ifdef CONFIG_PAX_REFCOUNT
15345 ++void pax_report_refcount_overflow(struct pt_regs *regs)
15346 ++{
15347 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
15348 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
15349 ++ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
15350 ++ show_registers(regs);
15351 ++ force_sig_specific(SIGKILL, current);
15352 ++}
15353 ++#endif
15354 ++
15355 + static int zap_process(struct task_struct *start)
15356 + {
15357 + struct task_struct *t;
15358 +@@ -1765,6 +1970,10 @@ int do_coredump(long signr, int exit_cod
15359 + */
15360 + clear_thread_flag(TIF_SIGPENDING);
15361 +
15362 ++ if (signr == SIGKILL || signr == SIGILL)
15363 ++ gr_handle_brute_attach(current);
15364 ++ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
15365 ++
15366 + /*
15367 + * lock_kernel() because format_corename() is controlled by sysctl, which
15368 + * uses lock_kernel()
15369 +@@ -1785,6 +1994,8 @@ int do_coredump(long signr, int exit_cod
15370 +
15371 + if (ispipe) {
15372 + helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
15373 ++ if (!helper_argv)
15374 ++ goto fail_unlock;
15375 + /* Terminate the string before the first option */
15376 + delimit = strchr(corename, ' ');
15377 + if (delimit)
15378 +diff -urNp linux-2.6.27.10/fs/ext2/balloc.c linux-2.6.27.10/fs/ext2/balloc.c
15379 +--- linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:37.000000000 -0500
15380 ++++ linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:46.000000000 -0500
15381 +@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
15382 +
15383 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15384 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15385 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15386 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15387 + sbi->s_resuid != current->fsuid &&
15388 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15389 + return 0;
15390 +diff -urNp linux-2.6.27.10/fs/ext3/balloc.c linux-2.6.27.10/fs/ext3/balloc.c
15391 +--- linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:37.000000000 -0500
15392 ++++ linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:46.000000000 -0500
15393 +@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
15394 +
15395 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15396 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15397 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15398 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15399 + sbi->s_resuid != current->fsuid &&
15400 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15401 + return 0;
15402 +diff -urNp linux-2.6.27.10/fs/ext3/namei.c linux-2.6.27.10/fs/ext3/namei.c
15403 +--- linux-2.6.27.10/fs/ext3/namei.c 2008-11-07 12:55:34.000000000 -0500
15404 ++++ linux-2.6.27.10/fs/ext3/namei.c 2008-11-18 03:38:45.000000000 -0500
15405 +@@ -1173,9 +1173,9 @@ static struct ext3_dir_entry_2 *do_split
15406 + u32 hash2;
15407 + struct dx_map_entry *map;
15408 + char *data1 = (*bh)->b_data, *data2;
15409 +- unsigned split, move, size, i;
15410 ++ unsigned split, move, size;
15411 + struct ext3_dir_entry_2 *de = NULL, *de2;
15412 +- int err = 0;
15413 ++ int i, err = 0;
15414 +
15415 + bh2 = ext3_append (handle, dir, &newblock, &err);
15416 + if (!(bh2)) {
15417 +diff -urNp linux-2.6.27.10/fs/ext3/xattr.c linux-2.6.27.10/fs/ext3/xattr.c
15418 +--- linux-2.6.27.10/fs/ext3/xattr.c 2008-11-07 12:55:34.000000000 -0500
15419 ++++ linux-2.6.27.10/fs/ext3/xattr.c 2008-11-18 03:38:45.000000000 -0500
15420 +@@ -89,8 +89,8 @@
15421 + printk("\n"); \
15422 + } while (0)
15423 + #else
15424 +-# define ea_idebug(f...)
15425 +-# define ea_bdebug(f...)
15426 ++# define ea_idebug(f...) do {} while (0)
15427 ++# define ea_bdebug(f...) do {} while (0)
15428 + #endif
15429 +
15430 + static void ext3_xattr_cache_insert(struct buffer_head *);
15431 +diff -urNp linux-2.6.27.10/fs/ext4/balloc.c linux-2.6.27.10/fs/ext4/balloc.c
15432 +--- linux-2.6.27.10/fs/ext4/balloc.c 2008-11-07 12:55:34.000000000 -0500
15433 ++++ linux-2.6.27.10/fs/ext4/balloc.c 2008-11-18 03:38:45.000000000 -0500
15434 +@@ -1617,7 +1617,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct
15435 +
15436 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15437 +
15438 +- if (!capable(CAP_SYS_RESOURCE) &&
15439 ++ if (!capable_nolog(CAP_SYS_RESOURCE) &&
15440 + sbi->s_resuid != current->fsuid &&
15441 + (sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
15442 + root_blocks = ext4_r_blocks_count(sbi->s_es);
15443 +diff -urNp linux-2.6.27.10/fs/ext4/namei.c linux-2.6.27.10/fs/ext4/namei.c
15444 +--- linux-2.6.27.10/fs/ext4/namei.c 2008-11-07 12:55:34.000000000 -0500
15445 ++++ linux-2.6.27.10/fs/ext4/namei.c 2008-11-18 03:38:45.000000000 -0500
15446 +@@ -1176,9 +1176,9 @@ static struct ext4_dir_entry_2 *do_split
15447 + u32 hash2;
15448 + struct dx_map_entry *map;
15449 + char *data1 = (*bh)->b_data, *data2;
15450 +- unsigned split, move, size, i;
15451 ++ unsigned split, move, size;
15452 + struct ext4_dir_entry_2 *de = NULL, *de2;
15453 +- int err = 0;
15454 ++ int i, err = 0;
15455 +
15456 + bh2 = ext4_append (handle, dir, &newblock, &err);
15457 + if (!(bh2)) {
15458 +diff -urNp linux-2.6.27.10/fs/fcntl.c linux-2.6.27.10/fs/fcntl.c
15459 +--- linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:16:51.000000000 -0500
15460 ++++ linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:14:31.000000000 -0500
15461 +@@ -19,6 +19,7 @@
15462 + #include <linux/signal.h>
15463 + #include <linux/rcupdate.h>
15464 + #include <linux/pid_namespace.h>
15465 ++#include <linux/grsecurity.h>
15466 + #include <linux/smp_lock.h>
15467 +
15468 + #include <asm/poll.h>
15469 +@@ -266,6 +267,7 @@ static long do_fcntl(int fd, unsigned in
15470 + switch (cmd) {
15471 + case F_DUPFD:
15472 + case F_DUPFD_CLOEXEC:
15473 ++ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
15474 + if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15475 + break;
15476 + err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
15477 +@@ -410,7 +412,8 @@ static inline int sigio_perm(struct task
15478 + return (((fown->euid == 0) ||
15479 + (fown->euid == p->suid) || (fown->euid == p->uid) ||
15480 + (fown->uid == p->suid) || (fown->uid == p->uid)) &&
15481 +- !security_file_send_sigiotask(p, fown, sig));
15482 ++ !security_file_send_sigiotask(p, fown, sig) &&
15483 ++ !gr_check_protected_task(p) && !gr_pid_is_chrooted(p));
15484 + }
15485 +
15486 + static void send_sigio_to_task(struct task_struct *p,
15487 +diff -urNp linux-2.6.27.10/fs/file.c linux-2.6.27.10/fs/file.c
15488 +--- linux-2.6.27.10/fs/file.c 2008-11-07 12:55:34.000000000 -0500
15489 ++++ linux-2.6.27.10/fs/file.c 2008-11-18 03:38:45.000000000 -0500
15490 +@@ -19,6 +19,7 @@
15491 + #include <linux/spinlock.h>
15492 + #include <linux/rcupdate.h>
15493 + #include <linux/workqueue.h>
15494 ++#include <linux/grsecurity.h>
15495 +
15496 + struct fdtable_defer {
15497 + spinlock_t lock;
15498 +@@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi
15499 + * N.B. For clone tasks sharing a files structure, this test
15500 + * will limit the total number of files that can be opened.
15501 + */
15502 ++
15503 ++ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
15504 + if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15505 + return -EMFILE;
15506 +
15507 +diff -urNp linux-2.6.27.10/fs/fuse/control.c linux-2.6.27.10/fs/fuse/control.c
15508 +--- linux-2.6.27.10/fs/fuse/control.c 2008-11-07 12:55:34.000000000 -0500
15509 ++++ linux-2.6.27.10/fs/fuse/control.c 2008-11-18 03:38:45.000000000 -0500
15510 +@@ -159,7 +159,7 @@ void fuse_ctl_remove_conn(struct fuse_co
15511 +
15512 + static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
15513 + {
15514 +- struct tree_descr empty_descr = {""};
15515 ++ struct tree_descr empty_descr = {"", NULL, 0};
15516 + struct fuse_conn *fc;
15517 + int err;
15518 +
15519 +diff -urNp linux-2.6.27.10/fs/fuse/dir.c linux-2.6.27.10/fs/fuse/dir.c
15520 +--- linux-2.6.27.10/fs/fuse/dir.c 2008-11-07 12:55:34.000000000 -0500
15521 ++++ linux-2.6.27.10/fs/fuse/dir.c 2008-11-18 03:38:45.000000000 -0500
15522 +@@ -1072,7 +1072,7 @@ static char *read_link(struct dentry *de
15523 + return link;
15524 + }
15525 +
15526 +-static void free_link(char *link)
15527 ++static void free_link(const char *link)
15528 + {
15529 + if (!IS_ERR(link))
15530 + free_page((unsigned long) link);
15531 +diff -urNp linux-2.6.27.10/fs/hfs/inode.c linux-2.6.27.10/fs/hfs/inode.c
15532 +--- linux-2.6.27.10/fs/hfs/inode.c 2008-11-07 12:55:34.000000000 -0500
15533 ++++ linux-2.6.27.10/fs/hfs/inode.c 2008-11-18 03:38:45.000000000 -0500
15534 +@@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode,
15535 +
15536 + if (S_ISDIR(main_inode->i_mode)) {
15537 + if (fd.entrylength < sizeof(struct hfs_cat_dir))
15538 +- /* panic? */;
15539 ++ {/* panic? */}
15540 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15541 + sizeof(struct hfs_cat_dir));
15542 + if (rec.type != HFS_CDR_DIR ||
15543 +@@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode,
15544 + sizeof(struct hfs_cat_file));
15545 + } else {
15546 + if (fd.entrylength < sizeof(struct hfs_cat_file))
15547 +- /* panic? */;
15548 ++ {/* panic? */}
15549 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15550 + sizeof(struct hfs_cat_file));
15551 + if (rec.type != HFS_CDR_FIL ||
15552 +diff -urNp linux-2.6.27.10/fs/hfsplus/inode.c linux-2.6.27.10/fs/hfsplus/inode.c
15553 +--- linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-07 12:55:34.000000000 -0500
15554 ++++ linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-18 03:38:45.000000000 -0500
15555 +@@ -417,7 +417,7 @@ int hfsplus_cat_read_inode(struct inode
15556 + struct hfsplus_cat_folder *folder = &entry.folder;
15557 +
15558 + if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
15559 +- /* panic? */;
15560 ++ {/* panic? */}
15561 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15562 + sizeof(struct hfsplus_cat_folder));
15563 + hfsplus_get_perms(inode, &folder->permissions, 1);
15564 +@@ -434,7 +434,7 @@ int hfsplus_cat_read_inode(struct inode
15565 + struct hfsplus_cat_file *file = &entry.file;
15566 +
15567 + if (fd->entrylength < sizeof(struct hfsplus_cat_file))
15568 +- /* panic? */;
15569 ++ {/* panic? */}
15570 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15571 + sizeof(struct hfsplus_cat_file));
15572 +
15573 +@@ -490,7 +490,7 @@ int hfsplus_cat_write_inode(struct inode
15574 + struct hfsplus_cat_folder *folder = &entry.folder;
15575 +
15576 + if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
15577 +- /* panic? */;
15578 ++ {/* panic? */}
15579 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15580 + sizeof(struct hfsplus_cat_folder));
15581 + /* simple node checks? */
15582 +@@ -512,7 +512,7 @@ int hfsplus_cat_write_inode(struct inode
15583 + struct hfsplus_cat_file *file = &entry.file;
15584 +
15585 + if (fd.entrylength < sizeof(struct hfsplus_cat_file))
15586 +- /* panic? */;
15587 ++ {/* panic? */}
15588 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15589 + sizeof(struct hfsplus_cat_file));
15590 + hfsplus_inode_write_fork(inode, &file->data_fork);
15591 +diff -urNp linux-2.6.27.10/fs/jffs2/debug.h linux-2.6.27.10/fs/jffs2/debug.h
15592 +--- linux-2.6.27.10/fs/jffs2/debug.h 2008-11-07 12:55:34.000000000 -0500
15593 ++++ linux-2.6.27.10/fs/jffs2/debug.h 2008-11-18 03:38:45.000000000 -0500
15594 +@@ -52,13 +52,13 @@
15595 + #if CONFIG_JFFS2_FS_DEBUG > 0
15596 + #define D1(x) x
15597 + #else
15598 +-#define D1(x)
15599 ++#define D1(x) do {} while (0);
15600 + #endif
15601 +
15602 + #if CONFIG_JFFS2_FS_DEBUG > 1
15603 + #define D2(x) x
15604 + #else
15605 +-#define D2(x)
15606 ++#define D2(x) do {} while (0);
15607 + #endif
15608 +
15609 + /* The prefixes of JFFS2 messages */
15610 +@@ -114,73 +114,73 @@
15611 + #ifdef JFFS2_DBG_READINODE_MESSAGES
15612 + #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15613 + #else
15614 +-#define dbg_readinode(fmt, ...)
15615 ++#define dbg_readinode(fmt, ...) do {} while (0)
15616 + #endif
15617 + #ifdef JFFS2_DBG_READINODE2_MESSAGES
15618 + #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15619 + #else
15620 +-#define dbg_readinode2(fmt, ...)
15621 ++#define dbg_readinode2(fmt, ...) do {} while (0)
15622 + #endif
15623 +
15624 + /* Fragtree build debugging messages */
15625 + #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
15626 + #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15627 + #else
15628 +-#define dbg_fragtree(fmt, ...)
15629 ++#define dbg_fragtree(fmt, ...) do {} while (0)
15630 + #endif
15631 + #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
15632 + #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15633 + #else
15634 +-#define dbg_fragtree2(fmt, ...)
15635 ++#define dbg_fragtree2(fmt, ...) do {} while (0)
15636 + #endif
15637 +
15638 + /* Directory entry list manilulation debugging messages */
15639 + #ifdef JFFS2_DBG_DENTLIST_MESSAGES
15640 + #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15641 + #else
15642 +-#define dbg_dentlist(fmt, ...)
15643 ++#define dbg_dentlist(fmt, ...) do {} while (0)
15644 + #endif
15645 +
15646 + /* Print the messages about manipulating node_refs */
15647 + #ifdef JFFS2_DBG_NODEREF_MESSAGES
15648 + #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15649 + #else
15650 +-#define dbg_noderef(fmt, ...)
15651 ++#define dbg_noderef(fmt, ...) do {} while (0)
15652 + #endif
15653 +
15654 + /* Manipulations with the list of inodes (JFFS2 inocache) */
15655 + #ifdef JFFS2_DBG_INOCACHE_MESSAGES
15656 + #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15657 + #else
15658 +-#define dbg_inocache(fmt, ...)
15659 ++#define dbg_inocache(fmt, ...) do {} while (0)
15660 + #endif
15661 +
15662 + /* Summary debugging messages */
15663 + #ifdef JFFS2_DBG_SUMMARY_MESSAGES
15664 + #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15665 + #else
15666 +-#define dbg_summary(fmt, ...)
15667 ++#define dbg_summary(fmt, ...) do {} while (0)
15668 + #endif
15669 +
15670 + /* File system build messages */
15671 + #ifdef JFFS2_DBG_FSBUILD_MESSAGES
15672 + #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15673 + #else
15674 +-#define dbg_fsbuild(fmt, ...)
15675 ++#define dbg_fsbuild(fmt, ...) do {} while (0)
15676 + #endif
15677 +
15678 + /* Watch the object allocations */
15679 + #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
15680 + #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15681 + #else
15682 +-#define dbg_memalloc(fmt, ...)
15683 ++#define dbg_memalloc(fmt, ...) do {} while (0)
15684 + #endif
15685 +
15686 + /* Watch the XATTR subsystem */
15687 + #ifdef JFFS2_DBG_XATTR_MESSAGES
15688 + #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15689 + #else
15690 +-#define dbg_xattr(fmt, ...)
15691 ++#define dbg_xattr(fmt, ...) do {} while (0)
15692 + #endif
15693 +
15694 + /* "Sanity" checks */
15695 +diff -urNp linux-2.6.27.10/fs/jffs2/erase.c linux-2.6.27.10/fs/jffs2/erase.c
15696 +--- linux-2.6.27.10/fs/jffs2/erase.c 2008-11-07 12:55:34.000000000 -0500
15697 ++++ linux-2.6.27.10/fs/jffs2/erase.c 2008-11-18 03:38:45.000000000 -0500
15698 +@@ -431,7 +431,8 @@ static void jffs2_mark_erased_block(stru
15699 + struct jffs2_unknown_node marker = {
15700 + .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
15701 + .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15702 +- .totlen = cpu_to_je32(c->cleanmarker_size)
15703 ++ .totlen = cpu_to_je32(c->cleanmarker_size),
15704 ++ .hdr_crc = cpu_to_je32(0)
15705 + };
15706 +
15707 + jffs2_prealloc_raw_node_refs(c, jeb, 1);
15708 +diff -urNp linux-2.6.27.10/fs/jffs2/summary.h linux-2.6.27.10/fs/jffs2/summary.h
15709 +--- linux-2.6.27.10/fs/jffs2/summary.h 2008-11-07 12:55:34.000000000 -0500
15710 ++++ linux-2.6.27.10/fs/jffs2/summary.h 2008-11-18 03:38:45.000000000 -0500
15711 +@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
15712 +
15713 + #define jffs2_sum_active() (0)
15714 + #define jffs2_sum_init(a) (0)
15715 +-#define jffs2_sum_exit(a)
15716 +-#define jffs2_sum_disable_collecting(a)
15717 ++#define jffs2_sum_exit(a) do {} while (0)
15718 ++#define jffs2_sum_disable_collecting(a) do {} while (0)
15719 + #define jffs2_sum_is_disabled(a) (0)
15720 +-#define jffs2_sum_reset_collected(a)
15721 ++#define jffs2_sum_reset_collected(a) do {} while (0)
15722 + #define jffs2_sum_add_kvec(a,b,c,d) (0)
15723 +-#define jffs2_sum_move_collected(a,b)
15724 ++#define jffs2_sum_move_collected(a,b) do {} while (0)
15725 + #define jffs2_sum_write_sumnode(a) (0)
15726 +-#define jffs2_sum_add_padding_mem(a,b)
15727 +-#define jffs2_sum_add_inode_mem(a,b,c)
15728 +-#define jffs2_sum_add_dirent_mem(a,b,c)
15729 +-#define jffs2_sum_add_xattr_mem(a,b,c)
15730 +-#define jffs2_sum_add_xref_mem(a,b,c)
15731 ++#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
15732 ++#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
15733 ++#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
15734 ++#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
15735 ++#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
15736 + #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
15737 +
15738 + #endif /* CONFIG_JFFS2_SUMMARY */
15739 +diff -urNp linux-2.6.27.10/fs/jffs2/wbuf.c linux-2.6.27.10/fs/jffs2/wbuf.c
15740 +--- linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-07 12:55:34.000000000 -0500
15741 ++++ linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-18 03:38:45.000000000 -0500
15742 +@@ -1015,7 +1015,8 @@ static const struct jffs2_unknown_node o
15743 + {
15744 + .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
15745 + .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15746 +- .totlen = constant_cpu_to_je32(8)
15747 ++ .totlen = constant_cpu_to_je32(8),
15748 ++ .hdr_crc = constant_cpu_to_je32(0)
15749 + };
15750 +
15751 + /*
15752 +diff -urNp linux-2.6.27.10/fs/locks.c linux-2.6.27.10/fs/locks.c
15753 +--- linux-2.6.27.10/fs/locks.c 2008-11-07 12:55:34.000000000 -0500
15754 ++++ linux-2.6.27.10/fs/locks.c 2008-11-18 03:38:45.000000000 -0500
15755 +@@ -2005,16 +2005,16 @@ void locks_remove_flock(struct file *fil
15756 + return;
15757 +
15758 + if (filp->f_op && filp->f_op->flock) {
15759 +- struct file_lock fl = {
15760 ++ struct file_lock flock = {
15761 + .fl_pid = current->tgid,
15762 + .fl_file = filp,
15763 + .fl_flags = FL_FLOCK,
15764 + .fl_type = F_UNLCK,
15765 + .fl_end = OFFSET_MAX,
15766 + };
15767 +- filp->f_op->flock(filp, F_SETLKW, &fl);
15768 +- if (fl.fl_ops && fl.fl_ops->fl_release_private)
15769 +- fl.fl_ops->fl_release_private(&fl);
15770 ++ filp->f_op->flock(filp, F_SETLKW, &flock);
15771 ++ if (flock.fl_ops && flock.fl_ops->fl_release_private)
15772 ++ flock.fl_ops->fl_release_private(&flock);
15773 + }
15774 +
15775 + lock_kernel();
15776 +diff -urNp linux-2.6.27.10/fs/namei.c linux-2.6.27.10/fs/namei.c
15777 +--- linux-2.6.27.10/fs/namei.c 2008-11-07 12:55:34.000000000 -0500
15778 ++++ linux-2.6.27.10/fs/namei.c 2008-11-18 04:47:57.000000000 -0500
15779 +@@ -31,6 +31,8 @@
15780 + #include <linux/file.h>
15781 + #include <linux/fcntl.h>
15782 + #include <linux/device_cgroup.h>
15783 ++#include <linux/grsecurity.h>
15784 ++
15785 + #include <asm/uaccess.h>
15786 +
15787 + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
15788 +@@ -646,7 +648,7 @@ static __always_inline int __do_follow_l
15789 + cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
15790 + error = PTR_ERR(cookie);
15791 + if (!IS_ERR(cookie)) {
15792 +- char *s = nd_get_link(nd);
15793 ++ const char *s = nd_get_link(nd);
15794 + error = 0;
15795 + if (s)
15796 + error = __vfs_follow_link(nd, s);
15797 +@@ -677,6 +679,13 @@ static inline int do_follow_link(struct
15798 + err = security_inode_follow_link(path->dentry, nd);
15799 + if (err)
15800 + goto loop;
15801 ++
15802 ++ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
15803 ++ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
15804 ++ err = -EACCES;
15805 ++ goto loop;
15806 ++ }
15807 ++
15808 + current->link_count++;
15809 + current->total_link_count++;
15810 + nd->depth++;
15811 +@@ -1025,11 +1034,18 @@ return_reval:
15812 + break;
15813 + }
15814 + return_base:
15815 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
15816 ++ path_put(&nd->path);
15817 ++ return -ENOENT;
15818 ++ }
15819 + return 0;
15820 + out_dput:
15821 + path_put_conditional(&next, nd);
15822 + break;
15823 + }
15824 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
15825 ++ err = -ENOENT;
15826 ++
15827 + path_put(&nd->path);
15828 + return_err:
15829 + return err;
15830 +@@ -1613,9 +1629,17 @@ static int __open_namei_create(struct na
15831 + int error;
15832 + struct dentry *dir = nd->path.dentry;
15833 +
15834 ++ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
15835 ++ error = -EACCES;
15836 ++ goto out_unlock_dput;
15837 ++ }
15838 ++
15839 + if (!IS_POSIXACL(dir->d_inode))
15840 + mode &= ~current->fs->umask;
15841 + error = vfs_create(dir->d_inode, path->dentry, mode, nd);
15842 ++ if (!error)
15843 ++ gr_handle_create(path->dentry, nd->path.mnt);
15844 ++out_unlock_dput:
15845 + mutex_unlock(&dir->d_inode->i_mutex);
15846 + dput(nd->path.dentry);
15847 + nd->path.dentry = path->dentry;
15848 +@@ -1696,6 +1720,17 @@ struct file *do_filp_open(int dfd, const
15849 + &nd, flag);
15850 + if (error)
15851 + return ERR_PTR(error);
15852 ++
15853 ++ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
15854 ++ error = -EPERM;
15855 ++ goto exit;
15856 ++ }
15857 ++
15858 ++ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
15859 ++ error = -EACCES;
15860 ++ goto exit;
15861 ++ }
15862 ++
15863 + goto ok;
15864 + }
15865 +
15866 +@@ -1759,6 +1794,20 @@ do_last:
15867 + /*
15868 + * It already exists.
15869 + */
15870 ++
15871 ++ if (gr_handle_rawio(path.dentry->d_inode)) {
15872 ++ error = -EPERM;
15873 ++ goto exit_mutex_unlock;
15874 ++ }
15875 ++ if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) {
15876 ++ error = -EACCES;
15877 ++ goto exit_mutex_unlock;
15878 ++ }
15879 ++ if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) {
15880 ++ error = -EACCES;
15881 ++ goto exit_mutex_unlock;
15882 ++ }
15883 ++
15884 + mutex_unlock(&dir->d_inode->i_mutex);
15885 + audit_inode(pathname, path.dentry);
15886 +
15887 +@@ -1843,6 +1892,13 @@ do_link:
15888 + error = security_inode_follow_link(path.dentry, &nd);
15889 + if (error)
15890 + goto exit_dput;
15891 ++
15892 ++ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
15893 ++ path.dentry, nd.path.mnt)) {
15894 ++ error = -EACCES;
15895 ++ goto exit_dput;
15896 ++ }
15897 ++
15898 + error = __do_follow_link(&path, &nd);
15899 + if (error) {
15900 + /* Does someone understand code flow here? Or it is only
15901 +@@ -2015,9 +2071,21 @@ asmlinkage long sys_mknodat(int dfd, con
15902 + error = may_mknod(mode);
15903 + if (error)
15904 + goto out_dput;
15905 ++
15906 ++ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
15907 ++ error = -EPERM;
15908 ++ goto out_dput;
15909 ++ }
15910 ++
15911 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
15912 ++ error = -EACCES;
15913 ++ goto out_dput;
15914 ++ }
15915 ++
15916 + error = mnt_want_write(nd.path.mnt);
15917 + if (error)
15918 + goto out_dput;
15919 ++
15920 + switch (mode & S_IFMT) {
15921 + case 0: case S_IFREG:
15922 + error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
15923 +@@ -2031,6 +2099,9 @@ asmlinkage long sys_mknodat(int dfd, con
15924 + break;
15925 + }
15926 + mnt_drop_write(nd.path.mnt);
15927 ++
15928 ++ if (!error)
15929 ++ gr_handle_create(dentry, nd.path.mnt);
15930 + out_dput:
15931 + dput(dentry);
15932 + out_unlock:
15933 +@@ -2084,6 +2155,11 @@ asmlinkage long sys_mkdirat(int dfd, con
15934 + if (IS_ERR(dentry))
15935 + goto out_unlock;
15936 +
15937 ++ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
15938 ++ error = -EACCES;
15939 ++ goto out_dput;
15940 ++ }
15941 ++
15942 + if (!IS_POSIXACL(nd.path.dentry->d_inode))
15943 + mode &= ~current->fs->umask;
15944 + error = mnt_want_write(nd.path.mnt);
15945 +@@ -2091,6 +2167,10 @@ asmlinkage long sys_mkdirat(int dfd, con
15946 + goto out_dput;
15947 + error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
15948 + mnt_drop_write(nd.path.mnt);
15949 ++
15950 ++ if (!error)
15951 ++ gr_handle_create(dentry, nd.path.mnt);
15952 ++
15953 + out_dput:
15954 + dput(dentry);
15955 + out_unlock:
15956 +@@ -2172,6 +2252,8 @@ static long do_rmdir(int dfd, const char
15957 + char * name;
15958 + struct dentry *dentry;
15959 + struct nameidata nd;
15960 ++ ino_t saved_ino = 0;
15961 ++ dev_t saved_dev = 0;
15962 +
15963 + error = user_path_parent(dfd, pathname, &nd, &name);
15964 + if (error)
15965 +@@ -2193,11 +2275,26 @@ static long do_rmdir(int dfd, const char
15966 + error = PTR_ERR(dentry);
15967 + if (IS_ERR(dentry))
15968 + goto exit2;
15969 ++
15970 ++ if (dentry->d_inode != NULL) {
15971 ++ if (dentry->d_inode->i_nlink <= 1) {
15972 ++ saved_ino = dentry->d_inode->i_ino;
15973 ++ saved_dev = dentry->d_inode->i_sb->s_dev;
15974 ++ }
15975 ++
15976 ++ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
15977 ++ error = -EACCES;
15978 ++ goto exit3;
15979 ++ }
15980 ++ }
15981 ++
15982 + error = mnt_want_write(nd.path.mnt);
15983 + if (error)
15984 + goto exit3;
15985 + error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
15986 + mnt_drop_write(nd.path.mnt);
15987 ++ if (!error && (saved_dev || saved_ino))
15988 ++ gr_handle_delete(saved_ino, saved_dev);
15989 + exit3:
15990 + dput(dentry);
15991 + exit2:
15992 +@@ -2257,6 +2354,8 @@ static long do_unlinkat(int dfd, const c
15993 + struct dentry *dentry;
15994 + struct nameidata nd;
15995 + struct inode *inode = NULL;
15996 ++ ino_t saved_ino = 0;
15997 ++ dev_t saved_dev = 0;
15998 +
15999 + error = user_path_parent(dfd, pathname, &nd, &name);
16000 + if (error)
16001 +@@ -2273,12 +2372,25 @@ static long do_unlinkat(int dfd, const c
16002 + if (nd.last.name[nd.last.len])
16003 + goto slashes;
16004 + inode = dentry->d_inode;
16005 +- if (inode)
16006 ++ if (inode) {
16007 ++ if (inode->i_nlink <= 1) {
16008 ++ saved_ino = inode->i_ino;
16009 ++ saved_dev = inode->i_sb->s_dev;
16010 ++ }
16011 ++
16012 + atomic_inc(&inode->i_count);
16013 ++
16014 ++ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
16015 ++ error = -EACCES;
16016 ++ goto exit2;
16017 ++ }
16018 ++ }
16019 + error = mnt_want_write(nd.path.mnt);
16020 + if (error)
16021 + goto exit2;
16022 + error = vfs_unlink(nd.path.dentry->d_inode, dentry);
16023 ++ if (!error && (saved_ino || saved_dev))
16024 ++ gr_handle_delete(saved_ino, saved_dev);
16025 + mnt_drop_write(nd.path.mnt);
16026 + exit2:
16027 + dput(dentry);
16028 +@@ -2356,10 +2468,17 @@ asmlinkage long sys_symlinkat(const char
16029 + if (IS_ERR(dentry))
16030 + goto out_unlock;
16031 +
16032 ++ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
16033 ++ error = -EACCES;
16034 ++ goto out_dput;
16035 ++ }
16036 ++
16037 + error = mnt_want_write(nd.path.mnt);
16038 + if (error)
16039 + goto out_dput;
16040 + error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
16041 ++ if (!error)
16042 ++ gr_handle_create(dentry, nd.path.mnt);
16043 + mnt_drop_write(nd.path.mnt);
16044 + out_dput:
16045 + dput(dentry);
16046 +@@ -2453,10 +2572,26 @@ asmlinkage long sys_linkat(int olddfd, c
16047 + error = PTR_ERR(new_dentry);
16048 + if (IS_ERR(new_dentry))
16049 + goto out_unlock;
16050 ++
16051 ++ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
16052 ++ old_path.dentry->d_inode,
16053 ++ old_path.dentry->d_inode->i_mode, to)) {
16054 ++ error = -EACCES;
16055 ++ goto out_dput;
16056 ++ }
16057 ++
16058 ++ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
16059 ++ old_path.dentry, old_path.mnt, to)) {
16060 ++ error = -EACCES;
16061 ++ goto out_dput;
16062 ++ }
16063 ++
16064 + error = mnt_want_write(nd.path.mnt);
16065 + if (error)
16066 + goto out_dput;
16067 + error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
16068 ++ if (!error)
16069 ++ gr_handle_create(new_dentry, nd.path.mnt);
16070 + mnt_drop_write(nd.path.mnt);
16071 + out_dput:
16072 + dput(new_dentry);
16073 +@@ -2612,8 +2747,10 @@ int vfs_rename(struct inode *old_dir, st
16074 + error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
16075 + else
16076 + error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
16077 ++
16078 + if (!error) {
16079 + const char *new_name = old_dentry->d_name.name;
16080 ++
16081 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
16082 + new_dentry->d_inode, old_dentry);
16083 + }
16084 +@@ -2685,11 +2822,21 @@ asmlinkage long sys_renameat(int olddfd,
16085 + if (new_dentry == trap)
16086 + goto exit5;
16087 +
16088 ++ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
16089 ++ old_dentry, old_dir->d_inode, oldnd.path.mnt,
16090 ++ to);
16091 ++ if (error)
16092 ++ goto exit5;
16093 ++
16094 + error = mnt_want_write(oldnd.path.mnt);
16095 + if (error)
16096 + goto exit5;
16097 + error = vfs_rename(old_dir->d_inode, old_dentry,
16098 + new_dir->d_inode, new_dentry);
16099 ++ if (!error)
16100 ++ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
16101 ++ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
16102 ++
16103 + mnt_drop_write(oldnd.path.mnt);
16104 + exit5:
16105 + dput(new_dentry);
16106 +diff -urNp linux-2.6.27.10/fs/namespace.c linux-2.6.27.10/fs/namespace.c
16107 +--- linux-2.6.27.10/fs/namespace.c 2008-11-18 11:38:40.000000000 -0500
16108 ++++ linux-2.6.27.10/fs/namespace.c 2008-11-18 11:40:53.000000000 -0500
16109 +@@ -27,6 +27,7 @@
16110 + #include <linux/ramfs.h>
16111 + #include <linux/log2.h>
16112 + #include <linux/idr.h>
16113 ++#include <linux/grsecurity.h>
16114 + #include <asm/uaccess.h>
16115 + #include <asm/unistd.h>
16116 + #include "pnode.h"
16117 +@@ -1094,6 +1095,8 @@ static int do_umount(struct vfsmount *mn
16118 + lock_kernel();
16119 + retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
16120 + unlock_kernel();
16121 ++
16122 ++ gr_log_remount(mnt->mnt_devname, retval);
16123 + }
16124 + up_write(&sb->s_umount);
16125 + return retval;
16126 +@@ -1117,6 +1120,9 @@ static int do_umount(struct vfsmount *mn
16127 + security_sb_umount_busy(mnt);
16128 + up_write(&namespace_sem);
16129 + release_mounts(&umount_list);
16130 ++
16131 ++ gr_log_unmount(mnt->mnt_devname, retval);
16132 ++
16133 + return retval;
16134 + }
16135 +
16136 +@@ -1954,6 +1960,11 @@ long do_mount(char *dev_name, char *dir_
16137 + if (retval)
16138 + goto dput_out;
16139 +
16140 ++ if (gr_handle_chroot_mount(nd.path.dentry, nd.path.mnt, dev_name)) {
16141 ++ retval = -EPERM;
16142 ++ goto dput_out;
16143 ++ }
16144 ++
16145 + if (flags & MS_REMOUNT)
16146 + retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
16147 + data_page);
16148 +@@ -1968,6 +1979,9 @@ long do_mount(char *dev_name, char *dir_
16149 + dev_name, data_page);
16150 + dput_out:
16151 + path_put(&nd.path);
16152 ++
16153 ++ gr_log_mount(dev_name, dir_name, retval);
16154 ++
16155 + return retval;
16156 + }
16157 +
16158 +@@ -2080,6 +2094,9 @@ asmlinkage long sys_mount(char __user *
16159 + if (retval < 0)
16160 + goto out3;
16161 +
16162 ++ if (gr_handle_chroot_pivot())
16163 ++ return -EPERM;
16164 ++
16165 + lock_kernel();
16166 + retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
16167 + flags, (void *)data_page);
16168 +diff -urNp linux-2.6.27.10/fs/nfs/nfs4proc.c linux-2.6.27.10/fs/nfs/nfs4proc.c
16169 +--- linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-07 12:55:34.000000000 -0500
16170 ++++ linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-18 03:38:45.000000000 -0500
16171 +@@ -653,7 +653,7 @@ static int _nfs4_do_open_reclaim(struct
16172 + static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
16173 + {
16174 + struct nfs_server *server = NFS_SERVER(state->inode);
16175 +- struct nfs4_exception exception = { };
16176 ++ struct nfs4_exception exception = {0, 0};
16177 + int err;
16178 + do {
16179 + err = _nfs4_do_open_reclaim(ctx, state);
16180 +@@ -695,7 +695,7 @@ static int _nfs4_open_delegation_recall(
16181 +
16182 + int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
16183 + {
16184 +- struct nfs4_exception exception = { };
16185 ++ struct nfs4_exception exception = {0, 0};
16186 + struct nfs_server *server = NFS_SERVER(state->inode);
16187 + int err;
16188 + do {
16189 +@@ -988,7 +988,7 @@ static int _nfs4_open_expired(struct nfs
16190 + static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
16191 + {
16192 + struct nfs_server *server = NFS_SERVER(state->inode);
16193 +- struct nfs4_exception exception = { };
16194 ++ struct nfs4_exception exception = {0, 0};
16195 + int err;
16196 +
16197 + do {
16198 +@@ -1090,7 +1090,7 @@ out_err:
16199 +
16200 + static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int flags, struct iattr *sattr, struct rpc_cred *cred)
16201 + {
16202 +- struct nfs4_exception exception = { };
16203 ++ struct nfs4_exception exception = {0, 0};
16204 + struct nfs4_state *res;
16205 + int status;
16206 +
16207 +@@ -1181,7 +1181,7 @@ static int nfs4_do_setattr(struct inode
16208 + struct nfs4_state *state)
16209 + {
16210 + struct nfs_server *server = NFS_SERVER(inode);
16211 +- struct nfs4_exception exception = { };
16212 ++ struct nfs4_exception exception = {0, 0};
16213 + int err;
16214 + do {
16215 + err = nfs4_handle_exception(server,
16216 +@@ -1494,7 +1494,7 @@ static int _nfs4_server_capabilities(str
16217 +
16218 + int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
16219 + {
16220 +- struct nfs4_exception exception = { };
16221 ++ struct nfs4_exception exception = {0, 0};
16222 + int err;
16223 + do {
16224 + err = nfs4_handle_exception(server,
16225 +@@ -1527,7 +1527,7 @@ static int _nfs4_lookup_root(struct nfs_
16226 + static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
16227 + struct nfs_fsinfo *info)
16228 + {
16229 +- struct nfs4_exception exception = { };
16230 ++ struct nfs4_exception exception = {0, 0};
16231 + int err;
16232 + do {
16233 + err = nfs4_handle_exception(server,
16234 +@@ -1616,7 +1616,7 @@ static int _nfs4_proc_getattr(struct nfs
16235 +
16236 + static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16237 + {
16238 +- struct nfs4_exception exception = { };
16239 ++ struct nfs4_exception exception = {0, 0};
16240 + int err;
16241 + do {
16242 + err = nfs4_handle_exception(server,
16243 +@@ -1702,7 +1702,7 @@ static int nfs4_proc_lookupfh(struct nfs
16244 + struct qstr *name, struct nfs_fh *fhandle,
16245 + struct nfs_fattr *fattr)
16246 + {
16247 +- struct nfs4_exception exception = { };
16248 ++ struct nfs4_exception exception = {0, 0};
16249 + int err;
16250 + do {
16251 + err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
16252 +@@ -1731,7 +1731,7 @@ static int _nfs4_proc_lookup(struct inod
16253 +
16254 + static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16255 + {
16256 +- struct nfs4_exception exception = { };
16257 ++ struct nfs4_exception exception = {0, 0};
16258 + int err;
16259 + do {
16260 + err = nfs4_handle_exception(NFS_SERVER(dir),
16261 +@@ -1795,7 +1795,7 @@ static int _nfs4_proc_access(struct inod
16262 +
16263 + static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
16264 + {
16265 +- struct nfs4_exception exception = { };
16266 ++ struct nfs4_exception exception = {0, 0};
16267 + int err;
16268 + do {
16269 + err = nfs4_handle_exception(NFS_SERVER(inode),
16270 +@@ -1850,7 +1850,7 @@ static int _nfs4_proc_readlink(struct in
16271 + static int nfs4_proc_readlink(struct inode *inode, struct page *page,
16272 + unsigned int pgbase, unsigned int pglen)
16273 + {
16274 +- struct nfs4_exception exception = { };
16275 ++ struct nfs4_exception exception = {0, 0};
16276 + int err;
16277 + do {
16278 + err = nfs4_handle_exception(NFS_SERVER(inode),
16279 +@@ -1947,7 +1947,7 @@ static int _nfs4_proc_remove(struct inod
16280 +
16281 + static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
16282 + {
16283 +- struct nfs4_exception exception = { };
16284 ++ struct nfs4_exception exception = {0, 0};
16285 + int err;
16286 + do {
16287 + err = nfs4_handle_exception(NFS_SERVER(dir),
16288 +@@ -2019,7 +2019,7 @@ static int _nfs4_proc_rename(struct inod
16289 + static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
16290 + struct inode *new_dir, struct qstr *new_name)
16291 + {
16292 +- struct nfs4_exception exception = { };
16293 ++ struct nfs4_exception exception = {0, 0};
16294 + int err;
16295 + do {
16296 + err = nfs4_handle_exception(NFS_SERVER(old_dir),
16297 +@@ -2066,7 +2066,7 @@ static int _nfs4_proc_link(struct inode
16298 +
16299 + static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
16300 + {
16301 +- struct nfs4_exception exception = { };
16302 ++ struct nfs4_exception exception = {0, 0};
16303 + int err;
16304 + do {
16305 + err = nfs4_handle_exception(NFS_SERVER(inode),
16306 +@@ -2157,7 +2157,7 @@ out:
16307 + static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
16308 + struct page *page, unsigned int len, struct iattr *sattr)
16309 + {
16310 +- struct nfs4_exception exception = { };
16311 ++ struct nfs4_exception exception = {0, 0};
16312 + int err;
16313 + do {
16314 + err = nfs4_handle_exception(NFS_SERVER(dir),
16315 +@@ -2188,7 +2188,7 @@ out:
16316 + static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
16317 + struct iattr *sattr)
16318 + {
16319 +- struct nfs4_exception exception = { };
16320 ++ struct nfs4_exception exception = {0, 0};
16321 + int err;
16322 + do {
16323 + err = nfs4_handle_exception(NFS_SERVER(dir),
16324 +@@ -2237,7 +2237,7 @@ static int _nfs4_proc_readdir(struct den
16325 + static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
16326 + u64 cookie, struct page *page, unsigned int count, int plus)
16327 + {
16328 +- struct nfs4_exception exception = { };
16329 ++ struct nfs4_exception exception = {0, 0};
16330 + int err;
16331 + do {
16332 + err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
16333 +@@ -2285,7 +2285,7 @@ out:
16334 + static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
16335 + struct iattr *sattr, dev_t rdev)
16336 + {
16337 +- struct nfs4_exception exception = { };
16338 ++ struct nfs4_exception exception = {0, 0};
16339 + int err;
16340 + do {
16341 + err = nfs4_handle_exception(NFS_SERVER(dir),
16342 +@@ -2314,7 +2314,7 @@ static int _nfs4_proc_statfs(struct nfs_
16343 +
16344 + static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
16345 + {
16346 +- struct nfs4_exception exception = { };
16347 ++ struct nfs4_exception exception = {0, 0};
16348 + int err;
16349 + do {
16350 + err = nfs4_handle_exception(server,
16351 +@@ -2342,7 +2342,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
16352 +
16353 + static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
16354 + {
16355 +- struct nfs4_exception exception = { };
16356 ++ struct nfs4_exception exception = {0, 0};
16357 + int err;
16358 +
16359 + do {
16360 +@@ -2385,7 +2385,7 @@ static int _nfs4_proc_pathconf(struct nf
16361 + static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
16362 + struct nfs_pathconf *pathconf)
16363 + {
16364 +- struct nfs4_exception exception = { };
16365 ++ struct nfs4_exception exception = {0, 0};
16366 + int err;
16367 +
16368 + do {
16369 +@@ -2672,7 +2672,7 @@ out_free:
16370 +
16371 + static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
16372 + {
16373 +- struct nfs4_exception exception = { };
16374 ++ struct nfs4_exception exception = {0, 0};
16375 + ssize_t ret;
16376 + do {
16377 + ret = __nfs4_get_acl_uncached(inode, buf, buflen);
16378 +@@ -2729,7 +2729,7 @@ static int __nfs4_proc_set_acl(struct in
16379 +
16380 + static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
16381 + {
16382 +- struct nfs4_exception exception = { };
16383 ++ struct nfs4_exception exception = {0, 0};
16384 + int err;
16385 + do {
16386 + err = nfs4_handle_exception(NFS_SERVER(inode),
16387 +@@ -3020,7 +3020,7 @@ out:
16388 + int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
16389 + {
16390 + struct nfs_server *server = NFS_SERVER(inode);
16391 +- struct nfs4_exception exception = { };
16392 ++ struct nfs4_exception exception = {0, 0};
16393 + int err;
16394 + do {
16395 + err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
16396 +@@ -3095,7 +3095,7 @@ out:
16397 +
16398 + static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16399 + {
16400 +- struct nfs4_exception exception = { };
16401 ++ struct nfs4_exception exception = {0, 0};
16402 + int err;
16403 +
16404 + do {
16405 +@@ -3445,7 +3445,7 @@ static int _nfs4_do_setlk(struct nfs4_st
16406 + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
16407 + {
16408 + struct nfs_server *server = NFS_SERVER(state->inode);
16409 +- struct nfs4_exception exception = { };
16410 ++ struct nfs4_exception exception = {0, 0};
16411 + int err;
16412 +
16413 + do {
16414 +@@ -3463,7 +3463,7 @@ static int nfs4_lock_reclaim(struct nfs4
16415 + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
16416 + {
16417 + struct nfs_server *server = NFS_SERVER(state->inode);
16418 +- struct nfs4_exception exception = { };
16419 ++ struct nfs4_exception exception = {0, 0};
16420 + int err;
16421 +
16422 + err = nfs4_set_lock_state(state, request);
16423 +@@ -3524,7 +3524,7 @@ out:
16424 +
16425 + static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16426 + {
16427 +- struct nfs4_exception exception = { };
16428 ++ struct nfs4_exception exception = {0, 0};
16429 + int err;
16430 +
16431 + do {
16432 +@@ -3574,7 +3574,7 @@ nfs4_proc_lock(struct file *filp, int cm
16433 + int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
16434 + {
16435 + struct nfs_server *server = NFS_SERVER(state->inode);
16436 +- struct nfs4_exception exception = { };
16437 ++ struct nfs4_exception exception = {0, 0};
16438 + int err;
16439 +
16440 + err = nfs4_set_lock_state(state, fl);
16441 +diff -urNp linux-2.6.27.10/fs/nfsd/export.c linux-2.6.27.10/fs/nfsd/export.c
16442 +--- linux-2.6.27.10/fs/nfsd/export.c 2008-11-07 12:55:34.000000000 -0500
16443 ++++ linux-2.6.27.10/fs/nfsd/export.c 2008-11-18 03:38:45.000000000 -0500
16444 +@@ -473,7 +473,7 @@ static int secinfo_parse(char **mesg, ch
16445 + * probably discover the problem when someone fails to
16446 + * authenticate.
16447 + */
16448 +- if (f->pseudoflavor < 0)
16449 ++ if ((s32)f->pseudoflavor < 0)
16450 + return -EINVAL;
16451 + err = get_int(mesg, &f->flags);
16452 + if (err)
16453 +diff -urNp linux-2.6.27.10/fs/nls/nls_base.c linux-2.6.27.10/fs/nls/nls_base.c
16454 +--- linux-2.6.27.10/fs/nls/nls_base.c 2008-11-07 12:55:34.000000000 -0500
16455 ++++ linux-2.6.27.10/fs/nls/nls_base.c 2008-11-18 03:38:45.000000000 -0500
16456 +@@ -42,7 +42,7 @@ static const struct utf8_table utf8_tabl
16457 + {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
16458 + {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
16459 + {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
16460 +- {0, /* end of table */}
16461 ++ {0, 0, 0, 0, 0, /* end of table */}
16462 + };
16463 +
16464 + int
16465 +diff -urNp linux-2.6.27.10/fs/ntfs/file.c linux-2.6.27.10/fs/ntfs/file.c
16466 +--- linux-2.6.27.10/fs/ntfs/file.c 2008-11-07 12:55:34.000000000 -0500
16467 ++++ linux-2.6.27.10/fs/ntfs/file.c 2008-11-18 03:38:45.000000000 -0500
16468 +@@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_
16469 + #endif /* NTFS_RW */
16470 + };
16471 +
16472 +-const struct file_operations ntfs_empty_file_ops = {};
16473 ++const struct file_operations ntfs_empty_file_ops;
16474 +
16475 +-const struct inode_operations ntfs_empty_inode_ops = {};
16476 ++const struct inode_operations ntfs_empty_inode_ops;
16477 +diff -urNp linux-2.6.27.10/fs/open.c linux-2.6.27.10/fs/open.c
16478 +--- linux-2.6.27.10/fs/open.c 2008-11-07 12:55:34.000000000 -0500
16479 ++++ linux-2.6.27.10/fs/open.c 2008-11-18 03:38:45.000000000 -0500
16480 +@@ -29,6 +29,7 @@
16481 + #include <linux/rcupdate.h>
16482 + #include <linux/audit.h>
16483 + #include <linux/falloc.h>
16484 ++#include <linux/grsecurity.h>
16485 +
16486 + int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
16487 + {
16488 +@@ -207,6 +208,9 @@ int do_truncate(struct dentry *dentry, l
16489 + if (length < 0)
16490 + return -EINVAL;
16491 +
16492 ++ if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt))
16493 ++ return -EACCES;
16494 ++
16495 + newattrs.ia_size = length;
16496 + newattrs.ia_valid = ATTR_SIZE | time_attrs;
16497 + if (filp) {
16498 +@@ -491,6 +495,9 @@ asmlinkage long sys_faccessat(int dfd, c
16499 + if (__mnt_is_readonly(path.mnt))
16500 + res = -EROFS;
16501 +
16502 ++ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
16503 ++ res = -EACCES;
16504 ++
16505 + out_path_release:
16506 + path_put(&path);
16507 + out:
16508 +@@ -521,6 +528,8 @@ asmlinkage long sys_chdir(const char __u
16509 + if (error)
16510 + goto dput_and_out;
16511 +
16512 ++ gr_log_chdir(path.dentry, path.mnt);
16513 ++
16514 + set_fs_pwd(current->fs, &path);
16515 +
16516 + dput_and_out:
16517 +@@ -547,6 +556,13 @@ asmlinkage long sys_fchdir(unsigned int
16518 + goto out_putf;
16519 +
16520 + error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
16521 ++
16522 ++ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
16523 ++ error = -EPERM;
16524 ++
16525 ++ if (!error)
16526 ++ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
16527 ++
16528 + if (!error)
16529 + set_fs_pwd(current->fs, &file->f_path);
16530 + out_putf:
16531 +@@ -572,7 +588,14 @@ asmlinkage long sys_chroot(const char __
16532 + if (!capable(CAP_SYS_CHROOT))
16533 + goto dput_and_out;
16534 +
16535 ++ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
16536 ++ goto dput_and_out;
16537 ++
16538 + set_fs_root(current->fs, &path);
16539 ++
16540 ++ gr_handle_chroot_caps(current);
16541 ++ gr_handle_chroot_chdir(&path);
16542 ++
16543 + error = 0;
16544 + dput_and_out:
16545 + path_put(&path);
16546 +@@ -600,13 +623,28 @@ asmlinkage long sys_fchmod(unsigned int
16547 + err = mnt_want_write(file->f_path.mnt);
16548 + if (err)
16549 + goto out_putf;
16550 ++
16551 ++ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
16552 ++ err = -EACCES;
16553 ++ goto out_drop_write;
16554 ++ }
16555 ++
16556 + mutex_lock(&inode->i_mutex);
16557 + if (mode == (mode_t) -1)
16558 + mode = inode->i_mode;
16559 ++
16560 ++ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
16561 ++ err = -EPERM;
16562 ++ mutex_unlock(&inode->i_mutex);
16563 ++ goto out_drop_write;
16564 ++ }
16565 ++
16566 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16567 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16568 + err = notify_change(dentry, &newattrs);
16569 + mutex_unlock(&inode->i_mutex);
16570 ++
16571 ++out_drop_write:
16572 + mnt_drop_write(file->f_path.mnt);
16573 + out_putf:
16574 + fput(file);
16575 +@@ -630,13 +668,28 @@ asmlinkage long sys_fchmodat(int dfd, co
16576 + error = mnt_want_write(path.mnt);
16577 + if (error)
16578 + goto dput_and_out;
16579 ++
16580 ++ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
16581 ++ error = -EACCES;
16582 ++ goto out_drop_write;
16583 ++ }
16584 ++
16585 + mutex_lock(&inode->i_mutex);
16586 + if (mode == (mode_t) -1)
16587 + mode = inode->i_mode;
16588 ++
16589 ++ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
16590 ++ error = -EACCES;
16591 ++ mutex_unlock(&inode->i_mutex);
16592 ++ goto out_drop_write;
16593 ++ }
16594 ++
16595 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16596 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16597 + error = notify_change(path.dentry, &newattrs);
16598 + mutex_unlock(&inode->i_mutex);
16599 ++
16600 ++out_drop_write:
16601 + mnt_drop_write(path.mnt);
16602 + dput_and_out:
16603 + path_put(&path);
16604 +@@ -649,12 +702,15 @@ asmlinkage long sys_chmod(const char __u
16605 + return sys_fchmodat(AT_FDCWD, filename, mode);
16606 + }
16607 +
16608 +-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
16609 ++static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
16610 + {
16611 + struct inode *inode = dentry->d_inode;
16612 + int error;
16613 + struct iattr newattrs;
16614 +
16615 ++ if (!gr_acl_handle_chown(dentry, mnt))
16616 ++ return -EACCES;
16617 ++
16618 + newattrs.ia_valid = ATTR_CTIME;
16619 + if (user != (uid_t) -1) {
16620 + newattrs.ia_valid |= ATTR_UID;
16621 +@@ -685,7 +741,7 @@ asmlinkage long sys_chown(const char __u
16622 + error = mnt_want_write(path.mnt);
16623 + if (error)
16624 + goto out_release;
16625 +- error = chown_common(path.dentry, user, group);
16626 ++ error = chown_common(path.dentry, user, group, path.mnt);
16627 + mnt_drop_write(path.mnt);
16628 + out_release:
16629 + path_put(&path);
16630 +@@ -710,7 +766,7 @@ asmlinkage long sys_fchownat(int dfd, co
16631 + error = mnt_want_write(path.mnt);
16632 + if (error)
16633 + goto out_release;
16634 +- error = chown_common(path.dentry, user, group);
16635 ++ error = chown_common(path.dentry, user, group, path.mnt);
16636 + mnt_drop_write(path.mnt);
16637 + out_release:
16638 + path_put(&path);
16639 +@@ -729,7 +785,7 @@ asmlinkage long sys_lchown(const char __
16640 + error = mnt_want_write(path.mnt);
16641 + if (error)
16642 + goto out_release;
16643 +- error = chown_common(path.dentry, user, group);
16644 ++ error = chown_common(path.dentry, user, group, path.mnt);
16645 + mnt_drop_write(path.mnt);
16646 + out_release:
16647 + path_put(&path);
16648 +@@ -753,7 +809,7 @@ asmlinkage long sys_fchown(unsigned int
16649 + goto out_fput;
16650 + dentry = file->f_path.dentry;
16651 + audit_inode(NULL, dentry);
16652 +- error = chown_common(dentry, user, group);
16653 ++ error = chown_common(dentry, user, group, file->f_path.mnt);
16654 + mnt_drop_write(file->f_path.mnt);
16655 + out_fput:
16656 + fput(file);
16657 +diff -urNp linux-2.6.27.10/fs/pipe.c linux-2.6.27.10/fs/pipe.c
16658 +--- linux-2.6.27.10/fs/pipe.c 2008-11-07 12:55:34.000000000 -0500
16659 ++++ linux-2.6.27.10/fs/pipe.c 2008-11-18 03:38:45.000000000 -0500
16660 +@@ -851,7 +851,7 @@ void free_pipe_info(struct inode *inode)
16661 + inode->i_pipe = NULL;
16662 + }
16663 +
16664 +-static struct vfsmount *pipe_mnt __read_mostly;
16665 ++struct vfsmount *pipe_mnt __read_mostly;
16666 + static int pipefs_delete_dentry(struct dentry *dentry)
16667 + {
16668 + /*
16669 +diff -urNp linux-2.6.27.10/fs/proc/array.c linux-2.6.27.10/fs/proc/array.c
16670 +--- linux-2.6.27.10/fs/proc/array.c 2008-11-07 12:55:34.000000000 -0500
16671 ++++ linux-2.6.27.10/fs/proc/array.c 2008-11-18 03:38:45.000000000 -0500
16672 +@@ -315,6 +315,21 @@ static inline void task_context_switch_c
16673 + p->nivcsw);
16674 + }
16675 +
16676 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16677 ++static inline void task_pax(struct seq_file *m, struct task_struct *p)
16678 ++{
16679 ++ if (p->mm)
16680 ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
16681 ++ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
16682 ++ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
16683 ++ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
16684 ++ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
16685 ++ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
16686 ++ else
16687 ++ seq_printf(m, "PaX:\t-----\n");
16688 ++}
16689 ++#endif
16690 ++
16691 + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
16692 + struct pid *pid, struct task_struct *task)
16693 + {
16694 +@@ -334,9 +349,20 @@ int proc_pid_status(struct seq_file *m,
16695 + task_show_regs(m, task);
16696 + #endif
16697 + task_context_switch_counts(m, task);
16698 ++
16699 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16700 ++ task_pax(m, task);
16701 ++#endif
16702 ++
16703 + return 0;
16704 + }
16705 +
16706 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16707 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
16708 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
16709 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
16710 ++#endif
16711 ++
16712 + static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
16713 + struct pid *pid, struct task_struct *task, int whole)
16714 + {
16715 +@@ -429,6 +455,19 @@ static int do_task_stat(struct seq_file
16716 + gtime = task_gtime(task);
16717 + }
16718 +
16719 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16720 ++ if (PAX_RAND_FLAGS(mm)) {
16721 ++ eip = 0;
16722 ++ esp = 0;
16723 ++ wchan = 0;
16724 ++ }
16725 ++#endif
16726 ++#ifdef CONFIG_GRKERNSEC_HIDESYM
16727 ++ wchan = 0;
16728 ++ eip =0;
16729 ++ esp =0;
16730 ++#endif
16731 ++
16732 + /* scale priority and nice values from timeslices to -20..20 */
16733 + /* to make it look like a "normal" Unix priority/nice value */
16734 + priority = task_prio(task);
16735 +@@ -469,9 +508,15 @@ static int do_task_stat(struct seq_file
16736 + vsize,
16737 + mm ? get_mm_rss(mm) : 0,
16738 + rsslim,
16739 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16740 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
16741 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
16742 ++ PAX_RAND_FLAGS(mm) ? 0 : (mm ? mm->start_stack : 0),
16743 ++#else
16744 + mm ? mm->start_code : 0,
16745 + mm ? mm->end_code : 0,
16746 + mm ? mm->start_stack : 0,
16747 ++#endif
16748 + esp,
16749 + eip,
16750 + /* The signal information here is obsolete.
16751 +@@ -524,3 +569,10 @@ int proc_pid_statm(struct seq_file *m, s
16752 +
16753 + return 0;
16754 + }
16755 ++
16756 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
16757 ++int proc_pid_ipaddr(struct task_struct *task, char *buffer)
16758 ++{
16759 ++ return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
16760 ++}
16761 ++#endif
16762 +diff -urNp linux-2.6.27.10/fs/proc/base.c linux-2.6.27.10/fs/proc/base.c
16763 +--- linux-2.6.27.10/fs/proc/base.c 2008-11-07 12:55:34.000000000 -0500
16764 ++++ linux-2.6.27.10/fs/proc/base.c 2008-11-18 03:38:45.000000000 -0500
16765 +@@ -79,6 +79,8 @@
16766 + #include <linux/oom.h>
16767 + #include <linux/elf.h>
16768 + #include <linux/pid_namespace.h>
16769 ++#include <linux/grsecurity.h>
16770 ++
16771 + #include "internal.h"
16772 +
16773 + /* NOTE:
16774 +@@ -148,7 +150,7 @@ static unsigned int pid_entry_count_dirs
16775 + return count;
16776 + }
16777 +
16778 +-int maps_protect;
16779 ++int maps_protect = 1;
16780 + EXPORT_SYMBOL(maps_protect);
16781 +
16782 + static struct fs_struct *get_fs_struct(struct task_struct *task)
16783 +@@ -229,6 +231,9 @@ static int check_mem_permission(struct t
16784 + if (task == current)
16785 + return 0;
16786 +
16787 ++ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
16788 ++ return -EPERM;
16789 ++
16790 + /*
16791 + * If current is actively ptrace'ing, and would also be
16792 + * permitted to freshly attach with ptrace now, permit it.
16793 +@@ -312,9 +317,9 @@ static int proc_pid_auxv(struct task_str
16794 + struct mm_struct *mm = get_task_mm(task);
16795 + if (mm) {
16796 + unsigned int nwords = 0;
16797 +- do
16798 ++ do {
16799 + nwords += 2;
16800 +- while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16801 ++ } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16802 + res = nwords * sizeof(mm->saved_auxv[0]);
16803 + if (res > PAGE_SIZE)
16804 + res = PAGE_SIZE;
16805 +@@ -1437,7 +1442,11 @@ static struct inode *proc_pid_make_inode
16806 + inode->i_gid = 0;
16807 + if (task_dumpable(task)) {
16808 + inode->i_uid = task->euid;
16809 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16810 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16811 ++#else
16812 + inode->i_gid = task->egid;
16813 ++#endif
16814 + }
16815 + security_task_to_inode(task, inode);
16816 +
16817 +@@ -1453,17 +1462,45 @@ static int pid_getattr(struct vfsmount *
16818 + {
16819 + struct inode *inode = dentry->d_inode;
16820 + struct task_struct *task;
16821 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16822 ++ struct task_struct *tmp = current;
16823 ++#endif
16824 ++
16825 + generic_fillattr(inode, stat);
16826 +
16827 + rcu_read_lock();
16828 + stat->uid = 0;
16829 + stat->gid = 0;
16830 + task = pid_task(proc_pid(inode), PIDTYPE_PID);
16831 +- if (task) {
16832 ++
16833 ++ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
16834 ++ rcu_read_unlock();
16835 ++ return -ENOENT;
16836 ++ }
16837 ++
16838 ++
16839 ++ if (task
16840 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16841 ++ && (!tmp->uid || (tmp->uid == task->uid)
16842 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16843 ++ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
16844 ++#endif
16845 ++ )
16846 ++#endif
16847 ++ ) {
16848 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16849 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16850 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16851 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16852 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16853 ++#endif
16854 + task_dumpable(task)) {
16855 + stat->uid = task->euid;
16856 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16857 ++ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
16858 ++#else
16859 + stat->gid = task->egid;
16860 ++#endif
16861 + }
16862 + }
16863 + rcu_read_unlock();
16864 +@@ -1491,11 +1528,21 @@ static int pid_revalidate(struct dentry
16865 + {
16866 + struct inode *inode = dentry->d_inode;
16867 + struct task_struct *task = get_proc_task(inode);
16868 ++
16869 + if (task) {
16870 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16871 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16872 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16873 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16874 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16875 ++#endif
16876 + task_dumpable(task)) {
16877 + inode->i_uid = task->euid;
16878 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16879 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16880 ++#else
16881 + inode->i_gid = task->egid;
16882 ++#endif
16883 + } else {
16884 + inode->i_uid = 0;
16885 + inode->i_gid = 0;
16886 +@@ -1863,12 +1910,22 @@ static const struct file_operations proc
16887 + static int proc_fd_permission(struct inode *inode, int mask)
16888 + {
16889 + int rv;
16890 ++ struct task_struct *task;
16891 +
16892 + rv = generic_permission(inode, mask, NULL);
16893 +- if (rv == 0)
16894 +- return 0;
16895 ++
16896 + if (task_pid(current) == proc_pid(inode))
16897 + rv = 0;
16898 ++
16899 ++ task = get_proc_task(inode);
16900 ++ if (task == NULL)
16901 ++ return rv;
16902 ++
16903 ++ if (gr_acl_handle_procpidmem(task))
16904 ++ rv = -EACCES;
16905 ++
16906 ++ put_task_struct(task);
16907 ++
16908 + return rv;
16909 + }
16910 +
16911 +@@ -1979,6 +2036,9 @@ static struct dentry *proc_pident_lookup
16912 + if (!task)
16913 + goto out_no_task;
16914 +
16915 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16916 ++ goto out;
16917 ++
16918 + /*
16919 + * Yes, it does not scale. And it should not. Don't add
16920 + * new entries into /proc/<tgid>/ without very good reasons.
16921 +@@ -2023,6 +2083,9 @@ static int proc_pident_readdir(struct fi
16922 + if (!task)
16923 + goto out_no_task;
16924 +
16925 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16926 ++ goto out;
16927 ++
16928 + ret = 0;
16929 + i = filp->f_pos;
16930 + switch (i) {
16931 +@@ -2385,6 +2448,9 @@ static struct dentry *proc_base_lookup(s
16932 + if (p > last)
16933 + goto out;
16934 +
16935 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16936 ++ goto out;
16937 ++
16938 + error = proc_base_instantiate(dir, dentry, task, p);
16939 +
16940 + out:
16941 +@@ -2518,6 +2584,9 @@ static const struct pid_entry tgid_base_
16942 + #ifdef CONFIG_TASK_IO_ACCOUNTING
16943 + INF("io", S_IRUGO, tgid_io_accounting),
16944 + #endif
16945 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
16946 ++ INF("ipaddr", S_IRUSR, pid_ipaddr),
16947 ++#endif
16948 + };
16949 +
16950 + static int proc_tgid_base_readdir(struct file * filp,
16951 +@@ -2647,7 +2716,14 @@ static struct dentry *proc_pid_instantia
16952 + if (!inode)
16953 + goto out;
16954 +
16955 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16956 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
16957 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16958 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16959 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
16960 ++#else
16961 + inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
16962 ++#endif
16963 + inode->i_op = &proc_tgid_base_inode_operations;
16964 + inode->i_fop = &proc_tgid_base_operations;
16965 + inode->i_flags|=S_IMMUTABLE;
16966 +@@ -2689,7 +2765,11 @@ struct dentry *proc_pid_lookup(struct in
16967 + if (!task)
16968 + goto out;
16969 +
16970 ++ if (gr_check_hidden_task(task))
16971 ++ goto out_put_task;
16972 ++
16973 + result = proc_pid_instantiate(dir, dentry, task, NULL);
16974 ++out_put_task:
16975 + put_task_struct(task);
16976 + out:
16977 + return result;
16978 +@@ -2754,6 +2834,9 @@ int proc_pid_readdir(struct file * filp,
16979 + {
16980 + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
16981 + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
16982 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16983 ++ struct task_struct *tmp = current;
16984 ++#endif
16985 + struct tgid_iter iter;
16986 + struct pid_namespace *ns;
16987 +
16988 +@@ -2772,6 +2855,17 @@ int proc_pid_readdir(struct file * filp,
16989 + for (iter = next_tgid(ns, iter);
16990 + iter.task;
16991 + iter.tgid += 1, iter = next_tgid(ns, iter)) {
16992 ++ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
16993 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16994 ++ || (tmp->uid && (iter.task->uid != tmp->uid)
16995 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16996 ++ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
16997 ++#endif
16998 ++ )
16999 ++#endif
17000 ++ )
17001 ++ continue;
17002 ++
17003 + filp->f_pos = iter.tgid + TGID_OFFSET;
17004 + if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
17005 + put_task_struct(iter.task);
17006 +diff -urNp linux-2.6.27.10/fs/proc/inode.c linux-2.6.27.10/fs/proc/inode.c
17007 +--- linux-2.6.27.10/fs/proc/inode.c 2008-11-07 12:55:34.000000000 -0500
17008 ++++ linux-2.6.27.10/fs/proc/inode.c 2008-11-18 03:38:45.000000000 -0500
17009 +@@ -467,7 +467,11 @@ struct inode *proc_get_inode(struct supe
17010 + if (de->mode) {
17011 + inode->i_mode = de->mode;
17012 + inode->i_uid = de->uid;
17013 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
17014 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
17015 ++#else
17016 + inode->i_gid = de->gid;
17017 ++#endif
17018 + }
17019 + if (de->size)
17020 + inode->i_size = de->size;
17021 +diff -urNp linux-2.6.27.10/fs/proc/internal.h linux-2.6.27.10/fs/proc/internal.h
17022 +--- linux-2.6.27.10/fs/proc/internal.h 2008-11-07 12:55:34.000000000 -0500
17023 ++++ linux-2.6.27.10/fs/proc/internal.h 2008-11-18 03:38:45.000000000 -0500
17024 +@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_fi
17025 + struct pid *pid, struct task_struct *task);
17026 + extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
17027 + struct pid *pid, struct task_struct *task);
17028 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
17029 ++extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
17030 ++#endif
17031 + extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
17032 +
17033 + extern const struct file_operations proc_maps_operations;
17034 +diff -urNp linux-2.6.27.10/fs/proc/Kconfig linux-2.6.27.10/fs/proc/Kconfig
17035 +--- linux-2.6.27.10/fs/proc/Kconfig 2008-11-07 12:55:34.000000000 -0500
17036 ++++ linux-2.6.27.10/fs/proc/Kconfig 2008-11-18 03:38:45.000000000 -0500
17037 +@@ -30,12 +30,12 @@ config PROC_FS
17038 +
17039 + config PROC_KCORE
17040 + bool "/proc/kcore support" if !ARM
17041 +- depends on PROC_FS && MMU
17042 ++ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
17043 +
17044 + config PROC_VMCORE
17045 + bool "/proc/vmcore support (EXPERIMENTAL)"
17046 +- depends on PROC_FS && CRASH_DUMP
17047 +- default y
17048 ++ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
17049 ++ default n
17050 + help
17051 + Exports the dump image of crashed kernel in ELF format.
17052 +
17053 +diff -urNp linux-2.6.27.10/fs/proc/proc_misc.c linux-2.6.27.10/fs/proc/proc_misc.c
17054 +--- linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-07 12:55:34.000000000 -0500
17055 ++++ linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-18 03:38:45.000000000 -0500
17056 +@@ -860,6 +860,8 @@ struct proc_dir_entry *proc_root_kcore;
17057 +
17058 + void __init proc_misc_init(void)
17059 + {
17060 ++ int gr_mode = 0;
17061 ++
17062 + static struct {
17063 + char *name;
17064 + int (*read_proc)(char*,char**,off_t,int,int*,void*);
17065 +@@ -875,13 +877,24 @@ void __init proc_misc_init(void)
17066 + {"stram", stram_read_proc},
17067 + #endif
17068 + {"filesystems", filesystems_read_proc},
17069 ++#ifndef CONFIG_GRKERNSEC_PROC_ADD
17070 + {"cmdline", cmdline_read_proc},
17071 ++#endif
17072 + {"execdomains", execdomains_read_proc},
17073 + {NULL,}
17074 + };
17075 + for (p = simple_ones; p->name; p++)
17076 + create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
17077 +
17078 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17079 ++ gr_mode = S_IRUSR;
17080 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17081 ++ gr_mode = S_IRUSR | S_IRGRP;
17082 ++#endif
17083 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17084 ++ create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
17085 ++#endif
17086 ++
17087 + proc_symlink("mounts", NULL, "self/mounts");
17088 +
17089 + /* And now for trickier ones */
17090 +@@ -889,14 +902,18 @@ void __init proc_misc_init(void)
17091 + proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
17092 + #endif
17093 + proc_create("locks", 0, NULL, &proc_locks_operations);
17094 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17095 ++ proc_create("devices", gr_mode, NULL, &proc_devinfo_operations);
17096 ++#else
17097 + proc_create("devices", 0, NULL, &proc_devinfo_operations);
17098 ++#endif
17099 + proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
17100 + #ifdef CONFIG_BLOCK
17101 + proc_create("partitions", 0, NULL, &proc_partitions_operations);
17102 + #endif
17103 + proc_create("stat", 0, NULL, &proc_stat_operations);
17104 + proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
17105 +-#ifdef CONFIG_SLABINFO
17106 ++#if defined(CONFIG_SLABINFO) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17107 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
17108 + #ifdef CONFIG_DEBUG_SLAB_LEAK
17109 + proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
17110 +@@ -918,7 +935,7 @@ void __init proc_misc_init(void)
17111 + #ifdef CONFIG_SCHEDSTATS
17112 + proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
17113 + #endif
17114 +-#ifdef CONFIG_PROC_KCORE
17115 ++#if defined(CONFIG_PROC_KCORE) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17116 + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
17117 + if (proc_root_kcore)
17118 + proc_root_kcore->size =
17119 +diff -urNp linux-2.6.27.10/fs/proc/proc_net.c linux-2.6.27.10/fs/proc/proc_net.c
17120 +--- linux-2.6.27.10/fs/proc/proc_net.c 2008-11-07 12:55:34.000000000 -0500
17121 ++++ linux-2.6.27.10/fs/proc/proc_net.c 2008-11-18 03:38:45.000000000 -0500
17122 +@@ -106,6 +106,14 @@ static struct net *get_proc_task_net(str
17123 + struct nsproxy *ns;
17124 + struct net *net = NULL;
17125 +
17126 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17127 ++ if (current->fsuid)
17128 ++ return net;
17129 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17130 ++ if (current->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
17131 ++ return net;
17132 ++#endif
17133 ++
17134 + rcu_read_lock();
17135 + task = pid_task(proc_pid(dir), PIDTYPE_PID);
17136 + if (task != NULL) {
17137 +diff -urNp linux-2.6.27.10/fs/proc/proc_sysctl.c linux-2.6.27.10/fs/proc/proc_sysctl.c
17138 +--- linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:38:40.000000000 -0500
17139 ++++ linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:40:53.000000000 -0500
17140 +@@ -7,6 +7,8 @@
17141 + #include <linux/security.h>
17142 + #include "internal.h"
17143 +
17144 ++extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
17145 ++
17146 + static struct dentry_operations proc_sys_dentry_operations;
17147 + static const struct file_operations proc_sys_file_operations;
17148 + static const struct inode_operations proc_sys_inode_operations;
17149 +@@ -110,6 +112,9 @@ static struct dentry *proc_sys_lookup(st
17150 + if (!p)
17151 + goto out;
17152 +
17153 ++ if (gr_handle_sysctl(p, MAY_EXEC))
17154 ++ goto out;
17155 ++
17156 + err = ERR_PTR(-ENOMEM);
17157 + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
17158 + if (h)
17159 +@@ -229,6 +234,9 @@ static int scan(struct ctl_table_header
17160 + if (*pos < file->f_pos)
17161 + continue;
17162 +
17163 ++ if (gr_handle_sysctl(table, 0))
17164 ++ continue;
17165 ++
17166 + res = proc_sys_fill_cache(file, dirent, filldir, head, table);
17167 + if (res)
17168 + return res;
17169 +@@ -339,6 +347,9 @@ static int proc_sys_getattr(struct vfsmo
17170 + if (IS_ERR(head))
17171 + return PTR_ERR(head);
17172 +
17173 ++ if (table && gr_handle_sysctl(table, MAY_EXEC))
17174 ++ return -ENOENT;
17175 ++
17176 + generic_fillattr(inode, stat);
17177 + if (table)
17178 + stat->mode = (stat->mode & S_IFMT) | table->mode;
17179 +diff -urNp linux-2.6.27.10/fs/proc/root.c linux-2.6.27.10/fs/proc/root.c
17180 +--- linux-2.6.27.10/fs/proc/root.c 2008-11-07 12:55:34.000000000 -0500
17181 ++++ linux-2.6.27.10/fs/proc/root.c 2008-11-18 03:38:45.000000000 -0500
17182 +@@ -135,7 +135,15 @@ void __init proc_root_init(void)
17183 + #ifdef CONFIG_PROC_DEVICETREE
17184 + proc_device_tree_init();
17185 + #endif
17186 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17187 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17188 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
17189 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17190 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
17191 ++#endif
17192 ++#else
17193 + proc_mkdir("bus", NULL);
17194 ++#endif
17195 + proc_sys_init();
17196 + }
17197 +
17198 +diff -urNp linux-2.6.27.10/fs/proc/task_mmu.c linux-2.6.27.10/fs/proc/task_mmu.c
17199 +--- linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:16:51.000000000 -0500
17200 ++++ linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:13:46.000000000 -0500
17201 +@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
17202 + "VmStk:\t%8lu kB\n"
17203 + "VmExe:\t%8lu kB\n"
17204 + "VmLib:\t%8lu kB\n"
17205 +- "VmPTE:\t%8lu kB\n",
17206 +- hiwater_vm << (PAGE_SHIFT-10),
17207 ++ "VmPTE:\t%8lu kB\n"
17208 ++
17209 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17210 ++ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
17211 ++#endif
17212 ++
17213 ++ ,hiwater_vm << (PAGE_SHIFT-10),
17214 + (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
17215 + mm->locked_vm << (PAGE_SHIFT-10),
17216 + hiwater_rss << (PAGE_SHIFT-10),
17217 + total_rss << (PAGE_SHIFT-10),
17218 + data << (PAGE_SHIFT-10),
17219 + mm->stack_vm << (PAGE_SHIFT-10), text, lib,
17220 +- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
17221 ++ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
17222 ++
17223 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17224 ++ , mm->context.user_cs_base, mm->context.user_cs_limit
17225 ++#endif
17226 ++
17227 ++ );
17228 + }
17229 +
17230 + unsigned long task_vsize(struct mm_struct *mm)
17231 +@@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in
17232 + return ret;
17233 + }
17234 +
17235 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17236 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
17237 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
17238 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
17239 ++#endif
17240 ++
17241 + static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
17242 + {
17243 + struct mm_struct *mm = vma->vm_mm;
17244 +@@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file
17245 + }
17246 +
17247 + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
17248 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17249 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
17250 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
17251 ++#else
17252 + vma->vm_start,
17253 + vma->vm_end,
17254 ++#endif
17255 + flags & VM_READ ? 'r' : '-',
17256 + flags & VM_WRITE ? 'w' : '-',
17257 + flags & VM_EXEC ? 'x' : '-',
17258 + flags & VM_MAYSHARE ? 's' : 'p',
17259 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17260 ++ PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17261 ++#else
17262 + ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17263 ++#endif
17264 + MAJOR(dev), MINOR(dev), ino, &len);
17265 +
17266 + /*
17267 +@@ -234,11 +260,11 @@ static void show_map_vma(struct seq_file
17268 + const char *name = arch_vma_name(vma);
17269 + if (!name) {
17270 + if (mm) {
17271 +- if (vma->vm_start <= mm->start_brk &&
17272 +- vma->vm_end >= mm->brk) {
17273 ++ if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
17274 + name = "[heap]";
17275 +- } else if (vma->vm_start <= mm->start_stack &&
17276 +- vma->vm_end >= mm->start_stack) {
17277 ++ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
17278 ++ (vma->vm_start <= mm->start_stack &&
17279 ++ vma->vm_end >= mm->start_stack)) {
17280 + name = "[stack]";
17281 + }
17282 + } else {
17283 +@@ -387,9 +413,16 @@ static int show_smap(struct seq_file *m,
17284 + return -EACCES;
17285 +
17286 + memset(&mss, 0, sizeof mss);
17287 +- mss.vma = vma;
17288 +- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17289 +- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17290 ++
17291 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17292 ++ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
17293 ++#endif
17294 ++ mss.vma = vma;
17295 ++ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17296 ++ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17297 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17298 ++ }
17299 ++#endif
17300 +
17301 + show_map_vma(m, vma);
17302 +
17303 +@@ -403,7 +436,11 @@ static int show_smap(struct seq_file *m,
17304 + "Private_Dirty: %8lu kB\n"
17305 + "Referenced: %8lu kB\n"
17306 + "Swap: %8lu kB\n",
17307 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17308 ++ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
17309 ++#else
17310 + (vma->vm_end - vma->vm_start) >> 10,
17311 ++#endif
17312 + mss.resident >> 10,
17313 + (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
17314 + mss.shared_clean >> 10,
17315 +@@ -757,6 +794,11 @@ static int show_numa_map_checked(struct
17316 + struct proc_maps_private *priv = m->private;
17317 + struct task_struct *task = priv->task;
17318 +
17319 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17320 ++ if (!ptrace_may_access(task, PTRACE_MODE_READ))
17321 ++ return -EACCES;
17322 ++#endif
17323 ++
17324 + if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
17325 + return -EACCES;
17326 +
17327 +diff -urNp linux-2.6.27.10/fs/readdir.c linux-2.6.27.10/fs/readdir.c
17328 +--- linux-2.6.27.10/fs/readdir.c 2008-11-07 12:55:34.000000000 -0500
17329 ++++ linux-2.6.27.10/fs/readdir.c 2008-11-18 03:38:45.000000000 -0500
17330 +@@ -16,6 +16,8 @@
17331 + #include <linux/security.h>
17332 + #include <linux/syscalls.h>
17333 + #include <linux/unistd.h>
17334 ++#include <linux/namei.h>
17335 ++#include <linux/grsecurity.h>
17336 +
17337 + #include <asm/uaccess.h>
17338 +
17339 +@@ -67,6 +69,7 @@ struct old_linux_dirent {
17340 +
17341 + struct readdir_callback {
17342 + struct old_linux_dirent __user * dirent;
17343 ++ struct file * file;
17344 + int result;
17345 + };
17346 +
17347 +@@ -84,6 +87,10 @@ static int fillonedir(void * __buf, cons
17348 + buf->result = -EOVERFLOW;
17349 + return -EOVERFLOW;
17350 + }
17351 ++
17352 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17353 ++ return 0;
17354 ++
17355 + buf->result++;
17356 + dirent = buf->dirent;
17357 + if (!access_ok(VERIFY_WRITE, dirent,
17358 +@@ -115,6 +122,7 @@ asmlinkage long old_readdir(unsigned int
17359 +
17360 + buf.result = 0;
17361 + buf.dirent = dirent;
17362 ++ buf.file = file;
17363 +
17364 + error = vfs_readdir(file, fillonedir, &buf);
17365 + if (error >= 0)
17366 +@@ -141,6 +149,7 @@ struct linux_dirent {
17367 + struct getdents_callback {
17368 + struct linux_dirent __user * current_dir;
17369 + struct linux_dirent __user * previous;
17370 ++ struct file * file;
17371 + int count;
17372 + int error;
17373 + };
17374 +@@ -161,6 +170,10 @@ static int filldir(void * __buf, const c
17375 + buf->error = -EOVERFLOW;
17376 + return -EOVERFLOW;
17377 + }
17378 ++
17379 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17380 ++ return 0;
17381 ++
17382 + dirent = buf->previous;
17383 + if (dirent) {
17384 + if (__put_user(offset, &dirent->d_off))
17385 +@@ -207,6 +220,7 @@ asmlinkage long sys_getdents(unsigned in
17386 + buf.previous = NULL;
17387 + buf.count = count;
17388 + buf.error = 0;
17389 ++ buf.file = file;
17390 +
17391 + error = vfs_readdir(file, filldir, &buf);
17392 + if (error < 0)
17393 +@@ -229,6 +243,7 @@ out:
17394 + struct getdents_callback64 {
17395 + struct linux_dirent64 __user * current_dir;
17396 + struct linux_dirent64 __user * previous;
17397 ++ struct file *file;
17398 + int count;
17399 + int error;
17400 + };
17401 +@@ -243,6 +258,10 @@ static int filldir64(void * __buf, const
17402 + buf->error = -EINVAL; /* only used if we fail.. */
17403 + if (reclen > buf->count)
17404 + return -EINVAL;
17405 ++
17406 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17407 ++ return 0;
17408 ++
17409 + dirent = buf->previous;
17410 + if (dirent) {
17411 + if (__put_user(offset, &dirent->d_off))
17412 +@@ -289,6 +308,7 @@ asmlinkage long sys_getdents64(unsigned
17413 +
17414 + buf.current_dir = dirent;
17415 + buf.previous = NULL;
17416 ++ buf.file = file;
17417 + buf.count = count;
17418 + buf.error = 0;
17419 +
17420 +diff -urNp linux-2.6.27.10/fs/select.c linux-2.6.27.10/fs/select.c
17421 +--- linux-2.6.27.10/fs/select.c 2008-11-07 12:55:34.000000000 -0500
17422 ++++ linux-2.6.27.10/fs/select.c 2008-11-18 03:38:45.000000000 -0500
17423 +@@ -24,6 +24,7 @@
17424 + #include <linux/fdtable.h>
17425 + #include <linux/fs.h>
17426 + #include <linux/rcupdate.h>
17427 ++#include <linux/grsecurity.h>
17428 +
17429 + #include <asm/uaccess.h>
17430 +
17431 +@@ -658,6 +659,7 @@ int do_sys_poll(struct pollfd __user *uf
17432 + struct poll_list *walk = head;
17433 + unsigned long todo = nfds;
17434 +
17435 ++ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
17436 + if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
17437 + return -EINVAL;
17438 +
17439 +diff -urNp linux-2.6.27.10/fs/smbfs/symlink.c linux-2.6.27.10/fs/smbfs/symlink.c
17440 +--- linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17441 ++++ linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17442 +@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
17443 +
17444 + static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
17445 + {
17446 +- char *s = nd_get_link(nd);
17447 ++ const char *s = nd_get_link(nd);
17448 + if (!IS_ERR(s))
17449 + __putname(s);
17450 + }
17451 +diff -urNp linux-2.6.27.10/fs/sysfs/symlink.c linux-2.6.27.10/fs/sysfs/symlink.c
17452 +--- linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17453 ++++ linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17454 +@@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de
17455 +
17456 + static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
17457 + {
17458 +- char *page = nd_get_link(nd);
17459 ++ const char *page = nd_get_link(nd);
17460 + if (!IS_ERR(page))
17461 + free_page((unsigned long)page);
17462 + }
17463 +diff -urNp linux-2.6.27.10/fs/udf/balloc.c linux-2.6.27.10/fs/udf/balloc.c
17464 +--- linux-2.6.27.10/fs/udf/balloc.c 2008-11-07 12:55:34.000000000 -0500
17465 ++++ linux-2.6.27.10/fs/udf/balloc.c 2008-11-18 03:38:45.000000000 -0500
17466 +@@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc
17467 + unsigned long overflow;
17468 +
17469 + mutex_lock(&sbi->s_alloc_mutex);
17470 +- if (bloc.logicalBlockNum < 0 ||
17471 +- (bloc.logicalBlockNum + count) >
17472 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17473 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17474 + udf_debug("%d < %d || %d + %d > %d\n",
17475 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17476 + sbi->s_partmaps[bloc.partitionReferenceNum].
17477 +@@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st
17478 +
17479 + mutex_lock(&sbi->s_alloc_mutex);
17480 + part_len = sbi->s_partmaps[partition].s_partition_len;
17481 +- if (first_block < 0 || first_block >= part_len)
17482 ++ if (first_block >= part_len)
17483 + goto out;
17484 +
17485 + if (first_block + block_count > part_len)
17486 +@@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s
17487 + mutex_lock(&sbi->s_alloc_mutex);
17488 +
17489 + repeat:
17490 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17491 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17492 + goal = 0;
17493 +
17494 + nr_groups = bitmap->s_nr_groups;
17495 +@@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct
17496 + struct udf_inode_info *iinfo;
17497 +
17498 + mutex_lock(&sbi->s_alloc_mutex);
17499 +- if (bloc.logicalBlockNum < 0 ||
17500 +- (bloc.logicalBlockNum + count) >
17501 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17502 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17503 + udf_debug("%d < %d || %d + %d > %d\n",
17504 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17505 + sbi->s_partmaps[bloc.partitionReferenceNum].
17506 +@@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str
17507 + int8_t etype = -1;
17508 + struct udf_inode_info *iinfo;
17509 +
17510 +- if (first_block < 0 ||
17511 +- first_block >= sbi->s_partmaps[partition].s_partition_len)
17512 ++ if (first_block >= sbi->s_partmaps[partition].s_partition_len)
17513 + return 0;
17514 +
17515 + iinfo = UDF_I(table);
17516 +@@ -750,7 +745,7 @@ static int udf_table_new_block(struct su
17517 + return newblock;
17518 +
17519 + mutex_lock(&sbi->s_alloc_mutex);
17520 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17521 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17522 + goal = 0;
17523 +
17524 + /* We search for the closest matching block to goal. If we find
17525 +diff -urNp linux-2.6.27.10/fs/ufs/inode.c linux-2.6.27.10/fs/ufs/inode.c
17526 +--- linux-2.6.27.10/fs/ufs/inode.c 2008-11-07 12:55:34.000000000 -0500
17527 ++++ linux-2.6.27.10/fs/ufs/inode.c 2008-11-18 03:38:45.000000000 -0500
17528 +@@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod
17529 +
17530 +
17531 + UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
17532 +- if (i_block < 0) {
17533 +- ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
17534 +- } else if (i_block < direct_blocks) {
17535 ++ if (i_block < direct_blocks) {
17536 + offsets[n++] = i_block;
17537 + } else if ((i_block -= direct_blocks) < indirect_blocks) {
17538 + offsets[n++] = UFS_IND_BLOCK;
17539 +@@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod
17540 + lock_kernel();
17541 +
17542 + UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
17543 +- if (fragment < 0)
17544 +- goto abort_negative;
17545 + if (fragment >
17546 + ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
17547 + << uspi->s_fpbshift))
17548 +@@ -504,10 +500,6 @@ abort:
17549 + unlock_kernel();
17550 + return err;
17551 +
17552 +-abort_negative:
17553 +- ufs_warning(sb, "ufs_get_block", "block < 0");
17554 +- goto abort;
17555 +-
17556 + abort_too_big:
17557 + ufs_warning(sb, "ufs_get_block", "block > big");
17558 + goto abort;
17559 +diff -urNp linux-2.6.27.10/fs/utimes.c linux-2.6.27.10/fs/utimes.c
17560 +--- linux-2.6.27.10/fs/utimes.c 2008-11-07 12:55:34.000000000 -0500
17561 ++++ linux-2.6.27.10/fs/utimes.c 2008-11-18 03:38:45.000000000 -0500
17562 +@@ -8,6 +8,7 @@
17563 + #include <linux/stat.h>
17564 + #include <linux/utime.h>
17565 + #include <linux/syscalls.h>
17566 ++#include <linux/grsecurity.h>
17567 + #include <asm/uaccess.h>
17568 + #include <asm/unistd.h>
17569 +
17570 +@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
17571 + goto mnt_drop_write_and_out;
17572 + }
17573 + }
17574 ++
17575 ++ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
17576 ++ error = -EACCES;
17577 ++ goto mnt_drop_write_and_out;
17578 ++ }
17579 ++
17580 + mutex_lock(&inode->i_mutex);
17581 + error = notify_change(path->dentry, &newattrs);
17582 + mutex_unlock(&inode->i_mutex);
17583 +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
17584 +--- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-07 12:55:34.000000000 -0500
17585 ++++ linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-18 03:38:45.000000000 -0500
17586 +@@ -500,7 +500,7 @@ xfs_vn_put_link(
17587 + struct nameidata *nd,
17588 + void *p)
17589 + {
17590 +- char *s = nd_get_link(nd);
17591 ++ const char *s = nd_get_link(nd);
17592 +
17593 + if (!IS_ERR(s))
17594 + kfree(s);
17595 +diff -urNp linux-2.6.27.10/fs/xfs/xfs_bmap.c linux-2.6.27.10/fs/xfs/xfs_bmap.c
17596 +--- linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-07 12:55:34.000000000 -0500
17597 ++++ linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-18 03:38:45.000000000 -0500
17598 +@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
17599 + int nmap,
17600 + int ret_nmap);
17601 + #else
17602 +-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
17603 ++#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
17604 + #endif /* DEBUG */
17605 +
17606 + #if defined(XFS_RW_TRACE)
17607 +diff -urNp linux-2.6.27.10/grsecurity/gracl_alloc.c linux-2.6.27.10/grsecurity/gracl_alloc.c
17608 +--- linux-2.6.27.10/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
17609 ++++ linux-2.6.27.10/grsecurity/gracl_alloc.c 2008-11-18 03:38:45.000000000 -0500
17610 +@@ -0,0 +1,91 @@
17611 ++#include <linux/kernel.h>
17612 ++#include <linux/mm.h>
17613 ++#include <linux/slab.h>
17614 ++#include <linux/vmalloc.h>
17615 ++#include <linux/gracl.h>
17616 ++#include <linux/grsecurity.h>
17617 ++
17618 ++static unsigned long alloc_stack_next = 1;
17619 ++static unsigned long alloc_stack_size = 1;
17620 ++static void **alloc_stack;
17621 ++
17622 ++static __inline__ int
17623 ++alloc_pop(void)
17624 ++{
17625 ++ if (alloc_stack_next == 1)
17626 ++ return 0;
17627 ++
17628 ++ kfree(alloc_stack[alloc_stack_next - 2]);
17629 ++
17630 ++ alloc_stack_next--;
17631 ++
17632 ++ return 1;
17633 ++}
17634 ++
17635 ++static __inline__ void
17636 ++alloc_push(void *buf)
17637 ++{
17638 ++ if (alloc_stack_next >= alloc_stack_size)
17639 ++ BUG();
17640 ++
17641 ++ alloc_stack[alloc_stack_next - 1] = buf;
17642 ++
17643 ++ alloc_stack_next++;
17644 ++
17645 ++ return;
17646 ++}
17647 ++
17648 ++void *
17649 ++acl_alloc(unsigned long len)
17650 ++{
17651 ++ void *ret;
17652 ++
17653 ++ if (len > PAGE_SIZE)
17654 ++ BUG();
17655 ++
17656 ++ ret = kmalloc(len, GFP_KERNEL);
17657 ++
17658 ++ if (ret)
17659 ++ alloc_push(ret);
17660 ++
17661 ++ return ret;
17662 ++}
17663 ++
17664 ++void
17665 ++acl_free_all(void)
17666 ++{
17667 ++ if (gr_acl_is_enabled() || !alloc_stack)
17668 ++ return;
17669 ++
17670 ++ while (alloc_pop()) ;
17671 ++
17672 ++ if (alloc_stack) {
17673 ++ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
17674 ++ kfree(alloc_stack);
17675 ++ else
17676 ++ vfree(alloc_stack);
17677 ++ }
17678 ++
17679 ++ alloc_stack = NULL;
17680 ++ alloc_stack_size = 1;
17681 ++ alloc_stack_next = 1;
17682 ++
17683 ++ return;
17684 ++}
17685 ++
17686 ++int
17687 ++acl_alloc_stack_init(unsigned long size)
17688 ++{
17689 ++ if ((size * sizeof (void *)) <= PAGE_SIZE)
17690 ++ alloc_stack =
17691 ++ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
17692 ++ else
17693 ++ alloc_stack = (void **) vmalloc(size * sizeof (void *));
17694 ++
17695 ++ alloc_stack_size = size;
17696 ++
17697 ++ if (!alloc_stack)
17698 ++ return 0;
17699 ++ else
17700 ++ return 1;
17701 ++}
17702 +diff -urNp linux-2.6.27.10/grsecurity/gracl.c linux-2.6.27.10/grsecurity/gracl.c
17703 +--- linux-2.6.27.10/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
17704 ++++ linux-2.6.27.10/grsecurity/gracl.c 2008-11-18 03:38:45.000000000 -0500
17705 +@@ -0,0 +1,3722 @@
17706 ++#include <linux/kernel.h>
17707 ++#include <linux/module.h>
17708 ++#include <linux/sched.h>
17709 ++#include <linux/mm.h>
17710 ++#include <linux/file.h>
17711 ++#include <linux/fs.h>
17712 ++#include <linux/namei.h>
17713 ++#include <linux/mount.h>
17714 ++#include <linux/tty.h>
17715 ++#include <linux/proc_fs.h>
17716 ++#include <linux/smp_lock.h>
17717 ++#include <linux/slab.h>
17718 ++#include <linux/vmalloc.h>
17719 ++#include <linux/types.h>
17720 ++#include <linux/sysctl.h>
17721 ++#include <linux/netdevice.h>
17722 ++#include <linux/ptrace.h>
17723 ++#include <linux/gracl.h>
17724 ++#include <linux/gralloc.h>
17725 ++#include <linux/grsecurity.h>
17726 ++#include <linux/grinternal.h>
17727 ++#include <linux/pid_namespace.h>
17728 ++#include <linux/fdtable.h>
17729 ++#include <linux/percpu.h>
17730 ++
17731 ++#include <asm/uaccess.h>
17732 ++#include <asm/errno.h>
17733 ++#include <asm/mman.h>
17734 ++
17735 ++static struct acl_role_db acl_role_set;
17736 ++static struct name_db name_set;
17737 ++static struct inodev_db inodev_set;
17738 ++
17739 ++/* for keeping track of userspace pointers used for subjects, so we
17740 ++ can share references in the kernel as well
17741 ++*/
17742 ++
17743 ++static struct dentry *real_root;
17744 ++static struct vfsmount *real_root_mnt;
17745 ++
17746 ++static struct acl_subj_map_db subj_map_set;
17747 ++
17748 ++static struct acl_role_label *default_role;
17749 ++
17750 ++static u16 acl_sp_role_value;
17751 ++
17752 ++extern char *gr_shared_page[4];
17753 ++static DECLARE_MUTEX(gr_dev_sem);
17754 ++DEFINE_RWLOCK(gr_inode_lock);
17755 ++
17756 ++struct gr_arg *gr_usermode;
17757 ++
17758 ++static unsigned int gr_status = GR_STATUS_INIT;
17759 ++
17760 ++extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
17761 ++extern void gr_clear_learn_entries(void);
17762 ++
17763 ++#ifdef CONFIG_GRKERNSEC_RESLOG
17764 ++extern void gr_log_resource(const struct task_struct *task,
17765 ++ const int res, const unsigned long wanted, const int gt);
17766 ++#endif
17767 ++
17768 ++unsigned char *gr_system_salt;
17769 ++unsigned char *gr_system_sum;
17770 ++
17771 ++static struct sprole_pw **acl_special_roles = NULL;
17772 ++static __u16 num_sprole_pws = 0;
17773 ++
17774 ++static struct acl_role_label *kernel_role = NULL;
17775 ++
17776 ++static unsigned int gr_auth_attempts = 0;
17777 ++static unsigned long gr_auth_expires = 0UL;
17778 ++
17779 ++extern struct vfsmount *sock_mnt;
17780 ++extern struct vfsmount *pipe_mnt;
17781 ++extern struct vfsmount *shm_mnt;
17782 ++static struct acl_object_label *fakefs_obj;
17783 ++
17784 ++extern int gr_init_uidset(void);
17785 ++extern void gr_free_uidset(void);
17786 ++extern void gr_remove_uid(uid_t uid);
17787 ++extern int gr_find_uid(uid_t uid);
17788 ++
17789 ++__inline__ int
17790 ++gr_acl_is_enabled(void)
17791 ++{
17792 ++ return (gr_status & GR_READY);
17793 ++}
17794 ++
17795 ++char gr_roletype_to_char(void)
17796 ++{
17797 ++ switch (current->role->roletype &
17798 ++ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
17799 ++ GR_ROLE_SPECIAL)) {
17800 ++ case GR_ROLE_DEFAULT:
17801 ++ return 'D';
17802 ++ case GR_ROLE_USER:
17803 ++ return 'U';
17804 ++ case GR_ROLE_GROUP:
17805 ++ return 'G';
17806 ++ case GR_ROLE_SPECIAL:
17807 ++ return 'S';
17808 ++ }
17809 ++
17810 ++ return 'X';
17811 ++}
17812 ++
17813 ++__inline__ int
17814 ++gr_acl_tpe_check(void)
17815 ++{
17816 ++ if (unlikely(!(gr_status & GR_READY)))
17817 ++ return 0;
17818 ++ if (current->role->roletype & GR_ROLE_TPE)
17819 ++ return 1;
17820 ++ else
17821 ++ return 0;
17822 ++}
17823 ++
17824 ++int
17825 ++gr_handle_rawio(const struct inode *inode)
17826 ++{
17827 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
17828 ++ if (inode && S_ISBLK(inode->i_mode) &&
17829 ++ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
17830 ++ !capable(CAP_SYS_RAWIO))
17831 ++ return 1;
17832 ++#endif
17833 ++ return 0;
17834 ++}
17835 ++
17836 ++static int
17837 ++gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
17838 ++{
17839 ++ int i;
17840 ++ unsigned long *l1;
17841 ++ unsigned long *l2;
17842 ++ unsigned char *c1;
17843 ++ unsigned char *c2;
17844 ++ int num_longs;
17845 ++
17846 ++ if (likely(lena != lenb))
17847 ++ return 0;
17848 ++
17849 ++ l1 = (unsigned long *)a;
17850 ++ l2 = (unsigned long *)b;
17851 ++
17852 ++ num_longs = lena / sizeof(unsigned long);
17853 ++
17854 ++ for (i = num_longs; i--; l1++, l2++) {
17855 ++ if (unlikely(*l1 != *l2))
17856 ++ return 0;
17857 ++ }
17858 ++
17859 ++ c1 = (unsigned char *) l1;
17860 ++ c2 = (unsigned char *) l2;
17861 ++
17862 ++ i = lena - (num_longs * sizeof(unsigned long));
17863 ++
17864 ++ for (; i--; c1++, c2++) {
17865 ++ if (unlikely(*c1 != *c2))
17866 ++ return 0;
17867 ++ }
17868 ++
17869 ++ return 1;
17870 ++}
17871 ++
17872 ++static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
17873 ++ struct dentry *root, struct vfsmount *rootmnt,
17874 ++ char *buffer, int buflen)
17875 ++{
17876 ++ char * end = buffer+buflen;
17877 ++ char * retval;
17878 ++ int namelen;
17879 ++
17880 ++ *--end = '\0';
17881 ++ buflen--;
17882 ++
17883 ++ if (buflen < 1)
17884 ++ goto Elong;
17885 ++ /* Get '/' right */
17886 ++ retval = end-1;
17887 ++ *retval = '/';
17888 ++
17889 ++ for (;;) {
17890 ++ struct dentry * parent;
17891 ++
17892 ++ if (dentry == root && vfsmnt == rootmnt)
17893 ++ break;
17894 ++ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
17895 ++ /* Global root? */
17896 ++ spin_lock(&vfsmount_lock);
17897 ++ if (vfsmnt->mnt_parent == vfsmnt) {
17898 ++ spin_unlock(&vfsmount_lock);
17899 ++ goto global_root;
17900 ++ }
17901 ++ dentry = vfsmnt->mnt_mountpoint;
17902 ++ vfsmnt = vfsmnt->mnt_parent;
17903 ++ spin_unlock(&vfsmount_lock);
17904 ++ continue;
17905 ++ }
17906 ++ parent = dentry->d_parent;
17907 ++ prefetch(parent);
17908 ++ namelen = dentry->d_name.len;
17909 ++ buflen -= namelen + 1;
17910 ++ if (buflen < 0)
17911 ++ goto Elong;
17912 ++ end -= namelen;
17913 ++ memcpy(end, dentry->d_name.name, namelen);
17914 ++ *--end = '/';
17915 ++ retval = end;
17916 ++ dentry = parent;
17917 ++ }
17918 ++
17919 ++ return retval;
17920 ++
17921 ++global_root:
17922 ++ namelen = dentry->d_name.len;
17923 ++ buflen -= namelen;
17924 ++ if (buflen < 0)
17925 ++ goto Elong;
17926 ++ retval -= namelen-1; /* hit the slash */
17927 ++ memcpy(retval, dentry->d_name.name, namelen);
17928 ++ return retval;
17929 ++Elong:
17930 ++ return ERR_PTR(-ENAMETOOLONG);
17931 ++}
17932 ++
17933 ++static char *
17934 ++gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
17935 ++ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
17936 ++{
17937 ++ char *retval;
17938 ++
17939 ++ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
17940 ++ if (unlikely(IS_ERR(retval)))
17941 ++ retval = strcpy(buf, "<path too long>");
17942 ++ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
17943 ++ retval[1] = '\0';
17944 ++
17945 ++ return retval;
17946 ++}
17947 ++
17948 ++static char *
17949 ++__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
17950 ++ char *buf, int buflen)
17951 ++{
17952 ++ char *res;
17953 ++
17954 ++ /* we can use real_root, real_root_mnt, because this is only called
17955 ++ by the RBAC system */
17956 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
17957 ++
17958 ++ return res;
17959 ++}
17960 ++
17961 ++static char *
17962 ++d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
17963 ++ char *buf, int buflen)
17964 ++{
17965 ++ char *res;
17966 ++ struct dentry *root;
17967 ++ struct vfsmount *rootmnt;
17968 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
17969 ++
17970 ++ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
17971 ++ read_lock(&reaper->fs->lock);
17972 ++ root = dget(reaper->fs->root.dentry);
17973 ++ rootmnt = mntget(reaper->fs->root.mnt);
17974 ++ read_unlock(&reaper->fs->lock);
17975 ++
17976 ++ spin_lock(&dcache_lock);
17977 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
17978 ++ spin_unlock(&dcache_lock);
17979 ++
17980 ++ dput(root);
17981 ++ mntput(rootmnt);
17982 ++ return res;
17983 ++}
17984 ++
17985 ++static char *
17986 ++gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
17987 ++{
17988 ++ char *ret;
17989 ++ spin_lock(&dcache_lock);
17990 ++ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
17991 ++ PAGE_SIZE);
17992 ++ spin_unlock(&dcache_lock);
17993 ++ return ret;
17994 ++}
17995 ++
17996 ++char *
17997 ++gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
17998 ++{
17999 ++ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
18000 ++ PAGE_SIZE);
18001 ++}
18002 ++
18003 ++char *
18004 ++gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
18005 ++{
18006 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
18007 ++ PAGE_SIZE);
18008 ++}
18009 ++
18010 ++char *
18011 ++gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
18012 ++{
18013 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
18014 ++ PAGE_SIZE);
18015 ++}
18016 ++
18017 ++char *
18018 ++gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
18019 ++{
18020 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
18021 ++ PAGE_SIZE);
18022 ++}
18023 ++
18024 ++char *
18025 ++gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
18026 ++{
18027 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
18028 ++ PAGE_SIZE);
18029 ++}
18030 ++
18031 ++__inline__ __u32
18032 ++to_gr_audit(const __u32 reqmode)
18033 ++{
18034 ++ /* masks off auditable permission flags, then shifts them to create
18035 ++ auditing flags, and adds the special case of append auditing if
18036 ++ we're requesting write */
18037 ++ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
18038 ++}
18039 ++
18040 ++struct acl_subject_label *
18041 ++lookup_subject_map(const struct acl_subject_label *userp)
18042 ++{
18043 ++ unsigned int index = shash(userp, subj_map_set.s_size);
18044 ++ struct subject_map *match;
18045 ++
18046 ++ match = subj_map_set.s_hash[index];
18047 ++
18048 ++ while (match && match->user != userp)
18049 ++ match = match->next;
18050 ++
18051 ++ if (match != NULL)
18052 ++ return match->kernel;
18053 ++ else
18054 ++ return NULL;
18055 ++}
18056 ++
18057 ++static void
18058 ++insert_subj_map_entry(struct subject_map *subjmap)
18059 ++{
18060 ++ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
18061 ++ struct subject_map **curr;
18062 ++
18063 ++ subjmap->prev = NULL;
18064 ++
18065 ++ curr = &subj_map_set.s_hash[index];
18066 ++ if (*curr != NULL)
18067 ++ (*curr)->prev = subjmap;
18068 ++
18069 ++ subjmap->next = *curr;
18070 ++ *curr = subjmap;
18071 ++
18072 ++ return;
18073 ++}
18074 ++
18075 ++static struct acl_role_label *
18076 ++lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
18077 ++ const gid_t gid)
18078 ++{
18079 ++ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
18080 ++ struct acl_role_label *match;
18081 ++ struct role_allowed_ip *ipp;
18082 ++ unsigned int x;
18083 ++
18084 ++ match = acl_role_set.r_hash[index];
18085 ++
18086 ++ while (match) {
18087 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
18088 ++ for (x = 0; x < match->domain_child_num; x++) {
18089 ++ if (match->domain_children[x] == uid)
18090 ++ goto found;
18091 ++ }
18092 ++ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
18093 ++ break;
18094 ++ match = match->next;
18095 ++ }
18096 ++found:
18097 ++ if (match == NULL) {
18098 ++ try_group:
18099 ++ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
18100 ++ match = acl_role_set.r_hash[index];
18101 ++
18102 ++ while (match) {
18103 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
18104 ++ for (x = 0; x < match->domain_child_num; x++) {
18105 ++ if (match->domain_children[x] == gid)
18106 ++ goto found2;
18107 ++ }
18108 ++ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
18109 ++ break;
18110 ++ match = match->next;
18111 ++ }
18112 ++found2:
18113 ++ if (match == NULL)
18114 ++ match = default_role;
18115 ++ if (match->allowed_ips == NULL)
18116 ++ return match;
18117 ++ else {
18118 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18119 ++ if (likely
18120 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18121 ++ (ntohl(ipp->addr) & ipp->netmask)))
18122 ++ return match;
18123 ++ }
18124 ++ match = default_role;
18125 ++ }
18126 ++ } else if (match->allowed_ips == NULL) {
18127 ++ return match;
18128 ++ } else {
18129 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18130 ++ if (likely
18131 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18132 ++ (ntohl(ipp->addr) & ipp->netmask)))
18133 ++ return match;
18134 ++ }
18135 ++ goto try_group;
18136 ++ }
18137 ++
18138 ++ return match;
18139 ++}
18140 ++
18141 ++struct acl_subject_label *
18142 ++lookup_acl_subj_label(const ino_t ino, const dev_t dev,
18143 ++ const struct acl_role_label *role)
18144 ++{
18145 ++ unsigned int index = fhash(ino, dev, role->subj_hash_size);
18146 ++ struct acl_subject_label *match;
18147 ++
18148 ++ match = role->subj_hash[index];
18149 ++
18150 ++ while (match && (match->inode != ino || match->device != dev ||
18151 ++ (match->mode & GR_DELETED))) {
18152 ++ match = match->next;
18153 ++ }
18154 ++
18155 ++ if (match && !(match->mode & GR_DELETED))
18156 ++ return match;
18157 ++ else
18158 ++ return NULL;
18159 ++}
18160 ++
18161 ++static struct acl_object_label *
18162 ++lookup_acl_obj_label(const ino_t ino, const dev_t dev,
18163 ++ const struct acl_subject_label *subj)
18164 ++{
18165 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18166 ++ struct acl_object_label *match;
18167 ++
18168 ++ match = subj->obj_hash[index];
18169 ++
18170 ++ while (match && (match->inode != ino || match->device != dev ||
18171 ++ (match->mode & GR_DELETED))) {
18172 ++ match = match->next;
18173 ++ }
18174 ++
18175 ++ if (match && !(match->mode & GR_DELETED))
18176 ++ return match;
18177 ++ else
18178 ++ return NULL;
18179 ++}
18180 ++
18181 ++static struct acl_object_label *
18182 ++lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
18183 ++ const struct acl_subject_label *subj)
18184 ++{
18185 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18186 ++ struct acl_object_label *match;
18187 ++
18188 ++ match = subj->obj_hash[index];
18189 ++
18190 ++ while (match && (match->inode != ino || match->device != dev ||
18191 ++ !(match->mode & GR_DELETED))) {
18192 ++ match = match->next;
18193 ++ }
18194 ++
18195 ++ if (match && (match->mode & GR_DELETED))
18196 ++ return match;
18197 ++
18198 ++ match = subj->obj_hash[index];
18199 ++
18200 ++ while (match && (match->inode != ino || match->device != dev ||
18201 ++ (match->mode & GR_DELETED))) {
18202 ++ match = match->next;
18203 ++ }
18204 ++
18205 ++ if (match && !(match->mode & GR_DELETED))
18206 ++ return match;
18207 ++ else
18208 ++ return NULL;
18209 ++}
18210 ++
18211 ++static struct name_entry *
18212 ++lookup_name_entry(const char *name)
18213 ++{
18214 ++ unsigned int len = strlen(name);
18215 ++ unsigned int key = full_name_hash(name, len);
18216 ++ unsigned int index = key % name_set.n_size;
18217 ++ struct name_entry *match;
18218 ++
18219 ++ match = name_set.n_hash[index];
18220 ++
18221 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
18222 ++ match = match->next;
18223 ++
18224 ++ return match;
18225 ++}
18226 ++
18227 ++static struct name_entry *
18228 ++lookup_name_entry_create(const char *name)
18229 ++{
18230 ++ unsigned int len = strlen(name);
18231 ++ unsigned int key = full_name_hash(name, len);
18232 ++ unsigned int index = key % name_set.n_size;
18233 ++ struct name_entry *match;
18234 ++
18235 ++ match = name_set.n_hash[index];
18236 ++
18237 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18238 ++ !match->deleted))
18239 ++ match = match->next;
18240 ++
18241 ++ if (match && match->deleted)
18242 ++ return match;
18243 ++
18244 ++ match = name_set.n_hash[index];
18245 ++
18246 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18247 ++ match->deleted))
18248 ++ match = match->next;
18249 ++
18250 ++ if (match && !match->deleted)
18251 ++ return match;
18252 ++ else
18253 ++ return NULL;
18254 ++}
18255 ++
18256 ++static struct inodev_entry *
18257 ++lookup_inodev_entry(const ino_t ino, const dev_t dev)
18258 ++{
18259 ++ unsigned int index = fhash(ino, dev, inodev_set.i_size);
18260 ++ struct inodev_entry *match;
18261 ++
18262 ++ match = inodev_set.i_hash[index];
18263 ++
18264 ++ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
18265 ++ match = match->next;
18266 ++
18267 ++ return match;
18268 ++}
18269 ++
18270 ++static void
18271 ++insert_inodev_entry(struct inodev_entry *entry)
18272 ++{
18273 ++ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
18274 ++ inodev_set.i_size);
18275 ++ struct inodev_entry **curr;
18276 ++
18277 ++ entry->prev = NULL;
18278 ++
18279 ++ curr = &inodev_set.i_hash[index];
18280 ++ if (*curr != NULL)
18281 ++ (*curr)->prev = entry;
18282 ++
18283 ++ entry->next = *curr;
18284 ++ *curr = entry;
18285 ++
18286 ++ return;
18287 ++}
18288 ++
18289 ++static void
18290 ++__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
18291 ++{
18292 ++ unsigned int index =
18293 ++ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
18294 ++ struct acl_role_label **curr;
18295 ++
18296 ++ role->prev = NULL;
18297 ++
18298 ++ curr = &acl_role_set.r_hash[index];
18299 ++ if (*curr != NULL)
18300 ++ (*curr)->prev = role;
18301 ++
18302 ++ role->next = *curr;
18303 ++ *curr = role;
18304 ++
18305 ++ return;
18306 ++}
18307 ++
18308 ++static void
18309 ++insert_acl_role_label(struct acl_role_label *role)
18310 ++{
18311 ++ int i;
18312 ++
18313 ++ if (role->roletype & GR_ROLE_DOMAIN) {
18314 ++ for (i = 0; i < role->domain_child_num; i++)
18315 ++ __insert_acl_role_label(role, role->domain_children[i]);
18316 ++ } else
18317 ++ __insert_acl_role_label(role, role->uidgid);
18318 ++}
18319 ++
18320 ++static int
18321 ++insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
18322 ++{
18323 ++ struct name_entry **curr, *nentry;
18324 ++ struct inodev_entry *ientry;
18325 ++ unsigned int len = strlen(name);
18326 ++ unsigned int key = full_name_hash(name, len);
18327 ++ unsigned int index = key % name_set.n_size;
18328 ++
18329 ++ curr = &name_set.n_hash[index];
18330 ++
18331 ++ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
18332 ++ curr = &((*curr)->next);
18333 ++
18334 ++ if (*curr != NULL)
18335 ++ return 1;
18336 ++
18337 ++ nentry = acl_alloc(sizeof (struct name_entry));
18338 ++ if (nentry == NULL)
18339 ++ return 0;
18340 ++ ientry = acl_alloc(sizeof (struct inodev_entry));
18341 ++ if (ientry == NULL)
18342 ++ return 0;
18343 ++ ientry->nentry = nentry;
18344 ++
18345 ++ nentry->key = key;
18346 ++ nentry->name = name;
18347 ++ nentry->inode = inode;
18348 ++ nentry->device = device;
18349 ++ nentry->len = len;
18350 ++ nentry->deleted = deleted;
18351 ++
18352 ++ nentry->prev = NULL;
18353 ++ curr = &name_set.n_hash[index];
18354 ++ if (*curr != NULL)
18355 ++ (*curr)->prev = nentry;
18356 ++ nentry->next = *curr;
18357 ++ *curr = nentry;
18358 ++
18359 ++ /* insert us into the table searchable by inode/dev */
18360 ++ insert_inodev_entry(ientry);
18361 ++
18362 ++ return 1;
18363 ++}
18364 ++
18365 ++static void
18366 ++insert_acl_obj_label(struct acl_object_label *obj,
18367 ++ struct acl_subject_label *subj)
18368 ++{
18369 ++ unsigned int index =
18370 ++ fhash(obj->inode, obj->device, subj->obj_hash_size);
18371 ++ struct acl_object_label **curr;
18372 ++
18373 ++
18374 ++ obj->prev = NULL;
18375 ++
18376 ++ curr = &subj->obj_hash[index];
18377 ++ if (*curr != NULL)
18378 ++ (*curr)->prev = obj;
18379 ++
18380 ++ obj->next = *curr;
18381 ++ *curr = obj;
18382 ++
18383 ++ return;
18384 ++}
18385 ++
18386 ++static void
18387 ++insert_acl_subj_label(struct acl_subject_label *obj,
18388 ++ struct acl_role_label *role)
18389 ++{
18390 ++ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
18391 ++ struct acl_subject_label **curr;
18392 ++
18393 ++ obj->prev = NULL;
18394 ++
18395 ++ curr = &role->subj_hash[index];
18396 ++ if (*curr != NULL)
18397 ++ (*curr)->prev = obj;
18398 ++
18399 ++ obj->next = *curr;
18400 ++ *curr = obj;
18401 ++
18402 ++ return;
18403 ++}
18404 ++
18405 ++/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
18406 ++
18407 ++static void *
18408 ++create_table(__u32 * len, int elementsize)
18409 ++{
18410 ++ unsigned int table_sizes[] = {
18411 ++ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
18412 ++ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
18413 ++ 4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
18414 ++ 268435399, 536870909, 1073741789, 2147483647
18415 ++ };
18416 ++ void *newtable = NULL;
18417 ++ unsigned int pwr = 0;
18418 ++
18419 ++ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
18420 ++ table_sizes[pwr] <= *len)
18421 ++ pwr++;
18422 ++
18423 ++ if (table_sizes[pwr] <= *len)
18424 ++ return newtable;
18425 ++
18426 ++ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
18427 ++ newtable =
18428 ++ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
18429 ++ else
18430 ++ newtable = vmalloc(table_sizes[pwr] * elementsize);
18431 ++
18432 ++ *len = table_sizes[pwr];
18433 ++
18434 ++ return newtable;
18435 ++}
18436 ++
18437 ++static int
18438 ++init_variables(const struct gr_arg *arg)
18439 ++{
18440 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
18441 ++ unsigned int stacksize;
18442 ++
18443 ++ subj_map_set.s_size = arg->role_db.num_subjects;
18444 ++ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
18445 ++ name_set.n_size = arg->role_db.num_objects;
18446 ++ inodev_set.i_size = arg->role_db.num_objects;
18447 ++
18448 ++ if (!subj_map_set.s_size || !acl_role_set.r_size ||
18449 ++ !name_set.n_size || !inodev_set.i_size)
18450 ++ return 1;
18451 ++
18452 ++ if (!gr_init_uidset())
18453 ++ return 1;
18454 ++
18455 ++ /* set up the stack that holds allocation info */
18456 ++
18457 ++ stacksize = arg->role_db.num_pointers + 5;
18458 ++
18459 ++ if (!acl_alloc_stack_init(stacksize))
18460 ++ return 1;
18461 ++
18462 ++ /* grab reference for the real root dentry and vfsmount */
18463 ++ read_lock(&reaper->fs->lock);
18464 ++ real_root_mnt = mntget(reaper->fs->root.mnt);
18465 ++ real_root = dget(reaper->fs->root.dentry);
18466 ++ read_unlock(&reaper->fs->lock);
18467 ++
18468 ++ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
18469 ++ if (fakefs_obj == NULL)
18470 ++ return 1;
18471 ++ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
18472 ++
18473 ++ subj_map_set.s_hash =
18474 ++ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
18475 ++ acl_role_set.r_hash =
18476 ++ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
18477 ++ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
18478 ++ inodev_set.i_hash =
18479 ++ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
18480 ++
18481 ++ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
18482 ++ !name_set.n_hash || !inodev_set.i_hash)
18483 ++ return 1;
18484 ++
18485 ++ memset(subj_map_set.s_hash, 0,
18486 ++ sizeof(struct subject_map *) * subj_map_set.s_size);
18487 ++ memset(acl_role_set.r_hash, 0,
18488 ++ sizeof (struct acl_role_label *) * acl_role_set.r_size);
18489 ++ memset(name_set.n_hash, 0,
18490 ++ sizeof (struct name_entry *) * name_set.n_size);
18491 ++ memset(inodev_set.i_hash, 0,
18492 ++ sizeof (struct inodev_entry *) * inodev_set.i_size);
18493 ++
18494 ++ return 0;
18495 ++}
18496 ++
18497 ++/* free information not needed after startup
18498 ++ currently contains user->kernel pointer mappings for subjects
18499 ++*/
18500 ++
18501 ++static void
18502 ++free_init_variables(void)
18503 ++{
18504 ++ __u32 i;
18505 ++
18506 ++ if (subj_map_set.s_hash) {
18507 ++ for (i = 0; i < subj_map_set.s_size; i++) {
18508 ++ if (subj_map_set.s_hash[i]) {
18509 ++ kfree(subj_map_set.s_hash[i]);
18510 ++ subj_map_set.s_hash[i] = NULL;
18511 ++ }
18512 ++ }
18513 ++
18514 ++ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
18515 ++ PAGE_SIZE)
18516 ++ kfree(subj_map_set.s_hash);
18517 ++ else
18518 ++ vfree(subj_map_set.s_hash);
18519 ++ }
18520 ++
18521 ++ return;
18522 ++}
18523 ++
18524 ++static void
18525 ++free_variables(void)
18526 ++{
18527 ++ struct acl_subject_label *s;
18528 ++ struct acl_role_label *r;
18529 ++ struct task_struct *task, *task2;
18530 ++ unsigned int i, x;
18531 ++
18532 ++ gr_clear_learn_entries();
18533 ++
18534 ++ read_lock(&tasklist_lock);
18535 ++ do_each_thread(task2, task) {
18536 ++ task->acl_sp_role = 0;
18537 ++ task->acl_role_id = 0;
18538 ++ task->acl = NULL;
18539 ++ task->role = NULL;
18540 ++ } while_each_thread(task2, task);
18541 ++ read_unlock(&tasklist_lock);
18542 ++
18543 ++ /* release the reference to the real root dentry and vfsmount */
18544 ++ if (real_root)
18545 ++ dput(real_root);
18546 ++ real_root = NULL;
18547 ++ if (real_root_mnt)
18548 ++ mntput(real_root_mnt);
18549 ++ real_root_mnt = NULL;
18550 ++
18551 ++ /* free all object hash tables */
18552 ++
18553 ++ FOR_EACH_ROLE_START(r, i)
18554 ++ if (r->subj_hash == NULL)
18555 ++ break;
18556 ++ FOR_EACH_SUBJECT_START(r, s, x)
18557 ++ if (s->obj_hash == NULL)
18558 ++ break;
18559 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18560 ++ kfree(s->obj_hash);
18561 ++ else
18562 ++ vfree(s->obj_hash);
18563 ++ FOR_EACH_SUBJECT_END(s, x)
18564 ++ FOR_EACH_NESTED_SUBJECT_START(r, s)
18565 ++ if (s->obj_hash == NULL)
18566 ++ break;
18567 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18568 ++ kfree(s->obj_hash);
18569 ++ else
18570 ++ vfree(s->obj_hash);
18571 ++ FOR_EACH_NESTED_SUBJECT_END(s)
18572 ++ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
18573 ++ kfree(r->subj_hash);
18574 ++ else
18575 ++ vfree(r->subj_hash);
18576 ++ r->subj_hash = NULL;
18577 ++ FOR_EACH_ROLE_END(r,i)
18578 ++
18579 ++ acl_free_all();
18580 ++
18581 ++ if (acl_role_set.r_hash) {
18582 ++ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
18583 ++ PAGE_SIZE)
18584 ++ kfree(acl_role_set.r_hash);
18585 ++ else
18586 ++ vfree(acl_role_set.r_hash);
18587 ++ }
18588 ++ if (name_set.n_hash) {
18589 ++ if ((name_set.n_size * sizeof (struct name_entry *)) <=
18590 ++ PAGE_SIZE)
18591 ++ kfree(name_set.n_hash);
18592 ++ else
18593 ++ vfree(name_set.n_hash);
18594 ++ }
18595 ++
18596 ++ if (inodev_set.i_hash) {
18597 ++ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
18598 ++ PAGE_SIZE)
18599 ++ kfree(inodev_set.i_hash);
18600 ++ else
18601 ++ vfree(inodev_set.i_hash);
18602 ++ }
18603 ++
18604 ++ gr_free_uidset();
18605 ++
18606 ++ memset(&name_set, 0, sizeof (struct name_db));
18607 ++ memset(&inodev_set, 0, sizeof (struct inodev_db));
18608 ++ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
18609 ++ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
18610 ++
18611 ++ default_role = NULL;
18612 ++
18613 ++ return;
18614 ++}
18615 ++
18616 ++static __u32
18617 ++count_user_objs(struct acl_object_label *userp)
18618 ++{
18619 ++ struct acl_object_label o_tmp;
18620 ++ __u32 num = 0;
18621 ++
18622 ++ while (userp) {
18623 ++ if (copy_from_user(&o_tmp, userp,
18624 ++ sizeof (struct acl_object_label)))
18625 ++ break;
18626 ++
18627 ++ userp = o_tmp.prev;
18628 ++ num++;
18629 ++ }
18630 ++
18631 ++ return num;
18632 ++}
18633 ++
18634 ++static struct acl_subject_label *
18635 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
18636 ++
18637 ++static int
18638 ++copy_user_glob(struct acl_object_label *obj)
18639 ++{
18640 ++ struct acl_object_label *g_tmp, **guser;
18641 ++ unsigned int len;
18642 ++ char *tmp;
18643 ++
18644 ++ if (obj->globbed == NULL)
18645 ++ return 0;
18646 ++
18647 ++ guser = &obj->globbed;
18648 ++ while (*guser) {
18649 ++ g_tmp = (struct acl_object_label *)
18650 ++ acl_alloc(sizeof (struct acl_object_label));
18651 ++ if (g_tmp == NULL)
18652 ++ return -ENOMEM;
18653 ++
18654 ++ if (copy_from_user(g_tmp, *guser,
18655 ++ sizeof (struct acl_object_label)))
18656 ++ return -EFAULT;
18657 ++
18658 ++ len = strnlen_user(g_tmp->filename, PATH_MAX);
18659 ++
18660 ++ if (!len || len >= PATH_MAX)
18661 ++ return -EINVAL;
18662 ++
18663 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18664 ++ return -ENOMEM;
18665 ++
18666 ++ if (copy_from_user(tmp, g_tmp->filename, len))
18667 ++ return -EFAULT;
18668 ++
18669 ++ g_tmp->filename = tmp;
18670 ++
18671 ++ *guser = g_tmp;
18672 ++ guser = &(g_tmp->next);
18673 ++ }
18674 ++
18675 ++ return 0;
18676 ++}
18677 ++
18678 ++static int
18679 ++copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
18680 ++ struct acl_role_label *role)
18681 ++{
18682 ++ struct acl_object_label *o_tmp;
18683 ++ unsigned int len;
18684 ++ int ret;
18685 ++ char *tmp;
18686 ++
18687 ++ while (userp) {
18688 ++ if ((o_tmp = (struct acl_object_label *)
18689 ++ acl_alloc(sizeof (struct acl_object_label))) == NULL)
18690 ++ return -ENOMEM;
18691 ++
18692 ++ if (copy_from_user(o_tmp, userp,
18693 ++ sizeof (struct acl_object_label)))
18694 ++ return -EFAULT;
18695 ++
18696 ++ userp = o_tmp->prev;
18697 ++
18698 ++ len = strnlen_user(o_tmp->filename, PATH_MAX);
18699 ++
18700 ++ if (!len || len >= PATH_MAX)
18701 ++ return -EINVAL;
18702 ++
18703 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18704 ++ return -ENOMEM;
18705 ++
18706 ++ if (copy_from_user(tmp, o_tmp->filename, len))
18707 ++ return -EFAULT;
18708 ++
18709 ++ o_tmp->filename = tmp;
18710 ++
18711 ++ insert_acl_obj_label(o_tmp, subj);
18712 ++ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
18713 ++ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
18714 ++ return -ENOMEM;
18715 ++
18716 ++ ret = copy_user_glob(o_tmp);
18717 ++ if (ret)
18718 ++ return ret;
18719 ++
18720 ++ if (o_tmp->nested) {
18721 ++ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
18722 ++ if (IS_ERR(o_tmp->nested))
18723 ++ return PTR_ERR(o_tmp->nested);
18724 ++
18725 ++ /* insert into nested subject list */
18726 ++ o_tmp->nested->next = role->hash->first;
18727 ++ role->hash->first = o_tmp->nested;
18728 ++ }
18729 ++ }
18730 ++
18731 ++ return 0;
18732 ++}
18733 ++
18734 ++static __u32
18735 ++count_user_subjs(struct acl_subject_label *userp)
18736 ++{
18737 ++ struct acl_subject_label s_tmp;
18738 ++ __u32 num = 0;
18739 ++
18740 ++ while (userp) {
18741 ++ if (copy_from_user(&s_tmp, userp,
18742 ++ sizeof (struct acl_subject_label)))
18743 ++ break;
18744 ++
18745 ++ userp = s_tmp.prev;
18746 ++ /* do not count nested subjects against this count, since
18747 ++ they are not included in the hash table, but are
18748 ++ attached to objects. We have already counted
18749 ++ the subjects in userspace for the allocation
18750 ++ stack
18751 ++ */
18752 ++ if (!(s_tmp.mode & GR_NESTED))
18753 ++ num++;
18754 ++ }
18755 ++
18756 ++ return num;
18757 ++}
18758 ++
18759 ++static int
18760 ++copy_user_allowedips(struct acl_role_label *rolep)
18761 ++{
18762 ++ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
18763 ++
18764 ++ ruserip = rolep->allowed_ips;
18765 ++
18766 ++ while (ruserip) {
18767 ++ rlast = rtmp;
18768 ++
18769 ++ if ((rtmp = (struct role_allowed_ip *)
18770 ++ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
18771 ++ return -ENOMEM;
18772 ++
18773 ++ if (copy_from_user(rtmp, ruserip,
18774 ++ sizeof (struct role_allowed_ip)))
18775 ++ return -EFAULT;
18776 ++
18777 ++ ruserip = rtmp->prev;
18778 ++
18779 ++ if (!rlast) {
18780 ++ rtmp->prev = NULL;
18781 ++ rolep->allowed_ips = rtmp;
18782 ++ } else {
18783 ++ rlast->next = rtmp;
18784 ++ rtmp->prev = rlast;
18785 ++ }
18786 ++
18787 ++ if (!ruserip)
18788 ++ rtmp->next = NULL;
18789 ++ }
18790 ++
18791 ++ return 0;
18792 ++}
18793 ++
18794 ++static int
18795 ++copy_user_transitions(struct acl_role_label *rolep)
18796 ++{
18797 ++ struct role_transition *rusertp, *rtmp = NULL, *rlast;
18798 ++
18799 ++ unsigned int len;
18800 ++ char *tmp;
18801 ++
18802 ++ rusertp = rolep->transitions;
18803 ++
18804 ++ while (rusertp) {
18805 ++ rlast = rtmp;
18806 ++
18807 ++ if ((rtmp = (struct role_transition *)
18808 ++ acl_alloc(sizeof (struct role_transition))) == NULL)
18809 ++ return -ENOMEM;
18810 ++
18811 ++ if (copy_from_user(rtmp, rusertp,
18812 ++ sizeof (struct role_transition)))
18813 ++ return -EFAULT;
18814 ++
18815 ++ rusertp = rtmp->prev;
18816 ++
18817 ++ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
18818 ++
18819 ++ if (!len || len >= GR_SPROLE_LEN)
18820 ++ return -EINVAL;
18821 ++
18822 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18823 ++ return -ENOMEM;
18824 ++
18825 ++ if (copy_from_user(tmp, rtmp->rolename, len))
18826 ++ return -EFAULT;
18827 ++
18828 ++ rtmp->rolename = tmp;
18829 ++
18830 ++ if (!rlast) {
18831 ++ rtmp->prev = NULL;
18832 ++ rolep->transitions = rtmp;
18833 ++ } else {
18834 ++ rlast->next = rtmp;
18835 ++ rtmp->prev = rlast;
18836 ++ }
18837 ++
18838 ++ if (!rusertp)
18839 ++ rtmp->next = NULL;
18840 ++ }
18841 ++
18842 ++ return 0;
18843 ++}
18844 ++
18845 ++static struct acl_subject_label *
18846 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
18847 ++{
18848 ++ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
18849 ++ unsigned int len;
18850 ++ char *tmp;
18851 ++ __u32 num_objs;
18852 ++ struct acl_ip_label **i_tmp, *i_utmp2;
18853 ++ struct gr_hash_struct ghash;
18854 ++ struct subject_map *subjmap;
18855 ++ unsigned int i_num;
18856 ++ int err;
18857 ++
18858 ++ s_tmp = lookup_subject_map(userp);
18859 ++
18860 ++ /* we've already copied this subject into the kernel, just return
18861 ++ the reference to it, and don't copy it over again
18862 ++ */
18863 ++ if (s_tmp)
18864 ++ return(s_tmp);
18865 ++
18866 ++ if ((s_tmp = (struct acl_subject_label *)
18867 ++ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
18868 ++ return ERR_PTR(-ENOMEM);
18869 ++
18870 ++ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
18871 ++ if (subjmap == NULL)
18872 ++ return ERR_PTR(-ENOMEM);
18873 ++
18874 ++ subjmap->user = userp;
18875 ++ subjmap->kernel = s_tmp;
18876 ++ insert_subj_map_entry(subjmap);
18877 ++
18878 ++ if (copy_from_user(s_tmp, userp,
18879 ++ sizeof (struct acl_subject_label)))
18880 ++ return ERR_PTR(-EFAULT);
18881 ++
18882 ++ len = strnlen_user(s_tmp->filename, PATH_MAX);
18883 ++
18884 ++ if (!len || len >= PATH_MAX)
18885 ++ return ERR_PTR(-EINVAL);
18886 ++
18887 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18888 ++ return ERR_PTR(-ENOMEM);
18889 ++
18890 ++ if (copy_from_user(tmp, s_tmp->filename, len))
18891 ++ return ERR_PTR(-EFAULT);
18892 ++
18893 ++ s_tmp->filename = tmp;
18894 ++
18895 ++ if (!strcmp(s_tmp->filename, "/"))
18896 ++ role->root_label = s_tmp;
18897 ++
18898 ++ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
18899 ++ return ERR_PTR(-EFAULT);
18900 ++
18901 ++ /* copy user and group transition tables */
18902 ++
18903 ++ if (s_tmp->user_trans_num) {
18904 ++ uid_t *uidlist;
18905 ++
18906 ++ uidlist = (uid_t *)acl_alloc(s_tmp->user_trans_num * sizeof(uid_t));
18907 ++ if (uidlist == NULL)
18908 ++ return ERR_PTR(-ENOMEM);
18909 ++ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
18910 ++ return ERR_PTR(-EFAULT);
18911 ++
18912 ++ s_tmp->user_transitions = uidlist;
18913 ++ }
18914 ++
18915 ++ if (s_tmp->group_trans_num) {
18916 ++ gid_t *gidlist;
18917 ++
18918 ++ gidlist = (gid_t *)acl_alloc(s_tmp->group_trans_num * sizeof(gid_t));
18919 ++ if (gidlist == NULL)
18920 ++ return ERR_PTR(-ENOMEM);
18921 ++ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
18922 ++ return ERR_PTR(-EFAULT);
18923 ++
18924 ++ s_tmp->group_transitions = gidlist;
18925 ++ }
18926 ++
18927 ++ /* set up object hash table */
18928 ++ num_objs = count_user_objs(ghash.first);
18929 ++
18930 ++ s_tmp->obj_hash_size = num_objs;
18931 ++ s_tmp->obj_hash =
18932 ++ (struct acl_object_label **)
18933 ++ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
18934 ++
18935 ++ if (!s_tmp->obj_hash)
18936 ++ return ERR_PTR(-ENOMEM);
18937 ++
18938 ++ memset(s_tmp->obj_hash, 0,
18939 ++ s_tmp->obj_hash_size *
18940 ++ sizeof (struct acl_object_label *));
18941 ++
18942 ++ /* add in objects */
18943 ++ err = copy_user_objs(ghash.first, s_tmp, role);
18944 ++
18945 ++ if (err)
18946 ++ return ERR_PTR(err);
18947 ++
18948 ++ /* set pointer for parent subject */
18949 ++ if (s_tmp->parent_subject) {
18950 ++ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
18951 ++
18952 ++ if (IS_ERR(s_tmp2))
18953 ++ return s_tmp2;
18954 ++
18955 ++ s_tmp->parent_subject = s_tmp2;
18956 ++ }
18957 ++
18958 ++ /* add in ip acls */
18959 ++
18960 ++ if (!s_tmp->ip_num) {
18961 ++ s_tmp->ips = NULL;
18962 ++ goto insert;
18963 ++ }
18964 ++
18965 ++ i_tmp =
18966 ++ (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
18967 ++ sizeof (struct
18968 ++ acl_ip_label *));
18969 ++
18970 ++ if (!i_tmp)
18971 ++ return ERR_PTR(-ENOMEM);
18972 ++
18973 ++ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
18974 ++ *(i_tmp + i_num) =
18975 ++ (struct acl_ip_label *)
18976 ++ acl_alloc(sizeof (struct acl_ip_label));
18977 ++ if (!*(i_tmp + i_num))
18978 ++ return ERR_PTR(-ENOMEM);
18979 ++
18980 ++ if (copy_from_user
18981 ++ (&i_utmp2, s_tmp->ips + i_num,
18982 ++ sizeof (struct acl_ip_label *)))
18983 ++ return ERR_PTR(-EFAULT);
18984 ++
18985 ++ if (copy_from_user
18986 ++ (*(i_tmp + i_num), i_utmp2,
18987 ++ sizeof (struct acl_ip_label)))
18988 ++ return ERR_PTR(-EFAULT);
18989 ++
18990 ++ if ((*(i_tmp + i_num))->iface == NULL)
18991 ++ continue;
18992 ++
18993 ++ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
18994 ++ if (!len || len >= IFNAMSIZ)
18995 ++ return ERR_PTR(-EINVAL);
18996 ++ tmp = acl_alloc(len);
18997 ++ if (tmp == NULL)
18998 ++ return ERR_PTR(-ENOMEM);
18999 ++ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
19000 ++ return ERR_PTR(-EFAULT);
19001 ++ (*(i_tmp + i_num))->iface = tmp;
19002 ++ }
19003 ++
19004 ++ s_tmp->ips = i_tmp;
19005 ++
19006 ++insert:
19007 ++ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
19008 ++ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
19009 ++ return ERR_PTR(-ENOMEM);
19010 ++
19011 ++ return s_tmp;
19012 ++}
19013 ++
19014 ++static int
19015 ++copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
19016 ++{
19017 ++ struct acl_subject_label s_pre;
19018 ++ struct acl_subject_label * ret;
19019 ++ int err;
19020 ++
19021 ++ while (userp) {
19022 ++ if (copy_from_user(&s_pre, userp,
19023 ++ sizeof (struct acl_subject_label)))
19024 ++ return -EFAULT;
19025 ++
19026 ++ /* do not add nested subjects here, add
19027 ++ while parsing objects
19028 ++ */
19029 ++
19030 ++ if (s_pre.mode & GR_NESTED) {
19031 ++ userp = s_pre.prev;
19032 ++ continue;
19033 ++ }
19034 ++
19035 ++ ret = do_copy_user_subj(userp, role);
19036 ++
19037 ++ err = PTR_ERR(ret);
19038 ++ if (IS_ERR(ret))
19039 ++ return err;
19040 ++
19041 ++ insert_acl_subj_label(ret, role);
19042 ++
19043 ++ userp = s_pre.prev;
19044 ++ }
19045 ++
19046 ++ return 0;
19047 ++}
19048 ++
19049 ++static int
19050 ++copy_user_acl(struct gr_arg *arg)
19051 ++{
19052 ++ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
19053 ++ struct sprole_pw *sptmp;
19054 ++ struct gr_hash_struct *ghash;
19055 ++ uid_t *domainlist;
19056 ++ unsigned int r_num;
19057 ++ unsigned int len;
19058 ++ char *tmp;
19059 ++ int err = 0;
19060 ++ __u16 i;
19061 ++ __u32 num_subjs;
19062 ++
19063 ++ /* we need a default and kernel role */
19064 ++ if (arg->role_db.num_roles < 2)
19065 ++ return -EINVAL;
19066 ++
19067 ++ /* copy special role authentication info from userspace */
19068 ++
19069 ++ num_sprole_pws = arg->num_sprole_pws;
19070 ++ acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
19071 ++
19072 ++ if (!acl_special_roles) {
19073 ++ err = -ENOMEM;
19074 ++ goto cleanup;
19075 ++ }
19076 ++
19077 ++ for (i = 0; i < num_sprole_pws; i++) {
19078 ++ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
19079 ++ if (!sptmp) {
19080 ++ err = -ENOMEM;
19081 ++ goto cleanup;
19082 ++ }
19083 ++ if (copy_from_user(sptmp, arg->sprole_pws + i,
19084 ++ sizeof (struct sprole_pw))) {
19085 ++ err = -EFAULT;
19086 ++ goto cleanup;
19087 ++ }
19088 ++
19089 ++ len =
19090 ++ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
19091 ++
19092 ++ if (!len || len >= GR_SPROLE_LEN) {
19093 ++ err = -EINVAL;
19094 ++ goto cleanup;
19095 ++ }
19096 ++
19097 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19098 ++ err = -ENOMEM;
19099 ++ goto cleanup;
19100 ++ }
19101 ++
19102 ++ if (copy_from_user(tmp, sptmp->rolename, len)) {
19103 ++ err = -EFAULT;
19104 ++ goto cleanup;
19105 ++ }
19106 ++
19107 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
19108 ++ printk(KERN_ALERT "Copying special role %s\n", tmp);
19109 ++#endif
19110 ++ sptmp->rolename = tmp;
19111 ++ acl_special_roles[i] = sptmp;
19112 ++ }
19113 ++
19114 ++ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
19115 ++
19116 ++ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
19117 ++ r_tmp = acl_alloc(sizeof (struct acl_role_label));
19118 ++
19119 ++ if (!r_tmp) {
19120 ++ err = -ENOMEM;
19121 ++ goto cleanup;
19122 ++ }
19123 ++
19124 ++ if (copy_from_user(&r_utmp2, r_utmp + r_num,
19125 ++ sizeof (struct acl_role_label *))) {
19126 ++ err = -EFAULT;
19127 ++ goto cleanup;
19128 ++ }
19129 ++
19130 ++ if (copy_from_user(r_tmp, r_utmp2,
19131 ++ sizeof (struct acl_role_label))) {
19132 ++ err = -EFAULT;
19133 ++ goto cleanup;
19134 ++ }
19135 ++
19136 ++ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
19137 ++
19138 ++ if (!len || len >= PATH_MAX) {
19139 ++ err = -EINVAL;
19140 ++ goto cleanup;
19141 ++ }
19142 ++
19143 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19144 ++ err = -ENOMEM;
19145 ++ goto cleanup;
19146 ++ }
19147 ++ if (copy_from_user(tmp, r_tmp->rolename, len)) {
19148 ++ err = -EFAULT;
19149 ++ goto cleanup;
19150 ++ }
19151 ++ r_tmp->rolename = tmp;
19152 ++
19153 ++ if (!strcmp(r_tmp->rolename, "default")
19154 ++ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
19155 ++ default_role = r_tmp;
19156 ++ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
19157 ++ kernel_role = r_tmp;
19158 ++ }
19159 ++
19160 ++ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
19161 ++ err = -ENOMEM;
19162 ++ goto cleanup;
19163 ++ }
19164 ++ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
19165 ++ err = -EFAULT;
19166 ++ goto cleanup;
19167 ++ }
19168 ++
19169 ++ r_tmp->hash = ghash;
19170 ++
19171 ++ num_subjs = count_user_subjs(r_tmp->hash->first);
19172 ++
19173 ++ r_tmp->subj_hash_size = num_subjs;
19174 ++ r_tmp->subj_hash =
19175 ++ (struct acl_subject_label **)
19176 ++ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
19177 ++
19178 ++ if (!r_tmp->subj_hash) {
19179 ++ err = -ENOMEM;
19180 ++ goto cleanup;
19181 ++ }
19182 ++
19183 ++ err = copy_user_allowedips(r_tmp);
19184 ++ if (err)
19185 ++ goto cleanup;
19186 ++
19187 ++ /* copy domain info */
19188 ++ if (r_tmp->domain_children != NULL) {
19189 ++ domainlist = acl_alloc(r_tmp->domain_child_num * sizeof(uid_t));
19190 ++ if (domainlist == NULL) {
19191 ++ err = -ENOMEM;
19192 ++ goto cleanup;
19193 ++ }
19194 ++ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
19195 ++ err = -EFAULT;
19196 ++ goto cleanup;
19197 ++ }
19198 ++ r_tmp->domain_children = domainlist;
19199 ++ }
19200 ++
19201 ++ err = copy_user_transitions(r_tmp);
19202 ++ if (err)
19203 ++ goto cleanup;
19204 ++
19205 ++ memset(r_tmp->subj_hash, 0,
19206 ++ r_tmp->subj_hash_size *
19207 ++ sizeof (struct acl_subject_label *));
19208 ++
19209 ++ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
19210 ++
19211 ++ if (err)
19212 ++ goto cleanup;
19213 ++
19214 ++ /* set nested subject list to null */
19215 ++ r_tmp->hash->first = NULL;
19216 ++
19217 ++ insert_acl_role_label(r_tmp);
19218 ++ }
19219 ++
19220 ++ goto return_err;
19221 ++ cleanup:
19222 ++ free_variables();
19223 ++ return_err:
19224 ++ return err;
19225 ++
19226 ++}
19227 ++
19228 ++static int
19229 ++gracl_init(struct gr_arg *args)
19230 ++{
19231 ++ int error = 0;
19232 ++
19233 ++ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
19234 ++ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
19235 ++
19236 ++ if (init_variables(args)) {
19237 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
19238 ++ error = -ENOMEM;
19239 ++ free_variables();
19240 ++ goto out;
19241 ++ }
19242 ++
19243 ++ error = copy_user_acl(args);
19244 ++ free_init_variables();
19245 ++ if (error) {
19246 ++ free_variables();
19247 ++ goto out;
19248 ++ }
19249 ++
19250 ++ if ((error = gr_set_acls(0))) {
19251 ++ free_variables();
19252 ++ goto out;
19253 ++ }
19254 ++
19255 ++ gr_status |= GR_READY;
19256 ++ out:
19257 ++ return error;
19258 ++}
19259 ++
19260 ++/* derived from glibc fnmatch() 0: match, 1: no match*/
19261 ++
19262 ++static int
19263 ++glob_match(const char *p, const char *n)
19264 ++{
19265 ++ char c;
19266 ++
19267 ++ while ((c = *p++) != '\0') {
19268 ++ switch (c) {
19269 ++ case '?':
19270 ++ if (*n == '\0')
19271 ++ return 1;
19272 ++ else if (*n == '/')
19273 ++ return 1;
19274 ++ break;
19275 ++ case '\\':
19276 ++ if (*n != c)
19277 ++ return 1;
19278 ++ break;
19279 ++ case '*':
19280 ++ for (c = *p++; c == '?' || c == '*'; c = *p++) {
19281 ++ if (*n == '/')
19282 ++ return 1;
19283 ++ else if (c == '?') {
19284 ++ if (*n == '\0')
19285 ++ return 1;
19286 ++ else
19287 ++ ++n;
19288 ++ }
19289 ++ }
19290 ++ if (c == '\0') {
19291 ++ return 0;
19292 ++ } else {
19293 ++ const char *endp;
19294 ++
19295 ++ if ((endp = strchr(n, '/')) == NULL)
19296 ++ endp = n + strlen(n);
19297 ++
19298 ++ if (c == '[') {
19299 ++ for (--p; n < endp; ++n)
19300 ++ if (!glob_match(p, n))
19301 ++ return 0;
19302 ++ } else if (c == '/') {
19303 ++ while (*n != '\0' && *n != '/')
19304 ++ ++n;
19305 ++ if (*n == '/' && !glob_match(p, n + 1))
19306 ++ return 0;
19307 ++ } else {
19308 ++ for (--p; n < endp; ++n)
19309 ++ if (*n == c && !glob_match(p, n))
19310 ++ return 0;
19311 ++ }
19312 ++
19313 ++ return 1;
19314 ++ }
19315 ++ case '[':
19316 ++ {
19317 ++ int not;
19318 ++ char cold;
19319 ++
19320 ++ if (*n == '\0' || *n == '/')
19321 ++ return 1;
19322 ++
19323 ++ not = (*p == '!' || *p == '^');
19324 ++ if (not)
19325 ++ ++p;
19326 ++
19327 ++ c = *p++;
19328 ++ for (;;) {
19329 ++ unsigned char fn = (unsigned char)*n;
19330 ++
19331 ++ if (c == '\0')
19332 ++ return 1;
19333 ++ else {
19334 ++ if (c == fn)
19335 ++ goto matched;
19336 ++ cold = c;
19337 ++ c = *p++;
19338 ++
19339 ++ if (c == '-' && *p != ']') {
19340 ++ unsigned char cend = *p++;
19341 ++
19342 ++ if (cend == '\0')
19343 ++ return 1;
19344 ++
19345 ++ if (cold <= fn && fn <= cend)
19346 ++ goto matched;
19347 ++
19348 ++ c = *p++;
19349 ++ }
19350 ++ }
19351 ++
19352 ++ if (c == ']')
19353 ++ break;
19354 ++ }
19355 ++ if (!not)
19356 ++ return 1;
19357 ++ break;
19358 ++ matched:
19359 ++ while (c != ']') {
19360 ++ if (c == '\0')
19361 ++ return 1;
19362 ++
19363 ++ c = *p++;
19364 ++ }
19365 ++ if (not)
19366 ++ return 1;
19367 ++ }
19368 ++ break;
19369 ++ default:
19370 ++ if (c != *n)
19371 ++ return 1;
19372 ++ }
19373 ++
19374 ++ ++n;
19375 ++ }
19376 ++
19377 ++ if (*n == '\0')
19378 ++ return 0;
19379 ++
19380 ++ if (*n == '/')
19381 ++ return 0;
19382 ++
19383 ++ return 1;
19384 ++}
19385 ++
19386 ++static struct acl_object_label *
19387 ++chk_glob_label(struct acl_object_label *globbed,
19388 ++ struct dentry *dentry, struct vfsmount *mnt, char **path)
19389 ++{
19390 ++ struct acl_object_label *tmp;
19391 ++
19392 ++ if (*path == NULL)
19393 ++ *path = gr_to_filename_nolock(dentry, mnt);
19394 ++
19395 ++ tmp = globbed;
19396 ++
19397 ++ while (tmp) {
19398 ++ if (!glob_match(tmp->filename, *path))
19399 ++ return tmp;
19400 ++ tmp = tmp->next;
19401 ++ }
19402 ++
19403 ++ return NULL;
19404 ++}
19405 ++
19406 ++static struct acl_object_label *
19407 ++__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19408 ++ const ino_t curr_ino, const dev_t curr_dev,
19409 ++ const struct acl_subject_label *subj, char **path)
19410 ++{
19411 ++ struct acl_subject_label *tmpsubj;
19412 ++ struct acl_object_label *retval;
19413 ++ struct acl_object_label *retval2;
19414 ++
19415 ++ tmpsubj = (struct acl_subject_label *) subj;
19416 ++ read_lock(&gr_inode_lock);
19417 ++ do {
19418 ++ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
19419 ++ if (retval) {
19420 ++ if (retval->globbed) {
19421 ++ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
19422 ++ (struct vfsmount *)orig_mnt, path);
19423 ++ if (retval2)
19424 ++ retval = retval2;
19425 ++ }
19426 ++ break;
19427 ++ }
19428 ++ } while ((tmpsubj = tmpsubj->parent_subject));
19429 ++ read_unlock(&gr_inode_lock);
19430 ++
19431 ++ return retval;
19432 ++}
19433 ++
19434 ++static __inline__ struct acl_object_label *
19435 ++full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19436 ++ const struct dentry *curr_dentry,
19437 ++ const struct acl_subject_label *subj, char **path)
19438 ++{
19439 ++ return __full_lookup(orig_dentry, orig_mnt,
19440 ++ curr_dentry->d_inode->i_ino,
19441 ++ curr_dentry->d_inode->i_sb->s_dev, subj, path);
19442 ++}
19443 ++
19444 ++static struct acl_object_label *
19445 ++__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19446 ++ const struct acl_subject_label *subj, char *path)
19447 ++{
19448 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19449 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19450 ++ struct acl_object_label *retval;
19451 ++
19452 ++ spin_lock(&dcache_lock);
19453 ++
19454 ++ if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
19455 ++ /* ignore Eric Biederman */
19456 ++ IS_PRIVATE(l_dentry->d_inode))) {
19457 ++ retval = fakefs_obj;
19458 ++ goto out;
19459 ++ }
19460 ++
19461 ++ for (;;) {
19462 ++ if (dentry == real_root && mnt == real_root_mnt)
19463 ++ break;
19464 ++
19465 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19466 ++ if (mnt->mnt_parent == mnt)
19467 ++ break;
19468 ++
19469 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19470 ++ if (retval != NULL)
19471 ++ goto out;
19472 ++
19473 ++ dentry = mnt->mnt_mountpoint;
19474 ++ mnt = mnt->mnt_parent;
19475 ++ continue;
19476 ++ }
19477 ++
19478 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19479 ++ if (retval != NULL)
19480 ++ goto out;
19481 ++
19482 ++ dentry = dentry->d_parent;
19483 ++ }
19484 ++
19485 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19486 ++
19487 ++ if (retval == NULL)
19488 ++ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path);
19489 ++out:
19490 ++ spin_unlock(&dcache_lock);
19491 ++ return retval;
19492 ++}
19493 ++
19494 ++static __inline__ struct acl_object_label *
19495 ++chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19496 ++ const struct acl_subject_label *subj)
19497 ++{
19498 ++ char *path = NULL;
19499 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19500 ++}
19501 ++
19502 ++static __inline__ struct acl_object_label *
19503 ++chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19504 ++ const struct acl_subject_label *subj, char *path)
19505 ++{
19506 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19507 ++}
19508 ++
19509 ++static struct acl_subject_label *
19510 ++chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19511 ++ const struct acl_role_label *role)
19512 ++{
19513 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19514 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19515 ++ struct acl_subject_label *retval;
19516 ++
19517 ++ spin_lock(&dcache_lock);
19518 ++
19519 ++ for (;;) {
19520 ++ if (dentry == real_root && mnt == real_root_mnt)
19521 ++ break;
19522 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19523 ++ if (mnt->mnt_parent == mnt)
19524 ++ break;
19525 ++
19526 ++ read_lock(&gr_inode_lock);
19527 ++ retval =
19528 ++ lookup_acl_subj_label(dentry->d_inode->i_ino,
19529 ++ dentry->d_inode->i_sb->s_dev, role);
19530 ++ read_unlock(&gr_inode_lock);
19531 ++ if (retval != NULL)
19532 ++ goto out;
19533 ++
19534 ++ dentry = mnt->mnt_mountpoint;
19535 ++ mnt = mnt->mnt_parent;
19536 ++ continue;
19537 ++ }
19538 ++
19539 ++ read_lock(&gr_inode_lock);
19540 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19541 ++ dentry->d_inode->i_sb->s_dev, role);
19542 ++ read_unlock(&gr_inode_lock);
19543 ++ if (retval != NULL)
19544 ++ goto out;
19545 ++
19546 ++ dentry = dentry->d_parent;
19547 ++ }
19548 ++
19549 ++ read_lock(&gr_inode_lock);
19550 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19551 ++ dentry->d_inode->i_sb->s_dev, role);
19552 ++ read_unlock(&gr_inode_lock);
19553 ++
19554 ++ if (unlikely(retval == NULL)) {
19555 ++ read_lock(&gr_inode_lock);
19556 ++ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
19557 ++ real_root->d_inode->i_sb->s_dev, role);
19558 ++ read_unlock(&gr_inode_lock);
19559 ++ }
19560 ++out:
19561 ++ spin_unlock(&dcache_lock);
19562 ++
19563 ++ return retval;
19564 ++}
19565 ++
19566 ++static void
19567 ++gr_log_learn(const struct task_struct *task, const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
19568 ++{
19569 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19570 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19571 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19572 ++ 1, 1, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19573 ++
19574 ++ return;
19575 ++}
19576 ++
19577 ++static void
19578 ++gr_log_learn_sysctl(const struct task_struct *task, const char *path, const __u32 mode)
19579 ++{
19580 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19581 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19582 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19583 ++ 1, 1, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19584 ++
19585 ++ return;
19586 ++}
19587 ++
19588 ++static void
19589 ++gr_log_learn_id_change(const struct task_struct *task, const char type, const unsigned int real,
19590 ++ const unsigned int effective, const unsigned int fs)
19591 ++{
19592 ++ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
19593 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19594 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19595 ++ type, real, effective, fs, NIPQUAD(task->signal->curr_ip));
19596 ++
19597 ++ return;
19598 ++}
19599 ++
19600 ++__u32
19601 ++gr_check_link(const struct dentry * new_dentry,
19602 ++ const struct dentry * parent_dentry,
19603 ++ const struct vfsmount * parent_mnt,
19604 ++ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
19605 ++{
19606 ++ struct acl_object_label *obj;
19607 ++ __u32 oldmode, newmode;
19608 ++ __u32 needmode;
19609 ++
19610 ++ if (unlikely(!(gr_status & GR_READY)))
19611 ++ return (GR_CREATE | GR_LINK);
19612 ++
19613 ++ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
19614 ++ oldmode = obj->mode;
19615 ++
19616 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19617 ++ oldmode |= (GR_CREATE | GR_LINK);
19618 ++
19619 ++ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
19620 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19621 ++ needmode |= GR_SETID | GR_AUDIT_SETID;
19622 ++
19623 ++ newmode =
19624 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
19625 ++ oldmode | needmode);
19626 ++
19627 ++ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
19628 ++ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
19629 ++ GR_INHERIT | GR_AUDIT_INHERIT);
19630 ++
19631 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
19632 ++ goto bad;
19633 ++
19634 ++ if ((oldmode & needmode) != needmode)
19635 ++ goto bad;
19636 ++
19637 ++ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
19638 ++ if ((newmode & needmode) != needmode)
19639 ++ goto bad;
19640 ++
19641 ++ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
19642 ++ return newmode;
19643 ++bad:
19644 ++ needmode = oldmode;
19645 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19646 ++ needmode |= GR_SETID;
19647 ++
19648 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19649 ++ gr_log_learn(current, old_dentry, old_mnt, needmode);
19650 ++ return (GR_CREATE | GR_LINK);
19651 ++ } else if (newmode & GR_SUPPRESS)
19652 ++ return GR_SUPPRESS;
19653 ++ else
19654 ++ return 0;
19655 ++}
19656 ++
19657 ++__u32
19658 ++gr_search_file(const struct dentry * dentry, const __u32 mode,
19659 ++ const struct vfsmount * mnt)
19660 ++{
19661 ++ __u32 retval = mode;
19662 ++ struct acl_subject_label *curracl;
19663 ++ struct acl_object_label *currobj;
19664 ++
19665 ++ if (unlikely(!(gr_status & GR_READY)))
19666 ++ return (mode & ~GR_AUDITS);
19667 ++
19668 ++ curracl = current->acl;
19669 ++
19670 ++ currobj = chk_obj_label(dentry, mnt, curracl);
19671 ++ retval = currobj->mode & mode;
19672 ++
19673 ++ if (unlikely
19674 ++ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
19675 ++ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
19676 ++ __u32 new_mode = mode;
19677 ++
19678 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19679 ++
19680 ++ retval = new_mode;
19681 ++
19682 ++ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
19683 ++ new_mode |= GR_INHERIT;
19684 ++
19685 ++ if (!(mode & GR_NOLEARN))
19686 ++ gr_log_learn(current, dentry, mnt, new_mode);
19687 ++ }
19688 ++
19689 ++ return retval;
19690 ++}
19691 ++
19692 ++__u32
19693 ++gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
19694 ++ const struct vfsmount * mnt, const __u32 mode)
19695 ++{
19696 ++ struct name_entry *match;
19697 ++ struct acl_object_label *matchpo;
19698 ++ struct acl_subject_label *curracl;
19699 ++ char *path;
19700 ++ __u32 retval;
19701 ++
19702 ++ if (unlikely(!(gr_status & GR_READY)))
19703 ++ return (mode & ~GR_AUDITS);
19704 ++
19705 ++ preempt_disable();
19706 ++ path = gr_to_filename_rbac(new_dentry, mnt);
19707 ++ match = lookup_name_entry_create(path);
19708 ++
19709 ++ if (!match)
19710 ++ goto check_parent;
19711 ++
19712 ++ curracl = current->acl;
19713 ++
19714 ++ read_lock(&gr_inode_lock);
19715 ++ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
19716 ++ read_unlock(&gr_inode_lock);
19717 ++
19718 ++ if (matchpo) {
19719 ++ if ((matchpo->mode & mode) !=
19720 ++ (mode & ~(GR_AUDITS | GR_SUPPRESS))
19721 ++ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19722 ++ __u32 new_mode = mode;
19723 ++
19724 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19725 ++
19726 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19727 ++
19728 ++ preempt_enable();
19729 ++ return new_mode;
19730 ++ }
19731 ++ preempt_enable();
19732 ++ return (matchpo->mode & mode);
19733 ++ }
19734 ++
19735 ++ check_parent:
19736 ++ curracl = current->acl;
19737 ++
19738 ++ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
19739 ++ retval = matchpo->mode & mode;
19740 ++
19741 ++ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
19742 ++ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
19743 ++ __u32 new_mode = mode;
19744 ++
19745 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19746 ++
19747 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19748 ++ preempt_enable();
19749 ++ return new_mode;
19750 ++ }
19751 ++
19752 ++ preempt_enable();
19753 ++ return retval;
19754 ++}
19755 ++
19756 ++int
19757 ++gr_check_hidden_task(const struct task_struct *task)
19758 ++{
19759 ++ if (unlikely(!(gr_status & GR_READY)))
19760 ++ return 0;
19761 ++
19762 ++ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
19763 ++ return 1;
19764 ++
19765 ++ return 0;
19766 ++}
19767 ++
19768 ++int
19769 ++gr_check_protected_task(const struct task_struct *task)
19770 ++{
19771 ++ if (unlikely(!(gr_status & GR_READY) || !task))
19772 ++ return 0;
19773 ++
19774 ++ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
19775 ++ task->acl != current->acl)
19776 ++ return 1;
19777 ++
19778 ++ return 0;
19779 ++}
19780 ++
19781 ++void
19782 ++gr_copy_label(struct task_struct *tsk)
19783 ++{
19784 ++ tsk->signal->used_accept = 0;
19785 ++ tsk->acl_sp_role = 0;
19786 ++ tsk->acl_role_id = current->acl_role_id;
19787 ++ tsk->acl = current->acl;
19788 ++ tsk->role = current->role;
19789 ++ tsk->signal->curr_ip = current->signal->curr_ip;
19790 ++ if (current->exec_file)
19791 ++ get_file(current->exec_file);
19792 ++ tsk->exec_file = current->exec_file;
19793 ++ tsk->is_writable = current->is_writable;
19794 ++ if (unlikely(current->signal->used_accept))
19795 ++ current->signal->curr_ip = 0;
19796 ++
19797 ++ return;
19798 ++}
19799 ++
19800 ++static void
19801 ++gr_set_proc_res(struct task_struct *task)
19802 ++{
19803 ++ struct acl_subject_label *proc;
19804 ++ unsigned short i;
19805 ++
19806 ++ proc = task->acl;
19807 ++
19808 ++ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
19809 ++ return;
19810 ++
19811 ++ for (i = 0; i < (GR_NLIMITS - 1); i++) {
19812 ++ if (!(proc->resmask & (1 << i)))
19813 ++ continue;
19814 ++
19815 ++ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
19816 ++ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
19817 ++ }
19818 ++
19819 ++ return;
19820 ++}
19821 ++
19822 ++int
19823 ++gr_check_user_change(int real, int effective, int fs)
19824 ++{
19825 ++ unsigned int i;
19826 ++ __u16 num;
19827 ++ uid_t *uidlist;
19828 ++ int curuid;
19829 ++ int realok = 0;
19830 ++ int effectiveok = 0;
19831 ++ int fsok = 0;
19832 ++
19833 ++ if (unlikely(!(gr_status & GR_READY)))
19834 ++ return 0;
19835 ++
19836 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19837 ++ gr_log_learn_id_change(current, 'u', real, effective, fs);
19838 ++
19839 ++ num = current->acl->user_trans_num;
19840 ++ uidlist = current->acl->user_transitions;
19841 ++
19842 ++ if (uidlist == NULL)
19843 ++ return 0;
19844 ++
19845 ++ if (real == -1)
19846 ++ realok = 1;
19847 ++ if (effective == -1)
19848 ++ effectiveok = 1;
19849 ++ if (fs == -1)
19850 ++ fsok = 1;
19851 ++
19852 ++ if (current->acl->user_trans_type & GR_ID_ALLOW) {
19853 ++ for (i = 0; i < num; i++) {
19854 ++ curuid = (int)uidlist[i];
19855 ++ if (real == curuid)
19856 ++ realok = 1;
19857 ++ if (effective == curuid)
19858 ++ effectiveok = 1;
19859 ++ if (fs == curuid)
19860 ++ fsok = 1;
19861 ++ }
19862 ++ } else if (current->acl->user_trans_type & GR_ID_DENY) {
19863 ++ for (i = 0; i < num; i++) {
19864 ++ curuid = (int)uidlist[i];
19865 ++ if (real == curuid)
19866 ++ break;
19867 ++ if (effective == curuid)
19868 ++ break;
19869 ++ if (fs == curuid)
19870 ++ break;
19871 ++ }
19872 ++ /* not in deny list */
19873 ++ if (i == num) {
19874 ++ realok = 1;
19875 ++ effectiveok = 1;
19876 ++ fsok = 1;
19877 ++ }
19878 ++ }
19879 ++
19880 ++ if (realok && effectiveok && fsok)
19881 ++ return 0;
19882 ++ else {
19883 ++ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
19884 ++ return 1;
19885 ++ }
19886 ++}
19887 ++
19888 ++int
19889 ++gr_check_group_change(int real, int effective, int fs)
19890 ++{
19891 ++ unsigned int i;
19892 ++ __u16 num;
19893 ++ gid_t *gidlist;
19894 ++ int curgid;
19895 ++ int realok = 0;
19896 ++ int effectiveok = 0;
19897 ++ int fsok = 0;
19898 ++
19899 ++ if (unlikely(!(gr_status & GR_READY)))
19900 ++ return 0;
19901 ++
19902 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19903 ++ gr_log_learn_id_change(current, 'g', real, effective, fs);
19904 ++
19905 ++ num = current->acl->group_trans_num;
19906 ++ gidlist = current->acl->group_transitions;
19907 ++
19908 ++ if (gidlist == NULL)
19909 ++ return 0;
19910 ++
19911 ++ if (real == -1)
19912 ++ realok = 1;
19913 ++ if (effective == -1)
19914 ++ effectiveok = 1;
19915 ++ if (fs == -1)
19916 ++ fsok = 1;
19917 ++
19918 ++ if (current->acl->group_trans_type & GR_ID_ALLOW) {
19919 ++ for (i = 0; i < num; i++) {
19920 ++ curgid = (int)gidlist[i];
19921 ++ if (real == curgid)
19922 ++ realok = 1;
19923 ++ if (effective == curgid)
19924 ++ effectiveok = 1;
19925 ++ if (fs == curgid)
19926 ++ fsok = 1;
19927 ++ }
19928 ++ } else if (current->acl->group_trans_type & GR_ID_DENY) {
19929 ++ for (i = 0; i < num; i++) {
19930 ++ curgid = (int)gidlist[i];
19931 ++ if (real == curgid)
19932 ++ break;
19933 ++ if (effective == curgid)
19934 ++ break;
19935 ++ if (fs == curgid)
19936 ++ break;
19937 ++ }
19938 ++ /* not in deny list */
19939 ++ if (i == num) {
19940 ++ realok = 1;
19941 ++ effectiveok = 1;
19942 ++ fsok = 1;
19943 ++ }
19944 ++ }
19945 ++
19946 ++ if (realok && effectiveok && fsok)
19947 ++ return 0;
19948 ++ else {
19949 ++ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
19950 ++ return 1;
19951 ++ }
19952 ++}
19953 ++
19954 ++void
19955 ++gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
19956 ++{
19957 ++ struct acl_role_label *role = task->role;
19958 ++ struct acl_subject_label *subj = NULL;
19959 ++ struct acl_object_label *obj;
19960 ++ struct file *filp;
19961 ++
19962 ++ if (unlikely(!(gr_status & GR_READY)))
19963 ++ return;
19964 ++
19965 ++ filp = task->exec_file;
19966 ++
19967 ++ /* kernel process, we'll give them the kernel role */
19968 ++ if (unlikely(!filp)) {
19969 ++ task->role = kernel_role;
19970 ++ task->acl = kernel_role->root_label;
19971 ++ return;
19972 ++ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
19973 ++ role = lookup_acl_role_label(task, uid, gid);
19974 ++
19975 ++ /* perform subject lookup in possibly new role
19976 ++ we can use this result below in the case where role == task->role
19977 ++ */
19978 ++ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
19979 ++
19980 ++ /* if we changed uid/gid, but result in the same role
19981 ++ and are using inheritance, don't lose the inherited subject
19982 ++ if current subject is other than what normal lookup
19983 ++ would result in, we arrived via inheritance, don't
19984 ++ lose subject
19985 ++ */
19986 ++ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
19987 ++ (subj == task->acl)))
19988 ++ task->acl = subj;
19989 ++
19990 ++ task->role = role;
19991 ++
19992 ++ task->is_writable = 0;
19993 ++
19994 ++ /* ignore additional mmap checks for processes that are writable
19995 ++ by the default ACL */
19996 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
19997 ++ if (unlikely(obj->mode & GR_WRITE))
19998 ++ task->is_writable = 1;
19999 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
20000 ++ if (unlikely(obj->mode & GR_WRITE))
20001 ++ task->is_writable = 1;
20002 ++
20003 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20004 ++ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20005 ++#endif
20006 ++
20007 ++ gr_set_proc_res(task);
20008 ++
20009 ++ return;
20010 ++}
20011 ++
20012 ++int
20013 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
20014 ++{
20015 ++ struct task_struct *task = current;
20016 ++ struct acl_subject_label *newacl;
20017 ++ struct acl_object_label *obj;
20018 ++ __u32 retmode;
20019 ++
20020 ++ if (unlikely(!(gr_status & GR_READY)))
20021 ++ return 0;
20022 ++
20023 ++ newacl = chk_subj_label(dentry, mnt, task->role);
20024 ++
20025 ++ task_lock(task);
20026 ++ if (((task->ptrace & PT_PTRACED) && !(task->acl->mode &
20027 ++ GR_POVERRIDE) && (task->acl != newacl) &&
20028 ++ !(task->role->roletype & GR_ROLE_GOD) &&
20029 ++ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
20030 ++ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) ||
20031 ++ (atomic_read(&task->fs->count) > 1 ||
20032 ++ atomic_read(&task->files->count) > 1 ||
20033 ++ atomic_read(&task->sighand->count) > 1)) {
20034 ++ task_unlock(task);
20035 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
20036 ++ return -EACCES;
20037 ++ }
20038 ++ task_unlock(task);
20039 ++
20040 ++ obj = chk_obj_label(dentry, mnt, task->acl);
20041 ++ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
20042 ++
20043 ++ if (!(task->acl->mode & GR_INHERITLEARN) &&
20044 ++ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
20045 ++ if (obj->nested)
20046 ++ task->acl = obj->nested;
20047 ++ else
20048 ++ task->acl = newacl;
20049 ++ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
20050 ++ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
20051 ++
20052 ++ task->is_writable = 0;
20053 ++
20054 ++ /* ignore additional mmap checks for processes that are writable
20055 ++ by the default ACL */
20056 ++ obj = chk_obj_label(dentry, mnt, default_role->root_label);
20057 ++ if (unlikely(obj->mode & GR_WRITE))
20058 ++ task->is_writable = 1;
20059 ++ obj = chk_obj_label(dentry, mnt, task->role->root_label);
20060 ++ if (unlikely(obj->mode & GR_WRITE))
20061 ++ task->is_writable = 1;
20062 ++
20063 ++ gr_set_proc_res(task);
20064 ++
20065 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20066 ++ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20067 ++#endif
20068 ++ return 0;
20069 ++}
20070 ++
20071 ++/* always called with valid inodev ptr */
20072 ++static void
20073 ++do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
20074 ++{
20075 ++ struct acl_object_label *matchpo;
20076 ++ struct acl_subject_label *matchps;
20077 ++ struct acl_subject_label *subj;
20078 ++ struct acl_role_label *role;
20079 ++ unsigned int i, x;
20080 ++
20081 ++ FOR_EACH_ROLE_START(role, i)
20082 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20083 ++ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
20084 ++ matchpo->mode |= GR_DELETED;
20085 ++ FOR_EACH_SUBJECT_END(subj,x)
20086 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20087 ++ if (subj->inode == ino && subj->device == dev)
20088 ++ subj->mode |= GR_DELETED;
20089 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20090 ++ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
20091 ++ matchps->mode |= GR_DELETED;
20092 ++ FOR_EACH_ROLE_END(role,i)
20093 ++
20094 ++ inodev->nentry->deleted = 1;
20095 ++
20096 ++ return;
20097 ++}
20098 ++
20099 ++void
20100 ++gr_handle_delete(const ino_t ino, const dev_t dev)
20101 ++{
20102 ++ struct inodev_entry *inodev;
20103 ++
20104 ++ if (unlikely(!(gr_status & GR_READY)))
20105 ++ return;
20106 ++
20107 ++ write_lock(&gr_inode_lock);
20108 ++ inodev = lookup_inodev_entry(ino, dev);
20109 ++ if (inodev != NULL)
20110 ++ do_handle_delete(inodev, ino, dev);
20111 ++ write_unlock(&gr_inode_lock);
20112 ++
20113 ++ return;
20114 ++}
20115 ++
20116 ++static void
20117 ++update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
20118 ++ const ino_t newinode, const dev_t newdevice,
20119 ++ struct acl_subject_label *subj)
20120 ++{
20121 ++ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
20122 ++ struct acl_object_label *match;
20123 ++
20124 ++ match = subj->obj_hash[index];
20125 ++
20126 ++ while (match && (match->inode != oldinode ||
20127 ++ match->device != olddevice ||
20128 ++ !(match->mode & GR_DELETED)))
20129 ++ match = match->next;
20130 ++
20131 ++ if (match && (match->inode == oldinode)
20132 ++ && (match->device == olddevice)
20133 ++ && (match->mode & GR_DELETED)) {
20134 ++ if (match->prev == NULL) {
20135 ++ subj->obj_hash[index] = match->next;
20136 ++ if (match->next != NULL)
20137 ++ match->next->prev = NULL;
20138 ++ } else {
20139 ++ match->prev->next = match->next;
20140 ++ if (match->next != NULL)
20141 ++ match->next->prev = match->prev;
20142 ++ }
20143 ++ match->prev = NULL;
20144 ++ match->next = NULL;
20145 ++ match->inode = newinode;
20146 ++ match->device = newdevice;
20147 ++ match->mode &= ~GR_DELETED;
20148 ++
20149 ++ insert_acl_obj_label(match, subj);
20150 ++ }
20151 ++
20152 ++ return;
20153 ++}
20154 ++
20155 ++static void
20156 ++update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
20157 ++ const ino_t newinode, const dev_t newdevice,
20158 ++ struct acl_role_label *role)
20159 ++{
20160 ++ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
20161 ++ struct acl_subject_label *match;
20162 ++
20163 ++ match = role->subj_hash[index];
20164 ++
20165 ++ while (match && (match->inode != oldinode ||
20166 ++ match->device != olddevice ||
20167 ++ !(match->mode & GR_DELETED)))
20168 ++ match = match->next;
20169 ++
20170 ++ if (match && (match->inode == oldinode)
20171 ++ && (match->device == olddevice)
20172 ++ && (match->mode & GR_DELETED)) {
20173 ++ if (match->prev == NULL) {
20174 ++ role->subj_hash[index] = match->next;
20175 ++ if (match->next != NULL)
20176 ++ match->next->prev = NULL;
20177 ++ } else {
20178 ++ match->prev->next = match->next;
20179 ++ if (match->next != NULL)
20180 ++ match->next->prev = match->prev;
20181 ++ }
20182 ++ match->prev = NULL;
20183 ++ match->next = NULL;
20184 ++ match->inode = newinode;
20185 ++ match->device = newdevice;
20186 ++ match->mode &= ~GR_DELETED;
20187 ++
20188 ++ insert_acl_subj_label(match, role);
20189 ++ }
20190 ++
20191 ++ return;
20192 ++}
20193 ++
20194 ++static void
20195 ++update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
20196 ++ const ino_t newinode, const dev_t newdevice)
20197 ++{
20198 ++ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
20199 ++ struct inodev_entry *match;
20200 ++
20201 ++ match = inodev_set.i_hash[index];
20202 ++
20203 ++ while (match && (match->nentry->inode != oldinode ||
20204 ++ match->nentry->device != olddevice || !match->nentry->deleted))
20205 ++ match = match->next;
20206 ++
20207 ++ if (match && (match->nentry->inode == oldinode)
20208 ++ && (match->nentry->device == olddevice) &&
20209 ++ match->nentry->deleted) {
20210 ++ if (match->prev == NULL) {
20211 ++ inodev_set.i_hash[index] = match->next;
20212 ++ if (match->next != NULL)
20213 ++ match->next->prev = NULL;
20214 ++ } else {
20215 ++ match->prev->next = match->next;
20216 ++ if (match->next != NULL)
20217 ++ match->next->prev = match->prev;
20218 ++ }
20219 ++ match->prev = NULL;
20220 ++ match->next = NULL;
20221 ++ match->nentry->inode = newinode;
20222 ++ match->nentry->device = newdevice;
20223 ++ match->nentry->deleted = 0;
20224 ++
20225 ++ insert_inodev_entry(match);
20226 ++ }
20227 ++
20228 ++ return;
20229 ++}
20230 ++
20231 ++static void
20232 ++do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
20233 ++ const struct vfsmount *mnt)
20234 ++{
20235 ++ struct acl_subject_label *subj;
20236 ++ struct acl_role_label *role;
20237 ++ unsigned int i, x;
20238 ++
20239 ++ FOR_EACH_ROLE_START(role, i)
20240 ++ update_acl_subj_label(matchn->inode, matchn->device,
20241 ++ dentry->d_inode->i_ino,
20242 ++ dentry->d_inode->i_sb->s_dev, role);
20243 ++
20244 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20245 ++ if ((subj->inode == dentry->d_inode->i_ino) &&
20246 ++ (subj->device == dentry->d_inode->i_sb->s_dev)) {
20247 ++ subj->inode = dentry->d_inode->i_ino;
20248 ++ subj->device = dentry->d_inode->i_sb->s_dev;
20249 ++ }
20250 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20251 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20252 ++ update_acl_obj_label(matchn->inode, matchn->device,
20253 ++ dentry->d_inode->i_ino,
20254 ++ dentry->d_inode->i_sb->s_dev, subj);
20255 ++ FOR_EACH_SUBJECT_END(subj,x)
20256 ++ FOR_EACH_ROLE_END(role,i)
20257 ++
20258 ++ update_inodev_entry(matchn->inode, matchn->device,
20259 ++ dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
20260 ++
20261 ++ return;
20262 ++}
20263 ++
20264 ++void
20265 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
20266 ++{
20267 ++ struct name_entry *matchn;
20268 ++
20269 ++ if (unlikely(!(gr_status & GR_READY)))
20270 ++ return;
20271 ++
20272 ++ preempt_disable();
20273 ++ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
20274 ++
20275 ++ if (unlikely((unsigned long)matchn)) {
20276 ++ write_lock(&gr_inode_lock);
20277 ++ do_handle_create(matchn, dentry, mnt);
20278 ++ write_unlock(&gr_inode_lock);
20279 ++ }
20280 ++ preempt_enable();
20281 ++
20282 ++ return;
20283 ++}
20284 ++
20285 ++void
20286 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
20287 ++ struct dentry *old_dentry,
20288 ++ struct dentry *new_dentry,
20289 ++ struct vfsmount *mnt, const __u8 replace)
20290 ++{
20291 ++ struct name_entry *matchn;
20292 ++ struct inodev_entry *inodev;
20293 ++
20294 ++ /* vfs_rename swaps the name and parent link for old_dentry and
20295 ++ new_dentry
20296 ++ at this point, old_dentry has the new name, parent link, and inode
20297 ++ for the renamed file
20298 ++ if a file is being replaced by a rename, new_dentry has the inode
20299 ++ and name for the replaced file
20300 ++ */
20301 ++
20302 ++ if (unlikely(!(gr_status & GR_READY)))
20303 ++ return;
20304 ++
20305 ++ preempt_disable();
20306 ++ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
20307 ++
20308 ++ /* we wouldn't have to check d_inode if it weren't for
20309 ++ NFS silly-renaming
20310 ++ */
20311 ++
20312 ++ write_lock(&gr_inode_lock);
20313 ++ if (unlikely(replace && new_dentry->d_inode)) {
20314 ++ inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
20315 ++ new_dentry->d_inode->i_sb->s_dev);
20316 ++ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
20317 ++ do_handle_delete(inodev, new_dentry->d_inode->i_ino,
20318 ++ new_dentry->d_inode->i_sb->s_dev);
20319 ++ }
20320 ++
20321 ++ inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
20322 ++ old_dentry->d_inode->i_sb->s_dev);
20323 ++ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
20324 ++ do_handle_delete(inodev, old_dentry->d_inode->i_ino,
20325 ++ old_dentry->d_inode->i_sb->s_dev);
20326 ++
20327 ++ if (unlikely((unsigned long)matchn))
20328 ++ do_handle_create(matchn, old_dentry, mnt);
20329 ++
20330 ++ write_unlock(&gr_inode_lock);
20331 ++ preempt_enable();
20332 ++
20333 ++ return;
20334 ++}
20335 ++
20336 ++static int
20337 ++lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
20338 ++ unsigned char **sum)
20339 ++{
20340 ++ struct acl_role_label *r;
20341 ++ struct role_allowed_ip *ipp;
20342 ++ struct role_transition *trans;
20343 ++ unsigned int i;
20344 ++ int found = 0;
20345 ++
20346 ++ /* check transition table */
20347 ++
20348 ++ for (trans = current->role->transitions; trans; trans = trans->next) {
20349 ++ if (!strcmp(rolename, trans->rolename)) {
20350 ++ found = 1;
20351 ++ break;
20352 ++ }
20353 ++ }
20354 ++
20355 ++ if (!found)
20356 ++ return 0;
20357 ++
20358 ++ /* handle special roles that do not require authentication
20359 ++ and check ip */
20360 ++
20361 ++ FOR_EACH_ROLE_START(r, i)
20362 ++ if (!strcmp(rolename, r->rolename) &&
20363 ++ (r->roletype & GR_ROLE_SPECIAL)) {
20364 ++ found = 0;
20365 ++ if (r->allowed_ips != NULL) {
20366 ++ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
20367 ++ if ((ntohl(current->signal->curr_ip) & ipp->netmask) ==
20368 ++ (ntohl(ipp->addr) & ipp->netmask))
20369 ++ found = 1;
20370 ++ }
20371 ++ } else
20372 ++ found = 2;
20373 ++ if (!found)
20374 ++ return 0;
20375 ++
20376 ++ if (((mode == SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
20377 ++ ((mode == SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
20378 ++ *salt = NULL;
20379 ++ *sum = NULL;
20380 ++ return 1;
20381 ++ }
20382 ++ }
20383 ++ FOR_EACH_ROLE_END(r,i)
20384 ++
20385 ++ for (i = 0; i < num_sprole_pws; i++) {
20386 ++ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
20387 ++ *salt = acl_special_roles[i]->salt;
20388 ++ *sum = acl_special_roles[i]->sum;
20389 ++ return 1;
20390 ++ }
20391 ++ }
20392 ++
20393 ++ return 0;
20394 ++}
20395 ++
20396 ++static void
20397 ++assign_special_role(char *rolename)
20398 ++{
20399 ++ struct acl_object_label *obj;
20400 ++ struct acl_role_label *r;
20401 ++ struct acl_role_label *assigned = NULL;
20402 ++ struct task_struct *tsk;
20403 ++ struct file *filp;
20404 ++ unsigned int i;
20405 ++
20406 ++ FOR_EACH_ROLE_START(r, i)
20407 ++ if (!strcmp(rolename, r->rolename) &&
20408 ++ (r->roletype & GR_ROLE_SPECIAL))
20409 ++ assigned = r;
20410 ++ FOR_EACH_ROLE_END(r,i)
20411 ++
20412 ++ if (!assigned)
20413 ++ return;
20414 ++
20415 ++ read_lock(&tasklist_lock);
20416 ++ read_lock(&grsec_exec_file_lock);
20417 ++
20418 ++ tsk = current->parent;
20419 ++ if (tsk == NULL)
20420 ++ goto out_unlock;
20421 ++
20422 ++ filp = tsk->exec_file;
20423 ++ if (filp == NULL)
20424 ++ goto out_unlock;
20425 ++
20426 ++ tsk->is_writable = 0;
20427 ++
20428 ++ tsk->acl_sp_role = 1;
20429 ++ tsk->acl_role_id = ++acl_sp_role_value;
20430 ++ tsk->role = assigned;
20431 ++ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
20432 ++
20433 ++ /* ignore additional mmap checks for processes that are writable
20434 ++ by the default ACL */
20435 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20436 ++ if (unlikely(obj->mode & GR_WRITE))
20437 ++ tsk->is_writable = 1;
20438 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
20439 ++ if (unlikely(obj->mode & GR_WRITE))
20440 ++ tsk->is_writable = 1;
20441 ++
20442 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20443 ++ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
20444 ++#endif
20445 ++
20446 ++out_unlock:
20447 ++ read_unlock(&grsec_exec_file_lock);
20448 ++ read_unlock(&tasklist_lock);
20449 ++ return;
20450 ++}
20451 ++
20452 ++int gr_check_secure_terminal(struct task_struct *task)
20453 ++{
20454 ++ struct task_struct *p, *p2, *p3;
20455 ++ struct files_struct *files;
20456 ++ struct fdtable *fdt;
20457 ++ struct file *our_file = NULL, *file;
20458 ++ int i;
20459 ++
20460 ++ if (task->signal->tty == NULL)
20461 ++ return 1;
20462 ++
20463 ++ files = get_files_struct(task);
20464 ++ if (files != NULL) {
20465 ++ rcu_read_lock();
20466 ++ fdt = files_fdtable(files);
20467 ++ for (i=0; i < fdt->max_fds; i++) {
20468 ++ file = fcheck_files(files, i);
20469 ++ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
20470 ++ get_file(file);
20471 ++ our_file = file;
20472 ++ }
20473 ++ }
20474 ++ rcu_read_unlock();
20475 ++ put_files_struct(files);
20476 ++ }
20477 ++
20478 ++ if (our_file == NULL)
20479 ++ return 1;
20480 ++
20481 ++ read_lock(&tasklist_lock);
20482 ++ do_each_thread(p2, p) {
20483 ++ files = get_files_struct(p);
20484 ++ if (files == NULL ||
20485 ++ (p->signal && p->signal->tty == task->signal->tty)) {
20486 ++ if (files != NULL)
20487 ++ put_files_struct(files);
20488 ++ continue;
20489 ++ }
20490 ++ rcu_read_lock();
20491 ++ fdt = files_fdtable(files);
20492 ++ for (i=0; i < fdt->max_fds; i++) {
20493 ++ file = fcheck_files(files, i);
20494 ++ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
20495 ++ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
20496 ++ p3 = task;
20497 ++ while (p3->pid > 0) {
20498 ++ if (p3 == p)
20499 ++ break;
20500 ++ p3 = p3->parent;
20501 ++ }
20502 ++ if (p3 == p)
20503 ++ break;
20504 ++ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
20505 ++ gr_handle_alertkill(p);
20506 ++ rcu_read_unlock();
20507 ++ put_files_struct(files);
20508 ++ read_unlock(&tasklist_lock);
20509 ++ fput(our_file);
20510 ++ return 0;
20511 ++ }
20512 ++ }
20513 ++ rcu_read_unlock();
20514 ++ put_files_struct(files);
20515 ++ } while_each_thread(p2, p);
20516 ++ read_unlock(&tasklist_lock);
20517 ++
20518 ++ fput(our_file);
20519 ++ return 1;
20520 ++}
20521 ++
20522 ++ssize_t
20523 ++write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
20524 ++{
20525 ++ struct gr_arg_wrapper uwrap;
20526 ++ unsigned char *sprole_salt;
20527 ++ unsigned char *sprole_sum;
20528 ++ int error = sizeof (struct gr_arg_wrapper);
20529 ++ int error2 = 0;
20530 ++
20531 ++ down(&gr_dev_sem);
20532 ++
20533 ++ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
20534 ++ error = -EPERM;
20535 ++ goto out;
20536 ++ }
20537 ++
20538 ++ if (count != sizeof (struct gr_arg_wrapper)) {
20539 ++ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
20540 ++ error = -EINVAL;
20541 ++ goto out;
20542 ++ }
20543 ++
20544 ++
20545 ++ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
20546 ++ gr_auth_expires = 0;
20547 ++ gr_auth_attempts = 0;
20548 ++ }
20549 ++
20550 ++ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
20551 ++ error = -EFAULT;
20552 ++ goto out;
20553 ++ }
20554 ++
20555 ++ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
20556 ++ error = -EINVAL;
20557 ++ goto out;
20558 ++ }
20559 ++
20560 ++ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
20561 ++ error = -EFAULT;
20562 ++ goto out;
20563 ++ }
20564 ++
20565 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != SPROLEPAM &&
20566 ++ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20567 ++ time_after(gr_auth_expires, get_seconds())) {
20568 ++ error = -EBUSY;
20569 ++ goto out;
20570 ++ }
20571 ++
20572 ++ /* if non-root trying to do anything other than use a special role,
20573 ++ do not attempt authentication, do not count towards authentication
20574 ++ locking
20575 ++ */
20576 ++
20577 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != STATUS &&
20578 ++ gr_usermode->mode != UNSPROLE && gr_usermode->mode != SPROLEPAM &&
20579 ++ current->uid) {
20580 ++ error = -EPERM;
20581 ++ goto out;
20582 ++ }
20583 ++
20584 ++ /* ensure pw and special role name are null terminated */
20585 ++
20586 ++ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
20587 ++ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
20588 ++
20589 ++ /* Okay.
20590 ++ * We have our enough of the argument structure..(we have yet
20591 ++ * to copy_from_user the tables themselves) . Copy the tables
20592 ++ * only if we need them, i.e. for loading operations. */
20593 ++
20594 ++ switch (gr_usermode->mode) {
20595 ++ case STATUS:
20596 ++ if (gr_status & GR_READY) {
20597 ++ error = 1;
20598 ++ if (!gr_check_secure_terminal(current))
20599 ++ error = 3;
20600 ++ } else
20601 ++ error = 2;
20602 ++ goto out;
20603 ++ case SHUTDOWN:
20604 ++ if ((gr_status & GR_READY)
20605 ++ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20606 ++ gr_status &= ~GR_READY;
20607 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
20608 ++ free_variables();
20609 ++ memset(gr_usermode, 0, sizeof (struct gr_arg));
20610 ++ memset(gr_system_salt, 0, GR_SALT_LEN);
20611 ++ memset(gr_system_sum, 0, GR_SHA_LEN);
20612 ++ } else if (gr_status & GR_READY) {
20613 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
20614 ++ error = -EPERM;
20615 ++ } else {
20616 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
20617 ++ error = -EAGAIN;
20618 ++ }
20619 ++ break;
20620 ++ case ENABLE:
20621 ++ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
20622 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
20623 ++ else {
20624 ++ if (gr_status & GR_READY)
20625 ++ error = -EAGAIN;
20626 ++ else
20627 ++ error = error2;
20628 ++ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
20629 ++ }
20630 ++ break;
20631 ++ case RELOAD:
20632 ++ if (!(gr_status & GR_READY)) {
20633 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
20634 ++ error = -EAGAIN;
20635 ++ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20636 ++ lock_kernel();
20637 ++ gr_status &= ~GR_READY;
20638 ++ free_variables();
20639 ++ if (!(error2 = gracl_init(gr_usermode))) {
20640 ++ unlock_kernel();
20641 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
20642 ++ } else {
20643 ++ unlock_kernel();
20644 ++ error = error2;
20645 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20646 ++ }
20647 ++ } else {
20648 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20649 ++ error = -EPERM;
20650 ++ }
20651 ++ break;
20652 ++ case SEGVMOD:
20653 ++ if (unlikely(!(gr_status & GR_READY))) {
20654 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
20655 ++ error = -EAGAIN;
20656 ++ break;
20657 ++ }
20658 ++
20659 ++ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20660 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
20661 ++ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
20662 ++ struct acl_subject_label *segvacl;
20663 ++ segvacl =
20664 ++ lookup_acl_subj_label(gr_usermode->segv_inode,
20665 ++ gr_usermode->segv_device,
20666 ++ current->role);
20667 ++ if (segvacl) {
20668 ++ segvacl->crashes = 0;
20669 ++ segvacl->expires = 0;
20670 ++ }
20671 ++ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
20672 ++ gr_remove_uid(gr_usermode->segv_uid);
20673 ++ }
20674 ++ } else {
20675 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
20676 ++ error = -EPERM;
20677 ++ }
20678 ++ break;
20679 ++ case SPROLE:
20680 ++ case SPROLEPAM:
20681 ++ if (unlikely(!(gr_status & GR_READY))) {
20682 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
20683 ++ error = -EAGAIN;
20684 ++ break;
20685 ++ }
20686 ++
20687 ++ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
20688 ++ current->role->expires = 0;
20689 ++ current->role->auth_attempts = 0;
20690 ++ }
20691 ++
20692 ++ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20693 ++ time_after(current->role->expires, get_seconds())) {
20694 ++ error = -EBUSY;
20695 ++ goto out;
20696 ++ }
20697 ++
20698 ++ if (lookup_special_role_auth
20699 ++ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
20700 ++ && ((!sprole_salt && !sprole_sum)
20701 ++ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
20702 ++ char *p = "";
20703 ++ assign_special_role(gr_usermode->sp_role);
20704 ++ read_lock(&tasklist_lock);
20705 ++ if (current->parent)
20706 ++ p = current->parent->role->rolename;
20707 ++ read_unlock(&tasklist_lock);
20708 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
20709 ++ p, acl_sp_role_value);
20710 ++ } else {
20711 ++ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
20712 ++ error = -EPERM;
20713 ++ if(!(current->role->auth_attempts++))
20714 ++ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20715 ++
20716 ++ goto out;
20717 ++ }
20718 ++ break;
20719 ++ case UNSPROLE:
20720 ++ if (unlikely(!(gr_status & GR_READY))) {
20721 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
20722 ++ error = -EAGAIN;
20723 ++ break;
20724 ++ }
20725 ++
20726 ++ if (current->role->roletype & GR_ROLE_SPECIAL) {
20727 ++ char *p = "";
20728 ++ int i = 0;
20729 ++
20730 ++ read_lock(&tasklist_lock);
20731 ++ if (current->parent) {
20732 ++ p = current->parent->role->rolename;
20733 ++ i = current->parent->acl_role_id;
20734 ++ }
20735 ++ read_unlock(&tasklist_lock);
20736 ++
20737 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
20738 ++ gr_set_acls(1);
20739 ++ } else {
20740 ++ gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename);
20741 ++ error = -EPERM;
20742 ++ goto out;
20743 ++ }
20744 ++ break;
20745 ++ default:
20746 ++ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
20747 ++ error = -EINVAL;
20748 ++ break;
20749 ++ }
20750 ++
20751 ++ if (error != -EPERM)
20752 ++ goto out;
20753 ++
20754 ++ if(!(gr_auth_attempts++))
20755 ++ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20756 ++
20757 ++ out:
20758 ++ up(&gr_dev_sem);
20759 ++ return error;
20760 ++}
20761 ++
20762 ++int
20763 ++gr_set_acls(const int type)
20764 ++{
20765 ++ struct acl_object_label *obj;
20766 ++ struct task_struct *task, *task2;
20767 ++ struct file *filp;
20768 ++ struct acl_role_label *role = current->role;
20769 ++ __u16 acl_role_id = current->acl_role_id;
20770 ++
20771 ++ read_lock(&tasklist_lock);
20772 ++ read_lock(&grsec_exec_file_lock);
20773 ++ do_each_thread(task2, task) {
20774 ++ /* check to see if we're called from the exit handler,
20775 ++ if so, only replace ACLs that have inherited the admin
20776 ++ ACL */
20777 ++
20778 ++ if (type && (task->role != role ||
20779 ++ task->acl_role_id != acl_role_id))
20780 ++ continue;
20781 ++
20782 ++ task->acl_role_id = 0;
20783 ++ task->acl_sp_role = 0;
20784 ++
20785 ++ if ((filp = task->exec_file)) {
20786 ++ task->role = lookup_acl_role_label(task, task->uid, task->gid);
20787 ++
20788 ++ task->acl =
20789 ++ chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
20790 ++ task->role);
20791 ++ if (task->acl) {
20792 ++ struct acl_subject_label *curr;
20793 ++ curr = task->acl;
20794 ++
20795 ++ task->is_writable = 0;
20796 ++ /* ignore additional mmap checks for processes that are writable
20797 ++ by the default ACL */
20798 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20799 ++ if (unlikely(obj->mode & GR_WRITE))
20800 ++ task->is_writable = 1;
20801 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
20802 ++ if (unlikely(obj->mode & GR_WRITE))
20803 ++ task->is_writable = 1;
20804 ++
20805 ++ gr_set_proc_res(task);
20806 ++
20807 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20808 ++ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20809 ++#endif
20810 ++ } else {
20811 ++ read_unlock(&grsec_exec_file_lock);
20812 ++ read_unlock(&tasklist_lock);
20813 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
20814 ++ return 1;
20815 ++ }
20816 ++ } else {
20817 ++ // it's a kernel process
20818 ++ task->role = kernel_role;
20819 ++ task->acl = kernel_role->root_label;
20820 ++#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
20821 ++ task->acl->mode &= ~GR_PROCFIND;
20822 ++#endif
20823 ++ }
20824 ++ } while_each_thread(task2, task);
20825 ++ read_unlock(&grsec_exec_file_lock);
20826 ++ read_unlock(&tasklist_lock);
20827 ++ return 0;
20828 ++}
20829 ++
20830 ++void
20831 ++gr_learn_resource(const struct task_struct *task,
20832 ++ const int res, const unsigned long wanted, const int gt)
20833 ++{
20834 ++ struct acl_subject_label *acl;
20835 ++
20836 ++ if (unlikely((gr_status & GR_READY) &&
20837 ++ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
20838 ++ goto skip_reslog;
20839 ++
20840 ++#ifdef CONFIG_GRKERNSEC_RESLOG
20841 ++ gr_log_resource(task, res, wanted, gt);
20842 ++#endif
20843 ++ skip_reslog:
20844 ++
20845 ++ if (unlikely(!(gr_status & GR_READY) || !wanted))
20846 ++ return;
20847 ++
20848 ++ acl = task->acl;
20849 ++
20850 ++ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
20851 ++ !(acl->resmask & (1 << (unsigned short) res))))
20852 ++ return;
20853 ++
20854 ++ if (wanted >= acl->res[res].rlim_cur) {
20855 ++ unsigned long res_add;
20856 ++
20857 ++ res_add = wanted;
20858 ++ switch (res) {
20859 ++ case RLIMIT_CPU:
20860 ++ res_add += GR_RLIM_CPU_BUMP;
20861 ++ break;
20862 ++ case RLIMIT_FSIZE:
20863 ++ res_add += GR_RLIM_FSIZE_BUMP;
20864 ++ break;
20865 ++ case RLIMIT_DATA:
20866 ++ res_add += GR_RLIM_DATA_BUMP;
20867 ++ break;
20868 ++ case RLIMIT_STACK:
20869 ++ res_add += GR_RLIM_STACK_BUMP;
20870 ++ break;
20871 ++ case RLIMIT_CORE:
20872 ++ res_add += GR_RLIM_CORE_BUMP;
20873 ++ break;
20874 ++ case RLIMIT_RSS:
20875 ++ res_add += GR_RLIM_RSS_BUMP;
20876 ++ break;
20877 ++ case RLIMIT_NPROC:
20878 ++ res_add += GR_RLIM_NPROC_BUMP;
20879 ++ break;
20880 ++ case RLIMIT_NOFILE:
20881 ++ res_add += GR_RLIM_NOFILE_BUMP;
20882 ++ break;
20883 ++ case RLIMIT_MEMLOCK:
20884 ++ res_add += GR_RLIM_MEMLOCK_BUMP;
20885 ++ break;
20886 ++ case RLIMIT_AS:
20887 ++ res_add += GR_RLIM_AS_BUMP;
20888 ++ break;
20889 ++ case RLIMIT_LOCKS:
20890 ++ res_add += GR_RLIM_LOCKS_BUMP;
20891 ++ break;
20892 ++ }
20893 ++
20894 ++ acl->res[res].rlim_cur = res_add;
20895 ++
20896 ++ if (wanted > acl->res[res].rlim_max)
20897 ++ acl->res[res].rlim_max = res_add;
20898 ++
20899 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
20900 ++ task->role->roletype, acl->filename,
20901 ++ acl->res[res].rlim_cur, acl->res[res].rlim_max,
20902 ++ "", (unsigned long) res);
20903 ++ }
20904 ++
20905 ++ return;
20906 ++}
20907 ++
20908 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
20909 ++void
20910 ++pax_set_initial_flags(struct linux_binprm *bprm)
20911 ++{
20912 ++ struct task_struct *task = current;
20913 ++ struct acl_subject_label *proc;
20914 ++ unsigned long flags;
20915 ++
20916 ++ if (unlikely(!(gr_status & GR_READY)))
20917 ++ return;
20918 ++
20919 ++ flags = pax_get_flags(task);
20920 ++
20921 ++ proc = task->acl;
20922 ++
20923 ++ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
20924 ++ flags &= ~MF_PAX_PAGEEXEC;
20925 ++ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
20926 ++ flags &= ~MF_PAX_SEGMEXEC;
20927 ++ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
20928 ++ flags &= ~MF_PAX_RANDMMAP;
20929 ++ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
20930 ++ flags &= ~MF_PAX_EMUTRAMP;
20931 ++ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
20932 ++ flags &= ~MF_PAX_MPROTECT;
20933 ++
20934 ++ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
20935 ++ flags |= MF_PAX_PAGEEXEC;
20936 ++ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
20937 ++ flags |= MF_PAX_SEGMEXEC;
20938 ++ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
20939 ++ flags |= MF_PAX_RANDMMAP;
20940 ++ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
20941 ++ flags |= MF_PAX_EMUTRAMP;
20942 ++ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
20943 ++ flags |= MF_PAX_MPROTECT;
20944 ++
20945 ++ pax_set_flags(task, flags);
20946 ++
20947 ++ return;
20948 ++}
20949 ++#endif
20950 ++
20951 ++#ifdef CONFIG_SYSCTL
20952 ++/* Eric Biederman likes breaking userland ABI and every inode-based security
20953 ++ system to save 35kb of memory */
20954 ++
20955 ++/* we modify the passed in filename, but adjust it back before returning */
20956 ++static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
20957 ++{
20958 ++ struct name_entry *nmatch;
20959 ++ char *p, *lastp = NULL;
20960 ++ struct acl_object_label *obj = NULL, *tmp;
20961 ++ struct acl_subject_label *tmpsubj;
20962 ++ char c = '\0';
20963 ++
20964 ++ read_lock(&gr_inode_lock);
20965 ++
20966 ++ p = name + len - 1;
20967 ++ do {
20968 ++ nmatch = lookup_name_entry(name);
20969 ++ if (lastp != NULL)
20970 ++ *lastp = c;
20971 ++
20972 ++ if (nmatch == NULL)
20973 ++ goto next_component;
20974 ++ tmpsubj = current->acl;
20975 ++ do {
20976 ++ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
20977 ++ if (obj != NULL) {
20978 ++ tmp = obj->globbed;
20979 ++ while (tmp) {
20980 ++ if (!glob_match(tmp->filename, name)) {
20981 ++ obj = tmp;
20982 ++ goto found_obj;
20983 ++ }
20984 ++ tmp = tmp->next;
20985 ++ }
20986 ++ goto found_obj;
20987 ++ }
20988 ++ } while ((tmpsubj = tmpsubj->parent_subject));
20989 ++next_component:
20990 ++ /* end case */
20991 ++ if (p == name)
20992 ++ break;
20993 ++
20994 ++ while (*p != '/')
20995 ++ p--;
20996 ++ if (p == name)
20997 ++ lastp = p + 1;
20998 ++ else {
20999 ++ lastp = p;
21000 ++ p--;
21001 ++ }
21002 ++ c = *lastp;
21003 ++ *lastp = '\0';
21004 ++ } while (1);
21005 ++found_obj:
21006 ++ read_unlock(&gr_inode_lock);
21007 ++ /* obj returned will always be non-null */
21008 ++ return obj;
21009 ++}
21010 ++
21011 ++/* returns 0 when allowing, non-zero on error
21012 ++ op of 0 is used for readdir, so we don't log the names of hidden files
21013 ++*/
21014 ++__u32
21015 ++gr_handle_sysctl(const struct ctl_table *table, const int op)
21016 ++{
21017 ++ ctl_table *tmp;
21018 ++ const char *proc_sys = "/proc/sys";
21019 ++ char *path;
21020 ++ struct acl_object_label *obj;
21021 ++ unsigned short len = 0, pos = 0, depth = 0, i;
21022 ++ __u32 err = 0;
21023 ++ __u32 mode = 0;
21024 ++
21025 ++ if (unlikely(!(gr_status & GR_READY)))
21026 ++ return 0;
21027 ++
21028 ++ /* for now, ignore operations on non-sysctl entries if it's not a
21029 ++ readdir*/
21030 ++ if (table->child != NULL && op != 0)
21031 ++ return 0;
21032 ++
21033 ++ mode |= GR_FIND;
21034 ++ /* it's only a read if it's an entry, read on dirs is for readdir */
21035 ++ if (op & MAY_READ)
21036 ++ mode |= GR_READ;
21037 ++ if (op & MAY_WRITE)
21038 ++ mode |= GR_WRITE;
21039 ++
21040 ++ preempt_disable();
21041 ++
21042 ++ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
21043 ++
21044 ++ /* it's only a read/write if it's an actual entry, not a dir
21045 ++ (which are opened for readdir)
21046 ++ */
21047 ++
21048 ++ /* convert the requested sysctl entry into a pathname */
21049 ++
21050 ++ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21051 ++ len += strlen(tmp->procname);
21052 ++ len++;
21053 ++ depth++;
21054 ++ }
21055 ++
21056 ++ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
21057 ++ /* deny */
21058 ++ goto out;
21059 ++ }
21060 ++
21061 ++ memset(path, 0, PAGE_SIZE);
21062 ++
21063 ++ memcpy(path, proc_sys, strlen(proc_sys));
21064 ++
21065 ++ pos += strlen(proc_sys);
21066 ++
21067 ++ for (; depth > 0; depth--) {
21068 ++ path[pos] = '/';
21069 ++ pos++;
21070 ++ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21071 ++ if (depth == i) {
21072 ++ memcpy(path + pos, tmp->procname,
21073 ++ strlen(tmp->procname));
21074 ++ pos += strlen(tmp->procname);
21075 ++ }
21076 ++ i++;
21077 ++ }
21078 ++ }
21079 ++
21080 ++ obj = gr_lookup_by_name(path, pos);
21081 ++ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
21082 ++
21083 ++ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
21084 ++ ((err & mode) != mode))) {
21085 ++ __u32 new_mode = mode;
21086 ++
21087 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21088 ++
21089 ++ err = 0;
21090 ++ gr_log_learn_sysctl(current, path, new_mode);
21091 ++ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
21092 ++ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
21093 ++ err = -ENOENT;
21094 ++ } else if (!(err & GR_FIND)) {
21095 ++ err = -ENOENT;
21096 ++ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
21097 ++ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
21098 ++ path, (mode & GR_READ) ? " reading" : "",
21099 ++ (mode & GR_WRITE) ? " writing" : "");
21100 ++ err = -EACCES;
21101 ++ } else if ((err & mode) != mode) {
21102 ++ err = -EACCES;
21103 ++ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
21104 ++ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
21105 ++ path, (mode & GR_READ) ? " reading" : "",
21106 ++ (mode & GR_WRITE) ? " writing" : "");
21107 ++ err = 0;
21108 ++ } else
21109 ++ err = 0;
21110 ++
21111 ++ out:
21112 ++ preempt_enable();
21113 ++
21114 ++ return err;
21115 ++}
21116 ++#endif
21117 ++
21118 ++int
21119 ++gr_handle_proc_ptrace(struct task_struct *task)
21120 ++{
21121 ++ struct file *filp;
21122 ++ struct task_struct *tmp = task;
21123 ++ struct task_struct *curtemp = current;
21124 ++ __u32 retmode;
21125 ++
21126 ++ if (unlikely(!(gr_status & GR_READY)))
21127 ++ return 0;
21128 ++
21129 ++ read_lock(&tasklist_lock);
21130 ++ read_lock(&grsec_exec_file_lock);
21131 ++ filp = task->exec_file;
21132 ++
21133 ++ while (tmp->pid > 0) {
21134 ++ if (tmp == curtemp)
21135 ++ break;
21136 ++ tmp = tmp->parent;
21137 ++ }
21138 ++
21139 ++ if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) {
21140 ++ read_unlock(&grsec_exec_file_lock);
21141 ++ read_unlock(&tasklist_lock);
21142 ++ return 1;
21143 ++ }
21144 ++
21145 ++ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
21146 ++ read_unlock(&grsec_exec_file_lock);
21147 ++ read_unlock(&tasklist_lock);
21148 ++
21149 ++ if (retmode & GR_NOPTRACE)
21150 ++ return 1;
21151 ++
21152 ++ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
21153 ++ && (current->acl != task->acl || (current->acl != current->role->root_label
21154 ++ && current->pid != task->pid)))
21155 ++ return 1;
21156 ++
21157 ++ return 0;
21158 ++}
21159 ++
21160 ++int
21161 ++gr_handle_ptrace(struct task_struct *task, const long request)
21162 ++{
21163 ++ struct task_struct *tmp = task;
21164 ++ struct task_struct *curtemp = current;
21165 ++ __u32 retmode;
21166 ++
21167 ++ if (unlikely(!(gr_status & GR_READY)))
21168 ++ return 0;
21169 ++
21170 ++ read_lock(&tasklist_lock);
21171 ++ while (tmp->pid > 0) {
21172 ++ if (tmp == curtemp)
21173 ++ break;
21174 ++ tmp = tmp->parent;
21175 ++ }
21176 ++
21177 ++ if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) {
21178 ++ read_unlock(&tasklist_lock);
21179 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21180 ++ return 1;
21181 ++ }
21182 ++ read_unlock(&tasklist_lock);
21183 ++
21184 ++ read_lock(&grsec_exec_file_lock);
21185 ++ if (unlikely(!task->exec_file)) {
21186 ++ read_unlock(&grsec_exec_file_lock);
21187 ++ return 0;
21188 ++ }
21189 ++
21190 ++ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
21191 ++ read_unlock(&grsec_exec_file_lock);
21192 ++
21193 ++ if (retmode & GR_NOPTRACE) {
21194 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21195 ++ return 1;
21196 ++ }
21197 ++
21198 ++ if (retmode & GR_PTRACERD) {
21199 ++ switch (request) {
21200 ++ case PTRACE_POKETEXT:
21201 ++ case PTRACE_POKEDATA:
21202 ++ case PTRACE_POKEUSR:
21203 ++#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
21204 ++ case PTRACE_SETREGS:
21205 ++ case PTRACE_SETFPREGS:
21206 ++#endif
21207 ++#ifdef CONFIG_X86
21208 ++ case PTRACE_SETFPXREGS:
21209 ++#endif
21210 ++#ifdef CONFIG_ALTIVEC
21211 ++ case PTRACE_SETVRREGS:
21212 ++#endif
21213 ++ return 1;
21214 ++ default:
21215 ++ return 0;
21216 ++ }
21217 ++ } else if (!(current->acl->mode & GR_POVERRIDE) &&
21218 ++ !(current->role->roletype & GR_ROLE_GOD) &&
21219 ++ (current->acl != task->acl)) {
21220 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21221 ++ return 1;
21222 ++ }
21223 ++
21224 ++ return 0;
21225 ++}
21226 ++
21227 ++static int is_writable_mmap(const struct file *filp)
21228 ++{
21229 ++ struct task_struct *task = current;
21230 ++ struct acl_object_label *obj, *obj2;
21231 ++
21232 ++ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
21233 ++ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) {
21234 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
21235 ++ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
21236 ++ task->role->root_label);
21237 ++ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
21238 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
21239 ++ return 1;
21240 ++ }
21241 ++ }
21242 ++ return 0;
21243 ++}
21244 ++
21245 ++int
21246 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
21247 ++{
21248 ++ __u32 mode;
21249 ++
21250 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21251 ++ return 1;
21252 ++
21253 ++ if (is_writable_mmap(file))
21254 ++ return 0;
21255 ++
21256 ++ mode =
21257 ++ gr_search_file(file->f_path.dentry,
21258 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21259 ++ file->f_path.mnt);
21260 ++
21261 ++ if (!gr_tpe_allow(file))
21262 ++ return 0;
21263 ++
21264 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21265 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21266 ++ return 0;
21267 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21268 ++ return 0;
21269 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21270 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21271 ++ return 1;
21272 ++ }
21273 ++
21274 ++ return 1;
21275 ++}
21276 ++
21277 ++int
21278 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
21279 ++{
21280 ++ __u32 mode;
21281 ++
21282 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21283 ++ return 1;
21284 ++
21285 ++ if (is_writable_mmap(file))
21286 ++ return 0;
21287 ++
21288 ++ mode =
21289 ++ gr_search_file(file->f_path.dentry,
21290 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21291 ++ file->f_path.mnt);
21292 ++
21293 ++ if (!gr_tpe_allow(file))
21294 ++ return 0;
21295 ++
21296 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21297 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21298 ++ return 0;
21299 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21300 ++ return 0;
21301 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21302 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21303 ++ return 1;
21304 ++ }
21305 ++
21306 ++ return 1;
21307 ++}
21308 ++
21309 ++void
21310 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
21311 ++{
21312 ++ unsigned long runtime;
21313 ++ unsigned long cputime;
21314 ++ unsigned int wday, cday;
21315 ++ __u8 whr, chr;
21316 ++ __u8 wmin, cmin;
21317 ++ __u8 wsec, csec;
21318 ++ struct timespec timeval;
21319 ++
21320 ++ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
21321 ++ !(task->acl->mode & GR_PROCACCT)))
21322 ++ return;
21323 ++
21324 ++ do_posix_clock_monotonic_gettime(&timeval);
21325 ++ runtime = timeval.tv_sec - task->start_time.tv_sec;
21326 ++ wday = runtime / (3600 * 24);
21327 ++ runtime -= wday * (3600 * 24);
21328 ++ whr = runtime / 3600;
21329 ++ runtime -= whr * 3600;
21330 ++ wmin = runtime / 60;
21331 ++ runtime -= wmin * 60;
21332 ++ wsec = runtime;
21333 ++
21334 ++ cputime = (task->utime + task->stime) / HZ;
21335 ++ cday = cputime / (3600 * 24);
21336 ++ cputime -= cday * (3600 * 24);
21337 ++ chr = cputime / 3600;
21338 ++ cputime -= chr * 3600;
21339 ++ cmin = cputime / 60;
21340 ++ cputime -= cmin * 60;
21341 ++ csec = cputime;
21342 ++
21343 ++ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
21344 ++
21345 ++ return;
21346 ++}
21347 ++
21348 ++void gr_set_kernel_label(struct task_struct *task)
21349 ++{
21350 ++ if (gr_status & GR_READY) {
21351 ++ task->role = kernel_role;
21352 ++ task->acl = kernel_role->root_label;
21353 ++ }
21354 ++ return;
21355 ++}
21356 ++
21357 ++int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
21358 ++{
21359 ++ struct task_struct *task = current;
21360 ++ struct dentry *dentry = file->f_path.dentry;
21361 ++ struct vfsmount *mnt = file->f_path.mnt;
21362 ++ struct acl_object_label *obj, *tmp;
21363 ++ struct acl_subject_label *subj;
21364 ++ unsigned int bufsize;
21365 ++ int is_not_root;
21366 ++ char *path;
21367 ++
21368 ++ if (unlikely(!(gr_status & GR_READY)))
21369 ++ return 1;
21370 ++
21371 ++ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21372 ++ return 1;
21373 ++
21374 ++ /* ignore Eric Biederman */
21375 ++ if (IS_PRIVATE(dentry->d_inode))
21376 ++ return 1;
21377 ++
21378 ++ subj = task->acl;
21379 ++ do {
21380 ++ obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
21381 ++ if (obj != NULL)
21382 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21383 ++ } while ((subj = subj->parent_subject));
21384 ++
21385 ++ obj = chk_obj_label(dentry, mnt, task->acl);
21386 ++ if (obj->globbed == NULL)
21387 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21388 ++
21389 ++ is_not_root = ((obj->filename[0] == '/') &&
21390 ++ (obj->filename[1] == '\0')) ? 0 : 1;
21391 ++ bufsize = PAGE_SIZE - namelen - is_not_root;
21392 ++
21393 ++ /* check bufsize > PAGE_SIZE || bufsize == 0 */
21394 ++ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
21395 ++ return 1;
21396 ++
21397 ++ preempt_disable();
21398 ++ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
21399 ++ bufsize);
21400 ++
21401 ++ bufsize = strlen(path);
21402 ++
21403 ++ /* if base is "/", don't append an additional slash */
21404 ++ if (is_not_root)
21405 ++ *(path + bufsize) = '/';
21406 ++ memcpy(path + bufsize + is_not_root, name, namelen);
21407 ++ *(path + bufsize + namelen + is_not_root) = '\0';
21408 ++
21409 ++ tmp = obj->globbed;
21410 ++ while (tmp) {
21411 ++ if (!glob_match(tmp->filename, path)) {
21412 ++ preempt_enable();
21413 ++ return (tmp->mode & GR_FIND) ? 1 : 0;
21414 ++ }
21415 ++ tmp = tmp->next;
21416 ++ }
21417 ++ preempt_enable();
21418 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21419 ++}
21420 ++
21421 ++EXPORT_SYMBOL(gr_learn_resource);
21422 ++EXPORT_SYMBOL(gr_set_kernel_label);
21423 ++#ifdef CONFIG_SECURITY
21424 ++EXPORT_SYMBOL(gr_check_user_change);
21425 ++EXPORT_SYMBOL(gr_check_group_change);
21426 ++#endif
21427 ++
21428 +diff -urNp linux-2.6.27.10/grsecurity/gracl_cap.c linux-2.6.27.10/grsecurity/gracl_cap.c
21429 +--- linux-2.6.27.10/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
21430 ++++ linux-2.6.27.10/grsecurity/gracl_cap.c 2008-11-18 03:38:45.000000000 -0500
21431 +@@ -0,0 +1,129 @@
21432 ++#include <linux/kernel.h>
21433 ++#include <linux/module.h>
21434 ++#include <linux/sched.h>
21435 ++#include <linux/gracl.h>
21436 ++#include <linux/grsecurity.h>
21437 ++#include <linux/grinternal.h>
21438 ++
21439 ++static const char *captab_log[] = {
21440 ++ "CAP_CHOWN",
21441 ++ "CAP_DAC_OVERRIDE",
21442 ++ "CAP_DAC_READ_SEARCH",
21443 ++ "CAP_FOWNER",
21444 ++ "CAP_FSETID",
21445 ++ "CAP_KILL",
21446 ++ "CAP_SETGID",
21447 ++ "CAP_SETUID",
21448 ++ "CAP_SETPCAP",
21449 ++ "CAP_LINUX_IMMUTABLE",
21450 ++ "CAP_NET_BIND_SERVICE",
21451 ++ "CAP_NET_BROADCAST",
21452 ++ "CAP_NET_ADMIN",
21453 ++ "CAP_NET_RAW",
21454 ++ "CAP_IPC_LOCK",
21455 ++ "CAP_IPC_OWNER",
21456 ++ "CAP_SYS_MODULE",
21457 ++ "CAP_SYS_RAWIO",
21458 ++ "CAP_SYS_CHROOT",
21459 ++ "CAP_SYS_PTRACE",
21460 ++ "CAP_SYS_PACCT",
21461 ++ "CAP_SYS_ADMIN",
21462 ++ "CAP_SYS_BOOT",
21463 ++ "CAP_SYS_NICE",
21464 ++ "CAP_SYS_RESOURCE",
21465 ++ "CAP_SYS_TIME",
21466 ++ "CAP_SYS_TTY_CONFIG",
21467 ++ "CAP_MKNOD",
21468 ++ "CAP_LEASE",
21469 ++ "CAP_AUDIT_WRITE",
21470 ++ "CAP_AUDIT_CONTROL",
21471 ++ "CAP_SETFCAP",
21472 ++ "CAP_MAC_OVERRIDE",
21473 ++ "CAP_MAC_ADMIN"
21474 ++};
21475 ++
21476 ++EXPORT_SYMBOL(gr_task_is_capable);
21477 ++EXPORT_SYMBOL(gr_is_capable_nolog);
21478 ++
21479 ++int
21480 ++gr_task_is_capable(struct task_struct *task, const int cap)
21481 ++{
21482 ++ struct acl_subject_label *curracl;
21483 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21484 ++
21485 ++ if (!gr_acl_is_enabled())
21486 ++ return 1;
21487 ++
21488 ++ curracl = task->acl;
21489 ++
21490 ++ cap_drop = curracl->cap_lower;
21491 ++ cap_mask = curracl->cap_mask;
21492 ++
21493 ++ while ((curracl = curracl->parent_subject)) {
21494 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21495 ++ current level subject, and is lowered in the current level subject, then add
21496 ++ it to the set of dropped capabilities
21497 ++ otherwise, add the current level subject's mask to the current computed mask
21498 ++ */
21499 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21500 ++ cap_raise(cap_mask, cap);
21501 ++ if (cap_raised(curracl->cap_lower, cap))
21502 ++ cap_raise(cap_drop, cap);
21503 ++ }
21504 ++ }
21505 ++
21506 ++ if (!cap_raised(cap_drop, cap))
21507 ++ return 1;
21508 ++
21509 ++ curracl = task->acl;
21510 ++
21511 ++ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
21512 ++ && cap_raised(task->cap_effective, cap)) {
21513 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
21514 ++ task->role->roletype, task->uid,
21515 ++ task->gid, task->exec_file ?
21516 ++ gr_to_filename(task->exec_file->f_path.dentry,
21517 ++ task->exec_file->f_path.mnt) : curracl->filename,
21518 ++ curracl->filename, 0UL,
21519 ++ 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip));
21520 ++ return 1;
21521 ++ }
21522 ++
21523 ++ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(task->cap_effective, cap))
21524 ++ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
21525 ++ return 0;
21526 ++}
21527 ++
21528 ++int
21529 ++gr_is_capable_nolog(const int cap)
21530 ++{
21531 ++ struct acl_subject_label *curracl;
21532 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21533 ++
21534 ++ if (!gr_acl_is_enabled())
21535 ++ return 1;
21536 ++
21537 ++ curracl = current->acl;
21538 ++
21539 ++ cap_drop = curracl->cap_lower;
21540 ++ cap_mask = curracl->cap_mask;
21541 ++
21542 ++ while ((curracl = curracl->parent_subject)) {
21543 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21544 ++ current level subject, and is lowered in the current level subject, then add
21545 ++ it to the set of dropped capabilities
21546 ++ otherwise, add the current level subject's mask to the current computed mask
21547 ++ */
21548 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21549 ++ cap_raise(cap_mask, cap);
21550 ++ if (cap_raised(curracl->cap_lower, cap))
21551 ++ cap_raise(cap_drop, cap);
21552 ++ }
21553 ++ }
21554 ++
21555 ++ if (!cap_raised(cap_drop, cap))
21556 ++ return 1;
21557 ++
21558 ++ return 0;
21559 ++}
21560 ++
21561 +diff -urNp linux-2.6.27.10/grsecurity/gracl_fs.c linux-2.6.27.10/grsecurity/gracl_fs.c
21562 +--- linux-2.6.27.10/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
21563 ++++ linux-2.6.27.10/grsecurity/gracl_fs.c 2008-11-18 03:38:45.000000000 -0500
21564 +@@ -0,0 +1,423 @@
21565 ++#include <linux/kernel.h>
21566 ++#include <linux/sched.h>
21567 ++#include <linux/types.h>
21568 ++#include <linux/fs.h>
21569 ++#include <linux/file.h>
21570 ++#include <linux/stat.h>
21571 ++#include <linux/grsecurity.h>
21572 ++#include <linux/grinternal.h>
21573 ++#include <linux/gracl.h>
21574 ++
21575 ++__u32
21576 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
21577 ++ const struct vfsmount * mnt)
21578 ++{
21579 ++ __u32 mode;
21580 ++
21581 ++ if (unlikely(!dentry->d_inode))
21582 ++ return GR_FIND;
21583 ++
21584 ++ mode =
21585 ++ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
21586 ++
21587 ++ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
21588 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21589 ++ return mode;
21590 ++ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
21591 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21592 ++ return 0;
21593 ++ } else if (unlikely(!(mode & GR_FIND)))
21594 ++ return 0;
21595 ++
21596 ++ return GR_FIND;
21597 ++}
21598 ++
21599 ++__u32
21600 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
21601 ++ const int fmode)
21602 ++{
21603 ++ __u32 reqmode = GR_FIND;
21604 ++ __u32 mode;
21605 ++
21606 ++ if (unlikely(!dentry->d_inode))
21607 ++ return reqmode;
21608 ++
21609 ++ if (unlikely(fmode & O_APPEND))
21610 ++ reqmode |= GR_APPEND;
21611 ++ else if (unlikely(fmode & FMODE_WRITE))
21612 ++ reqmode |= GR_WRITE;
21613 ++ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21614 ++ reqmode |= GR_READ;
21615 ++
21616 ++ mode =
21617 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21618 ++ mnt);
21619 ++
21620 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21621 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21622 ++ reqmode & GR_READ ? " reading" : "",
21623 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21624 ++ GR_APPEND ? " appending" : "");
21625 ++ return reqmode;
21626 ++ } else
21627 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21628 ++ {
21629 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21630 ++ reqmode & GR_READ ? " reading" : "",
21631 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21632 ++ GR_APPEND ? " appending" : "");
21633 ++ return 0;
21634 ++ } else if (unlikely((mode & reqmode) != reqmode))
21635 ++ return 0;
21636 ++
21637 ++ return reqmode;
21638 ++}
21639 ++
21640 ++__u32
21641 ++gr_acl_handle_creat(const struct dentry * dentry,
21642 ++ const struct dentry * p_dentry,
21643 ++ const struct vfsmount * p_mnt, const int fmode,
21644 ++ const int imode)
21645 ++{
21646 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21647 ++ __u32 mode;
21648 ++
21649 ++ if (unlikely(fmode & O_APPEND))
21650 ++ reqmode |= GR_APPEND;
21651 ++ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21652 ++ reqmode |= GR_READ;
21653 ++ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
21654 ++ reqmode |= GR_SETID;
21655 ++
21656 ++ mode =
21657 ++ gr_check_create(dentry, p_dentry, p_mnt,
21658 ++ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21659 ++
21660 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21661 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21662 ++ reqmode & GR_READ ? " reading" : "",
21663 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21664 ++ GR_APPEND ? " appending" : "");
21665 ++ return reqmode;
21666 ++ } else
21667 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21668 ++ {
21669 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21670 ++ reqmode & GR_READ ? " reading" : "",
21671 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21672 ++ GR_APPEND ? " appending" : "");
21673 ++ return 0;
21674 ++ } else if (unlikely((mode & reqmode) != reqmode))
21675 ++ return 0;
21676 ++
21677 ++ return reqmode;
21678 ++}
21679 ++
21680 ++__u32
21681 ++gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
21682 ++ const int fmode)
21683 ++{
21684 ++ __u32 mode, reqmode = GR_FIND;
21685 ++
21686 ++ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
21687 ++ reqmode |= GR_EXEC;
21688 ++ if (fmode & S_IWOTH)
21689 ++ reqmode |= GR_WRITE;
21690 ++ if (fmode & S_IROTH)
21691 ++ reqmode |= GR_READ;
21692 ++
21693 ++ mode =
21694 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21695 ++ mnt);
21696 ++
21697 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21698 ++ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21699 ++ reqmode & GR_READ ? " reading" : "",
21700 ++ reqmode & GR_WRITE ? " writing" : "",
21701 ++ reqmode & GR_EXEC ? " executing" : "");
21702 ++ return reqmode;
21703 ++ } else
21704 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21705 ++ {
21706 ++ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21707 ++ reqmode & GR_READ ? " reading" : "",
21708 ++ reqmode & GR_WRITE ? " writing" : "",
21709 ++ reqmode & GR_EXEC ? " executing" : "");
21710 ++ return 0;
21711 ++ } else if (unlikely((mode & reqmode) != reqmode))
21712 ++ return 0;
21713 ++
21714 ++ return reqmode;
21715 ++}
21716 ++
21717 ++static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
21718 ++{
21719 ++ __u32 mode;
21720 ++
21721 ++ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
21722 ++
21723 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21724 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
21725 ++ return mode;
21726 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21727 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
21728 ++ return 0;
21729 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21730 ++ return 0;
21731 ++
21732 ++ return (reqmode);
21733 ++}
21734 ++
21735 ++__u32
21736 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
21737 ++{
21738 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
21739 ++}
21740 ++
21741 ++__u32
21742 ++gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
21743 ++{
21744 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
21745 ++}
21746 ++
21747 ++__u32
21748 ++gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
21749 ++{
21750 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
21751 ++}
21752 ++
21753 ++__u32
21754 ++gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
21755 ++{
21756 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
21757 ++}
21758 ++
21759 ++__u32
21760 ++gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
21761 ++ mode_t mode)
21762 ++{
21763 ++ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
21764 ++ return 1;
21765 ++
21766 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21767 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21768 ++ GR_FCHMOD_ACL_MSG);
21769 ++ } else {
21770 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
21771 ++ }
21772 ++}
21773 ++
21774 ++__u32
21775 ++gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
21776 ++ mode_t mode)
21777 ++{
21778 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21779 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21780 ++ GR_CHMOD_ACL_MSG);
21781 ++ } else {
21782 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
21783 ++ }
21784 ++}
21785 ++
21786 ++__u32
21787 ++gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
21788 ++{
21789 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
21790 ++}
21791 ++
21792 ++__u32
21793 ++gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
21794 ++{
21795 ++ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
21796 ++}
21797 ++
21798 ++__u32
21799 ++gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
21800 ++{
21801 ++ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
21802 ++ GR_UNIXCONNECT_ACL_MSG);
21803 ++}
21804 ++
21805 ++/* hardlinks require at minimum create permission,
21806 ++ any additional privilege required is based on the
21807 ++ privilege of the file being linked to
21808 ++*/
21809 ++__u32
21810 ++gr_acl_handle_link(const struct dentry * new_dentry,
21811 ++ const struct dentry * parent_dentry,
21812 ++ const struct vfsmount * parent_mnt,
21813 ++ const struct dentry * old_dentry,
21814 ++ const struct vfsmount * old_mnt, const char *to)
21815 ++{
21816 ++ __u32 mode;
21817 ++ __u32 needmode = GR_CREATE | GR_LINK;
21818 ++ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
21819 ++
21820 ++ mode =
21821 ++ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
21822 ++ old_mnt);
21823 ++
21824 ++ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
21825 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21826 ++ return mode;
21827 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21828 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21829 ++ return 0;
21830 ++ } else if (unlikely((mode & needmode) != needmode))
21831 ++ return 0;
21832 ++
21833 ++ return 1;
21834 ++}
21835 ++
21836 ++__u32
21837 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
21838 ++ const struct dentry * parent_dentry,
21839 ++ const struct vfsmount * parent_mnt, const char *from)
21840 ++{
21841 ++ __u32 needmode = GR_WRITE | GR_CREATE;
21842 ++ __u32 mode;
21843 ++
21844 ++ mode =
21845 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
21846 ++ GR_CREATE | GR_AUDIT_CREATE |
21847 ++ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
21848 ++
21849 ++ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
21850 ++ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21851 ++ return mode;
21852 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21853 ++ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21854 ++ return 0;
21855 ++ } else if (unlikely((mode & needmode) != needmode))
21856 ++ return 0;
21857 ++
21858 ++ return (GR_WRITE | GR_CREATE);
21859 ++}
21860 ++
21861 ++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)
21862 ++{
21863 ++ __u32 mode;
21864 ++
21865 ++ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21866 ++
21867 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21868 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
21869 ++ return mode;
21870 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21871 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
21872 ++ return 0;
21873 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21874 ++ return 0;
21875 ++
21876 ++ return (reqmode);
21877 ++}
21878 ++
21879 ++__u32
21880 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
21881 ++ const struct dentry * parent_dentry,
21882 ++ const struct vfsmount * parent_mnt,
21883 ++ const int mode)
21884 ++{
21885 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21886 ++ if (unlikely(mode & (S_ISUID | S_ISGID)))
21887 ++ reqmode |= GR_SETID;
21888 ++
21889 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21890 ++ reqmode, GR_MKNOD_ACL_MSG);
21891 ++}
21892 ++
21893 ++__u32
21894 ++gr_acl_handle_mkdir(const struct dentry *new_dentry,
21895 ++ const struct dentry *parent_dentry,
21896 ++ const struct vfsmount *parent_mnt)
21897 ++{
21898 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21899 ++ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
21900 ++}
21901 ++
21902 ++#define RENAME_CHECK_SUCCESS(old, new) \
21903 ++ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
21904 ++ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
21905 ++
21906 ++int
21907 ++gr_acl_handle_rename(struct dentry *new_dentry,
21908 ++ struct dentry *parent_dentry,
21909 ++ const struct vfsmount *parent_mnt,
21910 ++ struct dentry *old_dentry,
21911 ++ struct inode *old_parent_inode,
21912 ++ struct vfsmount *old_mnt, const char *newname)
21913 ++{
21914 ++ __u32 comp1, comp2;
21915 ++ int error = 0;
21916 ++
21917 ++ if (unlikely(!gr_acl_is_enabled()))
21918 ++ return 0;
21919 ++
21920 ++ if (!new_dentry->d_inode) {
21921 ++ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
21922 ++ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
21923 ++ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
21924 ++ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
21925 ++ GR_DELETE | GR_AUDIT_DELETE |
21926 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
21927 ++ GR_SUPPRESS, old_mnt);
21928 ++ } else {
21929 ++ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
21930 ++ GR_CREATE | GR_DELETE |
21931 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
21932 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
21933 ++ GR_SUPPRESS, parent_mnt);
21934 ++ comp2 =
21935 ++ gr_search_file(old_dentry,
21936 ++ GR_READ | GR_WRITE | GR_AUDIT_READ |
21937 ++ GR_DELETE | GR_AUDIT_DELETE |
21938 ++ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
21939 ++ }
21940 ++
21941 ++ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
21942 ++ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
21943 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
21944 ++ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
21945 ++ && !(comp2 & GR_SUPPRESS)) {
21946 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
21947 ++ error = -EACCES;
21948 ++ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
21949 ++ error = -EACCES;
21950 ++
21951 ++ return error;
21952 ++}
21953 ++
21954 ++void
21955 ++gr_acl_handle_exit(void)
21956 ++{
21957 ++ u16 id;
21958 ++ char *rolename;
21959 ++ struct file *exec_file;
21960 ++
21961 ++ if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
21962 ++ id = current->acl_role_id;
21963 ++ rolename = current->role->rolename;
21964 ++ gr_set_acls(1);
21965 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
21966 ++ }
21967 ++
21968 ++ write_lock(&grsec_exec_file_lock);
21969 ++ exec_file = current->exec_file;
21970 ++ current->exec_file = NULL;
21971 ++ write_unlock(&grsec_exec_file_lock);
21972 ++
21973 ++ if (exec_file)
21974 ++ fput(exec_file);
21975 ++}
21976 ++
21977 ++int
21978 ++gr_acl_handle_procpidmem(const struct task_struct *task)
21979 ++{
21980 ++ if (unlikely(!gr_acl_is_enabled()))
21981 ++ return 0;
21982 ++
21983 ++ if (task != current && task->acl->mode & GR_PROTPROCFD)
21984 ++ return -EACCES;
21985 ++
21986 ++ return 0;
21987 ++}
21988 +diff -urNp linux-2.6.27.10/grsecurity/gracl_ip.c linux-2.6.27.10/grsecurity/gracl_ip.c
21989 +--- linux-2.6.27.10/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
21990 ++++ linux-2.6.27.10/grsecurity/gracl_ip.c 2008-11-18 03:38:45.000000000 -0500
21991 +@@ -0,0 +1,313 @@
21992 ++#include <linux/kernel.h>
21993 ++#include <asm/uaccess.h>
21994 ++#include <asm/errno.h>
21995 ++#include <net/sock.h>
21996 ++#include <linux/file.h>
21997 ++#include <linux/fs.h>
21998 ++#include <linux/net.h>
21999 ++#include <linux/in.h>
22000 ++#include <linux/skbuff.h>
22001 ++#include <linux/ip.h>
22002 ++#include <linux/udp.h>
22003 ++#include <linux/smp_lock.h>
22004 ++#include <linux/types.h>
22005 ++#include <linux/sched.h>
22006 ++#include <linux/netdevice.h>
22007 ++#include <linux/inetdevice.h>
22008 ++#include <linux/gracl.h>
22009 ++#include <linux/grsecurity.h>
22010 ++#include <linux/grinternal.h>
22011 ++
22012 ++#define GR_BIND 0x01
22013 ++#define GR_CONNECT 0x02
22014 ++#define GR_INVERT 0x04
22015 ++
22016 ++static const char * gr_protocols[256] = {
22017 ++ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
22018 ++ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
22019 ++ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
22020 ++ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
22021 ++ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
22022 ++ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
22023 ++ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
22024 ++ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
22025 ++ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
22026 ++ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
22027 ++ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
22028 ++ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
22029 ++ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
22030 ++ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
22031 ++ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
22032 ++ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
22033 ++ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
22034 ++ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
22035 ++ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
22036 ++ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
22037 ++ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
22038 ++ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
22039 ++ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
22040 ++ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
22041 ++ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
22042 ++ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
22043 ++ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
22044 ++ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
22045 ++ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
22046 ++ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
22047 ++ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
22048 ++ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
22049 ++ };
22050 ++
22051 ++static const char * gr_socktypes[11] = {
22052 ++ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
22053 ++ "unknown:7", "unknown:8", "unknown:9", "packet"
22054 ++ };
22055 ++
22056 ++const char *
22057 ++gr_proto_to_name(unsigned char proto)
22058 ++{
22059 ++ return gr_protocols[proto];
22060 ++}
22061 ++
22062 ++const char *
22063 ++gr_socktype_to_name(unsigned char type)
22064 ++{
22065 ++ return gr_socktypes[type];
22066 ++}
22067 ++
22068 ++int
22069 ++gr_search_socket(const int domain, const int type, const int protocol)
22070 ++{
22071 ++ struct acl_subject_label *curr;
22072 ++
22073 ++ if (unlikely(!gr_acl_is_enabled()))
22074 ++ goto exit;
22075 ++
22076 ++ if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
22077 ++ || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
22078 ++ goto exit; // let the kernel handle it
22079 ++
22080 ++ curr = current->acl;
22081 ++
22082 ++ if (!curr->ips)
22083 ++ goto exit;
22084 ++
22085 ++ if ((curr->ip_type & (1 << type)) &&
22086 ++ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
22087 ++ goto exit;
22088 ++
22089 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22090 ++ /* we don't place acls on raw sockets , and sometimes
22091 ++ dgram/ip sockets are opened for ioctl and not
22092 ++ bind/connect, so we'll fake a bind learn log */
22093 ++ if (type == SOCK_RAW || type == SOCK_PACKET) {
22094 ++ __u32 fakeip = 0;
22095 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22096 ++ current->role->roletype, current->uid,
22097 ++ current->gid, current->exec_file ?
22098 ++ gr_to_filename(current->exec_file->f_path.dentry,
22099 ++ current->exec_file->f_path.mnt) :
22100 ++ curr->filename, curr->filename,
22101 ++ NIPQUAD(fakeip), 0, type,
22102 ++ protocol, GR_CONNECT,
22103 ++NIPQUAD(current->signal->curr_ip));
22104 ++ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
22105 ++ __u32 fakeip = 0;
22106 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22107 ++ current->role->roletype, current->uid,
22108 ++ current->gid, current->exec_file ?
22109 ++ gr_to_filename(current->exec_file->f_path.dentry,
22110 ++ current->exec_file->f_path.mnt) :
22111 ++ curr->filename, curr->filename,
22112 ++ NIPQUAD(fakeip), 0, type,
22113 ++ protocol, GR_BIND, NIPQUAD(current->signal->curr_ip));
22114 ++ }
22115 ++ /* we'll log when they use connect or bind */
22116 ++ goto exit;
22117 ++ }
22118 ++
22119 ++ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet",
22120 ++ gr_socktype_to_name(type), gr_proto_to_name(protocol));
22121 ++
22122 ++ return 0;
22123 ++ exit:
22124 ++ return 1;
22125 ++}
22126 ++
22127 ++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)
22128 ++{
22129 ++ if ((ip->mode & mode) &&
22130 ++ (ip_port >= ip->low) &&
22131 ++ (ip_port <= ip->high) &&
22132 ++ ((ntohl(ip_addr) & our_netmask) ==
22133 ++ (ntohl(our_addr) & our_netmask))
22134 ++ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
22135 ++ && (ip->type & (1 << type))) {
22136 ++ if (ip->mode & GR_INVERT)
22137 ++ return 2; // specifically denied
22138 ++ else
22139 ++ return 1; // allowed
22140 ++ }
22141 ++
22142 ++ return 0; // not specifically allowed, may continue parsing
22143 ++}
22144 ++
22145 ++static int
22146 ++gr_search_connectbind(const int mode, const struct sock *sk,
22147 ++ const struct sockaddr_in *addr, const int type)
22148 ++{
22149 ++ char iface[IFNAMSIZ] = {0};
22150 ++ struct acl_subject_label *curr;
22151 ++ struct acl_ip_label *ip;
22152 ++ struct net_device *dev;
22153 ++ struct in_device *idev;
22154 ++ unsigned long i;
22155 ++ int ret;
22156 ++ __u32 ip_addr = 0;
22157 ++ __u32 our_addr;
22158 ++ __u32 our_netmask;
22159 ++ char *p;
22160 ++ __u16 ip_port = 0;
22161 ++
22162 ++ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
22163 ++ return 1;
22164 ++
22165 ++ curr = current->acl;
22166 ++
22167 ++ if (!curr->ips)
22168 ++ return 1;
22169 ++
22170 ++ ip_addr = addr->sin_addr.s_addr;
22171 ++ ip_port = ntohs(addr->sin_port);
22172 ++
22173 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22174 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22175 ++ current->role->roletype, current->uid,
22176 ++ current->gid, current->exec_file ?
22177 ++ gr_to_filename(current->exec_file->f_path.dentry,
22178 ++ current->exec_file->f_path.mnt) :
22179 ++ curr->filename, curr->filename,
22180 ++ NIPQUAD(ip_addr), ip_port, type,
22181 ++ sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip));
22182 ++ return 1;
22183 ++ }
22184 ++
22185 ++ for (i = 0; i < curr->ip_num; i++) {
22186 ++ ip = *(curr->ips + i);
22187 ++ if (ip->iface != NULL) {
22188 ++ strncpy(iface, ip->iface, IFNAMSIZ - 1);
22189 ++ p = strchr(iface, ':');
22190 ++ if (p != NULL)
22191 ++ *p = '\0';
22192 ++ dev = dev_get_by_name(sock_net(sk), iface);
22193 ++ if (dev == NULL)
22194 ++ continue;
22195 ++ idev = in_dev_get(dev);
22196 ++ if (idev == NULL) {
22197 ++ dev_put(dev);
22198 ++ continue;
22199 ++ }
22200 ++ rcu_read_lock();
22201 ++ for_ifa(idev) {
22202 ++ if (!strcmp(ip->iface, ifa->ifa_label)) {
22203 ++ our_addr = ifa->ifa_address;
22204 ++ our_netmask = 0xffffffff;
22205 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22206 ++ if (ret == 1) {
22207 ++ rcu_read_unlock();
22208 ++ in_dev_put(idev);
22209 ++ dev_put(dev);
22210 ++ return 1;
22211 ++ } else if (ret == 2) {
22212 ++ rcu_read_unlock();
22213 ++ in_dev_put(idev);
22214 ++ dev_put(dev);
22215 ++ goto denied;
22216 ++ }
22217 ++ }
22218 ++ } endfor_ifa(idev);
22219 ++ rcu_read_unlock();
22220 ++ in_dev_put(idev);
22221 ++ dev_put(dev);
22222 ++ } else {
22223 ++ our_addr = ip->addr;
22224 ++ our_netmask = ip->netmask;
22225 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22226 ++ if (ret == 1)
22227 ++ return 1;
22228 ++ else if (ret == 2)
22229 ++ goto denied;
22230 ++ }
22231 ++ }
22232 ++
22233 ++denied:
22234 ++ if (mode == GR_BIND)
22235 ++ 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));
22236 ++ else if (mode == GR_CONNECT)
22237 ++ 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));
22238 ++
22239 ++ return 0;
22240 ++}
22241 ++
22242 ++int
22243 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
22244 ++{
22245 ++ return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
22246 ++}
22247 ++
22248 ++int
22249 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
22250 ++{
22251 ++ return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
22252 ++}
22253 ++
22254 ++int gr_search_listen(const struct socket *sock)
22255 ++{
22256 ++ struct sock *sk = sock->sk;
22257 ++ struct sockaddr_in addr;
22258 ++
22259 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22260 ++ addr.sin_port = inet_sk(sk)->sport;
22261 ++
22262 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22263 ++}
22264 ++
22265 ++int gr_search_accept(const struct socket *sock)
22266 ++{
22267 ++ struct sock *sk = sock->sk;
22268 ++ struct sockaddr_in addr;
22269 ++
22270 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22271 ++ addr.sin_port = inet_sk(sk)->sport;
22272 ++
22273 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22274 ++}
22275 ++
22276 ++int
22277 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
22278 ++{
22279 ++ if (addr)
22280 ++ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
22281 ++ else {
22282 ++ struct sockaddr_in sin;
22283 ++ const struct inet_sock *inet = inet_sk(sk);
22284 ++
22285 ++ sin.sin_addr.s_addr = inet->daddr;
22286 ++ sin.sin_port = inet->dport;
22287 ++
22288 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22289 ++ }
22290 ++}
22291 ++
22292 ++int
22293 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
22294 ++{
22295 ++ struct sockaddr_in sin;
22296 ++
22297 ++ if (unlikely(skb->len < sizeof (struct udphdr)))
22298 ++ return 1; // skip this packet
22299 ++
22300 ++ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
22301 ++ sin.sin_port = udp_hdr(skb)->source;
22302 ++
22303 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22304 ++}
22305 +diff -urNp linux-2.6.27.10/grsecurity/gracl_learn.c linux-2.6.27.10/grsecurity/gracl_learn.c
22306 +--- linux-2.6.27.10/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
22307 ++++ linux-2.6.27.10/grsecurity/gracl_learn.c 2008-11-18 03:38:45.000000000 -0500
22308 +@@ -0,0 +1,211 @@
22309 ++#include <linux/kernel.h>
22310 ++#include <linux/mm.h>
22311 ++#include <linux/sched.h>
22312 ++#include <linux/poll.h>
22313 ++#include <linux/smp_lock.h>
22314 ++#include <linux/string.h>
22315 ++#include <linux/file.h>
22316 ++#include <linux/types.h>
22317 ++#include <linux/vmalloc.h>
22318 ++#include <linux/grinternal.h>
22319 ++
22320 ++extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
22321 ++ size_t count, loff_t *ppos);
22322 ++extern int gr_acl_is_enabled(void);
22323 ++
22324 ++static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
22325 ++static int gr_learn_attached;
22326 ++
22327 ++/* use a 512k buffer */
22328 ++#define LEARN_BUFFER_SIZE (512 * 1024)
22329 ++
22330 ++static DEFINE_SPINLOCK(gr_learn_lock);
22331 ++static DECLARE_MUTEX(gr_learn_user_sem);
22332 ++
22333 ++/* we need to maintain two buffers, so that the kernel context of grlearn
22334 ++ uses a semaphore around the userspace copying, and the other kernel contexts
22335 ++ use a spinlock when copying into the buffer, since they cannot sleep
22336 ++*/
22337 ++static char *learn_buffer;
22338 ++static char *learn_buffer_user;
22339 ++static int learn_buffer_len;
22340 ++static int learn_buffer_user_len;
22341 ++
22342 ++static ssize_t
22343 ++read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
22344 ++{
22345 ++ DECLARE_WAITQUEUE(wait, current);
22346 ++ ssize_t retval = 0;
22347 ++
22348 ++ add_wait_queue(&learn_wait, &wait);
22349 ++ set_current_state(TASK_INTERRUPTIBLE);
22350 ++ do {
22351 ++ down(&gr_learn_user_sem);
22352 ++ spin_lock(&gr_learn_lock);
22353 ++ if (learn_buffer_len)
22354 ++ break;
22355 ++ spin_unlock(&gr_learn_lock);
22356 ++ up(&gr_learn_user_sem);
22357 ++ if (file->f_flags & O_NONBLOCK) {
22358 ++ retval = -EAGAIN;
22359 ++ goto out;
22360 ++ }
22361 ++ if (signal_pending(current)) {
22362 ++ retval = -ERESTARTSYS;
22363 ++ goto out;
22364 ++ }
22365 ++
22366 ++ schedule();
22367 ++ } while (1);
22368 ++
22369 ++ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
22370 ++ learn_buffer_user_len = learn_buffer_len;
22371 ++ retval = learn_buffer_len;
22372 ++ learn_buffer_len = 0;
22373 ++
22374 ++ spin_unlock(&gr_learn_lock);
22375 ++
22376 ++ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
22377 ++ retval = -EFAULT;
22378 ++
22379 ++ up(&gr_learn_user_sem);
22380 ++out:
22381 ++ set_current_state(TASK_RUNNING);
22382 ++ remove_wait_queue(&learn_wait, &wait);
22383 ++ return retval;
22384 ++}
22385 ++
22386 ++static unsigned int
22387 ++poll_learn(struct file * file, poll_table * wait)
22388 ++{
22389 ++ poll_wait(file, &learn_wait, wait);
22390 ++
22391 ++ if (learn_buffer_len)
22392 ++ return (POLLIN | POLLRDNORM);
22393 ++
22394 ++ return 0;
22395 ++}
22396 ++
22397 ++void
22398 ++gr_clear_learn_entries(void)
22399 ++{
22400 ++ char *tmp;
22401 ++
22402 ++ down(&gr_learn_user_sem);
22403 ++ if (learn_buffer != NULL) {
22404 ++ spin_lock(&gr_learn_lock);
22405 ++ tmp = learn_buffer;
22406 ++ learn_buffer = NULL;
22407 ++ spin_unlock(&gr_learn_lock);
22408 ++ vfree(learn_buffer);
22409 ++ }
22410 ++ if (learn_buffer_user != NULL) {
22411 ++ vfree(learn_buffer_user);
22412 ++ learn_buffer_user = NULL;
22413 ++ }
22414 ++ learn_buffer_len = 0;
22415 ++ up(&gr_learn_user_sem);
22416 ++
22417 ++ return;
22418 ++}
22419 ++
22420 ++void
22421 ++gr_add_learn_entry(const char *fmt, ...)
22422 ++{
22423 ++ va_list args;
22424 ++ unsigned int len;
22425 ++
22426 ++ if (!gr_learn_attached)
22427 ++ return;
22428 ++
22429 ++ spin_lock(&gr_learn_lock);
22430 ++
22431 ++ /* leave a gap at the end so we know when it's "full" but don't have to
22432 ++ compute the exact length of the string we're trying to append
22433 ++ */
22434 ++ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
22435 ++ spin_unlock(&gr_learn_lock);
22436 ++ wake_up_interruptible(&learn_wait);
22437 ++ return;
22438 ++ }
22439 ++ if (learn_buffer == NULL) {
22440 ++ spin_unlock(&gr_learn_lock);
22441 ++ return;
22442 ++ }
22443 ++
22444 ++ va_start(args, fmt);
22445 ++ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
22446 ++ va_end(args);
22447 ++
22448 ++ learn_buffer_len += len + 1;
22449 ++
22450 ++ spin_unlock(&gr_learn_lock);
22451 ++ wake_up_interruptible(&learn_wait);
22452 ++
22453 ++ return;
22454 ++}
22455 ++
22456 ++static int
22457 ++open_learn(struct inode *inode, struct file *file)
22458 ++{
22459 ++ if (file->f_mode & FMODE_READ && gr_learn_attached)
22460 ++ return -EBUSY;
22461 ++ if (file->f_mode & FMODE_READ) {
22462 ++ int retval = 0;
22463 ++ down(&gr_learn_user_sem);
22464 ++ if (learn_buffer == NULL)
22465 ++ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
22466 ++ if (learn_buffer_user == NULL)
22467 ++ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
22468 ++ if (learn_buffer == NULL) {
22469 ++ retval = -ENOMEM;
22470 ++ goto out_error;
22471 ++ }
22472 ++ if (learn_buffer_user == NULL) {
22473 ++ retval = -ENOMEM;
22474 ++ goto out_error;
22475 ++ }
22476 ++ learn_buffer_len = 0;
22477 ++ learn_buffer_user_len = 0;
22478 ++ gr_learn_attached = 1;
22479 ++out_error:
22480 ++ up(&gr_learn_user_sem);
22481 ++ return retval;
22482 ++ }
22483 ++ return 0;
22484 ++}
22485 ++
22486 ++static int
22487 ++close_learn(struct inode *inode, struct file *file)
22488 ++{
22489 ++ char *tmp;
22490 ++
22491 ++ if (file->f_mode & FMODE_READ) {
22492 ++ down(&gr_learn_user_sem);
22493 ++ if (learn_buffer != NULL) {
22494 ++ spin_lock(&gr_learn_lock);
22495 ++ tmp = learn_buffer;
22496 ++ learn_buffer = NULL;
22497 ++ spin_unlock(&gr_learn_lock);
22498 ++ vfree(tmp);
22499 ++ }
22500 ++ if (learn_buffer_user != NULL) {
22501 ++ vfree(learn_buffer_user);
22502 ++ learn_buffer_user = NULL;
22503 ++ }
22504 ++ learn_buffer_len = 0;
22505 ++ learn_buffer_user_len = 0;
22506 ++ gr_learn_attached = 0;
22507 ++ up(&gr_learn_user_sem);
22508 ++ }
22509 ++
22510 ++ return 0;
22511 ++}
22512 ++
22513 ++struct file_operations grsec_fops = {
22514 ++ .read = read_learn,
22515 ++ .write = write_grsec_handler,
22516 ++ .open = open_learn,
22517 ++ .release = close_learn,
22518 ++ .poll = poll_learn,
22519 ++};
22520 +diff -urNp linux-2.6.27.10/grsecurity/gracl_res.c linux-2.6.27.10/grsecurity/gracl_res.c
22521 +--- linux-2.6.27.10/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
22522 ++++ linux-2.6.27.10/grsecurity/gracl_res.c 2008-11-18 03:38:45.000000000 -0500
22523 +@@ -0,0 +1,45 @@
22524 ++#include <linux/kernel.h>
22525 ++#include <linux/sched.h>
22526 ++#include <linux/gracl.h>
22527 ++#include <linux/grinternal.h>
22528 ++
22529 ++static const char *restab_log[] = {
22530 ++ [RLIMIT_CPU] = "RLIMIT_CPU",
22531 ++ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
22532 ++ [RLIMIT_DATA] = "RLIMIT_DATA",
22533 ++ [RLIMIT_STACK] = "RLIMIT_STACK",
22534 ++ [RLIMIT_CORE] = "RLIMIT_CORE",
22535 ++ [RLIMIT_RSS] = "RLIMIT_RSS",
22536 ++ [RLIMIT_NPROC] = "RLIMIT_NPROC",
22537 ++ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
22538 ++ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
22539 ++ [RLIMIT_AS] = "RLIMIT_AS",
22540 ++ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
22541 ++ [RLIMIT_LOCKS + 1] = "RLIMIT_CRASH"
22542 ++};
22543 ++
22544 ++void
22545 ++gr_log_resource(const struct task_struct *task,
22546 ++ const int res, const unsigned long wanted, const int gt)
22547 ++{
22548 ++ if (res == RLIMIT_NPROC &&
22549 ++ (cap_raised(task->cap_effective, CAP_SYS_ADMIN) ||
22550 ++ cap_raised(task->cap_effective, CAP_SYS_RESOURCE)))
22551 ++ return;
22552 ++ else if (res == RLIMIT_MEMLOCK &&
22553 ++ cap_raised(task->cap_effective, CAP_IPC_LOCK))
22554 ++ return;
22555 ++
22556 ++ if (!gr_acl_is_enabled() && !grsec_resource_logging)
22557 ++ return;
22558 ++
22559 ++ preempt_disable();
22560 ++
22561 ++ if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) ||
22562 ++ (!gt && wanted >= task->signal->rlim[res].rlim_cur)) &&
22563 ++ task->signal->rlim[res].rlim_cur != RLIM_INFINITY))
22564 ++ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur);
22565 ++ preempt_enable_no_resched();
22566 ++
22567 ++ return;
22568 ++}
22569 +diff -urNp linux-2.6.27.10/grsecurity/gracl_segv.c linux-2.6.27.10/grsecurity/gracl_segv.c
22570 +--- linux-2.6.27.10/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
22571 ++++ linux-2.6.27.10/grsecurity/gracl_segv.c 2008-11-18 03:38:45.000000000 -0500
22572 +@@ -0,0 +1,304 @@
22573 ++#include <linux/kernel.h>
22574 ++#include <linux/mm.h>
22575 ++#include <asm/uaccess.h>
22576 ++#include <asm/errno.h>
22577 ++#include <asm/mman.h>
22578 ++#include <net/sock.h>
22579 ++#include <linux/file.h>
22580 ++#include <linux/fs.h>
22581 ++#include <linux/net.h>
22582 ++#include <linux/in.h>
22583 ++#include <linux/smp_lock.h>
22584 ++#include <linux/slab.h>
22585 ++#include <linux/types.h>
22586 ++#include <linux/sched.h>
22587 ++#include <linux/timer.h>
22588 ++#include <linux/gracl.h>
22589 ++#include <linux/grsecurity.h>
22590 ++#include <linux/grinternal.h>
22591 ++
22592 ++static struct crash_uid *uid_set;
22593 ++static unsigned short uid_used;
22594 ++static DEFINE_SPINLOCK(gr_uid_lock);
22595 ++extern rwlock_t gr_inode_lock;
22596 ++extern struct acl_subject_label *
22597 ++ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
22598 ++ struct acl_role_label *role);
22599 ++extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
22600 ++
22601 ++int
22602 ++gr_init_uidset(void)
22603 ++{
22604 ++ uid_set =
22605 ++ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
22606 ++ uid_used = 0;
22607 ++
22608 ++ return uid_set ? 1 : 0;
22609 ++}
22610 ++
22611 ++void
22612 ++gr_free_uidset(void)
22613 ++{
22614 ++ if (uid_set)
22615 ++ kfree(uid_set);
22616 ++
22617 ++ return;
22618 ++}
22619 ++
22620 ++int
22621 ++gr_find_uid(const uid_t uid)
22622 ++{
22623 ++ struct crash_uid *tmp = uid_set;
22624 ++ uid_t buid;
22625 ++ int low = 0, high = uid_used - 1, mid;
22626 ++
22627 ++ while (high >= low) {
22628 ++ mid = (low + high) >> 1;
22629 ++ buid = tmp[mid].uid;
22630 ++ if (buid == uid)
22631 ++ return mid;
22632 ++ if (buid > uid)
22633 ++ high = mid - 1;
22634 ++ if (buid < uid)
22635 ++ low = mid + 1;
22636 ++ }
22637 ++
22638 ++ return -1;
22639 ++}
22640 ++
22641 ++static __inline__ void
22642 ++gr_insertsort(void)
22643 ++{
22644 ++ unsigned short i, j;
22645 ++ struct crash_uid index;
22646 ++
22647 ++ for (i = 1; i < uid_used; i++) {
22648 ++ index = uid_set[i];
22649 ++ j = i;
22650 ++ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
22651 ++ uid_set[j] = uid_set[j - 1];
22652 ++ j--;
22653 ++ }
22654 ++ uid_set[j] = index;
22655 ++ }
22656 ++
22657 ++ return;
22658 ++}
22659 ++
22660 ++static __inline__ void
22661 ++gr_insert_uid(const uid_t uid, const unsigned long expires)
22662 ++{
22663 ++ int loc;
22664 ++
22665 ++ if (uid_used == GR_UIDTABLE_MAX)
22666 ++ return;
22667 ++
22668 ++ loc = gr_find_uid(uid);
22669 ++
22670 ++ if (loc >= 0) {
22671 ++ uid_set[loc].expires = expires;
22672 ++ return;
22673 ++ }
22674 ++
22675 ++ uid_set[uid_used].uid = uid;
22676 ++ uid_set[uid_used].expires = expires;
22677 ++ uid_used++;
22678 ++
22679 ++ gr_insertsort();
22680 ++
22681 ++ return;
22682 ++}
22683 ++
22684 ++void
22685 ++gr_remove_uid(const unsigned short loc)
22686 ++{
22687 ++ unsigned short i;
22688 ++
22689 ++ for (i = loc + 1; i < uid_used; i++)
22690 ++ uid_set[i - 1] = uid_set[i];
22691 ++
22692 ++ uid_used--;
22693 ++
22694 ++ return;
22695 ++}
22696 ++
22697 ++int
22698 ++gr_check_crash_uid(const uid_t uid)
22699 ++{
22700 ++ int loc;
22701 ++ int ret = 0;
22702 ++
22703 ++ if (unlikely(!gr_acl_is_enabled()))
22704 ++ return 0;
22705 ++
22706 ++ spin_lock(&gr_uid_lock);
22707 ++ loc = gr_find_uid(uid);
22708 ++
22709 ++ if (loc < 0)
22710 ++ goto out_unlock;
22711 ++
22712 ++ if (time_before_eq(uid_set[loc].expires, get_seconds()))
22713 ++ gr_remove_uid(loc);
22714 ++ else
22715 ++ ret = 1;
22716 ++
22717 ++out_unlock:
22718 ++ spin_unlock(&gr_uid_lock);
22719 ++ return ret;
22720 ++}
22721 ++
22722 ++static __inline__ int
22723 ++proc_is_setxid(const struct task_struct *task)
22724 ++{
22725 ++ if (task->uid != task->euid || task->uid != task->suid ||
22726 ++ task->uid != task->fsuid)
22727 ++ return 1;
22728 ++ if (task->gid != task->egid || task->gid != task->sgid ||
22729 ++ task->gid != task->fsgid)
22730 ++ return 1;
22731 ++
22732 ++ return 0;
22733 ++}
22734 ++static __inline__ int
22735 ++gr_fake_force_sig(int sig, struct task_struct *t)
22736 ++{
22737 ++ unsigned long int flags;
22738 ++ int ret, blocked, ignored;
22739 ++ struct k_sigaction *action;
22740 ++
22741 ++ spin_lock_irqsave(&t->sighand->siglock, flags);
22742 ++ action = &t->sighand->action[sig-1];
22743 ++ ignored = action->sa.sa_handler == SIG_IGN;
22744 ++ blocked = sigismember(&t->blocked, sig);
22745 ++ if (blocked || ignored) {
22746 ++ action->sa.sa_handler = SIG_DFL;
22747 ++ if (blocked) {
22748 ++ sigdelset(&t->blocked, sig);
22749 ++ recalc_sigpending_and_wake(t);
22750 ++ }
22751 ++ }
22752 ++ if (action->sa.sa_handler == SIG_DFL)
22753 ++ t->signal->flags &= ~SIGNAL_UNKILLABLE;
22754 ++ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
22755 ++
22756 ++ spin_unlock_irqrestore(&t->sighand->siglock, flags);
22757 ++
22758 ++ return ret;
22759 ++}
22760 ++
22761 ++void
22762 ++gr_handle_crash(struct task_struct *task, const int sig)
22763 ++{
22764 ++ struct acl_subject_label *curr;
22765 ++ struct acl_subject_label *curr2;
22766 ++ struct task_struct *tsk, *tsk2;
22767 ++
22768 ++ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
22769 ++ return;
22770 ++
22771 ++ if (unlikely(!gr_acl_is_enabled()))
22772 ++ return;
22773 ++
22774 ++ curr = task->acl;
22775 ++
22776 ++ if (!(curr->resmask & (1 << GR_CRASH_RES)))
22777 ++ return;
22778 ++
22779 ++ if (time_before_eq(curr->expires, get_seconds())) {
22780 ++ curr->expires = 0;
22781 ++ curr->crashes = 0;
22782 ++ }
22783 ++
22784 ++ curr->crashes++;
22785 ++
22786 ++ if (!curr->expires)
22787 ++ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
22788 ++
22789 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22790 ++ time_after(curr->expires, get_seconds())) {
22791 ++ if (task->uid && proc_is_setxid(task)) {
22792 ++ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22793 ++ spin_lock(&gr_uid_lock);
22794 ++ gr_insert_uid(task->uid, curr->expires);
22795 ++ spin_unlock(&gr_uid_lock);
22796 ++ curr->expires = 0;
22797 ++ curr->crashes = 0;
22798 ++ read_lock(&tasklist_lock);
22799 ++ do_each_thread(tsk2, tsk) {
22800 ++ if (tsk != task && tsk->uid == task->uid)
22801 ++ gr_fake_force_sig(SIGKILL, tsk);
22802 ++ } while_each_thread(tsk2, tsk);
22803 ++ read_unlock(&tasklist_lock);
22804 ++ } else {
22805 ++ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22806 ++ read_lock(&tasklist_lock);
22807 ++ do_each_thread(tsk2, tsk) {
22808 ++ if (likely(tsk != task)) {
22809 ++ curr2 = tsk->acl;
22810 ++
22811 ++ if (curr2->device == curr->device &&
22812 ++ curr2->inode == curr->inode)
22813 ++ gr_fake_force_sig(SIGKILL, tsk);
22814 ++ }
22815 ++ } while_each_thread(tsk2, tsk);
22816 ++ read_unlock(&tasklist_lock);
22817 ++ }
22818 ++ }
22819 ++
22820 ++ return;
22821 ++}
22822 ++
22823 ++int
22824 ++gr_check_crash_exec(const struct file *filp)
22825 ++{
22826 ++ struct acl_subject_label *curr;
22827 ++
22828 ++ if (unlikely(!gr_acl_is_enabled()))
22829 ++ return 0;
22830 ++
22831 ++ read_lock(&gr_inode_lock);
22832 ++ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
22833 ++ filp->f_path.dentry->d_inode->i_sb->s_dev,
22834 ++ current->role);
22835 ++ read_unlock(&gr_inode_lock);
22836 ++
22837 ++ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
22838 ++ (!curr->crashes && !curr->expires))
22839 ++ return 0;
22840 ++
22841 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22842 ++ time_after(curr->expires, get_seconds()))
22843 ++ return 1;
22844 ++ else if (time_before_eq(curr->expires, get_seconds())) {
22845 ++ curr->crashes = 0;
22846 ++ curr->expires = 0;
22847 ++ }
22848 ++
22849 ++ return 0;
22850 ++}
22851 ++
22852 ++void
22853 ++gr_handle_alertkill(struct task_struct *task)
22854 ++{
22855 ++ struct acl_subject_label *curracl;
22856 ++ __u32 curr_ip;
22857 ++ struct task_struct *p, *p2;
22858 ++
22859 ++ if (unlikely(!gr_acl_is_enabled()))
22860 ++ return;
22861 ++
22862 ++ curracl = task->acl;
22863 ++ curr_ip = task->signal->curr_ip;
22864 ++
22865 ++ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
22866 ++ read_lock(&tasklist_lock);
22867 ++ do_each_thread(p2, p) {
22868 ++ if (p->signal->curr_ip == curr_ip)
22869 ++ gr_fake_force_sig(SIGKILL, p);
22870 ++ } while_each_thread(p2, p);
22871 ++ read_unlock(&tasklist_lock);
22872 ++ } else if (curracl->mode & GR_KILLPROC)
22873 ++ gr_fake_force_sig(SIGKILL, task);
22874 ++
22875 ++ return;
22876 ++}
22877 +diff -urNp linux-2.6.27.10/grsecurity/gracl_shm.c linux-2.6.27.10/grsecurity/gracl_shm.c
22878 +--- linux-2.6.27.10/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
22879 ++++ linux-2.6.27.10/grsecurity/gracl_shm.c 2008-11-18 03:38:45.000000000 -0500
22880 +@@ -0,0 +1,33 @@
22881 ++#include <linux/kernel.h>
22882 ++#include <linux/mm.h>
22883 ++#include <linux/sched.h>
22884 ++#include <linux/file.h>
22885 ++#include <linux/ipc.h>
22886 ++#include <linux/gracl.h>
22887 ++#include <linux/grsecurity.h>
22888 ++#include <linux/grinternal.h>
22889 ++
22890 ++int
22891 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
22892 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
22893 ++{
22894 ++ struct task_struct *task;
22895 ++
22896 ++ if (!gr_acl_is_enabled())
22897 ++ return 1;
22898 ++
22899 ++ task = find_task_by_vpid(shm_cprid);
22900 ++
22901 ++ if (unlikely(!task))
22902 ++ task = find_task_by_vpid(shm_lapid);
22903 ++
22904 ++ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
22905 ++ (task->pid == shm_lapid)) &&
22906 ++ (task->acl->mode & GR_PROTSHM) &&
22907 ++ (task->acl != current->acl))) {
22908 ++ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
22909 ++ return 0;
22910 ++ }
22911 ++
22912 ++ return 1;
22913 ++}
22914 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chdir.c linux-2.6.27.10/grsecurity/grsec_chdir.c
22915 +--- linux-2.6.27.10/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
22916 ++++ linux-2.6.27.10/grsecurity/grsec_chdir.c 2008-11-18 03:38:45.000000000 -0500
22917 +@@ -0,0 +1,19 @@
22918 ++#include <linux/kernel.h>
22919 ++#include <linux/sched.h>
22920 ++#include <linux/fs.h>
22921 ++#include <linux/file.h>
22922 ++#include <linux/grsecurity.h>
22923 ++#include <linux/grinternal.h>
22924 ++
22925 ++void
22926 ++gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
22927 ++{
22928 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
22929 ++ if ((grsec_enable_chdir && grsec_enable_group &&
22930 ++ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
22931 ++ !grsec_enable_group)) {
22932 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
22933 ++ }
22934 ++#endif
22935 ++ return;
22936 ++}
22937 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chroot.c linux-2.6.27.10/grsecurity/grsec_chroot.c
22938 +--- linux-2.6.27.10/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
22939 ++++ linux-2.6.27.10/grsecurity/grsec_chroot.c 2008-11-18 03:38:45.000000000 -0500
22940 +@@ -0,0 +1,336 @@
22941 ++#include <linux/kernel.h>
22942 ++#include <linux/module.h>
22943 ++#include <linux/sched.h>
22944 ++#include <linux/file.h>
22945 ++#include <linux/fs.h>
22946 ++#include <linux/mount.h>
22947 ++#include <linux/types.h>
22948 ++#include <linux/pid_namespace.h>
22949 ++#include <linux/grsecurity.h>
22950 ++#include <linux/grinternal.h>
22951 ++
22952 ++int
22953 ++gr_handle_chroot_unix(const pid_t pid)
22954 ++{
22955 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
22956 ++ struct pid *spid = NULL;
22957 ++
22958 ++ if (unlikely(!grsec_enable_chroot_unix))
22959 ++ return 1;
22960 ++
22961 ++ if (likely(!proc_is_chrooted(current)))
22962 ++ return 1;
22963 ++
22964 ++ read_lock(&tasklist_lock);
22965 ++
22966 ++ spid = find_vpid(pid);
22967 ++ if (spid) {
22968 ++ struct task_struct *p;
22969 ++ p = pid_task(spid, PIDTYPE_PID);
22970 ++ task_lock(p);
22971 ++ if (unlikely(!have_same_root(current, p))) {
22972 ++ task_unlock(p);
22973 ++ read_unlock(&tasklist_lock);
22974 ++ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
22975 ++ return 0;
22976 ++ }
22977 ++ task_unlock(p);
22978 ++ }
22979 ++ read_unlock(&tasklist_lock);
22980 ++#endif
22981 ++ return 1;
22982 ++}
22983 ++
22984 ++int
22985 ++gr_handle_chroot_nice(void)
22986 ++{
22987 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
22988 ++ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
22989 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
22990 ++ return -EPERM;
22991 ++ }
22992 ++#endif
22993 ++ return 0;
22994 ++}
22995 ++
22996 ++int
22997 ++gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
22998 ++{
22999 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
23000 ++ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
23001 ++ && proc_is_chrooted(current)) {
23002 ++ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
23003 ++ return -EACCES;
23004 ++ }
23005 ++#endif
23006 ++ return 0;
23007 ++}
23008 ++
23009 ++int
23010 ++gr_handle_chroot_rawio(const struct inode *inode)
23011 ++{
23012 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23013 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
23014 ++ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
23015 ++ return 1;
23016 ++#endif
23017 ++ return 0;
23018 ++}
23019 ++
23020 ++int
23021 ++gr_pid_is_chrooted(struct task_struct *p)
23022 ++{
23023 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
23024 ++ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
23025 ++ return 0;
23026 ++
23027 ++ task_lock(p);
23028 ++ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
23029 ++ !have_same_root(current, p)) {
23030 ++ task_unlock(p);
23031 ++ return 1;
23032 ++ }
23033 ++ task_unlock(p);
23034 ++#endif
23035 ++ return 0;
23036 ++}
23037 ++
23038 ++EXPORT_SYMBOL(gr_pid_is_chrooted);
23039 ++
23040 ++#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
23041 ++int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
23042 ++{
23043 ++ struct dentry *dentry = (struct dentry *)u_dentry;
23044 ++ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
23045 ++ struct dentry *realroot;
23046 ++ struct vfsmount *realrootmnt;
23047 ++ struct dentry *currentroot;
23048 ++ struct vfsmount *currentmnt;
23049 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
23050 ++ int ret = 1;
23051 ++
23052 ++ read_lock(&reaper->fs->lock);
23053 ++ realrootmnt = mntget(reaper->fs->root.mnt);
23054 ++ realroot = dget(reaper->fs->root.dentry);
23055 ++ read_unlock(&reaper->fs->lock);
23056 ++
23057 ++ read_lock(&current->fs->lock);
23058 ++ currentmnt = mntget(current->fs->root.mnt);
23059 ++ currentroot = dget(current->fs->root.dentry);
23060 ++ read_unlock(&current->fs->lock);
23061 ++
23062 ++ spin_lock(&dcache_lock);
23063 ++ for (;;) {
23064 ++ if (unlikely((dentry == realroot && mnt == realrootmnt)
23065 ++ || (dentry == currentroot && mnt == currentmnt)))
23066 ++ break;
23067 ++ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
23068 ++ if (mnt->mnt_parent == mnt)
23069 ++ break;
23070 ++ dentry = mnt->mnt_mountpoint;
23071 ++ mnt = mnt->mnt_parent;
23072 ++ continue;
23073 ++ }
23074 ++ dentry = dentry->d_parent;
23075 ++ }
23076 ++ spin_unlock(&dcache_lock);
23077 ++
23078 ++ dput(currentroot);
23079 ++ mntput(currentmnt);
23080 ++
23081 ++ /* access is outside of chroot */
23082 ++ if (dentry == realroot && mnt == realrootmnt)
23083 ++ ret = 0;
23084 ++
23085 ++ dput(realroot);
23086 ++ mntput(realrootmnt);
23087 ++ return ret;
23088 ++}
23089 ++#endif
23090 ++
23091 ++int
23092 ++gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
23093 ++{
23094 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
23095 ++ if (!grsec_enable_chroot_fchdir)
23096 ++ return 1;
23097 ++
23098 ++ if (!proc_is_chrooted(current))
23099 ++ return 1;
23100 ++ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
23101 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
23102 ++ return 0;
23103 ++ }
23104 ++#endif
23105 ++ return 1;
23106 ++}
23107 ++
23108 ++int
23109 ++gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23110 ++ const time_t shm_createtime)
23111 ++{
23112 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
23113 ++ struct pid *pid = NULL;
23114 ++ time_t starttime;
23115 ++
23116 ++ if (unlikely(!grsec_enable_chroot_shmat))
23117 ++ return 1;
23118 ++
23119 ++ if (likely(!proc_is_chrooted(current)))
23120 ++ return 1;
23121 ++
23122 ++ read_lock(&tasklist_lock);
23123 ++
23124 ++ pid = find_vpid(shm_cprid);
23125 ++ if (pid) {
23126 ++ struct task_struct *p;
23127 ++ p = pid_task(pid, PIDTYPE_PID);
23128 ++ task_lock(p);
23129 ++ starttime = p->start_time.tv_sec;
23130 ++ if (unlikely(!have_same_root(current, p) &&
23131 ++ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
23132 ++ task_unlock(p);
23133 ++ read_unlock(&tasklist_lock);
23134 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23135 ++ return 0;
23136 ++ }
23137 ++ task_unlock(p);
23138 ++ } else {
23139 ++ pid = find_vpid(shm_lapid);
23140 ++ if (pid) {
23141 ++ struct task_struct *p;
23142 ++ p = pid_task(pid, PIDTYPE_PID);
23143 ++ task_lock(p);
23144 ++ if (unlikely(!have_same_root(current, p))) {
23145 ++ task_unlock(p);
23146 ++ read_unlock(&tasklist_lock);
23147 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23148 ++ return 0;
23149 ++ }
23150 ++ task_unlock(p);
23151 ++ }
23152 ++ }
23153 ++
23154 ++ read_unlock(&tasklist_lock);
23155 ++#endif
23156 ++ return 1;
23157 ++}
23158 ++
23159 ++void
23160 ++gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
23161 ++{
23162 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
23163 ++ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
23164 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
23165 ++#endif
23166 ++ return;
23167 ++}
23168 ++
23169 ++int
23170 ++gr_handle_chroot_mknod(const struct dentry *dentry,
23171 ++ const struct vfsmount *mnt, const int mode)
23172 ++{
23173 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
23174 ++ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
23175 ++ proc_is_chrooted(current)) {
23176 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
23177 ++ return -EPERM;
23178 ++ }
23179 ++#endif
23180 ++ return 0;
23181 ++}
23182 ++
23183 ++int
23184 ++gr_handle_chroot_mount(const struct dentry *dentry,
23185 ++ const struct vfsmount *mnt, const char *dev_name)
23186 ++{
23187 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
23188 ++ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
23189 ++ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
23190 ++ return -EPERM;
23191 ++ }
23192 ++#endif
23193 ++ return 0;
23194 ++}
23195 ++
23196 ++int
23197 ++gr_handle_chroot_pivot(void)
23198 ++{
23199 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
23200 ++ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
23201 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
23202 ++ return -EPERM;
23203 ++ }
23204 ++#endif
23205 ++ return 0;
23206 ++}
23207 ++
23208 ++int
23209 ++gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
23210 ++{
23211 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
23212 ++ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
23213 ++ !gr_is_outside_chroot(dentry, mnt)) {
23214 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
23215 ++ return -EPERM;
23216 ++ }
23217 ++#endif
23218 ++ return 0;
23219 ++}
23220 ++
23221 ++void
23222 ++gr_handle_chroot_caps(struct task_struct *task)
23223 ++{
23224 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23225 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
23226 ++ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
23227 ++ task->cap_permitted =
23228 ++ cap_drop(task->cap_permitted, chroot_caps);
23229 ++ task->cap_inheritable =
23230 ++ cap_drop(task->cap_inheritable, chroot_caps);
23231 ++ task->cap_effective =
23232 ++ cap_drop(task->cap_effective, chroot_caps);
23233 ++ }
23234 ++#endif
23235 ++ return;
23236 ++}
23237 ++
23238 ++int
23239 ++gr_handle_chroot_sysctl(const int op)
23240 ++{
23241 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
23242 ++ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
23243 ++ && (op & MAY_WRITE))
23244 ++ return -EACCES;
23245 ++#endif
23246 ++ return 0;
23247 ++}
23248 ++
23249 ++void
23250 ++gr_handle_chroot_chdir(struct path *path)
23251 ++{
23252 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
23253 ++ if (grsec_enable_chroot_chdir)
23254 ++ set_fs_pwd(current->fs, path);
23255 ++#endif
23256 ++ return;
23257 ++}
23258 ++
23259 ++int
23260 ++gr_handle_chroot_chmod(const struct dentry *dentry,
23261 ++ const struct vfsmount *mnt, const int mode)
23262 ++{
23263 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
23264 ++ if (grsec_enable_chroot_chmod &&
23265 ++ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
23266 ++ proc_is_chrooted(current)) {
23267 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
23268 ++ return -EPERM;
23269 ++ }
23270 ++#endif
23271 ++ return 0;
23272 ++}
23273 ++
23274 ++#ifdef CONFIG_SECURITY
23275 ++EXPORT_SYMBOL(gr_handle_chroot_caps);
23276 ++#endif
23277 +diff -urNp linux-2.6.27.10/grsecurity/grsec_disabled.c linux-2.6.27.10/grsecurity/grsec_disabled.c
23278 +--- linux-2.6.27.10/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
23279 ++++ linux-2.6.27.10/grsecurity/grsec_disabled.c 2008-11-18 03:38:45.000000000 -0500
23280 +@@ -0,0 +1,418 @@
23281 ++#include <linux/kernel.h>
23282 ++#include <linux/module.h>
23283 ++#include <linux/sched.h>
23284 ++#include <linux/file.h>
23285 ++#include <linux/fs.h>
23286 ++#include <linux/kdev_t.h>
23287 ++#include <linux/net.h>
23288 ++#include <linux/in.h>
23289 ++#include <linux/ip.h>
23290 ++#include <linux/skbuff.h>
23291 ++#include <linux/sysctl.h>
23292 ++
23293 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
23294 ++void
23295 ++pax_set_initial_flags(struct linux_binprm *bprm)
23296 ++{
23297 ++ return;
23298 ++}
23299 ++#endif
23300 ++
23301 ++#ifdef CONFIG_SYSCTL
23302 ++__u32
23303 ++gr_handle_sysctl(const struct ctl_table * table, const int op)
23304 ++{
23305 ++ return 0;
23306 ++}
23307 ++#endif
23308 ++
23309 ++int
23310 ++gr_acl_is_enabled(void)
23311 ++{
23312 ++ return 0;
23313 ++}
23314 ++
23315 ++int
23316 ++gr_handle_rawio(const struct inode *inode)
23317 ++{
23318 ++ return 0;
23319 ++}
23320 ++
23321 ++void
23322 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
23323 ++{
23324 ++ return;
23325 ++}
23326 ++
23327 ++int
23328 ++gr_handle_ptrace(struct task_struct *task, const long request)
23329 ++{
23330 ++ return 0;
23331 ++}
23332 ++
23333 ++int
23334 ++gr_handle_proc_ptrace(struct task_struct *task)
23335 ++{
23336 ++ return 0;
23337 ++}
23338 ++
23339 ++void
23340 ++gr_learn_resource(const struct task_struct *task,
23341 ++ const int res, const unsigned long wanted, const int gt)
23342 ++{
23343 ++ return;
23344 ++}
23345 ++
23346 ++int
23347 ++gr_set_acls(const int type)
23348 ++{
23349 ++ return 0;
23350 ++}
23351 ++
23352 ++int
23353 ++gr_check_hidden_task(const struct task_struct *tsk)
23354 ++{
23355 ++ return 0;
23356 ++}
23357 ++
23358 ++int
23359 ++gr_check_protected_task(const struct task_struct *task)
23360 ++{
23361 ++ return 0;
23362 ++}
23363 ++
23364 ++void
23365 ++gr_copy_label(struct task_struct *tsk)
23366 ++{
23367 ++ return;
23368 ++}
23369 ++
23370 ++void
23371 ++gr_set_pax_flags(struct task_struct *task)
23372 ++{
23373 ++ return;
23374 ++}
23375 ++
23376 ++int
23377 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
23378 ++{
23379 ++ return 0;
23380 ++}
23381 ++
23382 ++void
23383 ++gr_handle_delete(const ino_t ino, const dev_t dev)
23384 ++{
23385 ++ return;
23386 ++}
23387 ++
23388 ++void
23389 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
23390 ++{
23391 ++ return;
23392 ++}
23393 ++
23394 ++void
23395 ++gr_handle_crash(struct task_struct *task, const int sig)
23396 ++{
23397 ++ return;
23398 ++}
23399 ++
23400 ++int
23401 ++gr_check_crash_exec(const struct file *filp)
23402 ++{
23403 ++ return 0;
23404 ++}
23405 ++
23406 ++int
23407 ++gr_check_crash_uid(const uid_t uid)
23408 ++{
23409 ++ return 0;
23410 ++}
23411 ++
23412 ++void
23413 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
23414 ++ struct dentry *old_dentry,
23415 ++ struct dentry *new_dentry,
23416 ++ struct vfsmount *mnt, const __u8 replace)
23417 ++{
23418 ++ return;
23419 ++}
23420 ++
23421 ++int
23422 ++gr_search_socket(const int family, const int type, const int protocol)
23423 ++{
23424 ++ return 1;
23425 ++}
23426 ++
23427 ++int
23428 ++gr_search_connectbind(const int mode, const struct socket *sock,
23429 ++ const struct sockaddr_in *addr)
23430 ++{
23431 ++ return 1;
23432 ++}
23433 ++
23434 ++int
23435 ++gr_task_is_capable(struct task_struct *task, const int cap)
23436 ++{
23437 ++ return 1;
23438 ++}
23439 ++
23440 ++int
23441 ++gr_is_capable_nolog(const int cap)
23442 ++{
23443 ++ return 1;
23444 ++}
23445 ++
23446 ++void
23447 ++gr_handle_alertkill(struct task_struct *task)
23448 ++{
23449 ++ return;
23450 ++}
23451 ++
23452 ++__u32
23453 ++gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
23454 ++{
23455 ++ return 1;
23456 ++}
23457 ++
23458 ++__u32
23459 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
23460 ++ const struct vfsmount * mnt)
23461 ++{
23462 ++ return 1;
23463 ++}
23464 ++
23465 ++__u32
23466 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
23467 ++ const int fmode)
23468 ++{
23469 ++ return 1;
23470 ++}
23471 ++
23472 ++__u32
23473 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
23474 ++{
23475 ++ return 1;
23476 ++}
23477 ++
23478 ++__u32
23479 ++gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
23480 ++{
23481 ++ return 1;
23482 ++}
23483 ++
23484 ++int
23485 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
23486 ++ unsigned int *vm_flags)
23487 ++{
23488 ++ return 1;
23489 ++}
23490 ++
23491 ++__u32
23492 ++gr_acl_handle_truncate(const struct dentry * dentry,
23493 ++ const struct vfsmount * mnt)
23494 ++{
23495 ++ return 1;
23496 ++}
23497 ++
23498 ++__u32
23499 ++gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
23500 ++{
23501 ++ return 1;
23502 ++}
23503 ++
23504 ++__u32
23505 ++gr_acl_handle_access(const struct dentry * dentry,
23506 ++ const struct vfsmount * mnt, const int fmode)
23507 ++{
23508 ++ return 1;
23509 ++}
23510 ++
23511 ++__u32
23512 ++gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
23513 ++ mode_t mode)
23514 ++{
23515 ++ return 1;
23516 ++}
23517 ++
23518 ++__u32
23519 ++gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
23520 ++ mode_t mode)
23521 ++{
23522 ++ return 1;
23523 ++}
23524 ++
23525 ++__u32
23526 ++gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
23527 ++{
23528 ++ return 1;
23529 ++}
23530 ++
23531 ++void
23532 ++grsecurity_init(void)
23533 ++{
23534 ++ return;
23535 ++}
23536 ++
23537 ++__u32
23538 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
23539 ++ const struct dentry * parent_dentry,
23540 ++ const struct vfsmount * parent_mnt,
23541 ++ const int mode)
23542 ++{
23543 ++ return 1;
23544 ++}
23545 ++
23546 ++__u32
23547 ++gr_acl_handle_mkdir(const struct dentry * new_dentry,
23548 ++ const struct dentry * parent_dentry,
23549 ++ const struct vfsmount * parent_mnt)
23550 ++{
23551 ++ return 1;
23552 ++}
23553 ++
23554 ++__u32
23555 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
23556 ++ const struct dentry * parent_dentry,
23557 ++ const struct vfsmount * parent_mnt, const char *from)
23558 ++{
23559 ++ return 1;
23560 ++}
23561 ++
23562 ++__u32
23563 ++gr_acl_handle_link(const struct dentry * new_dentry,
23564 ++ const struct dentry * parent_dentry,
23565 ++ const struct vfsmount * parent_mnt,
23566 ++ const struct dentry * old_dentry,
23567 ++ const struct vfsmount * old_mnt, const char *to)
23568 ++{
23569 ++ return 1;
23570 ++}
23571 ++
23572 ++int
23573 ++gr_acl_handle_rename(const struct dentry *new_dentry,
23574 ++ const struct dentry *parent_dentry,
23575 ++ const struct vfsmount *parent_mnt,
23576 ++ const struct dentry *old_dentry,
23577 ++ const struct inode *old_parent_inode,
23578 ++ const struct vfsmount *old_mnt, const char *newname)
23579 ++{
23580 ++ return 0;
23581 ++}
23582 ++
23583 ++int
23584 ++gr_acl_handle_filldir(const struct file *file, const char *name,
23585 ++ const int namelen, const ino_t ino)
23586 ++{
23587 ++ return 1;
23588 ++}
23589 ++
23590 ++int
23591 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23592 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
23593 ++{
23594 ++ return 1;
23595 ++}
23596 ++
23597 ++int
23598 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
23599 ++{
23600 ++ return 1;
23601 ++}
23602 ++
23603 ++int
23604 ++gr_search_accept(const struct socket *sock)
23605 ++{
23606 ++ return 1;
23607 ++}
23608 ++
23609 ++int
23610 ++gr_search_listen(const struct socket *sock)
23611 ++{
23612 ++ return 1;
23613 ++}
23614 ++
23615 ++int
23616 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
23617 ++{
23618 ++ return 1;
23619 ++}
23620 ++
23621 ++__u32
23622 ++gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
23623 ++{
23624 ++ return 1;
23625 ++}
23626 ++
23627 ++__u32
23628 ++gr_acl_handle_creat(const struct dentry * dentry,
23629 ++ const struct dentry * p_dentry,
23630 ++ const struct vfsmount * p_mnt, const int fmode,
23631 ++ const int imode)
23632 ++{
23633 ++ return 1;
23634 ++}
23635 ++
23636 ++void
23637 ++gr_acl_handle_exit(void)
23638 ++{
23639 ++ return;
23640 ++}
23641 ++
23642 ++int
23643 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
23644 ++{
23645 ++ return 1;
23646 ++}
23647 ++
23648 ++void
23649 ++gr_set_role_label(const uid_t uid, const gid_t gid)
23650 ++{
23651 ++ return;
23652 ++}
23653 ++
23654 ++int
23655 ++gr_acl_handle_procpidmem(const struct task_struct *task)
23656 ++{
23657 ++ return 0;
23658 ++}
23659 ++
23660 ++int
23661 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
23662 ++{
23663 ++ return 1;
23664 ++}
23665 ++
23666 ++int
23667 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
23668 ++{
23669 ++ return 1;
23670 ++}
23671 ++
23672 ++void
23673 ++gr_set_kernel_label(struct task_struct *task)
23674 ++{
23675 ++ return;
23676 ++}
23677 ++
23678 ++int
23679 ++gr_check_user_change(int real, int effective, int fs)
23680 ++{
23681 ++ return 0;
23682 ++}
23683 ++
23684 ++int
23685 ++gr_check_group_change(int real, int effective, int fs)
23686 ++{
23687 ++ return 0;
23688 ++}
23689 ++
23690 ++
23691 ++EXPORT_SYMBOL(gr_task_is_capable);
23692 ++EXPORT_SYMBOL(gr_is_capable_nolog);
23693 ++EXPORT_SYMBOL(gr_learn_resource);
23694 ++EXPORT_SYMBOL(gr_set_kernel_label);
23695 ++#ifdef CONFIG_SECURITY
23696 ++EXPORT_SYMBOL(gr_check_user_change);
23697 ++EXPORT_SYMBOL(gr_check_group_change);
23698 ++#endif
23699 +diff -urNp linux-2.6.27.10/grsecurity/grsec_exec.c linux-2.6.27.10/grsecurity/grsec_exec.c
23700 +--- linux-2.6.27.10/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
23701 ++++ linux-2.6.27.10/grsecurity/grsec_exec.c 2008-11-18 03:38:45.000000000 -0500
23702 +@@ -0,0 +1,88 @@
23703 ++#include <linux/kernel.h>
23704 ++#include <linux/sched.h>
23705 ++#include <linux/file.h>
23706 ++#include <linux/binfmts.h>
23707 ++#include <linux/smp_lock.h>
23708 ++#include <linux/fs.h>
23709 ++#include <linux/types.h>
23710 ++#include <linux/grdefs.h>
23711 ++#include <linux/grinternal.h>
23712 ++#include <linux/capability.h>
23713 ++
23714 ++#include <asm/uaccess.h>
23715 ++
23716 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23717 ++static char gr_exec_arg_buf[132];
23718 ++static DECLARE_MUTEX(gr_exec_arg_sem);
23719 ++#endif
23720 ++
23721 ++int
23722 ++gr_handle_nproc(void)
23723 ++{
23724 ++#ifdef CONFIG_GRKERNSEC_EXECVE
23725 ++ if (grsec_enable_execve && current->user &&
23726 ++ (atomic_read(&current->user->processes) >
23727 ++ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
23728 ++ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
23729 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
23730 ++ return -EAGAIN;
23731 ++ }
23732 ++#endif
23733 ++ return 0;
23734 ++}
23735 ++
23736 ++void
23737 ++gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv)
23738 ++{
23739 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23740 ++ char *grarg = gr_exec_arg_buf;
23741 ++ unsigned int i, x, execlen = 0;
23742 ++ char c;
23743 ++
23744 ++ if (!((grsec_enable_execlog && grsec_enable_group &&
23745 ++ in_group_p(grsec_audit_gid))
23746 ++ || (grsec_enable_execlog && !grsec_enable_group)))
23747 ++ return;
23748 ++
23749 ++ down(&gr_exec_arg_sem);
23750 ++ memset(grarg, 0, sizeof(gr_exec_arg_buf));
23751 ++
23752 ++ if (unlikely(argv == NULL))
23753 ++ goto log;
23754 ++
23755 ++ for (i = 0; i < bprm->argc && execlen < 128; i++) {
23756 ++ const char __user *p;
23757 ++ unsigned int len;
23758 ++
23759 ++ if (copy_from_user(&p, argv + i, sizeof(p)))
23760 ++ goto log;
23761 ++ if (!p)
23762 ++ goto log;
23763 ++ len = strnlen_user(p, 128 - execlen);
23764 ++ if (len > 128 - execlen)
23765 ++ len = 128 - execlen;
23766 ++ else if (len > 0)
23767 ++ len--;
23768 ++ if (copy_from_user(grarg + execlen, p, len))
23769 ++ goto log;
23770 ++
23771 ++ /* rewrite unprintable characters */
23772 ++ for (x = 0; x < len; x++) {
23773 ++ c = *(grarg + execlen + x);
23774 ++ if (c < 32 || c > 126)
23775 ++ *(grarg + execlen + x) = ' ';
23776 ++ }
23777 ++
23778 ++ execlen += len;
23779 ++ *(grarg + execlen) = ' ';
23780 ++ *(grarg + execlen + 1) = '\0';
23781 ++ execlen++;
23782 ++ }
23783 ++
23784 ++ log:
23785 ++ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
23786 ++ bprm->file->f_path.mnt, grarg);
23787 ++ up(&gr_exec_arg_sem);
23788 ++#endif
23789 ++ return;
23790 ++}
23791 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fifo.c linux-2.6.27.10/grsecurity/grsec_fifo.c
23792 +--- linux-2.6.27.10/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
23793 ++++ linux-2.6.27.10/grsecurity/grsec_fifo.c 2008-11-18 03:38:45.000000000 -0500
23794 +@@ -0,0 +1,22 @@
23795 ++#include <linux/kernel.h>
23796 ++#include <linux/sched.h>
23797 ++#include <linux/fs.h>
23798 ++#include <linux/file.h>
23799 ++#include <linux/grinternal.h>
23800 ++
23801 ++int
23802 ++gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
23803 ++ const struct dentry *dir, const int flag, const int acc_mode)
23804 ++{
23805 ++#ifdef CONFIG_GRKERNSEC_FIFO
23806 ++ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
23807 ++ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
23808 ++ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
23809 ++ (current->fsuid != dentry->d_inode->i_uid)) {
23810 ++ if (!generic_permission(dentry->d_inode, acc_mode, NULL))
23811 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
23812 ++ return -EACCES;
23813 ++ }
23814 ++#endif
23815 ++ return 0;
23816 ++}
23817 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fork.c linux-2.6.27.10/grsecurity/grsec_fork.c
23818 +--- linux-2.6.27.10/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
23819 ++++ linux-2.6.27.10/grsecurity/grsec_fork.c 2008-11-18 03:38:45.000000000 -0500
23820 +@@ -0,0 +1,15 @@
23821 ++#include <linux/kernel.h>
23822 ++#include <linux/sched.h>
23823 ++#include <linux/grsecurity.h>
23824 ++#include <linux/grinternal.h>
23825 ++#include <linux/errno.h>
23826 ++
23827 ++void
23828 ++gr_log_forkfail(const int retval)
23829 ++{
23830 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
23831 ++ if (grsec_enable_forkfail && retval != -ERESTARTNOINTR)
23832 ++ gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval);
23833 ++#endif
23834 ++ return;
23835 ++}
23836 +diff -urNp linux-2.6.27.10/grsecurity/grsec_init.c linux-2.6.27.10/grsecurity/grsec_init.c
23837 +--- linux-2.6.27.10/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
23838 ++++ linux-2.6.27.10/grsecurity/grsec_init.c 2008-11-18 03:38:45.000000000 -0500
23839 +@@ -0,0 +1,230 @@
23840 ++#include <linux/kernel.h>
23841 ++#include <linux/sched.h>
23842 ++#include <linux/mm.h>
23843 ++#include <linux/smp_lock.h>
23844 ++#include <linux/gracl.h>
23845 ++#include <linux/slab.h>
23846 ++#include <linux/vmalloc.h>
23847 ++#include <linux/percpu.h>
23848 ++
23849 ++int grsec_enable_link;
23850 ++int grsec_enable_dmesg;
23851 ++int grsec_enable_fifo;
23852 ++int grsec_enable_execve;
23853 ++int grsec_enable_execlog;
23854 ++int grsec_enable_signal;
23855 ++int grsec_enable_forkfail;
23856 ++int grsec_enable_time;
23857 ++int grsec_enable_audit_textrel;
23858 ++int grsec_enable_group;
23859 ++int grsec_audit_gid;
23860 ++int grsec_enable_chdir;
23861 ++int grsec_enable_audit_ipc;
23862 ++int grsec_enable_mount;
23863 ++int grsec_enable_chroot_findtask;
23864 ++int grsec_enable_chroot_mount;
23865 ++int grsec_enable_chroot_shmat;
23866 ++int grsec_enable_chroot_fchdir;
23867 ++int grsec_enable_chroot_double;
23868 ++int grsec_enable_chroot_pivot;
23869 ++int grsec_enable_chroot_chdir;
23870 ++int grsec_enable_chroot_chmod;
23871 ++int grsec_enable_chroot_mknod;
23872 ++int grsec_enable_chroot_nice;
23873 ++int grsec_enable_chroot_execlog;
23874 ++int grsec_enable_chroot_caps;
23875 ++int grsec_enable_chroot_sysctl;
23876 ++int grsec_enable_chroot_unix;
23877 ++int grsec_enable_tpe;
23878 ++int grsec_tpe_gid;
23879 ++int grsec_enable_tpe_all;
23880 ++int grsec_enable_socket_all;
23881 ++int grsec_socket_all_gid;
23882 ++int grsec_enable_socket_client;
23883 ++int grsec_socket_client_gid;
23884 ++int grsec_enable_socket_server;
23885 ++int grsec_socket_server_gid;
23886 ++int grsec_resource_logging;
23887 ++int grsec_lock;
23888 ++
23889 ++DEFINE_SPINLOCK(grsec_alert_lock);
23890 ++unsigned long grsec_alert_wtime = 0;
23891 ++unsigned long grsec_alert_fyet = 0;
23892 ++
23893 ++DEFINE_SPINLOCK(grsec_audit_lock);
23894 ++
23895 ++DEFINE_RWLOCK(grsec_exec_file_lock);
23896 ++
23897 ++char *gr_shared_page[4];
23898 ++
23899 ++char *gr_alert_log_fmt;
23900 ++char *gr_audit_log_fmt;
23901 ++char *gr_alert_log_buf;
23902 ++char *gr_audit_log_buf;
23903 ++
23904 ++extern struct gr_arg *gr_usermode;
23905 ++extern unsigned char *gr_system_salt;
23906 ++extern unsigned char *gr_system_sum;
23907 ++
23908 ++void
23909 ++grsecurity_init(void)
23910 ++{
23911 ++ int j;
23912 ++ /* create the per-cpu shared pages */
23913 ++
23914 ++#ifdef CONFIG_X86
23915 ++ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
23916 ++#endif
23917 ++
23918 ++ for (j = 0; j < 4; j++) {
23919 ++ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE);
23920 ++ if (gr_shared_page[j] == NULL) {
23921 ++ panic("Unable to allocate grsecurity shared page");
23922 ++ return;
23923 ++ }
23924 ++ }
23925 ++
23926 ++ /* allocate log buffers */
23927 ++ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
23928 ++ if (!gr_alert_log_fmt) {
23929 ++ panic("Unable to allocate grsecurity alert log format buffer");
23930 ++ return;
23931 ++ }
23932 ++ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
23933 ++ if (!gr_audit_log_fmt) {
23934 ++ panic("Unable to allocate grsecurity audit log format buffer");
23935 ++ return;
23936 ++ }
23937 ++ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
23938 ++ if (!gr_alert_log_buf) {
23939 ++ panic("Unable to allocate grsecurity alert log buffer");
23940 ++ return;
23941 ++ }
23942 ++ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
23943 ++ if (!gr_audit_log_buf) {
23944 ++ panic("Unable to allocate grsecurity audit log buffer");
23945 ++ return;
23946 ++ }
23947 ++
23948 ++ /* allocate memory for authentication structure */
23949 ++ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
23950 ++ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
23951 ++ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
23952 ++
23953 ++ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
23954 ++ panic("Unable to allocate grsecurity authentication structure");
23955 ++ return;
23956 ++ }
23957 ++
23958 ++#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
23959 ++#ifndef CONFIG_GRKERNSEC_SYSCTL
23960 ++ grsec_lock = 1;
23961 ++#endif
23962 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
23963 ++ grsec_enable_audit_textrel = 1;
23964 ++#endif
23965 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
23966 ++ grsec_enable_group = 1;
23967 ++ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
23968 ++#endif
23969 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
23970 ++ grsec_enable_chdir = 1;
23971 ++#endif
23972 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
23973 ++ grsec_enable_audit_ipc = 1;
23974 ++#endif
23975 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
23976 ++ grsec_enable_mount = 1;
23977 ++#endif
23978 ++#ifdef CONFIG_GRKERNSEC_LINK
23979 ++ grsec_enable_link = 1;
23980 ++#endif
23981 ++#ifdef CONFIG_GRKERNSEC_DMESG
23982 ++ grsec_enable_dmesg = 1;
23983 ++#endif
23984 ++#ifdef CONFIG_GRKERNSEC_FIFO
23985 ++ grsec_enable_fifo = 1;
23986 ++#endif
23987 ++#ifdef CONFIG_GRKERNSEC_EXECVE
23988 ++ grsec_enable_execve = 1;
23989 ++#endif
23990 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23991 ++ grsec_enable_execlog = 1;
23992 ++#endif
23993 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
23994 ++ grsec_enable_signal = 1;
23995 ++#endif
23996 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
23997 ++ grsec_enable_forkfail = 1;
23998 ++#endif
23999 ++#ifdef CONFIG_GRKERNSEC_TIME
24000 ++ grsec_enable_time = 1;
24001 ++#endif
24002 ++#ifdef CONFIG_GRKERNSEC_RESLOG
24003 ++ grsec_resource_logging = 1;
24004 ++#endif
24005 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
24006 ++ grsec_enable_chroot_findtask = 1;
24007 ++#endif
24008 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
24009 ++ grsec_enable_chroot_unix = 1;
24010 ++#endif
24011 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
24012 ++ grsec_enable_chroot_mount = 1;
24013 ++#endif
24014 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
24015 ++ grsec_enable_chroot_fchdir = 1;
24016 ++#endif
24017 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
24018 ++ grsec_enable_chroot_shmat = 1;
24019 ++#endif
24020 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
24021 ++ grsec_enable_chroot_double = 1;
24022 ++#endif
24023 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
24024 ++ grsec_enable_chroot_pivot = 1;
24025 ++#endif
24026 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
24027 ++ grsec_enable_chroot_chdir = 1;
24028 ++#endif
24029 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
24030 ++ grsec_enable_chroot_chmod = 1;
24031 ++#endif
24032 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
24033 ++ grsec_enable_chroot_mknod = 1;
24034 ++#endif
24035 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
24036 ++ grsec_enable_chroot_nice = 1;
24037 ++#endif
24038 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
24039 ++ grsec_enable_chroot_execlog = 1;
24040 ++#endif
24041 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
24042 ++ grsec_enable_chroot_caps = 1;
24043 ++#endif
24044 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
24045 ++ grsec_enable_chroot_sysctl = 1;
24046 ++#endif
24047 ++#ifdef CONFIG_GRKERNSEC_TPE
24048 ++ grsec_enable_tpe = 1;
24049 ++ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
24050 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
24051 ++ grsec_enable_tpe_all = 1;
24052 ++#endif
24053 ++#endif
24054 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24055 ++ grsec_enable_socket_all = 1;
24056 ++ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
24057 ++#endif
24058 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24059 ++ grsec_enable_socket_client = 1;
24060 ++ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
24061 ++#endif
24062 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24063 ++ grsec_enable_socket_server = 1;
24064 ++ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
24065 ++#endif
24066 ++#endif
24067 ++
24068 ++ return;
24069 ++}
24070 +diff -urNp linux-2.6.27.10/grsecurity/grsec_ipc.c linux-2.6.27.10/grsecurity/grsec_ipc.c
24071 +--- linux-2.6.27.10/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500
24072 ++++ linux-2.6.27.10/grsecurity/grsec_ipc.c 2008-11-18 03:38:45.000000000 -0500
24073 +@@ -0,0 +1,81 @@
24074 ++#include <linux/kernel.h>
24075 ++#include <linux/sched.h>
24076 ++#include <linux/types.h>
24077 ++#include <linux/ipc.h>
24078 ++#include <linux/grsecurity.h>
24079 ++#include <linux/grinternal.h>
24080 ++
24081 ++void
24082 ++gr_log_msgget(const int ret, const int msgflg)
24083 ++{
24084 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24085 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24086 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24087 ++ !grsec_enable_group)) && (ret >= 0)
24088 ++ && (msgflg & IPC_CREAT))
24089 ++ gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG);
24090 ++#endif
24091 ++ return;
24092 ++}
24093 ++
24094 ++void
24095 ++gr_log_msgrm(const uid_t uid, const uid_t cuid)
24096 ++{
24097 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24098 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24099 ++ grsec_enable_audit_ipc) ||
24100 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24101 ++ gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid);
24102 ++#endif
24103 ++ return;
24104 ++}
24105 ++
24106 ++void
24107 ++gr_log_semget(const int err, const int semflg)
24108 ++{
24109 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24110 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24111 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24112 ++ !grsec_enable_group)) && (err >= 0)
24113 ++ && (semflg & IPC_CREAT))
24114 ++ gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG);
24115 ++#endif
24116 ++ return;
24117 ++}
24118 ++
24119 ++void
24120 ++gr_log_semrm(const uid_t uid, const uid_t cuid)
24121 ++{
24122 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24123 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24124 ++ grsec_enable_audit_ipc) ||
24125 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24126 ++ gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid);
24127 ++#endif
24128 ++ return;
24129 ++}
24130 ++
24131 ++void
24132 ++gr_log_shmget(const int err, const int shmflg, const size_t size)
24133 ++{
24134 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24135 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24136 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24137 ++ !grsec_enable_group)) && (err >= 0)
24138 ++ && (shmflg & IPC_CREAT))
24139 ++ gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size);
24140 ++#endif
24141 ++ return;
24142 ++}
24143 ++
24144 ++void
24145 ++gr_log_shmrm(const uid_t uid, const uid_t cuid)
24146 ++{
24147 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24148 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24149 ++ grsec_enable_audit_ipc) ||
24150 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24151 ++ gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid);
24152 ++#endif
24153 ++ return;
24154 ++}
24155 +diff -urNp linux-2.6.27.10/grsecurity/grsec_link.c linux-2.6.27.10/grsecurity/grsec_link.c
24156 +--- linux-2.6.27.10/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
24157 ++++ linux-2.6.27.10/grsecurity/grsec_link.c 2008-11-18 03:38:45.000000000 -0500
24158 +@@ -0,0 +1,39 @@
24159 ++#include <linux/kernel.h>
24160 ++#include <linux/sched.h>
24161 ++#include <linux/fs.h>
24162 ++#include <linux/file.h>
24163 ++#include <linux/grinternal.h>
24164 ++
24165 ++int
24166 ++gr_handle_follow_link(const struct inode *parent,
24167 ++ const struct inode *inode,
24168 ++ const struct dentry *dentry, const struct vfsmount *mnt)
24169 ++{
24170 ++#ifdef CONFIG_GRKERNSEC_LINK
24171 ++ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
24172 ++ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
24173 ++ (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
24174 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
24175 ++ return -EACCES;
24176 ++ }
24177 ++#endif
24178 ++ return 0;
24179 ++}
24180 ++
24181 ++int
24182 ++gr_handle_hardlink(const struct dentry *dentry,
24183 ++ const struct vfsmount *mnt,
24184 ++ struct inode *inode, const int mode, const char *to)
24185 ++{
24186 ++#ifdef CONFIG_GRKERNSEC_LINK
24187 ++ if (grsec_enable_link && current->fsuid != inode->i_uid &&
24188 ++ (!S_ISREG(mode) || (mode & S_ISUID) ||
24189 ++ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
24190 ++ (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
24191 ++ !capable(CAP_FOWNER) && current->uid) {
24192 ++ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
24193 ++ return -EPERM;
24194 ++ }
24195 ++#endif
24196 ++ return 0;
24197 ++}
24198 +diff -urNp linux-2.6.27.10/grsecurity/grsec_log.c linux-2.6.27.10/grsecurity/grsec_log.c
24199 +--- linux-2.6.27.10/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
24200 ++++ linux-2.6.27.10/grsecurity/grsec_log.c 2008-11-18 03:38:45.000000000 -0500
24201 +@@ -0,0 +1,269 @@
24202 ++#include <linux/kernel.h>
24203 ++#include <linux/sched.h>
24204 ++#include <linux/file.h>
24205 ++#include <linux/tty.h>
24206 ++#include <linux/fs.h>
24207 ++#include <linux/grinternal.h>
24208 ++
24209 ++#define BEGIN_LOCKS(x) \
24210 ++ read_lock(&tasklist_lock); \
24211 ++ read_lock(&grsec_exec_file_lock); \
24212 ++ if (x != GR_DO_AUDIT) \
24213 ++ spin_lock(&grsec_alert_lock); \
24214 ++ else \
24215 ++ spin_lock(&grsec_audit_lock)
24216 ++
24217 ++#define END_LOCKS(x) \
24218 ++ if (x != GR_DO_AUDIT) \
24219 ++ spin_unlock(&grsec_alert_lock); \
24220 ++ else \
24221 ++ spin_unlock(&grsec_audit_lock); \
24222 ++ read_unlock(&grsec_exec_file_lock); \
24223 ++ read_unlock(&tasklist_lock); \
24224 ++ if (x == GR_DONT_AUDIT) \
24225 ++ gr_handle_alertkill(current)
24226 ++
24227 ++enum {
24228 ++ FLOODING,
24229 ++ NO_FLOODING
24230 ++};
24231 ++
24232 ++extern char *gr_alert_log_fmt;
24233 ++extern char *gr_audit_log_fmt;
24234 ++extern char *gr_alert_log_buf;
24235 ++extern char *gr_audit_log_buf;
24236 ++
24237 ++static int gr_log_start(int audit)
24238 ++{
24239 ++ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
24240 ++ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
24241 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24242 ++
24243 ++ if (audit == GR_DO_AUDIT)
24244 ++ goto set_fmt;
24245 ++
24246 ++ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
24247 ++ grsec_alert_wtime = jiffies;
24248 ++ grsec_alert_fyet = 0;
24249 ++ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
24250 ++ grsec_alert_fyet++;
24251 ++ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
24252 ++ grsec_alert_wtime = jiffies;
24253 ++ grsec_alert_fyet++;
24254 ++ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
24255 ++ return FLOODING;
24256 ++ } else return FLOODING;
24257 ++
24258 ++set_fmt:
24259 ++ memset(buf, 0, PAGE_SIZE);
24260 ++ if (current->signal->curr_ip && gr_acl_is_enabled()) {
24261 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
24262 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24263 ++ } else if (current->signal->curr_ip) {
24264 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
24265 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
24266 ++ } else if (gr_acl_is_enabled()) {
24267 ++ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
24268 ++ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24269 ++ } else {
24270 ++ sprintf(fmt, "%s%s", loglevel, "grsec: ");
24271 ++ strcpy(buf, fmt);
24272 ++ }
24273 ++
24274 ++ return NO_FLOODING;
24275 ++}
24276 ++
24277 ++static void gr_log_middle(int audit, const char *msg, va_list ap)
24278 ++{
24279 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24280 ++ unsigned int len = strlen(buf);
24281 ++
24282 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24283 ++
24284 ++ return;
24285 ++}
24286 ++
24287 ++static void gr_log_middle_varargs(int audit, const char *msg, ...)
24288 ++{
24289 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24290 ++ unsigned int len = strlen(buf);
24291 ++ va_list ap;
24292 ++
24293 ++ va_start(ap, msg);
24294 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24295 ++ va_end(ap);
24296 ++
24297 ++ return;
24298 ++}
24299 ++
24300 ++static void gr_log_end(int audit)
24301 ++{
24302 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24303 ++ unsigned int len = strlen(buf);
24304 ++
24305 ++ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current));
24306 ++ printk("%s\n", buf);
24307 ++
24308 ++ return;
24309 ++}
24310 ++
24311 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
24312 ++{
24313 ++ int logtype;
24314 ++ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
24315 ++ char *str1, *str2, *str3;
24316 ++ int num1, num2;
24317 ++ unsigned long ulong1, ulong2;
24318 ++ struct dentry *dentry;
24319 ++ struct vfsmount *mnt;
24320 ++ struct file *file;
24321 ++ struct task_struct *task;
24322 ++ va_list ap;
24323 ++
24324 ++ BEGIN_LOCKS(audit);
24325 ++ logtype = gr_log_start(audit);
24326 ++ if (logtype == FLOODING) {
24327 ++ END_LOCKS(audit);
24328 ++ return;
24329 ++ }
24330 ++ va_start(ap, argtypes);
24331 ++ switch (argtypes) {
24332 ++ case GR_TTYSNIFF:
24333 ++ task = va_arg(ap, struct task_struct *);
24334 ++ 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);
24335 ++ break;
24336 ++ case GR_SYSCTL_HIDDEN:
24337 ++ str1 = va_arg(ap, char *);
24338 ++ gr_log_middle_varargs(audit, msg, result, str1);
24339 ++ break;
24340 ++ case GR_RBAC:
24341 ++ dentry = va_arg(ap, struct dentry *);
24342 ++ mnt = va_arg(ap, struct vfsmount *);
24343 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
24344 ++ break;
24345 ++ case GR_RBAC_STR:
24346 ++ dentry = va_arg(ap, struct dentry *);
24347 ++ mnt = va_arg(ap, struct vfsmount *);
24348 ++ str1 = va_arg(ap, char *);
24349 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
24350 ++ break;
24351 ++ case GR_STR_RBAC:
24352 ++ str1 = va_arg(ap, char *);
24353 ++ dentry = va_arg(ap, struct dentry *);
24354 ++ mnt = va_arg(ap, struct vfsmount *);
24355 ++ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
24356 ++ break;
24357 ++ case GR_RBAC_MODE2:
24358 ++ dentry = va_arg(ap, struct dentry *);
24359 ++ mnt = va_arg(ap, struct vfsmount *);
24360 ++ str1 = va_arg(ap, char *);
24361 ++ str2 = va_arg(ap, char *);
24362 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
24363 ++ break;
24364 ++ case GR_RBAC_MODE3:
24365 ++ dentry = va_arg(ap, struct dentry *);
24366 ++ mnt = va_arg(ap, struct vfsmount *);
24367 ++ str1 = va_arg(ap, char *);
24368 ++ str2 = va_arg(ap, char *);
24369 ++ str3 = va_arg(ap, char *);
24370 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
24371 ++ break;
24372 ++ case GR_FILENAME:
24373 ++ dentry = va_arg(ap, struct dentry *);
24374 ++ mnt = va_arg(ap, struct vfsmount *);
24375 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
24376 ++ break;
24377 ++ case GR_STR_FILENAME:
24378 ++ str1 = va_arg(ap, char *);
24379 ++ dentry = va_arg(ap, struct dentry *);
24380 ++ mnt = va_arg(ap, struct vfsmount *);
24381 ++ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
24382 ++ break;
24383 ++ case GR_FILENAME_STR:
24384 ++ dentry = va_arg(ap, struct dentry *);
24385 ++ mnt = va_arg(ap, struct vfsmount *);
24386 ++ str1 = va_arg(ap, char *);
24387 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
24388 ++ break;
24389 ++ case GR_FILENAME_TWO_INT:
24390 ++ dentry = va_arg(ap, struct dentry *);
24391 ++ mnt = va_arg(ap, struct vfsmount *);
24392 ++ num1 = va_arg(ap, int);
24393 ++ num2 = va_arg(ap, int);
24394 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
24395 ++ break;
24396 ++ case GR_FILENAME_TWO_INT_STR:
24397 ++ dentry = va_arg(ap, struct dentry *);
24398 ++ mnt = va_arg(ap, struct vfsmount *);
24399 ++ num1 = va_arg(ap, int);
24400 ++ num2 = va_arg(ap, int);
24401 ++ str1 = va_arg(ap, char *);
24402 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
24403 ++ break;
24404 ++ case GR_TEXTREL:
24405 ++ file = va_arg(ap, struct file *);
24406 ++ ulong1 = va_arg(ap, unsigned long);
24407 ++ ulong2 = va_arg(ap, unsigned long);
24408 ++ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
24409 ++ break;
24410 ++ case GR_PTRACE:
24411 ++ task = va_arg(ap, struct task_struct *);
24412 ++ 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);
24413 ++ break;
24414 ++ case GR_RESOURCE:
24415 ++ task = va_arg(ap, struct task_struct *);
24416 ++ ulong1 = va_arg(ap, unsigned long);
24417 ++ str1 = va_arg(ap, char *);
24418 ++ ulong2 = va_arg(ap, unsigned long);
24419 ++ 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);
24420 ++ break;
24421 ++ case GR_CAP:
24422 ++ task = va_arg(ap, struct task_struct *);
24423 ++ str1 = va_arg(ap, char *);
24424 ++ 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);
24425 ++ break;
24426 ++ case GR_SIG:
24427 ++ task = va_arg(ap, struct task_struct *);
24428 ++ num1 = va_arg(ap, int);
24429 ++ 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);
24430 ++ break;
24431 ++ case GR_CRASH1:
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, task->uid, ulong1);
24435 ++ break;
24436 ++ case GR_CRASH2:
24437 ++ task = va_arg(ap, struct task_struct *);
24438 ++ ulong1 = va_arg(ap, unsigned long);
24439 ++ 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);
24440 ++ break;
24441 ++ case GR_PSACCT:
24442 ++ {
24443 ++ unsigned int wday, cday;
24444 ++ __u8 whr, chr;
24445 ++ __u8 wmin, cmin;
24446 ++ __u8 wsec, csec;
24447 ++ char cur_tty[64] = { 0 };
24448 ++ char parent_tty[64] = { 0 };
24449 ++
24450 ++ task = va_arg(ap, struct task_struct *);
24451 ++ wday = va_arg(ap, unsigned int);
24452 ++ cday = va_arg(ap, unsigned int);
24453 ++ whr = va_arg(ap, int);
24454 ++ chr = va_arg(ap, int);
24455 ++ wmin = va_arg(ap, int);
24456 ++ cmin = va_arg(ap, int);
24457 ++ wsec = va_arg(ap, int);
24458 ++ csec = va_arg(ap, int);
24459 ++ ulong1 = va_arg(ap, unsigned long);
24460 ++
24461 ++ 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);
24462 ++ }
24463 ++ break;
24464 ++ default:
24465 ++ gr_log_middle(audit, msg, ap);
24466 ++ }
24467 ++ va_end(ap);
24468 ++ gr_log_end(audit);
24469 ++ END_LOCKS(audit);
24470 ++}
24471 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mem.c linux-2.6.27.10/grsecurity/grsec_mem.c
24472 +--- linux-2.6.27.10/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
24473 ++++ linux-2.6.27.10/grsecurity/grsec_mem.c 2008-11-18 03:38:45.000000000 -0500
24474 +@@ -0,0 +1,71 @@
24475 ++#include <linux/kernel.h>
24476 ++#include <linux/sched.h>
24477 ++#include <linux/mm.h>
24478 ++#include <linux/mman.h>
24479 ++#include <linux/grinternal.h>
24480 ++
24481 ++void
24482 ++gr_handle_ioperm(void)
24483 ++{
24484 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
24485 ++ return;
24486 ++}
24487 ++
24488 ++void
24489 ++gr_handle_iopl(void)
24490 ++{
24491 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
24492 ++ return;
24493 ++}
24494 ++
24495 ++void
24496 ++gr_handle_mem_write(void)
24497 ++{
24498 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
24499 ++ return;
24500 ++}
24501 ++
24502 ++void
24503 ++gr_handle_kmem_write(void)
24504 ++{
24505 ++ gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
24506 ++ return;
24507 ++}
24508 ++
24509 ++void
24510 ++gr_handle_open_port(void)
24511 ++{
24512 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
24513 ++ return;
24514 ++}
24515 ++
24516 ++int
24517 ++gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
24518 ++{
24519 ++ unsigned long start, end;
24520 ++
24521 ++ start = offset;
24522 ++ end = start + vma->vm_end - vma->vm_start;
24523 ++
24524 ++ if (start > end) {
24525 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24526 ++ return -EPERM;
24527 ++ }
24528 ++
24529 ++ /* allowed ranges : ISA I/O BIOS */
24530 ++ if ((start >= __pa(high_memory))
24531 ++#ifdef CONFIG_X86
24532 ++ || (start >= 0x000a0000 && end <= 0x00100000)
24533 ++ || (start >= 0x00000000 && end <= 0x00001000)
24534 ++#endif
24535 ++ )
24536 ++ return 0;
24537 ++
24538 ++ if (vma->vm_flags & VM_WRITE) {
24539 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24540 ++ return -EPERM;
24541 ++ } else
24542 ++ vma->vm_flags &= ~VM_MAYWRITE;
24543 ++
24544 ++ return 0;
24545 ++}
24546 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mount.c linux-2.6.27.10/grsecurity/grsec_mount.c
24547 +--- linux-2.6.27.10/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
24548 ++++ linux-2.6.27.10/grsecurity/grsec_mount.c 2008-11-18 03:38:45.000000000 -0500
24549 +@@ -0,0 +1,34 @@
24550 ++#include <linux/kernel.h>
24551 ++#include <linux/sched.h>
24552 ++#include <linux/grsecurity.h>
24553 ++#include <linux/grinternal.h>
24554 ++
24555 ++void
24556 ++gr_log_remount(const char *devname, const int retval)
24557 ++{
24558 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24559 ++ if (grsec_enable_mount && (retval >= 0))
24560 ++ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
24561 ++#endif
24562 ++ return;
24563 ++}
24564 ++
24565 ++void
24566 ++gr_log_unmount(const char *devname, const int retval)
24567 ++{
24568 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24569 ++ if (grsec_enable_mount && (retval >= 0))
24570 ++ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
24571 ++#endif
24572 ++ return;
24573 ++}
24574 ++
24575 ++void
24576 ++gr_log_mount(const char *from, const char *to, const int retval)
24577 ++{
24578 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24579 ++ if (grsec_enable_mount && (retval >= 0))
24580 ++ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
24581 ++#endif
24582 ++ return;
24583 ++}
24584 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sig.c linux-2.6.27.10/grsecurity/grsec_sig.c
24585 +--- linux-2.6.27.10/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
24586 ++++ linux-2.6.27.10/grsecurity/grsec_sig.c 2008-11-18 03:38:45.000000000 -0500
24587 +@@ -0,0 +1,58 @@
24588 ++#include <linux/kernel.h>
24589 ++#include <linux/sched.h>
24590 ++#include <linux/delay.h>
24591 ++#include <linux/grsecurity.h>
24592 ++#include <linux/grinternal.h>
24593 ++
24594 ++void
24595 ++gr_log_signal(const int sig, const struct task_struct *t)
24596 ++{
24597 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
24598 ++ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
24599 ++ (sig == SIGABRT) || (sig == SIGBUS))) {
24600 ++ if (t->pid == current->pid) {
24601 ++ gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig);
24602 ++ } else {
24603 ++ gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
24604 ++ }
24605 ++ }
24606 ++#endif
24607 ++ return;
24608 ++}
24609 ++
24610 ++int
24611 ++gr_handle_signal(const struct task_struct *p, const int sig)
24612 ++{
24613 ++#ifdef CONFIG_GRKERNSEC
24614 ++ if (current->pid > 1 && gr_check_protected_task(p)) {
24615 ++ gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
24616 ++ return -EPERM;
24617 ++ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
24618 ++ return -EPERM;
24619 ++ }
24620 ++#endif
24621 ++ return 0;
24622 ++}
24623 ++
24624 ++void gr_handle_brute_attach(struct task_struct *p)
24625 ++{
24626 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24627 ++ read_lock(&tasklist_lock);
24628 ++ read_lock(&grsec_exec_file_lock);
24629 ++ if (p->parent && p->parent->exec_file == p->exec_file)
24630 ++ p->parent->brute = 1;
24631 ++ read_unlock(&grsec_exec_file_lock);
24632 ++ read_unlock(&tasklist_lock);
24633 ++#endif
24634 ++ return;
24635 ++}
24636 ++
24637 ++void gr_handle_brute_check(void)
24638 ++{
24639 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24640 ++ if (current->brute)
24641 ++ msleep(30 * 1000);
24642 ++#endif
24643 ++ return;
24644 ++}
24645 ++
24646 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sock.c linux-2.6.27.10/grsecurity/grsec_sock.c
24647 +--- linux-2.6.27.10/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
24648 ++++ linux-2.6.27.10/grsecurity/grsec_sock.c 2008-11-18 11:35:13.000000000 -0500
24649 +@@ -0,0 +1,274 @@
24650 ++#include <linux/kernel.h>
24651 ++#include <linux/module.h>
24652 ++#include <linux/sched.h>
24653 ++#include <linux/file.h>
24654 ++#include <linux/net.h>
24655 ++#include <linux/in.h>
24656 ++#include <linux/ip.h>
24657 ++#include <net/sock.h>
24658 ++#include <net/inet_sock.h>
24659 ++#include <linux/grsecurity.h>
24660 ++#include <linux/grinternal.h>
24661 ++#include <linux/gracl.h>
24662 ++
24663 ++#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
24664 ++extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
24665 ++EXPORT_SYMBOL(udp_v4_lookup);
24666 ++#endif
24667 ++
24668 ++kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
24669 ++EXPORT_SYMBOL(gr_cap_rtnetlink);
24670 ++
24671 ++extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
24672 ++extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
24673 ++
24674 ++EXPORT_SYMBOL(gr_search_udp_recvmsg);
24675 ++EXPORT_SYMBOL(gr_search_udp_sendmsg);
24676 ++
24677 ++#ifdef CONFIG_UNIX_MODULE
24678 ++EXPORT_SYMBOL(gr_acl_handle_unix);
24679 ++EXPORT_SYMBOL(gr_acl_handle_mknod);
24680 ++EXPORT_SYMBOL(gr_handle_chroot_unix);
24681 ++EXPORT_SYMBOL(gr_handle_create);
24682 ++#endif
24683 ++
24684 ++#ifdef CONFIG_GRKERNSEC
24685 ++#define gr_conn_table_size 32749
24686 ++struct conn_table_entry {
24687 ++ struct conn_table_entry *next;
24688 ++ struct signal_struct *sig;
24689 ++};
24690 ++
24691 ++struct conn_table_entry *gr_conn_table[gr_conn_table_size];
24692 ++DEFINE_SPINLOCK(gr_conn_table_lock);
24693 ++
24694 ++extern const char * gr_socktype_to_name(unsigned char type);
24695 ++extern const char * gr_proto_to_name(unsigned char proto);
24696 ++
24697 ++static __inline__ int
24698 ++conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
24699 ++{
24700 ++ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
24701 ++}
24702 ++
24703 ++static __inline__ int
24704 ++conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
24705 ++ __u16 sport, __u16 dport)
24706 ++{
24707 ++ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
24708 ++ sig->gr_sport == sport && sig->gr_dport == dport))
24709 ++ return 1;
24710 ++ else
24711 ++ return 0;
24712 ++}
24713 ++
24714 ++static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
24715 ++{
24716 ++ struct conn_table_entry **match;
24717 ++ unsigned int index;
24718 ++
24719 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24720 ++ sig->gr_sport, sig->gr_dport,
24721 ++ gr_conn_table_size);
24722 ++
24723 ++ newent->sig = sig;
24724 ++
24725 ++ match = &gr_conn_table[index];
24726 ++ newent->next = *match;
24727 ++ *match = newent;
24728 ++
24729 ++ return;
24730 ++}
24731 ++
24732 ++static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
24733 ++{
24734 ++ struct conn_table_entry *match, *last = NULL;
24735 ++ unsigned int index;
24736 ++
24737 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24738 ++ sig->gr_sport, sig->gr_dport,
24739 ++ gr_conn_table_size);
24740 ++
24741 ++ match = gr_conn_table[index];
24742 ++ while (match && !conn_match(match->sig,
24743 ++ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
24744 ++ sig->gr_dport)) {
24745 ++ last = match;
24746 ++ match = match->next;
24747 ++ }
24748 ++
24749 ++ if (match) {
24750 ++ if (last)
24751 ++ last->next = match->next;
24752 ++ else
24753 ++ gr_conn_table[index] = NULL;
24754 ++ kfree(match);
24755 ++ }
24756 ++
24757 ++ return;
24758 ++}
24759 ++
24760 ++static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
24761 ++ __u16 sport, __u16 dport)
24762 ++{
24763 ++ struct conn_table_entry *match;
24764 ++ unsigned int index;
24765 ++
24766 ++ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
24767 ++
24768 ++ match = gr_conn_table[index];
24769 ++ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
24770 ++ match = match->next;
24771 ++
24772 ++ if (match)
24773 ++ return match->sig;
24774 ++ else
24775 ++ return NULL;
24776 ++}
24777 ++
24778 ++#endif
24779 ++
24780 ++void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
24781 ++{
24782 ++#ifdef CONFIG_GRKERNSEC
24783 ++ struct signal_struct *sig = task->signal;
24784 ++ struct conn_table_entry *newent;
24785 ++
24786 ++ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
24787 ++ if (newent == NULL)
24788 ++ return;
24789 ++ /* no bh lock needed since we are called with bh disabled */
24790 ++ spin_lock(&gr_conn_table_lock);
24791 ++ gr_del_task_from_ip_table_nolock(sig);
24792 ++ sig->gr_saddr = inet->rcv_saddr;
24793 ++ sig->gr_daddr = inet->daddr;
24794 ++ sig->gr_sport = inet->sport;
24795 ++ sig->gr_dport = inet->dport;
24796 ++ gr_add_to_task_ip_table_nolock(sig, newent);
24797 ++ spin_unlock(&gr_conn_table_lock);
24798 ++#endif
24799 ++ return;
24800 ++}
24801 ++
24802 ++void gr_del_task_from_ip_table(struct task_struct *task)
24803 ++{
24804 ++#ifdef CONFIG_GRKERNSEC
24805 ++ spin_lock_bh(&gr_conn_table_lock);
24806 ++ gr_del_task_from_ip_table_nolock(task->signal);
24807 ++ spin_unlock_bh(&gr_conn_table_lock);
24808 ++#endif
24809 ++ return;
24810 ++}
24811 ++
24812 ++void
24813 ++gr_attach_curr_ip(const struct sock *sk)
24814 ++{
24815 ++#ifdef CONFIG_GRKERNSEC
24816 ++ struct signal_struct *p, *set;
24817 ++ const struct inet_sock *inet = inet_sk(sk);
24818 ++
24819 ++ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
24820 ++ return;
24821 ++
24822 ++ set = current->signal;
24823 ++
24824 ++ spin_lock_bh(&gr_conn_table_lock);
24825 ++ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
24826 ++ inet->dport, inet->sport);
24827 ++ if (unlikely(p != NULL)) {
24828 ++ set->curr_ip = p->curr_ip;
24829 ++ set->used_accept = 1;
24830 ++ gr_del_task_from_ip_table_nolock(p);
24831 ++ spin_unlock_bh(&gr_conn_table_lock);
24832 ++ return;
24833 ++ }
24834 ++ spin_unlock_bh(&gr_conn_table_lock);
24835 ++
24836 ++ set->curr_ip = inet->daddr;
24837 ++ set->used_accept = 1;
24838 ++#endif
24839 ++ return;
24840 ++}
24841 ++
24842 ++int
24843 ++gr_handle_sock_all(const int family, const int type, const int protocol)
24844 ++{
24845 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24846 ++ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
24847 ++ (family != AF_UNIX) && (family != AF_LOCAL)) {
24848 ++ gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol));
24849 ++ return -EACCES;
24850 ++ }
24851 ++#endif
24852 ++ return 0;
24853 ++}
24854 ++
24855 ++int
24856 ++gr_handle_sock_server(const struct sockaddr *sck)
24857 ++{
24858 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24859 ++ if (grsec_enable_socket_server &&
24860 ++ in_group_p(grsec_socket_server_gid) &&
24861 ++ sck && (sck->sa_family != AF_UNIX) &&
24862 ++ (sck->sa_family != AF_LOCAL)) {
24863 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24864 ++ return -EACCES;
24865 ++ }
24866 ++#endif
24867 ++ return 0;
24868 ++}
24869 ++
24870 ++int
24871 ++gr_handle_sock_server_other(const struct sock *sck)
24872 ++{
24873 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24874 ++ if (grsec_enable_socket_server &&
24875 ++ in_group_p(grsec_socket_server_gid) &&
24876 ++ sck && (sck->sk_family != AF_UNIX) &&
24877 ++ (sck->sk_family != AF_LOCAL)) {
24878 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24879 ++ return -EACCES;
24880 ++ }
24881 ++#endif
24882 ++ return 0;
24883 ++}
24884 ++
24885 ++int
24886 ++gr_handle_sock_client(const struct sockaddr *sck)
24887 ++{
24888 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24889 ++ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
24890 ++ sck && (sck->sa_family != AF_UNIX) &&
24891 ++ (sck->sa_family != AF_LOCAL)) {
24892 ++ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
24893 ++ return -EACCES;
24894 ++ }
24895 ++#endif
24896 ++ return 0;
24897 ++}
24898 ++
24899 ++kernel_cap_t
24900 ++gr_cap_rtnetlink(struct sock *sock)
24901 ++{
24902 ++#ifdef CONFIG_GRKERNSEC
24903 ++ if (!gr_acl_is_enabled())
24904 ++ return current->cap_effective;
24905 ++ else if (sock->sk_protocol == NETLINK_ISCSI &&
24906 ++ cap_raised(current->cap_effective, CAP_SYS_ADMIN) &&
24907 ++ gr_task_is_capable(current, CAP_SYS_ADMIN))
24908 ++ return current->cap_effective;
24909 ++ else if (sock->sk_protocol == NETLINK_AUDIT &&
24910 ++ cap_raised(current->cap_effective, CAP_AUDIT_WRITE) &&
24911 ++ gr_task_is_capable(current, CAP_AUDIT_WRITE) &&
24912 ++ cap_raised(current->cap_effective, CAP_AUDIT_CONTROL) &&
24913 ++ gr_task_is_capable(current, CAP_AUDIT_CONTROL))
24914 ++ return current->cap_effective;
24915 ++ else if (cap_raised(current->cap_effective, CAP_NET_ADMIN) &&
24916 ++ gr_task_is_capable(current, CAP_NET_ADMIN))
24917 ++ return current->cap_effective;
24918 ++ else
24919 ++ return __cap_empty_set;
24920 ++#else
24921 ++ return current->cap_effective;
24922 ++#endif
24923 ++}
24924 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sysctl.c linux-2.6.27.10/grsecurity/grsec_sysctl.c
24925 +--- linux-2.6.27.10/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
24926 ++++ linux-2.6.27.10/grsecurity/grsec_sysctl.c 2008-11-18 03:38:45.000000000 -0500
24927 +@@ -0,0 +1,435 @@
24928 ++#include <linux/kernel.h>
24929 ++#include <linux/sched.h>
24930 ++#include <linux/sysctl.h>
24931 ++#include <linux/grsecurity.h>
24932 ++#include <linux/grinternal.h>
24933 ++
24934 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
24935 ++int grsec_modstop;
24936 ++#endif
24937 ++
24938 ++int
24939 ++gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
24940 ++{
24941 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
24942 ++ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
24943 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
24944 ++ return -EACCES;
24945 ++ }
24946 ++#endif
24947 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
24948 ++ if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") &&
24949 ++ grsec_modstop && (op & MAY_WRITE)) {
24950 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
24951 ++ return -EACCES;
24952 ++ }
24953 ++#endif
24954 ++ return 0;
24955 ++}
24956 ++
24957 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
24958 ++ctl_table grsecurity_table[] = {
24959 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
24960 ++#ifdef CONFIG_GRKERNSEC_LINK
24961 ++ {
24962 ++ .ctl_name = CTL_UNNUMBERED,
24963 ++ .procname = "linking_restrictions",
24964 ++ .data = &grsec_enable_link,
24965 ++ .maxlen = sizeof(int),
24966 ++ .mode = 0600,
24967 ++ .proc_handler = &proc_dointvec,
24968 ++ },
24969 ++#endif
24970 ++#ifdef CONFIG_GRKERNSEC_FIFO
24971 ++ {
24972 ++ .ctl_name = CTL_UNNUMBERED,
24973 ++ .procname = "fifo_restrictions",
24974 ++ .data = &grsec_enable_fifo,
24975 ++ .maxlen = sizeof(int),
24976 ++ .mode = 0600,
24977 ++ .proc_handler = &proc_dointvec,
24978 ++ },
24979 ++#endif
24980 ++#ifdef CONFIG_GRKERNSEC_EXECVE
24981 ++ {
24982 ++ .ctl_name = CTL_UNNUMBERED,
24983 ++ .procname = "execve_limiting",
24984 ++ .data = &grsec_enable_execve,
24985 ++ .maxlen = sizeof(int),
24986 ++ .mode = 0600,
24987 ++ .proc_handler = &proc_dointvec,
24988 ++ },
24989 ++#endif
24990 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
24991 ++ {
24992 ++ .ctl_name = CTL_UNNUMBERED,
24993 ++ .procname = "exec_logging",
24994 ++ .data = &grsec_enable_execlog,
24995 ++ .maxlen = sizeof(int),
24996 ++ .mode = 0600,
24997 ++ .proc_handler = &proc_dointvec,
24998 ++ },
24999 ++#endif
25000 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
25001 ++ {
25002 ++ .ctl_name = CTL_UNNUMBERED,
25003 ++ .procname = "signal_logging",
25004 ++ .data = &grsec_enable_signal,
25005 ++ .maxlen = sizeof(int),
25006 ++ .mode = 0600,
25007 ++ .proc_handler = &proc_dointvec,
25008 ++ },
25009 ++#endif
25010 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
25011 ++ {
25012 ++ .ctl_name = CTL_UNNUMBERED,
25013 ++ .procname = "forkfail_logging",
25014 ++ .data = &grsec_enable_forkfail,
25015 ++ .maxlen = sizeof(int),
25016 ++ .mode = 0600,
25017 ++ .proc_handler = &proc_dointvec,
25018 ++ },
25019 ++#endif
25020 ++#ifdef CONFIG_GRKERNSEC_TIME
25021 ++ {
25022 ++ .ctl_name = CTL_UNNUMBERED,
25023 ++ .procname = "timechange_logging",
25024 ++ .data = &grsec_enable_time,
25025 ++ .maxlen = sizeof(int),
25026 ++ .mode = 0600,
25027 ++ .proc_handler = &proc_dointvec,
25028 ++ },
25029 ++#endif
25030 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
25031 ++ {
25032 ++ .ctl_name = CTL_UNNUMBERED,
25033 ++ .procname = "chroot_deny_shmat",
25034 ++ .data = &grsec_enable_chroot_shmat,
25035 ++ .maxlen = sizeof(int),
25036 ++ .mode = 0600,
25037 ++ .proc_handler = &proc_dointvec,
25038 ++ },
25039 ++#endif
25040 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
25041 ++ {
25042 ++ .ctl_name = CTL_UNNUMBERED,
25043 ++ .procname = "chroot_deny_unix",
25044 ++ .data = &grsec_enable_chroot_unix,
25045 ++ .maxlen = sizeof(int),
25046 ++ .mode = 0600,
25047 ++ .proc_handler = &proc_dointvec,
25048 ++ },
25049 ++#endif
25050 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
25051 ++ {
25052 ++ .ctl_name = CTL_UNNUMBERED,
25053 ++ .procname = "chroot_deny_mount",
25054 ++ .data = &grsec_enable_chroot_mount,
25055 ++ .maxlen = sizeof(int),
25056 ++ .mode = 0600,
25057 ++ .proc_handler = &proc_dointvec,
25058 ++ },
25059 ++#endif
25060 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
25061 ++ {
25062 ++ .ctl_name = CTL_UNNUMBERED,
25063 ++ .procname = "chroot_deny_fchdir",
25064 ++ .data = &grsec_enable_chroot_fchdir,
25065 ++ .maxlen = sizeof(int),
25066 ++ .mode = 0600,
25067 ++ .proc_handler = &proc_dointvec,
25068 ++ },
25069 ++#endif
25070 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
25071 ++ {
25072 ++ .ctl_name = CTL_UNNUMBERED,
25073 ++ .procname = "chroot_deny_chroot",
25074 ++ .data = &grsec_enable_chroot_double,
25075 ++ .maxlen = sizeof(int),
25076 ++ .mode = 0600,
25077 ++ .proc_handler = &proc_dointvec,
25078 ++ },
25079 ++#endif
25080 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
25081 ++ {
25082 ++ .ctl_name = CTL_UNNUMBERED,
25083 ++ .procname = "chroot_deny_pivot",
25084 ++ .data = &grsec_enable_chroot_pivot,
25085 ++ .maxlen = sizeof(int),
25086 ++ .mode = 0600,
25087 ++ .proc_handler = &proc_dointvec,
25088 ++ },
25089 ++#endif
25090 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
25091 ++ {
25092 ++ .ctl_name = CTL_UNNUMBERED,
25093 ++ .procname = "chroot_enforce_chdir",
25094 ++ .data = &grsec_enable_chroot_chdir,
25095 ++ .maxlen = sizeof(int),
25096 ++ .mode = 0600,
25097 ++ .proc_handler = &proc_dointvec,
25098 ++ },
25099 ++#endif
25100 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
25101 ++ {
25102 ++ .ctl_name = CTL_UNNUMBERED,
25103 ++ .procname = "chroot_deny_chmod",
25104 ++ .data = &grsec_enable_chroot_chmod,
25105 ++ .maxlen = sizeof(int),
25106 ++ .mode = 0600,
25107 ++ .proc_handler = &proc_dointvec,
25108 ++ },
25109 ++#endif
25110 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
25111 ++ {
25112 ++ .ctl_name = CTL_UNNUMBERED,
25113 ++ .procname = "chroot_deny_mknod",
25114 ++ .data = &grsec_enable_chroot_mknod,
25115 ++ .maxlen = sizeof(int),
25116 ++ .mode = 0600,
25117 ++ .proc_handler = &proc_dointvec,
25118 ++ },
25119 ++#endif
25120 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
25121 ++ {
25122 ++ .ctl_name = CTL_UNNUMBERED,
25123 ++ .procname = "chroot_restrict_nice",
25124 ++ .data = &grsec_enable_chroot_nice,
25125 ++ .maxlen = sizeof(int),
25126 ++ .mode = 0600,
25127 ++ .proc_handler = &proc_dointvec,
25128 ++ },
25129 ++#endif
25130 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
25131 ++ {
25132 ++ .ctl_name = CTL_UNNUMBERED,
25133 ++ .procname = "chroot_execlog",
25134 ++ .data = &grsec_enable_chroot_execlog,
25135 ++ .maxlen = sizeof(int),
25136 ++ .mode = 0600,
25137 ++ .proc_handler = &proc_dointvec,
25138 ++ },
25139 ++#endif
25140 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
25141 ++ {
25142 ++ .ctl_name = CTL_UNNUMBERED,
25143 ++ .procname = "chroot_caps",
25144 ++ .data = &grsec_enable_chroot_caps,
25145 ++ .maxlen = sizeof(int),
25146 ++ .mode = 0600,
25147 ++ .proc_handler = &proc_dointvec,
25148 ++ },
25149 ++#endif
25150 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
25151 ++ {
25152 ++ .ctl_name = CTL_UNNUMBERED,
25153 ++ .procname = "chroot_deny_sysctl",
25154 ++ .data = &grsec_enable_chroot_sysctl,
25155 ++ .maxlen = sizeof(int),
25156 ++ .mode = 0600,
25157 ++ .proc_handler = &proc_dointvec,
25158 ++ },
25159 ++#endif
25160 ++#ifdef CONFIG_GRKERNSEC_TPE
25161 ++ {
25162 ++ .ctl_name = CTL_UNNUMBERED,
25163 ++ .procname = "tpe",
25164 ++ .data = &grsec_enable_tpe,
25165 ++ .maxlen = sizeof(int),
25166 ++ .mode = 0600,
25167 ++ .proc_handler = &proc_dointvec,
25168 ++ },
25169 ++ {
25170 ++ .ctl_name = CTL_UNNUMBERED,
25171 ++ .procname = "tpe_gid",
25172 ++ .data = &grsec_tpe_gid,
25173 ++ .maxlen = sizeof(int),
25174 ++ .mode = 0600,
25175 ++ .proc_handler = &proc_dointvec,
25176 ++ },
25177 ++#endif
25178 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25179 ++ {
25180 ++ .ctl_name = CTL_UNNUMBERED,
25181 ++ .procname = "tpe_restrict_all",
25182 ++ .data = &grsec_enable_tpe_all,
25183 ++ .maxlen = sizeof(int),
25184 ++ .mode = 0600,
25185 ++ .proc_handler = &proc_dointvec,
25186 ++ },
25187 ++#endif
25188 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
25189 ++ {
25190 ++ .ctl_name = CTL_UNNUMBERED,
25191 ++ .procname = "socket_all",
25192 ++ .data = &grsec_enable_socket_all,
25193 ++ .maxlen = sizeof(int),
25194 ++ .mode = 0600,
25195 ++ .proc_handler = &proc_dointvec,
25196 ++ },
25197 ++ {
25198 ++ .ctl_name = CTL_UNNUMBERED,
25199 ++ .procname = "socket_all_gid",
25200 ++ .data = &grsec_socket_all_gid,
25201 ++ .maxlen = sizeof(int),
25202 ++ .mode = 0600,
25203 ++ .proc_handler = &proc_dointvec,
25204 ++ },
25205 ++#endif
25206 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
25207 ++ {
25208 ++ .ctl_name = CTL_UNNUMBERED,
25209 ++ .procname = "socket_client",
25210 ++ .data = &grsec_enable_socket_client,
25211 ++ .maxlen = sizeof(int),
25212 ++ .mode = 0600,
25213 ++ .proc_handler = &proc_dointvec,
25214 ++ },
25215 ++ {
25216 ++ .ctl_name = CTL_UNNUMBERED,
25217 ++ .procname = "socket_client_gid",
25218 ++ .data = &grsec_socket_client_gid,
25219 ++ .maxlen = sizeof(int),
25220 ++ .mode = 0600,
25221 ++ .proc_handler = &proc_dointvec,
25222 ++ },
25223 ++#endif
25224 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
25225 ++ {
25226 ++ .ctl_name = CTL_UNNUMBERED,
25227 ++ .procname = "socket_server",
25228 ++ .data = &grsec_enable_socket_server,
25229 ++ .maxlen = sizeof(int),
25230 ++ .mode = 0600,
25231 ++ .proc_handler = &proc_dointvec,
25232 ++ },
25233 ++ {
25234 ++ .ctl_name = CTL_UNNUMBERED,
25235 ++ .procname = "socket_server_gid",
25236 ++ .data = &grsec_socket_server_gid,
25237 ++ .maxlen = sizeof(int),
25238 ++ .mode = 0600,
25239 ++ .proc_handler = &proc_dointvec,
25240 ++ },
25241 ++#endif
25242 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
25243 ++ {
25244 ++ .ctl_name = CTL_UNNUMBERED,
25245 ++ .procname = "audit_group",
25246 ++ .data = &grsec_enable_group,
25247 ++ .maxlen = sizeof(int),
25248 ++ .mode = 0600,
25249 ++ .proc_handler = &proc_dointvec,
25250 ++ },
25251 ++ {
25252 ++ .ctl_name = CTL_UNNUMBERED,
25253 ++ .procname = "audit_gid",
25254 ++ .data = &grsec_audit_gid,
25255 ++ .maxlen = sizeof(int),
25256 ++ .mode = 0600,
25257 ++ .proc_handler = &proc_dointvec,
25258 ++ },
25259 ++#endif
25260 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
25261 ++ {
25262 ++ .ctl_name = CTL_UNNUMBERED,
25263 ++ .procname = "audit_chdir",
25264 ++ .data = &grsec_enable_chdir,
25265 ++ .maxlen = sizeof(int),
25266 ++ .mode = 0600,
25267 ++ .proc_handler = &proc_dointvec,
25268 ++ },
25269 ++#endif
25270 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
25271 ++ {
25272 ++ .ctl_name = CTL_UNNUMBERED,
25273 ++ .procname = "audit_mount",
25274 ++ .data = &grsec_enable_mount,
25275 ++ .maxlen = sizeof(int),
25276 ++ .mode = 0600,
25277 ++ .proc_handler = &proc_dointvec,
25278 ++ },
25279 ++#endif
25280 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25281 ++ {
25282 ++ .ctl_name = CTL_UNNUMBERED,
25283 ++ .procname = "audit_ipc",
25284 ++ .data = &grsec_enable_audit_ipc,
25285 ++ .maxlen = sizeof(int),
25286 ++ .mode = 0600,
25287 ++ .proc_handler = &proc_dointvec,
25288 ++ },
25289 ++#endif
25290 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25291 ++ {
25292 ++ .ctl_name = CTL_UNNUMBERED,
25293 ++ .procname = "audit_textrel",
25294 ++ .data = &grsec_enable_audit_textrel,
25295 ++ .maxlen = sizeof(int),
25296 ++ .mode = 0600,
25297 ++ .proc_handler = &proc_dointvec,
25298 ++ },
25299 ++#endif
25300 ++#ifdef CONFIG_GRKERNSEC_DMESG
25301 ++ {
25302 ++ .ctl_name = CTL_UNNUMBERED,
25303 ++ .procname = "dmesg",
25304 ++ .data = &grsec_enable_dmesg,
25305 ++ .maxlen = sizeof(int),
25306 ++ .mode = 0600,
25307 ++ .proc_handler = &proc_dointvec,
25308 ++ },
25309 ++#endif
25310 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
25311 ++ {
25312 ++ .ctl_name = CTL_UNNUMBERED,
25313 ++ .procname = "chroot_findtask",
25314 ++ .data = &grsec_enable_chroot_findtask,
25315 ++ .maxlen = sizeof(int),
25316 ++ .mode = 0600,
25317 ++ .proc_handler = &proc_dointvec,
25318 ++ },
25319 ++#endif
25320 ++#ifdef CONFIG_GRKERNSEC_RESLOG
25321 ++ {
25322 ++ .ctl_name = CTL_UNNUMBERED,
25323 ++ .procname = "resource_logging",
25324 ++ .data = &grsec_resource_logging,
25325 ++ .maxlen = sizeof(int),
25326 ++ .mode = 0600,
25327 ++ .proc_handler = &proc_dointvec,
25328 ++ },
25329 ++#endif
25330 ++ {
25331 ++ .ctl_name = CTL_UNNUMBERED,
25332 ++ .procname = "grsec_lock",
25333 ++ .data = &grsec_lock,
25334 ++ .maxlen = sizeof(int),
25335 ++ .mode = 0600,
25336 ++ .proc_handler = &proc_dointvec,
25337 ++ },
25338 ++#endif
25339 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25340 ++ {
25341 ++ .ctl_name = CTL_UNNUMBERED,
25342 ++ .procname = "disable_modules",
25343 ++ .data = &grsec_modstop,
25344 ++ .maxlen = sizeof(int),
25345 ++ .mode = 0600,
25346 ++ .proc_handler = &proc_dointvec,
25347 ++ },
25348 ++#endif
25349 ++ { .ctl_name = 0 }
25350 ++};
25351 ++#endif
25352 ++
25353 ++int gr_check_modstop(void)
25354 ++{
25355 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25356 ++ if (grsec_modstop == 1) {
25357 ++ gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG);
25358 ++ return 1;
25359 ++ }
25360 ++#endif
25361 ++ return 0;
25362 ++}
25363 +diff -urNp linux-2.6.27.10/grsecurity/grsec_textrel.c linux-2.6.27.10/grsecurity/grsec_textrel.c
25364 +--- linux-2.6.27.10/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500
25365 ++++ linux-2.6.27.10/grsecurity/grsec_textrel.c 2008-11-18 03:38:45.000000000 -0500
25366 +@@ -0,0 +1,16 @@
25367 ++#include <linux/kernel.h>
25368 ++#include <linux/sched.h>
25369 ++#include <linux/mm.h>
25370 ++#include <linux/file.h>
25371 ++#include <linux/grinternal.h>
25372 ++#include <linux/grsecurity.h>
25373 ++
25374 ++void
25375 ++gr_log_textrel(struct vm_area_struct * vma)
25376 ++{
25377 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25378 ++ if (grsec_enable_audit_textrel)
25379 ++ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
25380 ++#endif
25381 ++ return;
25382 ++}
25383 +diff -urNp linux-2.6.27.10/grsecurity/grsec_time.c linux-2.6.27.10/grsecurity/grsec_time.c
25384 +--- linux-2.6.27.10/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
25385 ++++ linux-2.6.27.10/grsecurity/grsec_time.c 2008-11-18 03:38:45.000000000 -0500
25386 +@@ -0,0 +1,13 @@
25387 ++#include <linux/kernel.h>
25388 ++#include <linux/sched.h>
25389 ++#include <linux/grinternal.h>
25390 ++
25391 ++void
25392 ++gr_log_timechange(void)
25393 ++{
25394 ++#ifdef CONFIG_GRKERNSEC_TIME
25395 ++ if (grsec_enable_time)
25396 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
25397 ++#endif
25398 ++ return;
25399 ++}
25400 +diff -urNp linux-2.6.27.10/grsecurity/grsec_tpe.c linux-2.6.27.10/grsecurity/grsec_tpe.c
25401 +--- linux-2.6.27.10/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
25402 ++++ linux-2.6.27.10/grsecurity/grsec_tpe.c 2008-11-18 03:38:45.000000000 -0500
25403 +@@ -0,0 +1,37 @@
25404 ++#include <linux/kernel.h>
25405 ++#include <linux/sched.h>
25406 ++#include <linux/file.h>
25407 ++#include <linux/fs.h>
25408 ++#include <linux/grinternal.h>
25409 ++
25410 ++extern int gr_acl_tpe_check(void);
25411 ++
25412 ++int
25413 ++gr_tpe_allow(const struct file *file)
25414 ++{
25415 ++#ifdef CONFIG_GRKERNSEC
25416 ++ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
25417 ++
25418 ++ if (current->uid && ((grsec_enable_tpe &&
25419 ++#ifdef CONFIG_GRKERNSEC_TPE_INVERT
25420 ++ !in_group_p(grsec_tpe_gid)
25421 ++#else
25422 ++ in_group_p(grsec_tpe_gid)
25423 ++#endif
25424 ++ ) || gr_acl_tpe_check()) &&
25425 ++ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
25426 ++ (inode->i_mode & S_IWOTH))))) {
25427 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25428 ++ return 0;
25429 ++ }
25430 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25431 ++ if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
25432 ++ ((inode->i_uid && (inode->i_uid != current->uid)) ||
25433 ++ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
25434 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25435 ++ return 0;
25436 ++ }
25437 ++#endif
25438 ++#endif
25439 ++ return 1;
25440 ++}
25441 +diff -urNp linux-2.6.27.10/grsecurity/grsum.c linux-2.6.27.10/grsecurity/grsum.c
25442 +--- linux-2.6.27.10/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
25443 ++++ linux-2.6.27.10/grsecurity/grsum.c 2008-11-18 03:38:45.000000000 -0500
25444 +@@ -0,0 +1,59 @@
25445 ++#include <linux/err.h>
25446 ++#include <linux/kernel.h>
25447 ++#include <linux/sched.h>
25448 ++#include <linux/mm.h>
25449 ++#include <linux/scatterlist.h>
25450 ++#include <linux/crypto.h>
25451 ++#include <linux/gracl.h>
25452 ++
25453 ++
25454 ++#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
25455 ++#error "crypto and sha256 must be built into the kernel"
25456 ++#endif
25457 ++
25458 ++int
25459 ++chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
25460 ++{
25461 ++ char *p;
25462 ++ struct crypto_hash *tfm;
25463 ++ struct hash_desc desc;
25464 ++ struct scatterlist sg;
25465 ++ unsigned char temp_sum[GR_SHA_LEN];
25466 ++ volatile int retval = 0;
25467 ++ volatile int dummy = 0;
25468 ++ unsigned int i;
25469 ++
25470 ++ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
25471 ++ if (IS_ERR(tfm)) {
25472 ++ /* should never happen, since sha256 should be built in */
25473 ++ return 1;
25474 ++ }
25475 ++
25476 ++ desc.tfm = tfm;
25477 ++ desc.flags = 0;
25478 ++
25479 ++ crypto_hash_init(&desc);
25480 ++
25481 ++ p = salt;
25482 ++ sg_set_buf(&sg, p, GR_SALT_LEN);
25483 ++ crypto_hash_update(&desc, &sg, sg.length);
25484 ++
25485 ++ p = entry->pw;
25486 ++ sg_set_buf(&sg, p, strlen(p));
25487 ++
25488 ++ crypto_hash_update(&desc, &sg, sg.length);
25489 ++
25490 ++ crypto_hash_final(&desc, temp_sum);
25491 ++
25492 ++ memset(entry->pw, 0, GR_PW_LEN);
25493 ++
25494 ++ for (i = 0; i < GR_SHA_LEN; i++)
25495 ++ if (sum[i] != temp_sum[i])
25496 ++ retval = 1;
25497 ++ else
25498 ++ dummy = 1; // waste a cycle
25499 ++
25500 ++ crypto_free_hash(tfm);
25501 ++
25502 ++ return retval;
25503 ++}
25504 +diff -urNp linux-2.6.27.10/grsecurity/Kconfig linux-2.6.27.10/grsecurity/Kconfig
25505 +--- linux-2.6.27.10/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
25506 ++++ linux-2.6.27.10/grsecurity/Kconfig 2008-11-18 11:18:57.000000000 -0500
25507 +@@ -0,0 +1,863 @@
25508 ++#
25509 ++# grecurity configuration
25510 ++#
25511 ++
25512 ++menu "Grsecurity"
25513 ++
25514 ++config GRKERNSEC
25515 ++ bool "Grsecurity"
25516 ++ select CRYPTO
25517 ++ select CRYPTO_SHA256
25518 ++ select SECURITY
25519 ++ select SECURITY_CAPABILITIES
25520 ++ help
25521 ++ If you say Y here, you will be able to configure many features
25522 ++ that will enhance the security of your system. It is highly
25523 ++ recommended that you say Y here and read through the help
25524 ++ for each option so that you fully understand the features and
25525 ++ can evaluate their usefulness for your machine.
25526 ++
25527 ++choice
25528 ++ prompt "Security Level"
25529 ++ depends on GRKERNSEC
25530 ++ default GRKERNSEC_CUSTOM
25531 ++
25532 ++config GRKERNSEC_LOW
25533 ++ bool "Low"
25534 ++ select GRKERNSEC_LINK
25535 ++ select GRKERNSEC_FIFO
25536 ++ select GRKERNSEC_EXECVE
25537 ++ select GRKERNSEC_RANDNET
25538 ++ select GRKERNSEC_DMESG
25539 ++ select GRKERNSEC_CHROOT_CHDIR
25540 ++ select GRKERNSEC_MODSTOP if (MODULES)
25541 ++
25542 ++ help
25543 ++ If you choose this option, several of the grsecurity options will
25544 ++ be enabled that will give you greater protection against a number
25545 ++ of attacks, while assuring that none of your software will have any
25546 ++ conflicts with the additional security measures. If you run a lot
25547 ++ of unusual software, or you are having problems with the higher
25548 ++ security levels, you should say Y here. With this option, the
25549 ++ following features are enabled:
25550 ++
25551 ++ - Linking restrictions
25552 ++ - FIFO restrictions
25553 ++ - Enforcing RLIMIT_NPROC on execve
25554 ++ - Restricted dmesg
25555 ++ - Enforced chdir("/") on chroot
25556 ++ - Runtime module disabling
25557 ++
25558 ++config GRKERNSEC_MEDIUM
25559 ++ bool "Medium"
25560 ++ select PAX
25561 ++ select PAX_EI_PAX
25562 ++ select PAX_PT_PAX_FLAGS
25563 ++ select PAX_HAVE_ACL_FLAGS
25564 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25565 ++ select GRKERNSEC_CHROOT_SYSCTL
25566 ++ select GRKERNSEC_LINK
25567 ++ select GRKERNSEC_FIFO
25568 ++ select GRKERNSEC_EXECVE
25569 ++ select GRKERNSEC_DMESG
25570 ++ select GRKERNSEC_RANDNET
25571 ++ select GRKERNSEC_FORKFAIL
25572 ++ select GRKERNSEC_TIME
25573 ++ select GRKERNSEC_SIGNAL
25574 ++ select GRKERNSEC_CHROOT
25575 ++ select GRKERNSEC_CHROOT_UNIX
25576 ++ select GRKERNSEC_CHROOT_MOUNT
25577 ++ select GRKERNSEC_CHROOT_PIVOT
25578 ++ select GRKERNSEC_CHROOT_DOUBLE
25579 ++ select GRKERNSEC_CHROOT_CHDIR
25580 ++ select GRKERNSEC_CHROOT_MKNOD
25581 ++ select GRKERNSEC_PROC
25582 ++ select GRKERNSEC_PROC_USERGROUP
25583 ++ select GRKERNSEC_MODSTOP if (MODULES)
25584 ++ select PAX_RANDUSTACK
25585 ++ select PAX_ASLR
25586 ++ select PAX_RANDMMAP
25587 ++ select PAX_REFCOUNT if (X86)
25588 ++
25589 ++ help
25590 ++ If you say Y here, several features in addition to those included
25591 ++ in the low additional security level will be enabled. These
25592 ++ features provide even more security to your system, though in rare
25593 ++ cases they may be incompatible with very old or poorly written
25594 ++ software. If you enable this option, make sure that your auth
25595 ++ service (identd) is running as gid 1001. With this option,
25596 ++ the following features (in addition to those provided in the
25597 ++ low additional security level) will be enabled:
25598 ++
25599 ++ - Failed fork logging
25600 ++ - Time change logging
25601 ++ - Signal logging
25602 ++ - Deny mounts in chroot
25603 ++ - Deny double chrooting
25604 ++ - Deny sysctl writes in chroot
25605 ++ - Deny mknod in chroot
25606 ++ - Deny access to abstract AF_UNIX sockets out of chroot
25607 ++ - Deny pivot_root in chroot
25608 ++ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
25609 ++ - /proc restrictions with special GID set to 10 (usually wheel)
25610 ++ - Address Space Layout Randomization (ASLR)
25611 ++
25612 ++config GRKERNSEC_HIGH
25613 ++ bool "High"
25614 ++ select GRKERNSEC_LINK
25615 ++ select GRKERNSEC_FIFO
25616 ++ select GRKERNSEC_EXECVE
25617 ++ select GRKERNSEC_DMESG
25618 ++ select GRKERNSEC_FORKFAIL
25619 ++ select GRKERNSEC_TIME
25620 ++ select GRKERNSEC_SIGNAL
25621 ++ select GRKERNSEC_CHROOT_SHMAT
25622 ++ select GRKERNSEC_CHROOT_UNIX
25623 ++ select GRKERNSEC_CHROOT_MOUNT
25624 ++ select GRKERNSEC_CHROOT_FCHDIR
25625 ++ select GRKERNSEC_CHROOT_PIVOT
25626 ++ select GRKERNSEC_CHROOT_DOUBLE
25627 ++ select GRKERNSEC_CHROOT_CHDIR
25628 ++ select GRKERNSEC_CHROOT_MKNOD
25629 ++ select GRKERNSEC_CHROOT_CAPS
25630 ++ select GRKERNSEC_CHROOT_SYSCTL
25631 ++ select GRKERNSEC_CHROOT_FINDTASK
25632 ++ select GRKERNSEC_PROC
25633 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25634 ++ select GRKERNSEC_HIDESYM
25635 ++ select GRKERNSEC_BRUTE
25636 ++ select GRKERNSEC_PROC_USERGROUP
25637 ++ select GRKERNSEC_KMEM
25638 ++ select GRKERNSEC_RESLOG
25639 ++ select GRKERNSEC_RANDNET
25640 ++ select GRKERNSEC_PROC_ADD
25641 ++ select GRKERNSEC_CHROOT_CHMOD
25642 ++ select GRKERNSEC_CHROOT_NICE
25643 ++ select GRKERNSEC_AUDIT_MOUNT
25644 ++ select GRKERNSEC_MODSTOP if (MODULES)
25645 ++ select PAX
25646 ++ select PAX_RANDUSTACK
25647 ++ select PAX_ASLR
25648 ++ select PAX_RANDMMAP
25649 ++ select PAX_NOEXEC
25650 ++ select PAX_MPROTECT
25651 ++ select PAX_EI_PAX
25652 ++ select PAX_PT_PAX_FLAGS
25653 ++ select PAX_HAVE_ACL_FLAGS
25654 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
25655 ++ select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO)
25656 ++ select PAX_RANDKSTACK if (X86_TSC && !X86_64)
25657 ++ select PAX_SEGMEXEC if (X86 && !X86_64)
25658 ++ select PAX_PAGEEXEC if (!X86)
25659 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
25660 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
25661 ++ select PAX_SYSCALL if (PPC32)
25662 ++ select PAX_EMUTRAMP if (PARISC)
25663 ++ select PAX_EMUSIGRT if (PARISC)
25664 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
25665 ++ select PAX_REFCOUNT if (X86)
25666 ++ help
25667 ++ If you say Y here, many of the features of grsecurity will be
25668 ++ enabled, which will protect you against many kinds of attacks
25669 ++ against your system. The heightened security comes at a cost
25670 ++ of an increased chance of incompatibilities with rare software
25671 ++ on your machine. Since this security level enables PaX, you should
25672 ++ view <http://pax.grsecurity.net> and read about the PaX
25673 ++ project. While you are there, download chpax and run it on
25674 ++ binaries that cause problems with PaX. Also remember that
25675 ++ since the /proc restrictions are enabled, you must run your
25676 ++ identd as gid 1001. This security level enables the following
25677 ++ features in addition to those listed in the low and medium
25678 ++ security levels:
25679 ++
25680 ++ - Additional /proc restrictions
25681 ++ - Chmod restrictions in chroot
25682 ++ - No signals, ptrace, or viewing of processes outside of chroot
25683 ++ - Capability restrictions in chroot
25684 ++ - Deny fchdir out of chroot
25685 ++ - Priority restrictions in chroot
25686 ++ - Segmentation-based implementation of PaX
25687 ++ - Mprotect restrictions
25688 ++ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
25689 ++ - Kernel stack randomization
25690 ++ - Mount/unmount/remount logging
25691 ++ - Kernel symbol hiding
25692 ++ - Prevention of memory exhaustion-based exploits
25693 ++config GRKERNSEC_CUSTOM
25694 ++ bool "Custom"
25695 ++ help
25696 ++ If you say Y here, you will be able to configure every grsecurity
25697 ++ option, which allows you to enable many more features that aren't
25698 ++ covered in the basic security levels. These additional features
25699 ++ include TPE, socket restrictions, and the sysctl system for
25700 ++ grsecurity. It is advised that you read through the help for
25701 ++ each option to determine its usefulness in your situation.
25702 ++
25703 ++endchoice
25704 ++
25705 ++menu "Address Space Protection"
25706 ++depends on GRKERNSEC
25707 ++
25708 ++config GRKERNSEC_KMEM
25709 ++ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
25710 ++ help
25711 ++ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
25712 ++ be written to via mmap or otherwise to modify the running kernel.
25713 ++ /dev/port will also not be allowed to be opened. If you have module
25714 ++ support disabled, enabling this will close up four ways that are
25715 ++ currently used to insert malicious code into the running kernel.
25716 ++ Even with all these features enabled, we still highly recommend that
25717 ++ you use the RBAC system, as it is still possible for an attacker to
25718 ++ modify the running kernel through privileged I/O granted by ioperm/iopl.
25719 ++ If you are not using XFree86, you may be able to stop this additional
25720 ++ case by enabling the 'Disable privileged I/O' option. Though nothing
25721 ++ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
25722 ++ but only to video memory, which is the only writing we allow in this
25723 ++ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
25724 ++ not be allowed to mprotect it with PROT_WRITE later.
25725 ++ It is highly recommended that you say Y here if you meet all the
25726 ++ conditions above.
25727 ++
25728 ++config GRKERNSEC_IO
25729 ++ bool "Disable privileged I/O"
25730 ++ depends on X86
25731 ++ select RTC
25732 ++ help
25733 ++ If you say Y here, all ioperm and iopl calls will return an error.
25734 ++ Ioperm and iopl can be used to modify the running kernel.
25735 ++ Unfortunately, some programs need this access to operate properly,
25736 ++ the most notable of which are XFree86 and hwclock. hwclock can be
25737 ++ remedied by having RTC support in the kernel, so CONFIG_RTC is
25738 ++ enabled if this option is enabled, to ensure that hwclock operates
25739 ++ correctly. XFree86 still will not operate correctly with this option
25740 ++ enabled, so DO NOT CHOOSE Y IF YOU USE XFree86. If you use XFree86
25741 ++ and you still want to protect your kernel against modification,
25742 ++ use the RBAC system.
25743 ++
25744 ++config GRKERNSEC_PROC_MEMMAP
25745 ++ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
25746 ++ depends on PAX_NOEXEC || PAX_ASLR
25747 ++ help
25748 ++ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
25749 ++ give no information about the addresses of its mappings if
25750 ++ PaX features that rely on random addresses are enabled on the task.
25751 ++ If you use PaX it is greatly recommended that you say Y here as it
25752 ++ closes up a hole that makes the full ASLR useless for suid
25753 ++ binaries.
25754 ++
25755 ++config GRKERNSEC_BRUTE
25756 ++ bool "Deter exploit bruteforcing"
25757 ++ help
25758 ++ If you say Y here, attempts to bruteforce exploits against forking
25759 ++ daemons such as apache or sshd will be deterred. When a child of a
25760 ++ forking daemon is killed by PaX or crashes due to an illegal
25761 ++ instruction, the parent process will be delayed 30 seconds upon every
25762 ++ subsequent fork until the administrator is able to assess the
25763 ++ situation and restart the daemon. It is recommended that you also
25764 ++ enable signal logging in the auditing section so that logs are
25765 ++ generated when a process performs an illegal instruction.
25766 ++
25767 ++config GRKERNSEC_MODSTOP
25768 ++ bool "Runtime module disabling"
25769 ++ depends on MODULES
25770 ++ help
25771 ++ If you say Y here, you will be able to disable the ability to (un)load
25772 ++ modules at runtime. This feature is useful if you need the ability
25773 ++ to load kernel modules at boot time, but do not want to allow an
25774 ++ attacker to load a rootkit kernel module into the system, or to remove
25775 ++ a loaded kernel module important to system functioning. You should
25776 ++ enable the /dev/mem protection feature as well, since rootkits can be
25777 ++ inserted into the kernel via other methods than kernel modules. Since
25778 ++ an untrusted module could still be loaded by modifying init scripts and
25779 ++ rebooting the system, it is also recommended that you enable the RBAC
25780 ++ system. If you enable this option, a sysctl option with name
25781 ++ "disable_modules" will be created. Setting this option to "1" disables
25782 ++ module loading. After this option is set, no further writes to it are
25783 ++ allowed until the system is rebooted.
25784 ++
25785 ++config GRKERNSEC_HIDESYM
25786 ++ bool "Hide kernel symbols"
25787 ++ help
25788 ++ If you say Y here, getting information on loaded modules, and
25789 ++ displaying all kernel symbols through a syscall will be restricted
25790 ++ to users with CAP_SYS_MODULE. This option is only effective
25791 ++ provided the following conditions are met:
25792 ++ 1) The kernel using grsecurity is not precompiled by some distribution
25793 ++ 2) You are using the RBAC system and hiding other files such as your
25794 ++ kernel image and System.map
25795 ++ 3) You have the additional /proc restrictions enabled, which removes
25796 ++ /proc/kcore
25797 ++ If the above conditions are met, this option will aid to provide a
25798 ++ useful protection against local and remote kernel exploitation of
25799 ++ overflows and arbitrary read/write vulnerabilities.
25800 ++
25801 ++endmenu
25802 ++menu "Role Based Access Control Options"
25803 ++depends on GRKERNSEC
25804 ++
25805 ++config GRKERNSEC_ACL_HIDEKERN
25806 ++ bool "Hide kernel processes"
25807 ++ help
25808 ++ If you say Y here, all kernel threads will be hidden to all
25809 ++ processes but those whose subject has the "view hidden processes"
25810 ++ flag.
25811 ++
25812 ++config GRKERNSEC_ACL_MAXTRIES
25813 ++ int "Maximum tries before password lockout"
25814 ++ default 3
25815 ++ help
25816 ++ This option enforces the maximum number of times a user can attempt
25817 ++ to authorize themselves with the grsecurity RBAC system before being
25818 ++ denied the ability to attempt authorization again for a specified time.
25819 ++ The lower the number, the harder it will be to brute-force a password.
25820 ++
25821 ++config GRKERNSEC_ACL_TIMEOUT
25822 ++ int "Time to wait after max password tries, in seconds"
25823 ++ default 30
25824 ++ help
25825 ++ This option specifies the time the user must wait after attempting to
25826 ++ authorize to the RBAC system with the maximum number of invalid
25827 ++ passwords. The higher the number, the harder it will be to brute-force
25828 ++ a password.
25829 ++
25830 ++endmenu
25831 ++menu "Filesystem Protections"
25832 ++depends on GRKERNSEC
25833 ++
25834 ++config GRKERNSEC_PROC
25835 ++ bool "Proc restrictions"
25836 ++ help
25837 ++ If you say Y here, the permissions of the /proc filesystem
25838 ++ will be altered to enhance system security and privacy. You MUST
25839 ++ choose either a user only restriction or a user and group restriction.
25840 ++ Depending upon the option you choose, you can either restrict users to
25841 ++ see only the processes they themselves run, or choose a group that can
25842 ++ view all processes and files normally restricted to root if you choose
25843 ++ the "restrict to user only" option. NOTE: If you're running identd as
25844 ++ a non-root user, you will have to run it as the group you specify here.
25845 ++
25846 ++config GRKERNSEC_PROC_USER
25847 ++ bool "Restrict /proc to user only"
25848 ++ depends on GRKERNSEC_PROC
25849 ++ help
25850 ++ If you say Y here, non-root users will only be able to view their own
25851 ++ processes, and restricts them from viewing network-related information,
25852 ++ and viewing kernel symbol and module information.
25853 ++
25854 ++config GRKERNSEC_PROC_USERGROUP
25855 ++ bool "Allow special group"
25856 ++ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
25857 ++ help
25858 ++ If you say Y here, you will be able to select a group that will be
25859 ++ able to view all processes, network-related information, and
25860 ++ kernel and symbol information. This option is useful if you want
25861 ++ to run identd as a non-root user.
25862 ++
25863 ++config GRKERNSEC_PROC_GID
25864 ++ int "GID for special group"
25865 ++ depends on GRKERNSEC_PROC_USERGROUP
25866 ++ default 1001
25867 ++
25868 ++config GRKERNSEC_PROC_ADD
25869 ++ bool "Additional restrictions"
25870 ++ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
25871 ++ help
25872 ++ If you say Y here, additional restrictions will be placed on
25873 ++ /proc that keep normal users from viewing device information and
25874 ++ slabinfo information that could be useful for exploits.
25875 ++
25876 ++config GRKERNSEC_LINK
25877 ++ bool "Linking restrictions"
25878 ++ help
25879 ++ If you say Y here, /tmp race exploits will be prevented, since users
25880 ++ will no longer be able to follow symlinks owned by other users in
25881 ++ world-writable +t directories (i.e. /tmp), unless the owner of the
25882 ++ symlink is the owner of the directory. users will also not be
25883 ++ able to hardlink to files they do not own. If the sysctl option is
25884 ++ enabled, a sysctl option with name "linking_restrictions" is created.
25885 ++
25886 ++config GRKERNSEC_FIFO
25887 ++ bool "FIFO restrictions"
25888 ++ help
25889 ++ If you say Y here, users will not be able to write to FIFOs they don't
25890 ++ own in world-writable +t directories (i.e. /tmp), unless the owner of
25891 ++ the FIFO is the same owner of the directory it's held in. If the sysctl
25892 ++ option is enabled, a sysctl option with name "fifo_restrictions" is
25893 ++ created.
25894 ++
25895 ++config GRKERNSEC_CHROOT
25896 ++ bool "Chroot jail restrictions"
25897 ++ help
25898 ++ If you say Y here, you will be able to choose several options that will
25899 ++ make breaking out of a chrooted jail much more difficult. If you
25900 ++ encounter no software incompatibilities with the following options, it
25901 ++ is recommended that you enable each one.
25902 ++
25903 ++config GRKERNSEC_CHROOT_MOUNT
25904 ++ bool "Deny mounts"
25905 ++ depends on GRKERNSEC_CHROOT
25906 ++ help
25907 ++ If you say Y here, processes inside a chroot will not be able to
25908 ++ mount or remount filesystems. If the sysctl option is enabled, a
25909 ++ sysctl option with name "chroot_deny_mount" is created.
25910 ++
25911 ++config GRKERNSEC_CHROOT_DOUBLE
25912 ++ bool "Deny double-chroots"
25913 ++ depends on GRKERNSEC_CHROOT
25914 ++ help
25915 ++ If you say Y here, processes inside a chroot will not be able to chroot
25916 ++ again outside the chroot. This is a widely used method of breaking
25917 ++ out of a chroot jail and should not be allowed. If the sysctl
25918 ++ option is enabled, a sysctl option with name
25919 ++ "chroot_deny_chroot" is created.
25920 ++
25921 ++config GRKERNSEC_CHROOT_PIVOT
25922 ++ bool "Deny pivot_root in chroot"
25923 ++ depends on GRKERNSEC_CHROOT
25924 ++ help
25925 ++ If you say Y here, processes inside a chroot will not be able to use
25926 ++ a function called pivot_root() that was introduced in Linux 2.3.41. It
25927 ++ works similar to chroot in that it changes the root filesystem. This
25928 ++ function could be misused in a chrooted process to attempt to break out
25929 ++ of the chroot, and therefore should not be allowed. If the sysctl
25930 ++ option is enabled, a sysctl option with name "chroot_deny_pivot" is
25931 ++ created.
25932 ++
25933 ++config GRKERNSEC_CHROOT_CHDIR
25934 ++ bool "Enforce chdir(\"/\") on all chroots"
25935 ++ depends on GRKERNSEC_CHROOT
25936 ++ help
25937 ++ If you say Y here, the current working directory of all newly-chrooted
25938 ++ applications will be set to the the root directory of the chroot.
25939 ++ The man page on chroot(2) states:
25940 ++ Note that this call does not change the current working
25941 ++ directory, so that `.' can be outside the tree rooted at
25942 ++ `/'. In particular, the super-user can escape from a
25943 ++ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
25944 ++
25945 ++ It is recommended that you say Y here, since it's not known to break
25946 ++ any software. If the sysctl option is enabled, a sysctl option with
25947 ++ name "chroot_enforce_chdir" is created.
25948 ++
25949 ++config GRKERNSEC_CHROOT_CHMOD
25950 ++ bool "Deny (f)chmod +s"
25951 ++ depends on GRKERNSEC_CHROOT
25952 ++ help
25953 ++ If you say Y here, processes inside a chroot will not be able to chmod
25954 ++ or fchmod files to make them have suid or sgid bits. This protects
25955 ++ against another published method of breaking a chroot. If the sysctl
25956 ++ option is enabled, a sysctl option with name "chroot_deny_chmod" is
25957 ++ created.
25958 ++
25959 ++config GRKERNSEC_CHROOT_FCHDIR
25960 ++ bool "Deny fchdir out of chroot"
25961 ++ depends on GRKERNSEC_CHROOT
25962 ++ help
25963 ++ If you say Y here, a well-known method of breaking chroots by fchdir'ing
25964 ++ to a file descriptor of the chrooting process that points to a directory
25965 ++ outside the filesystem will be stopped. If the sysctl option
25966 ++ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
25967 ++
25968 ++config GRKERNSEC_CHROOT_MKNOD
25969 ++ bool "Deny mknod"
25970 ++ depends on GRKERNSEC_CHROOT
25971 ++ help
25972 ++ If you say Y here, processes inside a chroot will not be allowed to
25973 ++ mknod. The problem with using mknod inside a chroot is that it
25974 ++ would allow an attacker to create a device entry that is the same
25975 ++ as one on the physical root of your system, which could range from
25976 ++ anything from the console device to a device for your harddrive (which
25977 ++ they could then use to wipe the drive or steal data). It is recommended
25978 ++ that you say Y here, unless you run into software incompatibilities.
25979 ++ If the sysctl option is enabled, a sysctl option with name
25980 ++ "chroot_deny_mknod" is created.
25981 ++
25982 ++config GRKERNSEC_CHROOT_SHMAT
25983 ++ bool "Deny shmat() out of chroot"
25984 ++ depends on GRKERNSEC_CHROOT
25985 ++ help
25986 ++ If you say Y here, processes inside a chroot will not be able to attach
25987 ++ to shared memory segments that were created outside of the chroot jail.
25988 ++ It is recommended that you say Y here. If the sysctl option is enabled,
25989 ++ a sysctl option with name "chroot_deny_shmat" is created.
25990 ++
25991 ++config GRKERNSEC_CHROOT_UNIX
25992 ++ bool "Deny access to abstract AF_UNIX sockets out of chroot"
25993 ++ depends on GRKERNSEC_CHROOT
25994 ++ help
25995 ++ If you say Y here, processes inside a chroot will not be able to
25996 ++ connect to abstract (meaning not belonging to a filesystem) Unix
25997 ++ domain sockets that were bound outside of a chroot. It is recommended
25998 ++ that you say Y here. If the sysctl option is enabled, a sysctl option
25999 ++ with name "chroot_deny_unix" is created.
26000 ++
26001 ++config GRKERNSEC_CHROOT_FINDTASK
26002 ++ bool "Protect outside processes"
26003 ++ depends on GRKERNSEC_CHROOT
26004 ++ help
26005 ++ If you say Y here, processes inside a chroot will not be able to
26006 ++ kill, send signals with fcntl, ptrace, capget, getpgid, getsid,
26007 ++ or view any process outside of the chroot. If the sysctl
26008 ++ option is enabled, a sysctl option with name "chroot_findtask" is
26009 ++ created.
26010 ++
26011 ++config GRKERNSEC_CHROOT_NICE
26012 ++ bool "Restrict priority changes"
26013 ++ depends on GRKERNSEC_CHROOT
26014 ++ help
26015 ++ If you say Y here, processes inside a chroot will not be able to raise
26016 ++ the priority of processes in the chroot, or alter the priority of
26017 ++ processes outside the chroot. This provides more security than simply
26018 ++ removing CAP_SYS_NICE from the process' capability set. If the
26019 ++ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
26020 ++ is created.
26021 ++
26022 ++config GRKERNSEC_CHROOT_SYSCTL
26023 ++ bool "Deny sysctl writes"
26024 ++ depends on GRKERNSEC_CHROOT
26025 ++ help
26026 ++ If you say Y here, an attacker in a chroot will not be able to
26027 ++ write to sysctl entries, either by sysctl(2) or through a /proc
26028 ++ interface. It is strongly recommended that you say Y here. If the
26029 ++ sysctl option is enabled, a sysctl option with name
26030 ++ "chroot_deny_sysctl" is created.
26031 ++
26032 ++config GRKERNSEC_CHROOT_CAPS
26033 ++ bool "Capability restrictions"
26034 ++ depends on GRKERNSEC_CHROOT
26035 ++ help
26036 ++ If you say Y here, the capabilities on all root processes within a
26037 ++ chroot jail will be lowered to stop module insertion, raw i/o,
26038 ++ system and net admin tasks, rebooting the system, modifying immutable
26039 ++ files, modifying IPC owned by another, and changing the system time.
26040 ++ This is left an option because it can break some apps. Disable this
26041 ++ if your chrooted apps are having problems performing those kinds of
26042 ++ tasks. If the sysctl option is enabled, a sysctl option with
26043 ++ name "chroot_caps" is created.
26044 ++
26045 ++endmenu
26046 ++menu "Kernel Auditing"
26047 ++depends on GRKERNSEC
26048 ++
26049 ++config GRKERNSEC_AUDIT_GROUP
26050 ++ bool "Single group for auditing"
26051 ++ help
26052 ++ If you say Y here, the exec, chdir, (un)mount, and ipc logging features
26053 ++ will only operate on a group you specify. This option is recommended
26054 ++ if you only want to watch certain users instead of having a large
26055 ++ amount of logs from the entire system. If the sysctl option is enabled,
26056 ++ a sysctl option with name "audit_group" is created.
26057 ++
26058 ++config GRKERNSEC_AUDIT_GID
26059 ++ int "GID for auditing"
26060 ++ depends on GRKERNSEC_AUDIT_GROUP
26061 ++ default 1007
26062 ++
26063 ++config GRKERNSEC_EXECLOG
26064 ++ bool "Exec logging"
26065 ++ help
26066 ++ If you say Y here, all execve() calls will be logged (since the
26067 ++ other exec*() calls are frontends to execve(), all execution
26068 ++ will be logged). Useful for shell-servers that like to keep track
26069 ++ of their users. If the sysctl option is enabled, a sysctl option with
26070 ++ name "exec_logging" is created.
26071 ++ WARNING: This option when enabled will produce a LOT of logs, especially
26072 ++ on an active system.
26073 ++
26074 ++config GRKERNSEC_RESLOG
26075 ++ bool "Resource logging"
26076 ++ help
26077 ++ If you say Y here, all attempts to overstep resource limits will
26078 ++ be logged with the resource name, the requested size, and the current
26079 ++ limit. It is highly recommended that you say Y here. If the sysctl
26080 ++ option is enabled, a sysctl option with name "resource_logging" is
26081 ++ created. If the RBAC system is enabled, the sysctl value is ignored.
26082 ++
26083 ++config GRKERNSEC_CHROOT_EXECLOG
26084 ++ bool "Log execs within chroot"
26085 ++ help
26086 ++ If you say Y here, all executions inside a chroot jail will be logged
26087 ++ to syslog. This can cause a large amount of logs if certain
26088 ++ applications (eg. djb's daemontools) are installed on the system, and
26089 ++ is therefore left as an option. If the sysctl option is enabled, a
26090 ++ sysctl option with name "chroot_execlog" is created.
26091 ++
26092 ++config GRKERNSEC_AUDIT_CHDIR
26093 ++ bool "Chdir logging"
26094 ++ help
26095 ++ If you say Y here, all chdir() calls will be logged. If the sysctl
26096 ++ option is enabled, a sysctl option with name "audit_chdir" is created.
26097 ++
26098 ++config GRKERNSEC_AUDIT_MOUNT
26099 ++ bool "(Un)Mount logging"
26100 ++ help
26101 ++ If you say Y here, all mounts and unmounts will be logged. If the
26102 ++ sysctl option is enabled, a sysctl option with name "audit_mount" is
26103 ++ created.
26104 ++
26105 ++config GRKERNSEC_AUDIT_IPC
26106 ++ bool "IPC logging"
26107 ++ help
26108 ++ If you say Y here, creation and removal of message queues, semaphores,
26109 ++ and shared memory will be logged. If the sysctl option is enabled, a
26110 ++ sysctl option with name "audit_ipc" is created.
26111 ++
26112 ++config GRKERNSEC_SIGNAL
26113 ++ bool "Signal logging"
26114 ++ help
26115 ++ If you say Y here, certain important signals will be logged, such as
26116 ++ SIGSEGV, which will as a result inform you of when a error in a program
26117 ++ occurred, which in some cases could mean a possible exploit attempt.
26118 ++ If the sysctl option is enabled, a sysctl option with name
26119 ++ "signal_logging" is created.
26120 ++
26121 ++config GRKERNSEC_FORKFAIL
26122 ++ bool "Fork failure logging"
26123 ++ help
26124 ++ If you say Y here, all failed fork() attempts will be logged.
26125 ++ This could suggest a fork bomb, or someone attempting to overstep
26126 ++ their process limit. If the sysctl option is enabled, a sysctl option
26127 ++ with name "forkfail_logging" is created.
26128 ++
26129 ++config GRKERNSEC_TIME
26130 ++ bool "Time change logging"
26131 ++ help
26132 ++ If you say Y here, any changes of the system clock will be logged.
26133 ++ If the sysctl option is enabled, a sysctl option with name
26134 ++ "timechange_logging" is created.
26135 ++
26136 ++config GRKERNSEC_PROC_IPADDR
26137 ++ bool "/proc/<pid>/ipaddr support"
26138 ++ help
26139 ++ If you say Y here, a new entry will be added to each /proc/<pid>
26140 ++ directory that contains the IP address of the person using the task.
26141 ++ The IP is carried across local TCP and AF_UNIX stream sockets.
26142 ++ This information can be useful for IDS/IPSes to perform remote response
26143 ++ to a local attack. The entry is readable by only the owner of the
26144 ++ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
26145 ++ the RBAC system), and thus does not create privacy concerns.
26146 ++
26147 ++config GRKERNSEC_AUDIT_TEXTREL
26148 ++ bool 'ELF text relocations logging (READ HELP)'
26149 ++ depends on PAX_MPROTECT
26150 ++ help
26151 ++ If you say Y here, text relocations will be logged with the filename
26152 ++ of the offending library or binary. The purpose of the feature is
26153 ++ to help Linux distribution developers get rid of libraries and
26154 ++ binaries that need text relocations which hinder the future progress
26155 ++ of PaX. Only Linux distribution developers should say Y here, and
26156 ++ never on a production machine, as this option creates an information
26157 ++ leak that could aid an attacker in defeating the randomization of
26158 ++ a single memory region. If the sysctl option is enabled, a sysctl
26159 ++ option with name "audit_textrel" is created.
26160 ++
26161 ++endmenu
26162 ++
26163 ++menu "Executable Protections"
26164 ++depends on GRKERNSEC
26165 ++
26166 ++config GRKERNSEC_EXECVE
26167 ++ bool "Enforce RLIMIT_NPROC on execs"
26168 ++ help
26169 ++ If you say Y here, users with a resource limit on processes will
26170 ++ have the value checked during execve() calls. The current system
26171 ++ only checks the system limit during fork() calls. If the sysctl option
26172 ++ is enabled, a sysctl option with name "execve_limiting" is created.
26173 ++
26174 ++config GRKERNSEC_DMESG
26175 ++ bool "Dmesg(8) restriction"
26176 ++ help
26177 ++ If you say Y here, non-root users will not be able to use dmesg(8)
26178 ++ to view up to the last 4kb of messages in the kernel's log buffer.
26179 ++ If the sysctl option is enabled, a sysctl option with name "dmesg" is
26180 ++ created.
26181 ++
26182 ++config GRKERNSEC_TPE
26183 ++ bool "Trusted Path Execution (TPE)"
26184 ++ help
26185 ++ If you say Y here, you will be able to choose a gid to add to the
26186 ++ supplementary groups of users you want to mark as "untrusted."
26187 ++ These users will not be able to execute any files that are not in
26188 ++ root-owned directories writable only by root. If the sysctl option
26189 ++ is enabled, a sysctl option with name "tpe" is created.
26190 ++
26191 ++config GRKERNSEC_TPE_ALL
26192 ++ bool "Partially restrict non-root users"
26193 ++ depends on GRKERNSEC_TPE
26194 ++ help
26195 ++ If you say Y here, All non-root users other than the ones in the
26196 ++ group specified in the main TPE option will only be allowed to
26197 ++ execute files in directories they own that are not group or
26198 ++ world-writable, or in directories owned by root and writable only by
26199 ++ root. If the sysctl option is enabled, a sysctl option with name
26200 ++ "tpe_restrict_all" is created.
26201 ++
26202 ++config GRKERNSEC_TPE_INVERT
26203 ++ bool "Invert GID option"
26204 ++ depends on GRKERNSEC_TPE
26205 ++ help
26206 ++ If you say Y here, the group you specify in the TPE configuration will
26207 ++ decide what group TPE restrictions will be *disabled* for. This
26208 ++ option is useful if you want TPE restrictions to be applied to most
26209 ++ users on the system.
26210 ++
26211 ++config GRKERNSEC_TPE_GID
26212 ++ int "GID for untrusted users"
26213 ++ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
26214 ++ default 1005
26215 ++ help
26216 ++ If you have selected the "Invert GID option" above, setting this
26217 ++ GID determines what group TPE restrictions will be *disabled* for.
26218 ++ If you have not selected the "Invert GID option" above, setting this
26219 ++ GID determines what group TPE restrictions will be *enabled* for.
26220 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26221 ++ is created.
26222 ++
26223 ++config GRKERNSEC_TPE_GID
26224 ++ int "GID for trusted users"
26225 ++ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
26226 ++ default 1005
26227 ++ help
26228 ++ If you have selected the "Invert GID option" above, setting this
26229 ++ GID determines what group TPE restrictions will be *disabled* for.
26230 ++ If you have not selected the "Invert GID option" above, setting this
26231 ++ GID determines what group TPE restrictions will be *enabled* for.
26232 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26233 ++ is created.
26234 ++
26235 ++endmenu
26236 ++menu "Network Protections"
26237 ++depends on GRKERNSEC
26238 ++
26239 ++config GRKERNSEC_RANDNET
26240 ++ bool "Larger entropy pools"
26241 ++ help
26242 ++ If you say Y here, the entropy pools used for many features of Linux
26243 ++ and grsecurity will be doubled in size. Since several grsecurity
26244 ++ features use additional randomness, it is recommended that you say Y
26245 ++ here. Saying Y here has a similar effect as modifying
26246 ++ /proc/sys/kernel/random/poolsize.
26247 ++
26248 ++config GRKERNSEC_SOCKET
26249 ++ bool "Socket restrictions"
26250 ++ help
26251 ++ If you say Y here, you will be able to choose from several options.
26252 ++ If you assign a GID on your system and add it to the supplementary
26253 ++ groups of users you want to restrict socket access to, this patch
26254 ++ will perform up to three things, based on the option(s) you choose.
26255 ++
26256 ++config GRKERNSEC_SOCKET_ALL
26257 ++ bool "Deny any sockets to group"
26258 ++ depends on GRKERNSEC_SOCKET
26259 ++ help
26260 ++ If you say Y here, you will be able to choose a GID of whose users will
26261 ++ be unable to connect to other hosts from your machine or run server
26262 ++ applications from your machine. If the sysctl option is enabled, a
26263 ++ sysctl option with name "socket_all" is created.
26264 ++
26265 ++config GRKERNSEC_SOCKET_ALL_GID
26266 ++ int "GID to deny all sockets for"
26267 ++ depends on GRKERNSEC_SOCKET_ALL
26268 ++ default 1004
26269 ++ help
26270 ++ Here you can choose the GID to disable socket access for. Remember to
26271 ++ add the users you want socket access disabled for to the GID
26272 ++ specified here. If the sysctl option is enabled, a sysctl option
26273 ++ with name "socket_all_gid" is created.
26274 ++
26275 ++config GRKERNSEC_SOCKET_CLIENT
26276 ++ bool "Deny client sockets to group"
26277 ++ depends on GRKERNSEC_SOCKET
26278 ++ help
26279 ++ If you say Y here, you will be able to choose a GID of whose users will
26280 ++ be unable to connect to other hosts from your machine, but will be
26281 ++ able to run servers. If this option is enabled, all users in the group
26282 ++ you specify will have to use passive mode when initiating ftp transfers
26283 ++ from the shell on your machine. If the sysctl option is enabled, a
26284 ++ sysctl option with name "socket_client" is created.
26285 ++
26286 ++config GRKERNSEC_SOCKET_CLIENT_GID
26287 ++ int "GID to deny client sockets for"
26288 ++ depends on GRKERNSEC_SOCKET_CLIENT
26289 ++ default 1003
26290 ++ help
26291 ++ Here you can choose the GID to disable client socket access for.
26292 ++ Remember to add the users you want client socket access disabled for to
26293 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26294 ++ option with name "socket_client_gid" is created.
26295 ++
26296 ++config GRKERNSEC_SOCKET_SERVER
26297 ++ bool "Deny server sockets to group"
26298 ++ depends on GRKERNSEC_SOCKET
26299 ++ help
26300 ++ If you say Y here, you will be able to choose a GID of whose users will
26301 ++ be unable to run server applications from your machine. If the sysctl
26302 ++ option is enabled, a sysctl option with name "socket_server" is created.
26303 ++
26304 ++config GRKERNSEC_SOCKET_SERVER_GID
26305 ++ int "GID to deny server sockets for"
26306 ++ depends on GRKERNSEC_SOCKET_SERVER
26307 ++ default 1002
26308 ++ help
26309 ++ Here you can choose the GID to disable server socket access for.
26310 ++ Remember to add the users you want server socket access disabled for to
26311 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26312 ++ option with name "socket_server_gid" is created.
26313 ++
26314 ++endmenu
26315 ++menu "Sysctl support"
26316 ++depends on GRKERNSEC && SYSCTL
26317 ++
26318 ++config GRKERNSEC_SYSCTL
26319 ++ bool "Sysctl support"
26320 ++ help
26321 ++ If you say Y here, you will be able to change the options that
26322 ++ grsecurity runs with at bootup, without having to recompile your
26323 ++ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
26324 ++ to enable (1) or disable (0) various features. All the sysctl entries
26325 ++ are mutable until the "grsec_lock" entry is set to a non-zero value.
26326 ++ All features enabled in the kernel configuration are disabled at boot
26327 ++ if you do not say Y to the "Turn on features by default" option.
26328 ++ All options should be set at startup, and the grsec_lock entry should
26329 ++ be set to a non-zero value after all the options are set.
26330 ++ *THIS IS EXTREMELY IMPORTANT*
26331 ++
26332 ++config GRKERNSEC_SYSCTL_ON
26333 ++ bool "Turn on features by default"
26334 ++ depends on GRKERNSEC_SYSCTL
26335 ++ help
26336 ++ If you say Y here, instead of having all features enabled in the
26337 ++ kernel configuration disabled at boot time, the features will be
26338 ++ enabled at boot time. It is recommended you say Y here unless
26339 ++ there is some reason you would want all sysctl-tunable features to
26340 ++ be disabled by default. As mentioned elsewhere, it is important
26341 ++ to enable the grsec_lock entry once you have finished modifying
26342 ++ the sysctl entries.
26343 ++
26344 ++endmenu
26345 ++menu "Logging Options"
26346 ++depends on GRKERNSEC
26347 ++
26348 ++config GRKERNSEC_FLOODTIME
26349 ++ int "Seconds in between log messages (minimum)"
26350 ++ default 10
26351 ++ help
26352 ++ This option allows you to enforce the number of seconds between
26353 ++ grsecurity log messages. The default should be suitable for most
26354 ++ people, however, if you choose to change it, choose a value small enough
26355 ++ to allow informative logs to be produced, but large enough to
26356 ++ prevent flooding.
26357 ++
26358 ++config GRKERNSEC_FLOODBURST
26359 ++ int "Number of messages in a burst (maximum)"
26360 ++ default 4
26361 ++ help
26362 ++ This option allows you to choose the maximum number of messages allowed
26363 ++ within the flood time interval you chose in a separate option. The
26364 ++ default should be suitable for most people, however if you find that
26365 ++ many of your logs are being interpreted as flooding, you may want to
26366 ++ raise this value.
26367 ++
26368 ++endmenu
26369 ++
26370 ++endmenu
26371 +diff -urNp linux-2.6.27.10/grsecurity/Makefile linux-2.6.27.10/grsecurity/Makefile
26372 +--- linux-2.6.27.10/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
26373 ++++ linux-2.6.27.10/grsecurity/Makefile 2008-11-18 03:38:45.000000000 -0500
26374 +@@ -0,0 +1,20 @@
26375 ++# grsecurity's ACL system was originally written in 2001 by Michael Dalton
26376 ++# during 2001-2005 it has been completely redesigned by Brad Spengler
26377 ++# into an RBAC system
26378 ++#
26379 ++# All code in this directory and various hooks inserted throughout the kernel
26380 ++# are copyright Brad Spengler, and released under the GPL v2 or higher
26381 ++
26382 ++obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
26383 ++ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
26384 ++ grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o
26385 ++
26386 ++obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
26387 ++ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
26388 ++ gracl_learn.o grsec_log.o
26389 ++obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
26390 ++
26391 ++ifndef CONFIG_GRKERNSEC
26392 ++obj-y += grsec_disabled.o
26393 ++endif
26394 ++
26395 +diff -urNp linux-2.6.27.10/include/asm-cris/kmap_types.h linux-2.6.27.10/include/asm-cris/kmap_types.h
26396 +--- linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26397 ++++ linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26398 +@@ -19,6 +19,7 @@ enum km_type {
26399 + KM_IRQ1,
26400 + KM_SOFTIRQ0,
26401 + KM_SOFTIRQ1,
26402 ++ KM_CLEARPAGE,
26403 + KM_TYPE_NR
26404 + };
26405 +
26406 +diff -urNp linux-2.6.27.10/include/asm-frv/kmap_types.h linux-2.6.27.10/include/asm-frv/kmap_types.h
26407 +--- linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26408 ++++ linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26409 +@@ -23,6 +23,7 @@ enum km_type {
26410 + KM_IRQ1,
26411 + KM_SOFTIRQ0,
26412 + KM_SOFTIRQ1,
26413 ++ KM_CLEARPAGE,
26414 + KM_TYPE_NR
26415 + };
26416 +
26417 +diff -urNp linux-2.6.27.10/include/asm-generic/futex.h linux-2.6.27.10/include/asm-generic/futex.h
26418 +--- linux-2.6.27.10/include/asm-generic/futex.h 2008-11-07 12:55:34.000000000 -0500
26419 ++++ linux-2.6.27.10/include/asm-generic/futex.h 2008-11-18 03:38:45.000000000 -0500
26420 +@@ -6,7 +6,7 @@
26421 + #include <asm/errno.h>
26422 +
26423 + static inline int
26424 +-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
26425 ++futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
26426 + {
26427 + int op = (encoded_op >> 28) & 7;
26428 + int cmp = (encoded_op >> 24) & 15;
26429 +@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
26430 + }
26431 +
26432 + static inline int
26433 +-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
26434 ++futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
26435 + {
26436 + return -ENOSYS;
26437 + }
26438 +diff -urNp linux-2.6.27.10/include/asm-generic/vmlinux.lds.h linux-2.6.27.10/include/asm-generic/vmlinux.lds.h
26439 +--- linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-07 12:55:34.000000000 -0500
26440 ++++ linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-18 03:38:45.000000000 -0500
26441 +@@ -59,6 +59,7 @@
26442 + .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
26443 + VMLINUX_SYMBOL(__start_rodata) = .; \
26444 + *(.rodata) *(.rodata.*) \
26445 ++ *(.data.read_only) \
26446 + *(__vermagic) /* Kernel version magic */ \
26447 + *(__markers_strings) /* Markers: strings */ \
26448 + } \
26449 +diff -urNp linux-2.6.27.10/include/asm-m32r/kmap_types.h linux-2.6.27.10/include/asm-m32r/kmap_types.h
26450 +--- linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26451 ++++ linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26452 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
26453 + D(10) KM_IRQ1,
26454 + D(11) KM_SOFTIRQ0,
26455 + D(12) KM_SOFTIRQ1,
26456 +-D(13) KM_TYPE_NR
26457 ++D(13) KM_CLEARPAGE,
26458 ++D(14) KM_TYPE_NR
26459 + };
26460 +
26461 + #undef D
26462 +diff -urNp linux-2.6.27.10/include/asm-m68k/kmap_types.h linux-2.6.27.10/include/asm-m68k/kmap_types.h
26463 +--- linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26464 ++++ linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26465 +@@ -15,6 +15,7 @@ enum km_type {
26466 + KM_IRQ1,
26467 + KM_SOFTIRQ0,
26468 + KM_SOFTIRQ1,
26469 ++ KM_CLEARPAGE,
26470 + KM_TYPE_NR
26471 + };
26472 +
26473 +diff -urNp linux-2.6.27.10/include/asm-mips/elf.h linux-2.6.27.10/include/asm-mips/elf.h
26474 +--- linux-2.6.27.10/include/asm-mips/elf.h 2008-11-07 12:55:34.000000000 -0500
26475 ++++ linux-2.6.27.10/include/asm-mips/elf.h 2008-11-18 03:38:45.000000000 -0500
26476 +@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
26477 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
26478 + #endif
26479 +
26480 ++#ifdef CONFIG_PAX_ASLR
26481 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
26482 ++
26483 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26484 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26485 ++#endif
26486 ++
26487 + #endif /* _ASM_ELF_H */
26488 +diff -urNp linux-2.6.27.10/include/asm-mips/kmap_types.h linux-2.6.27.10/include/asm-mips/kmap_types.h
26489 +--- linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26490 ++++ linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26491 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26492 + D(10) KM_IRQ1,
26493 + D(11) KM_SOFTIRQ0,
26494 + D(12) KM_SOFTIRQ1,
26495 +-D(13) KM_TYPE_NR
26496 ++D(13) KM_CLEARPAGE,
26497 ++D(14) KM_TYPE_NR
26498 + };
26499 +
26500 + #undef D
26501 +diff -urNp linux-2.6.27.10/include/asm-mips/page.h linux-2.6.27.10/include/asm-mips/page.h
26502 +--- linux-2.6.27.10/include/asm-mips/page.h 2008-11-07 12:55:34.000000000 -0500
26503 ++++ linux-2.6.27.10/include/asm-mips/page.h 2008-11-18 03:38:45.000000000 -0500
26504 +@@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa
26505 + #ifdef CONFIG_CPU_MIPS32
26506 + typedef struct { unsigned long pte_low, pte_high; } pte_t;
26507 + #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
26508 +- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
26509 ++ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
26510 + #else
26511 + typedef struct { unsigned long long pte; } pte_t;
26512 + #define pte_val(x) ((x).pte)
26513 +diff -urNp linux-2.6.27.10/include/asm-mips/system.h linux-2.6.27.10/include/asm-mips/system.h
26514 +--- linux-2.6.27.10/include/asm-mips/system.h 2008-11-07 12:55:34.000000000 -0500
26515 ++++ linux-2.6.27.10/include/asm-mips/system.h 2008-11-18 03:38:45.000000000 -0500
26516 +@@ -215,6 +215,6 @@ extern void per_cpu_trap_init(void);
26517 + */
26518 + #define __ARCH_WANT_UNLOCKED_CTXSW
26519 +
26520 +-extern unsigned long arch_align_stack(unsigned long sp);
26521 ++#define arch_align_stack(x) ((x) & ALMASK)
26522 +
26523 + #endif /* _ASM_SYSTEM_H */
26524 +diff -urNp linux-2.6.27.10/include/asm-mn10300/kmap_types.h linux-2.6.27.10/include/asm-mn10300/kmap_types.h
26525 +--- linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26526 ++++ linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
26527 +@@ -25,6 +25,7 @@ enum km_type {
26528 + KM_IRQ1,
26529 + KM_SOFTIRQ0,
26530 + KM_SOFTIRQ1,
26531 ++ KM_CLEARPAGE,
26532 + KM_TYPE_NR
26533 + };
26534 +
26535 +diff -urNp linux-2.6.27.10/include/asm-parisc/elf.h linux-2.6.27.10/include/asm-parisc/elf.h
26536 +--- linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-07 12:55:34.000000000 -0500
26537 ++++ linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-18 03:38:45.000000000 -0500
26538 +@@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration..
26539 +
26540 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
26541 +
26542 ++#ifdef CONFIG_PAX_ASLR
26543 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
26544 ++
26545 ++#define PAX_DELTA_MMAP_LEN 16
26546 ++#define PAX_DELTA_STACK_LEN 16
26547 ++#endif
26548 ++
26549 + /* This yields a mask that user programs can use to figure out what
26550 + instruction set this CPU supports. This could be done in user space,
26551 + but it's not easy, and we've already done it here. */
26552 +diff -urNp linux-2.6.27.10/include/asm-parisc/kmap_types.h linux-2.6.27.10/include/asm-parisc/kmap_types.h
26553 +--- linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26554 ++++ linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26555 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26556 + D(10) KM_IRQ1,
26557 + D(11) KM_SOFTIRQ0,
26558 + D(12) KM_SOFTIRQ1,
26559 +-D(13) KM_TYPE_NR
26560 ++D(13) KM_CLEARPAGE,
26561 ++D(14) KM_TYPE_NR
26562 + };
26563 +
26564 + #undef D
26565 +diff -urNp linux-2.6.27.10/include/asm-parisc/pgtable.h linux-2.6.27.10/include/asm-parisc/pgtable.h
26566 +--- linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-07 12:55:34.000000000 -0500
26567 ++++ linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-18 03:38:45.000000000 -0500
26568 +@@ -202,6 +202,17 @@
26569 + #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
26570 + #define PAGE_COPY PAGE_EXECREAD
26571 + #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
26572 ++
26573 ++#ifdef CONFIG_PAX_PAGEEXEC
26574 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
26575 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26576 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26577 ++#else
26578 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
26579 ++# define PAGE_COPY_NOEXEC PAGE_COPY
26580 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
26581 ++#endif
26582 ++
26583 + #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
26584 + #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
26585 + #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
26586 +diff -urNp linux-2.6.27.10/include/asm-um/kmap_types.h linux-2.6.27.10/include/asm-um/kmap_types.h
26587 +--- linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26588 ++++ linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26589 +@@ -23,6 +23,7 @@ enum km_type {
26590 + KM_IRQ1,
26591 + KM_SOFTIRQ0,
26592 + KM_SOFTIRQ1,
26593 ++ KM_CLEARPAGE,
26594 + KM_TYPE_NR
26595 + };
26596 +
26597 +diff -urNp linux-2.6.27.10/include/asm-um/page.h linux-2.6.27.10/include/asm-um/page.h
26598 +--- linux-2.6.27.10/include/asm-um/page.h 2008-11-07 12:55:34.000000000 -0500
26599 ++++ linux-2.6.27.10/include/asm-um/page.h 2008-11-18 03:38:45.000000000 -0500
26600 +@@ -14,6 +14,9 @@
26601 + #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
26602 + #define PAGE_MASK (~(PAGE_SIZE-1))
26603 +
26604 ++#define ktla_ktva(addr) (addr)
26605 ++#define ktva_ktla(addr) (addr)
26606 ++
26607 + #ifndef __ASSEMBLY__
26608 +
26609 + struct page;
26610 +diff -urNp linux-2.6.27.10/include/asm-x86/alternative.h linux-2.6.27.10/include/asm-x86/alternative.h
26611 +--- linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-07 12:55:34.000000000 -0500
26612 ++++ linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-18 03:38:45.000000000 -0500
26613 +@@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab
26614 + " .byte 662b-661b\n" /* sourcelen */ \
26615 + " .byte 664f-663f\n" /* replacementlen */ \
26616 + ".previous\n" \
26617 +- ".section .altinstr_replacement,\"ax\"\n" \
26618 ++ ".section .altinstr_replacement,\"a\"\n" \
26619 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26620 + ".previous" :: "i" (feature) : "memory")
26621 +
26622 +@@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab
26623 + " .byte 662b-661b\n" /* sourcelen */ \
26624 + " .byte 664f-663f\n" /* replacementlen */ \
26625 + ".previous\n" \
26626 +- ".section .altinstr_replacement,\"ax\"\n" \
26627 ++ ".section .altinstr_replacement,\"a\"\n" \
26628 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26629 + ".previous" :: "i" (feature), ##input)
26630 +
26631 +@@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab
26632 + " .byte 662b-661b\n" /* sourcelen */ \
26633 + " .byte 664f-663f\n" /* replacementlen */ \
26634 + ".previous\n" \
26635 +- ".section .altinstr_replacement,\"ax\"\n" \
26636 ++ ".section .altinstr_replacement,\"a\"\n" \
26637 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26638 + ".previous" : output : [feat] "i" (feature), ##input)
26639 +
26640 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_32.h linux-2.6.27.10/include/asm-x86/atomic_32.h
26641 +--- linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-07 12:55:34.000000000 -0500
26642 ++++ linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-18 03:38:45.000000000 -0500
26643 +@@ -47,7 +47,15 @@ typedef struct {
26644 + */
26645 + static inline void atomic_add(int i, atomic_t *v)
26646 + {
26647 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26648 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26649 ++
26650 ++#ifdef CONFIG_PAX_REFCOUNT
26651 ++ "jno 0f\n"
26652 ++ LOCK_PREFIX "subl %1,%0\n"
26653 ++ "into\n0:\n"
26654 ++ _ASM_EXTABLE(0b, 0b)
26655 ++#endif
26656 ++
26657 + : "+m" (v->counter)
26658 + : "ir" (i));
26659 + }
26660 +@@ -61,7 +69,15 @@ static inline void atomic_add(int i, ato
26661 + */
26662 + static inline void atomic_sub(int i, atomic_t *v)
26663 + {
26664 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26665 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26666 ++
26667 ++#ifdef CONFIG_PAX_REFCOUNT
26668 ++ "jno 0f\n"
26669 ++ LOCK_PREFIX "addl %1,%0\n"
26670 ++ "into\n0:\n"
26671 ++ _ASM_EXTABLE(0b, 0b)
26672 ++#endif
26673 ++
26674 + : "+m" (v->counter)
26675 + : "ir" (i));
26676 + }
26677 +@@ -79,7 +95,16 @@ static inline int atomic_sub_and_test(in
26678 + {
26679 + unsigned char c;
26680 +
26681 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26682 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26683 ++
26684 ++#ifdef CONFIG_PAX_REFCOUNT
26685 ++ "jno 0f\n"
26686 ++ LOCK_PREFIX "addl %2,%0\n"
26687 ++ "into\n0:\n"
26688 ++ _ASM_EXTABLE(0b, 0b)
26689 ++#endif
26690 ++
26691 ++ "sete %1\n"
26692 + : "+m" (v->counter), "=qm" (c)
26693 + : "ir" (i) : "memory");
26694 + return c;
26695 +@@ -93,7 +118,18 @@ static inline int atomic_sub_and_test(in
26696 + */
26697 + static inline void atomic_inc(atomic_t *v)
26698 + {
26699 +- asm volatile(LOCK_PREFIX "incl %0"
26700 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26701 ++
26702 ++#ifdef CONFIG_PAX_REFCOUNT
26703 ++ "into\n0:\n"
26704 ++ ".pushsection .fixup,\"ax\"\n"
26705 ++ "1:\n"
26706 ++ LOCK_PREFIX "decl %0\n"
26707 ++ "jmp 0b\n"
26708 ++ ".popsection\n"
26709 ++ _ASM_EXTABLE(0b, 1b)
26710 ++#endif
26711 ++
26712 + : "+m" (v->counter));
26713 + }
26714 +
26715 +@@ -105,7 +141,18 @@ static inline void atomic_inc(atomic_t *
26716 + */
26717 + static inline void atomic_dec(atomic_t *v)
26718 + {
26719 +- asm volatile(LOCK_PREFIX "decl %0"
26720 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26721 ++
26722 ++#ifdef CONFIG_PAX_REFCOUNT
26723 ++ "into\n0:\n"
26724 ++ ".pushsection .fixup,\"ax\"\n"
26725 ++ "1: \n"
26726 ++ LOCK_PREFIX "incl %0\n"
26727 ++ "jmp 0b\n"
26728 ++ ".popsection\n"
26729 ++ _ASM_EXTABLE(0b, 1b)
26730 ++#endif
26731 ++
26732 + : "+m" (v->counter));
26733 + }
26734 +
26735 +@@ -121,7 +168,19 @@ static inline int atomic_dec_and_test(at
26736 + {
26737 + unsigned char c;
26738 +
26739 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26740 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26741 ++
26742 ++#ifdef CONFIG_PAX_REFCOUNT
26743 ++ "into\n0:\n"
26744 ++ ".pushsection .fixup,\"ax\"\n"
26745 ++ "1: \n"
26746 ++ LOCK_PREFIX "incl %0\n"
26747 ++ "jmp 0b\n"
26748 ++ ".popsection\n"
26749 ++ _ASM_EXTABLE(0b, 1b)
26750 ++#endif
26751 ++
26752 ++ "sete %1\n"
26753 + : "+m" (v->counter), "=qm" (c)
26754 + : : "memory");
26755 + return c != 0;
26756 +@@ -139,7 +198,19 @@ static inline int atomic_inc_and_test(at
26757 + {
26758 + unsigned char c;
26759 +
26760 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
26761 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26762 ++
26763 ++#ifdef CONFIG_PAX_REFCOUNT
26764 ++ "into\n0:\n"
26765 ++ ".pushsection .fixup,\"ax\"\n"
26766 ++ "1: \n"
26767 ++ LOCK_PREFIX "decl %0\n"
26768 ++ "jmp 0b\n"
26769 ++ ".popsection\n"
26770 ++ _ASM_EXTABLE(0b, 1b)
26771 ++#endif
26772 ++
26773 ++ "sete %1\n"
26774 + : "+m" (v->counter), "=qm" (c)
26775 + : : "memory");
26776 + return c != 0;
26777 +@@ -158,7 +229,16 @@ static inline int atomic_add_negative(in
26778 + {
26779 + unsigned char c;
26780 +
26781 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
26782 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
26783 ++
26784 ++#ifdef CONFIG_PAX_REFCOUNT
26785 ++ "jno 0f\n"
26786 ++ LOCK_PREFIX "subl %2,%0\n"
26787 ++ "into\n0:\n"
26788 ++ _ASM_EXTABLE(0b, 0b)
26789 ++#endif
26790 ++
26791 ++ "sets %1\n"
26792 + : "+m" (v->counter), "=qm" (c)
26793 + : "ir" (i) : "memory");
26794 + return c;
26795 +@@ -181,7 +261,15 @@ static inline int atomic_add_return(int
26796 + #endif
26797 + /* Modern 486+ processor */
26798 + __i = i;
26799 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
26800 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
26801 ++
26802 ++#ifdef CONFIG_PAX_REFCOUNT
26803 ++ "jno 0f\n"
26804 ++ "movl %0, %1\n"
26805 ++ "into\n0:\n"
26806 ++ _ASM_EXTABLE(0b, 0b)
26807 ++#endif
26808 ++
26809 + : "+r" (i), "+m" (v->counter)
26810 + : : "memory");
26811 + return i + __i;
26812 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_64.h linux-2.6.27.10/include/asm-x86/atomic_64.h
26813 +--- linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-07 12:55:34.000000000 -0500
26814 ++++ linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-18 03:38:45.000000000 -0500
26815 +@@ -48,7 +48,15 @@ typedef struct {
26816 + */
26817 + static inline void atomic_add(int i, atomic_t *v)
26818 + {
26819 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26820 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26821 ++
26822 ++#ifdef CONFIG_PAX_REFCOUNT
26823 ++ "jno 0f\n"
26824 ++ LOCK_PREFIX "subl %1,%0\n"
26825 ++ "int $4\n0:\n"
26826 ++ _ASM_EXTABLE(0b, 0b)
26827 ++#endif
26828 ++
26829 + : "=m" (v->counter)
26830 + : "ir" (i), "m" (v->counter));
26831 + }
26832 +@@ -62,7 +70,15 @@ static inline void atomic_add(int i, ato
26833 + */
26834 + static inline void atomic_sub(int i, atomic_t *v)
26835 + {
26836 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26837 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26838 ++
26839 ++#ifdef CONFIG_PAX_REFCOUNT
26840 ++ "jno 0f\n"
26841 ++ LOCK_PREFIX "addl %1,%0\n"
26842 ++ "int $4\n0:\n"
26843 ++ _ASM_EXTABLE(0b, 0b)
26844 ++#endif
26845 ++
26846 + : "=m" (v->counter)
26847 + : "ir" (i), "m" (v->counter));
26848 + }
26849 +@@ -80,7 +96,16 @@ static inline int atomic_sub_and_test(in
26850 + {
26851 + unsigned char c;
26852 +
26853 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26854 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26855 ++
26856 ++#ifdef CONFIG_PAX_REFCOUNT
26857 ++ "jno 0f\n"
26858 ++ LOCK_PREFIX "addl %2,%0\n"
26859 ++ "int $4\n0:\n"
26860 ++ _ASM_EXTABLE(0b, 0b)
26861 ++#endif
26862 ++
26863 ++ "sete %1\n"
26864 + : "=m" (v->counter), "=qm" (c)
26865 + : "ir" (i), "m" (v->counter) : "memory");
26866 + return c;
26867 +@@ -94,7 +119,19 @@ static inline int atomic_sub_and_test(in
26868 + */
26869 + static inline void atomic_inc(atomic_t *v)
26870 + {
26871 +- asm volatile(LOCK_PREFIX "incl %0"
26872 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26873 ++
26874 ++#ifdef CONFIG_PAX_REFCOUNT
26875 ++ "jno 0f\n"
26876 ++ "int $4\n0:\n"
26877 ++ ".pushsection .fixup,\"ax\"\n"
26878 ++ "1:\n"
26879 ++ LOCK_PREFIX "decl %0\n"
26880 ++ "jmp 0b\n"
26881 ++ ".popsection\n"
26882 ++ _ASM_EXTABLE(0b, 1b)
26883 ++#endif
26884 ++
26885 + : "=m" (v->counter)
26886 + : "m" (v->counter));
26887 + }
26888 +@@ -107,7 +144,19 @@ static inline void atomic_inc(atomic_t *
26889 + */
26890 + static inline void atomic_dec(atomic_t *v)
26891 + {
26892 +- asm volatile(LOCK_PREFIX "decl %0"
26893 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26894 ++
26895 ++#ifdef CONFIG_PAX_REFCOUNT
26896 ++ "jno 0f\n"
26897 ++ "int $4\n0:\n"
26898 ++ ".pushsection .fixup,\"ax\"\n"
26899 ++ "1: \n"
26900 ++ LOCK_PREFIX "incl %0\n"
26901 ++ "jmp 0b\n"
26902 ++ ".popsection\n"
26903 ++ _ASM_EXTABLE(0b, 1b)
26904 ++#endif
26905 ++
26906 + : "=m" (v->counter)
26907 + : "m" (v->counter));
26908 + }
26909 +@@ -124,7 +173,20 @@ static inline int atomic_dec_and_test(at
26910 + {
26911 + unsigned char c;
26912 +
26913 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26914 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26915 ++
26916 ++#ifdef CONFIG_PAX_REFCOUNT
26917 ++ "jno 0f\n"
26918 ++ "int $4\n0:\n"
26919 ++ ".pushsection .fixup,\"ax\"\n"
26920 ++ "1: \n"
26921 ++ LOCK_PREFIX "incl %0\n"
26922 ++ "jmp 0b\n"
26923 ++ ".popsection\n"
26924 ++ _ASM_EXTABLE(0b, 1b)
26925 ++#endif
26926 ++
26927 ++ "sete %1\n"
26928 + : "=m" (v->counter), "=qm" (c)
26929 + : "m" (v->counter) : "memory");
26930 + return c != 0;
26931 +@@ -142,7 +204,20 @@ static inline int atomic_inc_and_test(at
26932 + {
26933 + unsigned char c;
26934 +
26935 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
26936 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26937 ++
26938 ++#ifdef CONFIG_PAX_REFCOUNT
26939 ++ "jno 0f\n"
26940 ++ "int $4\n0:\n"
26941 ++ ".pushsection .fixup,\"ax\"\n"
26942 ++ "1: \n"
26943 ++ LOCK_PREFIX "decl %0\n"
26944 ++ "jmp 0b\n"
26945 ++ ".popsection\n"
26946 ++ _ASM_EXTABLE(0b, 1b)
26947 ++#endif
26948 ++
26949 ++ "sete %1\n"
26950 + : "=m" (v->counter), "=qm" (c)
26951 + : "m" (v->counter) : "memory");
26952 + return c != 0;
26953 +@@ -161,7 +236,16 @@ static inline int atomic_add_negative(in
26954 + {
26955 + unsigned char c;
26956 +
26957 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
26958 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
26959 ++
26960 ++#ifdef CONFIG_PAX_REFCOUNT
26961 ++ "jno 0f\n"
26962 ++ LOCK_PREFIX "subl %2,%0\n"
26963 ++ "int $4\n0:\n"
26964 ++ _ASM_EXTABLE(0b, 0b)
26965 ++#endif
26966 ++
26967 ++ "sets %1\n"
26968 + : "=m" (v->counter), "=qm" (c)
26969 + : "ir" (i), "m" (v->counter) : "memory");
26970 + return c;
26971 +@@ -177,7 +261,15 @@ static inline int atomic_add_negative(in
26972 + static inline int atomic_add_return(int i, atomic_t *v)
26973 + {
26974 + int __i = i;
26975 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
26976 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
26977 ++
26978 ++#ifdef CONFIG_PAX_REFCOUNT
26979 ++ "jno 0f\n"
26980 ++ "movl %0, %1\n"
26981 ++ "int $4\n0:\n"
26982 ++ _ASM_EXTABLE(0b, 0b)
26983 ++#endif
26984 ++
26985 + : "+r" (i), "+m" (v->counter)
26986 + : : "memory");
26987 + return i + __i;
26988 +@@ -226,7 +318,15 @@ typedef struct {
26989 + */
26990 + static inline void atomic64_add(long i, atomic64_t *v)
26991 + {
26992 +- asm volatile(LOCK_PREFIX "addq %1,%0"
26993 ++ asm volatile(LOCK_PREFIX "addq %1,%0\n"
26994 ++
26995 ++#ifdef CONFIG_PAX_REFCOUNT
26996 ++ "jno 0f\n"
26997 ++ LOCK_PREFIX "subq %1,%0\n"
26998 ++ "int $4\n0:\n"
26999 ++ _ASM_EXTABLE(0b, 0b)
27000 ++#endif
27001 ++
27002 + : "=m" (v->counter)
27003 + : "er" (i), "m" (v->counter));
27004 + }
27005 +@@ -240,7 +340,15 @@ static inline void atomic64_add(long i,
27006 + */
27007 + static inline void atomic64_sub(long i, atomic64_t *v)
27008 + {
27009 +- asm volatile(LOCK_PREFIX "subq %1,%0"
27010 ++ asm volatile(LOCK_PREFIX "subq %1,%0\n"
27011 ++
27012 ++#ifdef CONFIG_PAX_REFCOUNT
27013 ++ "jno 0f\n"
27014 ++ LOCK_PREFIX "addq %1,%0\n"
27015 ++ "int $4\n0:\n"
27016 ++ _ASM_EXTABLE(0b, 0b)
27017 ++#endif
27018 ++
27019 + : "=m" (v->counter)
27020 + : "er" (i), "m" (v->counter));
27021 + }
27022 +@@ -258,7 +366,16 @@ static inline int atomic64_sub_and_test(
27023 + {
27024 + unsigned char c;
27025 +
27026 +- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
27027 ++ asm volatile(LOCK_PREFIX "subq %2,%0\n"
27028 ++
27029 ++#ifdef CONFIG_PAX_REFCOUNT
27030 ++ "jno 0f\n"
27031 ++ LOCK_PREFIX "addq %2,%0\n"
27032 ++ "int $4\n0:\n"
27033 ++ _ASM_EXTABLE(0b, 0b)
27034 ++#endif
27035 ++
27036 ++ "sete %1\n"
27037 + : "=m" (v->counter), "=qm" (c)
27038 + : "er" (i), "m" (v->counter) : "memory");
27039 + return c;
27040 +@@ -272,7 +389,19 @@ static inline int atomic64_sub_and_test(
27041 + */
27042 + static inline void atomic64_inc(atomic64_t *v)
27043 + {
27044 +- asm volatile(LOCK_PREFIX "incq %0"
27045 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27046 ++
27047 ++#ifdef CONFIG_PAX_REFCOUNT
27048 ++ "jno 0f\n"
27049 ++ "int $4\n0:\n"
27050 ++ ".pushsection .fixup,\"ax\"\n"
27051 ++ "1:\n"
27052 ++ LOCK_PREFIX "decq %0\n"
27053 ++ "jmp 0b\n"
27054 ++ ".popsection\n"
27055 ++ _ASM_EXTABLE(0b, 1b)
27056 ++#endif
27057 ++
27058 + : "=m" (v->counter)
27059 + : "m" (v->counter));
27060 + }
27061 +@@ -285,7 +414,19 @@ static inline void atomic64_inc(atomic64
27062 + */
27063 + static inline void atomic64_dec(atomic64_t *v)
27064 + {
27065 +- asm volatile(LOCK_PREFIX "decq %0"
27066 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27067 ++
27068 ++#ifdef CONFIG_PAX_REFCOUNT
27069 ++ "jno 0f\n"
27070 ++ "int $4\n0:\n"
27071 ++ ".pushsection .fixup,\"ax\"\n"
27072 ++ "1: \n"
27073 ++ LOCK_PREFIX "incq %0\n"
27074 ++ "jmp 0b\n"
27075 ++ ".popsection\n"
27076 ++ _ASM_EXTABLE(0b, 1b)
27077 ++#endif
27078 ++
27079 + : "=m" (v->counter)
27080 + : "m" (v->counter));
27081 + }
27082 +@@ -302,7 +443,20 @@ static inline int atomic64_dec_and_test(
27083 + {
27084 + unsigned char c;
27085 +
27086 +- asm volatile(LOCK_PREFIX "decq %0; sete %1"
27087 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27088 ++
27089 ++#ifdef CONFIG_PAX_REFCOUNT
27090 ++ "jno 0f\n"
27091 ++ "int $4\n0:\n"
27092 ++ ".pushsection .fixup,\"ax\"\n"
27093 ++ "1: \n"
27094 ++ LOCK_PREFIX "incq %0\n"
27095 ++ "jmp 0b\n"
27096 ++ ".popsection\n"
27097 ++ _ASM_EXTABLE(0b, 1b)
27098 ++#endif
27099 ++
27100 ++ "sete %1\n"
27101 + : "=m" (v->counter), "=qm" (c)
27102 + : "m" (v->counter) : "memory");
27103 + return c != 0;
27104 +@@ -320,7 +474,20 @@ static inline int atomic64_inc_and_test(
27105 + {
27106 + unsigned char c;
27107 +
27108 +- asm volatile(LOCK_PREFIX "incq %0; sete %1"
27109 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27110 ++
27111 ++#ifdef CONFIG_PAX_REFCOUNT
27112 ++ "jno 0f\n"
27113 ++ "int $4\n0:\n"
27114 ++ ".pushsection .fixup,\"ax\"\n"
27115 ++ "1: \n"
27116 ++ LOCK_PREFIX "decq %0\n"
27117 ++ "jmp 0b\n"
27118 ++ ".popsection\n"
27119 ++ _ASM_EXTABLE(0b, 1b)
27120 ++#endif
27121 ++
27122 ++ "sete %1\n"
27123 + : "=m" (v->counter), "=qm" (c)
27124 + : "m" (v->counter) : "memory");
27125 + return c != 0;
27126 +@@ -339,7 +506,16 @@ static inline int atomic64_add_negative(
27127 + {
27128 + unsigned char c;
27129 +
27130 +- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
27131 ++ asm volatile(LOCK_PREFIX "addq %2,%0\n"
27132 ++
27133 ++#ifdef CONFIG_PAX_REFCOUNT
27134 ++ "jno 0f\n"
27135 ++ LOCK_PREFIX "subq %2,%0\n"
27136 ++ "int $4\n0:\n"
27137 ++ _ASM_EXTABLE(0b, 0b)
27138 ++#endif
27139 ++
27140 ++ "sets %1\n"
27141 + : "=m" (v->counter), "=qm" (c)
27142 + : "er" (i), "m" (v->counter) : "memory");
27143 + return c;
27144 +@@ -355,7 +531,15 @@ static inline int atomic64_add_negative(
27145 + static inline long atomic64_add_return(long i, atomic64_t *v)
27146 + {
27147 + long __i = i;
27148 +- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
27149 ++ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
27150 ++
27151 ++#ifdef CONFIG_PAX_REFCOUNT
27152 ++ "jno 0f\n"
27153 ++ "movq %0, %1\n"
27154 ++ "int $4\n0:\n"
27155 ++ _ASM_EXTABLE(0b, 0b)
27156 ++#endif
27157 ++
27158 + : "+r" (i), "+m" (v->counter)
27159 + : : "memory");
27160 + return i + __i;
27161 +diff -urNp linux-2.6.27.10/include/asm-x86/boot.h linux-2.6.27.10/include/asm-x86/boot.h
27162 +--- linux-2.6.27.10/include/asm-x86/boot.h 2008-11-07 12:55:34.000000000 -0500
27163 ++++ linux-2.6.27.10/include/asm-x86/boot.h 2008-11-18 03:38:45.000000000 -0500
27164 +@@ -13,10 +13,15 @@
27165 + #define ASK_VGA 0xfffd /* ask for it at bootup */
27166 +
27167 + /* Physical address where kernel should be loaded. */
27168 +-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27169 ++#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27170 + + (CONFIG_PHYSICAL_ALIGN - 1)) \
27171 + & ~(CONFIG_PHYSICAL_ALIGN - 1))
27172 +
27173 ++#ifndef __ASSEMBLY__
27174 ++extern unsigned char __LOAD_PHYSICAL_ADDR[];
27175 ++#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
27176 ++#endif
27177 ++
27178 + #ifdef CONFIG_X86_64
27179 + #define BOOT_HEAP_SIZE 0x7000
27180 + #define BOOT_STACK_SIZE 0x4000
27181 +diff -urNp linux-2.6.27.10/include/asm-x86/cache.h linux-2.6.27.10/include/asm-x86/cache.h
27182 +--- linux-2.6.27.10/include/asm-x86/cache.h 2008-11-07 12:55:34.000000000 -0500
27183 ++++ linux-2.6.27.10/include/asm-x86/cache.h 2008-11-18 03:38:45.000000000 -0500
27184 +@@ -6,6 +6,7 @@
27185 + #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
27186 +
27187 + #define __read_mostly __attribute__((__section__(".data.read_mostly")))
27188 ++#define __read_only __attribute__((__section__(".data.read_only")))
27189 +
27190 + #ifdef CONFIG_X86_VSMP
27191 + /* vSMP Internode cacheline shift */
27192 +diff -urNp linux-2.6.27.10/include/asm-x86/checksum_32.h linux-2.6.27.10/include/asm-x86/checksum_32.h
27193 +--- linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-07 12:55:34.000000000 -0500
27194 ++++ linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-18 03:38:45.000000000 -0500
27195 +@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
27196 + int len, __wsum sum,
27197 + int *src_err_ptr, int *dst_err_ptr);
27198 +
27199 ++asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
27200 ++ int len, __wsum sum,
27201 ++ int *src_err_ptr, int *dst_err_ptr);
27202 ++
27203 ++asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
27204 ++ int len, __wsum sum,
27205 ++ int *src_err_ptr, int *dst_err_ptr);
27206 ++
27207 + /*
27208 + * Note: when you get a NULL pointer exception here this means someone
27209 + * passed in an incorrect kernel address to one of these functions.
27210 +@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
27211 + int *err_ptr)
27212 + {
27213 + might_sleep();
27214 +- return csum_partial_copy_generic((__force void *)src, dst,
27215 ++ return csum_partial_copy_generic_from_user((__force void *)src, dst,
27216 + len, sum, err_ptr, NULL);
27217 + }
27218 +
27219 +@@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us
27220 + {
27221 + might_sleep();
27222 + if (access_ok(VERIFY_WRITE, dst, len))
27223 +- return csum_partial_copy_generic(src, (__force void *)dst,
27224 ++ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
27225 + len, sum, NULL, err_ptr);
27226 +
27227 + if (len)
27228 +diff -urNp linux-2.6.27.10/include/asm-x86/desc.h linux-2.6.27.10/include/asm-x86/desc.h
27229 +--- linux-2.6.27.10/include/asm-x86/desc.h 2008-11-07 12:55:34.000000000 -0500
27230 ++++ linux-2.6.27.10/include/asm-x86/desc.h 2008-11-18 03:38:45.000000000 -0500
27231 +@@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_
27232 + desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
27233 + desc->type = (info->read_exec_only ^ 1) << 1;
27234 + desc->type |= info->contents << 2;
27235 ++ desc->type |= info->seg_not_present ^ 1;
27236 + desc->s = 1;
27237 + desc->dpl = 0x3;
27238 + desc->p = info->seg_not_present ^ 1;
27239 +@@ -27,16 +28,12 @@ static inline void fill_ldt(struct desc_
27240 + }
27241 +
27242 + extern struct desc_ptr idt_descr;
27243 +-extern gate_desc idt_table[];
27244 +-
27245 +-struct gdt_page {
27246 +- struct desc_struct gdt[GDT_ENTRIES];
27247 +-} __attribute__((aligned(PAGE_SIZE)));
27248 +-DECLARE_PER_CPU(struct gdt_page, gdt_page);
27249 ++extern gate_desc idt_table[256];
27250 +
27251 ++extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
27252 + static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
27253 + {
27254 +- return per_cpu(gdt_page, cpu).gdt;
27255 ++ return cpu_gdt_table[cpu];
27256 + }
27257 +
27258 + #ifdef CONFIG_X86_64
27259 +@@ -65,7 +62,6 @@ static inline void pack_gate(gate_desc *
27260 + gate->b = (base & 0xffff0000) |
27261 + (((0x80 | type | (dpl << 5)) & 0xff) << 8);
27262 + }
27263 +-
27264 + #endif
27265 +
27266 + static inline int desc_empty(const void *ptr)
27267 +@@ -102,19 +98,48 @@ static inline int desc_empty(const void
27268 + static inline void native_write_idt_entry(gate_desc *idt, int entry,
27269 + const gate_desc *gate)
27270 + {
27271 ++
27272 ++#ifdef CONFIG_PAX_KERNEXEC
27273 ++ unsigned long cr0;
27274 ++
27275 ++ pax_open_kernel(cr0);
27276 ++#endif
27277 ++
27278 + memcpy(&idt[entry], gate, sizeof(*gate));
27279 ++
27280 ++#ifdef CONFIG_PAX_KERNEXEC
27281 ++ pax_close_kernel(cr0);
27282 ++#endif
27283 ++
27284 + }
27285 +
27286 + static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
27287 + const void *desc)
27288 + {
27289 ++
27290 ++#ifdef CONFIG_PAX_KERNEXEC
27291 ++ unsigned long cr0;
27292 ++
27293 ++ pax_open_kernel(cr0);
27294 ++#endif
27295 ++
27296 + memcpy(&ldt[entry], desc, 8);
27297 ++
27298 ++#ifdef CONFIG_PAX_KERNEXEC
27299 ++ pax_close_kernel(cr0);
27300 ++#endif
27301 ++
27302 + }
27303 +
27304 + static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
27305 + const void *desc, int type)
27306 + {
27307 + unsigned int size;
27308 ++
27309 ++#ifdef CONFIG_PAX_KERNEXEC
27310 ++ unsigned long cr0;
27311 ++#endif
27312 ++
27313 + switch (type) {
27314 + case DESC_TSS:
27315 + size = sizeof(tss_desc);
27316 +@@ -126,7 +151,17 @@ static inline void native_write_gdt_entr
27317 + size = sizeof(struct desc_struct);
27318 + break;
27319 + }
27320 ++
27321 ++#ifdef CONFIG_PAX_KERNEXEC
27322 ++ pax_open_kernel(cr0);
27323 ++#endif
27324 ++
27325 + memcpy(&gdt[entry], desc, size);
27326 ++
27327 ++#ifdef CONFIG_PAX_KERNEXEC
27328 ++ pax_close_kernel(cr0);
27329 ++#endif
27330 ++
27331 + }
27332 +
27333 + static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
27334 +@@ -198,7 +233,19 @@ static inline void native_set_ldt(const
27335 +
27336 + static inline void native_load_tr_desc(void)
27337 + {
27338 ++
27339 ++#ifdef CONFIG_PAX_KERNEXEC
27340 ++ unsigned long cr0;
27341 ++
27342 ++ pax_open_kernel(cr0);
27343 ++#endif
27344 ++
27345 + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
27346 ++
27347 ++#ifdef CONFIG_PAX_KERNEXEC
27348 ++ pax_close_kernel(cr0);
27349 ++#endif
27350 ++
27351 + }
27352 +
27353 + static inline void native_load_gdt(const struct desc_ptr *dtr)
27354 +@@ -233,8 +280,19 @@ static inline void native_load_tls(struc
27355 + unsigned int i;
27356 + struct desc_struct *gdt = get_cpu_gdt_table(cpu);
27357 +
27358 ++#ifdef CONFIG_PAX_KERNEXEC
27359 ++ unsigned long cr0;
27360 ++
27361 ++ pax_open_kernel(cr0);
27362 ++#endif
27363 ++
27364 + for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
27365 + gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
27366 ++
27367 ++#ifdef CONFIG_PAX_KERNEXEC
27368 ++ pax_close_kernel(cr0);
27369 ++#endif
27370 ++
27371 + }
27372 +
27373 + #define _LDT_empty(info) \
27374 +@@ -372,6 +430,18 @@ static inline void set_system_gate_ist(i
27375 + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
27376 + }
27377 +
27378 ++#ifdef CONFIG_X86_32
27379 ++static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
27380 ++{
27381 ++ struct desc_struct d;
27382 ++
27383 ++ if (likely(limit))
27384 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
27385 ++ pack_descriptor(&d, base, limit, 0xFB, 0xC);
27386 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
27387 ++}
27388 ++#endif
27389 ++
27390 + #else
27391 + /*
27392 + * GET_DESC_BASE reads the descriptor base of the specified segment.
27393 +diff -urNp linux-2.6.27.10/include/asm-x86/e820.h linux-2.6.27.10/include/asm-x86/e820.h
27394 +--- linux-2.6.27.10/include/asm-x86/e820.h 2008-11-07 12:55:34.000000000 -0500
27395 ++++ linux-2.6.27.10/include/asm-x86/e820.h 2008-11-18 03:38:45.000000000 -0500
27396 +@@ -131,7 +131,7 @@ extern char *memory_setup(void);
27397 + #define ISA_END_ADDRESS 0x100000
27398 + #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
27399 +
27400 +-#define BIOS_BEGIN 0x000a0000
27401 ++#define BIOS_BEGIN 0x000c0000
27402 + #define BIOS_END 0x00100000
27403 +
27404 + #ifdef __KERNEL__
27405 +diff -urNp linux-2.6.27.10/include/asm-x86/elf.h linux-2.6.27.10/include/asm-x86/elf.h
27406 +--- linux-2.6.27.10/include/asm-x86/elf.h 2008-11-07 12:55:34.000000000 -0500
27407 ++++ linux-2.6.27.10/include/asm-x86/elf.h 2008-11-18 03:38:45.000000000 -0500
27408 +@@ -251,7 +251,25 @@ extern int force_personality32;
27409 + the loader. We need to make sure that it is out of the way of the program
27410 + that it will "exec", and that there is sufficient room for the brk. */
27411 +
27412 ++#ifdef CONFIG_PAX_SEGMEXEC
27413 ++#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
27414 ++#else
27415 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
27416 ++#endif
27417 ++
27418 ++#ifdef CONFIG_PAX_ASLR
27419 ++#ifdef CONFIG_X86_32
27420 ++#define PAX_ELF_ET_DYN_BASE 0x10000000UL
27421 ++
27422 ++#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27423 ++#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27424 ++#else
27425 ++#define PAX_ELF_ET_DYN_BASE 0x400000UL
27426 ++
27427 ++#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27428 ++#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27429 ++#endif
27430 ++#endif
27431 +
27432 + /* This yields a mask that user programs can use to figure out what
27433 + instruction set this CPU supports. This could be done in user space,
27434 +@@ -303,8 +321,7 @@ do { \
27435 + #define ARCH_DLINFO \
27436 + do { \
27437 + if (vdso_enabled) \
27438 +- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
27439 +- (unsigned long)current->mm->context.vdso); \
27440 ++ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
27441 + } while (0)
27442 +
27443 + #define AT_SYSINFO 32
27444 +@@ -315,7 +332,7 @@ do { \
27445 +
27446 + #endif /* !CONFIG_X86_32 */
27447 +
27448 +-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
27449 ++#define VDSO_CURRENT_BASE (current->mm->context.vdso)
27450 +
27451 + #define VDSO_ENTRY \
27452 + ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
27453 +@@ -329,7 +346,4 @@ extern int arch_setup_additional_pages(s
27454 + extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
27455 + #define compat_arch_setup_additional_pages syscall32_setup_pages
27456 +
27457 +-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
27458 +-#define arch_randomize_brk arch_randomize_brk
27459 +-
27460 + #endif
27461 +diff -urNp linux-2.6.27.10/include/asm-x86/futex.h linux-2.6.27.10/include/asm-x86/futex.h
27462 +--- linux-2.6.27.10/include/asm-x86/futex.h 2008-11-07 12:55:34.000000000 -0500
27463 ++++ linux-2.6.27.10/include/asm-x86/futex.h 2008-11-18 03:38:45.000000000 -0500
27464 +@@ -11,6 +11,40 @@
27465 + #include <asm/processor.h>
27466 + #include <asm/system.h>
27467 +
27468 ++#ifdef CONFIG_X86_32
27469 ++#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27470 ++ asm volatile( \
27471 ++ "movw\t%w6, %%ds\n" \
27472 ++ "1:\t" insn "\n" \
27473 ++ "2:\tpushl\t%%ss\n" \
27474 ++ "\tpopl\t%%ds\n" \
27475 ++ "\t.section .fixup,\"ax\"\n" \
27476 ++ "3:\tmov\t%3, %1\n" \
27477 ++ "\tjmp\t2b\n" \
27478 ++ "\t.previous\n" \
27479 ++ _ASM_EXTABLE(1b, 3b) \
27480 ++ : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
27481 ++ : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS))
27482 ++
27483 ++#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
27484 ++ asm volatile("movw\t%w7, %%es\n" \
27485 ++ "1:\tmovl\t%%es:%2, %0\n" \
27486 ++ "\tmovl\t%0, %3\n" \
27487 ++ "\t" insn "\n" \
27488 ++ "2:\tlock; cmpxchgl %3, %%es:%2\n" \
27489 ++ "\tjnz\t1b\n" \
27490 ++ "3:\tpushl\t%%ss\n" \
27491 ++ "\tpopl\t%%es\n" \
27492 ++ "\t.section .fixup,\"ax\"\n" \
27493 ++ "4:\tmov\t%5, %1\n" \
27494 ++ "\tjmp\t3b\n" \
27495 ++ "\t.previous\n" \
27496 ++ _ASM_EXTABLE(1b, 4b) \
27497 ++ _ASM_EXTABLE(2b, 4b) \
27498 ++ : "=&a" (oldval), "=&r" (ret), \
27499 ++ "+m" (*uaddr), "=&r" (tem) \
27500 ++ : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS))
27501 ++#else
27502 + #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27503 + asm volatile("1:\t" insn "\n" \
27504 + "2:\t.section .fixup,\"ax\"\n" \
27505 +@@ -36,8 +70,9 @@
27506 + : "=&a" (oldval), "=&r" (ret), \
27507 + "+m" (*uaddr), "=&r" (tem) \
27508 + : "r" (oparg), "i" (-EFAULT), "1" (0))
27509 ++#endif
27510 +
27511 +-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
27512 ++static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
27513 + {
27514 + int op = (encoded_op >> 28) & 7;
27515 + int cmp = (encoded_op >> 24) & 15;
27516 +@@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser
27517 +
27518 + switch (op) {
27519 + case FUTEX_OP_SET:
27520 ++#ifdef CONFIG_X86_32
27521 ++ __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg);
27522 ++#else
27523 + __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
27524 ++#endif
27525 + break;
27526 + case FUTEX_OP_ADD:
27527 ++#ifdef CONFIG_X86_32
27528 ++ __futex_atomic_op1("lock ; xaddl %0, %%ds:%2", ret, oldval,
27529 ++ uaddr, oparg);
27530 ++#else
27531 + __futex_atomic_op1("lock; xaddl %0, %2", ret, oldval,
27532 + uaddr, oparg);
27533 ++#endif
27534 + break;
27535 + case FUTEX_OP_OR:
27536 + __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg);
27537 +@@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser
27538 + return ret;
27539 + }
27540 +
27541 +-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
27542 ++static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
27543 + int newval)
27544 + {
27545 +
27546 +@@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i
27547 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
27548 + return -EFAULT;
27549 +
27550 +- asm volatile("1:\tlock; cmpxchgl %3, %1\n"
27551 ++ asm volatile(
27552 ++#ifdef CONFIG_X86_32
27553 ++ "\tmovw %w5, %%ds\n"
27554 ++ "1:\tlock; cmpxchgl %3, %1\n"
27555 ++ "2:\tpushl %%ss\n"
27556 ++ "\tpopl %%ds\n"
27557 ++ "\t.section .fixup, \"ax\"\n"
27558 ++#else
27559 ++ "1:\tlock; cmpxchgl %3, %1\n"
27560 + "2:\t.section .fixup, \"ax\"\n"
27561 ++#endif
27562 + "3:\tmov %2, %0\n"
27563 + "\tjmp 2b\n"
27564 + "\t.previous\n"
27565 + _ASM_EXTABLE(1b, 3b)
27566 + : "=a" (oldval), "+m" (*uaddr)
27567 ++#ifdef CONFIG_X86_32
27568 ++ : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS)
27569 ++#else
27570 + : "i" (-EFAULT), "r" (newval), "0" (oldval)
27571 ++#endif
27572 + : "memory"
27573 + );
27574 +
27575 +diff -urNp linux-2.6.27.10/include/asm-x86/i387.h linux-2.6.27.10/include/asm-x86/i387.h
27576 +--- linux-2.6.27.10/include/asm-x86/i387.h 2008-11-07 12:55:34.000000000 -0500
27577 ++++ linux-2.6.27.10/include/asm-x86/i387.h 2008-11-18 03:38:45.000000000 -0500
27578 +@@ -159,13 +159,8 @@ static inline void restore_fpu(struct ta
27579 + }
27580 +
27581 + /* We need a safe address that is cheap to find and that is already
27582 +- in L1 during context switch. The best choices are unfortunately
27583 +- different for UP and SMP */
27584 +-#ifdef CONFIG_SMP
27585 +-#define safe_address (__per_cpu_offset[0])
27586 +-#else
27587 +-#define safe_address (kstat_cpu(0).cpustat.user)
27588 +-#endif
27589 ++ in L1 during context switch. */
27590 ++#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
27591 +
27592 + /*
27593 + * These must be called with preempt disabled
27594 +diff -urNp linux-2.6.27.10/include/asm-x86/io_64.h linux-2.6.27.10/include/asm-x86/io_64.h
27595 +--- linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-07 12:55:34.000000000 -0500
27596 ++++ linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-18 03:38:45.000000000 -0500
27597 +@@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne
27598 + }
27599 + #endif
27600 +
27601 ++#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
27602 ++static inline int valid_phys_addr_range (unsigned long addr, size_t count)
27603 ++{
27604 ++ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27605 ++}
27606 ++
27607 ++static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count)
27608 ++{
27609 ++ return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27610 ++}
27611 ++
27612 + /*
27613 + * Change "struct page" to physical address.
27614 + */
27615 +diff -urNp linux-2.6.27.10/include/asm-x86/irqflags.h linux-2.6.27.10/include/asm-x86/irqflags.h
27616 +--- linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-07 12:55:34.000000000 -0500
27617 ++++ linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-18 03:38:45.000000000 -0500
27618 +@@ -141,6 +141,8 @@ static inline unsigned long __raw_local_
27619 + #define INTERRUPT_RETURN iret
27620 + #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
27621 + #define GET_CR0_INTO_EAX movl %cr0, %eax
27622 ++#define GET_CR0_INTO_EDX movl %cr0, %edx
27623 ++#define SET_CR0_FROM_EDX movl %edx, %cr0
27624 + #endif
27625 +
27626 +
27627 +diff -urNp linux-2.6.27.10/include/asm-x86/kmap_types.h linux-2.6.27.10/include/asm-x86/kmap_types.h
27628 +--- linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
27629 ++++ linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
27630 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
27631 + D(10) KM_IRQ1,
27632 + D(11) KM_SOFTIRQ0,
27633 + D(12) KM_SOFTIRQ1,
27634 +-D(13) KM_TYPE_NR
27635 ++D(13) KM_CLEARPAGE,
27636 ++D(14) KM_TYPE_NR
27637 + };
27638 +
27639 + #undef D
27640 +diff -urNp linux-2.6.27.10/include/asm-x86/linkage.h linux-2.6.27.10/include/asm-x86/linkage.h
27641 +--- linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-07 12:55:34.000000000 -0500
27642 ++++ linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-18 03:38:45.000000000 -0500
27643 +@@ -7,6 +7,11 @@
27644 + #ifdef CONFIG_X86_64
27645 + #define __ALIGN .p2align 4,,15
27646 + #define __ALIGN_STR ".p2align 4,,15"
27647 ++#else
27648 ++#ifdef CONFIG_X86_ALIGNMENT_16
27649 ++#define __ALIGN .align 16,0x90
27650 ++#define __ALIGN_STR ".align 16,0x90"
27651 ++#endif
27652 + #endif
27653 +
27654 + #ifdef CONFIG_X86_32
27655 +@@ -52,10 +57,5 @@
27656 +
27657 + #endif
27658 +
27659 +-#ifdef CONFIG_X86_ALIGNMENT_16
27660 +-#define __ALIGN .align 16,0x90
27661 +-#define __ALIGN_STR ".align 16,0x90"
27662 +-#endif
27663 +-
27664 + #endif
27665 +
27666 +diff -urNp linux-2.6.27.10/include/asm-x86/local.h linux-2.6.27.10/include/asm-x86/local.h
27667 +--- linux-2.6.27.10/include/asm-x86/local.h 2008-11-07 12:55:34.000000000 -0500
27668 ++++ linux-2.6.27.10/include/asm-x86/local.h 2008-11-18 03:38:45.000000000 -0500
27669 +@@ -18,26 +18,90 @@ typedef struct {
27670 +
27671 + static inline void local_inc(local_t *l)
27672 + {
27673 +- asm volatile(_ASM_INC "%0"
27674 ++ asm volatile(_ASM_INC "%0\n"
27675 ++
27676 ++#ifdef CONFIG_PAX_REFCOUNT
27677 ++#ifdef CONFIG_X86_32
27678 ++ "into\n0:\n"
27679 ++#else
27680 ++ "jno 0f\n"
27681 ++ "int $4\n0:\n"
27682 ++#endif
27683 ++ ".pushsection .fixup,\"ax\"\n"
27684 ++ "1:\n"
27685 ++ _ASM_DEC "%0\n"
27686 ++ "jmp 0b\n"
27687 ++ ".popsection\n"
27688 ++ _ASM_EXTABLE(0b, 1b)
27689 ++#endif
27690 ++
27691 + : "+m" (l->a.counter));
27692 + }
27693 +
27694 + static inline void local_dec(local_t *l)
27695 + {
27696 +- asm volatile(_ASM_DEC "%0"
27697 ++ asm volatile(_ASM_DEC "%0\n"
27698 ++
27699 ++#ifdef CONFIG_PAX_REFCOUNT
27700 ++#ifdef CONFIG_X86_32
27701 ++ "into\n0:\n"
27702 ++#else
27703 ++ "jno 0f\n"
27704 ++ "int $4\n0:\n"
27705 ++#endif
27706 ++ ".pushsection .fixup,\"ax\"\n"
27707 ++ "1:\n"
27708 ++ _ASM_INC "%0\n"
27709 ++ "jmp 0b\n"
27710 ++ ".popsection\n"
27711 ++ _ASM_EXTABLE(0b, 1b)
27712 ++#endif
27713 ++
27714 + : "+m" (l->a.counter));
27715 + }
27716 +
27717 + static inline void local_add(long i, local_t *l)
27718 + {
27719 +- asm volatile(_ASM_ADD "%1,%0"
27720 ++ asm volatile(_ASM_ADD "%1,%0\n"
27721 ++
27722 ++#ifdef CONFIG_PAX_REFCOUNT
27723 ++#ifdef CONFIG_X86_32
27724 ++ "into\n0:\n"
27725 ++#else
27726 ++ "jno 0f\n"
27727 ++ "int $4\n0:\n"
27728 ++#endif
27729 ++ ".pushsection .fixup,\"ax\"\n"
27730 ++ "1:\n"
27731 ++ _ASM_SUB "%1,%0\n"
27732 ++ "jmp 0b\n"
27733 ++ ".popsection\n"
27734 ++ _ASM_EXTABLE(0b, 1b)
27735 ++#endif
27736 ++
27737 + : "+m" (l->a.counter)
27738 + : "ir" (i));
27739 + }
27740 +
27741 + static inline void local_sub(long i, local_t *l)
27742 + {
27743 +- asm volatile(_ASM_SUB "%1,%0"
27744 ++ asm volatile(_ASM_SUB "%1,%0\n"
27745 ++
27746 ++#ifdef CONFIG_PAX_REFCOUNT
27747 ++#ifdef CONFIG_X86_32
27748 ++ "into\n0:\n"
27749 ++#else
27750 ++ "jno 0f\n"
27751 ++ "int $4\n0:\n"
27752 ++#endif
27753 ++ ".pushsection .fixup,\"ax\"\n"
27754 ++ "1:\n"
27755 ++ _ASM_ADD "%1,%0\n"
27756 ++ "jmp 0b\n"
27757 ++ ".popsection\n"
27758 ++ _ASM_EXTABLE(0b, 1b)
27759 ++#endif
27760 ++
27761 + : "+m" (l->a.counter)
27762 + : "ir" (i));
27763 + }
27764 +@@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon
27765 + {
27766 + unsigned char c;
27767 +
27768 +- asm volatile(_ASM_SUB "%2,%0; sete %1"
27769 ++ asm volatile(_ASM_SUB "%2,%0\n"
27770 ++
27771 ++#ifdef CONFIG_PAX_REFCOUNT
27772 ++#ifdef CONFIG_X86_32
27773 ++ "into\n0:\n"
27774 ++#else
27775 ++ "jno 0f\n"
27776 ++ "int $4\n0:\n"
27777 ++#endif
27778 ++ ".pushsection .fixup,\"ax\"\n"
27779 ++ "1:\n"
27780 ++ _ASM_ADD "%2,%0\n"
27781 ++ "jmp 0b\n"
27782 ++ ".popsection\n"
27783 ++ _ASM_EXTABLE(0b, 1b)
27784 ++#endif
27785 ++
27786 ++ "sete %1\n"
27787 + : "+m" (l->a.counter), "=qm" (c)
27788 + : "ir" (i) : "memory");
27789 + return c;
27790 +@@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc
27791 + {
27792 + unsigned char c;
27793 +
27794 +- asm volatile(_ASM_DEC "%0; sete %1"
27795 ++ asm volatile(_ASM_DEC "%0\n"
27796 ++
27797 ++#ifdef CONFIG_PAX_REFCOUNT
27798 ++#ifdef CONFIG_X86_32
27799 ++ "into\n0:\n"
27800 ++#else
27801 ++ "jno 0f\n"
27802 ++ "int $4\n0:\n"
27803 ++#endif
27804 ++ ".pushsection .fixup,\"ax\"\n"
27805 ++ "1:\n"
27806 ++ _ASM_INC "%0\n"
27807 ++ "jmp 0b\n"
27808 ++ ".popsection\n"
27809 ++ _ASM_EXTABLE(0b, 1b)
27810 ++#endif
27811 ++
27812 ++ "sete %1\n"
27813 + : "+m" (l->a.counter), "=qm" (c)
27814 + : : "memory");
27815 + return c != 0;
27816 +@@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc
27817 + {
27818 + unsigned char c;
27819 +
27820 +- asm volatile(_ASM_INC "%0; sete %1"
27821 ++ asm volatile(_ASM_INC "%0\n"
27822 ++
27823 ++#ifdef CONFIG_PAX_REFCOUNT
27824 ++#ifdef CONFIG_X86_32
27825 ++ "into\n0:\n"
27826 ++#else
27827 ++ "jno 0f\n"
27828 ++ "int $4\n0:\n"
27829 ++#endif
27830 ++ ".pushsection .fixup,\"ax\"\n"
27831 ++ "1:\n"
27832 ++ _ASM_DEC "%0\n"
27833 ++ "jmp 0b\n"
27834 ++ ".popsection\n"
27835 ++ _ASM_EXTABLE(0b, 1b)
27836 ++#endif
27837 ++
27838 ++ "sete %1\n"
27839 + : "+m" (l->a.counter), "=qm" (c)
27840 + : : "memory");
27841 + return c != 0;
27842 +@@ -110,7 +225,24 @@ static inline int local_add_negative(lon
27843 + {
27844 + unsigned char c;
27845 +
27846 +- asm volatile(_ASM_ADD "%2,%0; sets %1"
27847 ++ asm volatile(_ASM_ADD "%2,%0\n"
27848 ++
27849 ++#ifdef CONFIG_PAX_REFCOUNT
27850 ++#ifdef CONFIG_X86_32
27851 ++ "into\n0:\n"
27852 ++#else
27853 ++ "jno 0f\n"
27854 ++ "int $4\n0:\n"
27855 ++#endif
27856 ++ ".pushsection .fixup,\"ax\"\n"
27857 ++ "1:\n"
27858 ++ _ASM_SUB "%2,%0\n"
27859 ++ "jmp 0b\n"
27860 ++ ".popsection\n"
27861 ++ _ASM_EXTABLE(0b, 1b)
27862 ++#endif
27863 ++
27864 ++ "sets %1\n"
27865 + : "+m" (l->a.counter), "=qm" (c)
27866 + : "ir" (i) : "memory");
27867 + return c;
27868 +@@ -133,7 +265,23 @@ static inline long local_add_return(long
27869 + #endif
27870 + /* Modern 486+ processor */
27871 + __i = i;
27872 +- asm volatile(_ASM_XADD "%0, %1;"
27873 ++ asm volatile(_ASM_XADD "%0, %1\n"
27874 ++
27875 ++#ifdef CONFIG_PAX_REFCOUNT
27876 ++#ifdef CONFIG_X86_32
27877 ++ "into\n0:\n"
27878 ++#else
27879 ++ "jno 0f\n"
27880 ++ "int $4\n0:\n"
27881 ++#endif
27882 ++ ".pushsection .fixup,\"ax\"\n"
27883 ++ "1:\n"
27884 ++ _ASM_MOV_UL "%0,%1\n"
27885 ++ "jmp 0b\n"
27886 ++ ".popsection\n"
27887 ++ _ASM_EXTABLE(0b, 1b)
27888 ++#endif
27889 ++
27890 + : "+r" (i), "+m" (l->a.counter)
27891 + : : "memory");
27892 + return i + __i;
27893 +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
27894 +--- linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-07 12:55:34.000000000 -0500
27895 ++++ linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-18 03:38:45.000000000 -0500
27896 +@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
27897 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27898 + "pushl %%edi\n\t"
27899 + "pushl %%ebp\n\t"
27900 +- "lcall *%%cs:apm_bios_entry\n\t"
27901 ++ "lcall *%%ss:apm_bios_entry\n\t"
27902 + "setc %%al\n\t"
27903 + "popl %%ebp\n\t"
27904 + "popl %%edi\n\t"
27905 +@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
27906 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27907 + "pushl %%edi\n\t"
27908 + "pushl %%ebp\n\t"
27909 +- "lcall *%%cs:apm_bios_entry\n\t"
27910 ++ "lcall *%%ss:apm_bios_entry\n\t"
27911 + "setc %%bl\n\t"
27912 + "popl %%ebp\n\t"
27913 + "popl %%edi\n\t"
27914 +diff -urNp linux-2.6.27.10/include/asm-x86/mman.h linux-2.6.27.10/include/asm-x86/mman.h
27915 +--- linux-2.6.27.10/include/asm-x86/mman.h 2008-11-07 12:55:34.000000000 -0500
27916 ++++ linux-2.6.27.10/include/asm-x86/mman.h 2008-11-18 03:38:45.000000000 -0500
27917 +@@ -17,4 +17,14 @@
27918 + #define MCL_CURRENT 1 /* lock all current mappings */
27919 + #define MCL_FUTURE 2 /* lock all future mappings */
27920 +
27921 ++#ifdef __KERNEL__
27922 ++#ifndef __ASSEMBLY__
27923 ++#ifdef CONFIG_X86_32
27924 ++#define arch_mmap_check i386_mmap_check
27925 ++int i386_mmap_check(unsigned long addr, unsigned long len,
27926 ++ unsigned long flags);
27927 ++#endif
27928 ++#endif
27929 ++#endif
27930 ++
27931 + #endif /* _ASM_X86_MMAN_H */
27932 +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
27933 +--- linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-07 12:55:34.000000000 -0500
27934 ++++ linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-18 03:38:45.000000000 -0500
27935 +@@ -33,6 +33,22 @@ static inline void switch_mm(struct mm_s
27936 + */
27937 + if (unlikely(prev->context.ldt != next->context.ldt))
27938 + load_LDT_nolock(&next->context);
27939 ++
27940 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
27941 ++ if (!nx_enabled) {
27942 ++ smp_mb__before_clear_bit();
27943 ++ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
27944 ++ smp_mb__after_clear_bit();
27945 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
27946 ++ }
27947 ++#endif
27948 ++
27949 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27950 ++ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
27951 ++ prev->context.user_cs_limit != next->context.user_cs_limit))
27952 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
27953 ++#endif
27954 ++
27955 + }
27956 + #ifdef CONFIG_SMP
27957 + else {
27958 +@@ -45,6 +61,19 @@ static inline void switch_mm(struct mm_s
27959 + */
27960 + load_cr3(next->pgd);
27961 + load_LDT_nolock(&next->context);
27962 ++
27963 ++#ifdef CONFIG_PAX_PAGEEXEC
27964 ++ if (!nx_enabled)
27965 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
27966 ++#endif
27967 ++
27968 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27969 ++#ifdef CONFIG_PAX_PAGEEXEC
27970 ++ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
27971 ++#endif
27972 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
27973 ++#endif
27974 ++
27975 + }
27976 + }
27977 + #endif
27978 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu.h linux-2.6.27.10/include/asm-x86/mmu.h
27979 +--- linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-07 12:55:34.000000000 -0500
27980 ++++ linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-18 03:38:45.000000000 -0500
27981 +@@ -11,13 +11,26 @@
27982 + * cpu_vm_mask is used to optimize ldt flushing.
27983 + */
27984 + typedef struct {
27985 +- void *ldt;
27986 ++ struct desc_struct *ldt;
27987 + #ifdef CONFIG_X86_64
27988 + rwlock_t ldtlock;
27989 + #endif
27990 + int size;
27991 + struct mutex lock;
27992 +- void *vdso;
27993 ++ unsigned long vdso;
27994 ++
27995 ++#ifdef CONFIG_X86_32
27996 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27997 ++ unsigned long user_cs_base;
27998 ++ unsigned long user_cs_limit;
27999 ++
28000 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
28001 ++ cpumask_t cpu_user_cs_mask;
28002 ++#endif
28003 ++
28004 ++#endif
28005 ++#endif
28006 ++
28007 + } mm_context_t;
28008 +
28009 + #ifdef CONFIG_SMP
28010 +diff -urNp linux-2.6.27.10/include/asm-x86/module.h linux-2.6.27.10/include/asm-x86/module.h
28011 +--- linux-2.6.27.10/include/asm-x86/module.h 2008-11-07 12:55:34.000000000 -0500
28012 ++++ linux-2.6.27.10/include/asm-x86/module.h 2008-11-18 03:38:45.000000000 -0500
28013 +@@ -76,7 +76,12 @@ struct mod_arch_specific {};
28014 + # else
28015 + # define MODULE_STACKSIZE ""
28016 + # endif
28017 +-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
28018 ++# ifdef CONFIG_GRKERNSEC
28019 ++# define MODULE_GRSEC "GRSECURITY "
28020 ++# else
28021 ++# define MODULE_GRSEC ""
28022 ++# endif
28023 ++# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC
28024 + #endif
28025 +
28026 + #endif /* _ASM_MODULE_H */
28027 +diff -urNp linux-2.6.27.10/include/asm-x86/page_32.h linux-2.6.27.10/include/asm-x86/page_32.h
28028 +--- linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-07 12:55:34.000000000 -0500
28029 ++++ linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-18 03:38:45.000000000 -0500
28030 +@@ -13,6 +13,23 @@
28031 + */
28032 + #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
28033 +
28034 ++#ifdef CONFIG_PAX_KERNEXEC
28035 ++#ifndef __ASSEMBLY__
28036 ++extern unsigned char MODULES_VADDR[];
28037 ++extern unsigned char MODULES_END[];
28038 ++extern unsigned char KERNEL_TEXT_OFFSET[];
28039 ++#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET)
28040 ++#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET)
28041 ++#endif
28042 ++#else
28043 ++#define ktla_ktva(addr) (addr)
28044 ++#define ktva_ktla(addr) (addr)
28045 ++#endif
28046 ++
28047 ++#ifdef CONFIG_PAX_PAGEEXEC
28048 ++#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1
28049 ++#endif
28050 ++
28051 + #ifdef CONFIG_4KSTACKS
28052 + #define THREAD_ORDER 0
28053 + #else
28054 +diff -urNp linux-2.6.27.10/include/asm-x86/page_64.h linux-2.6.27.10/include/asm-x86/page_64.h
28055 +--- linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-07 12:55:34.000000000 -0500
28056 ++++ linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-18 03:38:45.000000000 -0500
28057 +@@ -49,6 +49,9 @@
28058 + #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
28059 + #define __START_KERNEL_map _AC(0xffffffff80000000, UL)
28060 +
28061 ++#define ktla_ktva(addr) (addr)
28062 ++#define ktva_ktla(addr) (addr)
28063 ++
28064 + /* See Documentation/x86_64/mm.txt for a description of the memory map. */
28065 + #define __PHYSICAL_MASK_SHIFT 46
28066 + #define __VIRTUAL_MASK_SHIFT 48
28067 +@@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign
28068 + #define pfn_valid(pfn) ((pfn) < max_pfn)
28069 + #endif
28070 +
28071 ++#define nx_enabled (1)
28072 +
28073 + #endif /* _X86_64_PAGE_H */
28074 +diff -urNp linux-2.6.27.10/include/asm-x86/paravirt.h linux-2.6.27.10/include/asm-x86/paravirt.h
28075 +--- linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-07 12:55:34.000000000 -0500
28076 ++++ linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-18 03:38:45.000000000 -0500
28077 +@@ -1557,7 +1557,7 @@ static inline unsigned long __raw_local_
28078 + #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
28079 + #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
28080 + #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
28081 +-#define PARA_INDIRECT(addr) *%cs:addr
28082 ++#define PARA_INDIRECT(addr) *%ss:addr
28083 + #endif
28084 +
28085 + #define INTERRUPT_RETURN \
28086 +diff -urNp linux-2.6.27.10/include/asm-x86/pda.h linux-2.6.27.10/include/asm-x86/pda.h
28087 +--- linux-2.6.27.10/include/asm-x86/pda.h 2008-11-07 12:55:34.000000000 -0500
28088 ++++ linux-2.6.27.10/include/asm-x86/pda.h 2008-11-18 03:38:45.000000000 -0500
28089 +@@ -16,11 +16,9 @@ struct x8664_pda {
28090 + unsigned long oldrsp; /* 24 user rsp for system call */
28091 + int irqcount; /* 32 Irq nesting counter. Starts -1 */
28092 + unsigned int cpunumber; /* 36 Logical CPU number */
28093 +-#ifdef CONFIG_CC_STACKPROTECTOR
28094 + unsigned long stack_canary; /* 40 stack canary value */
28095 + /* gcc-ABI: this canary MUST be at
28096 + offset 40!!! */
28097 +-#endif
28098 + char *irqstackptr;
28099 + short nodenumber; /* number of current node (32k max) */
28100 + short in_bootmem; /* pda lives in bootmem */
28101 +diff -urNp linux-2.6.27.10/include/asm-x86/percpu.h linux-2.6.27.10/include/asm-x86/percpu.h
28102 +--- linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-07 12:55:34.000000000 -0500
28103 ++++ linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-18 03:38:45.000000000 -0500
28104 +@@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda);
28105 +
28106 + #define __my_cpu_offset x86_read_percpu(this_cpu_off)
28107 +
28108 ++#include <asm-generic/sections.h>
28109 ++#include <linux/threads.h>
28110 ++#define __per_cpu_offset __per_cpu_offset
28111 ++extern unsigned long __per_cpu_offset[NR_CPUS];
28112 ++#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start)
28113 ++
28114 + /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
28115 + #define __percpu_seg "%%fs:"
28116 +
28117 +diff -urNp linux-2.6.27.10/include/asm-x86/pgalloc.h linux-2.6.27.10/include/asm-x86/pgalloc.h
28118 +--- linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-07 12:55:34.000000000 -0500
28119 ++++ linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-18 03:38:45.000000000 -0500
28120 +@@ -51,7 +51,7 @@ static inline void pmd_populate_kernel(s
28121 + pmd_t *pmd, pte_t *pte)
28122 + {
28123 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
28124 +- set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
28125 ++ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
28126 + }
28127 +
28128 + static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
28129 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-2level.h linux-2.6.27.10/include/asm-x86/pgtable-2level.h
28130 +--- linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-07 12:55:34.000000000 -0500
28131 ++++ linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-18 03:38:45.000000000 -0500
28132 +@@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t
28133 +
28134 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28135 + {
28136 ++
28137 ++#ifdef CONFIG_PAX_KERNEXEC
28138 ++ unsigned long cr0;
28139 ++
28140 ++ pax_open_kernel(cr0);
28141 ++#endif
28142 ++
28143 + *pmdp = pmd;
28144 ++
28145 ++#ifdef CONFIG_PAX_KERNEXEC
28146 ++ pax_close_kernel(cr0);
28147 ++#endif
28148 ++
28149 + }
28150 +
28151 + static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
28152 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_32.h linux-2.6.27.10/include/asm-x86/pgtable_32.h
28153 +--- linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
28154 ++++ linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-18 03:38:45.000000000 -0500
28155 +@@ -25,8 +25,6 @@
28156 + struct mm_struct;
28157 + struct vm_area_struct;
28158 +
28159 +-extern pgd_t swapper_pg_dir[1024];
28160 +-
28161 + static inline void pgtable_cache_init(void) { }
28162 + static inline void check_pgt_cache(void) { }
28163 + void paging_init(void);
28164 +@@ -45,6 +43,11 @@ void paging_init(void);
28165 + # include <asm/pgtable-2level-defs.h>
28166 + #endif
28167 +
28168 ++extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
28169 ++#ifdef CONFIG_X86_PAE
28170 ++extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
28171 ++#endif
28172 ++
28173 + #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
28174 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
28175 +
28176 +@@ -81,7 +84,7 @@ void paging_init(void);
28177 + #undef TEST_ACCESS_OK
28178 +
28179 + /* The boot page tables (all created as a single array) */
28180 +-extern unsigned long pg0[];
28181 ++extern pte_t pg0[];
28182 +
28183 + #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
28184 +
28185 +@@ -173,6 +176,9 @@ do { \
28186 +
28187 + #endif /* !__ASSEMBLY__ */
28188 +
28189 ++#define HAVE_ARCH_UNMAPPED_AREA
28190 ++#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
28191 ++
28192 + /*
28193 + * kern_addr_valid() is (1) for FLATMEM and (0) for
28194 + * SPARSEMEM and DISCONTIGMEM
28195 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-3level.h linux-2.6.27.10/include/asm-x86/pgtable-3level.h
28196 +--- linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-07 12:55:34.000000000 -0500
28197 ++++ linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-18 03:38:45.000000000 -0500
28198 +@@ -70,12 +70,36 @@ static inline void native_set_pte_atomic
28199 +
28200 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28201 + {
28202 ++
28203 ++#ifdef CONFIG_PAX_KERNEXEC
28204 ++ unsigned long cr0;
28205 ++
28206 ++ pax_open_kernel(cr0);
28207 ++#endif
28208 ++
28209 + set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
28210 ++
28211 ++#ifdef CONFIG_PAX_KERNEXEC
28212 ++ pax_close_kernel(cr0);
28213 ++#endif
28214 ++
28215 + }
28216 +
28217 + static inline void native_set_pud(pud_t *pudp, pud_t pud)
28218 + {
28219 ++
28220 ++#ifdef CONFIG_PAX_KERNEXEC
28221 ++ unsigned long cr0;
28222 ++
28223 ++ pax_open_kernel(cr0);
28224 ++#endif
28225 ++
28226 + set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
28227 ++
28228 ++#ifdef CONFIG_PAX_KERNEXEC
28229 ++ pax_close_kernel(cr0);
28230 ++#endif
28231 ++
28232 + }
28233 +
28234 + /*
28235 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_64.h linux-2.6.27.10/include/asm-x86/pgtable_64.h
28236 +--- linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-07 12:55:34.000000000 -0500
28237 ++++ linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-18 03:38:45.000000000 -0500
28238 +@@ -15,9 +15,12 @@
28239 +
28240 + extern pud_t level3_kernel_pgt[512];
28241 + extern pud_t level3_ident_pgt[512];
28242 ++extern pud_t level3_vmalloc_pgt[512];
28243 ++extern pud_t level3_vmemmap_pgt[512];
28244 + extern pmd_t level2_kernel_pgt[512];
28245 + extern pmd_t level2_fixmap_pgt[512];
28246 + extern pmd_t level2_ident_pgt[512];
28247 ++extern pte_t level1_fixmap_pgt[512];
28248 + extern pgd_t init_level4_pgt[];
28249 +
28250 + #define swapper_pg_dir init_level4_pgt
28251 +@@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_
28252 +
28253 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28254 + {
28255 ++
28256 ++#ifdef CONFIG_PAX_KERNEXEC
28257 ++ unsigned long cr0;
28258 ++
28259 ++ pax_open_kernel(cr0);
28260 ++#endif
28261 ++
28262 + *pmdp = pmd;
28263 ++
28264 ++#ifdef CONFIG_PAX_KERNEXEC
28265 ++ pax_close_kernel(cr0);
28266 ++#endif
28267 ++
28268 + }
28269 +
28270 + static inline void native_pmd_clear(pmd_t *pmd)
28271 +@@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_
28272 +
28273 + static inline int pgd_bad(pgd_t pgd)
28274 + {
28275 +- return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28276 ++ return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28277 + }
28278 +
28279 + static inline int pud_bad(pud_t pud)
28280 + {
28281 +- return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28282 ++ return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28283 + }
28284 +
28285 + static inline int pmd_bad(pmd_t pmd)
28286 + {
28287 +- return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28288 ++ return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28289 + }
28290 +
28291 + #define pte_none(x) (!pte_val((x)))
28292 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable.h linux-2.6.27.10/include/asm-x86/pgtable.h
28293 +--- linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-07 12:55:34.000000000 -0500
28294 ++++ linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-18 03:38:45.000000000 -0500
28295 +@@ -41,7 +41,7 @@
28296 + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28297 + #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
28298 + #else
28299 +-#define _PAGE_NX (_AT(pteval_t, 0))
28300 ++#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
28301 + #endif
28302 +
28303 + /* If _PAGE_PRESENT is clear, we use these: */
28304 +@@ -81,6 +81,9 @@
28305 + #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
28306 + _PAGE_ACCESSED)
28307 +
28308 ++#define PAGE_READONLY_NOEXEC PAGE_READONLY
28309 ++#define PAGE_SHARED_NOEXEC PAGE_SHARED
28310 ++
28311 + #define __PAGE_KERNEL_EXEC \
28312 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
28313 + #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
28314 +@@ -92,7 +95,7 @@
28315 + #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
28316 + #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
28317 + #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
28318 +-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
28319 ++#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
28320 + #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
28321 + #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
28322 + #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
28323 +@@ -142,10 +145,17 @@ extern unsigned long empty_zero_page[PAG
28324 + extern spinlock_t pgd_lock;
28325 + extern struct list_head pgd_list;
28326 +
28327 ++extern pteval_t __supported_pte_mask;
28328 ++
28329 + /*
28330 + * The following only work if pte_present() is true.
28331 + * Undefined behaviour if not..
28332 + */
28333 ++static inline int pte_user(pte_t pte)
28334 ++{
28335 ++ return pte_val(pte) & _PAGE_USER;
28336 ++}
28337 ++
28338 + static inline int pte_dirty(pte_t pte)
28339 + {
28340 + return pte_flags(pte) & _PAGE_DIRTY;
28341 +@@ -207,9 +217,29 @@ static inline pte_t pte_wrprotect(pte_t
28342 + return __pte(pte_val(pte) & ~_PAGE_RW);
28343 + }
28344 +
28345 ++static inline pte_t pte_mkread(pte_t pte)
28346 ++{
28347 ++ return __pte(pte_val(pte) | _PAGE_USER);
28348 ++}
28349 ++
28350 + static inline pte_t pte_mkexec(pte_t pte)
28351 + {
28352 +- return __pte(pte_val(pte) & ~_PAGE_NX);
28353 ++#ifdef CONFIG_X86_PAE
28354 ++ if (__supported_pte_mask & _PAGE_NX)
28355 ++ return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
28356 ++ else
28357 ++#endif
28358 ++ return __pte(pte_val(pte) | _PAGE_USER);
28359 ++}
28360 ++
28361 ++static inline pte_t pte_exprotect(pte_t pte)
28362 ++{
28363 ++#ifdef CONFIG_X86_PAE
28364 ++ if (__supported_pte_mask & _PAGE_NX)
28365 ++ return __pte(pte_val(pte) | _PAGE_NX);
28366 ++ else
28367 ++#endif
28368 ++ return __pte(pte_val(pte) & ~_PAGE_USER);
28369 + }
28370 +
28371 + static inline pte_t pte_mkdirty(pte_t pte)
28372 +@@ -252,8 +282,6 @@ static inline pte_t pte_mkspecial(pte_t
28373 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
28374 + }
28375 +
28376 +-extern pteval_t __supported_pte_mask;
28377 +-
28378 + static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
28379 + {
28380 + return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
28381 +@@ -514,7 +542,19 @@ static inline void ptep_set_wrprotect(st
28382 + */
28383 + static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
28384 + {
28385 +- memcpy(dst, src, count * sizeof(pgd_t));
28386 ++
28387 ++#ifdef CONFIG_PAX_KERNEXEC
28388 ++ unsigned long cr0;
28389 ++
28390 ++ pax_open_kernel(cr0);
28391 ++#endif
28392 ++
28393 ++ memcpy(dst, src, count * sizeof(pgd_t));
28394 ++
28395 ++#ifdef CONFIG_PAX_KERNEXEC
28396 ++ pax_close_kernel(cr0);
28397 ++#endif
28398 ++
28399 + }
28400 +
28401 +
28402 +diff -urNp linux-2.6.27.10/include/asm-x86/processor.h linux-2.6.27.10/include/asm-x86/processor.h
28403 +--- linux-2.6.27.10/include/asm-x86/processor.h 2008-11-07 12:55:34.000000000 -0500
28404 ++++ linux-2.6.27.10/include/asm-x86/processor.h 2008-11-18 03:38:45.000000000 -0500
28405 +@@ -269,7 +269,7 @@ struct tss_struct {
28406 +
28407 + } ____cacheline_aligned;
28408 +
28409 +-DECLARE_PER_CPU(struct tss_struct, init_tss);
28410 ++extern struct tss_struct init_tss[NR_CPUS];
28411 +
28412 + /*
28413 + * Save the original ist values for checking stack pointers during debugging
28414 +@@ -832,11 +832,20 @@ static inline void spin_lock_prefetch(co
28415 + * User space process size: 3GB (default).
28416 + */
28417 + #define TASK_SIZE PAGE_OFFSET
28418 ++
28419 ++#ifdef CONFIG_PAX_SEGMEXEC
28420 ++#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
28421 ++#endif
28422 ++
28423 ++#ifdef CONFIG_PAX_SEGMEXEC
28424 ++#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
28425 ++#else
28426 + #define STACK_TOP TASK_SIZE
28427 +-#define STACK_TOP_MAX STACK_TOP
28428 ++#endif
28429 ++#define STACK_TOP_MAX TASK_SIZE
28430 +
28431 + #define INIT_THREAD { \
28432 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28433 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28434 + .vm86_info = NULL, \
28435 + .sysenter_cs = __KERNEL_CS, \
28436 + .io_bitmap_ptr = NULL, \
28437 +@@ -851,7 +860,7 @@ static inline void spin_lock_prefetch(co
28438 + */
28439 + #define INIT_TSS { \
28440 + .x86_tss = { \
28441 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28442 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28443 + .ss0 = __KERNEL_DS, \
28444 + .ss1 = __KERNEL_CS, \
28445 + .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
28446 +@@ -862,11 +871,7 @@ static inline void spin_lock_prefetch(co
28447 + extern unsigned long thread_saved_pc(struct task_struct *tsk);
28448 +
28449 + #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
28450 +-#define KSTK_TOP(info) \
28451 +-({ \
28452 +- unsigned long *__ptr = (unsigned long *)(info); \
28453 +- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
28454 +-})
28455 ++#define KSTK_TOP(info) ((info)->task.thread.sp0)
28456 +
28457 + /*
28458 + * The below -8 is to reserve 8 bytes on top of the ring0 stack.
28459 +@@ -881,7 +886,7 @@ extern unsigned long thread_saved_pc(str
28460 + #define task_pt_regs(task) \
28461 + ({ \
28462 + struct pt_regs *__regs__; \
28463 +- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
28464 ++ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
28465 + __regs__ - 1; \
28466 + })
28467 +
28468 +@@ -897,7 +902,7 @@ extern unsigned long thread_saved_pc(str
28469 + * space during mmap's.
28470 + */
28471 + #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
28472 +- 0xc0000000 : 0xFFFFe000)
28473 ++ 0xc0000000 : 0xFFFFf000)
28474 +
28475 + #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
28476 + IA32_PAGE_OFFSET : TASK_SIZE64)
28477 +@@ -934,6 +939,10 @@ extern void start_thread(struct pt_regs
28478 + */
28479 + #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
28480 +
28481 ++#ifdef CONFIG_PAX_SEGMEXEC
28482 ++#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
28483 ++#endif
28484 ++
28485 + #define KSTK_EIP(task) (task_pt_regs(task)->ip)
28486 +
28487 + /* Get/set a process' ability to use the timestamp counter instruction */
28488 +diff -urNp linux-2.6.27.10/include/asm-x86/ptrace.h linux-2.6.27.10/include/asm-x86/ptrace.h
28489 +--- linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-07 12:55:34.000000000 -0500
28490 ++++ linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-18 03:38:45.000000000 -0500
28491 +@@ -131,6 +131,7 @@ struct pt_regs {
28492 +
28493 + /* the DS BTS struct is used for ptrace as well */
28494 + #include <asm/ds.h>
28495 ++#include <asm/segment.h>
28496 +
28497 + struct task_struct;
28498 +
28499 +@@ -154,28 +155,29 @@ static inline unsigned long regs_return_
28500 + }
28501 +
28502 + /*
28503 +- * user_mode_vm(regs) determines whether a register set came from user mode.
28504 ++ * user_mode(regs) determines whether a register set came from user mode.
28505 + * This is true if V8086 mode was enabled OR if the register set was from
28506 + * protected mode with RPL-3 CS value. This tricky test checks that with
28507 + * one comparison. Many places in the kernel can bypass this full check
28508 +- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
28509 ++ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
28510 ++ * be used.
28511 + */
28512 +-static inline int user_mode(struct pt_regs *regs)
28513 ++static inline int user_mode_novm(struct pt_regs *regs)
28514 + {
28515 + #ifdef CONFIG_X86_32
28516 + return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
28517 + #else
28518 +- return !!(regs->cs & 3);
28519 ++ return !!(regs->cs & SEGMENT_RPL_MASK);
28520 + #endif
28521 + }
28522 +
28523 +-static inline int user_mode_vm(struct pt_regs *regs)
28524 ++static inline int user_mode(struct pt_regs *regs)
28525 + {
28526 + #ifdef CONFIG_X86_32
28527 + return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
28528 + USER_RPL;
28529 + #else
28530 +- return user_mode(regs);
28531 ++ return user_mode_novm(regs);
28532 + #endif
28533 + }
28534 +
28535 +diff -urNp linux-2.6.27.10/include/asm-x86/reboot.h linux-2.6.27.10/include/asm-x86/reboot.h
28536 +--- linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-07 12:55:34.000000000 -0500
28537 ++++ linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-18 03:38:45.000000000 -0500
28538 +@@ -16,6 +16,6 @@ extern struct machine_ops machine_ops;
28539 +
28540 + void native_machine_crash_shutdown(struct pt_regs *regs);
28541 + void native_machine_shutdown(void);
28542 +-void machine_real_restart(const unsigned char *code, int length);
28543 ++void machine_real_restart(const unsigned char *code, unsigned int length);
28544 +
28545 + #endif /* _ASM_REBOOT_H */
28546 +diff -urNp linux-2.6.27.10/include/asm-x86/rwsem.h linux-2.6.27.10/include/asm-x86/rwsem.h
28547 +--- linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-07 12:55:34.000000000 -0500
28548 ++++ linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-18 03:38:45.000000000 -0500
28549 +@@ -106,10 +106,26 @@ static inline void __down_read(struct rw
28550 + {
28551 + asm volatile("# beginning down_read\n\t"
28552 + LOCK_PREFIX " incl (%%eax)\n\t"
28553 ++
28554 ++#ifdef CONFIG_PAX_REFCOUNT
28555 ++#ifdef CONFIG_X86_32
28556 ++ "into\n0:\n"
28557 ++#else
28558 ++ "jno 0f\n"
28559 ++ "int $4\n0:\n"
28560 ++#endif
28561 ++ ".pushsection .fixup,\"ax\"\n"
28562 ++ "1:\n"
28563 ++ LOCK_PREFIX "decl (%%eax)\n"
28564 ++ "jmp 0b\n"
28565 ++ ".popsection\n"
28566 ++ _ASM_EXTABLE(0b, 1b)
28567 ++#endif
28568 ++
28569 + /* adds 0x00000001, returns the old value */
28570 +- " jns 1f\n"
28571 ++ " jns 2f\n"
28572 + " call call_rwsem_down_read_failed\n"
28573 +- "1:\n\t"
28574 ++ "2:\n\t"
28575 + "# ending down_read\n\t"
28576 + : "+m" (sem->count)
28577 + : "a" (sem)
28578 +@@ -124,13 +140,29 @@ static inline int __down_read_trylock(st
28579 + __s32 result, tmp;
28580 + asm volatile("# beginning __down_read_trylock\n\t"
28581 + " movl %0,%1\n\t"
28582 +- "1:\n\t"
28583 ++ "2:\n\t"
28584 + " movl %1,%2\n\t"
28585 + " addl %3,%2\n\t"
28586 +- " jle 2f\n\t"
28587 ++
28588 ++#ifdef CONFIG_PAX_REFCOUNT
28589 ++#ifdef CONFIG_X86_32
28590 ++ "into\n0:\n"
28591 ++#else
28592 ++ "jno 0f\n"
28593 ++ "int $4\n0:\n"
28594 ++#endif
28595 ++ ".pushsection .fixup,\"ax\"\n"
28596 ++ "1:\n"
28597 ++ "subl %3,%2\n"
28598 ++ "jmp 0b\n"
28599 ++ ".popsection\n"
28600 ++ _ASM_EXTABLE(0b, 1b)
28601 ++#endif
28602 ++
28603 ++ " jle 3f\n\t"
28604 + LOCK_PREFIX " cmpxchgl %2,%0\n\t"
28605 +- " jnz 1b\n\t"
28606 +- "2:\n\t"
28607 ++ " jnz 2b\n\t"
28608 ++ "3:\n\t"
28609 + "# ending __down_read_trylock\n\t"
28610 + : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
28611 + : "i" (RWSEM_ACTIVE_READ_BIAS)
28612 +@@ -148,12 +180,28 @@ static inline void __down_write_nested(s
28613 + tmp = RWSEM_ACTIVE_WRITE_BIAS;
28614 + asm volatile("# beginning down_write\n\t"
28615 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28616 ++
28617 ++#ifdef CONFIG_PAX_REFCOUNT
28618 ++#ifdef CONFIG_X86_32
28619 ++ "into\n0:\n"
28620 ++#else
28621 ++ "jno 0f\n"
28622 ++ "int $4\n0:\n"
28623 ++#endif
28624 ++ ".pushsection .fixup,\"ax\"\n"
28625 ++ "1:\n"
28626 ++ "movl %%edx,(%%eax)\n"
28627 ++ "jmp 0b\n"
28628 ++ ".popsection\n"
28629 ++ _ASM_EXTABLE(0b, 1b)
28630 ++#endif
28631 ++
28632 + /* subtract 0x0000ffff, returns the old value */
28633 + " testl %%edx,%%edx\n\t"
28634 + /* was the count 0 before? */
28635 +- " jz 1f\n"
28636 ++ " jz 2f\n"
28637 + " call call_rwsem_down_write_failed\n"
28638 +- "1:\n"
28639 ++ "2:\n"
28640 + "# ending down_write"
28641 + : "+m" (sem->count), "=d" (tmp)
28642 + : "a" (sem), "1" (tmp)
28643 +@@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s
28644 + __s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
28645 + asm volatile("# beginning __up_read\n\t"
28646 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28647 ++
28648 ++#ifdef CONFIG_PAX_REFCOUNT
28649 ++#ifdef CONFIG_X86_32
28650 ++ "into\n0:\n"
28651 ++#else
28652 ++ "jno 0f\n"
28653 ++ "int $4\n0:\n"
28654 ++#endif
28655 ++ ".pushsection .fixup,\"ax\"\n"
28656 ++ "1:\n"
28657 ++ "movl %%edx,(%%eax)\n"
28658 ++ "jmp 0b\n"
28659 ++ ".popsection\n"
28660 ++ _ASM_EXTABLE(0b, 1b)
28661 ++#endif
28662 ++
28663 + /* subtracts 1, returns the old value */
28664 +- " jns 1f\n\t"
28665 ++ " jns 2f\n\t"
28666 + " call call_rwsem_wake\n"
28667 +- "1:\n"
28668 ++ "2:\n"
28669 + "# ending __up_read\n"
28670 + : "+m" (sem->count), "=d" (tmp)
28671 + : "a" (sem), "1" (tmp)
28672 +@@ -204,11 +268,27 @@ static inline void __up_write(struct rw_
28673 + asm volatile("# beginning __up_write\n\t"
28674 + " movl %2,%%edx\n\t"
28675 + LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t"
28676 ++
28677 ++#ifdef CONFIG_PAX_REFCOUNT
28678 ++#ifdef CONFIG_X86_32
28679 ++ "into\n0:\n"
28680 ++#else
28681 ++ "jno 0f\n"
28682 ++ "int $4\n0:\n"
28683 ++#endif
28684 ++ ".pushsection .fixup,\"ax\"\n"
28685 ++ "1:\n"
28686 ++ "movl %%edx,(%%eax)\n"
28687 ++ "jmp 0b\n"
28688 ++ ".popsection\n"
28689 ++ _ASM_EXTABLE(0b, 1b)
28690 ++#endif
28691 ++
28692 + /* tries to transition
28693 + 0xffff0001 -> 0x00000000 */
28694 +- " jz 1f\n"
28695 ++ " jz 2f\n"
28696 + " call call_rwsem_wake\n"
28697 +- "1:\n\t"
28698 ++ "2:\n\t"
28699 + "# ending __up_write\n"
28700 + : "+m" (sem->count)
28701 + : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
28702 +@@ -222,10 +302,26 @@ static inline void __downgrade_write(str
28703 + {
28704 + asm volatile("# beginning __downgrade_write\n\t"
28705 + LOCK_PREFIX " addl %2,(%%eax)\n\t"
28706 ++
28707 ++#ifdef CONFIG_PAX_REFCOUNT
28708 ++#ifdef CONFIG_X86_32
28709 ++ "into\n0:\n"
28710 ++#else
28711 ++ "jno 0f\n"
28712 ++ "int $4\n0:\n"
28713 ++#endif
28714 ++ ".pushsection .fixup,\"ax\"\n"
28715 ++ "1:\n"
28716 ++ LOCK_PREFIX "subl %2,(%%eax)\n"
28717 ++ "jmp 0b\n"
28718 ++ ".popsection\n"
28719 ++ _ASM_EXTABLE(0b, 1b)
28720 ++#endif
28721 ++
28722 + /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
28723 +- " jns 1f\n\t"
28724 ++ " jns 2f\n\t"
28725 + " call call_rwsem_downgrade_wake\n"
28726 +- "1:\n\t"
28727 ++ "2:\n\t"
28728 + "# ending __downgrade_write\n"
28729 + : "+m" (sem->count)
28730 + : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
28731 +@@ -237,7 +333,23 @@ static inline void __downgrade_write(str
28732 + */
28733 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
28734 + {
28735 +- asm volatile(LOCK_PREFIX "addl %1,%0"
28736 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
28737 ++
28738 ++#ifdef CONFIG_PAX_REFCOUNT
28739 ++#ifdef CONFIG_X86_32
28740 ++ "into\n0:\n"
28741 ++#else
28742 ++ "jno 0f\n"
28743 ++ "int $4\n0:\n"
28744 ++#endif
28745 ++ ".pushsection .fixup,\"ax\"\n"
28746 ++ "1:\n"
28747 ++ LOCK_PREFIX "subl %1,%0\n"
28748 ++ "jmp 0b\n"
28749 ++ ".popsection\n"
28750 ++ _ASM_EXTABLE(0b, 1b)
28751 ++#endif
28752 ++
28753 + : "+m" (sem->count)
28754 + : "ir" (delta));
28755 + }
28756 +@@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in
28757 + {
28758 + int tmp = delta;
28759 +
28760 +- asm volatile(LOCK_PREFIX "xadd %0,%1"
28761 ++ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
28762 ++
28763 ++#ifdef CONFIG_PAX_REFCOUNT
28764 ++#ifdef CONFIG_X86_32
28765 ++ "into\n0:\n"
28766 ++#else
28767 ++ "jno 0f\n"
28768 ++ "int $4\n0:\n"
28769 ++#endif
28770 ++ ".pushsection .fixup,\"ax\"\n"
28771 ++ "1:\n"
28772 ++ "movl %0,%1\n"
28773 ++ "jmp 0b\n"
28774 ++ ".popsection\n"
28775 ++ _ASM_EXTABLE(0b, 1b)
28776 ++#endif
28777 ++
28778 + : "+r" (tmp), "+m" (sem->count)
28779 + : : "memory");
28780 +
28781 +diff -urNp linux-2.6.27.10/include/asm-x86/segment.h linux-2.6.27.10/include/asm-x86/segment.h
28782 +--- linux-2.6.27.10/include/asm-x86/segment.h 2008-11-07 12:55:34.000000000 -0500
28783 ++++ linux-2.6.27.10/include/asm-x86/segment.h 2008-11-18 03:38:45.000000000 -0500
28784 +@@ -88,13 +88,19 @@
28785 + #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
28786 + #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
28787 +
28788 +-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28789 ++#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28790 + #ifdef CONFIG_SMP
28791 + #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
28792 + #else
28793 + #define __KERNEL_PERCPU 0
28794 + #endif
28795 +
28796 ++#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16)
28797 ++#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
28798 ++
28799 ++#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17)
28800 ++#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
28801 ++
28802 + #define GDT_ENTRY_DOUBLEFAULT_TSS 31
28803 +
28804 + /*
28805 +@@ -135,10 +141,10 @@
28806 + #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
28807 +
28808 + /* Matches __KERNEL_CS and __USER_CS (they must be 2 entries apart) */
28809 +-#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xec) == GDT_ENTRY_KERNEL_CS * 8)
28810 ++#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xFFFCU) == __KERNEL_CS || ((x) & 0xFFFCU) == __USER_CS)
28811 +
28812 + /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
28813 +-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
28814 ++#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
28815 +
28816 +
28817 + #else
28818 +diff -urNp linux-2.6.27.10/include/asm-x86/spinlock.h linux-2.6.27.10/include/asm-x86/spinlock.h
28819 +--- linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-07 12:55:34.000000000 -0500
28820 ++++ linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-18 03:38:45.000000000 -0500
28821 +@@ -315,18 +315,50 @@ static inline int __raw_write_can_lock(r
28822 + static inline void __raw_read_lock(raw_rwlock_t *rw)
28823 + {
28824 + asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
28825 +- "jns 1f\n"
28826 +- "call __read_lock_failed\n\t"
28827 ++
28828 ++#ifdef CONFIG_PAX_REFCOUNT
28829 ++#ifdef CONFIG_X86_32
28830 ++ "into\n0:\n"
28831 ++#else
28832 ++ "jno 0f\n"
28833 ++ "int $4\n0:\n"
28834 ++#endif
28835 ++ ".pushsection .fixup,\"ax\"\n"
28836 + "1:\n"
28837 ++ LOCK_PREFIX " addl $1,(%0)\n"
28838 ++ "jmp 0b\n"
28839 ++ ".popsection\n"
28840 ++ _ASM_EXTABLE(0b, 1b)
28841 ++#endif
28842 ++
28843 ++ "jns 2f\n"
28844 ++ "call __read_lock_failed\n\t"
28845 ++ "2:\n"
28846 + ::LOCK_PTR_REG (rw) : "memory");
28847 + }
28848 +
28849 + static inline void __raw_write_lock(raw_rwlock_t *rw)
28850 + {
28851 + asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
28852 +- "jz 1f\n"
28853 +- "call __write_lock_failed\n\t"
28854 ++
28855 ++#ifdef CONFIG_PAX_REFCOUNT
28856 ++#ifdef CONFIG_X86_32
28857 ++ "into\n0:\n"
28858 ++#else
28859 ++ "jno 0f\n"
28860 ++ "int $4\n0:\n"
28861 ++#endif
28862 ++ ".pushsection .fixup,\"ax\"\n"
28863 + "1:\n"
28864 ++ LOCK_PREFIX " addl %1,(%0)\n"
28865 ++ "jmp 0b\n"
28866 ++ ".popsection\n"
28867 ++ _ASM_EXTABLE(0b, 1b)
28868 ++#endif
28869 ++
28870 ++ "jz 2f\n"
28871 ++ "call __write_lock_failed\n\t"
28872 ++ "2:\n"
28873 + ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory");
28874 + }
28875 +
28876 +@@ -353,12 +385,45 @@ static inline int __raw_write_trylock(ra
28877 +
28878 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
28879 + {
28880 +- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
28881 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28882 ++
28883 ++#ifdef CONFIG_PAX_REFCOUNT
28884 ++#ifdef CONFIG_X86_32
28885 ++ "into\n0:\n"
28886 ++#else
28887 ++ "jno 0f\n"
28888 ++ "int $4\n0:\n"
28889 ++#endif
28890 ++ ".pushsection .fixup,\"ax\"\n"
28891 ++ "1:\n"
28892 ++ LOCK_PREFIX "decl %0\n"
28893 ++ "jmp 0b\n"
28894 ++ ".popsection\n"
28895 ++ _ASM_EXTABLE(0b, 1b)
28896 ++#endif
28897 ++
28898 ++ :"+m" (rw->lock) : : "memory");
28899 + }
28900 +
28901 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
28902 + {
28903 +- asm volatile(LOCK_PREFIX "addl %1, %0"
28904 ++ asm volatile(LOCK_PREFIX "addl %1, %0\n"
28905 ++
28906 ++#ifdef CONFIG_PAX_REFCOUNT
28907 ++#ifdef CONFIG_X86_32
28908 ++ "into\n0:\n"
28909 ++#else
28910 ++ "jno 0f\n"
28911 ++ "int $4\n0:\n"
28912 ++#endif
28913 ++ ".pushsection .fixup,\"ax\"\n"
28914 ++ "1:\n"
28915 ++ LOCK_PREFIX "subl %1,%0\n"
28916 ++ "jmp 0b\n"
28917 ++ ".popsection\n"
28918 ++ _ASM_EXTABLE(0b, 1b)
28919 ++#endif
28920 ++
28921 + : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
28922 + }
28923 +
28924 +diff -urNp linux-2.6.27.10/include/asm-x86/system.h linux-2.6.27.10/include/asm-x86/system.h
28925 +--- linux-2.6.27.10/include/asm-x86/system.h 2008-11-07 12:55:34.000000000 -0500
28926 ++++ linux-2.6.27.10/include/asm-x86/system.h 2008-11-18 03:38:45.000000000 -0500
28927 +@@ -92,6 +92,8 @@ do { \
28928 + ".globl thread_return\n" \
28929 + "thread_return:\n\t" \
28930 + "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
28931 ++ "movq %P[task_canary](%%rsi),%%r8\n\t" \
28932 ++ "movq %%r8,%%gs:%P[pda_canary]\n\t" \
28933 + "movq %P[thread_info](%%rsi),%%r8\n\t" \
28934 + LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
28935 + "movq %%rax,%%rdi\n\t" \
28936 +@@ -103,7 +105,9 @@ do { \
28937 + [ti_flags] "i" (offsetof(struct thread_info, flags)), \
28938 + [tif_fork] "i" (TIF_FORK), \
28939 + [thread_info] "i" (offsetof(struct task_struct, stack)), \
28940 +- [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
28941 ++ [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \
28942 ++ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
28943 ++ [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
28944 + : "memory", "cc" __EXTRA_CLOBBER)
28945 + #endif
28946 +
28947 +@@ -166,7 +170,7 @@ static inline unsigned long get_limit(un
28948 + {
28949 + unsigned long __limit;
28950 + asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
28951 +- return __limit + 1;
28952 ++ return __limit;
28953 + }
28954 +
28955 + static inline void native_clts(void)
28956 +@@ -292,6 +296,21 @@ static inline void native_wbinvd(void)
28957 +
28958 + #define stts() write_cr0(read_cr0() | X86_CR0_TS)
28959 +
28960 ++#define pax_open_kernel(cr0) \
28961 ++do { \
28962 ++ typecheck(unsigned long, cr0); \
28963 ++ preempt_disable(); \
28964 ++ cr0 = read_cr0(); \
28965 ++ write_cr0(cr0 & ~X86_CR0_WP); \
28966 ++} while (0)
28967 ++
28968 ++#define pax_close_kernel(cr0) \
28969 ++do { \
28970 ++ typecheck(unsigned long, cr0); \
28971 ++ write_cr0(cr0); \
28972 ++ preempt_enable_no_resched(); \
28973 ++} while (0)
28974 ++
28975 + #endif /* __KERNEL__ */
28976 +
28977 + static inline void clflush(volatile void *__p)
28978 +@@ -306,7 +325,7 @@ void enable_hlt(void);
28979 +
28980 + void cpu_idle_wait(void);
28981 +
28982 +-extern unsigned long arch_align_stack(unsigned long sp);
28983 ++#define arch_align_stack(x) ((x) & ~0xfUL)
28984 + extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
28985 +
28986 + void default_idle(void);
28987 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess_64.h linux-2.6.27.10/include/asm-x86/uaccess_64.h
28988 +--- linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-07 12:55:34.000000000 -0500
28989 ++++ linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-18 03:38:45.000000000 -0500
28990 +@@ -10,6 +10,8 @@
28991 + #include <linux/lockdep.h>
28992 + #include <asm/page.h>
28993 +
28994 ++#define set_fs(x) (current_thread_info()->addr_limit = (x))
28995 ++
28996 + /*
28997 + * Copy To/From Userspace
28998 + */
28999 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess.h linux-2.6.27.10/include/asm-x86/uaccess.h
29000 +--- linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-07 12:55:34.000000000 -0500
29001 ++++ linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-18 03:38:45.000000000 -0500
29002 +@@ -10,6 +10,7 @@
29003 + #include <linux/string.h>
29004 + #include <asm/asm.h>
29005 + #include <asm/page.h>
29006 ++#include <asm/segment.h>
29007 +
29008 + #define VERIFY_READ 0
29009 + #define VERIFY_WRITE 1
29010 +@@ -29,7 +30,12 @@
29011 +
29012 + #define get_ds() (KERNEL_DS)
29013 + #define get_fs() (current_thread_info()->addr_limit)
29014 ++#ifdef CONFIG_X86_32
29015 ++void __set_fs(mm_segment_t x, int cpu);
29016 ++void set_fs(mm_segment_t x);
29017 ++#else
29018 + #define set_fs(x) (current_thread_info()->addr_limit = (x))
29019 ++#endif
29020 +
29021 + #define segment_eq(a, b) ((a).seg == (b).seg)
29022 +
29023 +@@ -97,6 +103,7 @@ struct exception_table_entry {
29024 + };
29025 +
29026 + extern int fixup_exception(struct pt_regs *regs);
29027 ++#define ARCH_HAS_SORT_EXTABLE
29028 +
29029 + /*
29030 + * These are the main single-value transfer routines. They automatically
29031 +@@ -186,9 +193,12 @@ extern int __get_user_bad(void);
29032 +
29033 + #ifdef CONFIG_X86_32
29034 + #define __put_user_u64(x, addr, err) \
29035 +- asm volatile("1: movl %%eax,0(%2)\n" \
29036 +- "2: movl %%edx,4(%2)\n" \
29037 ++ asm volatile(" movw %w5,%%ds\n" \
29038 ++ "1: movl %%eax,%%ds:0(%2)\n" \
29039 ++ "2: movl %%edx,%%ds:4(%2)\n" \
29040 + "3:\n" \
29041 ++ " pushl %%ss\n" \
29042 ++ " popl %%ds\n" \
29043 + ".section .fixup,\"ax\"\n" \
29044 + "4: movl %3,%0\n" \
29045 + " jmp 3b\n" \
29046 +@@ -196,7 +206,8 @@ extern int __get_user_bad(void);
29047 + _ASM_EXTABLE(1b, 4b) \
29048 + _ASM_EXTABLE(2b, 4b) \
29049 + : "=r" (err) \
29050 +- : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
29051 ++ : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \
29052 ++ "r"(__USER_DS))
29053 +
29054 + #define __put_user_x8(x, ptr, __ret_pu) \
29055 + asm volatile("call __put_user_8" : "=a" (__ret_pu) \
29056 +@@ -336,6 +347,22 @@ do { \
29057 + } \
29058 + } while (0)
29059 +
29060 ++#ifdef CONFIG_X86_32
29061 ++#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29062 ++ asm volatile(" movw %w5,%%ds\n" \
29063 ++ "1: mov"itype" %%ds:%2,%"rtype"1\n" \
29064 ++ "2:\n" \
29065 ++ " pushl %%ss\n" \
29066 ++ " popl %%ds\n" \
29067 ++ ".section .fixup,\"ax\"\n" \
29068 ++ "3: movl %3,%0\n" \
29069 ++ " xor"itype" %"rtype"1,%"rtype"1\n" \
29070 ++ " jmp 2b\n" \
29071 ++ ".previous\n" \
29072 ++ _ASM_EXTABLE(1b, 3b) \
29073 ++ : "=r" (err), ltype (x) \
29074 ++ : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS))
29075 ++#else
29076 + #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29077 + asm volatile("1: mov"itype" %2,%"rtype"1\n" \
29078 + "2:\n" \
29079 +@@ -347,6 +374,7 @@ do { \
29080 + _ASM_EXTABLE(1b, 3b) \
29081 + : "=r" (err), ltype(x) \
29082 + : "m" (__m(addr)), "i" (errret), "0" (err))
29083 ++#endif
29084 +
29085 + #define __put_user_nocheck(x, ptr, size) \
29086 + ({ \
29087 +@@ -373,6 +401,22 @@ struct __large_struct { unsigned long bu
29088 + * we do not write to any memory gcc knows about, so there are no
29089 + * aliasing issues.
29090 + */
29091 ++#ifdef CONFIG_X86_32
29092 ++#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29093 ++ asm volatile(" movw %w5,%%ds\n" \
29094 ++ "1: mov"itype" %"rtype"1,%%ds:%2\n" \
29095 ++ "2:\n" \
29096 ++ " pushl %%ss\n" \
29097 ++ " popl %%ds\n" \
29098 ++ ".section .fixup,\"ax\"\n" \
29099 ++ "3: movl %3,%0\n" \
29100 ++ " jmp 2b\n" \
29101 ++ ".previous\n" \
29102 ++ _ASM_EXTABLE(1b, 3b) \
29103 ++ : "=r"(err) \
29104 ++ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\
29105 ++ "r"(__USER_DS))
29106 ++#else
29107 + #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29108 + asm volatile("1: mov"itype" %"rtype"1,%2\n" \
29109 + "2:\n" \
29110 +@@ -383,6 +427,7 @@ struct __large_struct { unsigned long bu
29111 + _ASM_EXTABLE(1b, 3b) \
29112 + : "=r"(err) \
29113 + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
29114 ++#endif
29115 + /**
29116 + * __get_user: - Get a simple variable from user space, with less checking.
29117 + * @x: Variable to store result.
29118 +@@ -447,6 +492,7 @@ extern struct movsl_mask {
29119 + # include "uaccess_32.h"
29120 + #else
29121 + # define ARCH_HAS_SEARCH_EXTABLE
29122 ++# define ARCH_HAS_SORT_EXTABLE
29123 + # include "uaccess_64.h"
29124 + #endif
29125 +
29126 +diff -urNp linux-2.6.27.10/include/asm-xtensa/kmap_types.h linux-2.6.27.10/include/asm-xtensa/kmap_types.h
29127 +--- linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
29128 ++++ linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
29129 +@@ -25,6 +25,7 @@ enum km_type {
29130 + KM_IRQ1,
29131 + KM_SOFTIRQ0,
29132 + KM_SOFTIRQ1,
29133 ++ KM_CLEARPAGE,
29134 + KM_TYPE_NR
29135 + };
29136 +
29137 +diff -urNp linux-2.6.27.10/include/drm/drm_pciids.h linux-2.6.27.10/include/drm/drm_pciids.h
29138 +--- linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-07 12:55:34.000000000 -0500
29139 ++++ linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-18 03:38:45.000000000 -0500
29140 +@@ -237,7 +237,7 @@
29141 + {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
29142 + {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29143 + {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29144 +- {0, 0, 0}
29145 ++ {0, 0, 0, 0, 0, 0}
29146 +
29147 + #define r128_PCI_IDS \
29148 + {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29149 +@@ -277,14 +277,14 @@
29150 + {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29151 + {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29152 + {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29153 +- {0, 0, 0}
29154 ++ {0, 0, 0, 0, 0, 0}
29155 +
29156 + #define mga_PCI_IDS \
29157 + {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29158 + {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29159 + {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
29160 + {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
29161 +- {0, 0, 0}
29162 ++ {0, 0, 0, 0, 0, 0}
29163 +
29164 + #define mach64_PCI_IDS \
29165 + {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29166 +@@ -307,7 +307,7 @@
29167 + {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29168 + {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29169 + {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29170 +- {0, 0, 0}
29171 ++ {0, 0, 0, 0, 0, 0}
29172 +
29173 + #define sisdrv_PCI_IDS \
29174 + {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29175 +@@ -318,7 +318,7 @@
29176 + {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29177 + {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29178 + {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29179 +- {0, 0, 0}
29180 ++ {0, 0, 0, 0, 0, 0}
29181 +
29182 + #define tdfx_PCI_IDS \
29183 + {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29184 +@@ -327,7 +327,7 @@
29185 + {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29186 + {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29187 + {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29188 +- {0, 0, 0}
29189 ++ {0, 0, 0, 0, 0, 0}
29190 +
29191 + #define viadrv_PCI_IDS \
29192 + {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29193 +@@ -339,25 +339,25 @@
29194 + {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29195 + {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
29196 + {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
29197 +- {0, 0, 0}
29198 ++ {0, 0, 0, 0, 0, 0}
29199 +
29200 + #define i810_PCI_IDS \
29201 + {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29202 + {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29203 + {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29204 + {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29205 +- {0, 0, 0}
29206 ++ {0, 0, 0, 0, 0, 0}
29207 +
29208 + #define i830_PCI_IDS \
29209 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29210 + {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29211 + {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29212 + {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29213 +- {0, 0, 0}
29214 ++ {0, 0, 0, 0, 0, 0}
29215 +
29216 + #define gamma_PCI_IDS \
29217 + {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29218 +- {0, 0, 0}
29219 ++ {0, 0, 0, 0, 0, 0}
29220 +
29221 + #define savage_PCI_IDS \
29222 + {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
29223 +@@ -383,10 +383,10 @@
29224 + {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
29225 + {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29226 + {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29227 +- {0, 0, 0}
29228 ++ {0, 0, 0, 0, 0, 0}
29229 +
29230 + #define ffb_PCI_IDS \
29231 +- {0, 0, 0}
29232 ++ {0, 0, 0, 0, 0, 0}
29233 +
29234 + #define i915_PCI_IDS \
29235 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29236 +@@ -412,4 +412,4 @@
29237 + {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29238 + {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29239 + {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29240 +- {0, 0, 0}
29241 ++ {0, 0, 0, 0, 0, 0}
29242 +diff -urNp linux-2.6.27.10/include/linux/a.out.h linux-2.6.27.10/include/linux/a.out.h
29243 +--- linux-2.6.27.10/include/linux/a.out.h 2008-11-07 12:55:34.000000000 -0500
29244 ++++ linux-2.6.27.10/include/linux/a.out.h 2008-11-18 03:38:45.000000000 -0500
29245 +@@ -39,6 +39,14 @@ enum machine_type {
29246 + M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
29247 + };
29248 +
29249 ++/* Constants for the N_FLAGS field */
29250 ++#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29251 ++#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
29252 ++#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
29253 ++#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
29254 ++/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29255 ++#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29256 ++
29257 + #if !defined (N_MAGIC)
29258 + #define N_MAGIC(exec) ((exec).a_info & 0xffff)
29259 + #endif
29260 +diff -urNp linux-2.6.27.10/include/linux/binfmts.h linux-2.6.27.10/include/linux/binfmts.h
29261 +--- linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:16:52.000000000 -0500
29262 ++++ linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:13:46.000000000 -0500
29263 +@@ -71,6 +71,7 @@ struct linux_binfmt {
29264 + int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
29265 + int (*load_shlib)(struct file *);
29266 + int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
29267 ++ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
29268 + unsigned long min_coredump; /* minimal dump size */
29269 + int hasvdso;
29270 + };
29271 +diff -urNp linux-2.6.27.10/include/linux/cache.h linux-2.6.27.10/include/linux/cache.h
29272 +--- linux-2.6.27.10/include/linux/cache.h 2008-11-07 12:55:34.000000000 -0500
29273 ++++ linux-2.6.27.10/include/linux/cache.h 2008-11-18 03:38:45.000000000 -0500
29274 +@@ -16,6 +16,10 @@
29275 + #define __read_mostly
29276 + #endif
29277 +
29278 ++#ifndef __read_only
29279 ++#define __read_only __read_mostly
29280 ++#endif
29281 ++
29282 + #ifndef ____cacheline_aligned
29283 + #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
29284 + #endif
29285 +diff -urNp linux-2.6.27.10/include/linux/capability.h linux-2.6.27.10/include/linux/capability.h
29286 +--- linux-2.6.27.10/include/linux/capability.h 2008-11-07 12:55:34.000000000 -0500
29287 ++++ linux-2.6.27.10/include/linux/capability.h 2008-11-18 03:38:45.000000000 -0500
29288 +@@ -516,6 +516,7 @@ kernel_cap_t cap_set_effective(const ker
29289 + #define has_capability(t, cap) (security_capable((t), (cap)) == 0)
29290 +
29291 + extern int capable(int cap);
29292 ++int capable_nolog(int cap);
29293 +
29294 + #endif /* __KERNEL__ */
29295 +
29296 +diff -urNp linux-2.6.27.10/include/linux/cpumask.h linux-2.6.27.10/include/linux/cpumask.h
29297 +--- linux-2.6.27.10/include/linux/cpumask.h 2008-11-07 12:55:34.000000000 -0500
29298 ++++ linux-2.6.27.10/include/linux/cpumask.h 2008-11-18 03:38:45.000000000 -0500
29299 +@@ -139,7 +139,6 @@
29300 + #include <linux/bitmap.h>
29301 +
29302 + typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
29303 +-extern cpumask_t _unused_cpumask_arg_;
29304 +
29305 + #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
29306 + static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
29307 +diff -urNp linux-2.6.27.10/include/linux/elf.h linux-2.6.27.10/include/linux/elf.h
29308 +--- linux-2.6.27.10/include/linux/elf.h 2008-11-07 12:55:34.000000000 -0500
29309 ++++ linux-2.6.27.10/include/linux/elf.h 2008-12-21 00:44:29.000000000 -0500
29310 +@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
29311 + #define PT_GNU_EH_FRAME 0x6474e550
29312 +
29313 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
29314 ++#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
29315 ++
29316 ++#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
29317 ++
29318 ++/* Constants for the e_flags field */
29319 ++#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29320 ++#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
29321 ++#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
29322 ++#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
29323 ++/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29324 ++#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29325 +
29326 + /* These constants define the different elf file types */
29327 + #define ET_NONE 0
29328 +@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
29329 + #define DT_DEBUG 21
29330 + #define DT_TEXTREL 22
29331 + #define DT_JMPREL 23
29332 ++#define DT_FLAGS 30
29333 ++ #define DF_TEXTREL 0x00000004
29334 + #define DT_ENCODING 32
29335 + #define OLD_DT_LOOS 0x60000000
29336 + #define DT_LOOS 0x6000000d
29337 +@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
29338 + #define PF_W 0x2
29339 + #define PF_X 0x1
29340 +
29341 ++#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
29342 ++#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
29343 ++#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
29344 ++#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
29345 ++#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
29346 ++#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
29347 ++/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
29348 ++/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
29349 ++#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
29350 ++#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
29351 ++#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
29352 ++#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
29353 ++
29354 + typedef struct elf32_phdr{
29355 + Elf32_Word p_type;
29356 + Elf32_Off p_offset;
29357 +@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
29358 + #define EI_OSABI 7
29359 + #define EI_PAD 8
29360 +
29361 ++#define EI_PAX 14
29362 ++
29363 + #define ELFMAG0 0x7f /* EI_MAG */
29364 + #define ELFMAG1 'E'
29365 + #define ELFMAG2 'L'
29366 +@@ -383,6 +411,7 @@ extern Elf32_Dyn _DYNAMIC [];
29367 + #define elf_phdr elf32_phdr
29368 + #define elf_note elf32_note
29369 + #define elf_addr_t Elf32_Off
29370 ++#define elf_dyn Elf32_Dyn
29371 +
29372 + #else
29373 +
29374 +@@ -391,6 +420,7 @@ extern Elf64_Dyn _DYNAMIC [];
29375 + #define elf_phdr elf64_phdr
29376 + #define elf_note elf64_note
29377 + #define elf_addr_t Elf64_Off
29378 ++#define elf_dyn Elf64_Dyn
29379 +
29380 + #endif
29381 +
29382 +diff -urNp linux-2.6.27.10/include/linux/gracl.h linux-2.6.27.10/include/linux/gracl.h
29383 +--- linux-2.6.27.10/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
29384 ++++ linux-2.6.27.10/include/linux/gracl.h 2008-11-18 03:38:45.000000000 -0500
29385 +@@ -0,0 +1,318 @@
29386 ++#ifndef GR_ACL_H
29387 ++#define GR_ACL_H
29388 ++
29389 ++#include <linux/grdefs.h>
29390 ++#include <linux/resource.h>
29391 ++#include <linux/capability.h>
29392 ++#include <linux/dcache.h>
29393 ++#include <asm/resource.h>
29394 ++
29395 ++/* Major status information */
29396 ++
29397 ++#define GR_VERSION "grsecurity 2.1.12"
29398 ++#define GRSECURITY_VERSION 0x2112
29399 ++
29400 ++enum {
29401 ++
29402 ++ SHUTDOWN = 0,
29403 ++ ENABLE = 1,
29404 ++ SPROLE = 2,
29405 ++ RELOAD = 3,
29406 ++ SEGVMOD = 4,
29407 ++ STATUS = 5,
29408 ++ UNSPROLE = 6,
29409 ++ PASSSET = 7,
29410 ++ SPROLEPAM = 8
29411 ++};
29412 ++
29413 ++/* Password setup definitions
29414 ++ * kernel/grhash.c */
29415 ++enum {
29416 ++ GR_PW_LEN = 128,
29417 ++ GR_SALT_LEN = 16,
29418 ++ GR_SHA_LEN = 32,
29419 ++};
29420 ++
29421 ++enum {
29422 ++ GR_SPROLE_LEN = 64,
29423 ++};
29424 ++
29425 ++#define GR_NLIMITS (RLIMIT_LOCKS + 2)
29426 ++
29427 ++/* Begin Data Structures */
29428 ++
29429 ++struct sprole_pw {
29430 ++ unsigned char *rolename;
29431 ++ unsigned char salt[GR_SALT_LEN];
29432 ++ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
29433 ++};
29434 ++
29435 ++struct name_entry {
29436 ++ __u32 key;
29437 ++ ino_t inode;
29438 ++ dev_t device;
29439 ++ char *name;
29440 ++ __u16 len;
29441 ++ __u8 deleted;
29442 ++ struct name_entry *prev;
29443 ++ struct name_entry *next;
29444 ++};
29445 ++
29446 ++struct inodev_entry {
29447 ++ struct name_entry *nentry;
29448 ++ struct inodev_entry *prev;
29449 ++ struct inodev_entry *next;
29450 ++};
29451 ++
29452 ++struct acl_role_db {
29453 ++ struct acl_role_label **r_hash;
29454 ++ __u32 r_size;
29455 ++};
29456 ++
29457 ++struct inodev_db {
29458 ++ struct inodev_entry **i_hash;
29459 ++ __u32 i_size;
29460 ++};
29461 ++
29462 ++struct name_db {
29463 ++ struct name_entry **n_hash;
29464 ++ __u32 n_size;
29465 ++};
29466 ++
29467 ++struct crash_uid {
29468 ++ uid_t uid;
29469 ++ unsigned long expires;
29470 ++};
29471 ++
29472 ++struct gr_hash_struct {
29473 ++ void **table;
29474 ++ void **nametable;
29475 ++ void *first;
29476 ++ __u32 table_size;
29477 ++ __u32 used_size;
29478 ++ int type;
29479 ++};
29480 ++
29481 ++/* Userspace Grsecurity ACL data structures */
29482 ++
29483 ++struct acl_subject_label {
29484 ++ char *filename;
29485 ++ ino_t inode;
29486 ++ dev_t device;
29487 ++ __u32 mode;
29488 ++ kernel_cap_t cap_mask;
29489 ++ kernel_cap_t cap_lower;
29490 ++
29491 ++ struct rlimit res[GR_NLIMITS];
29492 ++ __u16 resmask;
29493 ++
29494 ++ __u8 user_trans_type;
29495 ++ __u8 group_trans_type;
29496 ++ uid_t *user_transitions;
29497 ++ gid_t *group_transitions;
29498 ++ __u16 user_trans_num;
29499 ++ __u16 group_trans_num;
29500 ++
29501 ++ __u32 ip_proto[8];
29502 ++ __u32 ip_type;
29503 ++ struct acl_ip_label **ips;
29504 ++ __u32 ip_num;
29505 ++
29506 ++ __u32 crashes;
29507 ++ unsigned long expires;
29508 ++
29509 ++ struct acl_subject_label *parent_subject;
29510 ++ struct gr_hash_struct *hash;
29511 ++ struct acl_subject_label *prev;
29512 ++ struct acl_subject_label *next;
29513 ++
29514 ++ struct acl_object_label **obj_hash;
29515 ++ __u32 obj_hash_size;
29516 ++ __u16 pax_flags;
29517 ++};
29518 ++
29519 ++struct role_allowed_ip {
29520 ++ __u32 addr;
29521 ++ __u32 netmask;
29522 ++
29523 ++ struct role_allowed_ip *prev;
29524 ++ struct role_allowed_ip *next;
29525 ++};
29526 ++
29527 ++struct role_transition {
29528 ++ char *rolename;
29529 ++
29530 ++ struct role_transition *prev;
29531 ++ struct role_transition *next;
29532 ++};
29533 ++
29534 ++struct acl_role_label {
29535 ++ char *rolename;
29536 ++ uid_t uidgid;
29537 ++ __u16 roletype;
29538 ++
29539 ++ __u16 auth_attempts;
29540 ++ unsigned long expires;
29541 ++
29542 ++ struct acl_subject_label *root_label;
29543 ++ struct gr_hash_struct *hash;
29544 ++
29545 ++ struct acl_role_label *prev;
29546 ++ struct acl_role_label *next;
29547 ++
29548 ++ struct role_transition *transitions;
29549 ++ struct role_allowed_ip *allowed_ips;
29550 ++ uid_t *domain_children;
29551 ++ __u16 domain_child_num;
29552 ++
29553 ++ struct acl_subject_label **subj_hash;
29554 ++ __u32 subj_hash_size;
29555 ++};
29556 ++
29557 ++struct user_acl_role_db {
29558 ++ struct acl_role_label **r_table;
29559 ++ __u32 num_pointers; /* Number of allocations to track */
29560 ++ __u32 num_roles; /* Number of roles */
29561 ++ __u32 num_domain_children; /* Number of domain children */
29562 ++ __u32 num_subjects; /* Number of subjects */
29563 ++ __u32 num_objects; /* Number of objects */
29564 ++};
29565 ++
29566 ++struct acl_object_label {
29567 ++ char *filename;
29568 ++ ino_t inode;
29569 ++ dev_t device;
29570 ++ __u32 mode;
29571 ++
29572 ++ struct acl_subject_label *nested;
29573 ++ struct acl_object_label *globbed;
29574 ++
29575 ++ /* next two structures not used */
29576 ++
29577 ++ struct acl_object_label *prev;
29578 ++ struct acl_object_label *next;
29579 ++};
29580 ++
29581 ++struct acl_ip_label {
29582 ++ char *iface;
29583 ++ __u32 addr;
29584 ++ __u32 netmask;
29585 ++ __u16 low, high;
29586 ++ __u8 mode;
29587 ++ __u32 type;
29588 ++ __u32 proto[8];
29589 ++
29590 ++ /* next two structures not used */
29591 ++
29592 ++ struct acl_ip_label *prev;
29593 ++ struct acl_ip_label *next;
29594 ++};
29595 ++
29596 ++struct gr_arg {
29597 ++ struct user_acl_role_db role_db;
29598 ++ unsigned char pw[GR_PW_LEN];
29599 ++ unsigned char salt[GR_SALT_LEN];
29600 ++ unsigned char sum[GR_SHA_LEN];
29601 ++ unsigned char sp_role[GR_SPROLE_LEN];
29602 ++ struct sprole_pw *sprole_pws;
29603 ++ dev_t segv_device;
29604 ++ ino_t segv_inode;
29605 ++ uid_t segv_uid;
29606 ++ __u16 num_sprole_pws;
29607 ++ __u16 mode;
29608 ++};
29609 ++
29610 ++struct gr_arg_wrapper {
29611 ++ struct gr_arg *arg;
29612 ++ __u32 version;
29613 ++ __u32 size;
29614 ++};
29615 ++
29616 ++struct subject_map {
29617 ++ struct acl_subject_label *user;
29618 ++ struct acl_subject_label *kernel;
29619 ++ struct subject_map *prev;
29620 ++ struct subject_map *next;
29621 ++};
29622 ++
29623 ++struct acl_subj_map_db {
29624 ++ struct subject_map **s_hash;
29625 ++ __u32 s_size;
29626 ++};
29627 ++
29628 ++/* End Data Structures Section */
29629 ++
29630 ++/* Hash functions generated by empirical testing by Brad Spengler
29631 ++ Makes good use of the low bits of the inode. Generally 0-1 times
29632 ++ in loop for successful match. 0-3 for unsuccessful match.
29633 ++ Shift/add algorithm with modulus of table size and an XOR*/
29634 ++
29635 ++static __inline__ unsigned int
29636 ++rhash(const uid_t uid, const __u16 type, const unsigned int sz)
29637 ++{
29638 ++ return (((uid << type) + (uid ^ type)) % sz);
29639 ++}
29640 ++
29641 ++ static __inline__ unsigned int
29642 ++shash(const struct acl_subject_label *userp, const unsigned int sz)
29643 ++{
29644 ++ return ((const unsigned long)userp % sz);
29645 ++}
29646 ++
29647 ++static __inline__ unsigned int
29648 ++fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
29649 ++{
29650 ++ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
29651 ++}
29652 ++
29653 ++static __inline__ unsigned int
29654 ++nhash(const char *name, const __u16 len, const unsigned int sz)
29655 ++{
29656 ++ return full_name_hash(name, len) % sz;
29657 ++}
29658 ++
29659 ++#define FOR_EACH_ROLE_START(role,iter) \
29660 ++ role = NULL; \
29661 ++ iter = 0; \
29662 ++ while (iter < acl_role_set.r_size) { \
29663 ++ if (role == NULL) \
29664 ++ role = acl_role_set.r_hash[iter]; \
29665 ++ if (role == NULL) { \
29666 ++ iter++; \
29667 ++ continue; \
29668 ++ }
29669 ++
29670 ++#define FOR_EACH_ROLE_END(role,iter) \
29671 ++ role = role->next; \
29672 ++ if (role == NULL) \
29673 ++ iter++; \
29674 ++ }
29675 ++
29676 ++#define FOR_EACH_SUBJECT_START(role,subj,iter) \
29677 ++ subj = NULL; \
29678 ++ iter = 0; \
29679 ++ while (iter < role->subj_hash_size) { \
29680 ++ if (subj == NULL) \
29681 ++ subj = role->subj_hash[iter]; \
29682 ++ if (subj == NULL) { \
29683 ++ iter++; \
29684 ++ continue; \
29685 ++ }
29686 ++
29687 ++#define FOR_EACH_SUBJECT_END(subj,iter) \
29688 ++ subj = subj->next; \
29689 ++ if (subj == NULL) \
29690 ++ iter++; \
29691 ++ }
29692 ++
29693 ++
29694 ++#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
29695 ++ subj = role->hash->first; \
29696 ++ while (subj != NULL) {
29697 ++
29698 ++#define FOR_EACH_NESTED_SUBJECT_END(subj) \
29699 ++ subj = subj->next; \
29700 ++ }
29701 ++
29702 ++#endif
29703 ++
29704 +diff -urNp linux-2.6.27.10/include/linux/gralloc.h linux-2.6.27.10/include/linux/gralloc.h
29705 +--- linux-2.6.27.10/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
29706 ++++ linux-2.6.27.10/include/linux/gralloc.h 2008-11-18 03:38:45.000000000 -0500
29707 +@@ -0,0 +1,8 @@
29708 ++#ifndef __GRALLOC_H
29709 ++#define __GRALLOC_H
29710 ++
29711 ++void acl_free_all(void);
29712 ++int acl_alloc_stack_init(unsigned long size);
29713 ++void *acl_alloc(unsigned long len);
29714 ++
29715 ++#endif
29716 +diff -urNp linux-2.6.27.10/include/linux/grdefs.h linux-2.6.27.10/include/linux/grdefs.h
29717 +--- linux-2.6.27.10/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
29718 ++++ linux-2.6.27.10/include/linux/grdefs.h 2008-11-18 03:38:45.000000000 -0500
29719 +@@ -0,0 +1,131 @@
29720 ++#ifndef GRDEFS_H
29721 ++#define GRDEFS_H
29722 ++
29723 ++/* Begin grsecurity status declarations */
29724 ++
29725 ++enum {
29726 ++ GR_READY = 0x01,
29727 ++ GR_STATUS_INIT = 0x00 // disabled state
29728 ++};
29729 ++
29730 ++/* Begin ACL declarations */
29731 ++
29732 ++/* Role flags */
29733 ++
29734 ++enum {
29735 ++ GR_ROLE_USER = 0x0001,
29736 ++ GR_ROLE_GROUP = 0x0002,
29737 ++ GR_ROLE_DEFAULT = 0x0004,
29738 ++ GR_ROLE_SPECIAL = 0x0008,
29739 ++ GR_ROLE_AUTH = 0x0010,
29740 ++ GR_ROLE_NOPW = 0x0020,
29741 ++ GR_ROLE_GOD = 0x0040,
29742 ++ GR_ROLE_LEARN = 0x0080,
29743 ++ GR_ROLE_TPE = 0x0100,
29744 ++ GR_ROLE_DOMAIN = 0x0200,
29745 ++ GR_ROLE_PAM = 0x0400
29746 ++};
29747 ++
29748 ++/* ACL Subject and Object mode flags */
29749 ++enum {
29750 ++ GR_DELETED = 0x80000000
29751 ++};
29752 ++
29753 ++/* ACL Object-only mode flags */
29754 ++enum {
29755 ++ GR_READ = 0x00000001,
29756 ++ GR_APPEND = 0x00000002,
29757 ++ GR_WRITE = 0x00000004,
29758 ++ GR_EXEC = 0x00000008,
29759 ++ GR_FIND = 0x00000010,
29760 ++ GR_INHERIT = 0x00000020,
29761 ++ GR_SETID = 0x00000040,
29762 ++ GR_CREATE = 0x00000080,
29763 ++ GR_DELETE = 0x00000100,
29764 ++ GR_LINK = 0x00000200,
29765 ++ GR_AUDIT_READ = 0x00000400,
29766 ++ GR_AUDIT_APPEND = 0x00000800,
29767 ++ GR_AUDIT_WRITE = 0x00001000,
29768 ++ GR_AUDIT_EXEC = 0x00002000,
29769 ++ GR_AUDIT_FIND = 0x00004000,
29770 ++ GR_AUDIT_INHERIT= 0x00008000,
29771 ++ GR_AUDIT_SETID = 0x00010000,
29772 ++ GR_AUDIT_CREATE = 0x00020000,
29773 ++ GR_AUDIT_DELETE = 0x00040000,
29774 ++ GR_AUDIT_LINK = 0x00080000,
29775 ++ GR_PTRACERD = 0x00100000,
29776 ++ GR_NOPTRACE = 0x00200000,
29777 ++ GR_SUPPRESS = 0x00400000,
29778 ++ GR_NOLEARN = 0x00800000
29779 ++};
29780 ++
29781 ++#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
29782 ++ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
29783 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
29784 ++
29785 ++/* ACL subject-only mode flags */
29786 ++enum {
29787 ++ GR_KILL = 0x00000001,
29788 ++ GR_VIEW = 0x00000002,
29789 ++ GR_PROTECTED = 0x00000004,
29790 ++ GR_LEARN = 0x00000008,
29791 ++ GR_OVERRIDE = 0x00000010,
29792 ++ /* just a placeholder, this mode is only used in userspace */
29793 ++ GR_DUMMY = 0x00000020,
29794 ++ GR_PROTSHM = 0x00000040,
29795 ++ GR_KILLPROC = 0x00000080,
29796 ++ GR_KILLIPPROC = 0x00000100,
29797 ++ /* just a placeholder, this mode is only used in userspace */
29798 ++ GR_NOTROJAN = 0x00000200,
29799 ++ GR_PROTPROCFD = 0x00000400,
29800 ++ GR_PROCACCT = 0x00000800,
29801 ++ GR_RELAXPTRACE = 0x00001000,
29802 ++ GR_NESTED = 0x00002000,
29803 ++ GR_INHERITLEARN = 0x00004000,
29804 ++ GR_PROCFIND = 0x00008000,
29805 ++ GR_POVERRIDE = 0x00010000,
29806 ++ GR_KERNELAUTH = 0x00020000,
29807 ++};
29808 ++
29809 ++enum {
29810 ++ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
29811 ++ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
29812 ++ GR_PAX_ENABLE_MPROTECT = 0x0004,
29813 ++ GR_PAX_ENABLE_RANDMMAP = 0x0008,
29814 ++ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
29815 ++ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
29816 ++ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
29817 ++ GR_PAX_DISABLE_MPROTECT = 0x0400,
29818 ++ GR_PAX_DISABLE_RANDMMAP = 0x0800,
29819 ++ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
29820 ++};
29821 ++
29822 ++enum {
29823 ++ GR_ID_USER = 0x01,
29824 ++ GR_ID_GROUP = 0x02,
29825 ++};
29826 ++
29827 ++enum {
29828 ++ GR_ID_ALLOW = 0x01,
29829 ++ GR_ID_DENY = 0x02,
29830 ++};
29831 ++
29832 ++#define GR_CRASH_RES 11
29833 ++#define GR_UIDTABLE_MAX 500
29834 ++
29835 ++/* begin resource learning section */
29836 ++enum {
29837 ++ GR_RLIM_CPU_BUMP = 60,
29838 ++ GR_RLIM_FSIZE_BUMP = 50000,
29839 ++ GR_RLIM_DATA_BUMP = 10000,
29840 ++ GR_RLIM_STACK_BUMP = 1000,
29841 ++ GR_RLIM_CORE_BUMP = 10000,
29842 ++ GR_RLIM_RSS_BUMP = 500000,
29843 ++ GR_RLIM_NPROC_BUMP = 1,
29844 ++ GR_RLIM_NOFILE_BUMP = 5,
29845 ++ GR_RLIM_MEMLOCK_BUMP = 50000,
29846 ++ GR_RLIM_AS_BUMP = 500000,
29847 ++ GR_RLIM_LOCKS_BUMP = 2
29848 ++};
29849 ++
29850 ++#endif
29851 +diff -urNp linux-2.6.27.10/include/linux/grinternal.h linux-2.6.27.10/include/linux/grinternal.h
29852 +--- linux-2.6.27.10/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
29853 ++++ linux-2.6.27.10/include/linux/grinternal.h 2008-11-18 03:38:45.000000000 -0500
29854 +@@ -0,0 +1,210 @@
29855 ++#ifndef __GRINTERNAL_H
29856 ++#define __GRINTERNAL_H
29857 ++
29858 ++#ifdef CONFIG_GRKERNSEC
29859 ++
29860 ++#include <linux/fs.h>
29861 ++#include <linux/gracl.h>
29862 ++#include <linux/grdefs.h>
29863 ++#include <linux/grmsg.h>
29864 ++
29865 ++void gr_add_learn_entry(const char *fmt, ...);
29866 ++__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
29867 ++ const struct vfsmount *mnt);
29868 ++__u32 gr_check_create(const struct dentry *new_dentry,
29869 ++ const struct dentry *parent,
29870 ++ const struct vfsmount *mnt, const __u32 mode);
29871 ++int gr_check_protected_task(const struct task_struct *task);
29872 ++__u32 to_gr_audit(const __u32 reqmode);
29873 ++int gr_set_acls(const int type);
29874 ++
29875 ++int gr_acl_is_enabled(void);
29876 ++char gr_roletype_to_char(void);
29877 ++
29878 ++void gr_handle_alertkill(struct task_struct *task);
29879 ++char *gr_to_filename(const struct dentry *dentry,
29880 ++ const struct vfsmount *mnt);
29881 ++char *gr_to_filename1(const struct dentry *dentry,
29882 ++ const struct vfsmount *mnt);
29883 ++char *gr_to_filename2(const struct dentry *dentry,
29884 ++ const struct vfsmount *mnt);
29885 ++char *gr_to_filename3(const struct dentry *dentry,
29886 ++ const struct vfsmount *mnt);
29887 ++
29888 ++extern int grsec_enable_link;
29889 ++extern int grsec_enable_fifo;
29890 ++extern int grsec_enable_execve;
29891 ++extern int grsec_enable_shm;
29892 ++extern int grsec_enable_execlog;
29893 ++extern int grsec_enable_signal;
29894 ++extern int grsec_enable_forkfail;
29895 ++extern int grsec_enable_time;
29896 ++extern int grsec_enable_chroot_shmat;
29897 ++extern int grsec_enable_chroot_findtask;
29898 ++extern int grsec_enable_chroot_mount;
29899 ++extern int grsec_enable_chroot_double;
29900 ++extern int grsec_enable_chroot_pivot;
29901 ++extern int grsec_enable_chroot_chdir;
29902 ++extern int grsec_enable_chroot_chmod;
29903 ++extern int grsec_enable_chroot_mknod;
29904 ++extern int grsec_enable_chroot_fchdir;
29905 ++extern int grsec_enable_chroot_nice;
29906 ++extern int grsec_enable_chroot_execlog;
29907 ++extern int grsec_enable_chroot_caps;
29908 ++extern int grsec_enable_chroot_sysctl;
29909 ++extern int grsec_enable_chroot_unix;
29910 ++extern int grsec_enable_tpe;
29911 ++extern int grsec_tpe_gid;
29912 ++extern int grsec_enable_tpe_all;
29913 ++extern int grsec_enable_sidcaps;
29914 ++extern int grsec_enable_socket_all;
29915 ++extern int grsec_socket_all_gid;
29916 ++extern int grsec_enable_socket_client;
29917 ++extern int grsec_socket_client_gid;
29918 ++extern int grsec_enable_socket_server;
29919 ++extern int grsec_socket_server_gid;
29920 ++extern int grsec_audit_gid;
29921 ++extern int grsec_enable_group;
29922 ++extern int grsec_enable_audit_ipc;
29923 ++extern int grsec_enable_audit_textrel;
29924 ++extern int grsec_enable_mount;
29925 ++extern int grsec_enable_chdir;
29926 ++extern int grsec_resource_logging;
29927 ++extern int grsec_lock;
29928 ++
29929 ++extern spinlock_t grsec_alert_lock;
29930 ++extern unsigned long grsec_alert_wtime;
29931 ++extern unsigned long grsec_alert_fyet;
29932 ++
29933 ++extern spinlock_t grsec_audit_lock;
29934 ++
29935 ++extern rwlock_t grsec_exec_file_lock;
29936 ++
29937 ++#define gr_task_fullpath(tsk) (tsk->exec_file ? \
29938 ++ gr_to_filename2(tsk->exec_file->f_path.dentry, \
29939 ++ tsk->exec_file->f_vfsmnt) : "/")
29940 ++
29941 ++#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \
29942 ++ gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \
29943 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
29944 ++
29945 ++#define gr_task_fullpath0(tsk) (tsk->exec_file ? \
29946 ++ gr_to_filename(tsk->exec_file->f_path.dentry, \
29947 ++ tsk->exec_file->f_vfsmnt) : "/")
29948 ++
29949 ++#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \
29950 ++ gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \
29951 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
29952 ++
29953 ++#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \
29954 ++ ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \
29955 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \
29956 ++ (tsk_a->fs->root.dentry->d_inode->i_ino != \
29957 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino)))
29958 ++
29959 ++#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \
29960 ++ (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \
29961 ++ tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \
29962 ++ (tsk_a->fs->root.dentry->d_inode->i_ino == \
29963 ++ tsk_b->fs->root.dentry->d_inode->i_ino))
29964 ++
29965 ++#define DEFAULTSECARGS(task) gr_task_fullpath(task), task->comm, \
29966 ++ task->pid, task->uid, \
29967 ++ task->euid, task->gid, task->egid, \
29968 ++ gr_parent_task_fullpath(task), \
29969 ++ task->parent->comm, task->parent->pid, \
29970 ++ task->parent->uid, task->parent->euid, \
29971 ++ task->parent->gid, task->parent->egid
29972 ++
29973 ++#define GR_CHROOT_CAPS {{ \
29974 ++ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
29975 ++ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
29976 ++ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
29977 ++ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
29978 ++ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
29979 ++ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
29980 ++
29981 ++#define security_learn(normal_msg,args...) \
29982 ++({ \
29983 ++ read_lock(&grsec_exec_file_lock); \
29984 ++ gr_add_learn_entry(normal_msg "\n", ## args); \
29985 ++ read_unlock(&grsec_exec_file_lock); \
29986 ++})
29987 ++
29988 ++enum {
29989 ++ GR_DO_AUDIT,
29990 ++ GR_DONT_AUDIT,
29991 ++ GR_DONT_AUDIT_GOOD
29992 ++};
29993 ++
29994 ++enum {
29995 ++ GR_TTYSNIFF,
29996 ++ GR_RBAC,
29997 ++ GR_RBAC_STR,
29998 ++ GR_STR_RBAC,
29999 ++ GR_RBAC_MODE2,
30000 ++ GR_RBAC_MODE3,
30001 ++ GR_FILENAME,
30002 ++ GR_SYSCTL_HIDDEN,
30003 ++ GR_NOARGS,
30004 ++ GR_ONE_INT,
30005 ++ GR_ONE_INT_TWO_STR,
30006 ++ GR_ONE_STR,
30007 ++ GR_STR_INT,
30008 ++ GR_TWO_INT,
30009 ++ GR_THREE_INT,
30010 ++ GR_FIVE_INT_TWO_STR,
30011 ++ GR_TWO_STR,
30012 ++ GR_THREE_STR,
30013 ++ GR_FOUR_STR,
30014 ++ GR_STR_FILENAME,
30015 ++ GR_FILENAME_STR,
30016 ++ GR_FILENAME_TWO_INT,
30017 ++ GR_FILENAME_TWO_INT_STR,
30018 ++ GR_TEXTREL,
30019 ++ GR_PTRACE,
30020 ++ GR_RESOURCE,
30021 ++ GR_CAP,
30022 ++ GR_SIG,
30023 ++ GR_CRASH1,
30024 ++ GR_CRASH2,
30025 ++ GR_PSACCT
30026 ++};
30027 ++
30028 ++#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
30029 ++#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
30030 ++#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
30031 ++#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
30032 ++#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
30033 ++#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
30034 ++#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)
30035 ++#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
30036 ++#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
30037 ++#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
30038 ++#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
30039 ++#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
30040 ++#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
30041 ++#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
30042 ++#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
30043 ++#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)
30044 ++#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
30045 ++#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
30046 ++#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
30047 ++#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
30048 ++#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
30049 ++#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
30050 ++#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)
30051 ++#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
30052 ++#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
30053 ++#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
30054 ++#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
30055 ++#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num)
30056 ++#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
30057 ++#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
30058 ++#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)
30059 ++
30060 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
30061 ++
30062 ++#endif
30063 ++
30064 ++#endif
30065 +diff -urNp linux-2.6.27.10/include/linux/grmsg.h linux-2.6.27.10/include/linux/grmsg.h
30066 +--- linux-2.6.27.10/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
30067 ++++ linux-2.6.27.10/include/linux/grmsg.h 2008-11-18 03:38:45.000000000 -0500
30068 +@@ -0,0 +1,108 @@
30069 ++#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"
30070 ++#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"
30071 ++#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
30072 ++#define GR_STOPMOD_MSG "denied modification of module state by "
30073 ++#define GR_IOPERM_MSG "denied use of ioperm() by "
30074 ++#define GR_IOPL_MSG "denied use of iopl() by "
30075 ++#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
30076 ++#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
30077 ++#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
30078 ++#define GR_KMEM_MSG "denied write of /dev/kmem by "
30079 ++#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
30080 ++#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
30081 ++#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
30082 ++#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
30083 ++#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"
30084 ++#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"
30085 ++#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
30086 ++#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
30087 ++#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
30088 ++#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
30089 ++#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
30090 ++#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
30091 ++#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
30092 ++#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
30093 ++#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
30094 ++#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
30095 ++#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
30096 ++#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
30097 ++#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
30098 ++#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
30099 ++#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
30100 ++#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
30101 ++#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
30102 ++#define GR_NPROC_MSG "denied overstep of process limit by "
30103 ++#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
30104 ++#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
30105 ++#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
30106 ++#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
30107 ++#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
30108 ++#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
30109 ++#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
30110 ++#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
30111 ++#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
30112 ++#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
30113 ++#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
30114 ++#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
30115 ++#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
30116 ++#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
30117 ++#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
30118 ++#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
30119 ++#define GR_INITF_ACL_MSG "init_variables() failed %s by "
30120 ++#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"
30121 ++#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
30122 ++#define GR_SHUTS_ACL_MSG "shutdown auth success for "
30123 ++#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
30124 ++#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
30125 ++#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
30126 ++#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
30127 ++#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
30128 ++#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
30129 ++#define GR_ENABLEF_ACL_MSG "unable to load %s for "
30130 ++#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
30131 ++#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
30132 ++#define GR_RELOADF_ACL_MSG "failed reload of %s for "
30133 ++#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
30134 ++#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
30135 ++#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
30136 ++#define GR_SPROLEF_ACL_MSG "special role %s failure for "
30137 ++#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
30138 ++#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
30139 ++#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for "
30140 ++#define GR_INVMODE_ACL_MSG "invalid mode %d by "
30141 ++#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
30142 ++#define GR_FAILFORK_MSG "failed fork with errno %d by "
30143 ++#define GR_NICE_CHROOT_MSG "denied priority change by "
30144 ++#define GR_UNISIGLOG_MSG "signal %d sent to "
30145 ++#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
30146 ++#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
30147 ++#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
30148 ++#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
30149 ++#define GR_TIME_MSG "time set by "
30150 ++#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
30151 ++#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
30152 ++#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
30153 ++#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
30154 ++#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by "
30155 ++#define GR_BIND_MSG "denied bind() by "
30156 ++#define GR_CONNECT_MSG "denied connect() by "
30157 ++#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30158 ++#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30159 ++#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"
30160 ++#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
30161 ++#define GR_CAP_ACL_MSG "use of %s denied for "
30162 ++#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
30163 ++#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
30164 ++#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
30165 ++#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
30166 ++#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
30167 ++#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
30168 ++#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
30169 ++#define GR_MSGQ_AUDIT_MSG "message queue created by "
30170 ++#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by "
30171 ++#define GR_SEM_AUDIT_MSG "semaphore created by "
30172 ++#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by "
30173 ++#define GR_SHM_AUDIT_MSG "shared memory of size %d created by "
30174 ++#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by "
30175 ++#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
30176 ++#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
30177 +diff -urNp linux-2.6.27.10/include/linux/grsecurity.h linux-2.6.27.10/include/linux/grsecurity.h
30178 +--- linux-2.6.27.10/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
30179 ++++ linux-2.6.27.10/include/linux/grsecurity.h 2008-11-18 03:38:45.000000000 -0500
30180 +@@ -0,0 +1,200 @@
30181 ++#ifndef GR_SECURITY_H
30182 ++#define GR_SECURITY_H
30183 ++#include <linux/fs.h>
30184 ++#include <linux/binfmts.h>
30185 ++#include <linux/gracl.h>
30186 ++
30187 ++/* notify of brain-dead configs */
30188 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
30189 ++#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
30190 ++#endif
30191 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30192 ++#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30193 ++#endif
30194 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30195 ++#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30196 ++#endif
30197 ++#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
30198 ++#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
30199 ++#endif
30200 ++#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
30201 ++#error "CONFIG_PAX enabled, but no PaX options are enabled."
30202 ++#endif
30203 ++
30204 ++void gr_handle_brute_attach(struct task_struct *p);
30205 ++void gr_handle_brute_check(void);
30206 ++
30207 ++char gr_roletype_to_char(void);
30208 ++
30209 ++int gr_check_user_change(int real, int effective, int fs);
30210 ++int gr_check_group_change(int real, int effective, int fs);
30211 ++
30212 ++void gr_del_task_from_ip_table(struct task_struct *p);
30213 ++
30214 ++int gr_pid_is_chrooted(struct task_struct *p);
30215 ++int gr_handle_chroot_nice(void);
30216 ++int gr_handle_chroot_sysctl(const int op);
30217 ++int gr_handle_chroot_setpriority(struct task_struct *p,
30218 ++ const int niceval);
30219 ++int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
30220 ++int gr_handle_chroot_chroot(const struct dentry *dentry,
30221 ++ const struct vfsmount *mnt);
30222 ++void gr_handle_chroot_caps(struct task_struct *task);
30223 ++void gr_handle_chroot_chdir(struct path *path);
30224 ++int gr_handle_chroot_chmod(const struct dentry *dentry,
30225 ++ const struct vfsmount *mnt, const int mode);
30226 ++int gr_handle_chroot_mknod(const struct dentry *dentry,
30227 ++ const struct vfsmount *mnt, const int mode);
30228 ++int gr_handle_chroot_mount(const struct dentry *dentry,
30229 ++ const struct vfsmount *mnt,
30230 ++ const char *dev_name);
30231 ++int gr_handle_chroot_pivot(void);
30232 ++int gr_handle_chroot_unix(const pid_t pid);
30233 ++
30234 ++int gr_handle_rawio(const struct inode *inode);
30235 ++int gr_handle_nproc(void);
30236 ++
30237 ++void gr_handle_ioperm(void);
30238 ++void gr_handle_iopl(void);
30239 ++
30240 ++int gr_tpe_allow(const struct file *file);
30241 ++
30242 ++int gr_random_pid(void);
30243 ++
30244 ++void gr_log_forkfail(const int retval);
30245 ++void gr_log_timechange(void);
30246 ++void gr_log_signal(const int sig, const struct task_struct *t);
30247 ++void gr_log_chdir(const struct dentry *dentry,
30248 ++ const struct vfsmount *mnt);
30249 ++void gr_log_chroot_exec(const struct dentry *dentry,
30250 ++ const struct vfsmount *mnt);
30251 ++void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
30252 ++void gr_log_remount(const char *devname, const int retval);
30253 ++void gr_log_unmount(const char *devname, const int retval);
30254 ++void gr_log_mount(const char *from, const char *to, const int retval);
30255 ++void gr_log_msgget(const int ret, const int msgflg);
30256 ++void gr_log_msgrm(const uid_t uid, const uid_t cuid);
30257 ++void gr_log_semget(const int err, const int semflg);
30258 ++void gr_log_semrm(const uid_t uid, const uid_t cuid);
30259 ++void gr_log_shmget(const int err, const int shmflg, const size_t size);
30260 ++void gr_log_shmrm(const uid_t uid, const uid_t cuid);
30261 ++void gr_log_textrel(struct vm_area_struct *vma);
30262 ++
30263 ++int gr_handle_follow_link(const struct inode *parent,
30264 ++ const struct inode *inode,
30265 ++ const struct dentry *dentry,
30266 ++ const struct vfsmount *mnt);
30267 ++int gr_handle_fifo(const struct dentry *dentry,
30268 ++ const struct vfsmount *mnt,
30269 ++ const struct dentry *dir, const int flag,
30270 ++ const int acc_mode);
30271 ++int gr_handle_hardlink(const struct dentry *dentry,
30272 ++ const struct vfsmount *mnt,
30273 ++ struct inode *inode,
30274 ++ const int mode, const char *to);
30275 ++
30276 ++int gr_task_is_capable(struct task_struct *task, const int cap);
30277 ++int gr_is_capable_nolog(const int cap);
30278 ++void gr_learn_resource(const struct task_struct *task, const int limit,
30279 ++ const unsigned long wanted, const int gt);
30280 ++void gr_copy_label(struct task_struct *tsk);
30281 ++void gr_handle_crash(struct task_struct *task, const int sig);
30282 ++int gr_handle_signal(const struct task_struct *p, const int sig);
30283 ++int gr_check_crash_uid(const uid_t uid);
30284 ++int gr_check_protected_task(const struct task_struct *task);
30285 ++int gr_acl_handle_mmap(const struct file *file,
30286 ++ const unsigned long prot);
30287 ++int gr_acl_handle_mprotect(const struct file *file,
30288 ++ const unsigned long prot);
30289 ++int gr_check_hidden_task(const struct task_struct *tsk);
30290 ++__u32 gr_acl_handle_truncate(const struct dentry *dentry,
30291 ++ const struct vfsmount *mnt);
30292 ++__u32 gr_acl_handle_utime(const struct dentry *dentry,
30293 ++ const struct vfsmount *mnt);
30294 ++__u32 gr_acl_handle_access(const struct dentry *dentry,
30295 ++ const struct vfsmount *mnt, const int fmode);
30296 ++__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
30297 ++ const struct vfsmount *mnt, mode_t mode);
30298 ++__u32 gr_acl_handle_chmod(const struct dentry *dentry,
30299 ++ const struct vfsmount *mnt, mode_t mode);
30300 ++__u32 gr_acl_handle_chown(const struct dentry *dentry,
30301 ++ const struct vfsmount *mnt);
30302 ++int gr_handle_ptrace(struct task_struct *task, const long request);
30303 ++int gr_handle_proc_ptrace(struct task_struct *task);
30304 ++__u32 gr_acl_handle_execve(const struct dentry *dentry,
30305 ++ const struct vfsmount *mnt);
30306 ++int gr_check_crash_exec(const struct file *filp);
30307 ++int gr_acl_is_enabled(void);
30308 ++void gr_set_kernel_label(struct task_struct *task);
30309 ++void gr_set_role_label(struct task_struct *task, const uid_t uid,
30310 ++ const gid_t gid);
30311 ++int gr_set_proc_label(const struct dentry *dentry,
30312 ++ const struct vfsmount *mnt);
30313 ++__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
30314 ++ const struct vfsmount *mnt);
30315 ++__u32 gr_acl_handle_open(const struct dentry *dentry,
30316 ++ const struct vfsmount *mnt, const int fmode);
30317 ++__u32 gr_acl_handle_creat(const struct dentry *dentry,
30318 ++ const struct dentry *p_dentry,
30319 ++ const struct vfsmount *p_mnt, const int fmode,
30320 ++ const int imode);
30321 ++void gr_handle_create(const struct dentry *dentry,
30322 ++ const struct vfsmount *mnt);
30323 ++__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
30324 ++ const struct dentry *parent_dentry,
30325 ++ const struct vfsmount *parent_mnt,
30326 ++ const int mode);
30327 ++__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
30328 ++ const struct dentry *parent_dentry,
30329 ++ const struct vfsmount *parent_mnt);
30330 ++__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
30331 ++ const struct vfsmount *mnt);
30332 ++void gr_handle_delete(const ino_t ino, const dev_t dev);
30333 ++__u32 gr_acl_handle_unlink(const struct dentry *dentry,
30334 ++ const struct vfsmount *mnt);
30335 ++__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
30336 ++ const struct dentry *parent_dentry,
30337 ++ const struct vfsmount *parent_mnt,
30338 ++ const char *from);
30339 ++__u32 gr_acl_handle_link(const struct dentry *new_dentry,
30340 ++ const struct dentry *parent_dentry,
30341 ++ const struct vfsmount *parent_mnt,
30342 ++ const struct dentry *old_dentry,
30343 ++ const struct vfsmount *old_mnt, const char *to);
30344 ++int gr_acl_handle_rename(struct dentry *new_dentry,
30345 ++ struct dentry *parent_dentry,
30346 ++ const struct vfsmount *parent_mnt,
30347 ++ struct dentry *old_dentry,
30348 ++ struct inode *old_parent_inode,
30349 ++ struct vfsmount *old_mnt, const char *newname);
30350 ++void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
30351 ++ struct dentry *old_dentry,
30352 ++ struct dentry *new_dentry,
30353 ++ struct vfsmount *mnt, const __u8 replace);
30354 ++__u32 gr_check_link(const struct dentry *new_dentry,
30355 ++ const struct dentry *parent_dentry,
30356 ++ const struct vfsmount *parent_mnt,
30357 ++ const struct dentry *old_dentry,
30358 ++ const struct vfsmount *old_mnt);
30359 ++int gr_acl_handle_filldir(const struct file *file, const char *name,
30360 ++ const unsigned int namelen, const ino_t ino);
30361 ++
30362 ++__u32 gr_acl_handle_unix(const struct dentry *dentry,
30363 ++ const struct vfsmount *mnt);
30364 ++void gr_acl_handle_exit(void);
30365 ++void gr_acl_handle_psacct(struct task_struct *task, const long code);
30366 ++int gr_acl_handle_procpidmem(const struct task_struct *task);
30367 ++
30368 ++#ifdef CONFIG_GRKERNSEC
30369 ++void gr_handle_mem_write(void);
30370 ++void gr_handle_kmem_write(void);
30371 ++void gr_handle_open_port(void);
30372 ++int gr_handle_mem_mmap(const unsigned long offset,
30373 ++ struct vm_area_struct *vma);
30374 ++
30375 ++extern int grsec_enable_dmesg;
30376 ++extern int grsec_enable_randsrc;
30377 ++extern int grsec_enable_shm;
30378 ++#endif
30379 ++
30380 ++#endif
30381 +diff -urNp linux-2.6.27.10/include/linux/highmem.h linux-2.6.27.10/include/linux/highmem.h
30382 +--- linux-2.6.27.10/include/linux/highmem.h 2008-11-07 12:55:34.000000000 -0500
30383 ++++ linux-2.6.27.10/include/linux/highmem.h 2008-11-18 03:38:45.000000000 -0500
30384 +@@ -122,6 +122,13 @@ static inline void clear_highpage(struct
30385 + kunmap_atomic(kaddr, KM_USER0);
30386 + }
30387 +
30388 ++static inline void sanitize_highpage(struct page *page)
30389 ++{
30390 ++ void *kaddr = kmap_atomic(page, KM_CLEARPAGE);
30391 ++ clear_page(kaddr);
30392 ++ kunmap_atomic(kaddr, KM_CLEARPAGE);
30393 ++}
30394 ++
30395 + static inline void zero_user_segments(struct page *page,
30396 + unsigned start1, unsigned end1,
30397 + unsigned start2, unsigned end2)
30398 +diff -urNp linux-2.6.27.10/include/linux/jbd2.h linux-2.6.27.10/include/linux/jbd2.h
30399 +--- linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:38.000000000 -0500
30400 ++++ linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:46.000000000 -0500
30401 +@@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug;
30402 + } \
30403 + } while (0)
30404 + #else
30405 +-#define jbd_debug(f, a...) /**/
30406 ++#define jbd_debug(f, a...) do {} while (0)
30407 + #endif
30408 +
30409 + static inline void *jbd2_alloc(size_t size, gfp_t flags)
30410 +diff -urNp linux-2.6.27.10/include/linux/jbd.h linux-2.6.27.10/include/linux/jbd.h
30411 +--- linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:16:52.000000000 -0500
30412 ++++ linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:13:46.000000000 -0500
30413 +@@ -66,7 +66,7 @@ extern u8 journal_enable_debug;
30414 + } \
30415 + } while (0)
30416 + #else
30417 +-#define jbd_debug(f, a...) /**/
30418 ++#define jbd_debug(f, a...) do {} while (0)
30419 + #endif
30420 +
30421 + static inline void *jbd_alloc(size_t size, gfp_t flags)
30422 +diff -urNp linux-2.6.27.10/include/linux/libata.h linux-2.6.27.10/include/linux/libata.h
30423 +--- linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:38.000000000 -0500
30424 ++++ linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:46.000000000 -0500
30425 +@@ -64,11 +64,11 @@
30426 + #ifdef ATA_VERBOSE_DEBUG
30427 + #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30428 + #else
30429 +-#define VPRINTK(fmt, args...)
30430 ++#define VPRINTK(fmt, args...) do {} while (0)
30431 + #endif /* ATA_VERBOSE_DEBUG */
30432 + #else
30433 +-#define DPRINTK(fmt, args...)
30434 +-#define VPRINTK(fmt, args...)
30435 ++#define DPRINTK(fmt, args...) do {} while (0)
30436 ++#define VPRINTK(fmt, args...) do {} while (0)
30437 + #endif /* ATA_DEBUG */
30438 +
30439 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30440 +diff -urNp linux-2.6.27.10/include/linux/mm.h linux-2.6.27.10/include/linux/mm.h
30441 +--- linux-2.6.27.10/include/linux/mm.h 2008-11-07 12:55:34.000000000 -0500
30442 ++++ linux-2.6.27.10/include/linux/mm.h 2008-12-21 00:44:29.000000000 -0500
30443 +@@ -38,6 +38,7 @@ extern unsigned long mmap_min_addr;
30444 + #include <asm/page.h>
30445 + #include <asm/pgtable.h>
30446 + #include <asm/processor.h>
30447 ++#include <asm/mman.h>
30448 +
30449 + #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
30450 +
30451 +@@ -114,6 +115,10 @@ extern unsigned int kobjsize(const void
30452 + #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
30453 + #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
30454 +
30455 ++#ifdef CONFIG_PAX_PAGEEXEC
30456 ++#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */
30457 ++#endif
30458 ++
30459 + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
30460 + #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
30461 + #endif
30462 +@@ -874,6 +879,8 @@ struct shrinker {
30463 + extern void register_shrinker(struct shrinker *);
30464 + extern void unregister_shrinker(struct shrinker *);
30465 +
30466 ++pgprot_t vm_get_page_prot(unsigned long vm_flags);
30467 ++
30468 + int vma_wants_writenotify(struct vm_area_struct *vma);
30469 +
30470 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
30471 +@@ -1129,6 +1136,7 @@ out:
30472 + }
30473 +
30474 + extern int do_munmap(struct mm_struct *, unsigned long, size_t);
30475 ++extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
30476 +
30477 + extern unsigned long do_brk(unsigned long, unsigned long);
30478 +
30479 +@@ -1181,6 +1189,10 @@ extern struct vm_area_struct * find_vma(
30480 + extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
30481 + struct vm_area_struct **pprev);
30482 +
30483 ++extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
30484 ++extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
30485 ++extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
30486 ++
30487 + /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
30488 + NULL if none. Assume start_addr < end_addr. */
30489 + static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
30490 +@@ -1197,7 +1209,6 @@ static inline unsigned long vma_pages(st
30491 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
30492 + }
30493 +
30494 +-pgprot_t vm_get_page_prot(unsigned long vm_flags);
30495 + struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
30496 + int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
30497 + unsigned long pfn, unsigned long size, pgprot_t);
30498 +@@ -1286,5 +1297,11 @@ int vmemmap_populate_basepages(struct pa
30499 + int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
30500 + void vmemmap_populate_print_last(void);
30501 +
30502 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
30503 ++extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
30504 ++#else
30505 ++static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
30506 ++#endif
30507 ++
30508 + #endif /* __KERNEL__ */
30509 + #endif /* _LINUX_MM_H */
30510 +diff -urNp linux-2.6.27.10/include/linux/mm_types.h linux-2.6.27.10/include/linux/mm_types.h
30511 +--- linux-2.6.27.10/include/linux/mm_types.h 2008-11-07 12:55:34.000000000 -0500
30512 ++++ linux-2.6.27.10/include/linux/mm_types.h 2008-11-18 03:38:45.000000000 -0500
30513 +@@ -158,6 +158,8 @@ struct vm_area_struct {
30514 + #ifdef CONFIG_NUMA
30515 + struct mempolicy *vm_policy; /* NUMA policy for the VMA */
30516 + #endif
30517 ++
30518 ++ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
30519 + };
30520 +
30521 + struct core_thread {
30522 +@@ -257,6 +259,24 @@ struct mm_struct {
30523 + #ifdef CONFIG_MMU_NOTIFIER
30524 + struct mmu_notifier_mm *mmu_notifier_mm;
30525 + #endif
30526 ++
30527 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30528 ++ unsigned long pax_flags;
30529 ++#endif
30530 ++
30531 ++#ifdef CONFIG_PAX_DLRESOLVE
30532 ++ unsigned long call_dl_resolve;
30533 ++#endif
30534 ++
30535 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
30536 ++ unsigned long call_syscall;
30537 ++#endif
30538 ++
30539 ++#ifdef CONFIG_PAX_ASLR
30540 ++ unsigned long delta_mmap; /* randomized offset */
30541 ++ unsigned long delta_stack; /* randomized offset */
30542 ++#endif
30543 ++
30544 + };
30545 +
30546 + #endif /* _LINUX_MM_TYPES_H */
30547 +diff -urNp linux-2.6.27.10/include/linux/module.h linux-2.6.27.10/include/linux/module.h
30548 +--- linux-2.6.27.10/include/linux/module.h 2008-11-07 12:55:34.000000000 -0500
30549 ++++ linux-2.6.27.10/include/linux/module.h 2008-11-18 03:38:45.000000000 -0500
30550 +@@ -282,16 +282,16 @@ struct module
30551 + int (*init)(void);
30552 +
30553 + /* If this is non-NULL, vfree after init() returns */
30554 +- void *module_init;
30555 ++ void *module_init_rx, *module_init_rw;
30556 +
30557 + /* Here is the actual code + data, vfree'd on unload. */
30558 +- void *module_core;
30559 ++ void *module_core_rx, *module_core_rw;
30560 +
30561 + /* Here are the sizes of the init and core sections */
30562 +- unsigned int init_size, core_size;
30563 ++ unsigned int init_size_rw, core_size_rw;
30564 +
30565 + /* The size of the executable code in each section. */
30566 +- unsigned int init_text_size, core_text_size;
30567 ++ unsigned int init_size_rx, core_size_rx;
30568 +
30569 + /* The handle returned from unwind_add_table. */
30570 + void *unwind_info;
30571 +diff -urNp linux-2.6.27.10/include/linux/moduleloader.h linux-2.6.27.10/include/linux/moduleloader.h
30572 +--- linux-2.6.27.10/include/linux/moduleloader.h 2008-11-07 12:55:34.000000000 -0500
30573 ++++ linux-2.6.27.10/include/linux/moduleloader.h 2008-11-18 03:38:45.000000000 -0500
30574 +@@ -17,9 +17,21 @@ int module_frob_arch_sections(Elf_Ehdr *
30575 + sections. Returns NULL on failure. */
30576 + void *module_alloc(unsigned long size);
30577 +
30578 ++#ifdef CONFIG_PAX_KERNEXEC
30579 ++void *module_alloc_exec(unsigned long size);
30580 ++#else
30581 ++#define module_alloc_exec(x) module_alloc(x)
30582 ++#endif
30583 ++
30584 + /* Free memory returned from module_alloc. */
30585 + void module_free(struct module *mod, void *module_region);
30586 +
30587 ++#ifdef CONFIG_PAX_KERNEXEC
30588 ++void module_free_exec(struct module *mod, void *module_region);
30589 ++#else
30590 ++#define module_free_exec(x, y) module_free(x, y)
30591 ++#endif
30592 ++
30593 + /* Apply the given relocation to the (simplified) ELF. Return -error
30594 + or 0. */
30595 + int apply_relocate(Elf_Shdr *sechdrs,
30596 +diff -urNp linux-2.6.27.10/include/linux/namei.h linux-2.6.27.10/include/linux/namei.h
30597 +--- linux-2.6.27.10/include/linux/namei.h 2008-11-07 12:55:34.000000000 -0500
30598 ++++ linux-2.6.27.10/include/linux/namei.h 2008-11-18 03:38:45.000000000 -0500
30599 +@@ -21,7 +21,7 @@ struct nameidata {
30600 + unsigned int flags;
30601 + int last_type;
30602 + unsigned depth;
30603 +- char *saved_names[MAX_NESTED_LINKS + 1];
30604 ++ const char *saved_names[MAX_NESTED_LINKS + 1];
30605 +
30606 + /* Intent data */
30607 + union {
30608 +@@ -80,12 +80,12 @@ extern int follow_up(struct vfsmount **,
30609 + extern struct dentry *lock_rename(struct dentry *, struct dentry *);
30610 + extern void unlock_rename(struct dentry *, struct dentry *);
30611 +
30612 +-static inline void nd_set_link(struct nameidata *nd, char *path)
30613 ++static inline void nd_set_link(struct nameidata *nd, const char *path)
30614 + {
30615 + nd->saved_names[nd->depth] = path;
30616 + }
30617 +
30618 +-static inline char *nd_get_link(struct nameidata *nd)
30619 ++static inline const char *nd_get_link(struct nameidata *nd)
30620 + {
30621 + return nd->saved_names[nd->depth];
30622 + }
30623 +diff -urNp linux-2.6.27.10/include/linux/nodemask.h linux-2.6.27.10/include/linux/nodemask.h
30624 +--- linux-2.6.27.10/include/linux/nodemask.h 2008-11-07 12:55:34.000000000 -0500
30625 ++++ linux-2.6.27.10/include/linux/nodemask.h 2008-11-18 03:38:45.000000000 -0500
30626 +@@ -442,11 +442,11 @@ static inline int num_node_state(enum no
30627 +
30628 + #define any_online_node(mask) \
30629 + ({ \
30630 +- int node; \
30631 +- for_each_node_mask(node, (mask)) \
30632 +- if (node_online(node)) \
30633 ++ int __node; \
30634 ++ for_each_node_mask(__node, (mask)) \
30635 ++ if (node_online(__node)) \
30636 + break; \
30637 +- node; \
30638 ++ __node; \
30639 + })
30640 +
30641 + #define num_online_nodes() num_node_state(N_ONLINE)
30642 +diff -urNp linux-2.6.27.10/include/linux/percpu.h linux-2.6.27.10/include/linux/percpu.h
30643 +--- linux-2.6.27.10/include/linux/percpu.h 2008-11-07 12:55:34.000000000 -0500
30644 ++++ linux-2.6.27.10/include/linux/percpu.h 2008-11-18 03:38:45.000000000 -0500
30645 +@@ -43,7 +43,7 @@
30646 + #endif
30647 +
30648 + #define PERCPU_ENOUGH_ROOM \
30649 +- (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
30650 ++ ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE))
30651 + #endif /* PERCPU_ENOUGH_ROOM */
30652 +
30653 + /*
30654 +diff -urNp linux-2.6.27.10/include/linux/poison.h linux-2.6.27.10/include/linux/poison.h
30655 +--- linux-2.6.27.10/include/linux/poison.h 2008-11-07 12:55:34.000000000 -0500
30656 ++++ linux-2.6.27.10/include/linux/poison.h 2008-11-18 03:38:45.000000000 -0500
30657 +@@ -7,8 +7,8 @@
30658 + * under normal circumstances, used to verify that nobody uses
30659 + * non-initialized list entries.
30660 + */
30661 +-#define LIST_POISON1 ((void *) 0x00100100)
30662 +-#define LIST_POISON2 ((void *) 0x00200200)
30663 ++#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL)
30664 ++#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL)
30665 +
30666 + /********** include/linux/timer.h **********/
30667 + /*
30668 +diff -urNp linux-2.6.27.10/include/linux/random.h linux-2.6.27.10/include/linux/random.h
30669 +--- linux-2.6.27.10/include/linux/random.h 2008-11-07 12:55:34.000000000 -0500
30670 ++++ linux-2.6.27.10/include/linux/random.h 2008-11-18 03:38:45.000000000 -0500
30671 +@@ -72,6 +72,11 @@ unsigned long randomize_range(unsigned l
30672 + u32 random32(void);
30673 + void srandom32(u32 seed);
30674 +
30675 ++static inline unsigned long pax_get_random_long(void)
30676 ++{
30677 ++ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
30678 ++}
30679 ++
30680 + #endif /* __KERNEL___ */
30681 +
30682 + #endif /* _LINUX_RANDOM_H */
30683 +diff -urNp linux-2.6.27.10/include/linux/sched.h linux-2.6.27.10/include/linux/sched.h
30684 +--- linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:38.000000000 -0500
30685 ++++ linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:46.000000000 -0500
30686 +@@ -96,6 +96,7 @@ struct exec_domain;
30687 + struct futex_pi_state;
30688 + struct robust_list_head;
30689 + struct bio;
30690 ++struct linux_binprm;
30691 +
30692 + /*
30693 + * List of flags we want to share for kernel threads,
30694 +@@ -545,6 +546,15 @@ struct signal_struct {
30695 + unsigned audit_tty;
30696 + struct tty_audit_buf *tty_audit_buf;
30697 + #endif
30698 ++
30699 ++#ifdef CONFIG_GRKERNSEC
30700 ++ u32 curr_ip;
30701 ++ u32 gr_saddr;
30702 ++ u32 gr_daddr;
30703 ++ u16 gr_sport;
30704 ++ u16 gr_dport;
30705 ++ u8 used_accept:1;
30706 ++#endif
30707 + };
30708 +
30709 + /* Context switch must be unlocked if interrupts are to be enabled */
30710 +@@ -1030,7 +1040,7 @@ struct sched_rt_entity {
30711 +
30712 + struct task_struct {
30713 + volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
30714 +- void *stack;
30715 ++ struct thread_info *stack;
30716 + atomic_t usage;
30717 + unsigned int flags; /* per process flags, defined below */
30718 + unsigned int ptrace;
30719 +@@ -1095,10 +1105,9 @@ struct task_struct {
30720 + pid_t pid;
30721 + pid_t tgid;
30722 +
30723 +-#ifdef CONFIG_CC_STACKPROTECTOR
30724 + /* Canary value for the -fstack-protector gcc feature */
30725 + unsigned long stack_canary;
30726 +-#endif
30727 ++
30728 + /*
30729 + * pointers to (original) parent process, youngest child, younger sibling,
30730 + * older sibling, respectively. (p->father can be replaced with
30731 +@@ -1126,8 +1135,8 @@ struct task_struct {
30732 + struct list_head thread_group;
30733 +
30734 + struct completion *vfork_done; /* for vfork() */
30735 +- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
30736 +- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30737 ++ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
30738 ++ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30739 +
30740 + cputime_t utime, stime, utimescaled, stimescaled;
30741 + cputime_t gtime;
30742 +@@ -1307,8 +1316,64 @@ struct task_struct {
30743 + int latency_record_count;
30744 + struct latency_record latency_record[LT_SAVECOUNT];
30745 + #endif
30746 ++
30747 ++#ifdef CONFIG_GRKERNSEC
30748 ++ /* grsecurity */
30749 ++ struct acl_subject_label *acl;
30750 ++ struct acl_role_label *role;
30751 ++ struct file *exec_file;
30752 ++ u16 acl_role_id;
30753 ++ u8 acl_sp_role;
30754 ++ u8 is_writable;
30755 ++ u8 brute;
30756 ++#endif
30757 ++
30758 + };
30759 +
30760 ++#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
30761 ++#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
30762 ++#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
30763 ++#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
30764 ++/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
30765 ++#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
30766 ++
30767 ++#ifdef CONFIG_PAX_SOFTMODE
30768 ++extern unsigned int pax_softmode;
30769 ++#endif
30770 ++
30771 ++extern int pax_check_flags(unsigned long *);
30772 ++
30773 ++/* if tsk != current then task_lock must be held on it */
30774 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30775 ++static inline unsigned long pax_get_flags(struct task_struct *tsk)
30776 ++{
30777 ++ if (likely(tsk->mm))
30778 ++ return tsk->mm->pax_flags;
30779 ++ else
30780 ++ return 0UL;
30781 ++}
30782 ++
30783 ++/* if tsk != current then task_lock must be held on it */
30784 ++static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
30785 ++{
30786 ++ if (likely(tsk->mm)) {
30787 ++ tsk->mm->pax_flags = flags;
30788 ++ return 0;
30789 ++ }
30790 ++ return -EINVAL;
30791 ++}
30792 ++#endif
30793 ++
30794 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
30795 ++extern void pax_set_initial_flags(struct linux_binprm *bprm);
30796 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
30797 ++extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
30798 ++#endif
30799 ++
30800 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
30801 ++void pax_report_insns(void *pc, void *sp);
30802 ++void pax_report_refcount_overflow(struct pt_regs *regs);
30803 ++
30804 + /*
30805 + * Priority of a process goes from 0..MAX_PRIO-1, valid RT
30806 + * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
30807 +@@ -1849,7 +1914,7 @@ extern void __cleanup_sighand(struct sig
30808 + extern void exit_itimers(struct signal_struct *);
30809 + extern void flush_itimer_signals(void);
30810 +
30811 +-extern NORET_TYPE void do_group_exit(int);
30812 ++extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
30813 +
30814 + extern void daemonize(const char *, ...);
30815 + extern int allow_signal(int);
30816 +@@ -1952,8 +2017,8 @@ static inline void unlock_task_sighand(s
30817 +
30818 + #ifndef __HAVE_THREAD_FUNCTIONS
30819 +
30820 +-#define task_thread_info(task) ((struct thread_info *)(task)->stack)
30821 +-#define task_stack_page(task) ((task)->stack)
30822 ++#define task_thread_info(task) ((task)->stack)
30823 ++#define task_stack_page(task) ((void *)(task)->stack)
30824 +
30825 + static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
30826 + {
30827 +diff -urNp linux-2.6.27.10/include/linux/screen_info.h linux-2.6.27.10/include/linux/screen_info.h
30828 +--- linux-2.6.27.10/include/linux/screen_info.h 2008-11-07 12:55:34.000000000 -0500
30829 ++++ linux-2.6.27.10/include/linux/screen_info.h 2008-11-18 03:38:45.000000000 -0500
30830 +@@ -42,7 +42,8 @@ struct screen_info {
30831 + __u16 pages; /* 0x32 */
30832 + __u16 vesa_attributes; /* 0x34 */
30833 + __u32 capabilities; /* 0x36 */
30834 +- __u8 _reserved[6]; /* 0x3a */
30835 ++ __u16 vesapm_size; /* 0x3a */
30836 ++ __u8 _reserved[4]; /* 0x3c */
30837 + } __attribute__((packed));
30838 +
30839 + #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
30840 +diff -urNp linux-2.6.27.10/include/linux/shm.h linux-2.6.27.10/include/linux/shm.h
30841 +--- linux-2.6.27.10/include/linux/shm.h 2008-11-07 12:55:34.000000000 -0500
30842 ++++ linux-2.6.27.10/include/linux/shm.h 2008-11-18 03:38:45.000000000 -0500
30843 +@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
30844 + pid_t shm_cprid;
30845 + pid_t shm_lprid;
30846 + struct user_struct *mlock_user;
30847 ++#ifdef CONFIG_GRKERNSEC
30848 ++ time_t shm_createtime;
30849 ++ pid_t shm_lapid;
30850 ++#endif
30851 + };
30852 +
30853 + /* shm_mode upper byte flags */
30854 +diff -urNp linux-2.6.27.10/include/linux/slab.h linux-2.6.27.10/include/linux/slab.h
30855 +--- linux-2.6.27.10/include/linux/slab.h 2008-11-07 12:55:34.000000000 -0500
30856 ++++ linux-2.6.27.10/include/linux/slab.h 2008-11-18 03:38:45.000000000 -0500
30857 +@@ -45,10 +45,9 @@
30858 + * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
30859 + * Both make kfree a no-op.
30860 + */
30861 +-#define ZERO_SIZE_PTR ((void *)16)
30862 ++#define ZERO_SIZE_PTR ((void *)-1024L)
30863 +
30864 +-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
30865 +- (unsigned long)ZERO_SIZE_PTR)
30866 ++#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR)
30867 +
30868 + /*
30869 + * struct kmem_cache related prototypes
30870 +diff -urNp linux-2.6.27.10/include/linux/sysctl.h linux-2.6.27.10/include/linux/sysctl.h
30871 +--- linux-2.6.27.10/include/linux/sysctl.h 2008-11-07 12:55:34.000000000 -0500
30872 ++++ linux-2.6.27.10/include/linux/sysctl.h 2008-11-18 03:38:45.000000000 -0500
30873 +@@ -165,7 +165,11 @@ enum
30874 + KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
30875 + };
30876 +
30877 +-
30878 ++#ifdef CONFIG_PAX_SOFTMODE
30879 ++enum {
30880 ++ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
30881 ++};
30882 ++#endif
30883 +
30884 + /* CTL_VM names: */
30885 + enum
30886 +diff -urNp linux-2.6.27.10/include/linux/thread_info.h linux-2.6.27.10/include/linux/thread_info.h
30887 +--- linux-2.6.27.10/include/linux/thread_info.h 2008-11-07 12:55:34.000000000 -0500
30888 ++++ linux-2.6.27.10/include/linux/thread_info.h 2008-11-18 03:38:45.000000000 -0500
30889 +@@ -23,7 +23,7 @@ struct restart_block {
30890 + };
30891 + /* For futex_wait */
30892 + struct {
30893 +- u32 *uaddr;
30894 ++ u32 __user *uaddr;
30895 + u32 val;
30896 + u32 flags;
30897 + u32 bitset;
30898 +diff -urNp linux-2.6.27.10/include/linux/uaccess.h linux-2.6.27.10/include/linux/uaccess.h
30899 +--- linux-2.6.27.10/include/linux/uaccess.h 2008-11-07 12:55:34.000000000 -0500
30900 ++++ linux-2.6.27.10/include/linux/uaccess.h 2008-11-18 03:38:45.000000000 -0500
30901 +@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
30902 + long ret; \
30903 + mm_segment_t old_fs = get_fs(); \
30904 + \
30905 +- set_fs(KERNEL_DS); \
30906 + pagefault_disable(); \
30907 ++ set_fs(KERNEL_DS); \
30908 + ret = __get_user(retval, (__force typeof(retval) __user *)(addr)); \
30909 +- pagefault_enable(); \
30910 + set_fs(old_fs); \
30911 ++ pagefault_enable(); \
30912 + ret; \
30913 + })
30914 +
30915 +diff -urNp linux-2.6.27.10/include/linux/vmalloc.h linux-2.6.27.10/include/linux/vmalloc.h
30916 +--- linux-2.6.27.10/include/linux/vmalloc.h 2008-11-07 12:55:34.000000000 -0500
30917 ++++ linux-2.6.27.10/include/linux/vmalloc.h 2008-11-18 03:38:45.000000000 -0500
30918 +@@ -12,6 +12,11 @@ struct vm_area_struct; /* vma defining
30919 + #define VM_MAP 0x00000004 /* vmap()ed pages */
30920 + #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
30921 + #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
30922 ++
30923 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30924 ++#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
30925 ++#endif
30926 ++
30927 + /* bits [20..32] reserved for arch specific ioremap internals */
30928 +
30929 + /*
30930 +diff -urNp linux-2.6.27.10/include/net/sctp/sctp.h linux-2.6.27.10/include/net/sctp/sctp.h
30931 +--- linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-07 12:55:34.000000000 -0500
30932 ++++ linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-18 03:38:45.000000000 -0500
30933 +@@ -309,8 +309,8 @@ extern int sctp_debug_flag;
30934 +
30935 + #else /* SCTP_DEBUG */
30936 +
30937 +-#define SCTP_DEBUG_PRINTK(whatever...)
30938 +-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
30939 ++#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
30940 ++#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
30941 + #define SCTP_ENABLE_DEBUG
30942 + #define SCTP_DISABLE_DEBUG
30943 + #define SCTP_ASSERT(expr, str, func)
30944 +diff -urNp linux-2.6.27.10/include/sound/core.h linux-2.6.27.10/include/sound/core.h
30945 +--- linux-2.6.27.10/include/sound/core.h 2008-11-07 12:55:34.000000000 -0500
30946 ++++ linux-2.6.27.10/include/sound/core.h 2008-11-18 03:38:45.000000000 -0500
30947 +@@ -406,9 +406,9 @@ void snd_verbose_printd(const char *file
30948 +
30949 + #else /* !CONFIG_SND_DEBUG */
30950 +
30951 +-#define snd_printd(fmt, args...) /* nothing */
30952 ++#define snd_printd(fmt, args...) do {} while (0)
30953 + #define snd_assert(expr, args...) (void)(expr)
30954 +-#define snd_BUG() /* nothing */
30955 ++#define snd_BUG() do {} while (0)
30956 +
30957 + #endif /* CONFIG_SND_DEBUG */
30958 +
30959 +@@ -422,7 +422,7 @@ void snd_verbose_printd(const char *file
30960 + */
30961 + #define snd_printdd(format, args...) snd_printk(format, ##args)
30962 + #else
30963 +-#define snd_printdd(format, args...) /* nothing */
30964 ++#define snd_printdd(format, args...) do {} while (0)
30965 + #endif
30966 +
30967 +
30968 +diff -urNp linux-2.6.27.10/include/video/uvesafb.h linux-2.6.27.10/include/video/uvesafb.h
30969 +--- linux-2.6.27.10/include/video/uvesafb.h 2008-11-07 12:55:34.000000000 -0500
30970 ++++ linux-2.6.27.10/include/video/uvesafb.h 2008-11-18 03:38:45.000000000 -0500
30971 +@@ -175,6 +175,7 @@ struct uvesafb_par {
30972 + u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
30973 + u8 pmi_setpal; /* PMI for palette changes */
30974 + u16 *pmi_base; /* protected mode interface location */
30975 ++ u8 *pmi_code; /* protected mode code location */
30976 + void *pmi_start;
30977 + void *pmi_pal;
30978 + u8 *vbe_state_orig; /*
30979 +diff -urNp linux-2.6.27.10/init/do_mounts.c linux-2.6.27.10/init/do_mounts.c
30980 +--- linux-2.6.27.10/init/do_mounts.c 2008-11-07 12:55:34.000000000 -0500
30981 ++++ linux-2.6.27.10/init/do_mounts.c 2008-11-18 03:38:45.000000000 -0500
30982 +@@ -214,11 +214,11 @@ static void __init get_fs_names(char *pa
30983 +
30984 + static int __init do_mount_root(char *name, char *fs, int flags, void *data)
30985 + {
30986 +- int err = sys_mount(name, "/root", fs, flags, data);
30987 ++ int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data);
30988 + if (err)
30989 + return err;
30990 +
30991 +- sys_chdir("/root");
30992 ++ sys_chdir((char __user *)"/root");
30993 + ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
30994 + printk("VFS: Mounted root (%s filesystem)%s.\n",
30995 + current->fs->pwd.mnt->mnt_sb->s_type->name,
30996 +@@ -304,18 +304,18 @@ void __init change_floppy(char *fmt, ...
30997 + va_start(args, fmt);
30998 + vsprintf(buf, fmt, args);
30999 + va_end(args);
31000 +- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
31001 ++ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
31002 + if (fd >= 0) {
31003 + sys_ioctl(fd, FDEJECT, 0);
31004 + sys_close(fd);
31005 + }
31006 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
31007 +- fd = sys_open("/dev/console", O_RDWR, 0);
31008 ++ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
31009 + if (fd >= 0) {
31010 + sys_ioctl(fd, TCGETS, (long)&termios);
31011 + termios.c_lflag &= ~ICANON;
31012 + sys_ioctl(fd, TCSETSF, (long)&termios);
31013 +- sys_read(fd, &c, 1);
31014 ++ sys_read(fd, (char __user *)&c, 1);
31015 + termios.c_lflag |= ICANON;
31016 + sys_ioctl(fd, TCSETSF, (long)&termios);
31017 + sys_close(fd);
31018 +@@ -402,7 +402,7 @@ void __init prepare_namespace(void)
31019 +
31020 + mount_root();
31021 + out:
31022 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31023 +- sys_chroot(".");
31024 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31025 ++ sys_chroot((char __user *)".");
31026 + }
31027 +
31028 +diff -urNp linux-2.6.27.10/init/do_mounts.h linux-2.6.27.10/init/do_mounts.h
31029 +--- linux-2.6.27.10/init/do_mounts.h 2008-11-07 12:55:34.000000000 -0500
31030 ++++ linux-2.6.27.10/init/do_mounts.h 2008-11-18 03:38:45.000000000 -0500
31031 +@@ -14,15 +14,15 @@ extern int root_mountflags;
31032 +
31033 + static inline int create_dev(char *name, dev_t dev)
31034 + {
31035 +- sys_unlink(name);
31036 +- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
31037 ++ sys_unlink((char __user *)name);
31038 ++ return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
31039 + }
31040 +
31041 + #if BITS_PER_LONG == 32
31042 + static inline u32 bstat(char *name)
31043 + {
31044 + struct stat64 stat;
31045 +- if (sys_stat64(name, &stat) != 0)
31046 ++ if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0)
31047 + return 0;
31048 + if (!S_ISBLK(stat.st_mode))
31049 + return 0;
31050 +diff -urNp linux-2.6.27.10/init/do_mounts_initrd.c linux-2.6.27.10/init/do_mounts_initrd.c
31051 +--- linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-07 12:55:34.000000000 -0500
31052 ++++ linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-18 03:38:45.000000000 -0500
31053 +@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
31054 + sys_close(old_fd);sys_close(root_fd);
31055 + sys_close(0);sys_close(1);sys_close(2);
31056 + sys_setsid();
31057 +- (void) sys_open("/dev/console",O_RDWR,0);
31058 ++ (void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
31059 + (void) sys_dup(0);
31060 + (void) sys_dup(0);
31061 + return kernel_execve(shell, argv, envp_init);
31062 +@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
31063 + create_dev("/dev/root.old", Root_RAM0);
31064 + /* mount initrd on rootfs' /root */
31065 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
31066 +- sys_mkdir("/old", 0700);
31067 +- root_fd = sys_open("/", 0, 0);
31068 +- old_fd = sys_open("/old", 0, 0);
31069 ++ sys_mkdir((const char __user *)"/old", 0700);
31070 ++ root_fd = sys_open((const char __user *)"/", 0, 0);
31071 ++ old_fd = sys_open((const char __user *)"/old", 0, 0);
31072 + /* move initrd over / and chdir/chroot in initrd root */
31073 +- sys_chdir("/root");
31074 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31075 +- sys_chroot(".");
31076 ++ sys_chdir((const char __user *)"/root");
31077 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31078 ++ sys_chroot((const char __user *)".");
31079 +
31080 + /*
31081 + * In case that a resume from disk is carried out by linuxrc or one of
31082 +@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
31083 +
31084 + /* move initrd to rootfs' /old */
31085 + sys_fchdir(old_fd);
31086 +- sys_mount("/", ".", NULL, MS_MOVE, NULL);
31087 ++ sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
31088 + /* switch root and cwd back to / of rootfs */
31089 + sys_fchdir(root_fd);
31090 +- sys_chroot(".");
31091 ++ sys_chroot((const char __user *)".");
31092 + sys_close(old_fd);
31093 + sys_close(root_fd);
31094 +
31095 + if (new_decode_dev(real_root_dev) == Root_RAM0) {
31096 +- sys_chdir("/old");
31097 ++ sys_chdir((const char __user *)"/old");
31098 + return;
31099 + }
31100 +
31101 +@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
31102 + mount_root();
31103 +
31104 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
31105 +- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
31106 ++ error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
31107 + if (!error)
31108 + printk("okay\n");
31109 + else {
31110 +- int fd = sys_open("/dev/root.old", O_RDWR, 0);
31111 ++ int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
31112 + if (error == -ENOENT)
31113 + printk("/initrd does not exist. Ignored.\n");
31114 + else
31115 + printk("failed\n");
31116 + printk(KERN_NOTICE "Unmounting old root\n");
31117 +- sys_umount("/old", MNT_DETACH);
31118 ++ sys_umount((char __user *)"/old", MNT_DETACH);
31119 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
31120 + if (fd < 0) {
31121 + error = fd;
31122 +@@ -119,11 +119,11 @@ int __init initrd_load(void)
31123 + * mounted in the normal path.
31124 + */
31125 + if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
31126 +- sys_unlink("/initrd.image");
31127 ++ sys_unlink((const char __user *)"/initrd.image");
31128 + handle_initrd();
31129 + return 1;
31130 + }
31131 + }
31132 +- sys_unlink("/initrd.image");
31133 ++ sys_unlink((const char __user *)"/initrd.image");
31134 + return 0;
31135 + }
31136 +diff -urNp linux-2.6.27.10/init/do_mounts_md.c linux-2.6.27.10/init/do_mounts_md.c
31137 +--- linux-2.6.27.10/init/do_mounts_md.c 2008-11-07 12:55:34.000000000 -0500
31138 ++++ linux-2.6.27.10/init/do_mounts_md.c 2008-11-18 03:38:45.000000000 -0500
31139 +@@ -166,7 +166,7 @@ static void __init md_setup_drive(void)
31140 + partitioned ? "_d" : "", minor,
31141 + md_setup_args[ent].device_names);
31142 +
31143 +- fd = sys_open(name, 0, 0);
31144 ++ fd = sys_open((char __user *)name, 0, 0);
31145 + if (fd < 0) {
31146 + printk(KERN_ERR "md: open failed - cannot start "
31147 + "array %s\n", name);
31148 +@@ -229,7 +229,7 @@ static void __init md_setup_drive(void)
31149 + * array without it
31150 + */
31151 + sys_close(fd);
31152 +- fd = sys_open(name, 0, 0);
31153 ++ fd = sys_open((char __user *)name, 0, 0);
31154 + sys_ioctl(fd, BLKRRPART, 0);
31155 + }
31156 + sys_close(fd);
31157 +@@ -270,7 +270,7 @@ void __init md_run_setup(void)
31158 + if (raid_noautodetect)
31159 + printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
31160 + else {
31161 +- int fd = sys_open("/dev/md0", 0, 0);
31162 ++ int fd = sys_open((char __user *)"/dev/md0", 0, 0);
31163 + if (fd >= 0) {
31164 + sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
31165 + sys_close(fd);
31166 +diff -urNp linux-2.6.27.10/init/initramfs.c linux-2.6.27.10/init/initramfs.c
31167 +--- linux-2.6.27.10/init/initramfs.c 2008-11-07 12:55:34.000000000 -0500
31168 ++++ linux-2.6.27.10/init/initramfs.c 2008-11-18 03:38:45.000000000 -0500
31169 +@@ -230,7 +230,7 @@ static int __init maybe_link(void)
31170 + if (nlink >= 2) {
31171 + char *old = find_link(major, minor, ino, mode, collected);
31172 + if (old)
31173 +- return (sys_link(old, collected) < 0) ? -1 : 1;
31174 ++ return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1;
31175 + }
31176 + return 0;
31177 + }
31178 +@@ -239,11 +239,11 @@ static void __init clean_path(char *path
31179 + {
31180 + struct stat st;
31181 +
31182 +- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
31183 ++ if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
31184 + if (S_ISDIR(st.st_mode))
31185 +- sys_rmdir(path);
31186 ++ sys_rmdir((char __user *)path);
31187 + else
31188 +- sys_unlink(path);
31189 ++ sys_unlink((char __user *)path);
31190 + }
31191 + }
31192 +
31193 +@@ -266,7 +266,7 @@ static int __init do_name(void)
31194 + int openflags = O_WRONLY|O_CREAT;
31195 + if (ml != 1)
31196 + openflags |= O_TRUNC;
31197 +- wfd = sys_open(collected, openflags, mode);
31198 ++ wfd = sys_open((char __user *)collected, openflags, mode);
31199 +
31200 + if (wfd >= 0) {
31201 + sys_fchown(wfd, uid, gid);
31202 +@@ -275,15 +275,15 @@ static int __init do_name(void)
31203 + }
31204 + }
31205 + } else if (S_ISDIR(mode)) {
31206 +- sys_mkdir(collected, mode);
31207 +- sys_chown(collected, uid, gid);
31208 +- sys_chmod(collected, mode);
31209 ++ sys_mkdir((char __user *)collected, mode);
31210 ++ sys_chown((char __user *)collected, uid, gid);
31211 ++ sys_chmod((char __user *)collected, mode);
31212 + } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
31213 + S_ISFIFO(mode) || S_ISSOCK(mode)) {
31214 + if (maybe_link() == 0) {
31215 +- sys_mknod(collected, mode, rdev);
31216 +- sys_chown(collected, uid, gid);
31217 +- sys_chmod(collected, mode);
31218 ++ sys_mknod((char __user *)collected, mode, rdev);
31219 ++ sys_chown((char __user *)collected, uid, gid);
31220 ++ sys_chmod((char __user *)collected, mode);
31221 + }
31222 + }
31223 + return 0;
31224 +@@ -292,13 +292,13 @@ static int __init do_name(void)
31225 + static int __init do_copy(void)
31226 + {
31227 + if (count >= body_len) {
31228 +- sys_write(wfd, victim, body_len);
31229 ++ sys_write(wfd, (char __user *)victim, body_len);
31230 + sys_close(wfd);
31231 + eat(body_len);
31232 + state = SkipIt;
31233 + return 0;
31234 + } else {
31235 +- sys_write(wfd, victim, count);
31236 ++ sys_write(wfd, (char __user *)victim, count);
31237 + body_len -= count;
31238 + eat(count);
31239 + return 1;
31240 +@@ -309,8 +309,8 @@ static int __init do_symlink(void)
31241 + {
31242 + collected[N_ALIGN(name_len) + body_len] = '\0';
31243 + clean_path(collected, 0);
31244 +- sys_symlink(collected + N_ALIGN(name_len), collected);
31245 +- sys_lchown(collected, uid, gid);
31246 ++ sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected);
31247 ++ sys_lchown((char __user *)collected, uid, gid);
31248 + state = SkipIt;
31249 + next_state = Reset;
31250 + return 0;
31251 +diff -urNp linux-2.6.27.10/init/Kconfig linux-2.6.27.10/init/Kconfig
31252 +--- linux-2.6.27.10/init/Kconfig 2008-11-07 12:55:34.000000000 -0500
31253 ++++ linux-2.6.27.10/init/Kconfig 2008-11-18 03:38:45.000000000 -0500
31254 +@@ -561,6 +561,7 @@ config SYSCTL_SYSCALL
31255 + config KALLSYMS
31256 + bool "Load all symbols for debugging/ksymoops" if EMBEDDED
31257 + default y
31258 ++ depends on !GRKERNSEC_HIDESYM
31259 + help
31260 + Say Y here to let the kernel print out symbolic crash information and
31261 + symbolic stack backtraces. This increases the size of the kernel
31262 +@@ -780,8 +781,8 @@ config MARKERS
31263 + source "arch/Kconfig"
31264 +
31265 + config PROC_PAGE_MONITOR
31266 +- default y
31267 +- depends on PROC_FS && MMU
31268 ++ default n
31269 ++ depends on PROC_FS && MMU && !GRKERNSEC
31270 + bool "Enable /proc page monitoring" if EMBEDDED
31271 + help
31272 + Various /proc files exist to monitor process memory utilization:
31273 +@@ -797,9 +798,9 @@ config HAVE_GENERIC_DMA_COHERENT
31274 +
31275 + config SLABINFO
31276 + bool
31277 +- depends on PROC_FS
31278 ++ depends on PROC_FS && !GRKERNSEC_PROC_ADD
31279 + depends on SLAB || SLUB_DEBUG
31280 +- default y
31281 ++ default n
31282 +
31283 + config RT_MUTEXES
31284 + boolean
31285 +diff -urNp linux-2.6.27.10/init/main.c linux-2.6.27.10/init/main.c
31286 +--- linux-2.6.27.10/init/main.c 2008-11-07 12:55:34.000000000 -0500
31287 ++++ linux-2.6.27.10/init/main.c 2008-11-18 03:38:45.000000000 -0500
31288 +@@ -101,6 +101,7 @@ static inline void mark_rodata_ro(void)
31289 + #ifdef CONFIG_TC
31290 + extern void tc_init(void);
31291 + #endif
31292 ++extern void grsecurity_init(void);
31293 +
31294 + enum system_states system_state;
31295 + EXPORT_SYMBOL(system_state);
31296 +@@ -187,6 +188,40 @@ static int __init set_reset_devices(char
31297 +
31298 + __setup("reset_devices", set_reset_devices);
31299 +
31300 ++#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32)
31301 ++static int __init setup_pax_nouderef(char *str)
31302 ++{
31303 ++ unsigned int cpu;
31304 ++
31305 ++#ifdef CONFIG_PAX_KERNEXEC
31306 ++ unsigned long cr0;
31307 ++
31308 ++ pax_open_kernel(cr0);
31309 ++#endif
31310 ++
31311 ++ for (cpu = 0; cpu < NR_CPUS; cpu++)
31312 ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300;
31313 ++
31314 ++#ifdef CONFIG_PAX_KERNEXEC
31315 ++ pax_close_kernel(cr0);
31316 ++#endif
31317 ++
31318 ++ return 1;
31319 ++}
31320 ++__setup("pax_nouderef", setup_pax_nouderef);
31321 ++#endif
31322 ++
31323 ++#ifdef CONFIG_PAX_SOFTMODE
31324 ++unsigned int pax_softmode;
31325 ++
31326 ++static int __init setup_pax_softmode(char *str)
31327 ++{
31328 ++ get_option(&str, &pax_softmode);
31329 ++ return 1;
31330 ++}
31331 ++__setup("pax_softmode=", setup_pax_softmode);
31332 ++#endif
31333 ++
31334 + static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
31335 + char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
31336 + static const char *panic_later, *panic_param;
31337 +@@ -385,7 +420,7 @@ static void __init setup_nr_cpu_ids(void
31338 + }
31339 +
31340 + #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
31341 +-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
31342 ++unsigned long __per_cpu_offset[NR_CPUS] __read_only;
31343 +
31344 + EXPORT_SYMBOL(__per_cpu_offset);
31345 +
31346 +@@ -704,6 +739,7 @@ int do_one_initcall(initcall_t fn)
31347 + {
31348 + int count = preempt_count();
31349 + ktime_t t0, t1, delta;
31350 ++ const char *msg1 = "", *msg2 = "";
31351 + char msgbuf[64];
31352 + int result;
31353 +
31354 +@@ -729,15 +765,15 @@ int do_one_initcall(initcall_t fn)
31355 + sprintf(msgbuf, "error code %d ", result);
31356 +
31357 + if (preempt_count() != count) {
31358 +- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
31359 ++ msg1 = " preemption imbalance";
31360 + preempt_count() = count;
31361 + }
31362 + if (irqs_disabled()) {
31363 +- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
31364 ++ msg2 = " disabled interrupts";
31365 + local_irq_enable();
31366 + }
31367 +- if (msgbuf[0]) {
31368 +- printk("initcall %pF returned with %s\n", fn, msgbuf);
31369 ++ if (msgbuf[0] || *msg1 || *msg2) {
31370 ++ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
31371 + }
31372 +
31373 + return result;
31374 +@@ -876,6 +912,8 @@ static int __init kernel_init(void * unu
31375 + prepare_namespace();
31376 + }
31377 +
31378 ++ grsecurity_init();
31379 ++
31380 + /*
31381 + * Ok, we have completed the initial bootup, and
31382 + * we're essentially up and running. Get rid of the
31383 +diff -urNp linux-2.6.27.10/init/noinitramfs.c linux-2.6.27.10/init/noinitramfs.c
31384 +--- linux-2.6.27.10/init/noinitramfs.c 2008-11-07 12:55:34.000000000 -0500
31385 ++++ linux-2.6.27.10/init/noinitramfs.c 2008-11-18 03:38:45.000000000 -0500
31386 +@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
31387 + {
31388 + int err;
31389 +
31390 +- err = sys_mkdir("/dev", 0755);
31391 ++ err = sys_mkdir((const char __user *)"/dev", 0755);
31392 + if (err < 0)
31393 + goto out;
31394 +
31395 +@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
31396 + if (err < 0)
31397 + goto out;
31398 +
31399 +- err = sys_mkdir("/root", 0700);
31400 ++ err = sys_mkdir((const char __user *)"/root", 0700);
31401 + if (err < 0)
31402 + goto out;
31403 +
31404 +diff -urNp linux-2.6.27.10/ipc/ipc_sysctl.c linux-2.6.27.10/ipc/ipc_sysctl.c
31405 +--- linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-07 12:55:34.000000000 -0500
31406 ++++ linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-18 03:38:45.000000000 -0500
31407 +@@ -268,7 +268,7 @@ static struct ctl_table ipc_kern_table[]
31408 + .extra1 = &zero,
31409 + .extra2 = &one,
31410 + },
31411 +- {}
31412 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31413 + };
31414 +
31415 + static struct ctl_table ipc_root_table[] = {
31416 +@@ -278,7 +278,7 @@ static struct ctl_table ipc_root_table[]
31417 + .mode = 0555,
31418 + .child = ipc_kern_table,
31419 + },
31420 +- {}
31421 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31422 + };
31423 +
31424 + static int __init ipc_sysctl_init(void)
31425 +diff -urNp linux-2.6.27.10/ipc/msg.c linux-2.6.27.10/ipc/msg.c
31426 +--- linux-2.6.27.10/ipc/msg.c 2008-11-07 12:55:34.000000000 -0500
31427 ++++ linux-2.6.27.10/ipc/msg.c 2008-11-18 03:38:45.000000000 -0500
31428 +@@ -38,6 +38,7 @@
31429 + #include <linux/rwsem.h>
31430 + #include <linux/nsproxy.h>
31431 + #include <linux/ipc_namespace.h>
31432 ++#include <linux/grsecurity.h>
31433 +
31434 + #include <asm/current.h>
31435 + #include <asm/uaccess.h>
31436 +@@ -314,6 +315,7 @@ asmlinkage long sys_msgget(key_t key, in
31437 + struct ipc_namespace *ns;
31438 + struct ipc_ops msg_ops;
31439 + struct ipc_params msg_params;
31440 ++ long err;
31441 +
31442 + ns = current->nsproxy->ipc_ns;
31443 +
31444 +@@ -324,7 +326,11 @@ asmlinkage long sys_msgget(key_t key, in
31445 + msg_params.key = key;
31446 + msg_params.flg = msgflg;
31447 +
31448 +- return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31449 ++ err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31450 ++
31451 ++ gr_log_msgget(err, msgflg);
31452 ++
31453 ++ return err;
31454 + }
31455 +
31456 + static inline unsigned long
31457 +@@ -434,6 +440,7 @@ static int msgctl_down(struct ipc_namesp
31458 +
31459 + switch (cmd) {
31460 + case IPC_RMID:
31461 ++ gr_log_msgrm(ipcp->uid, ipcp->cuid);
31462 + freeque(ns, ipcp);
31463 + goto out_up;
31464 + case IPC_SET:
31465 +diff -urNp linux-2.6.27.10/ipc/sem.c linux-2.6.27.10/ipc/sem.c
31466 +--- linux-2.6.27.10/ipc/sem.c 2008-11-07 12:55:34.000000000 -0500
31467 ++++ linux-2.6.27.10/ipc/sem.c 2008-11-18 03:38:45.000000000 -0500
31468 +@@ -83,6 +83,7 @@
31469 + #include <linux/rwsem.h>
31470 + #include <linux/nsproxy.h>
31471 + #include <linux/ipc_namespace.h>
31472 ++#include <linux/grsecurity.h>
31473 +
31474 + #include <asm/uaccess.h>
31475 + #include "util.h"
31476 +@@ -313,6 +314,7 @@ asmlinkage long sys_semget(key_t key, in
31477 + struct ipc_namespace *ns;
31478 + struct ipc_ops sem_ops;
31479 + struct ipc_params sem_params;
31480 ++ long err;
31481 +
31482 + ns = current->nsproxy->ipc_ns;
31483 +
31484 +@@ -327,7 +329,11 @@ asmlinkage long sys_semget(key_t key, in
31485 + sem_params.flg = semflg;
31486 + sem_params.u.nsems = nsems;
31487 +
31488 +- return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31489 ++ err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31490 ++
31491 ++ gr_log_semget(err, semflg);
31492 ++
31493 ++ return err;
31494 + }
31495 +
31496 + /*
31497 +@@ -870,6 +876,7 @@ static int semctl_down(struct ipc_namesp
31498 +
31499 + switch(cmd){
31500 + case IPC_RMID:
31501 ++ gr_log_semrm(ipcp->uid, ipcp->cuid);
31502 + freeary(ns, ipcp);
31503 + goto out_up;
31504 + case IPC_SET:
31505 +diff -urNp linux-2.6.27.10/ipc/shm.c linux-2.6.27.10/ipc/shm.c
31506 +--- linux-2.6.27.10/ipc/shm.c 2008-11-07 12:55:34.000000000 -0500
31507 ++++ linux-2.6.27.10/ipc/shm.c 2008-11-18 03:38:45.000000000 -0500
31508 +@@ -39,6 +39,7 @@
31509 + #include <linux/nsproxy.h>
31510 + #include <linux/mount.h>
31511 + #include <linux/ipc_namespace.h>
31512 ++#include <linux/grsecurity.h>
31513 +
31514 + #include <asm/uaccess.h>
31515 +
31516 +@@ -69,6 +70,14 @@ static void shm_destroy (struct ipc_name
31517 + static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
31518 + #endif
31519 +
31520 ++#ifdef CONFIG_GRKERNSEC
31521 ++extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31522 ++ const time_t shm_createtime, const uid_t cuid,
31523 ++ const int shmid);
31524 ++extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31525 ++ const time_t shm_createtime);
31526 ++#endif
31527 ++
31528 + void shm_init_ns(struct ipc_namespace *ns)
31529 + {
31530 + ns->shm_ctlmax = SHMMAX;
31531 +@@ -87,6 +96,8 @@ static void do_shm_rmid(struct ipc_names
31532 + struct shmid_kernel *shp;
31533 + shp = container_of(ipcp, struct shmid_kernel, shm_perm);
31534 +
31535 ++ gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
31536 ++
31537 + if (shp->shm_nattch){
31538 + shp->shm_perm.mode |= SHM_DEST;
31539 + /* Do not find it any more */
31540 +@@ -392,6 +403,14 @@ static int newseg(struct ipc_namespace *
31541 + shp->shm_lprid = 0;
31542 + shp->shm_atim = shp->shm_dtim = 0;
31543 + shp->shm_ctim = get_seconds();
31544 ++#ifdef CONFIG_GRKERNSEC
31545 ++ {
31546 ++ struct timespec timeval;
31547 ++ do_posix_clock_monotonic_gettime(&timeval);
31548 ++
31549 ++ shp->shm_createtime = timeval.tv_sec;
31550 ++ }
31551 ++#endif
31552 + shp->shm_segsz = size;
31553 + shp->shm_nattch = 0;
31554 + shp->shm_file = file;
31555 +@@ -445,6 +464,7 @@ asmlinkage long sys_shmget (key_t key, s
31556 + struct ipc_namespace *ns;
31557 + struct ipc_ops shm_ops;
31558 + struct ipc_params shm_params;
31559 ++ long err;
31560 +
31561 + ns = current->nsproxy->ipc_ns;
31562 +
31563 +@@ -456,7 +476,11 @@ asmlinkage long sys_shmget (key_t key, s
31564 + shm_params.flg = shmflg;
31565 + shm_params.u.size = size;
31566 +
31567 +- return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31568 ++ err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31569 ++
31570 ++ gr_log_shmget(err, shmflg, size);
31571 ++
31572 ++ return err;
31573 + }
31574 +
31575 + static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
31576 +@@ -869,9 +893,21 @@ long do_shmat(int shmid, char __user *sh
31577 + if (err)
31578 + goto out_unlock;
31579 +
31580 ++#ifdef CONFIG_GRKERNSEC
31581 ++ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
31582 ++ shp->shm_perm.cuid, shmid) ||
31583 ++ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
31584 ++ err = -EACCES;
31585 ++ goto out_unlock;
31586 ++ }
31587 ++#endif
31588 ++
31589 + path.dentry = dget(shp->shm_file->f_path.dentry);
31590 + path.mnt = shp->shm_file->f_path.mnt;
31591 + shp->shm_nattch++;
31592 ++#ifdef CONFIG_GRKERNSEC
31593 ++ shp->shm_lapid = current->pid;
31594 ++#endif
31595 + size = i_size_read(path.dentry->d_inode);
31596 + shm_unlock(shp);
31597 +
31598 +diff -urNp linux-2.6.27.10/kernel/acct.c linux-2.6.27.10/kernel/acct.c
31599 +--- linux-2.6.27.10/kernel/acct.c 2008-11-07 12:55:34.000000000 -0500
31600 ++++ linux-2.6.27.10/kernel/acct.c 2008-11-18 03:38:45.000000000 -0500
31601 +@@ -573,7 +573,7 @@ static void do_acct_process(struct bsd_a
31602 + */
31603 + flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
31604 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
31605 +- file->f_op->write(file, (char *)&ac,
31606 ++ file->f_op->write(file, (char __user *)&ac,
31607 + sizeof(acct_t), &file->f_pos);
31608 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
31609 + set_fs(fs);
31610 +diff -urNp linux-2.6.27.10/kernel/capability.c linux-2.6.27.10/kernel/capability.c
31611 +--- linux-2.6.27.10/kernel/capability.c 2008-11-07 12:55:34.000000000 -0500
31612 ++++ linux-2.6.27.10/kernel/capability.c 2008-11-18 03:38:45.000000000 -0500
31613 +@@ -13,6 +13,7 @@
31614 + #include <linux/security.h>
31615 + #include <linux/syscalls.h>
31616 + #include <linux/pid_namespace.h>
31617 ++#include <linux/grsecurity.h>
31618 + #include <asm/uaccess.h>
31619 +
31620 + /*
31621 +@@ -498,10 +499,21 @@ asmlinkage long sys_capset(cap_user_head
31622 + */
31623 + int capable(int cap)
31624 + {
31625 +- if (has_capability(current, cap)) {
31626 ++ if (has_capability(current, cap) && gr_task_is_capable(current, cap)) {
31627 + current->flags |= PF_SUPERPRIV;
31628 + return 1;
31629 + }
31630 + return 0;
31631 + }
31632 ++
31633 ++int capable_nolog(int cap)
31634 ++{
31635 ++ if (has_capability(current, cap) && gr_is_capable_nolog(cap)) {
31636 ++ current->flags |= PF_SUPERPRIV;
31637 ++ return 1;
31638 ++ }
31639 ++ return 0;
31640 ++}
31641 ++
31642 + EXPORT_SYMBOL(capable);
31643 ++EXPORT_SYMBOL(capable_nolog);
31644 +diff -urNp linux-2.6.27.10/kernel/configs.c linux-2.6.27.10/kernel/configs.c
31645 +--- linux-2.6.27.10/kernel/configs.c 2008-11-07 12:55:34.000000000 -0500
31646 ++++ linux-2.6.27.10/kernel/configs.c 2008-11-18 03:38:45.000000000 -0500
31647 +@@ -79,8 +79,19 @@ static int __init ikconfig_init(void)
31648 + struct proc_dir_entry *entry;
31649 +
31650 + /* create the current config file */
31651 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
31652 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
31653 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
31654 ++ &ikconfig_file_ops);
31655 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
31656 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
31657 ++ &ikconfig_file_ops);
31658 ++#endif
31659 ++#else
31660 + entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
31661 + &ikconfig_file_ops);
31662 ++#endif
31663 ++
31664 + if (!entry)
31665 + return -ENOMEM;
31666 +
31667 +diff -urNp linux-2.6.27.10/kernel/cpu.c linux-2.6.27.10/kernel/cpu.c
31668 +--- linux-2.6.27.10/kernel/cpu.c 2008-11-07 12:55:34.000000000 -0500
31669 ++++ linux-2.6.27.10/kernel/cpu.c 2008-11-18 03:38:45.000000000 -0500
31670 +@@ -40,7 +40,7 @@ EXPORT_SYMBOL(cpu_possible_map);
31671 + /* Serializes the updates to cpu_online_map, cpu_present_map */
31672 + static DEFINE_MUTEX(cpu_add_remove_lock);
31673 +
31674 +-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
31675 ++static RAW_NOTIFIER_HEAD(cpu_chain);
31676 +
31677 + /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
31678 + * Should always be manipulated under cpu_add_remove_lock
31679 +diff -urNp linux-2.6.27.10/kernel/exit.c linux-2.6.27.10/kernel/exit.c
31680 +--- linux-2.6.27.10/kernel/exit.c 2008-11-07 12:55:34.000000000 -0500
31681 ++++ linux-2.6.27.10/kernel/exit.c 2008-11-29 19:01:27.000000000 -0500
31682 +@@ -40,13 +40,17 @@
31683 + #include <linux/cn_proc.h>
31684 + #include <linux/mutex.h>
31685 + #include <linux/futex.h>
31686 +-#include <linux/compat.h>
31687 + #include <linux/pipe_fs_i.h>
31688 + #include <linux/audit.h> /* for audit_free() */
31689 + #include <linux/resource.h>
31690 + #include <linux/blkdev.h>
31691 + #include <linux/task_io_accounting_ops.h>
31692 + #include <linux/tracehook.h>
31693 ++#include <linux/grsecurity.h>
31694 ++
31695 ++#ifdef CONFIG_GRKERNSEC
31696 ++extern rwlock_t grsec_exec_file_lock;
31697 ++#endif
31698 +
31699 + #include <asm/uaccess.h>
31700 + #include <asm/unistd.h>
31701 +@@ -133,7 +137,6 @@ static void __exit_signal(struct task_st
31702 + * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
31703 + */
31704 + flush_sigqueue(&tsk->pending);
31705 +-
31706 + tsk->signal = NULL;
31707 + tsk->sighand = NULL;
31708 + spin_unlock(&sighand->siglock);
31709 +@@ -158,6 +161,8 @@ void release_task(struct task_struct * p
31710 + struct task_struct *leader;
31711 + int zap_leader;
31712 + repeat:
31713 ++ gr_del_task_from_ip_table(p);
31714 ++
31715 + tracehook_prepare_release_task(p);
31716 + atomic_dec(&p->user->processes);
31717 + proc_flush_task(p);
31718 +@@ -321,11 +326,22 @@ static void reparent_to_kthreadd(void)
31719 + {
31720 + write_lock_irq(&tasklist_lock);
31721 +
31722 ++#ifdef CONFIG_GRKERNSEC
31723 ++ write_lock(&grsec_exec_file_lock);
31724 ++ if (current->exec_file) {
31725 ++ fput(current->exec_file);
31726 ++ current->exec_file = NULL;
31727 ++ }
31728 ++ write_unlock(&grsec_exec_file_lock);
31729 ++#endif
31730 ++
31731 + ptrace_unlink(current);
31732 + /* Reparent to init */
31733 + current->real_parent = current->parent = kthreadd_task;
31734 + list_move_tail(&current->sibling, &current->real_parent->children);
31735 +
31736 ++ gr_set_kernel_label(current);
31737 ++
31738 + /* Set the exit signal to SIGCHLD so we signal init on exit */
31739 + current->exit_signal = SIGCHLD;
31740 +
31741 +@@ -419,6 +435,17 @@ void daemonize(const char *name, ...)
31742 + vsnprintf(current->comm, sizeof(current->comm), name, args);
31743 + va_end(args);
31744 +
31745 ++#ifdef CONFIG_GRKERNSEC
31746 ++ write_lock(&grsec_exec_file_lock);
31747 ++ if (current->exec_file) {
31748 ++ fput(current->exec_file);
31749 ++ current->exec_file = NULL;
31750 ++ }
31751 ++ write_unlock(&grsec_exec_file_lock);
31752 ++#endif
31753 ++
31754 ++ gr_set_kernel_label(current);
31755 ++
31756 + /*
31757 + * If we were started as result of loading a module, close all of the
31758 + * user space pages. We don't need them, and if we didn't close them
31759 +@@ -1054,14 +1081,6 @@ NORET_TYPE void do_exit(long code)
31760 + exit_itimers(tsk->signal);
31761 + }
31762 + acct_collect(code, group_dead);
31763 +-#ifdef CONFIG_FUTEX
31764 +- if (unlikely(tsk->robust_list))
31765 +- exit_robust_list(tsk);
31766 +-#ifdef CONFIG_COMPAT
31767 +- if (unlikely(tsk->compat_robust_list))
31768 +- compat_exit_robust_list(tsk);
31769 +-#endif
31770 +-#endif
31771 + if (group_dead)
31772 + tty_audit_exit();
31773 + if (unlikely(tsk->audit_context))
31774 +@@ -1070,6 +1089,9 @@ NORET_TYPE void do_exit(long code)
31775 + tsk->exit_code = code;
31776 + taskstats_exit(tsk, group_dead);
31777 +
31778 ++ gr_acl_handle_psacct(tsk, code);
31779 ++ gr_acl_handle_exit();
31780 ++
31781 + exit_mm(tsk);
31782 +
31783 + if (group_dead)
31784 +@@ -1272,7 +1294,7 @@ static int wait_task_zombie(struct task_
31785 + if (unlikely(options & WNOWAIT)) {
31786 + uid_t uid = p->uid;
31787 + int exit_code = p->exit_code;
31788 +- int why, status;
31789 ++ int why;
31790 +
31791 + get_task_struct(p);
31792 + read_unlock(&tasklist_lock);
31793 +diff -urNp linux-2.6.27.10/kernel/fork.c linux-2.6.27.10/kernel/fork.c
31794 +--- linux-2.6.27.10/kernel/fork.c 2008-12-21 01:16:52.000000000 -0500
31795 ++++ linux-2.6.27.10/kernel/fork.c 2008-12-21 01:13:46.000000000 -0500
31796 +@@ -40,6 +40,7 @@
31797 + #include <linux/jiffies.h>
31798 + #include <linux/tracehook.h>
31799 + #include <linux/futex.h>
31800 ++#include <linux/compat.h>
31801 + #include <linux/task_io_accounting_ops.h>
31802 + #include <linux/rcupdate.h>
31803 + #include <linux/ptrace.h>
31804 +@@ -58,6 +59,7 @@
31805 + #include <linux/tty.h>
31806 + #include <linux/proc_fs.h>
31807 + #include <linux/blkdev.h>
31808 ++#include <linux/grsecurity.h>
31809 +
31810 + #include <asm/pgtable.h>
31811 + #include <asm/pgalloc.h>
31812 +@@ -234,7 +236,7 @@ static struct task_struct *dup_task_stru
31813 + setup_thread_stack(tsk, orig);
31814 +
31815 + #ifdef CONFIG_CC_STACKPROTECTOR
31816 +- tsk->stack_canary = get_random_int();
31817 ++ tsk->stack_canary = pax_get_random_long();
31818 + #endif
31819 +
31820 + /* One for us, one for whoever does the "release_task()" (usually parent) */
31821 +@@ -271,8 +273,8 @@ static int dup_mmap(struct mm_struct *mm
31822 + mm->locked_vm = 0;
31823 + mm->mmap = NULL;
31824 + mm->mmap_cache = NULL;
31825 +- mm->free_area_cache = oldmm->mmap_base;
31826 +- mm->cached_hole_size = ~0UL;
31827 ++ mm->free_area_cache = oldmm->free_area_cache;
31828 ++ mm->cached_hole_size = oldmm->cached_hole_size;
31829 + mm->map_count = 0;
31830 + cpus_clear(mm->cpu_vm_mask);
31831 + mm->mm_rb = RB_ROOT;
31832 +@@ -309,6 +311,7 @@ static int dup_mmap(struct mm_struct *mm
31833 + tmp->vm_flags &= ~VM_LOCKED;
31834 + tmp->vm_mm = mm;
31835 + tmp->vm_next = NULL;
31836 ++ tmp->vm_mirror = NULL;
31837 + anon_vma_link(tmp);
31838 + file = tmp->vm_file;
31839 + if (file) {
31840 +@@ -356,6 +359,31 @@ static int dup_mmap(struct mm_struct *mm
31841 + if (retval)
31842 + goto out;
31843 + }
31844 ++
31845 ++#ifdef CONFIG_PAX_SEGMEXEC
31846 ++ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
31847 ++ struct vm_area_struct *mpnt_m;
31848 ++
31849 ++ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
31850 ++ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
31851 ++
31852 ++ if (!mpnt->vm_mirror)
31853 ++ continue;
31854 ++
31855 ++ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
31856 ++ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
31857 ++ mpnt->vm_mirror = mpnt_m;
31858 ++ } else {
31859 ++ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
31860 ++ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
31861 ++ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
31862 ++ mpnt->vm_mirror->vm_mirror = mpnt;
31863 ++ }
31864 ++ }
31865 ++ BUG_ON(mpnt_m);
31866 ++ }
31867 ++#endif
31868 ++
31869 + /* a new mm has just been created */
31870 + arch_dup_mmap(oldmm, mm);
31871 + retval = 0;
31872 +@@ -521,6 +549,18 @@ void mm_release(struct task_struct *tsk,
31873 + {
31874 + struct completion *vfork_done = tsk->vfork_done;
31875 +
31876 ++ /* Get rid of any futexes when releasing the mm */
31877 ++#ifdef CONFIG_FUTEX
31878 ++ if (unlikely(tsk->robust_list))
31879 ++ exit_robust_list(tsk);
31880 ++ tsk->robust_list = NULL;
31881 ++#ifdef CONFIG_COMPAT
31882 ++ if (unlikely(tsk->compat_robust_list))
31883 ++ compat_exit_robust_list(tsk);
31884 ++ tsk->compat_robust_list = NULL;
31885 ++#endif
31886 ++#endif
31887 ++
31888 + /* Get rid of any cached register state */
31889 + deactivate_mm(tsk, mm);
31890 +
31891 +@@ -539,7 +579,7 @@ void mm_release(struct task_struct *tsk,
31892 + if (tsk->clear_child_tid
31893 + && !(tsk->flags & PF_SIGNALED)
31894 + && atomic_read(&mm->mm_users) > 1) {
31895 +- u32 __user * tidptr = tsk->clear_child_tid;
31896 ++ pid_t __user * tidptr = tsk->clear_child_tid;
31897 + tsk->clear_child_tid = NULL;
31898 +
31899 + /*
31900 +@@ -547,7 +587,7 @@ void mm_release(struct task_struct *tsk,
31901 + * not set up a proper pointer then tough luck.
31902 + */
31903 + put_user(0, tidptr);
31904 +- sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31905 ++ sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31906 + }
31907 + }
31908 +
31909 +@@ -942,6 +982,9 @@ static struct task_struct *copy_process(
31910 + DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
31911 + #endif
31912 + retval = -EAGAIN;
31913 ++
31914 ++ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes), 0);
31915 ++
31916 + if (atomic_read(&p->user->processes) >=
31917 + p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
31918 + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
31919 +@@ -1108,6 +1151,8 @@ static struct task_struct *copy_process(
31920 + goto bad_fork_free_pid;
31921 + }
31922 +
31923 ++ gr_copy_label(p);
31924 ++
31925 + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
31926 + /*
31927 + * Clear TID on mm_release()?
31928 +@@ -1293,6 +1338,8 @@ bad_fork_cleanup_count:
31929 + bad_fork_free:
31930 + free_task(p);
31931 + fork_out:
31932 ++ gr_log_forkfail(retval);
31933 ++
31934 + return ERR_PTR(retval);
31935 + }
31936 +
31937 +@@ -1369,6 +1416,8 @@ long do_fork(unsigned long clone_flags,
31938 + if (clone_flags & CLONE_PARENT_SETTID)
31939 + put_user(nr, parent_tidptr);
31940 +
31941 ++ gr_handle_brute_check();
31942 ++
31943 + if (clone_flags & CLONE_VFORK) {
31944 + p->vfork_done = &vfork;
31945 + init_completion(&vfork);
31946 +diff -urNp linux-2.6.27.10/kernel/futex.c linux-2.6.27.10/kernel/futex.c
31947 +--- linux-2.6.27.10/kernel/futex.c 2008-11-07 12:55:34.000000000 -0500
31948 ++++ linux-2.6.27.10/kernel/futex.c 2008-11-18 03:38:45.000000000 -0500
31949 +@@ -188,6 +188,11 @@ static int get_futex_key(u32 __user *uad
31950 + struct page *page;
31951 + int err;
31952 +
31953 ++#ifdef CONFIG_PAX_SEGMEXEC
31954 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
31955 ++ return -EFAULT;
31956 ++#endif
31957 ++
31958 + /*
31959 + * The futex address must be "naturally" aligned.
31960 + */
31961 +@@ -214,8 +219,8 @@ static int get_futex_key(u32 __user *uad
31962 + * The futex is hashed differently depending on whether
31963 + * it's in a shared or private mapping. So check vma first.
31964 + */
31965 +- vma = find_extend_vma(mm, address);
31966 +- if (unlikely(!vma))
31967 ++ vma = find_vma(mm, address);
31968 ++ if (unlikely(!vma || address < vma->vm_start))
31969 + return -EFAULT;
31970 +
31971 + /*
31972 +@@ -1345,7 +1350,7 @@ static int futex_wait(u32 __user *uaddr,
31973 + struct restart_block *restart;
31974 + restart = &current_thread_info()->restart_block;
31975 + restart->fn = futex_wait_restart;
31976 +- restart->futex.uaddr = (u32 *)uaddr;
31977 ++ restart->futex.uaddr = uaddr;
31978 + restart->futex.val = val;
31979 + restart->futex.time = abs_time->tv64;
31980 + restart->futex.bitset = bitset;
31981 +@@ -1906,7 +1911,7 @@ retry:
31982 + */
31983 + static inline int fetch_robust_entry(struct robust_list __user **entry,
31984 + struct robust_list __user * __user *head,
31985 +- int *pi)
31986 ++ unsigned int *pi)
31987 + {
31988 + unsigned long uentry;
31989 +
31990 +diff -urNp linux-2.6.27.10/kernel/irq/handle.c linux-2.6.27.10/kernel/irq/handle.c
31991 +--- linux-2.6.27.10/kernel/irq/handle.c 2008-11-07 12:55:34.000000000 -0500
31992 ++++ linux-2.6.27.10/kernel/irq/handle.c 2008-11-18 03:38:45.000000000 -0500
31993 +@@ -55,7 +55,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach
31994 + .depth = 1,
31995 + .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
31996 + #ifdef CONFIG_SMP
31997 +- .affinity = CPU_MASK_ALL
31998 ++ .affinity = CPU_MASK_ALL,
31999 ++ .cpu = 0,
32000 + #endif
32001 + }
32002 + };
32003 +diff -urNp linux-2.6.27.10/kernel/kallsyms.c linux-2.6.27.10/kernel/kallsyms.c
32004 +--- linux-2.6.27.10/kernel/kallsyms.c 2008-11-07 12:55:34.000000000 -0500
32005 ++++ linux-2.6.27.10/kernel/kallsyms.c 2008-11-18 03:38:45.000000000 -0500
32006 +@@ -62,6 +62,19 @@ static inline int is_kernel_text(unsigne
32007 +
32008 + static inline int is_kernel(unsigned long addr)
32009 + {
32010 ++
32011 ++#ifdef CONFIG_PAX_KERNEXEC
32012 ++
32013 ++#ifdef CONFIG_MODULES
32014 ++ if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) &&
32015 ++ ktla_ktva(addr) < (unsigned long)MODULES_END)
32016 ++ return 0;
32017 ++#endif
32018 ++
32019 ++ if (is_kernel_inittext(addr))
32020 ++ return 1;
32021 ++#endif
32022 ++
32023 + if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
32024 + return 1;
32025 + return in_gate_area_no_task(addr);
32026 +@@ -366,7 +379,6 @@ static unsigned long get_ksymbol_core(st
32027 +
32028 + static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
32029 + {
32030 +- iter->name[0] = '\0';
32031 + iter->nameoff = get_symbol_offset(new_pos);
32032 + iter->pos = new_pos;
32033 + }
32034 +@@ -450,7 +462,7 @@ static int kallsyms_open(struct inode *i
32035 + struct kallsym_iter *iter;
32036 + int ret;
32037 +
32038 +- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
32039 ++ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
32040 + if (!iter)
32041 + return -ENOMEM;
32042 + reset_iter(iter, 0);
32043 +@@ -472,7 +484,15 @@ static const struct file_operations kall
32044 +
32045 + static int __init kallsyms_init(void)
32046 + {
32047 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
32048 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32049 ++ proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations);
32050 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32051 ++ proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations);
32052 ++#endif
32053 ++#else
32054 + proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
32055 ++#endif
32056 + return 0;
32057 + }
32058 + __initcall(kallsyms_init);
32059 +diff -urNp linux-2.6.27.10/kernel/kmod.c linux-2.6.27.10/kernel/kmod.c
32060 +--- linux-2.6.27.10/kernel/kmod.c 2008-11-07 12:55:34.000000000 -0500
32061 ++++ linux-2.6.27.10/kernel/kmod.c 2008-11-18 03:38:45.000000000 -0500
32062 +@@ -108,7 +108,7 @@ int request_module(const char *fmt, ...)
32063 + return -ENOMEM;
32064 + }
32065 +
32066 +- ret = call_usermodehelper(modprobe_path, argv, envp, 1);
32067 ++ ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC);
32068 + atomic_dec(&kmod_concurrent);
32069 + return ret;
32070 + }
32071 +diff -urNp linux-2.6.27.10/kernel/kprobes.c linux-2.6.27.10/kernel/kprobes.c
32072 +--- linux-2.6.27.10/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
32073 ++++ linux-2.6.27.10/kernel/kprobes.c 2008-11-18 03:38:45.000000000 -0500
32074 +@@ -182,7 +182,7 @@ kprobe_opcode_t __kprobes *get_insn_slot
32075 + * kernel image and loaded module images reside. This is required
32076 + * so x86_64 can correctly handle the %rip-relative fixups.
32077 + */
32078 +- kip->insns = module_alloc(PAGE_SIZE);
32079 ++ kip->insns = module_alloc_exec(PAGE_SIZE);
32080 + if (!kip->insns) {
32081 + kfree(kip);
32082 + return NULL;
32083 +@@ -214,7 +214,7 @@ static int __kprobes collect_one_slot(st
32084 + hlist_add_head(&kip->hlist,
32085 + &kprobe_insn_pages);
32086 + } else {
32087 +- module_free(NULL, kip->insns);
32088 ++ module_free_exec(NULL, kip->insns);
32089 + kfree(kip);
32090 + }
32091 + return 1;
32092 +diff -urNp linux-2.6.27.10/kernel/lockdep.c linux-2.6.27.10/kernel/lockdep.c
32093 +--- linux-2.6.27.10/kernel/lockdep.c 2008-11-07 12:55:34.000000000 -0500
32094 ++++ linux-2.6.27.10/kernel/lockdep.c 2008-11-18 03:38:45.000000000 -0500
32095 +@@ -627,6 +627,10 @@ static int static_obj(void *obj)
32096 + int i;
32097 + #endif
32098 +
32099 ++#ifdef CONFIG_PAX_KERNEXEC
32100 ++ start = (unsigned long )&_data;
32101 ++#endif
32102 ++
32103 + /*
32104 + * static variable?
32105 + */
32106 +@@ -638,9 +642,12 @@ static int static_obj(void *obj)
32107 + * percpu var?
32108 + */
32109 + for_each_possible_cpu(i) {
32110 ++#ifdef CONFIG_X86_32
32111 ++ start = per_cpu_offset(i);
32112 ++#else
32113 + start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
32114 +- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
32115 +- + per_cpu_offset(i);
32116 ++#endif
32117 ++ end = start + PERCPU_ENOUGH_ROOM;
32118 +
32119 + if ((addr >= start) && (addr < end))
32120 + return 1;
32121 +diff -urNp linux-2.6.27.10/kernel/module.c linux-2.6.27.10/kernel/module.c
32122 +--- linux-2.6.27.10/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
32123 ++++ linux-2.6.27.10/kernel/module.c 2008-12-21 01:17:47.000000000 -0500
32124 +@@ -44,6 +44,11 @@
32125 + #include <linux/unwind.h>
32126 + #include <asm/uaccess.h>
32127 + #include <asm/cacheflush.h>
32128 ++
32129 ++#ifdef CONFIG_PAX_KERNEXEC
32130 ++#include <asm/desc.h>
32131 ++#endif
32132 ++
32133 + #include <linux/license.h>
32134 + #include <asm/sections.h>
32135 +
32136 +@@ -71,7 +76,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
32137 + static BLOCKING_NOTIFIER_HEAD(module_notify_list);
32138 +
32139 + /* Bounds of module allocation, for speeding __module_text_address */
32140 +-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
32141 ++static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
32142 ++static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
32143 ++
32144 ++extern int gr_check_modstop(void);
32145 +
32146 + int register_module_notifier(struct notifier_block * nb)
32147 + {
32148 +@@ -217,7 +225,7 @@ static bool each_symbol(bool (*fn)(const
32149 + return true;
32150 +
32151 + list_for_each_entry(mod, &modules, list) {
32152 +- struct symsearch arr[] = {
32153 ++ struct symsearch modarr[] = {
32154 + { mod->syms, mod->syms + mod->num_syms, mod->crcs,
32155 + NOT_GPL_ONLY, false },
32156 + { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
32157 +@@ -239,7 +247,7 @@ static bool each_symbol(bool (*fn)(const
32158 + #endif
32159 + };
32160 +
32161 +- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
32162 ++ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
32163 + return true;
32164 + }
32165 + return false;
32166 +@@ -375,6 +383,8 @@ static inline unsigned int block_size(in
32167 + return val;
32168 + }
32169 +
32170 ++EXPORT_SYMBOL(__per_cpu_start);
32171 ++
32172 + static void *percpu_modalloc(unsigned long size, unsigned long align,
32173 + const char *name)
32174 + {
32175 +@@ -382,7 +392,7 @@ static void *percpu_modalloc(unsigned lo
32176 + unsigned int i;
32177 + void *ptr;
32178 +
32179 +- if (align > PAGE_SIZE) {
32180 ++ if (align-1 >= PAGE_SIZE) {
32181 + printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
32182 + name, align, PAGE_SIZE);
32183 + align = PAGE_SIZE;
32184 +@@ -464,7 +474,11 @@ static void percpu_modcopy(void *pcpudes
32185 + int cpu;
32186 +
32187 + for_each_possible_cpu(cpu)
32188 ++#ifdef CONFIG_X86_32
32189 ++ memcpy(pcpudest + __per_cpu_offset[cpu], from, size);
32190 ++#else
32191 + memcpy(pcpudest + per_cpu_offset(cpu), from, size);
32192 ++#endif
32193 + }
32194 +
32195 + static int percpu_modinit(void)
32196 +@@ -722,6 +736,9 @@ sys_delete_module(const char __user *nam
32197 + char name[MODULE_NAME_LEN];
32198 + int ret, forced = 0;
32199 +
32200 ++ if (gr_check_modstop())
32201 ++ return -EPERM;
32202 ++
32203 + if (!capable(CAP_SYS_MODULE))
32204 + return -EPERM;
32205 +
32206 +@@ -1430,16 +1447,19 @@ static void free_module(struct module *m
32207 + module_unload_free(mod);
32208 +
32209 + /* This may be NULL, but that's OK */
32210 +- module_free(mod, mod->module_init);
32211 ++ module_free(mod, mod->module_init_rw);
32212 ++ module_free_exec(mod, mod->module_init_rx);
32213 + kfree(mod->args);
32214 + if (mod->percpu)
32215 + percpu_modfree(mod->percpu);
32216 +
32217 + /* Free lock-classes: */
32218 +- lockdep_free_key_range(mod->module_core, mod->core_size);
32219 ++ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
32220 ++ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
32221 +
32222 + /* Finally, free the core (containing the module structure) */
32223 +- module_free(mod, mod->module_core);
32224 ++ module_free_exec(mod, mod->module_core_rx);
32225 ++ module_free(mod, mod->module_core_rw);
32226 + }
32227 +
32228 + void *__symbol_get(const char *symbol)
32229 +@@ -1505,10 +1525,14 @@ static int simplify_symbols(Elf_Shdr *se
32230 + struct module *mod)
32231 + {
32232 + Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
32233 +- unsigned long secbase;
32234 ++ unsigned long secbase, symbol;
32235 + unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32236 + int ret = 0;
32237 +
32238 ++#ifdef CONFIG_PAX_KERNEXEC
32239 ++ unsigned long cr0;
32240 ++#endif
32241 ++
32242 + for (i = 1; i < n; i++) {
32243 + switch (sym[i].st_shndx) {
32244 + case SHN_COMMON:
32245 +@@ -1527,10 +1551,19 @@ static int simplify_symbols(Elf_Shdr *se
32246 + break;
32247 +
32248 + case SHN_UNDEF:
32249 +- sym[i].st_value
32250 +- = resolve_symbol(sechdrs, versindex,
32251 ++ symbol = resolve_symbol(sechdrs, versindex,
32252 + strtab + sym[i].st_name, mod);
32253 +
32254 ++#ifdef CONFIG_PAX_KERNEXEC
32255 ++ pax_open_kernel(cr0);
32256 ++#endif
32257 ++
32258 ++ sym[i].st_value = symbol;
32259 ++
32260 ++#ifdef CONFIG_PAX_KERNEXEC
32261 ++ pax_close_kernel(cr0);
32262 ++#endif
32263 ++
32264 + /* Ok if resolved. */
32265 + if (!IS_ERR_VALUE(sym[i].st_value))
32266 + break;
32267 +@@ -1545,11 +1578,27 @@ static int simplify_symbols(Elf_Shdr *se
32268 +
32269 + default:
32270 + /* Divert to percpu allocation if a percpu var. */
32271 +- if (sym[i].st_shndx == pcpuindex)
32272 ++ if (sym[i].st_shndx == pcpuindex) {
32273 ++
32274 ++#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
32275 ++ secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start;
32276 ++#else
32277 + secbase = (unsigned long)mod->percpu;
32278 +- else
32279 ++#endif
32280 ++
32281 ++ } else
32282 + secbase = sechdrs[sym[i].st_shndx].sh_addr;
32283 ++
32284 ++#ifdef CONFIG_PAX_KERNEXEC
32285 ++ pax_open_kernel(cr0);
32286 ++#endif
32287 ++
32288 + sym[i].st_value += secbase;
32289 ++
32290 ++#ifdef CONFIG_PAX_KERNEXEC
32291 ++ pax_close_kernel(cr0);
32292 ++#endif
32293 ++
32294 + break;
32295 + }
32296 + }
32297 +@@ -1601,11 +1650,12 @@ static void layout_sections(struct modul
32298 + || strncmp(secstrings + s->sh_name,
32299 + ".init", 5) == 0)
32300 + continue;
32301 +- s->sh_entsize = get_offset(&mod->core_size, s);
32302 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32303 ++ s->sh_entsize = get_offset(&mod->core_size_rw, s);
32304 ++ else
32305 ++ s->sh_entsize = get_offset(&mod->core_size_rx, s);
32306 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32307 + }
32308 +- if (m == 0)
32309 +- mod->core_text_size = mod->core_size;
32310 + }
32311 +
32312 + DEBUGP("Init section allocation order:\n");
32313 +@@ -1619,12 +1669,13 @@ static void layout_sections(struct modul
32314 + || strncmp(secstrings + s->sh_name,
32315 + ".init", 5) != 0)
32316 + continue;
32317 +- s->sh_entsize = (get_offset(&mod->init_size, s)
32318 +- | INIT_OFFSET_MASK);
32319 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32320 ++ s->sh_entsize = get_offset(&mod->init_size_rw, s);
32321 ++ else
32322 ++ s->sh_entsize = get_offset(&mod->init_size_rx, s);
32323 ++ s->sh_entsize |= INIT_OFFSET_MASK;
32324 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32325 + }
32326 +- if (m == 0)
32327 +- mod->init_text_size = mod->init_size;
32328 + }
32329 + }
32330 +
32331 +@@ -1764,14 +1815,31 @@ static void add_kallsyms(struct module *
32332 + {
32333 + unsigned int i;
32334 +
32335 ++#ifdef CONFIG_PAX_KERNEXEC
32336 ++ unsigned long cr0;
32337 ++#endif
32338 ++
32339 + mod->symtab = (void *)sechdrs[symindex].sh_addr;
32340 + mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32341 + mod->strtab = (void *)sechdrs[strindex].sh_addr;
32342 +
32343 + /* Set types up while we still have access to sections. */
32344 +- for (i = 0; i < mod->num_symtab; i++)
32345 +- mod->symtab[i].st_info
32346 +- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32347 ++
32348 ++ for (i = 0; i < mod->num_symtab; i++) {
32349 ++ char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32350 ++
32351 ++#ifdef CONFIG_PAX_KERNEXEC
32352 ++ pax_open_kernel(cr0);
32353 ++#endif
32354 ++
32355 ++ mod->symtab[i].st_info = type;
32356 ++
32357 ++#ifdef CONFIG_PAX_KERNEXEC
32358 ++ pax_close_kernel(cr0);
32359 ++#endif
32360 ++
32361 ++ }
32362 ++
32363 + }
32364 + #else
32365 + static inline void add_kallsyms(struct module *mod,
32366 +@@ -1783,16 +1851,30 @@ static inline void add_kallsyms(struct m
32367 + }
32368 + #endif /* CONFIG_KALLSYMS */
32369 +
32370 +-static void *module_alloc_update_bounds(unsigned long size)
32371 ++static void *module_alloc_update_bounds_rw(unsigned long size)
32372 + {
32373 + void *ret = module_alloc(size);
32374 +
32375 + if (ret) {
32376 + /* Update module bounds. */
32377 +- if ((unsigned long)ret < module_addr_min)
32378 +- module_addr_min = (unsigned long)ret;
32379 +- if ((unsigned long)ret + size > module_addr_max)
32380 +- module_addr_max = (unsigned long)ret + size;
32381 ++ if ((unsigned long)ret < module_addr_min_rw)
32382 ++ module_addr_min_rw = (unsigned long)ret;
32383 ++ if ((unsigned long)ret + size > module_addr_max_rw)
32384 ++ module_addr_max_rw = (unsigned long)ret + size;
32385 ++ }
32386 ++ return ret;
32387 ++}
32388 ++
32389 ++static void *module_alloc_update_bounds_rx(unsigned long size)
32390 ++{
32391 ++ void *ret = module_alloc_exec(size);
32392 ++
32393 ++ if (ret) {
32394 ++ /* Update module bounds. */
32395 ++ if ((unsigned long)ret < module_addr_min_rx)
32396 ++ module_addr_min_rx = (unsigned long)ret;
32397 ++ if ((unsigned long)ret + size > module_addr_max_rx)
32398 ++ module_addr_max_rx = (unsigned long)ret + size;
32399 + }
32400 + return ret;
32401 + }
32402 +@@ -1837,6 +1919,10 @@ static noinline struct module *load_modu
32403 + struct exception_table_entry *extable;
32404 + mm_segment_t old_fs;
32405 +
32406 ++#ifdef CONFIG_PAX_KERNEXEC
32407 ++ unsigned long cr0;
32408 ++#endif
32409 ++
32410 + DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
32411 + umod, len, uargs);
32412 + if (len < sizeof(*hdr))
32413 +@@ -1998,22 +2084,57 @@ static noinline struct module *load_modu
32414 + layout_sections(mod, hdr, sechdrs, secstrings);
32415 +
32416 + /* Do the allocs. */
32417 +- ptr = module_alloc_update_bounds(mod->core_size);
32418 ++ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
32419 + if (!ptr) {
32420 + err = -ENOMEM;
32421 + goto free_percpu;
32422 + }
32423 +- memset(ptr, 0, mod->core_size);
32424 +- mod->module_core = ptr;
32425 ++ memset(ptr, 0, mod->core_size_rw);
32426 ++ mod->module_core_rw = ptr;
32427 ++
32428 ++ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
32429 ++ if (!ptr && mod->init_size_rw) {
32430 ++ err = -ENOMEM;
32431 ++ goto free_core_rw;
32432 ++ }
32433 ++ memset(ptr, 0, mod->init_size_rw);
32434 ++ mod->module_init_rw = ptr;
32435 ++
32436 ++ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
32437 ++ if (!ptr) {
32438 ++ err = -ENOMEM;
32439 ++ goto free_init_rw;
32440 ++ }
32441 ++
32442 ++#ifdef CONFIG_PAX_KERNEXEC
32443 ++ pax_open_kernel(cr0);
32444 ++#endif
32445 ++
32446 ++ memset(ptr, 0, mod->core_size_rx);
32447 +
32448 +- ptr = module_alloc_update_bounds(mod->init_size);
32449 +- if (!ptr && mod->init_size) {
32450 ++#ifdef CONFIG_PAX_KERNEXEC
32451 ++ pax_close_kernel(cr0);
32452 ++#endif
32453 ++
32454 ++ mod->module_core_rx = ptr;
32455 ++
32456 ++ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
32457 ++ if (!ptr && mod->init_size_rx) {
32458 + err = -ENOMEM;
32459 +- goto free_core;
32460 ++ goto free_core_rx;
32461 + }
32462 +- memset(ptr, 0, mod->init_size);
32463 +- mod->module_init = ptr;
32464 +
32465 ++#ifdef CONFIG_PAX_KERNEXEC
32466 ++ pax_open_kernel(cr0);
32467 ++#endif
32468 ++
32469 ++ memset(ptr, 0, mod->init_size_rx);
32470 ++
32471 ++#ifdef CONFIG_PAX_KERNEXEC
32472 ++ pax_close_kernel(cr0);
32473 ++#endif
32474 ++
32475 ++ mod->module_init_rx = ptr;
32476 + /* Transfer each section which specifies SHF_ALLOC */
32477 + DEBUGP("final section addresses:\n");
32478 + for (i = 0; i < hdr->e_shnum; i++) {
32479 +@@ -2022,17 +2143,41 @@ static noinline struct module *load_modu
32480 + if (!(sechdrs[i].sh_flags & SHF_ALLOC))
32481 + continue;
32482 +
32483 +- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
32484 +- dest = mod->module_init
32485 +- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32486 +- else
32487 +- dest = mod->module_core + sechdrs[i].sh_entsize;
32488 ++ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
32489 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32490 ++ dest = mod->module_init_rw
32491 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32492 ++ else
32493 ++ dest = mod->module_init_rx
32494 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32495 ++ } else {
32496 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32497 ++ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
32498 ++ else
32499 ++ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
32500 ++ }
32501 +
32502 +- if (sechdrs[i].sh_type != SHT_NOBITS)
32503 +- memcpy(dest, (void *)sechdrs[i].sh_addr,
32504 +- sechdrs[i].sh_size);
32505 ++ if (sechdrs[i].sh_type != SHT_NOBITS) {
32506 ++
32507 ++#ifdef CONFIG_PAX_KERNEXEC
32508 ++ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
32509 ++ pax_open_kernel(cr0);
32510 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32511 ++ pax_close_kernel(cr0);
32512 ++ } else
32513 ++#endif
32514 ++
32515 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32516 ++ }
32517 + /* Update sh_addr to point to copy in image. */
32518 +- sechdrs[i].sh_addr = (unsigned long)dest;
32519 ++
32520 ++#ifdef CONFIG_PAX_KERNEXEC
32521 ++ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
32522 ++ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
32523 ++ else
32524 ++#endif
32525 ++
32526 ++ sechdrs[i].sh_addr = (unsigned long)dest;
32527 + DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
32528 + }
32529 + /* Module has been moved. */
32530 +@@ -2120,8 +2265,8 @@ static noinline struct module *load_modu
32531 +
32532 + /* Now do relocations. */
32533 + for (i = 1; i < hdr->e_shnum; i++) {
32534 +- const char *strtab = (char *)sechdrs[strindex].sh_addr;
32535 + unsigned int info = sechdrs[i].sh_info;
32536 ++ strtab = (char *)sechdrs[strindex].sh_addr;
32537 +
32538 + /* Not a valid relocation section? */
32539 + if (info >= hdr->e_shnum)
32540 +@@ -2180,12 +2325,12 @@ static noinline struct module *load_modu
32541 + * Do it before processing of module parameters, so the module
32542 + * can provide parameter accessor functions of its own.
32543 + */
32544 +- if (mod->module_init)
32545 +- flush_icache_range((unsigned long)mod->module_init,
32546 +- (unsigned long)mod->module_init
32547 +- + mod->init_size);
32548 +- flush_icache_range((unsigned long)mod->module_core,
32549 +- (unsigned long)mod->module_core + mod->core_size);
32550 ++ if (mod->module_init_rx)
32551 ++ flush_icache_range((unsigned long)mod->module_init_rx,
32552 ++ (unsigned long)mod->module_init_rx
32553 ++ + mod->init_size_rx);
32554 ++ flush_icache_range((unsigned long)mod->module_core_rx,
32555 ++ (unsigned long)mod->module_core_rx + mod->core_size_rx);
32556 +
32557 + set_fs(old_fs);
32558 +
32559 +@@ -2238,9 +2383,13 @@ static noinline struct module *load_modu
32560 + kobject_put(&mod->mkobj.kobj);
32561 + free_unload:
32562 + module_unload_free(mod);
32563 +- module_free(mod, mod->module_init);
32564 +- free_core:
32565 +- module_free(mod, mod->module_core);
32566 ++ module_free_exec(mod, mod->module_init_rx);
32567 ++ free_core_rx:
32568 ++ module_free_exec(mod, mod->module_core_rx);
32569 ++ free_init_rw:
32570 ++ module_free(mod, mod->module_init_rw);
32571 ++ free_core_rw:
32572 ++ module_free(mod, mod->module_core_rw);
32573 + free_percpu:
32574 + if (percpu)
32575 + percpu_modfree(percpu);
32576 +@@ -2265,6 +2414,9 @@ sys_init_module(void __user *umod,
32577 + struct module *mod;
32578 + int ret = 0;
32579 +
32580 ++ if (gr_check_modstop())
32581 ++ return -EPERM;
32582 ++
32583 + /* Must have permission */
32584 + if (!capable(CAP_SYS_MODULE))
32585 + return -EPERM;
32586 +@@ -2320,10 +2472,12 @@ sys_init_module(void __user *umod,
32587 + /* Drop initial reference. */
32588 + module_put(mod);
32589 + unwind_remove_table(mod->unwind_info, 1);
32590 +- module_free(mod, mod->module_init);
32591 +- mod->module_init = NULL;
32592 +- mod->init_size = 0;
32593 +- mod->init_text_size = 0;
32594 ++ module_free(mod, mod->module_init_rw);
32595 ++ module_free_exec(mod, mod->module_init_rx);
32596 ++ mod->module_init_rw = NULL;
32597 ++ mod->module_init_rx = NULL;
32598 ++ mod->init_size_rw = 0;
32599 ++ mod->init_size_rx = 0;
32600 + mutex_unlock(&module_mutex);
32601 +
32602 + return 0;
32603 +@@ -2331,6 +2485,13 @@ sys_init_module(void __user *umod,
32604 +
32605 + static inline int within(unsigned long addr, void *start, unsigned long size)
32606 + {
32607 ++
32608 ++#ifdef CONFIG_PAX_KERNEXEC
32609 ++ if (ktla_ktva(addr) >= (unsigned long)start &&
32610 ++ ktla_ktva(addr) < (unsigned long)start + size)
32611 ++ return 1;
32612 ++#endif
32613 ++
32614 + return ((void *)addr >= start && (void *)addr < start + size);
32615 + }
32616 +
32617 +@@ -2354,10 +2515,14 @@ static const char *get_ksymbol(struct mo
32618 + unsigned long nextval;
32619 +
32620 + /* At worse, next value is at end of module */
32621 +- if (within(addr, mod->module_init, mod->init_size))
32622 +- nextval = (unsigned long)mod->module_init+mod->init_text_size;
32623 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx))
32624 ++ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
32625 ++ else if (within(addr, mod->module_init_rw, mod->init_size_rw))
32626 ++ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
32627 ++ else if (within(addr, mod->module_core_rx, mod->core_size_rx))
32628 ++ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
32629 + else
32630 +- nextval = (unsigned long)mod->module_core+mod->core_text_size;
32631 ++ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
32632 +
32633 + /* Scan for closest preceeding symbol, and next symbol. (ELF
32634 + starts real symbols at 1). */
32635 +@@ -2402,8 +2567,10 @@ const char *module_address_lookup(unsign
32636 +
32637 + preempt_disable();
32638 + list_for_each_entry(mod, &modules, list) {
32639 +- if (within(addr, mod->module_init, mod->init_size)
32640 +- || within(addr, mod->module_core, mod->core_size)) {
32641 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32642 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32643 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32644 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32645 + if (modname)
32646 + *modname = mod->name;
32647 + ret = get_ksymbol(mod, addr, size, offset);
32648 +@@ -2425,8 +2592,10 @@ int lookup_module_symbol_name(unsigned l
32649 +
32650 + preempt_disable();
32651 + list_for_each_entry(mod, &modules, list) {
32652 +- if (within(addr, mod->module_init, mod->init_size) ||
32653 +- within(addr, mod->module_core, mod->core_size)) {
32654 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32655 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32656 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32657 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32658 + const char *sym;
32659 +
32660 + sym = get_ksymbol(mod, addr, NULL, NULL);
32661 +@@ -2449,8 +2618,10 @@ int lookup_module_symbol_attrs(unsigned
32662 +
32663 + preempt_disable();
32664 + list_for_each_entry(mod, &modules, list) {
32665 +- if (within(addr, mod->module_init, mod->init_size) ||
32666 +- within(addr, mod->module_core, mod->core_size)) {
32667 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32668 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32669 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32670 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32671 + const char *sym;
32672 +
32673 + sym = get_ksymbol(mod, addr, size, offset);
32674 +@@ -2581,7 +2752,7 @@ static int m_show(struct seq_file *m, vo
32675 + char buf[8];
32676 +
32677 + seq_printf(m, "%s %u",
32678 +- mod->name, mod->init_size + mod->core_size);
32679 ++ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
32680 + print_unload_info(m, mod);
32681 +
32682 + /* Informative for users. */
32683 +@@ -2590,7 +2761,7 @@ static int m_show(struct seq_file *m, vo
32684 + mod->state == MODULE_STATE_COMING ? "Loading":
32685 + "Live");
32686 + /* Used by oprofile and other similar tools. */
32687 +- seq_printf(m, " 0x%p", mod->module_core);
32688 ++ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
32689 +
32690 + /* Taints info */
32691 + if (mod->taints)
32692 +@@ -2646,7 +2817,8 @@ int is_module_address(unsigned long addr
32693 + preempt_disable();
32694 +
32695 + list_for_each_entry(mod, &modules, list) {
32696 +- if (within(addr, mod->module_core, mod->core_size)) {
32697 ++ if (within(addr, mod->module_core_rx, mod->core_size_rx) ||
32698 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32699 + preempt_enable();
32700 + return 1;
32701 + }
32702 +@@ -2663,12 +2835,16 @@ struct module *__module_text_address(uns
32703 + {
32704 + struct module *mod;
32705 +
32706 +- if (addr < module_addr_min || addr > module_addr_max)
32707 ++#ifdef CONFIG_X86_32
32708 ++ addr = ktla_ktva(addr);
32709 ++#endif
32710 ++
32711 ++ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
32712 + return NULL;
32713 +
32714 + list_for_each_entry(mod, &modules, list)
32715 +- if (within(addr, mod->module_init, mod->init_text_size)
32716 +- || within(addr, mod->module_core, mod->core_text_size))
32717 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx)
32718 ++ || within(addr, mod->module_core_rx, mod->core_size_rx))
32719 + return mod;
32720 + return NULL;
32721 + }
32722 +diff -urNp linux-2.6.27.10/kernel/mutex.c linux-2.6.27.10/kernel/mutex.c
32723 +--- linux-2.6.27.10/kernel/mutex.c 2008-11-07 12:55:34.000000000 -0500
32724 ++++ linux-2.6.27.10/kernel/mutex.c 2008-11-18 03:38:45.000000000 -0500
32725 +@@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
32726 + *
32727 + * This function is similar to (but not equivalent to) down().
32728 + */
32729 +-void inline __sched mutex_lock(struct mutex *lock)
32730 ++inline void __sched mutex_lock(struct mutex *lock)
32731 + {
32732 + might_sleep();
32733 + /*
32734 +diff -urNp linux-2.6.27.10/kernel/panic.c linux-2.6.27.10/kernel/panic.c
32735 +--- linux-2.6.27.10/kernel/panic.c 2008-11-07 12:55:34.000000000 -0500
32736 ++++ linux-2.6.27.10/kernel/panic.c 2008-11-18 03:38:45.000000000 -0500
32737 +@@ -349,6 +349,8 @@ EXPORT_SYMBOL(warn_slowpath);
32738 + */
32739 + void __stack_chk_fail(void)
32740 + {
32741 ++ print_symbol("stack corrupted in: %s\n", (unsigned long)__builtin_return_address(0));
32742 ++ dump_stack();
32743 + panic("stack-protector: Kernel stack is corrupted");
32744 + }
32745 + EXPORT_SYMBOL(__stack_chk_fail);
32746 +diff -urNp linux-2.6.27.10/kernel/pid.c linux-2.6.27.10/kernel/pid.c
32747 +--- linux-2.6.27.10/kernel/pid.c 2008-11-07 12:55:34.000000000 -0500
32748 ++++ linux-2.6.27.10/kernel/pid.c 2008-11-18 03:38:45.000000000 -0500
32749 +@@ -36,6 +36,7 @@
32750 + #include <linux/pid_namespace.h>
32751 + #include <linux/init_task.h>
32752 + #include <linux/syscalls.h>
32753 ++#include <linux/grsecurity.h>
32754 +
32755 + #define pid_hashfn(nr, ns) \
32756 + hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
32757 +@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
32758 +
32759 + int pid_max = PID_MAX_DEFAULT;
32760 +
32761 +-#define RESERVED_PIDS 300
32762 ++#define RESERVED_PIDS 500
32763 +
32764 + int pid_max_min = RESERVED_PIDS + 1;
32765 + int pid_max_max = PID_MAX_LIMIT;
32766 +@@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task);
32767 + struct task_struct *find_task_by_pid_type_ns(int type, int nr,
32768 + struct pid_namespace *ns)
32769 + {
32770 +- return pid_task(find_pid_ns(nr, ns), type);
32771 ++ struct task_struct *task;
32772 ++
32773 ++ task = pid_task(find_pid_ns(nr, ns), type);
32774 ++
32775 ++ if (gr_pid_is_chrooted(task))
32776 ++ return NULL;
32777 ++
32778 ++ return task;
32779 + }
32780 +
32781 + EXPORT_SYMBOL(find_task_by_pid_type_ns);
32782 +diff -urNp linux-2.6.27.10/kernel/posix-cpu-timers.c linux-2.6.27.10/kernel/posix-cpu-timers.c
32783 +--- linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-07 12:55:34.000000000 -0500
32784 ++++ linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-18 03:38:45.000000000 -0500
32785 +@@ -6,6 +6,7 @@
32786 + #include <linux/posix-timers.h>
32787 + #include <linux/errno.h>
32788 + #include <linux/math64.h>
32789 ++#include <linux/grsecurity.h>
32790 + #include <asm/uaccess.h>
32791 +
32792 + static int check_clock(const clockid_t which_clock)
32793 +@@ -1176,6 +1177,7 @@ static void check_process_timers(struct
32794 + __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
32795 + return;
32796 + }
32797 ++ gr_learn_resource(tsk, RLIMIT_CPU, psecs, 1);
32798 + if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
32799 + /*
32800 + * At the soft limit, send a SIGXCPU every second.
32801 +@@ -1370,17 +1372,17 @@ void run_posix_cpu_timers(struct task_st
32802 + * timer call will interfere.
32803 + */
32804 + list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
32805 +- int firing;
32806 ++ int __firing;
32807 + spin_lock(&timer->it_lock);
32808 + list_del_init(&timer->it.cpu.entry);
32809 +- firing = timer->it.cpu.firing;
32810 ++ __firing = timer->it.cpu.firing;
32811 + timer->it.cpu.firing = 0;
32812 + /*
32813 + * The firing flag is -1 if we collided with a reset
32814 + * of the timer, which already reported this
32815 + * almost-firing as an overrun. So don't generate an event.
32816 + */
32817 +- if (likely(firing >= 0)) {
32818 ++ if (likely(__firing >= 0)) {
32819 + cpu_timer_fire(timer);
32820 + }
32821 + spin_unlock(&timer->it_lock);
32822 +diff -urNp linux-2.6.27.10/kernel/power/poweroff.c linux-2.6.27.10/kernel/power/poweroff.c
32823 +--- linux-2.6.27.10/kernel/power/poweroff.c 2008-11-07 12:55:34.000000000 -0500
32824 ++++ linux-2.6.27.10/kernel/power/poweroff.c 2008-11-18 03:38:45.000000000 -0500
32825 +@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
32826 + .enable_mask = SYSRQ_ENABLE_BOOT,
32827 + };
32828 +
32829 +-static int pm_sysrq_init(void)
32830 ++static int __init pm_sysrq_init(void)
32831 + {
32832 + register_sysrq_key('o', &sysrq_poweroff_op);
32833 + return 0;
32834 +diff -urNp linux-2.6.27.10/kernel/printk.c linux-2.6.27.10/kernel/printk.c
32835 +--- linux-2.6.27.10/kernel/printk.c 2008-11-07 12:55:34.000000000 -0500
32836 ++++ linux-2.6.27.10/kernel/printk.c 2008-11-18 03:38:45.000000000 -0500
32837 +@@ -32,6 +32,7 @@
32838 + #include <linux/security.h>
32839 + #include <linux/bootmem.h>
32840 + #include <linux/syscalls.h>
32841 ++#include <linux/grsecurity.h>
32842 +
32843 + #include <asm/uaccess.h>
32844 +
32845 +@@ -293,6 +294,11 @@ int do_syslog(int type, char __user *buf
32846 + char c;
32847 + int error = 0;
32848 +
32849 ++#ifdef CONFIG_GRKERNSEC_DMESG
32850 ++ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
32851 ++ return -EPERM;
32852 ++#endif
32853 ++
32854 + error = security_syslog(type);
32855 + if (error)
32856 + return error;
32857 +diff -urNp linux-2.6.27.10/kernel/ptrace.c linux-2.6.27.10/kernel/ptrace.c
32858 +--- linux-2.6.27.10/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
32859 ++++ linux-2.6.27.10/kernel/ptrace.c 2008-11-18 03:38:45.000000000 -0500
32860 +@@ -21,6 +21,7 @@
32861 + #include <linux/audit.h>
32862 + #include <linux/pid_namespace.h>
32863 + #include <linux/syscalls.h>
32864 ++#include <linux/grsecurity.h>
32865 +
32866 + #include <asm/pgtable.h>
32867 + #include <asm/uaccess.h>
32868 +@@ -132,12 +133,12 @@ int __ptrace_may_access(struct task_stru
32869 + (current->uid != task->uid) ||
32870 + (current->gid != task->egid) ||
32871 + (current->gid != task->sgid) ||
32872 +- (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
32873 ++ (current->gid != task->gid)) && !capable_nolog(CAP_SYS_PTRACE))
32874 + return -EPERM;
32875 + smp_rmb();
32876 + if (task->mm)
32877 + dumpable = get_dumpable(task->mm);
32878 +- if (!dumpable && !capable(CAP_SYS_PTRACE))
32879 ++ if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
32880 + return -EPERM;
32881 +
32882 + return security_ptrace_may_access(task, mode);
32883 +@@ -193,7 +194,7 @@ repeat:
32884 +
32885 + /* Go */
32886 + task->ptrace |= PT_PTRACED;
32887 +- if (capable(CAP_SYS_PTRACE))
32888 ++ if (capable_nolog(CAP_SYS_PTRACE))
32889 + task->ptrace |= PT_PTRACE_CAP;
32890 +
32891 + __ptrace_link(task, current);
32892 +@@ -582,6 +583,11 @@ asmlinkage long sys_ptrace(long request,
32893 + if (ret < 0)
32894 + goto out_put_task_struct;
32895 +
32896 ++ if (gr_handle_ptrace(child, request)) {
32897 ++ ret = -EPERM;
32898 ++ goto out_put_task_struct;
32899 ++ }
32900 ++
32901 + ret = arch_ptrace(child, request, addr, data);
32902 + if (ret < 0)
32903 + goto out_put_task_struct;
32904 +diff -urNp linux-2.6.27.10/kernel/relay.c linux-2.6.27.10/kernel/relay.c
32905 +--- linux-2.6.27.10/kernel/relay.c 2008-11-07 12:55:34.000000000 -0500
32906 ++++ linux-2.6.27.10/kernel/relay.c 2008-11-18 03:38:45.000000000 -0500
32907 +@@ -1291,7 +1291,7 @@ static int subbuf_splice_actor(struct fi
32908 + return 0;
32909 +
32910 + ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
32911 +- if (ret < 0 || ret < total_len)
32912 ++ if ((int)ret < 0 || ret < total_len)
32913 + return ret;
32914 +
32915 + if (read_start + ret == nonpad_end)
32916 +diff -urNp linux-2.6.27.10/kernel/resource.c linux-2.6.27.10/kernel/resource.c
32917 +--- linux-2.6.27.10/kernel/resource.c 2008-11-07 12:55:34.000000000 -0500
32918 ++++ linux-2.6.27.10/kernel/resource.c 2008-11-18 03:38:45.000000000 -0500
32919 +@@ -131,8 +131,18 @@ static const struct file_operations proc
32920 +
32921 + static int __init ioresources_init(void)
32922 + {
32923 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
32924 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32925 ++ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
32926 ++ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
32927 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32928 ++ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
32929 ++ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
32930 ++#endif
32931 ++#else
32932 + proc_create("ioports", 0, NULL, &proc_ioports_operations);
32933 + proc_create("iomem", 0, NULL, &proc_iomem_operations);
32934 ++#endif
32935 + return 0;
32936 + }
32937 + __initcall(ioresources_init);
32938 +diff -urNp linux-2.6.27.10/kernel/sched.c linux-2.6.27.10/kernel/sched.c
32939 +--- linux-2.6.27.10/kernel/sched.c 2008-12-21 01:16:52.000000000 -0500
32940 ++++ linux-2.6.27.10/kernel/sched.c 2008-12-21 01:13:46.000000000 -0500
32941 +@@ -71,6 +71,7 @@
32942 + #include <linux/debugfs.h>
32943 + #include <linux/ctype.h>
32944 + #include <linux/ftrace.h>
32945 ++#include <linux/grsecurity.h>
32946 +
32947 + #include <asm/tlb.h>
32948 + #include <asm/irq_regs.h>
32949 +@@ -4962,7 +4963,8 @@ asmlinkage long sys_nice(int increment)
32950 + if (nice > 19)
32951 + nice = 19;
32952 +
32953 +- if (increment < 0 && !can_nice(current, nice))
32954 ++ if (increment < 0 && (!can_nice(current, nice) ||
32955 ++ gr_handle_chroot_nice()))
32956 + return -EPERM;
32957 +
32958 + retval = security_task_setnice(current, nice);
32959 +@@ -6225,7 +6227,7 @@ static struct ctl_table sd_ctl_dir[] = {
32960 + .procname = "sched_domain",
32961 + .mode = 0555,
32962 + },
32963 +- {0, },
32964 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
32965 + };
32966 +
32967 + static struct ctl_table sd_ctl_root[] = {
32968 +@@ -6235,7 +6237,7 @@ static struct ctl_table sd_ctl_root[] =
32969 + .mode = 0555,
32970 + .child = sd_ctl_dir,
32971 + },
32972 +- {0, },
32973 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
32974 + };
32975 +
32976 + static struct ctl_table *sd_alloc_ctl_entry(int n)
32977 +diff -urNp linux-2.6.27.10/kernel/signal.c linux-2.6.27.10/kernel/signal.c
32978 +--- linux-2.6.27.10/kernel/signal.c 2008-11-07 12:55:34.000000000 -0500
32979 ++++ linux-2.6.27.10/kernel/signal.c 2008-11-18 03:38:45.000000000 -0500
32980 +@@ -26,6 +26,7 @@
32981 + #include <linux/capability.h>
32982 + #include <linux/freezer.h>
32983 + #include <linux/pid_namespace.h>
32984 ++#include <linux/grsecurity.h>
32985 + #include <linux/nsproxy.h>
32986 +
32987 + #include <asm/param.h>
32988 +@@ -595,6 +596,9 @@ static int check_kill_permission(int sig
32989 + }
32990 + }
32991 +
32992 ++ if (gr_handle_signal(t, sig))
32993 ++ return -EPERM;
32994 ++
32995 + return security_task_kill(t, info, sig, 0);
32996 + }
32997 +
32998 +@@ -884,8 +888,8 @@ static void print_fatal_signal(struct pt
32999 + for (i = 0; i < 16; i++) {
33000 + unsigned char insn;
33001 +
33002 +- __get_user(insn, (unsigned char *)(regs->ip + i));
33003 +- printk("%02x ", insn);
33004 ++ if (!get_user(insn, (unsigned char __user *)(regs->ip + i)))
33005 ++ printk("%02x ", insn);
33006 + }
33007 + }
33008 + #endif
33009 +@@ -908,7 +912,7 @@ __group_send_sig_info(int sig, struct si
33010 + return send_signal(sig, info, p, 1);
33011 + }
33012 +
33013 +-static int
33014 ++int
33015 + specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
33016 + {
33017 + return send_signal(sig, info, t, 0);
33018 +@@ -946,8 +950,12 @@ force_sig_info(int sig, struct siginfo *
33019 + if (action->sa.sa_handler == SIG_DFL)
33020 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
33021 + ret = specific_send_sig_info(sig, info, t);
33022 ++
33023 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
33024 +
33025 ++ gr_log_signal(sig, t);
33026 ++ gr_handle_crash(t, sig);
33027 ++
33028 + return ret;
33029 + }
33030 +
33031 +@@ -1018,6 +1026,8 @@ int group_send_sig_info(int sig, struct
33032 + ret = __group_send_sig_info(sig, info, p);
33033 + unlock_task_sighand(p, &flags);
33034 + }
33035 ++ if (!ret)
33036 ++ gr_log_signal(sig, p);
33037 + }
33038 +
33039 + return ret;
33040 +diff -urNp linux-2.6.27.10/kernel/softirq.c linux-2.6.27.10/kernel/softirq.c
33041 +--- linux-2.6.27.10/kernel/softirq.c 2008-11-07 12:55:34.000000000 -0500
33042 ++++ linux-2.6.27.10/kernel/softirq.c 2008-11-18 03:38:45.000000000 -0500
33043 +@@ -453,9 +453,9 @@ void tasklet_kill(struct tasklet_struct
33044 + printk("Attempt to kill tasklet from interrupt\n");
33045 +
33046 + while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
33047 +- do
33048 ++ do {
33049 + yield();
33050 +- while (test_bit(TASKLET_STATE_SCHED, &t->state));
33051 ++ } while (test_bit(TASKLET_STATE_SCHED, &t->state));
33052 + }
33053 + tasklet_unlock_wait(t);
33054 + clear_bit(TASKLET_STATE_SCHED, &t->state);
33055 +diff -urNp linux-2.6.27.10/kernel/sys.c linux-2.6.27.10/kernel/sys.c
33056 +--- linux-2.6.27.10/kernel/sys.c 2008-11-07 12:55:34.000000000 -0500
33057 ++++ linux-2.6.27.10/kernel/sys.c 2008-11-18 03:38:45.000000000 -0500
33058 +@@ -33,6 +33,7 @@
33059 + #include <linux/task_io_accounting_ops.h>
33060 + #include <linux/seccomp.h>
33061 + #include <linux/cpu.h>
33062 ++#include <linux/grsecurity.h>
33063 +
33064 + #include <linux/compat.h>
33065 + #include <linux/syscalls.h>
33066 +@@ -125,6 +126,12 @@ static int set_one_prio(struct task_stru
33067 + error = -EACCES;
33068 + goto out;
33069 + }
33070 ++
33071 ++ if (gr_handle_chroot_setpriority(p, niceval)) {
33072 ++ error = -EACCES;
33073 ++ goto out;
33074 ++ }
33075 ++
33076 + no_nice = security_task_setnice(p, niceval);
33077 + if (no_nice) {
33078 + error = no_nice;
33079 +@@ -181,10 +188,10 @@ asmlinkage long sys_setpriority(int whic
33080 + if ((who != current->uid) && !(user = find_user(who)))
33081 + goto out_unlock; /* No processes for this user */
33082 +
33083 +- do_each_thread(g, p)
33084 ++ do_each_thread(g, p) {
33085 + if (p->uid == who)
33086 + error = set_one_prio(p, niceval, error);
33087 +- while_each_thread(g, p);
33088 ++ } while_each_thread(g, p);
33089 + if (who != current->uid)
33090 + free_uid(user); /* For find_user() */
33091 + break;
33092 +@@ -243,13 +250,13 @@ asmlinkage long sys_getpriority(int whic
33093 + if ((who != current->uid) && !(user = find_user(who)))
33094 + goto out_unlock; /* No processes for this user */
33095 +
33096 +- do_each_thread(g, p)
33097 ++ do_each_thread(g, p) {
33098 + if (p->uid == who) {
33099 + niceval = 20 - task_nice(p);
33100 + if (niceval > retval)
33101 + retval = niceval;
33102 + }
33103 +- while_each_thread(g, p);
33104 ++ } while_each_thread(g, p);
33105 + if (who != current->uid)
33106 + free_uid(user); /* for find_user() */
33107 + break;
33108 +@@ -499,6 +506,10 @@ asmlinkage long sys_setregid(gid_t rgid,
33109 + else
33110 + return -EPERM;
33111 + }
33112 ++
33113 ++ if (gr_check_group_change(new_rgid, new_egid, -1))
33114 ++ return -EPERM;
33115 ++
33116 + if (new_egid != old_egid) {
33117 + set_dumpable(current->mm, suid_dumpable);
33118 + smp_wmb();
33119 +@@ -506,6 +517,9 @@ asmlinkage long sys_setregid(gid_t rgid,
33120 + if (rgid != (gid_t) -1 ||
33121 + (egid != (gid_t) -1 && egid != old_rgid))
33122 + current->sgid = new_egid;
33123 ++
33124 ++ gr_set_role_label(current, current->uid, new_rgid);
33125 ++
33126 + current->fsgid = new_egid;
33127 + current->egid = new_egid;
33128 + current->gid = new_rgid;
33129 +@@ -528,11 +542,17 @@ asmlinkage long sys_setgid(gid_t gid)
33130 + if (retval)
33131 + return retval;
33132 +
33133 ++ if (gr_check_group_change(gid, gid, gid))
33134 ++ return -EPERM;
33135 ++
33136 + if (capable(CAP_SETGID)) {
33137 + if (old_egid != gid) {
33138 + set_dumpable(current->mm, suid_dumpable);
33139 + smp_wmb();
33140 + }
33141 ++
33142 ++ gr_set_role_label(current, current->uid, gid);
33143 ++
33144 + current->gid = current->egid = current->sgid = current->fsgid = gid;
33145 + } else if ((gid == current->gid) || (gid == current->sgid)) {
33146 + if (old_egid != gid) {
33147 +@@ -570,6 +590,9 @@ static int set_user(uid_t new_ruid, int
33148 + set_dumpable(current->mm, suid_dumpable);
33149 + smp_wmb();
33150 + }
33151 ++
33152 ++ gr_set_role_label(current, new_ruid, current->gid);
33153 ++
33154 + current->uid = new_ruid;
33155 + return 0;
33156 + }
33157 +@@ -619,6 +642,9 @@ asmlinkage long sys_setreuid(uid_t ruid,
33158 + return -EPERM;
33159 + }
33160 +
33161 ++ if (gr_check_user_change(new_ruid, new_euid, -1))
33162 ++ return -EPERM;
33163 ++
33164 + if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
33165 + return -EAGAIN;
33166 +
33167 +@@ -665,6 +691,12 @@ asmlinkage long sys_setuid(uid_t uid)
33168 + old_suid = current->suid;
33169 + new_suid = old_suid;
33170 +
33171 ++ if (gr_check_crash_uid(uid))
33172 ++ return -EPERM;
33173 ++
33174 ++ if (gr_check_user_change(uid, uid, uid))
33175 ++ return -EPERM;
33176 ++
33177 + if (capable(CAP_SETUID)) {
33178 + if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
33179 + return -EAGAIN;
33180 +@@ -712,6 +744,10 @@ asmlinkage long sys_setresuid(uid_t ruid
33181 + (suid != current->euid) && (suid != current->suid))
33182 + return -EPERM;
33183 + }
33184 ++
33185 ++ if (gr_check_user_change(ruid, euid, -1))
33186 ++ return -EPERM;
33187 ++
33188 + if (ruid != (uid_t) -1) {
33189 + if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
33190 + return -EAGAIN;
33191 +@@ -766,6 +802,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33192 + (sgid != current->egid) && (sgid != current->sgid))
33193 + return -EPERM;
33194 + }
33195 ++
33196 ++ if (gr_check_group_change(rgid, egid, -1))
33197 ++ return -EPERM;
33198 ++
33199 + if (egid != (gid_t) -1) {
33200 + if (egid != current->egid) {
33201 + set_dumpable(current->mm, suid_dumpable);
33202 +@@ -774,8 +814,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33203 + current->egid = egid;
33204 + }
33205 + current->fsgid = current->egid;
33206 +- if (rgid != (gid_t) -1)
33207 ++ if (rgid != (gid_t) -1) {
33208 ++ gr_set_role_label(current, current->uid, rgid);
33209 + current->gid = rgid;
33210 ++ }
33211 + if (sgid != (gid_t) -1)
33212 + current->sgid = sgid;
33213 +
33214 +@@ -810,6 +852,9 @@ asmlinkage long sys_setfsuid(uid_t uid)
33215 + if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
33216 + return old_fsuid;
33217 +
33218 ++ if (gr_check_user_change(-1, -1, uid))
33219 ++ return old_fsuid;
33220 ++
33221 + if (uid == current->uid || uid == current->euid ||
33222 + uid == current->suid || uid == current->fsuid ||
33223 + capable(CAP_SETUID)) {
33224 +@@ -842,6 +887,9 @@ asmlinkage long sys_setfsgid(gid_t gid)
33225 + if (gid == current->gid || gid == current->egid ||
33226 + gid == current->sgid || gid == current->fsgid ||
33227 + capable(CAP_SETGID)) {
33228 ++ if (gr_check_group_change(-1, -1, gid))
33229 ++ return old_fsgid;
33230 ++
33231 + if (gid != old_fsgid) {
33232 + set_dumpable(current->mm, suid_dumpable);
33233 + smp_wmb();
33234 +@@ -923,7 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, p
33235 + write_lock_irq(&tasklist_lock);
33236 +
33237 + err = -ESRCH;
33238 +- p = find_task_by_vpid(pid);
33239 ++ /* grsec: replaced find_task_by_vpid with equivalent call which
33240 ++ lacks the chroot restriction
33241 ++ */
33242 ++ p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID);
33243 + if (!p)
33244 + goto out;
33245 +
33246 +@@ -1655,7 +1706,7 @@ asmlinkage long sys_prctl(int option, un
33247 + error = get_dumpable(current->mm);
33248 + break;
33249 + case PR_SET_DUMPABLE:
33250 +- if (arg2 < 0 || arg2 > 1) {
33251 ++ if (arg2 > 1) {
33252 + error = -EINVAL;
33253 + break;
33254 + }
33255 +diff -urNp linux-2.6.27.10/kernel/sysctl.c linux-2.6.27.10/kernel/sysctl.c
33256 +--- linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:38.000000000 -0500
33257 ++++ linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:46.000000000 -0500
33258 +@@ -61,6 +61,13 @@
33259 + static int deprecated_sysctl_warning(struct __sysctl_args *args);
33260 +
33261 + #if defined(CONFIG_SYSCTL)
33262 ++#include <linux/grsecurity.h>
33263 ++#include <linux/grinternal.h>
33264 ++
33265 ++extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
33266 ++extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
33267 ++ const int op);
33268 ++extern int gr_handle_chroot_sysctl(const int op);
33269 +
33270 + /* External variables not in a header file. */
33271 + extern int C_A_D;
33272 +@@ -155,6 +162,7 @@ static int proc_do_cad_pid(struct ctl_ta
33273 + static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
33274 + void __user *buffer, size_t *lenp, loff_t *ppos);
33275 + #endif
33276 ++extern ctl_table grsecurity_table[];
33277 +
33278 + static struct ctl_table root_table[];
33279 + static struct ctl_table_root sysctl_table_root;
33280 +@@ -187,6 +195,21 @@ extern struct ctl_table epoll_table[];
33281 + int sysctl_legacy_va_layout;
33282 + #endif
33283 +
33284 ++#ifdef CONFIG_PAX_SOFTMODE
33285 ++static ctl_table pax_table[] = {
33286 ++ {
33287 ++ .ctl_name = CTL_UNNUMBERED,
33288 ++ .procname = "softmode",
33289 ++ .data = &pax_softmode,
33290 ++ .maxlen = sizeof(unsigned int),
33291 ++ .mode = 0600,
33292 ++ .proc_handler = &proc_dointvec,
33293 ++ },
33294 ++
33295 ++ { .ctl_name = 0 }
33296 ++};
33297 ++#endif
33298 ++
33299 + extern int prove_locking;
33300 + extern int lock_stat;
33301 +
33302 +@@ -223,6 +246,7 @@ static struct ctl_table root_table[] = {
33303 + .mode = 0555,
33304 + .child = dev_table,
33305 + },
33306 ++
33307 + /*
33308 + * NOTE: do not add new entries to this table unless you have read
33309 + * Documentation/sysctl/ctl_unnumbered.txt
33310 +@@ -850,6 +874,25 @@ static struct ctl_table kern_table[] = {
33311 + .proc_handler = &proc_dointvec,
33312 + },
33313 + #endif
33314 ++
33315 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
33316 ++ {
33317 ++ .ctl_name = CTL_UNNUMBERED,
33318 ++ .procname = "grsecurity",
33319 ++ .mode = 0500,
33320 ++ .child = grsecurity_table,
33321 ++ },
33322 ++#endif
33323 ++
33324 ++#ifdef CONFIG_PAX_SOFTMODE
33325 ++ {
33326 ++ .ctl_name = CTL_UNNUMBERED,
33327 ++ .procname = "pax",
33328 ++ .mode = 0500,
33329 ++ .child = pax_table,
33330 ++ },
33331 ++#endif
33332 ++
33333 + /*
33334 + * NOTE: do not add new entries to this table unless you have read
33335 + * Documentation/sysctl/ctl_unnumbered.txt
33336 +@@ -1179,6 +1222,7 @@ static struct ctl_table vm_table[] = {
33337 + .extra2 = &one,
33338 + },
33339 + #endif
33340 ++
33341 + /*
33342 + * NOTE: do not add new entries to this table unless you have read
33343 + * Documentation/sysctl/ctl_unnumbered.txt
33344 +@@ -1553,6 +1597,8 @@ static int do_sysctl_strategy(struct ctl
33345 + return 0;
33346 + }
33347 +
33348 ++static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
33349 ++
33350 + static int parse_table(int __user *name, int nlen,
33351 + void __user *oldval, size_t __user *oldlenp,
33352 + void __user *newval, size_t newlen,
33353 +@@ -1571,7 +1617,7 @@ repeat:
33354 + if (n == table->ctl_name) {
33355 + int error;
33356 + if (table->child) {
33357 +- if (sysctl_perm(root, table, MAY_EXEC))
33358 ++ if (sysctl_perm_nochk(root, table, MAY_EXEC))
33359 + return -EPERM;
33360 + name++;
33361 + nlen--;
33362 +@@ -1656,6 +1702,33 @@ int sysctl_perm(struct ctl_table_root *r
33363 + int error;
33364 + int mode;
33365 +
33366 ++ if (table->parent != NULL && table->parent->procname != NULL &&
33367 ++ table->procname != NULL &&
33368 ++ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
33369 ++ return -EACCES;
33370 ++ if (gr_handle_chroot_sysctl(op))
33371 ++ return -EACCES;
33372 ++ error = gr_handle_sysctl(table, op);
33373 ++ if (error)
33374 ++ return error;
33375 ++
33376 ++ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33377 ++ if (error)
33378 ++ return error;
33379 ++
33380 ++ if (root->permissions)
33381 ++ mode = root->permissions(root, current->nsproxy, table);
33382 ++ else
33383 ++ mode = table->mode;
33384 ++
33385 ++ return test_perm(mode, op);
33386 ++}
33387 ++
33388 ++int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
33389 ++{
33390 ++ int error;
33391 ++ int mode;
33392 ++
33393 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33394 + if (error)
33395 + return error;
33396 +diff -urNp linux-2.6.27.10/kernel/time/tick-broadcast.c linux-2.6.27.10/kernel/time/tick-broadcast.c
33397 +--- linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-07 12:55:34.000000000 -0500
33398 ++++ linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-18 03:38:45.000000000 -0500
33399 +@@ -114,7 +114,7 @@ int tick_device_uses_broadcast(struct cl
33400 + * then clear the broadcast bit.
33401 + */
33402 + if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
33403 +- int cpu = smp_processor_id();
33404 ++ cpu = smp_processor_id();
33405 +
33406 + cpu_clear(cpu, tick_broadcast_mask);
33407 + tick_broadcast_clear_oneshot(cpu);
33408 +diff -urNp linux-2.6.27.10/kernel/time.c linux-2.6.27.10/kernel/time.c
33409 +--- linux-2.6.27.10/kernel/time.c 2008-11-07 12:55:34.000000000 -0500
33410 ++++ linux-2.6.27.10/kernel/time.c 2008-11-18 03:38:45.000000000 -0500
33411 +@@ -37,6 +37,7 @@
33412 + #include <linux/fs.h>
33413 + #include <linux/slab.h>
33414 + #include <linux/math64.h>
33415 ++#include <linux/grsecurity.h>
33416 +
33417 + #include <asm/uaccess.h>
33418 + #include <asm/unistd.h>
33419 +@@ -92,6 +93,9 @@ asmlinkage long sys_stime(time_t __user
33420 + return err;
33421 +
33422 + do_settimeofday(&tv);
33423 ++
33424 ++ gr_log_timechange();
33425 ++
33426 + return 0;
33427 + }
33428 +
33429 +@@ -200,6 +204,8 @@ asmlinkage long sys_settimeofday(struct
33430 + return -EFAULT;
33431 + }
33432 +
33433 ++ gr_log_timechange();
33434 ++
33435 + return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
33436 + }
33437 +
33438 +@@ -238,7 +244,7 @@ EXPORT_SYMBOL(current_fs_time);
33439 + * Avoid unnecessary multiplications/divisions in the
33440 + * two most common HZ cases:
33441 + */
33442 +-unsigned int inline jiffies_to_msecs(const unsigned long j)
33443 ++inline unsigned int jiffies_to_msecs(const unsigned long j)
33444 + {
33445 + #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
33446 + return (MSEC_PER_SEC / HZ) * j;
33447 +@@ -254,7 +260,7 @@ unsigned int inline jiffies_to_msecs(con
33448 + }
33449 + EXPORT_SYMBOL(jiffies_to_msecs);
33450 +
33451 +-unsigned int inline jiffies_to_usecs(const unsigned long j)
33452 ++inline unsigned int jiffies_to_usecs(const unsigned long j)
33453 + {
33454 + #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
33455 + return (USEC_PER_SEC / HZ) * j;
33456 +diff -urNp linux-2.6.27.10/kernel/utsname_sysctl.c linux-2.6.27.10/kernel/utsname_sysctl.c
33457 +--- linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-07 12:55:34.000000000 -0500
33458 ++++ linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-18 03:38:45.000000000 -0500
33459 +@@ -124,7 +124,7 @@ static struct ctl_table uts_kern_table[]
33460 + .proc_handler = proc_do_uts_string,
33461 + .strategy = sysctl_uts_string,
33462 + },
33463 +- {}
33464 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33465 + };
33466 +
33467 + static struct ctl_table uts_root_table[] = {
33468 +@@ -134,7 +134,7 @@ static struct ctl_table uts_root_table[]
33469 + .mode = 0555,
33470 + .child = uts_kern_table,
33471 + },
33472 +- {}
33473 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33474 + };
33475 +
33476 + static int __init utsname_sysctl_init(void)
33477 +diff -urNp linux-2.6.27.10/lib/radix-tree.c linux-2.6.27.10/lib/radix-tree.c
33478 +--- linux-2.6.27.10/lib/radix-tree.c 2008-11-07 12:55:34.000000000 -0500
33479 ++++ linux-2.6.27.10/lib/radix-tree.c 2008-11-18 03:38:45.000000000 -0500
33480 +@@ -81,7 +81,7 @@ struct radix_tree_preload {
33481 + int nr;
33482 + struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
33483 + };
33484 +-DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
33485 ++DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
33486 +
33487 + static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
33488 + {
33489 +diff -urNp linux-2.6.27.10/localversion-grsec linux-2.6.27.10/localversion-grsec
33490 +--- linux-2.6.27.10/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
33491 ++++ linux-2.6.27.10/localversion-grsec 2008-11-18 03:38:45.000000000 -0500
33492 +@@ -0,0 +1 @@
33493 ++-grsec
33494 +diff -urNp linux-2.6.27.10/Makefile linux-2.6.27.10/Makefile
33495 +--- linux-2.6.27.10/Makefile 2008-12-21 01:18:11.000000000 -0500
33496 ++++ linux-2.6.27.10/Makefile 2008-12-21 01:18:21.000000000 -0500
33497 +@@ -221,7 +221,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
33498 +
33499 + HOSTCC = gcc
33500 + HOSTCXX = g++
33501 +-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
33502 ++HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
33503 + HOSTCXXFLAGS = -O2
33504 +
33505 + # Decide whether to build built-in, modular, or both.
33506 +@@ -619,7 +619,7 @@ export mod_strip_cmd
33507 +
33508 +
33509 + ifeq ($(KBUILD_EXTMOD),)
33510 +-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
33511 ++core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
33512 +
33513 + vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
33514 + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
33515 +diff -urNp linux-2.6.27.10/mm/filemap.c linux-2.6.27.10/mm/filemap.c
33516 +--- linux-2.6.27.10/mm/filemap.c 2008-11-07 12:55:34.000000000 -0500
33517 ++++ linux-2.6.27.10/mm/filemap.c 2008-11-18 03:38:45.000000000 -0500
33518 +@@ -33,6 +33,7 @@
33519 + #include <linux/cpuset.h>
33520 + #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
33521 + #include <linux/memcontrol.h>
33522 ++#include <linux/grsecurity.h>
33523 + #include "internal.h"
33524 +
33525 + /*
33526 +@@ -1588,7 +1589,7 @@ int generic_file_mmap(struct file * file
33527 + struct address_space *mapping = file->f_mapping;
33528 +
33529 + if (!mapping->a_ops->readpage)
33530 +- return -ENOEXEC;
33531 ++ return -ENODEV;
33532 + file_accessed(file);
33533 + vma->vm_ops = &generic_file_vm_ops;
33534 + vma->vm_flags |= VM_CAN_NONLINEAR;
33535 +@@ -1949,6 +1950,7 @@ inline int generic_write_checks(struct f
33536 + *pos = i_size_read(inode);
33537 +
33538 + if (limit != RLIM_INFINITY) {
33539 ++ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
33540 + if (*pos >= limit) {
33541 + send_sig(SIGXFSZ, current, 0);
33542 + return -EFBIG;
33543 +diff -urNp linux-2.6.27.10/mm/fremap.c linux-2.6.27.10/mm/fremap.c
33544 +--- linux-2.6.27.10/mm/fremap.c 2008-11-07 12:55:34.000000000 -0500
33545 ++++ linux-2.6.27.10/mm/fremap.c 2008-11-18 03:38:45.000000000 -0500
33546 +@@ -151,6 +151,13 @@ asmlinkage long sys_remap_file_pages(uns
33547 + retry:
33548 + vma = find_vma(mm, start);
33549 +
33550 ++#ifdef CONFIG_PAX_SEGMEXEC
33551 ++ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) {
33552 ++ up_read(&mm->mmap_sem);
33553 ++ return err;
33554 ++ }
33555 ++#endif
33556 ++
33557 + /*
33558 + * Make sure the vma is shared, that it supports prefaulting,
33559 + * and that the remapped range is valid and fully within
33560 +diff -urNp linux-2.6.27.10/mm/hugetlb.c linux-2.6.27.10/mm/hugetlb.c
33561 +--- linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:38:40.000000000 -0500
33562 ++++ linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:40:53.000000000 -0500
33563 +@@ -1833,6 +1833,26 @@ int unmap_ref_private(struct mm_struct *
33564 + return 1;
33565 + }
33566 +
33567 ++#ifdef CONFIG_PAX_SEGMEXEC
33568 ++static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
33569 ++{
33570 ++ struct mm_struct *mm = vma->vm_mm;
33571 ++ struct vm_area_struct *vma_m;
33572 ++ unsigned long address_m;
33573 ++ pte_t *ptep_m;
33574 ++
33575 ++ vma_m = pax_find_mirror_vma(vma);
33576 ++ if (!vma_m)
33577 ++ return;
33578 ++
33579 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33580 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33581 ++ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
33582 ++ get_page(page_m);
33583 ++ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
33584 ++}
33585 ++#endif
33586 ++
33587 + static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
33588 + unsigned long address, pte_t *ptep, pte_t pte,
33589 + struct page *pagecache_page)
33590 +@@ -1904,6 +1924,11 @@ retry_avoidcopy:
33591 + huge_ptep_clear_flush(vma, address, ptep);
33592 + set_huge_pte_at(mm, address, ptep,
33593 + make_huge_pte(vma, new_page, 1));
33594 ++
33595 ++#ifdef CONFIG_PAX_SEGMEXEC
33596 ++ pax_mirror_huge_pte(vma, address, new_page);
33597 ++#endif
33598 ++
33599 + /* Make the old page be freed below */
33600 + new_page = old_page;
33601 + }
33602 +@@ -2013,6 +2038,10 @@ retry:
33603 + && (vma->vm_flags & VM_SHARED)));
33604 + set_huge_pte_at(mm, address, ptep, new_pte);
33605 +
33606 ++#ifdef CONFIG_PAX_SEGMEXEC
33607 ++ pax_mirror_huge_pte(vma, address, page);
33608 ++#endif
33609 ++
33610 + if (write_access && !(vma->vm_flags & VM_SHARED)) {
33611 + /* Optimization, do the COW without a second fault */
33612 + ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
33613 +@@ -2041,6 +2070,28 @@ int hugetlb_fault(struct mm_struct *mm,
33614 + static DEFINE_MUTEX(hugetlb_instantiation_mutex);
33615 + struct hstate *h = hstate_vma(vma);
33616 +
33617 ++#ifdef CONFIG_PAX_SEGMEXEC
33618 ++ struct vm_area_struct *vma_m;
33619 ++
33620 ++ vma_m = pax_find_mirror_vma(vma);
33621 ++ if (vma_m) {
33622 ++ unsigned long address_m;
33623 ++
33624 ++ if (vma->vm_start > vma_m->vm_start) {
33625 ++ address_m = address;
33626 ++ address -= SEGMEXEC_TASK_SIZE;
33627 ++ vma = vma_m;
33628 ++ h = hstate_vma(vma);
33629 ++ } else
33630 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33631 ++
33632 ++ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
33633 ++ return VM_FAULT_OOM;
33634 ++ address_m &= HPAGE_MASK;
33635 ++ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
33636 ++ }
33637 ++#endif
33638 ++
33639 + ptep = huge_pte_alloc(mm, address, huge_page_size(h));
33640 + if (!ptep)
33641 + return VM_FAULT_OOM;
33642 +diff -urNp linux-2.6.27.10/mm/madvise.c linux-2.6.27.10/mm/madvise.c
33643 +--- linux-2.6.27.10/mm/madvise.c 2008-11-07 12:55:34.000000000 -0500
33644 ++++ linux-2.6.27.10/mm/madvise.c 2008-11-18 03:38:45.000000000 -0500
33645 +@@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a
33646 + pgoff_t pgoff;
33647 + int new_flags = vma->vm_flags;
33648 +
33649 ++#ifdef CONFIG_PAX_SEGMEXEC
33650 ++ struct vm_area_struct *vma_m;
33651 ++#endif
33652 ++
33653 + switch (behavior) {
33654 + case MADV_NORMAL:
33655 + new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
33656 +@@ -92,6 +96,13 @@ success:
33657 + /*
33658 + * vm_flags is protected by the mmap_sem held in write mode.
33659 + */
33660 ++
33661 ++#ifdef CONFIG_PAX_SEGMEXEC
33662 ++ vma_m = pax_find_mirror_vma(vma);
33663 ++ if (vma_m)
33664 ++ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
33665 ++#endif
33666 ++
33667 + vma->vm_flags = new_flags;
33668 +
33669 + out:
33670 +@@ -236,6 +247,17 @@ madvise_vma(struct vm_area_struct *vma,
33671 +
33672 + case MADV_DONTNEED:
33673 + error = madvise_dontneed(vma, prev, start, end);
33674 ++
33675 ++#ifdef CONFIG_PAX_SEGMEXEC
33676 ++ if (!error) {
33677 ++ struct vm_area_struct *vma_m, *prev_m;
33678 ++
33679 ++ vma_m = pax_find_mirror_vma(vma);
33680 ++ if (vma_m)
33681 ++ error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE);
33682 ++ }
33683 ++#endif
33684 ++
33685 + break;
33686 +
33687 + default:
33688 +@@ -308,6 +330,16 @@ asmlinkage long sys_madvise(unsigned lon
33689 + if (end < start)
33690 + goto out;
33691 +
33692 ++#ifdef CONFIG_PAX_SEGMEXEC
33693 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
33694 ++ if (end > SEGMEXEC_TASK_SIZE)
33695 ++ goto out;
33696 ++ } else
33697 ++#endif
33698 ++
33699 ++ if (end > TASK_SIZE)
33700 ++ goto out;
33701 ++
33702 + error = 0;
33703 + if (end == start)
33704 + goto out;
33705 +diff -urNp linux-2.6.27.10/mm/memory.c linux-2.6.27.10/mm/memory.c
33706 +--- linux-2.6.27.10/mm/memory.c 2008-11-07 12:55:34.000000000 -0500
33707 ++++ linux-2.6.27.10/mm/memory.c 2008-11-18 03:38:45.000000000 -0500
33708 +@@ -52,6 +52,7 @@
33709 + #include <linux/writeback.h>
33710 + #include <linux/memcontrol.h>
33711 + #include <linux/mmu_notifier.h>
33712 ++#include <linux/grsecurity.h>
33713 +
33714 + #include <asm/pgalloc.h>
33715 + #include <asm/uaccess.h>
33716 +@@ -1146,11 +1147,11 @@ int get_user_pages(struct task_struct *t
33717 + vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
33718 + i = 0;
33719 +
33720 +- do {
33721 ++ while (len) {
33722 + struct vm_area_struct *vma;
33723 + unsigned int foll_flags;
33724 +
33725 +- vma = find_extend_vma(mm, start);
33726 ++ vma = find_vma(mm, start);
33727 + if (!vma && in_gate_area(tsk, start)) {
33728 + unsigned long pg = start & PAGE_MASK;
33729 + struct vm_area_struct *gate_vma = get_gate_vma(tsk);
33730 +@@ -1190,7 +1191,7 @@ int get_user_pages(struct task_struct *t
33731 + continue;
33732 + }
33733 +
33734 +- if (!vma || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33735 ++ if (!vma || start < vma->vm_start || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33736 + || !(vm_flags & vma->vm_flags))
33737 + return i ? : -EFAULT;
33738 +
33739 +@@ -1263,7 +1264,7 @@ int get_user_pages(struct task_struct *t
33740 + start += PAGE_SIZE;
33741 + len--;
33742 + } while (len && start < vma->vm_end);
33743 +- } while (len);
33744 ++ }
33745 + return i;
33746 + }
33747 + EXPORT_SYMBOL(get_user_pages);
33748 +@@ -1741,6 +1742,186 @@ static inline void cow_user_page(struct
33749 + copy_user_highpage(dst, src, va, vma);
33750 + }
33751 +
33752 ++#ifdef CONFIG_PAX_SEGMEXEC
33753 ++static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
33754 ++{
33755 ++ struct mm_struct *mm = vma->vm_mm;
33756 ++ spinlock_t *ptl;
33757 ++ pte_t *pte, entry;
33758 ++
33759 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
33760 ++ entry = *pte;
33761 ++ if (!pte_present(entry)) {
33762 ++ if (!pte_none(entry)) {
33763 ++ BUG_ON(pte_file(entry));
33764 ++ free_swap_and_cache(pte_to_swp_entry(entry));
33765 ++ pte_clear_not_present_full(mm, address, pte, 0);
33766 ++ }
33767 ++ } else {
33768 ++ struct page *page;
33769 ++
33770 ++ flush_cache_page(vma, address, pte_pfn(entry));
33771 ++ entry = ptep_clear_flush(vma, address, pte);
33772 ++ BUG_ON(pte_dirty(entry));
33773 ++ page = vm_normal_page(vma, address, entry);
33774 ++ if (page) {
33775 ++ update_hiwater_rss(mm);
33776 ++ if (PageAnon(page))
33777 ++ dec_mm_counter(mm, anon_rss);
33778 ++ else
33779 ++ dec_mm_counter(mm, file_rss);
33780 ++ page_remove_rmap(page, vma);
33781 ++ page_cache_release(page);
33782 ++ }
33783 ++ }
33784 ++ pte_unmap_unlock(pte, ptl);
33785 ++}
33786 ++
33787 ++/* PaX: if vma is mirrored, synchronize the mirror's PTE
33788 ++ *
33789 ++ * the ptl of the lower mapped page is held on entry and is not released on exit
33790 ++ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
33791 ++ */
33792 ++static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33793 ++{
33794 ++ struct mm_struct *mm = vma->vm_mm;
33795 ++ unsigned long address_m;
33796 ++ spinlock_t *ptl_m;
33797 ++ struct vm_area_struct *vma_m;
33798 ++ pmd_t *pmd_m;
33799 ++ pte_t *pte_m, entry_m;
33800 ++
33801 ++ BUG_ON(!page_m || !PageAnon(page_m));
33802 ++
33803 ++ vma_m = pax_find_mirror_vma(vma);
33804 ++ if (!vma_m)
33805 ++ return;
33806 ++
33807 ++ BUG_ON(!PageLocked(page_m));
33808 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33809 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33810 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33811 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33812 ++ ptl_m = pte_lockptr(mm, pmd_m);
33813 ++ if (ptl != ptl_m) {
33814 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33815 ++ if (!pte_none(*pte_m))
33816 ++ goto out;
33817 ++ }
33818 ++
33819 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33820 ++ page_cache_get(page_m);
33821 ++ page_add_anon_rmap(page_m, vma_m, address_m);
33822 ++ inc_mm_counter(mm, anon_rss);
33823 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33824 ++ update_mmu_cache(vma_m, address_m, entry_m);
33825 ++out:
33826 ++ if (ptl != ptl_m)
33827 ++ spin_unlock(ptl_m);
33828 ++ pte_unmap_nested(pte_m);
33829 ++ unlock_page(page_m);
33830 ++}
33831 ++
33832 ++void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33833 ++{
33834 ++ struct mm_struct *mm = vma->vm_mm;
33835 ++ unsigned long address_m;
33836 ++ spinlock_t *ptl_m;
33837 ++ struct vm_area_struct *vma_m;
33838 ++ pmd_t *pmd_m;
33839 ++ pte_t *pte_m, entry_m;
33840 ++
33841 ++ BUG_ON(!page_m || PageAnon(page_m));
33842 ++
33843 ++ vma_m = pax_find_mirror_vma(vma);
33844 ++ if (!vma_m)
33845 ++ return;
33846 ++
33847 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33848 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33849 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33850 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33851 ++ ptl_m = pte_lockptr(mm, pmd_m);
33852 ++ if (ptl != ptl_m) {
33853 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33854 ++ if (!pte_none(*pte_m))
33855 ++ goto out;
33856 ++ }
33857 ++
33858 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33859 ++ page_cache_get(page_m);
33860 ++ page_add_file_rmap(page_m);
33861 ++ inc_mm_counter(mm, file_rss);
33862 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33863 ++ update_mmu_cache(vma_m, address_m, entry_m);
33864 ++out:
33865 ++ if (ptl != ptl_m)
33866 ++ spin_unlock(ptl_m);
33867 ++ pte_unmap_nested(pte_m);
33868 ++}
33869 ++
33870 ++static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
33871 ++{
33872 ++ struct mm_struct *mm = vma->vm_mm;
33873 ++ unsigned long address_m;
33874 ++ spinlock_t *ptl_m;
33875 ++ struct vm_area_struct *vma_m;
33876 ++ pmd_t *pmd_m;
33877 ++ pte_t *pte_m, entry_m;
33878 ++
33879 ++ vma_m = pax_find_mirror_vma(vma);
33880 ++ if (!vma_m)
33881 ++ return;
33882 ++
33883 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33884 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33885 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33886 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33887 ++ ptl_m = pte_lockptr(mm, pmd_m);
33888 ++ if (ptl != ptl_m) {
33889 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33890 ++ if (!pte_none(*pte_m))
33891 ++ goto out;
33892 ++ }
33893 ++
33894 ++ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
33895 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33896 ++out:
33897 ++ if (ptl != ptl_m)
33898 ++ spin_unlock(ptl_m);
33899 ++ pte_unmap_nested(pte_m);
33900 ++}
33901 ++
33902 ++static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
33903 ++{
33904 ++ struct page *page_m;
33905 ++ pte_t entry;
33906 ++
33907 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
33908 ++ goto out;
33909 ++
33910 ++ entry = *pte;
33911 ++ page_m = vm_normal_page(vma, address, entry);
33912 ++ if (!page_m)
33913 ++ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
33914 ++ else if (PageAnon(page_m)) {
33915 ++ if (pax_find_mirror_vma(vma)) {
33916 ++ pte_unmap_unlock(pte, ptl);
33917 ++ lock_page(page_m);
33918 ++ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
33919 ++ if (pte_same(entry, *pte))
33920 ++ pax_mirror_anon_pte(vma, address, page_m, ptl);
33921 ++ else
33922 ++ unlock_page(page_m);
33923 ++ }
33924 ++ } else
33925 ++ pax_mirror_file_pte(vma, address, page_m, ptl);
33926 ++
33927 ++out:
33928 ++ pte_unmap_unlock(pte, ptl);
33929 ++}
33930 ++#endif
33931 ++
33932 + /*
33933 + * This routine handles present pages, when users try to write
33934 + * to a shared page. It is done by copying the page to a new address
33935 +@@ -1869,6 +2050,12 @@ gotten:
33936 + */
33937 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
33938 + if (likely(pte_same(*page_table, orig_pte))) {
33939 ++
33940 ++#ifdef CONFIG_PAX_SEGMEXEC
33941 ++ if (pax_find_mirror_vma(vma))
33942 ++ BUG_ON(!trylock_page(new_page));
33943 ++#endif
33944 ++
33945 + if (old_page) {
33946 + if (!PageAnon(old_page)) {
33947 + dec_mm_counter(mm, file_rss);
33948 +@@ -1917,6 +2104,10 @@ gotten:
33949 + page_remove_rmap(old_page, vma);
33950 + }
33951 +
33952 ++#ifdef CONFIG_PAX_SEGMEXEC
33953 ++ pax_mirror_anon_pte(vma, address, new_page, ptl);
33954 ++#endif
33955 ++
33956 + /* Free the old page.. */
33957 + new_page = old_page;
33958 + ret |= VM_FAULT_WRITE;
33959 +@@ -2176,6 +2367,7 @@ int vmtruncate(struct inode * inode, lof
33960 + unsigned long limit;
33961 +
33962 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
33963 ++ gr_learn_resource(current, RLIMIT_FSIZE, offset, 1);
33964 + if (limit != RLIM_INFINITY && offset > limit)
33965 + goto out_sig;
33966 + if (offset > inode->i_sb->s_maxbytes)
33967 +@@ -2326,6 +2518,11 @@ static int do_swap_page(struct mm_struct
33968 + swap_free(entry);
33969 + if (vm_swap_full())
33970 + remove_exclusive_swap_page(page);
33971 ++
33972 ++#ifdef CONFIG_PAX_SEGMEXEC
33973 ++ if (write_access || !pax_find_mirror_vma(vma))
33974 ++#endif
33975 ++
33976 + unlock_page(page);
33977 +
33978 + if (write_access) {
33979 +@@ -2337,6 +2534,11 @@ static int do_swap_page(struct mm_struct
33980 +
33981 + /* No need to invalidate - it was non-present before */
33982 + update_mmu_cache(vma, address, pte);
33983 ++
33984 ++#ifdef CONFIG_PAX_SEGMEXEC
33985 ++ pax_mirror_anon_pte(vma, address, page, ptl);
33986 ++#endif
33987 ++
33988 + unlock:
33989 + pte_unmap_unlock(page_table, ptl);
33990 + out:
33991 +@@ -2381,6 +2583,12 @@ static int do_anonymous_page(struct mm_s
33992 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
33993 + if (!pte_none(*page_table))
33994 + goto release;
33995 ++
33996 ++#ifdef CONFIG_PAX_SEGMEXEC
33997 ++ if (pax_find_mirror_vma(vma))
33998 ++ BUG_ON(!trylock_page(page));
33999 ++#endif
34000 ++
34001 + inc_mm_counter(mm, anon_rss);
34002 + lru_cache_add_active(page);
34003 + page_add_new_anon_rmap(page, vma, address);
34004 +@@ -2388,6 +2596,11 @@ static int do_anonymous_page(struct mm_s
34005 +
34006 + /* No need to invalidate - it was non-present before */
34007 + update_mmu_cache(vma, address, entry);
34008 ++
34009 ++#ifdef CONFIG_PAX_SEGMEXEC
34010 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34011 ++#endif
34012 ++
34013 + unlock:
34014 + pte_unmap_unlock(page_table, ptl);
34015 + return 0;
34016 +@@ -2516,6 +2729,12 @@ static int __do_fault(struct mm_struct *
34017 + */
34018 + /* Only go through if we didn't race with anybody else... */
34019 + if (likely(pte_same(*page_table, orig_pte))) {
34020 ++
34021 ++#ifdef CONFIG_PAX_SEGMEXEC
34022 ++ if (anon && pax_find_mirror_vma(vma))
34023 ++ BUG_ON(!trylock_page(page));
34024 ++#endif
34025 ++
34026 + flush_icache_page(vma, page);
34027 + entry = mk_pte(page, vma->vm_page_prot);
34028 + if (flags & FAULT_FLAG_WRITE)
34029 +@@ -2536,6 +2755,14 @@ static int __do_fault(struct mm_struct *
34030 +
34031 + /* no need to invalidate: a not-present page won't be cached */
34032 + update_mmu_cache(vma, address, entry);
34033 ++
34034 ++#ifdef CONFIG_PAX_SEGMEXEC
34035 ++ if (anon)
34036 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34037 ++ else
34038 ++ pax_mirror_file_pte(vma, address, page, ptl);
34039 ++#endif
34040 ++
34041 + } else {
34042 + mem_cgroup_uncharge_page(page);
34043 + if (anon)
34044 +@@ -2668,6 +2895,12 @@ static inline int handle_pte_fault(struc
34045 + if (write_access)
34046 + flush_tlb_page(vma, address);
34047 + }
34048 ++
34049 ++#ifdef CONFIG_PAX_SEGMEXEC
34050 ++ pax_mirror_pte(vma, address, pte, pmd, ptl);
34051 ++ return 0;
34052 ++#endif
34053 ++
34054 + unlock:
34055 + pte_unmap_unlock(pte, ptl);
34056 + return 0;
34057 +@@ -2684,6 +2917,10 @@ int handle_mm_fault(struct mm_struct *mm
34058 + pmd_t *pmd;
34059 + pte_t *pte;
34060 +
34061 ++#ifdef CONFIG_PAX_SEGMEXEC
34062 ++ struct vm_area_struct *vma_m;
34063 ++#endif
34064 ++
34065 + __set_current_state(TASK_RUNNING);
34066 +
34067 + count_vm_event(PGFAULT);
34068 +@@ -2691,6 +2928,34 @@ int handle_mm_fault(struct mm_struct *mm
34069 + if (unlikely(is_vm_hugetlb_page(vma)))
34070 + return hugetlb_fault(mm, vma, address, write_access);
34071 +
34072 ++#ifdef CONFIG_PAX_SEGMEXEC
34073 ++ vma_m = pax_find_mirror_vma(vma);
34074 ++ if (vma_m) {
34075 ++ unsigned long address_m;
34076 ++ pgd_t *pgd_m;
34077 ++ pud_t *pud_m;
34078 ++ pmd_t *pmd_m;
34079 ++
34080 ++ if (vma->vm_start > vma_m->vm_start) {
34081 ++ address_m = address;
34082 ++ address -= SEGMEXEC_TASK_SIZE;
34083 ++ vma = vma_m;
34084 ++ } else
34085 ++ address_m = address + SEGMEXEC_TASK_SIZE;
34086 ++
34087 ++ pgd_m = pgd_offset(mm, address_m);
34088 ++ pud_m = pud_alloc(mm, pgd_m, address_m);
34089 ++ if (!pud_m)
34090 ++ return VM_FAULT_OOM;
34091 ++ pmd_m = pmd_alloc(mm, pud_m, address_m);
34092 ++ if (!pmd_m)
34093 ++ return VM_FAULT_OOM;
34094 ++ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
34095 ++ return VM_FAULT_OOM;
34096 ++ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
34097 ++ }
34098 ++#endif
34099 ++
34100 + pgd = pgd_offset(mm, address);
34101 + pud = pud_alloc(mm, pgd, address);
34102 + if (!pud)
34103 +@@ -2798,7 +3063,7 @@ static int __init gate_vma_init(void)
34104 + gate_vma.vm_start = FIXADDR_USER_START;
34105 + gate_vma.vm_end = FIXADDR_USER_END;
34106 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34107 +- gate_vma.vm_page_prot = __P101;
34108 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34109 + /*
34110 + * Make sure the vDSO gets into every core dump.
34111 + * Dumping its contents makes post-mortem fully interpretable later
34112 +diff -urNp linux-2.6.27.10/mm/mempolicy.c linux-2.6.27.10/mm/mempolicy.c
34113 +--- linux-2.6.27.10/mm/mempolicy.c 2008-11-07 12:55:34.000000000 -0500
34114 ++++ linux-2.6.27.10/mm/mempolicy.c 2008-11-18 03:38:45.000000000 -0500
34115 +@@ -555,6 +555,10 @@ static int mbind_range(struct vm_area_st
34116 + struct vm_area_struct *next;
34117 + int err;
34118 +
34119 ++#ifdef CONFIG_PAX_SEGMEXEC
34120 ++ struct vm_area_struct *vma_m;
34121 ++#endif
34122 ++
34123 + err = 0;
34124 + for (; vma && vma->vm_start < end; vma = next) {
34125 + next = vma->vm_next;
34126 +@@ -566,6 +570,16 @@ static int mbind_range(struct vm_area_st
34127 + err = policy_vma(vma, new);
34128 + if (err)
34129 + break;
34130 ++
34131 ++#ifdef CONFIG_PAX_SEGMEXEC
34132 ++ vma_m = pax_find_mirror_vma(vma);
34133 ++ if (vma_m) {
34134 ++ err = policy_vma(vma_m, new);
34135 ++ if (err)
34136 ++ break;
34137 ++ }
34138 ++#endif
34139 ++
34140 + }
34141 + return err;
34142 + }
34143 +@@ -951,6 +965,17 @@ static long do_mbind(unsigned long start
34144 +
34145 + if (end < start)
34146 + return -EINVAL;
34147 ++
34148 ++#ifdef CONFIG_PAX_SEGMEXEC
34149 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
34150 ++ if (end > SEGMEXEC_TASK_SIZE)
34151 ++ return -EINVAL;
34152 ++ } else
34153 ++#endif
34154 ++
34155 ++ if (end > TASK_SIZE)
34156 ++ return -EINVAL;
34157 ++
34158 + if (end == start)
34159 + return 0;
34160 +
34161 +diff -urNp linux-2.6.27.10/mm/mlock.c linux-2.6.27.10/mm/mlock.c
34162 +--- linux-2.6.27.10/mm/mlock.c 2008-11-07 12:55:34.000000000 -0500
34163 ++++ linux-2.6.27.10/mm/mlock.c 2008-11-18 03:38:45.000000000 -0500
34164 +@@ -12,6 +12,7 @@
34165 + #include <linux/syscalls.h>
34166 + #include <linux/sched.h>
34167 + #include <linux/module.h>
34168 ++#include <linux/grsecurity.h>
34169 +
34170 + int can_do_mlock(void)
34171 + {
34172 +@@ -93,6 +94,17 @@ static int do_mlock(unsigned long start,
34173 + return -EINVAL;
34174 + if (end == start)
34175 + return 0;
34176 ++
34177 ++#ifdef CONFIG_PAX_SEGMEXEC
34178 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
34179 ++ if (end > SEGMEXEC_TASK_SIZE)
34180 ++ return -EINVAL;
34181 ++ } else
34182 ++#endif
34183 ++
34184 ++ if (end > TASK_SIZE)
34185 ++ return -EINVAL;
34186 ++
34187 + vma = find_vma_prev(current->mm, start, &prev);
34188 + if (!vma || vma->vm_start > start)
34189 + return -ENOMEM;
34190 +@@ -150,6 +162,7 @@ asmlinkage long sys_mlock(unsigned long
34191 + lock_limit >>= PAGE_SHIFT;
34192 +
34193 + /* check against resource limits */
34194 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
34195 + if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
34196 + error = do_mlock(start, len, 1);
34197 + up_write(&current->mm->mmap_sem);
34198 +@@ -171,10 +184,10 @@ asmlinkage long sys_munlock(unsigned lon
34199 + static int do_mlockall(int flags)
34200 + {
34201 + struct vm_area_struct * vma, * prev = NULL;
34202 +- unsigned int def_flags = 0;
34203 ++ unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED;
34204 +
34205 + if (flags & MCL_FUTURE)
34206 +- def_flags = VM_LOCKED;
34207 ++ def_flags |= VM_LOCKED;
34208 + current->mm->def_flags = def_flags;
34209 + if (flags == MCL_FUTURE)
34210 + goto out;
34211 +@@ -182,6 +195,12 @@ static int do_mlockall(int flags)
34212 + for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
34213 + unsigned int newflags;
34214 +
34215 ++#ifdef CONFIG_PAX_SEGMEXEC
34216 ++ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
34217 ++ break;
34218 ++#endif
34219 ++
34220 ++ BUG_ON(vma->vm_end > TASK_SIZE);
34221 + newflags = vma->vm_flags | VM_LOCKED;
34222 + if (!(flags & MCL_CURRENT))
34223 + newflags &= ~VM_LOCKED;
34224 +@@ -211,6 +230,7 @@ asmlinkage long sys_mlockall(int flags)
34225 + lock_limit >>= PAGE_SHIFT;
34226 +
34227 + ret = -ENOMEM;
34228 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1);
34229 + if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
34230 + capable(CAP_IPC_LOCK))
34231 + ret = do_mlockall(flags);
34232 +diff -urNp linux-2.6.27.10/mm/mmap.c linux-2.6.27.10/mm/mmap.c
34233 +--- linux-2.6.27.10/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
34234 ++++ linux-2.6.27.10/mm/mmap.c 2008-12-21 00:44:29.000000000 -0500
34235 +@@ -27,6 +27,7 @@
34236 + #include <linux/mempolicy.h>
34237 + #include <linux/rmap.h>
34238 + #include <linux/mmu_notifier.h>
34239 ++#include <linux/grsecurity.h>
34240 +
34241 + #include <asm/uaccess.h>
34242 + #include <asm/cacheflush.h>
34243 +@@ -43,6 +44,16 @@
34244 + #define arch_rebalance_pgtables(addr, len) (addr)
34245 + #endif
34246 +
34247 ++static inline void verify_mm_writelocked(struct mm_struct *mm)
34248 ++{
34249 ++#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
34250 ++ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
34251 ++ up_read(&mm->mmap_sem);
34252 ++ BUG();
34253 ++ }
34254 ++#endif
34255 ++}
34256 ++
34257 + static void unmap_region(struct mm_struct *mm,
34258 + struct vm_area_struct *vma, struct vm_area_struct *prev,
34259 + unsigned long start, unsigned long end);
34260 +@@ -68,16 +79,25 @@ static void unmap_region(struct mm_struc
34261 + * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
34262 + *
34263 + */
34264 +-pgprot_t protection_map[16] = {
34265 ++pgprot_t protection_map[16] __read_only = {
34266 + __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
34267 + __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
34268 + };
34269 +
34270 + pgprot_t vm_get_page_prot(unsigned long vm_flags)
34271 + {
34272 +- return __pgprot(pgprot_val(protection_map[vm_flags &
34273 ++ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
34274 + (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
34275 + pgprot_val(arch_vm_get_page_prot(vm_flags)));
34276 ++
34277 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34278 ++ if (!nx_enabled &&
34279 ++ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
34280 ++ (vm_flags & (VM_READ | VM_WRITE)))
34281 ++ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
34282 ++#endif
34283 ++
34284 ++ return prot;
34285 + }
34286 + EXPORT_SYMBOL(vm_get_page_prot);
34287 +
34288 +@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
34289 + struct vm_area_struct *next = vma->vm_next;
34290 +
34291 + might_sleep();
34292 ++ BUG_ON(vma->vm_mirror);
34293 + if (vma->vm_ops && vma->vm_ops->close)
34294 + vma->vm_ops->close(vma);
34295 + if (vma->vm_file) {
34296 +@@ -268,6 +289,7 @@ asmlinkage unsigned long sys_brk(unsigne
34297 + * not page aligned -Ram Gupta
34298 + */
34299 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
34300 ++ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
34301 + if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
34302 + (mm->end_data - mm->start_data) > rlim)
34303 + goto out;
34304 +@@ -697,6 +719,12 @@ static int
34305 + can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
34306 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34307 + {
34308 ++
34309 ++#ifdef CONFIG_PAX_SEGMEXEC
34310 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
34311 ++ return 0;
34312 ++#endif
34313 ++
34314 + if (is_mergeable_vma(vma, file, vm_flags) &&
34315 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34316 + if (vma->vm_pgoff == vm_pgoff)
34317 +@@ -716,6 +744,12 @@ static int
34318 + can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
34319 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34320 + {
34321 ++
34322 ++#ifdef CONFIG_PAX_SEGMEXEC
34323 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
34324 ++ return 0;
34325 ++#endif
34326 ++
34327 + if (is_mergeable_vma(vma, file, vm_flags) &&
34328 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34329 + pgoff_t vm_pglen;
34330 +@@ -758,12 +792,19 @@ can_vma_merge_after(struct vm_area_struc
34331 + struct vm_area_struct *vma_merge(struct mm_struct *mm,
34332 + struct vm_area_struct *prev, unsigned long addr,
34333 + unsigned long end, unsigned long vm_flags,
34334 +- struct anon_vma *anon_vma, struct file *file,
34335 ++ struct anon_vma *anon_vma, struct file *file,
34336 + pgoff_t pgoff, struct mempolicy *policy)
34337 + {
34338 + pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
34339 + struct vm_area_struct *area, *next;
34340 +
34341 ++#ifdef CONFIG_PAX_SEGMEXEC
34342 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
34343 ++ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
34344 ++
34345 ++ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
34346 ++#endif
34347 ++
34348 + /*
34349 + * We later require that vma->vm_flags == vm_flags,
34350 + * so this tests vma->vm_flags & VM_SPECIAL, too.
34351 +@@ -779,6 +820,15 @@ struct vm_area_struct *vma_merge(struct
34352 + if (next && next->vm_end == end) /* cases 6, 7, 8 */
34353 + next = next->vm_next;
34354 +
34355 ++#ifdef CONFIG_PAX_SEGMEXEC
34356 ++ if (prev)
34357 ++ prev_m = pax_find_mirror_vma(prev);
34358 ++ if (area)
34359 ++ area_m = pax_find_mirror_vma(area);
34360 ++ if (next)
34361 ++ next_m = pax_find_mirror_vma(next);
34362 ++#endif
34363 ++
34364 + /*
34365 + * Can it merge with the predecessor?
34366 + */
34367 +@@ -798,9 +848,24 @@ struct vm_area_struct *vma_merge(struct
34368 + /* cases 1, 6 */
34369 + vma_adjust(prev, prev->vm_start,
34370 + next->vm_end, prev->vm_pgoff, NULL);
34371 +- } else /* cases 2, 5, 7 */
34372 ++
34373 ++#ifdef CONFIG_PAX_SEGMEXEC
34374 ++ if (prev_m)
34375 ++ vma_adjust(prev_m, prev_m->vm_start,
34376 ++ next_m->vm_end, prev_m->vm_pgoff, NULL);
34377 ++#endif
34378 ++
34379 ++ } else { /* cases 2, 5, 7 */
34380 + vma_adjust(prev, prev->vm_start,
34381 + end, prev->vm_pgoff, NULL);
34382 ++
34383 ++#ifdef CONFIG_PAX_SEGMEXEC
34384 ++ if (prev_m)
34385 ++ vma_adjust(prev_m, prev_m->vm_start,
34386 ++ end_m, prev_m->vm_pgoff, NULL);
34387 ++#endif
34388 ++
34389 ++ }
34390 + return prev;
34391 + }
34392 +
34393 +@@ -811,12 +876,27 @@ struct vm_area_struct *vma_merge(struct
34394 + mpol_equal(policy, vma_policy(next)) &&
34395 + can_vma_merge_before(next, vm_flags,
34396 + anon_vma, file, pgoff+pglen)) {
34397 +- if (prev && addr < prev->vm_end) /* case 4 */
34398 ++ if (prev && addr < prev->vm_end) { /* case 4 */
34399 + vma_adjust(prev, prev->vm_start,
34400 + addr, prev->vm_pgoff, NULL);
34401 +- else /* cases 3, 8 */
34402 ++
34403 ++#ifdef CONFIG_PAX_SEGMEXEC
34404 ++ if (prev_m)
34405 ++ vma_adjust(prev_m, prev_m->vm_start,
34406 ++ addr_m, prev_m->vm_pgoff, NULL);
34407 ++#endif
34408 ++
34409 ++ } else { /* cases 3, 8 */
34410 + vma_adjust(area, addr, next->vm_end,
34411 + next->vm_pgoff - pglen, NULL);
34412 ++
34413 ++#ifdef CONFIG_PAX_SEGMEXEC
34414 ++ if (area_m)
34415 ++ vma_adjust(area_m, addr_m, next_m->vm_end,
34416 ++ next_m->vm_pgoff - pglen, NULL);
34417 ++#endif
34418 ++
34419 ++ }
34420 + return area;
34421 + }
34422 +
34423 +@@ -891,14 +971,11 @@ none:
34424 + void vm_stat_account(struct mm_struct *mm, unsigned long flags,
34425 + struct file *file, long pages)
34426 + {
34427 +- const unsigned long stack_flags
34428 +- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
34429 +-
34430 + if (file) {
34431 + mm->shared_vm += pages;
34432 + if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
34433 + mm->exec_vm += pages;
34434 +- } else if (flags & stack_flags)
34435 ++ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
34436 + mm->stack_vm += pages;
34437 + if (flags & (VM_RESERVED|VM_IO))
34438 + mm->reserved_vm += pages;
34439 +@@ -926,7 +1003,7 @@ unsigned long do_mmap_pgoff(struct file
34440 + * (the exception is when the underlying filesystem is noexec
34441 + * mounted, in which case we dont add PROT_EXEC.)
34442 + */
34443 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
34444 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
34445 + if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
34446 + prot |= PROT_EXEC;
34447 +
34448 +@@ -936,15 +1013,15 @@ unsigned long do_mmap_pgoff(struct file
34449 + if (!(flags & MAP_FIXED))
34450 + addr = round_hint_to_min(addr);
34451 +
34452 +- error = arch_mmap_check(addr, len, flags);
34453 +- if (error)
34454 +- return error;
34455 +-
34456 + /* Careful about overflows.. */
34457 + len = PAGE_ALIGN(len);
34458 + if (!len || len > TASK_SIZE)
34459 + return -ENOMEM;
34460 +
34461 ++ error = arch_mmap_check(addr, len, flags);
34462 ++ if (error)
34463 ++ return error;
34464 ++
34465 + /* offset overflow? */
34466 + if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
34467 + return -EOVERFLOW;
34468 +@@ -956,7 +1033,7 @@ unsigned long do_mmap_pgoff(struct file
34469 + /* Obtain the address to map to. we verify (or select) it and ensure
34470 + * that it represents a valid section of the address space.
34471 + */
34472 +- addr = get_unmapped_area(file, addr, len, pgoff, flags);
34473 ++ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
34474 + if (addr & ~PAGE_MASK)
34475 + return addr;
34476 +
34477 +@@ -967,6 +1044,26 @@ unsigned long do_mmap_pgoff(struct file
34478 + vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
34479 + mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
34480 +
34481 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
34482 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
34483 ++
34484 ++#ifdef CONFIG_PAX_MPROTECT
34485 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
34486 ++ if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC)
34487 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
34488 ++ else
34489 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
34490 ++ }
34491 ++#endif
34492 ++
34493 ++ }
34494 ++#endif
34495 ++
34496 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34497 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
34498 ++ vm_flags &= ~VM_PAGEEXEC;
34499 ++#endif
34500 ++
34501 + if (flags & MAP_LOCKED) {
34502 + if (!can_do_mlock())
34503 + return -EPERM;
34504 +@@ -979,6 +1076,7 @@ unsigned long do_mmap_pgoff(struct file
34505 + locked += mm->locked_vm;
34506 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
34507 + lock_limit >>= PAGE_SHIFT;
34508 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34509 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
34510 + return -EAGAIN;
34511 + }
34512 +@@ -1051,6 +1149,9 @@ unsigned long do_mmap_pgoff(struct file
34513 + if (error)
34514 + return error;
34515 +
34516 ++ if (!gr_acl_handle_mmap(file, prot))
34517 ++ return -EACCES;
34518 ++
34519 + return mmap_region(file, addr, len, flags, vm_flags, pgoff,
34520 + accountable);
34521 + }
34522 +@@ -1064,10 +1165,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
34523 + */
34524 + int vma_wants_writenotify(struct vm_area_struct *vma)
34525 + {
34526 +- unsigned int vm_flags = vma->vm_flags;
34527 ++ unsigned long vm_flags = vma->vm_flags;
34528 +
34529 + /* If it was private or non-writable, the write bit is already clear */
34530 +- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
34531 ++ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
34532 + return 0;
34533 +
34534 + /* The backer wishes to know when pages are first written to? */
34535 +@@ -1101,14 +1202,24 @@ unsigned long mmap_region(struct file *f
34536 + unsigned long charged = 0;
34537 + struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
34538 +
34539 ++#ifdef CONFIG_PAX_SEGMEXEC
34540 ++ struct vm_area_struct *vma_m = NULL;
34541 ++#endif
34542 ++
34543 ++ /*
34544 ++ * mm->mmap_sem is required to protect against another thread
34545 ++ * changing the mappings in case we sleep.
34546 ++ */
34547 ++ verify_mm_writelocked(mm);
34548 ++
34549 + /* Clear old maps */
34550 + error = -ENOMEM;
34551 +-munmap_back:
34552 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34553 + if (vma && vma->vm_start < addr + len) {
34554 + if (do_munmap(mm, addr, len))
34555 + return -ENOMEM;
34556 +- goto munmap_back;
34557 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34558 ++ BUG_ON(vma && vma->vm_start < addr + len);
34559 + }
34560 +
34561 + /* Check against address space limit. */
34562 +@@ -1155,6 +1266,16 @@ munmap_back:
34563 + goto unacct_error;
34564 + }
34565 +
34566 ++#ifdef CONFIG_PAX_SEGMEXEC
34567 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
34568 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
34569 ++ if (!vma_m) {
34570 ++ error = -ENOMEM;
34571 ++ goto free_vma;
34572 ++ }
34573 ++ }
34574 ++#endif
34575 ++
34576 + vma->vm_mm = mm;
34577 + vma->vm_start = addr;
34578 + vma->vm_end = addr + len;
34579 +@@ -1177,6 +1298,19 @@ munmap_back:
34580 + error = file->f_op->mmap(file, vma);
34581 + if (error)
34582 + goto unmap_and_free_vma;
34583 ++
34584 ++#ifdef CONFIG_PAX_SEGMEXEC
34585 ++ if (vma_m && (vm_flags & VM_EXECUTABLE))
34586 ++ added_exe_file_vma(mm);
34587 ++#endif
34588 ++
34589 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34590 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
34591 ++ vma->vm_flags |= VM_PAGEEXEC;
34592 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
34593 ++ }
34594 ++#endif
34595 ++
34596 + if (vm_flags & VM_EXECUTABLE)
34597 + added_exe_file_vma(mm);
34598 + } else if (vm_flags & VM_SHARED) {
34599 +@@ -1209,12 +1343,29 @@ munmap_back:
34600 + vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) {
34601 + mpol_put(vma_policy(vma));
34602 + kmem_cache_free(vm_area_cachep, vma);
34603 ++ vma = NULL;
34604 + fput(file);
34605 ++
34606 ++#ifdef CONFIG_PAX_SEGMEXEC
34607 ++ if (vma_m) {
34608 ++ kmem_cache_free(vm_area_cachep, vma_m);
34609 ++
34610 ++ if (vm_flags & VM_EXECUTABLE)
34611 ++ removed_exe_file_vma(mm);
34612 ++ }
34613 ++#endif
34614 ++
34615 + if (vm_flags & VM_EXECUTABLE)
34616 + removed_exe_file_vma(mm);
34617 + } else {
34618 + vma_link(mm, vma, prev, rb_link, rb_parent);
34619 + file = vma->vm_file;
34620 ++
34621 ++#ifdef CONFIG_PAX_SEGMEXEC
34622 ++ if (vma_m)
34623 ++ pax_mirror_vma(vma_m, vma);
34624 ++#endif
34625 ++
34626 + }
34627 +
34628 + /* Once vma denies write, undo our temporary denial count */
34629 +@@ -1223,6 +1374,7 @@ munmap_back:
34630 + out:
34631 + mm->total_vm += len >> PAGE_SHIFT;
34632 + vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
34633 ++ track_exec_limit(mm, addr, addr + len, vm_flags);
34634 + if (vm_flags & VM_LOCKED) {
34635 + mm->locked_vm += len >> PAGE_SHIFT;
34636 + make_pages_present(addr, addr + len);
34637 +@@ -1241,6 +1393,12 @@ unmap_and_free_vma:
34638 + unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
34639 + charged = 0;
34640 + free_vma:
34641 ++
34642 ++#ifdef CONFIG_PAX_SEGMEXEC
34643 ++ if (vma_m)
34644 ++ kmem_cache_free(vm_area_cachep, vma_m);
34645 ++#endif
34646 ++
34647 + kmem_cache_free(vm_area_cachep, vma);
34648 + unacct_error:
34649 + if (charged)
34650 +@@ -1274,6 +1432,10 @@ arch_get_unmapped_area(struct file *filp
34651 + if (flags & MAP_FIXED)
34652 + return addr;
34653 +
34654 ++#ifdef CONFIG_PAX_RANDMMAP
34655 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34656 ++#endif
34657 ++
34658 + if (addr) {
34659 + addr = PAGE_ALIGN(addr);
34660 + vma = find_vma(mm, addr);
34661 +@@ -1282,10 +1444,10 @@ arch_get_unmapped_area(struct file *filp
34662 + return addr;
34663 + }
34664 + if (len > mm->cached_hole_size) {
34665 +- start_addr = addr = mm->free_area_cache;
34666 ++ start_addr = addr = mm->free_area_cache;
34667 + } else {
34668 +- start_addr = addr = TASK_UNMAPPED_BASE;
34669 +- mm->cached_hole_size = 0;
34670 ++ start_addr = addr = mm->mmap_base;
34671 ++ mm->cached_hole_size = 0;
34672 + }
34673 +
34674 + full_search:
34675 +@@ -1296,9 +1458,8 @@ full_search:
34676 + * Start a new search - just in case we missed
34677 + * some holes.
34678 + */
34679 +- if (start_addr != TASK_UNMAPPED_BASE) {
34680 +- addr = TASK_UNMAPPED_BASE;
34681 +- start_addr = addr;
34682 ++ if (start_addr != mm->mmap_base) {
34683 ++ start_addr = addr = mm->mmap_base;
34684 + mm->cached_hole_size = 0;
34685 + goto full_search;
34686 + }
34687 +@@ -1320,10 +1481,16 @@ full_search:
34688 +
34689 + void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
34690 + {
34691 ++
34692 ++#ifdef CONFIG_PAX_SEGMEXEC
34693 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34694 ++ return;
34695 ++#endif
34696 ++
34697 + /*
34698 + * Is this a new hole at the lowest possible address?
34699 + */
34700 +- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
34701 ++ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
34702 + mm->free_area_cache = addr;
34703 + mm->cached_hole_size = ~0UL;
34704 + }
34705 +@@ -1341,7 +1508,7 @@ arch_get_unmapped_area_topdown(struct fi
34706 + {
34707 + struct vm_area_struct *vma;
34708 + struct mm_struct *mm = current->mm;
34709 +- unsigned long addr = addr0;
34710 ++ unsigned long base = mm->mmap_base, addr = addr0;
34711 +
34712 + /* requested length too big for entire address space */
34713 + if (len > TASK_SIZE)
34714 +@@ -1350,6 +1517,10 @@ arch_get_unmapped_area_topdown(struct fi
34715 + if (flags & MAP_FIXED)
34716 + return addr;
34717 +
34718 ++#ifdef CONFIG_PAX_RANDMMAP
34719 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34720 ++#endif
34721 ++
34722 + /* requesting a specific address */
34723 + if (addr) {
34724 + addr = PAGE_ALIGN(addr);
34725 +@@ -1407,13 +1578,21 @@ bottomup:
34726 + * can happen with large stack limits and large mmap()
34727 + * allocations.
34728 + */
34729 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
34730 ++
34731 ++#ifdef CONFIG_PAX_RANDMMAP
34732 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
34733 ++ mm->mmap_base += mm->delta_mmap;
34734 ++#endif
34735 ++
34736 ++ mm->free_area_cache = mm->mmap_base;
34737 + mm->cached_hole_size = ~0UL;
34738 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
34739 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
34740 + /*
34741 + * Restore the topdown base:
34742 + */
34743 +- mm->free_area_cache = mm->mmap_base;
34744 ++ mm->mmap_base = base;
34745 ++ mm->free_area_cache = base;
34746 + mm->cached_hole_size = ~0UL;
34747 +
34748 + return addr;
34749 +@@ -1422,6 +1601,12 @@ bottomup:
34750 +
34751 + void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
34752 + {
34753 ++
34754 ++#ifdef CONFIG_PAX_SEGMEXEC
34755 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34756 ++ return;
34757 ++#endif
34758 ++
34759 + /*
34760 + * Is this a new hole at the highest possible address?
34761 + */
34762 +@@ -1429,8 +1614,10 @@ void arch_unmap_area_topdown(struct mm_s
34763 + mm->free_area_cache = addr;
34764 +
34765 + /* dont allow allocations above current base */
34766 +- if (mm->free_area_cache > mm->mmap_base)
34767 ++ if (mm->free_area_cache > mm->mmap_base) {
34768 + mm->free_area_cache = mm->mmap_base;
34769 ++ mm->cached_hole_size = ~0UL;
34770 ++ }
34771 + }
34772 +
34773 + unsigned long
34774 +@@ -1530,6 +1717,27 @@ out:
34775 + return prev ? prev->vm_next : vma;
34776 + }
34777 +
34778 ++#ifdef CONFIG_PAX_SEGMEXEC
34779 ++struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
34780 ++{
34781 ++ struct vm_area_struct *vma_m;
34782 ++
34783 ++ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
34784 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
34785 ++ BUG_ON(vma->vm_mirror);
34786 ++ return NULL;
34787 ++ }
34788 ++ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
34789 ++ vma_m = vma->vm_mirror;
34790 ++ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
34791 ++ BUG_ON(vma->vm_file != vma_m->vm_file);
34792 ++ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
34793 ++ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
34794 ++ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
34795 ++ return vma_m;
34796 ++}
34797 ++#endif
34798 ++
34799 + /*
34800 + * Verify that the stack growth is acceptable and
34801 + * update accounting. This is shared with both the
34802 +@@ -1546,6 +1754,7 @@ static int acct_stack_growth(struct vm_a
34803 + return -ENOMEM;
34804 +
34805 + /* Stack limit test */
34806 ++ gr_learn_resource(current, RLIMIT_STACK, size, 1);
34807 + if (size > rlim[RLIMIT_STACK].rlim_cur)
34808 + return -ENOMEM;
34809 +
34810 +@@ -1555,6 +1764,7 @@ static int acct_stack_growth(struct vm_a
34811 + unsigned long limit;
34812 + locked = mm->locked_vm + grow;
34813 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
34814 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34815 + if (locked > limit && !capable(CAP_IPC_LOCK))
34816 + return -ENOMEM;
34817 + }
34818 +@@ -1569,7 +1779,7 @@ static int acct_stack_growth(struct vm_a
34819 + * Overcommit.. This must be the final test, as it will
34820 + * update security statistics.
34821 + */
34822 +- if (security_vm_enough_memory(grow))
34823 ++ if (security_vm_enough_memory_mm(mm, grow))
34824 + return -ENOMEM;
34825 +
34826 + /* Ok, everything looks good - let it rip */
34827 +@@ -1590,35 +1800,40 @@ static inline
34828 + #endif
34829 + int expand_upwards(struct vm_area_struct *vma, unsigned long address)
34830 + {
34831 +- int error;
34832 ++ int error, locknext;
34833 +
34834 + if (!(vma->vm_flags & VM_GROWSUP))
34835 + return -EFAULT;
34836 +
34837 ++ /* Also guard against wrapping around to address 0. */
34838 ++ if (address < PAGE_ALIGN(address+1))
34839 ++ address = PAGE_ALIGN(address+1);
34840 ++ else
34841 ++ return -ENOMEM;
34842 ++
34843 + /*
34844 + * We must make sure the anon_vma is allocated
34845 + * so that the anon_vma locking is not a noop.
34846 + */
34847 + if (unlikely(anon_vma_prepare(vma)))
34848 + return -ENOMEM;
34849 ++ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
34850 ++ if (locknext && unlikely(anon_vma_prepare(vma->vm_next)))
34851 ++ return -ENOMEM;
34852 + anon_vma_lock(vma);
34853 ++ if (locknext)
34854 ++ anon_vma_lock(vma->vm_next);
34855 +
34856 + /*
34857 + * vma->vm_start/vm_end cannot change under us because the caller
34858 + * is required to hold the mmap_sem in read mode. We need the
34859 +- * anon_vma lock to serialize against concurrent expand_stacks.
34860 +- * Also guard against wrapping around to address 0.
34861 ++ * anon_vma locks to serialize against concurrent expand_stacks
34862 ++ * and expand_upwards.
34863 + */
34864 +- if (address < PAGE_ALIGN(address+4))
34865 +- address = PAGE_ALIGN(address+4);
34866 +- else {
34867 +- anon_vma_unlock(vma);
34868 +- return -ENOMEM;
34869 +- }
34870 + error = 0;
34871 +
34872 + /* Somebody else might have raced and expanded it already */
34873 +- if (address > vma->vm_end) {
34874 ++ if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
34875 + unsigned long size, grow;
34876 +
34877 + size = address - vma->vm_start;
34878 +@@ -1628,6 +1843,8 @@ int expand_upwards(struct vm_area_struct
34879 + if (!error)
34880 + vma->vm_end = address;
34881 + }
34882 ++ if (locknext)
34883 ++ anon_vma_unlock(vma->vm_next);
34884 + anon_vma_unlock(vma);
34885 + return error;
34886 + }
34887 +@@ -1639,7 +1856,8 @@ int expand_upwards(struct vm_area_struct
34888 + static inline int expand_downwards(struct vm_area_struct *vma,
34889 + unsigned long address)
34890 + {
34891 +- int error;
34892 ++ int error, lockprev = 0;
34893 ++ struct vm_area_struct *prev = NULL;
34894 +
34895 + /*
34896 + * We must make sure the anon_vma is allocated
34897 +@@ -1653,6 +1871,15 @@ static inline int expand_downwards(struc
34898 + if (error)
34899 + return error;
34900 +
34901 ++#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
34902 ++ find_vma_prev(vma->vm_mm, address, &prev);
34903 ++ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
34904 ++#endif
34905 ++ if (lockprev && unlikely(anon_vma_prepare(prev)))
34906 ++ return -ENOMEM;
34907 ++ if (lockprev)
34908 ++ anon_vma_lock(prev);
34909 ++
34910 + anon_vma_lock(vma);
34911 +
34912 + /*
34913 +@@ -1662,9 +1889,15 @@ static inline int expand_downwards(struc
34914 + */
34915 +
34916 + /* Somebody else might have raced and expanded it already */
34917 +- if (address < vma->vm_start) {
34918 ++ if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
34919 + unsigned long size, grow;
34920 +
34921 ++#ifdef CONFIG_PAX_SEGMEXEC
34922 ++ struct vm_area_struct *vma_m;
34923 ++
34924 ++ vma_m = pax_find_mirror_vma(vma);
34925 ++#endif
34926 ++
34927 + size = vma->vm_end - address;
34928 + grow = (vma->vm_start - address) >> PAGE_SHIFT;
34929 +
34930 +@@ -1672,9 +1905,20 @@ static inline int expand_downwards(struc
34931 + if (!error) {
34932 + vma->vm_start = address;
34933 + vma->vm_pgoff -= grow;
34934 ++ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
34935 ++
34936 ++#ifdef CONFIG_PAX_SEGMEXEC
34937 ++ if (vma_m) {
34938 ++ vma_m->vm_start -= grow << PAGE_SHIFT;
34939 ++ vma_m->vm_pgoff -= grow;
34940 ++ }
34941 ++#endif
34942 ++
34943 + }
34944 + }
34945 + anon_vma_unlock(vma);
34946 ++ if (lockprev)
34947 ++ anon_vma_unlock(prev);
34948 + return error;
34949 + }
34950 +
34951 +@@ -1746,6 +1990,13 @@ static void remove_vma_list(struct mm_st
34952 + do {
34953 + long nrpages = vma_pages(vma);
34954 +
34955 ++#ifdef CONFIG_PAX_SEGMEXEC
34956 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
34957 ++ vma = remove_vma(vma);
34958 ++ continue;
34959 ++ }
34960 ++#endif
34961 ++
34962 + mm->total_vm -= nrpages;
34963 + if (vma->vm_flags & VM_LOCKED)
34964 + mm->locked_vm -= nrpages;
34965 +@@ -1792,6 +2043,16 @@ detach_vmas_to_be_unmapped(struct mm_str
34966 +
34967 + insertion_point = (prev ? &prev->vm_next : &mm->mmap);
34968 + do {
34969 ++
34970 ++#ifdef CONFIG_PAX_SEGMEXEC
34971 ++ if (vma->vm_mirror) {
34972 ++ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
34973 ++ vma->vm_mirror->vm_mirror = NULL;
34974 ++ vma->vm_mirror->vm_flags &= ~VM_EXEC;
34975 ++ vma->vm_mirror = NULL;
34976 ++ }
34977 ++#endif
34978 ++
34979 + rb_erase(&vma->vm_rb, &mm->mm_rb);
34980 + mm->map_count--;
34981 + tail_vma = vma;
34982 +@@ -1811,6 +2072,108 @@ detach_vmas_to_be_unmapped(struct mm_str
34983 + * Split a vma into two pieces at address 'addr', a new vma is allocated
34984 + * either for the first part or the tail.
34985 + */
34986 ++
34987 ++#ifdef CONFIG_PAX_SEGMEXEC
34988 ++int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
34989 ++ unsigned long addr, int new_below)
34990 ++{
34991 ++ struct mempolicy *pol;
34992 ++ struct vm_area_struct *new, *vma_m, *new_m = NULL;
34993 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
34994 ++
34995 ++ if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK))
34996 ++ return -EINVAL;
34997 ++
34998 ++ vma_m = pax_find_mirror_vma(vma);
34999 ++ if (vma_m) {
35000 ++ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
35001 ++ if (mm->map_count >= sysctl_max_map_count-1)
35002 ++ return -ENOMEM;
35003 ++ } else if (mm->map_count >= sysctl_max_map_count)
35004 ++ return -ENOMEM;
35005 ++
35006 ++ new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35007 ++ if (!new)
35008 ++ return -ENOMEM;
35009 ++
35010 ++ if (vma_m) {
35011 ++ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35012 ++ if (!new_m) {
35013 ++ kmem_cache_free(vm_area_cachep, new);
35014 ++ return -ENOMEM;
35015 ++ }
35016 ++ }
35017 ++
35018 ++ /* most fields are the same, copy all, and then fixup */
35019 ++ *new = *vma;
35020 ++
35021 ++ if (new_below)
35022 ++ new->vm_end = addr;
35023 ++ else {
35024 ++ new->vm_start = addr;
35025 ++ new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
35026 ++ }
35027 ++
35028 ++ if (vma_m) {
35029 ++ *new_m = *vma_m;
35030 ++ new_m->vm_mirror = new;
35031 ++ new->vm_mirror = new_m;
35032 ++
35033 ++ if (new_below)
35034 ++ new_m->vm_end = addr_m;
35035 ++ else {
35036 ++ new_m->vm_start = addr_m;
35037 ++ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
35038 ++ }
35039 ++ }
35040 ++
35041 ++ pol = mpol_dup(vma_policy(vma));
35042 ++ if (IS_ERR(pol)) {
35043 ++ if (new_m)
35044 ++ kmem_cache_free(vm_area_cachep, new_m);
35045 ++ kmem_cache_free(vm_area_cachep, new);
35046 ++ return PTR_ERR(pol);
35047 ++ }
35048 ++ vma_set_policy(new, pol);
35049 ++
35050 ++ if (new->vm_file) {
35051 ++ get_file(new->vm_file);
35052 ++ if (vma->vm_flags & VM_EXECUTABLE)
35053 ++ added_exe_file_vma(mm);
35054 ++ }
35055 ++
35056 ++ if (new->vm_ops && new->vm_ops->open)
35057 ++ new->vm_ops->open(new);
35058 ++
35059 ++ if (new_below)
35060 ++ vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff +
35061 ++ ((addr - new->vm_start) >> PAGE_SHIFT), new);
35062 ++ else
35063 ++ vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
35064 ++
35065 ++ if (vma_m) {
35066 ++ mpol_get(pol);
35067 ++ vma_set_policy(new_m, pol);
35068 ++
35069 ++ if (new_m->vm_file) {
35070 ++ get_file(new_m->vm_file);
35071 ++ if (vma_m->vm_flags & VM_EXECUTABLE)
35072 ++ added_exe_file_vma(mm);
35073 ++ }
35074 ++
35075 ++ if (new_m->vm_ops && new_m->vm_ops->open)
35076 ++ new_m->vm_ops->open(new_m);
35077 ++
35078 ++ if (new_below)
35079 ++ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
35080 ++ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
35081 ++ else
35082 ++ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
35083 ++ }
35084 ++
35085 ++ return 0;
35086 ++}
35087 ++#else
35088 + int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
35089 + unsigned long addr, int new_below)
35090 + {
35091 +@@ -1862,17 +2225,37 @@ int split_vma(struct mm_struct * mm, str
35092 +
35093 + return 0;
35094 + }
35095 ++#endif
35096 +
35097 + /* Munmap is split into 2 main parts -- this part which finds
35098 + * what needs doing, and the areas themselves, which do the
35099 + * work. This now handles partial unmappings.
35100 + * Jeremy Fitzhardinge <jeremy@××××.org>
35101 + */
35102 ++#ifdef CONFIG_PAX_SEGMEXEC
35103 + int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35104 + {
35105 ++ int ret = __do_munmap(mm, start, len);
35106 ++ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
35107 ++ return ret;
35108 ++
35109 ++ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
35110 ++}
35111 ++
35112 ++int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35113 ++#else
35114 ++int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35115 ++#endif
35116 ++{
35117 + unsigned long end;
35118 + struct vm_area_struct *vma, *prev, *last;
35119 +
35120 ++ /*
35121 ++ * mm->mmap_sem is required to protect against another thread
35122 ++ * changing the mappings in case we sleep.
35123 ++ */
35124 ++ verify_mm_writelocked(mm);
35125 ++
35126 + if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
35127 + return -EINVAL;
35128 +
35129 +@@ -1922,6 +2305,8 @@ int do_munmap(struct mm_struct *mm, unsi
35130 + /* Fix up all other VM information */
35131 + remove_vma_list(mm, vma);
35132 +
35133 ++ track_exec_limit(mm, start, end, 0UL);
35134 ++
35135 + return 0;
35136 + }
35137 +
35138 +@@ -1934,22 +2319,18 @@ asmlinkage long sys_munmap(unsigned long
35139 +
35140 + profile_munmap(addr);
35141 +
35142 ++#ifdef CONFIG_PAX_SEGMEXEC
35143 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
35144 ++ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
35145 ++ return -EINVAL;
35146 ++#endif
35147 ++
35148 + down_write(&mm->mmap_sem);
35149 + ret = do_munmap(mm, addr, len);
35150 + up_write(&mm->mmap_sem);
35151 + return ret;
35152 + }
35153 +
35154 +-static inline void verify_mm_writelocked(struct mm_struct *mm)
35155 +-{
35156 +-#ifdef CONFIG_DEBUG_VM
35157 +- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
35158 +- WARN_ON(1);
35159 +- up_read(&mm->mmap_sem);
35160 +- }
35161 +-#endif
35162 +-}
35163 +-
35164 + /*
35165 + * this is really a simplified "do_mmap". it only handles
35166 + * anonymous maps. eventually we may be able to do some
35167 +@@ -1963,6 +2344,11 @@ unsigned long do_brk(unsigned long addr,
35168 + struct rb_node ** rb_link, * rb_parent;
35169 + pgoff_t pgoff = addr >> PAGE_SHIFT;
35170 + int error;
35171 ++ unsigned long charged;
35172 ++
35173 ++#ifdef CONFIG_PAX_SEGMEXEC
35174 ++ struct vm_area_struct *vma_m = NULL;
35175 ++#endif
35176 +
35177 + len = PAGE_ALIGN(len);
35178 + if (!len)
35179 +@@ -1980,19 +2366,34 @@ unsigned long do_brk(unsigned long addr,
35180 +
35181 + flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
35182 +
35183 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
35184 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
35185 ++ flags &= ~VM_EXEC;
35186 ++
35187 ++#ifdef CONFIG_PAX_MPROTECT
35188 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
35189 ++ flags &= ~VM_MAYEXEC;
35190 ++#endif
35191 ++
35192 ++ }
35193 ++#endif
35194 ++
35195 + error = arch_mmap_check(addr, len, flags);
35196 + if (error)
35197 + return error;
35198 +
35199 ++ charged = len >> PAGE_SHIFT;
35200 ++
35201 + /*
35202 + * mlock MCL_FUTURE?
35203 + */
35204 + if (mm->def_flags & VM_LOCKED) {
35205 + unsigned long locked, lock_limit;
35206 +- locked = len >> PAGE_SHIFT;
35207 ++ locked = charged;
35208 + locked += mm->locked_vm;
35209 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
35210 + lock_limit >>= PAGE_SHIFT;
35211 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
35212 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
35213 + return -EAGAIN;
35214 + }
35215 +@@ -2006,22 +2407,22 @@ unsigned long do_brk(unsigned long addr,
35216 + /*
35217 + * Clear old maps. this also does some error checking for us
35218 + */
35219 +- munmap_back:
35220 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35221 + if (vma && vma->vm_start < addr + len) {
35222 + if (do_munmap(mm, addr, len))
35223 + return -ENOMEM;
35224 +- goto munmap_back;
35225 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35226 ++ BUG_ON(vma && vma->vm_start < addr + len);
35227 + }
35228 +
35229 + /* Check against address space limits *after* clearing old maps... */
35230 +- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
35231 ++ if (!may_expand_vm(mm, charged))
35232 + return -ENOMEM;
35233 +
35234 + if (mm->map_count > sysctl_max_map_count)
35235 + return -ENOMEM;
35236 +
35237 +- if (security_vm_enough_memory(len >> PAGE_SHIFT))
35238 ++ if (security_vm_enough_memory(charged))
35239 + return -ENOMEM;
35240 +
35241 + /* Can we just expand an old private anonymous mapping? */
35242 +@@ -2034,10 +2435,21 @@ unsigned long do_brk(unsigned long addr,
35243 + */
35244 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35245 + if (!vma) {
35246 +- vm_unacct_memory(len >> PAGE_SHIFT);
35247 ++ vm_unacct_memory(charged);
35248 + return -ENOMEM;
35249 + }
35250 +
35251 ++#ifdef CONFIG_PAX_SEGMEXEC
35252 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) {
35253 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35254 ++ if (!vma_m) {
35255 ++ kmem_cache_free(vm_area_cachep, vma);
35256 ++ vm_unacct_memory(charged);
35257 ++ return -ENOMEM;
35258 ++ }
35259 ++ }
35260 ++#endif
35261 ++
35262 + vma->vm_mm = mm;
35263 + vma->vm_start = addr;
35264 + vma->vm_end = addr + len;
35265 +@@ -2045,12 +2457,19 @@ unsigned long do_brk(unsigned long addr,
35266 + vma->vm_flags = flags;
35267 + vma->vm_page_prot = vm_get_page_prot(flags);
35268 + vma_link(mm, vma, prev, rb_link, rb_parent);
35269 ++
35270 ++#ifdef CONFIG_PAX_SEGMEXEC
35271 ++ if (vma_m)
35272 ++ pax_mirror_vma(vma_m, vma);
35273 ++#endif
35274 ++
35275 + out:
35276 +- mm->total_vm += len >> PAGE_SHIFT;
35277 ++ mm->total_vm += charged;
35278 + if (flags & VM_LOCKED) {
35279 +- mm->locked_vm += len >> PAGE_SHIFT;
35280 ++ mm->locked_vm += charged;
35281 + make_pages_present(addr, addr + len);
35282 + }
35283 ++ track_exec_limit(mm, addr, addr + len, flags);
35284 + return addr;
35285 + }
35286 +
35287 +@@ -2082,8 +2501,10 @@ void exit_mmap(struct mm_struct *mm)
35288 + * Walk the list again, actually closing and freeing it,
35289 + * with preemption enabled, without holding any MM locks.
35290 + */
35291 +- while (vma)
35292 ++ while (vma) {
35293 ++ vma->vm_mirror = NULL;
35294 + vma = remove_vma(vma);
35295 ++ }
35296 +
35297 + BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
35298 + }
35299 +@@ -2097,6 +2518,10 @@ int insert_vm_struct(struct mm_struct *
35300 + struct vm_area_struct * __vma, * prev;
35301 + struct rb_node ** rb_link, * rb_parent;
35302 +
35303 ++#ifdef CONFIG_PAX_SEGMEXEC
35304 ++ struct vm_area_struct *vma_m = NULL;
35305 ++#endif
35306 ++
35307 + /*
35308 + * The vm_pgoff of a purely anonymous vma should be irrelevant
35309 + * until its first write fault, when page's anon_vma and index
35310 +@@ -2119,7 +2544,22 @@ int insert_vm_struct(struct mm_struct *
35311 + if ((vma->vm_flags & VM_ACCOUNT) &&
35312 + security_vm_enough_memory_mm(mm, vma_pages(vma)))
35313 + return -ENOMEM;
35314 ++
35315 ++#ifdef CONFIG_PAX_SEGMEXEC
35316 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
35317 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35318 ++ if (!vma_m)
35319 ++ return -ENOMEM;
35320 ++ }
35321 ++#endif
35322 ++
35323 + vma_link(mm, vma, prev, rb_link, rb_parent);
35324 ++
35325 ++#ifdef CONFIG_PAX_SEGMEXEC
35326 ++ if (vma_m)
35327 ++ pax_mirror_vma(vma_m, vma);
35328 ++#endif
35329 ++
35330 + return 0;
35331 + }
35332 +
35333 +@@ -2137,6 +2577,8 @@ struct vm_area_struct *copy_vma(struct v
35334 + struct rb_node **rb_link, *rb_parent;
35335 + struct mempolicy *pol;
35336 +
35337 ++ BUG_ON(vma->vm_mirror);
35338 ++
35339 + /*
35340 + * If anonymous vma has not yet been faulted, update new pgoff
35341 + * to match new location, to increase its chance of merging.
35342 +@@ -2180,6 +2622,35 @@ struct vm_area_struct *copy_vma(struct v
35343 + return new_vma;
35344 + }
35345 +
35346 ++#ifdef CONFIG_PAX_SEGMEXEC
35347 ++void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
35348 ++{
35349 ++ struct vm_area_struct *prev_m;
35350 ++ struct rb_node **rb_link_m, *rb_parent_m;
35351 ++ struct mempolicy *pol_m;
35352 ++
35353 ++ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
35354 ++ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
35355 ++ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
35356 ++ *vma_m = *vma;
35357 ++ pol_m = vma_policy(vma_m);
35358 ++ mpol_get(pol_m);
35359 ++ vma_set_policy(vma_m, pol_m);
35360 ++ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
35361 ++ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
35362 ++ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
35363 ++ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
35364 ++ if (vma_m->vm_file)
35365 ++ get_file(vma_m->vm_file);
35366 ++ if (vma_m->vm_ops && vma_m->vm_ops->open)
35367 ++ vma_m->vm_ops->open(vma_m);
35368 ++ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
35369 ++ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
35370 ++ vma_m->vm_mirror = vma;
35371 ++ vma->vm_mirror = vma_m;
35372 ++}
35373 ++#endif
35374 ++
35375 + /*
35376 + * Return true if the calling process may expand its vm space by the passed
35377 + * number of pages
35378 +@@ -2190,7 +2661,7 @@ int may_expand_vm(struct mm_struct *mm,
35379 + unsigned long lim;
35380 +
35381 + lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
35382 +-
35383 ++ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
35384 + if (cur + npages > lim)
35385 + return 0;
35386 + return 1;
35387 +@@ -2259,6 +2730,15 @@ int install_special_mapping(struct mm_st
35388 + vma->vm_start = addr;
35389 + vma->vm_end = addr + len;
35390 +
35391 ++#ifdef CONFIG_PAX_MPROTECT
35392 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
35393 ++ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
35394 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
35395 ++ else
35396 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
35397 ++ }
35398 ++#endif
35399 ++
35400 + vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
35401 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
35402 +
35403 +diff -urNp linux-2.6.27.10/mm/mprotect.c linux-2.6.27.10/mm/mprotect.c
35404 +--- linux-2.6.27.10/mm/mprotect.c 2008-11-07 12:55:34.000000000 -0500
35405 ++++ linux-2.6.27.10/mm/mprotect.c 2008-12-21 00:45:45.000000000 -0500
35406 +@@ -22,10 +22,17 @@
35407 + #include <linux/swap.h>
35408 + #include <linux/swapops.h>
35409 + #include <linux/mmu_notifier.h>
35410 ++#include <linux/grsecurity.h>
35411 ++
35412 ++#ifdef CONFIG_PAX_MPROTECT
35413 ++#include <linux/elf.h>
35414 ++#endif
35415 ++
35416 + #include <asm/uaccess.h>
35417 + #include <asm/pgtable.h>
35418 + #include <asm/cacheflush.h>
35419 + #include <asm/tlbflush.h>
35420 ++#include <asm/mmu_context.h>
35421 +
35422 + #ifndef pgprot_modify
35423 + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
35424 +@@ -133,6 +140,48 @@ static void change_protection(struct vm_
35425 + flush_tlb_range(vma, start, end);
35426 + }
35427 +
35428 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35429 ++/* called while holding the mmap semaphor for writing except stack expansion */
35430 ++void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
35431 ++{
35432 ++ unsigned long oldlimit, newlimit = 0UL;
35433 ++
35434 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
35435 ++ return;
35436 ++
35437 ++ spin_lock(&mm->page_table_lock);
35438 ++ oldlimit = mm->context.user_cs_limit;
35439 ++ if ((prot & VM_EXEC) && oldlimit < end)
35440 ++ /* USER_CS limit moved up */
35441 ++ newlimit = end;
35442 ++ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
35443 ++ /* USER_CS limit moved down */
35444 ++ newlimit = start;
35445 ++
35446 ++ if (newlimit) {
35447 ++ mm->context.user_cs_limit = newlimit;
35448 ++
35449 ++#ifdef CONFIG_SMP
35450 ++ wmb();
35451 ++ cpus_clear(mm->context.cpu_user_cs_mask);
35452 ++ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
35453 ++#endif
35454 ++
35455 ++ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
35456 ++ }
35457 ++ spin_unlock(&mm->page_table_lock);
35458 ++ if (newlimit == end) {
35459 ++ struct vm_area_struct *vma = find_vma(mm, oldlimit);
35460 ++
35461 ++ for (; vma && vma->vm_start < end; vma = vma->vm_next)
35462 ++ if (is_vm_hugetlb_page(vma))
35463 ++ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
35464 ++ else
35465 ++ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
35466 ++ }
35467 ++}
35468 ++#endif
35469 ++
35470 + int
35471 + mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
35472 + unsigned long start, unsigned long end, unsigned long newflags)
35473 +@@ -145,6 +194,14 @@ mprotect_fixup(struct vm_area_struct *vm
35474 + int error;
35475 + int dirty_accountable = 0;
35476 +
35477 ++#ifdef CONFIG_PAX_SEGMEXEC
35478 ++ struct vm_area_struct *vma_m = NULL;
35479 ++ unsigned long start_m, end_m;
35480 ++
35481 ++ start_m = start + SEGMEXEC_TASK_SIZE;
35482 ++ end_m = end + SEGMEXEC_TASK_SIZE;
35483 ++#endif
35484 ++
35485 + if (newflags == oldflags) {
35486 + *pprev = vma;
35487 + return 0;
35488 +@@ -165,6 +222,38 @@ mprotect_fixup(struct vm_area_struct *vm
35489 + }
35490 + }
35491 +
35492 ++#ifdef CONFIG_PAX_SEGMEXEC
35493 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
35494 ++ if (start != vma->vm_start) {
35495 ++ error = split_vma(mm, vma, start, 1);
35496 ++ if (error)
35497 ++ goto fail;
35498 ++ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
35499 ++ *pprev = (*pprev)->vm_next;
35500 ++ }
35501 ++
35502 ++ if (end != vma->vm_end) {
35503 ++ error = split_vma(mm, vma, end, 0);
35504 ++ if (error)
35505 ++ goto fail;
35506 ++ }
35507 ++
35508 ++ if (pax_find_mirror_vma(vma)) {
35509 ++ error = __do_munmap(mm, start_m, end_m - start_m);
35510 ++ if (error)
35511 ++ goto fail;
35512 ++ } else {
35513 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35514 ++ if (!vma_m) {
35515 ++ error = -ENOMEM;
35516 ++ goto fail;
35517 ++ }
35518 ++ vma->vm_flags = newflags;
35519 ++ pax_mirror_vma(vma_m, vma);
35520 ++ }
35521 ++ }
35522 ++#endif
35523 ++
35524 + /*
35525 + * First try to merge with previous and/or next vma.
35526 + */
35527 +@@ -196,8 +285,14 @@ success:
35528 + * held in write mode.
35529 + */
35530 + vma->vm_flags = newflags;
35531 ++
35532 ++#ifdef CONFIG_PAX_MPROTECT
35533 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35534 ++ current->binfmt->handle_mprotect(vma, newflags);
35535 ++#endif
35536 ++
35537 + vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
35538 +- vm_get_page_prot(newflags));
35539 ++ vm_get_page_prot(vma->vm_flags));
35540 +
35541 + if (vma_wants_writenotify(vma)) {
35542 + vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
35543 +@@ -238,6 +333,17 @@ sys_mprotect(unsigned long start, size_t
35544 + end = start + len;
35545 + if (end <= start)
35546 + return -ENOMEM;
35547 ++
35548 ++#ifdef CONFIG_PAX_SEGMEXEC
35549 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35550 ++ if (end > SEGMEXEC_TASK_SIZE)
35551 ++ return -EINVAL;
35552 ++ } else
35553 ++#endif
35554 ++
35555 ++ if (end > TASK_SIZE)
35556 ++ return -EINVAL;
35557 ++
35558 + if (!arch_validate_prot(prot))
35559 + return -EINVAL;
35560 +
35561 +@@ -245,7 +351,7 @@ sys_mprotect(unsigned long start, size_t
35562 + /*
35563 + * Does the application expect PROT_READ to imply PROT_EXEC:
35564 + */
35565 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
35566 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
35567 + prot |= PROT_EXEC;
35568 +
35569 + vm_flags = calc_vm_prot_bits(prot);
35570 +@@ -277,6 +383,16 @@ sys_mprotect(unsigned long start, size_t
35571 + if (start > vma->vm_start)
35572 + prev = vma;
35573 +
35574 ++ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
35575 ++ error = -EACCES;
35576 ++ goto out;
35577 ++ }
35578 ++
35579 ++#ifdef CONFIG_PAX_MPROTECT
35580 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35581 ++ current->binfmt->handle_mprotect(vma, vm_flags);
35582 ++#endif
35583 ++
35584 + for (nstart = start ; ; ) {
35585 + unsigned long newflags;
35586 +
35587 +@@ -300,6 +416,9 @@ sys_mprotect(unsigned long start, size_t
35588 + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
35589 + if (error)
35590 + goto out;
35591 ++
35592 ++ track_exec_limit(current->mm, nstart, tmp, vm_flags);
35593 ++
35594 + nstart = tmp;
35595 +
35596 + if (nstart < prev->vm_end)
35597 +diff -urNp linux-2.6.27.10/mm/mremap.c linux-2.6.27.10/mm/mremap.c
35598 +--- linux-2.6.27.10/mm/mremap.c 2008-11-07 12:55:34.000000000 -0500
35599 ++++ linux-2.6.27.10/mm/mremap.c 2008-11-18 03:38:45.000000000 -0500
35600 +@@ -111,6 +111,12 @@ static void move_ptes(struct vm_area_str
35601 + continue;
35602 + pte = ptep_clear_flush(vma, old_addr, old_pte);
35603 + pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
35604 ++
35605 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35606 ++ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
35607 ++ pte = pte_exprotect(pte);
35608 ++#endif
35609 ++
35610 + set_pte_at(mm, new_addr, new_pte, pte);
35611 + }
35612 +
35613 +@@ -260,6 +266,7 @@ unsigned long do_mremap(unsigned long ad
35614 + struct vm_area_struct *vma;
35615 + unsigned long ret = -EINVAL;
35616 + unsigned long charged = 0;
35617 ++ unsigned long pax_task_size = TASK_SIZE;
35618 +
35619 + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
35620 + goto out;
35621 +@@ -278,6 +285,15 @@ unsigned long do_mremap(unsigned long ad
35622 + if (!new_len)
35623 + goto out;
35624 +
35625 ++#ifdef CONFIG_PAX_SEGMEXEC
35626 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
35627 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
35628 ++#endif
35629 ++
35630 ++ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
35631 ++ old_len > pax_task_size || addr > pax_task_size-old_len)
35632 ++ goto out;
35633 ++
35634 + /* new_addr is only valid if MREMAP_FIXED is specified */
35635 + if (flags & MREMAP_FIXED) {
35636 + if (new_addr & ~PAGE_MASK)
35637 +@@ -285,16 +301,13 @@ unsigned long do_mremap(unsigned long ad
35638 + if (!(flags & MREMAP_MAYMOVE))
35639 + goto out;
35640 +
35641 +- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
35642 ++ if (new_addr > pax_task_size - new_len)
35643 + goto out;
35644 +
35645 + /* Check if the location we're moving into overlaps the
35646 + * old location at all, and fail if it does.
35647 + */
35648 +- if ((new_addr <= addr) && (new_addr+new_len) > addr)
35649 +- goto out;
35650 +-
35651 +- if ((addr <= new_addr) && (addr+old_len) > new_addr)
35652 ++ if (addr + old_len > new_addr && new_addr + new_len > addr)
35653 + goto out;
35654 +
35655 + ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
35656 +@@ -332,6 +345,14 @@ unsigned long do_mremap(unsigned long ad
35657 + ret = -EINVAL;
35658 + goto out;
35659 + }
35660 ++
35661 ++#ifdef CONFIG_PAX_SEGMEXEC
35662 ++ if (pax_find_mirror_vma(vma)) {
35663 ++ ret = -EINVAL;
35664 ++ goto out;
35665 ++ }
35666 ++#endif
35667 ++
35668 + /* We can't remap across vm area boundaries */
35669 + if (old_len > vma->vm_end - addr)
35670 + goto out;
35671 +@@ -365,7 +386,7 @@ unsigned long do_mremap(unsigned long ad
35672 + if (old_len == vma->vm_end - addr &&
35673 + !((flags & MREMAP_FIXED) && (addr != new_addr)) &&
35674 + (old_len != new_len || !(flags & MREMAP_MAYMOVE))) {
35675 +- unsigned long max_addr = TASK_SIZE;
35676 ++ unsigned long max_addr = pax_task_size;
35677 + if (vma->vm_next)
35678 + max_addr = vma->vm_next->vm_start;
35679 + /* can we just expand the current mapping? */
35680 +@@ -383,6 +404,7 @@ unsigned long do_mremap(unsigned long ad
35681 + addr + new_len);
35682 + }
35683 + ret = addr;
35684 ++ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
35685 + goto out;
35686 + }
35687 + }
35688 +@@ -393,8 +415,8 @@ unsigned long do_mremap(unsigned long ad
35689 + */
35690 + ret = -ENOMEM;
35691 + if (flags & MREMAP_MAYMOVE) {
35692 ++ unsigned long map_flags = 0;
35693 + if (!(flags & MREMAP_FIXED)) {
35694 +- unsigned long map_flags = 0;
35695 + if (vma->vm_flags & VM_MAYSHARE)
35696 + map_flags |= MAP_SHARED;
35697 +
35698 +@@ -409,7 +431,12 @@ unsigned long do_mremap(unsigned long ad
35699 + if (ret)
35700 + goto out;
35701 + }
35702 ++ map_flags = vma->vm_flags;
35703 + ret = move_vma(vma, addr, old_len, new_len, new_addr);
35704 ++ if (!(ret & ~PAGE_MASK)) {
35705 ++ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
35706 ++ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
35707 ++ }
35708 + }
35709 + out:
35710 + if (ret & ~PAGE_MASK)
35711 +diff -urNp linux-2.6.27.10/mm/nommu.c linux-2.6.27.10/mm/nommu.c
35712 +--- linux-2.6.27.10/mm/nommu.c 2008-11-07 12:55:34.000000000 -0500
35713 ++++ linux-2.6.27.10/mm/nommu.c 2008-11-18 03:38:45.000000000 -0500
35714 +@@ -437,15 +437,6 @@ struct vm_area_struct *find_vma(struct m
35715 + }
35716 + EXPORT_SYMBOL(find_vma);
35717 +
35718 +-/*
35719 +- * find a VMA
35720 +- * - we don't extend stack VMAs under NOMMU conditions
35721 +- */
35722 +-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
35723 +-{
35724 +- return find_vma(mm, addr);
35725 +-}
35726 +-
35727 + int expand_stack(struct vm_area_struct *vma, unsigned long address)
35728 + {
35729 + return -ENOMEM;
35730 +diff -urNp linux-2.6.27.10/mm/page_alloc.c linux-2.6.27.10/mm/page_alloc.c
35731 +--- linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:12.000000000 -0500
35732 ++++ linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:22.000000000 -0500
35733 +@@ -515,9 +515,20 @@ static void free_pages_bulk(struct zone
35734 +
35735 + static void free_one_page(struct zone *zone, struct page *page, int order)
35736 + {
35737 ++
35738 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35739 ++ unsigned long index = 1UL << order;
35740 ++#endif
35741 ++
35742 + spin_lock(&zone->lock);
35743 + zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
35744 + zone->pages_scanned = 0;
35745 ++
35746 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35747 ++ for (; index; --index)
35748 ++ sanitize_highpage(page + index - 1);
35749 ++#endif
35750 ++
35751 + __free_one_page(page, zone, order);
35752 + spin_unlock(&zone->lock);
35753 + }
35754 +@@ -635,8 +646,10 @@ static int prep_new_page(struct page *pa
35755 + arch_alloc_page(page, order);
35756 + kernel_map_pages(page, 1 << order, 1);
35757 +
35758 ++#ifndef CONFIG_PAX_MEMORY_SANITIZE
35759 + if (gfp_flags & __GFP_ZERO)
35760 + prep_zero_page(page, order, gfp_flags);
35761 ++#endif
35762 +
35763 + if (order && (gfp_flags & __GFP_COMP))
35764 + prep_compound_page(page, order);
35765 +@@ -1009,6 +1022,11 @@ static void free_hot_cold_page(struct pa
35766 + list_add(&page->lru, &pcp->list);
35767 + set_page_private(page, get_pageblock_migratetype(page));
35768 + pcp->count++;
35769 ++
35770 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35771 ++ sanitize_highpage(page);
35772 ++#endif
35773 ++
35774 + if (pcp->count >= pcp->high) {
35775 + free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
35776 + pcp->count -= pcp->batch;
35777 +diff -urNp linux-2.6.27.10/mm/rmap.c linux-2.6.27.10/mm/rmap.c
35778 +--- linux-2.6.27.10/mm/rmap.c 2008-11-07 12:55:34.000000000 -0500
35779 ++++ linux-2.6.27.10/mm/rmap.c 2008-11-18 03:38:45.000000000 -0500
35780 +@@ -91,6 +91,10 @@ int anon_vma_prepare(struct vm_area_stru
35781 + struct mm_struct *mm = vma->vm_mm;
35782 + struct anon_vma *allocated;
35783 +
35784 ++#ifdef CONFIG_PAX_SEGMEXEC
35785 ++ struct vm_area_struct *vma_m;
35786 ++#endif
35787 ++
35788 + anon_vma = find_mergeable_anon_vma(vma);
35789 + allocated = NULL;
35790 + if (!anon_vma) {
35791 +@@ -104,6 +108,15 @@ int anon_vma_prepare(struct vm_area_stru
35792 + /* page_table_lock to protect against threads */
35793 + spin_lock(&mm->page_table_lock);
35794 + if (likely(!vma->anon_vma)) {
35795 ++
35796 ++#ifdef CONFIG_PAX_SEGMEXEC
35797 ++ vma_m = pax_find_mirror_vma(vma);
35798 ++ if (vma_m) {
35799 ++ vma_m->anon_vma = anon_vma;
35800 ++ __anon_vma_link(vma_m);
35801 ++ }
35802 ++#endif
35803 ++
35804 + vma->anon_vma = anon_vma;
35805 + list_add_tail(&vma->anon_vma_node, &anon_vma->head);
35806 + allocated = NULL;
35807 +diff -urNp linux-2.6.27.10/mm/shmem.c linux-2.6.27.10/mm/shmem.c
35808 +--- linux-2.6.27.10/mm/shmem.c 2008-11-07 12:55:34.000000000 -0500
35809 ++++ linux-2.6.27.10/mm/shmem.c 2008-11-18 03:38:45.000000000 -0500
35810 +@@ -2483,7 +2483,7 @@ static struct file_system_type tmpfs_fs_
35811 + .get_sb = shmem_get_sb,
35812 + .kill_sb = kill_litter_super,
35813 + };
35814 +-static struct vfsmount *shm_mnt;
35815 ++struct vfsmount *shm_mnt;
35816 +
35817 + static int __init init_tmpfs(void)
35818 + {
35819 +diff -urNp linux-2.6.27.10/mm/slab.c linux-2.6.27.10/mm/slab.c
35820 +--- linux-2.6.27.10/mm/slab.c 2008-11-07 12:55:34.000000000 -0500
35821 ++++ linux-2.6.27.10/mm/slab.c 2008-11-18 03:38:45.000000000 -0500
35822 +@@ -304,7 +304,7 @@ struct kmem_list3 {
35823 + * Need this for bootstrapping a per node allocator.
35824 + */
35825 + #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
35826 +-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
35827 ++struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
35828 + #define CACHE_CACHE 0
35829 + #define SIZE_AC MAX_NUMNODES
35830 + #define SIZE_L3 (2 * MAX_NUMNODES)
35831 +@@ -653,14 +653,14 @@ struct cache_names {
35832 + static struct cache_names __initdata cache_names[] = {
35833 + #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
35834 + #include <linux/kmalloc_sizes.h>
35835 +- {NULL,}
35836 ++ {NULL, NULL}
35837 + #undef CACHE
35838 + };
35839 +
35840 + static struct arraycache_init initarray_cache __initdata =
35841 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35842 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35843 + static struct arraycache_init initarray_generic =
35844 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35845 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35846 +
35847 + /* internal cache of cache description objs */
35848 + static struct kmem_cache cache_cache = {
35849 +@@ -2996,7 +2996,7 @@ retry:
35850 + * there must be at least one object available for
35851 + * allocation.
35852 + */
35853 +- BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num);
35854 ++ BUG_ON(slabp->inuse >= cachep->num);
35855 +
35856 + while (slabp->inuse < cachep->num && batchcount--) {
35857 + STATS_INC_ALLOCED(cachep);
35858 +diff -urNp linux-2.6.27.10/mm/tiny-shmem.c linux-2.6.27.10/mm/tiny-shmem.c
35859 +--- linux-2.6.27.10/mm/tiny-shmem.c 2008-11-07 12:55:34.000000000 -0500
35860 ++++ linux-2.6.27.10/mm/tiny-shmem.c 2008-11-18 03:38:45.000000000 -0500
35861 +@@ -26,7 +26,7 @@ static struct file_system_type tmpfs_fs_
35862 + .kill_sb = kill_litter_super,
35863 + };
35864 +
35865 +-static struct vfsmount *shm_mnt;
35866 ++struct vfsmount *shm_mnt;
35867 +
35868 + static int __init init_tmpfs(void)
35869 + {
35870 +diff -urNp linux-2.6.27.10/mm/util.c linux-2.6.27.10/mm/util.c
35871 +--- linux-2.6.27.10/mm/util.c 2008-11-07 12:55:34.000000000 -0500
35872 ++++ linux-2.6.27.10/mm/util.c 2008-11-18 03:38:45.000000000 -0500
35873 +@@ -167,6 +167,12 @@ EXPORT_SYMBOL(strndup_user);
35874 + void arch_pick_mmap_layout(struct mm_struct *mm)
35875 + {
35876 + mm->mmap_base = TASK_UNMAPPED_BASE;
35877 ++
35878 ++#ifdef CONFIG_PAX_RANDMMAP
35879 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
35880 ++ mm->mmap_base += mm->delta_mmap;
35881 ++#endif
35882 ++
35883 + mm->get_unmapped_area = arch_get_unmapped_area;
35884 + mm->unmap_area = arch_unmap_area;
35885 + }
35886 +diff -urNp linux-2.6.27.10/mm/vmalloc.c linux-2.6.27.10/mm/vmalloc.c
35887 +--- linux-2.6.27.10/mm/vmalloc.c 2008-11-07 12:55:34.000000000 -0500
35888 ++++ linux-2.6.27.10/mm/vmalloc.c 2008-11-18 03:38:45.000000000 -0500
35889 +@@ -98,19 +98,36 @@ static int vmap_pte_range(pmd_t *pmd, un
35890 + unsigned long end, pgprot_t prot, struct page ***pages)
35891 + {
35892 + pte_t *pte;
35893 ++ int ret = -ENOMEM;
35894 ++
35895 ++#ifdef CONFIG_PAX_KERNEXEC
35896 ++ unsigned long cr0;
35897 ++#endif
35898 +
35899 + pte = pte_alloc_kernel(pmd, addr);
35900 + if (!pte)
35901 + return -ENOMEM;
35902 ++
35903 ++#ifdef CONFIG_PAX_KERNEXEC
35904 ++ pax_open_kernel(cr0);
35905 ++#endif
35906 ++
35907 + do {
35908 + struct page *page = **pages;
35909 + WARN_ON(!pte_none(*pte));
35910 + if (!page)
35911 +- return -ENOMEM;
35912 ++ goto out;
35913 + set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
35914 + (*pages)++;
35915 + } while (pte++, addr += PAGE_SIZE, addr != end);
35916 +- return 0;
35917 ++ ret = 0;
35918 ++out:
35919 ++
35920 ++#ifdef CONFIG_PAX_KERNEXEC
35921 ++ pax_close_kernel(cr0);
35922 ++#endif
35923 ++
35924 ++ return ret;
35925 + }
35926 +
35927 + static inline int vmap_pmd_range(pud_t *pud, unsigned long addr,
35928 +@@ -215,6 +232,16 @@ __get_vm_area_node(unsigned long size, u
35929 + unsigned long addr;
35930 +
35931 + BUG_ON(in_interrupt());
35932 ++
35933 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35934 ++ if (flags & VM_KERNEXEC) {
35935 ++ if (start != VMALLOC_START || end != VMALLOC_END)
35936 ++ return NULL;
35937 ++ start = (unsigned long)MODULES_VADDR;
35938 ++ end = (unsigned long)MODULES_END;
35939 ++ }
35940 ++#endif
35941 ++
35942 + if (flags & VM_IOREMAP) {
35943 + int bit = fls(size);
35944 +
35945 +@@ -248,20 +275,15 @@ __get_vm_area_node(unsigned long size, u
35946 + (unsigned long)tmp->addr, align);
35947 + continue;
35948 + }
35949 +- if ((size + addr) < addr)
35950 +- goto out;
35951 + if (size + addr <= (unsigned long)tmp->addr)
35952 +- goto found;
35953 ++ break;
35954 + addr = ALIGN(tmp->size + (unsigned long)tmp->addr, align);
35955 +- if (addr > end - size)
35956 +- goto out;
35957 + }
35958 + if ((size + addr) < addr)
35959 + goto out;
35960 + if (addr > end - size)
35961 + goto out;
35962 +
35963 +-found:
35964 + area->next = *p;
35965 + *p = area;
35966 +
35967 +@@ -466,6 +488,11 @@ void *vmap(struct page **pages, unsigned
35968 + if (count > num_physpages)
35969 + return NULL;
35970 +
35971 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35972 ++ if (!(pgprot_val(prot) & _PAGE_NX))
35973 ++ flags |= VM_KERNEXEC;
35974 ++#endif
35975 ++
35976 + area = get_vm_area_caller((count << PAGE_SHIFT), flags,
35977 + __builtin_return_address(0));
35978 + if (!area)
35979 +@@ -560,6 +587,13 @@ static void *__vmalloc_node(unsigned lon
35980 + if (!size || (size >> PAGE_SHIFT) > num_physpages)
35981 + return NULL;
35982 +
35983 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35984 ++ if (!(pgprot_val(prot) & _PAGE_NX))
35985 ++ area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
35986 ++ node, gfp_mask, caller);
35987 ++ else
35988 ++#endif
35989 ++
35990 + area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
35991 + node, gfp_mask, caller);
35992 +
35993 +@@ -651,7 +685,7 @@ EXPORT_SYMBOL(vmalloc_node);
35994 +
35995 + void *vmalloc_exec(unsigned long size)
35996 + {
35997 +- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
35998 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC);
35999 + }
36000 +
36001 + #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
36002 +diff -urNp linux-2.6.27.10/net/bridge/br_stp_if.c linux-2.6.27.10/net/bridge/br_stp_if.c
36003 +--- linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-07 12:55:34.000000000 -0500
36004 ++++ linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-18 03:38:45.000000000 -0500
36005 +@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
36006 + char *envp[] = { NULL };
36007 +
36008 + if (br->stp_enabled == BR_USER_STP) {
36009 +- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
36010 ++ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
36011 + printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
36012 + br->dev->name, r);
36013 +
36014 +diff -urNp linux-2.6.27.10/net/core/flow.c linux-2.6.27.10/net/core/flow.c
36015 +--- linux-2.6.27.10/net/core/flow.c 2008-11-07 12:55:34.000000000 -0500
36016 ++++ linux-2.6.27.10/net/core/flow.c 2008-11-18 03:38:45.000000000 -0500
36017 +@@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT(
36018 +
36019 + static u32 flow_hash_shift;
36020 + #define flow_hash_size (1 << flow_hash_shift)
36021 +-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
36022 ++static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
36023 +
36024 + #define flow_table(cpu) (per_cpu(flow_tables, cpu))
36025 +
36026 +@@ -52,7 +52,7 @@ struct flow_percpu_info {
36027 + u32 hash_rnd;
36028 + int count;
36029 + };
36030 +-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
36031 ++static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
36032 +
36033 + #define flow_hash_rnd_recalc(cpu) \
36034 + (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
36035 +@@ -69,7 +69,7 @@ struct flow_flush_info {
36036 + atomic_t cpuleft;
36037 + struct completion completion;
36038 + };
36039 +-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
36040 ++static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
36041 +
36042 + #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
36043 +
36044 +diff -urNp linux-2.6.27.10/net/dccp/ccids/ccid3.c linux-2.6.27.10/net/dccp/ccids/ccid3.c
36045 +--- linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-07 12:55:34.000000000 -0500
36046 ++++ linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-18 03:38:45.000000000 -0500
36047 +@@ -43,7 +43,7 @@
36048 + static int ccid3_debug;
36049 + #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
36050 + #else
36051 +-#define ccid3_pr_debug(format, a...)
36052 ++#define ccid3_pr_debug(format, a...) do {} while (0)
36053 + #endif
36054 +
36055 + /*
36056 +diff -urNp linux-2.6.27.10/net/dccp/dccp.h linux-2.6.27.10/net/dccp/dccp.h
36057 +--- linux-2.6.27.10/net/dccp/dccp.h 2008-11-07 12:55:34.000000000 -0500
36058 ++++ linux-2.6.27.10/net/dccp/dccp.h 2008-11-18 03:38:45.000000000 -0500
36059 +@@ -43,8 +43,8 @@ extern int dccp_debug;
36060 + #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a)
36061 + #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
36062 + #else
36063 +-#define dccp_pr_debug(format, a...)
36064 +-#define dccp_pr_debug_cat(format, a...)
36065 ++#define dccp_pr_debug(format, a...) do {} while (0)
36066 ++#define dccp_pr_debug_cat(format, a...) do {} while (0)
36067 + #endif
36068 +
36069 + extern struct inet_hashinfo dccp_hashinfo;
36070 +diff -urNp linux-2.6.27.10/net/ipv4/inet_connection_sock.c linux-2.6.27.10/net/ipv4/inet_connection_sock.c
36071 +--- linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-07 12:55:34.000000000 -0500
36072 ++++ linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-18 03:38:45.000000000 -0500
36073 +@@ -15,6 +15,7 @@
36074 +
36075 + #include <linux/module.h>
36076 + #include <linux/jhash.h>
36077 ++#include <linux/grsecurity.h>
36078 +
36079 + #include <net/inet_connection_sock.h>
36080 + #include <net/inet_hashtables.h>
36081 +diff -urNp linux-2.6.27.10/net/ipv4/inet_hashtables.c linux-2.6.27.10/net/ipv4/inet_hashtables.c
36082 +--- linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-07 12:55:34.000000000 -0500
36083 ++++ linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-18 03:38:45.000000000 -0500
36084 +@@ -18,11 +18,14 @@
36085 + #include <linux/sched.h>
36086 + #include <linux/slab.h>
36087 + #include <linux/wait.h>
36088 ++#include <linux/grsecurity.h>
36089 +
36090 + #include <net/inet_connection_sock.h>
36091 + #include <net/inet_hashtables.h>
36092 + #include <net/ip.h>
36093 +
36094 ++extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
36095 ++
36096 + /*
36097 + * Allocate and initialize a new local port bind bucket.
36098 + * The bindhash mutex for snum's hash chain must be held here.
36099 +@@ -487,6 +490,8 @@ ok:
36100 + }
36101 + spin_unlock(&head->lock);
36102 +
36103 ++ gr_update_task_in_ip_table(current, inet_sk(sk));
36104 ++
36105 + if (tw) {
36106 + inet_twsk_deschedule(tw, death_row);
36107 + inet_twsk_put(tw);
36108 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c
36109 +--- linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 1969-12-31 19:00:00.000000000 -0500
36110 ++++ linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 2008-11-18 03:38:45.000000000 -0500
36111 +@@ -0,0 +1,114 @@
36112 ++/* Kernel module to add stealth support.
36113 ++ *
36114 ++ * Copyright (C) 2002-2006 Brad Spengler <spender@××××××××××.net>
36115 ++ *
36116 ++ */
36117 ++
36118 ++#include <linux/kernel.h>
36119 ++#include <linux/module.h>
36120 ++#include <linux/skbuff.h>
36121 ++#include <linux/net.h>
36122 ++#include <linux/sched.h>
36123 ++#include <linux/inet.h>
36124 ++#include <linux/stddef.h>
36125 ++
36126 ++#include <net/ip.h>
36127 ++#include <net/sock.h>
36128 ++#include <net/tcp.h>
36129 ++#include <net/udp.h>
36130 ++#include <net/route.h>
36131 ++#include <net/inet_common.h>
36132 ++
36133 ++#include <linux/netfilter_ipv4/ip_tables.h>
36134 ++
36135 ++MODULE_LICENSE("GPL");
36136 ++
36137 ++extern struct sock *udp_v4_lookup(struct net *net, u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
36138 ++
36139 ++static bool
36140 ++match(const struct sk_buff *skb,
36141 ++ const struct net_device *in,
36142 ++ const struct net_device *out,
36143 ++ const struct xt_match *match,
36144 ++ const void *matchinfo,
36145 ++ int offset,
36146 ++ unsigned int protoff,
36147 ++ bool *hotdrop)
36148 ++{
36149 ++ struct iphdr *ip = ip_hdr(skb);
36150 ++ struct tcphdr th;
36151 ++ struct udphdr uh;
36152 ++ struct sock *sk = NULL;
36153 ++
36154 ++ if (!ip || offset) return false;
36155 ++
36156 ++ switch(ip->protocol) {
36157 ++ case IPPROTO_TCP:
36158 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &th, sizeof(th)) < 0) {
36159 ++ *hotdrop = true;
36160 ++ return false;
36161 ++ }
36162 ++ if (!(th.syn && !th.ack)) return false;
36163 ++ sk = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, ip->daddr, th.dest, inet_iif(skb));
36164 ++ break;
36165 ++ case IPPROTO_UDP:
36166 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &uh, sizeof(uh)) < 0) {
36167 ++ *hotdrop = true;
36168 ++ return false;
36169 ++ }
36170 ++ sk = udp_v4_lookup(dev_net(skb->dev), ip->saddr, uh.source, ip->daddr, uh.dest, skb->dev->ifindex);
36171 ++ break;
36172 ++ default:
36173 ++ return false;
36174 ++ }
36175 ++
36176 ++ if(!sk) // port is being listened on, match this
36177 ++ return true;
36178 ++ else {
36179 ++ sock_put(sk);
36180 ++ return false;
36181 ++ }
36182 ++}
36183 ++
36184 ++/* Called when user tries to insert an entry of this type. */
36185 ++static bool
36186 ++checkentry(const char *tablename,
36187 ++ const void *nip,
36188 ++ const struct xt_match *match,
36189 ++ void *matchinfo,
36190 ++ unsigned int hook_mask)
36191 ++{
36192 ++ const struct ipt_ip *ip = (const struct ipt_ip *)nip;
36193 ++
36194 ++ if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
36195 ++ ((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
36196 ++ && (hook_mask & (1 << NF_INET_LOCAL_IN)))
36197 ++ return true;
36198 ++
36199 ++ printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
36200 ++
36201 ++ return false;
36202 ++}
36203 ++
36204 ++
36205 ++static struct xt_match stealth_match __read_mostly = {
36206 ++ .name = "stealth",
36207 ++ .family = AF_INET,
36208 ++ .match = match,
36209 ++ .checkentry = checkentry,
36210 ++ .destroy = NULL,
36211 ++ .me = THIS_MODULE
36212 ++};
36213 ++
36214 ++static int __init init(void)
36215 ++{
36216 ++ return xt_register_match(&stealth_match);
36217 ++}
36218 ++
36219 ++static void __exit fini(void)
36220 ++{
36221 ++ xt_unregister_match(&stealth_match);
36222 ++}
36223 ++
36224 ++module_init(init);
36225 ++module_exit(fini);
36226 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Kconfig linux-2.6.27.10/net/ipv4/netfilter/Kconfig
36227 +--- linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-07 12:55:34.000000000 -0500
36228 ++++ linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-18 03:38:45.000000000 -0500
36229 +@@ -111,6 +111,21 @@ config IP_NF_MATCH_ADDRTYPE
36230 + If you want to compile it as a module, say M here and read
36231 + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
36232 +
36233 ++config IP_NF_MATCH_STEALTH
36234 ++ tristate "stealth match support"
36235 ++ depends on IP_NF_IPTABLES
36236 ++ help
36237 ++ Enabling this option will drop all syn packets coming to unserved tcp
36238 ++ ports as well as all packets coming to unserved udp ports. If you
36239 ++ are using your system to route any type of packets (ie. via NAT)
36240 ++ you should put this module at the end of your ruleset, since it will
36241 ++ drop packets that aren't going to ports that are listening on your
36242 ++ machine itself, it doesn't take into account that the packet might be
36243 ++ destined for someone on your internal network if you're using NAT for
36244 ++ instance.
36245 ++
36246 ++ To compile it as a module, choose M here. If unsure, say N.
36247 ++
36248 + # `filter', generic and specific targets
36249 + config IP_NF_FILTER
36250 + tristate "Packet filtering"
36251 +@@ -407,4 +422,3 @@ config IP_NF_ARP_MANGLE
36252 + hardware and network addresses.
36253 +
36254 + endmenu
36255 +-
36256 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Makefile linux-2.6.27.10/net/ipv4/netfilter/Makefile
36257 +--- linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-07 12:55:34.000000000 -0500
36258 ++++ linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-18 03:38:45.000000000 -0500
36259 +@@ -59,6 +59,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
36260 + obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
36261 + obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
36262 + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
36263 ++obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
36264 + obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
36265 + obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
36266 +
36267 +diff -urNp linux-2.6.27.10/net/ipv4/tcp_ipv4.c linux-2.6.27.10/net/ipv4/tcp_ipv4.c
36268 +--- linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-07 12:55:34.000000000 -0500
36269 ++++ linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-18 03:38:45.000000000 -0500
36270 +@@ -59,6 +59,7 @@
36271 + #include <linux/jhash.h>
36272 + #include <linux/init.h>
36273 + #include <linux/times.h>
36274 ++#include <linux/grsecurity.h>
36275 +
36276 + #include <net/net_namespace.h>
36277 + #include <net/icmp.h>
36278 +diff -urNp linux-2.6.27.10/net/ipv4/udp.c linux-2.6.27.10/net/ipv4/udp.c
36279 +--- linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:16:52.000000000 -0500
36280 ++++ linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:13:47.000000000 -0500
36281 +@@ -97,6 +97,7 @@
36282 + #include <linux/skbuff.h>
36283 + #include <linux/proc_fs.h>
36284 + #include <linux/seq_file.h>
36285 ++#include <linux/grsecurity.h>
36286 + #include <net/net_namespace.h>
36287 + #include <net/icmp.h>
36288 + #include <net/route.h>
36289 +@@ -104,6 +105,11 @@
36290 + #include <net/xfrm.h>
36291 + #include "udp_impl.h"
36292 +
36293 ++extern int gr_search_udp_recvmsg(const struct sock *sk,
36294 ++ const struct sk_buff *skb);
36295 ++extern int gr_search_udp_sendmsg(const struct sock *sk,
36296 ++ const struct sockaddr_in *addr);
36297 ++
36298 + /*
36299 + * Snmp MIB for the UDP layer
36300 + */
36301 +@@ -302,6 +308,13 @@ static struct sock *__udp4_lib_lookup(st
36302 + return result;
36303 + }
36304 +
36305 ++struct sock *udp_v4_lookup(struct net *net, __be32 saddr, __be16 sport,
36306 ++ __be32 daddr, __be16 dport, int dif)
36307 ++{
36308 ++ return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash);
36309 ++}
36310 ++
36311 ++
36312 + static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
36313 + __be16 loc_port, __be32 loc_addr,
36314 + __be16 rmt_port, __be32 rmt_addr,
36315 +@@ -592,9 +605,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
36316 + dport = usin->sin_port;
36317 + if (dport == 0)
36318 + return -EINVAL;
36319 ++
36320 ++ if (!gr_search_udp_sendmsg(sk, usin))
36321 ++ return -EPERM;
36322 + } else {
36323 + if (sk->sk_state != TCP_ESTABLISHED)
36324 + return -EDESTADDRREQ;
36325 ++
36326 ++ if (!gr_search_udp_sendmsg(sk, NULL))
36327 ++ return -EPERM;
36328 ++
36329 + daddr = inet->daddr;
36330 + dport = inet->dport;
36331 + /* Open fast path for connected socket.
36332 +@@ -859,6 +879,11 @@ try_again:
36333 + if (!skb)
36334 + goto out;
36335 +
36336 ++ if (!gr_search_udp_recvmsg(sk, skb)) {
36337 ++ err = -EPERM;
36338 ++ goto out_free;
36339 ++ }
36340 ++
36341 + ulen = skb->len - sizeof(struct udphdr);
36342 + copied = len;
36343 + if (copied > ulen)
36344 +diff -urNp linux-2.6.27.10/net/ipv6/exthdrs.c linux-2.6.27.10/net/ipv6/exthdrs.c
36345 +--- linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-07 12:55:34.000000000 -0500
36346 ++++ linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-18 03:38:45.000000000 -0500
36347 +@@ -624,7 +624,7 @@ static struct tlvtype_proc tlvprochopopt
36348 + .type = IPV6_TLV_JUMBO,
36349 + .func = ipv6_hop_jumbo,
36350 + },
36351 +- { -1, }
36352 ++ { -1, NULL }
36353 + };
36354 +
36355 + int ipv6_parse_hopopts(struct sk_buff *skb)
36356 +diff -urNp linux-2.6.27.10/net/ipv6/raw.c linux-2.6.27.10/net/ipv6/raw.c
36357 +--- linux-2.6.27.10/net/ipv6/raw.c 2008-11-07 12:55:34.000000000 -0500
36358 ++++ linux-2.6.27.10/net/ipv6/raw.c 2008-11-18 03:38:45.000000000 -0500
36359 +@@ -600,7 +600,7 @@ out:
36360 + return err;
36361 + }
36362 +
36363 +-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
36364 ++static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
36365 + struct flowi *fl, struct rt6_info *rt,
36366 + unsigned int flags)
36367 + {
36368 +diff -urNp linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c
36369 +--- linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-07 12:55:34.000000000 -0500
36370 ++++ linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-18 03:38:45.000000000 -0500
36371 +@@ -371,7 +371,7 @@ static int ircomm_tty_open(struct tty_st
36372 + IRDA_DEBUG(2, "%s()\n", __func__ );
36373 +
36374 + line = tty->index;
36375 +- if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
36376 ++ if (line >= IRCOMM_TTY_PORTS) {
36377 + return -ENODEV;
36378 + }
36379 +
36380 +diff -urNp linux-2.6.27.10/net/sctp/socket.c linux-2.6.27.10/net/sctp/socket.c
36381 +--- linux-2.6.27.10/net/sctp/socket.c 2008-11-07 12:55:34.000000000 -0500
36382 ++++ linux-2.6.27.10/net/sctp/socket.c 2008-11-18 03:38:45.000000000 -0500
36383 +@@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
36384 + struct sctp_sndrcvinfo *sinfo;
36385 + struct sctp_initmsg *sinit;
36386 + sctp_assoc_t associd = 0;
36387 +- sctp_cmsgs_t cmsgs = { NULL };
36388 ++ sctp_cmsgs_t cmsgs = { NULL, NULL };
36389 + int err;
36390 + sctp_scope_t scope;
36391 + long timeo;
36392 +@@ -5616,7 +5616,6 @@ pp_found:
36393 + */
36394 + int reuse = sk->sk_reuse;
36395 + struct sock *sk2;
36396 +- struct hlist_node *node;
36397 +
36398 + SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
36399 + if (pp->fastreuse && sk->sk_reuse &&
36400 +diff -urNp linux-2.6.27.10/net/socket.c linux-2.6.27.10/net/socket.c
36401 +--- linux-2.6.27.10/net/socket.c 2008-11-07 12:55:34.000000000 -0500
36402 ++++ linux-2.6.27.10/net/socket.c 2008-11-18 03:38:45.000000000 -0500
36403 +@@ -87,6 +87,7 @@
36404 + #include <linux/audit.h>
36405 + #include <linux/wireless.h>
36406 + #include <linux/nsproxy.h>
36407 ++#include <linux/in.h>
36408 +
36409 + #include <asm/uaccess.h>
36410 + #include <asm/unistd.h>
36411 +@@ -97,6 +98,21 @@
36412 + #include <net/sock.h>
36413 + #include <linux/netfilter.h>
36414 +
36415 ++extern void gr_attach_curr_ip(const struct sock *sk);
36416 ++extern int gr_handle_sock_all(const int family, const int type,
36417 ++ const int protocol);
36418 ++extern int gr_handle_sock_server(const struct sockaddr *sck);
36419 ++extern int gr_handle_sock_server_other(const struct socket *sck);
36420 ++extern int gr_handle_sock_client(const struct sockaddr *sck);
36421 ++extern int gr_search_connect(const struct socket * sock,
36422 ++ const struct sockaddr_in * addr);
36423 ++extern int gr_search_bind(const struct socket * sock,
36424 ++ const struct sockaddr_in * addr);
36425 ++extern int gr_search_listen(const struct socket * sock);
36426 ++extern int gr_search_accept(const struct socket * sock);
36427 ++extern int gr_search_socket(const int domain, const int type,
36428 ++ const int protocol);
36429 ++
36430 + static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
36431 + static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
36432 + unsigned long nr_segs, loff_t pos);
36433 +@@ -300,7 +316,7 @@ static int sockfs_get_sb(struct file_sys
36434 + mnt);
36435 + }
36436 +
36437 +-static struct vfsmount *sock_mnt __read_mostly;
36438 ++struct vfsmount *sock_mnt __read_mostly;
36439 +
36440 + static struct file_system_type sock_fs_type = {
36441 + .name = "sockfs",
36442 +@@ -1236,6 +1252,16 @@ asmlinkage long sys_socket(int family, i
36443 + if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
36444 + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
36445 +
36446 ++ if(!gr_search_socket(family, type, protocol)) {
36447 ++ retval = -EACCES;
36448 ++ goto out;
36449 ++ }
36450 ++
36451 ++ if (gr_handle_sock_all(family, type, protocol)) {
36452 ++ retval = -EACCES;
36453 ++ goto out;
36454 ++ }
36455 ++
36456 + retval = sock_create(family, type, protocol, &sock);
36457 + if (retval < 0)
36458 + goto out;
36459 +@@ -1375,6 +1401,12 @@ asmlinkage long sys_bind(int fd, struct
36460 + if (sock) {
36461 + err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
36462 + if (err >= 0) {
36463 ++ if (!gr_search_bind(sock, (struct sockaddr_in *)&address) ||
36464 ++ gr_handle_sock_server((struct sockaddr *)&address)) {
36465 ++ err = -EACCES;
36466 ++ goto error;
36467 ++ }
36468 ++
36469 + err = security_socket_bind(sock,
36470 + (struct sockaddr *)&address,
36471 + addrlen);
36472 +@@ -1383,6 +1415,7 @@ asmlinkage long sys_bind(int fd, struct
36473 + (struct sockaddr *)
36474 + &address, addrlen);
36475 + }
36476 ++error:
36477 + fput_light(sock->file, fput_needed);
36478 + }
36479 + return err;
36480 +@@ -1406,10 +1439,17 @@ asmlinkage long sys_listen(int fd, int b
36481 + if ((unsigned)backlog > somaxconn)
36482 + backlog = somaxconn;
36483 +
36484 ++ if (gr_handle_sock_server_other(sock) ||
36485 ++ !gr_search_listen(sock)) {
36486 ++ err = -EPERM;
36487 ++ goto error;
36488 ++ }
36489 ++
36490 + err = security_socket_listen(sock, backlog);
36491 + if (!err)
36492 + err = sock->ops->listen(sock, backlog);
36493 +
36494 ++error:
36495 + fput_light(sock->file, fput_needed);
36496 + }
36497 + return err;
36498 +@@ -1452,6 +1492,13 @@ long do_accept(int fd, struct sockaddr _
36499 + newsock->type = sock->type;
36500 + newsock->ops = sock->ops;
36501 +
36502 ++ if (gr_handle_sock_server_other(sock) ||
36503 ++ !gr_search_accept(sock)) {
36504 ++ err = -EPERM;
36505 ++ sock_release(newsock);
36506 ++ goto out_put;
36507 ++ }
36508 ++
36509 + /*
36510 + * We don't need try_module_get here, as the listening socket (sock)
36511 + * has the protocol module (sock->ops->owner) held.
36512 +@@ -1495,6 +1542,7 @@ long do_accept(int fd, struct sockaddr _
36513 + err = newfd;
36514 +
36515 + security_socket_post_accept(sock, newsock);
36516 ++ gr_attach_curr_ip(newsock->sk);
36517 +
36518 + out_put:
36519 + fput_light(sock->file, fput_needed);
36520 +@@ -1589,6 +1637,7 @@ asmlinkage long sys_connect(int fd, stru
36521 + int addrlen)
36522 + {
36523 + struct socket *sock;
36524 ++ struct sockaddr *sck;
36525 + struct sockaddr_storage address;
36526 + int err, fput_needed;
36527 +
36528 +@@ -1599,6 +1648,13 @@ asmlinkage long sys_connect(int fd, stru
36529 + if (err < 0)
36530 + goto out_put;
36531 +
36532 ++ sck = (struct sockaddr *)&address;
36533 ++ if (!gr_search_connect(sock, (struct sockaddr_in *)sck) ||
36534 ++ gr_handle_sock_client(sck)) {
36535 ++ err = -EACCES;
36536 ++ goto out_put;
36537 ++ }
36538 ++
36539 + err =
36540 + security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
36541 + if (err)
36542 +@@ -1866,6 +1922,7 @@ asmlinkage long sys_shutdown(int fd, int
36543 + err = sock->ops->shutdown(sock, how);
36544 + fput_light(sock->file, fput_needed);
36545 + }
36546 ++
36547 + return err;
36548 + }
36549 +
36550 +diff -urNp linux-2.6.27.10/net/unix/af_unix.c linux-2.6.27.10/net/unix/af_unix.c
36551 +--- linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:16:52.000000000 -0500
36552 ++++ linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:13:47.000000000 -0500
36553 +@@ -114,6 +114,7 @@
36554 + #include <linux/mount.h>
36555 + #include <net/checksum.h>
36556 + #include <linux/security.h>
36557 ++#include <linux/grsecurity.h>
36558 +
36559 + static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
36560 + static DEFINE_SPINLOCK(unix_table_lock);
36561 +@@ -725,6 +726,12 @@ static struct sock *unix_find_other(stru
36562 + err = -ECONNREFUSED;
36563 + if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode))
36564 + goto put_fail;
36565 ++
36566 ++ if (!gr_acl_handle_unix(nd.path.dentry, nd.path.mnt)) {
36567 ++ err = -EACCES;
36568 ++ goto put_fail;
36569 ++ }
36570 ++
36571 + u = unix_find_socket_byinode(net, nd.path.dentry->d_inode);
36572 + if (!u)
36573 + goto put_fail;
36574 +@@ -745,6 +752,13 @@ static struct sock *unix_find_other(stru
36575 + if (u) {
36576 + struct dentry *dentry;
36577 + dentry = unix_sk(u)->dentry;
36578 ++
36579 ++ if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
36580 ++ err = -EPERM;
36581 ++ sock_put(u);
36582 ++ goto fail;
36583 ++ }
36584 ++
36585 + if (dentry)
36586 + touch_atime(unix_sk(u)->mnt, dentry);
36587 + } else
36588 +@@ -827,10 +841,20 @@ static int unix_bind(struct socket *sock
36589 + err = mnt_want_write(nd.path.mnt);
36590 + if (err)
36591 + goto out_mknod_dput;
36592 ++
36593 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
36594 ++ err = -EACCES;
36595 ++ mnt_drop_write(nd.path.mnt);
36596 ++ goto out_mknod_dput;
36597 ++ }
36598 ++
36599 + err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
36600 + mnt_drop_write(nd.path.mnt);
36601 + if (err)
36602 + goto out_mknod_dput;
36603 ++
36604 ++ gr_handle_create(dentry, nd.path.mnt);
36605 ++
36606 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
36607 + dput(nd.path.dentry);
36608 + nd.path.dentry = dentry;
36609 +@@ -848,6 +872,10 @@ static int unix_bind(struct socket *sock
36610 + goto out_unlock;
36611 + }
36612 +
36613 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
36614 ++ sk->sk_peercred.pid = current->pid;
36615 ++#endif
36616 ++
36617 + list = &unix_socket_table[addr->hash];
36618 + } else {
36619 + list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
36620 +diff -urNp linux-2.6.27.10/scripts/pnmtologo.c linux-2.6.27.10/scripts/pnmtologo.c
36621 +--- linux-2.6.27.10/scripts/pnmtologo.c 2008-11-07 12:55:34.000000000 -0500
36622 ++++ linux-2.6.27.10/scripts/pnmtologo.c 2008-11-18 03:38:45.000000000 -0500
36623 +@@ -237,14 +237,14 @@ static void write_header(void)
36624 + fprintf(out, " * Linux logo %s\n", logoname);
36625 + fputs(" */\n\n", out);
36626 + fputs("#include <linux/linux_logo.h>\n\n", out);
36627 +- fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
36628 ++ fprintf(out, "static unsigned char %s_data[] = {\n",
36629 + logoname);
36630 + }
36631 +
36632 + static void write_footer(void)
36633 + {
36634 + fputs("\n};\n\n", out);
36635 +- fprintf(out, "struct linux_logo %s __initdata = {\n", logoname);
36636 ++ fprintf(out, "struct linux_logo %s = {\n", logoname);
36637 + fprintf(out, " .type\t= %s,\n", logo_types[logo_type]);
36638 + fprintf(out, " .width\t= %d,\n", logo_width);
36639 + fprintf(out, " .height\t= %d,\n", logo_height);
36640 +@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
36641 + fputs("\n};\n\n", out);
36642 +
36643 + /* write logo clut */
36644 +- fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
36645 ++ fprintf(out, "static unsigned char %s_clut[] = {\n",
36646 + logoname);
36647 + write_hex_cnt = 0;
36648 + for (i = 0; i < logo_clutsize; i++) {
36649 +diff -urNp linux-2.6.27.10/security/commoncap.c linux-2.6.27.10/security/commoncap.c
36650 +--- linux-2.6.27.10/security/commoncap.c 2008-11-07 12:55:34.000000000 -0500
36651 ++++ linux-2.6.27.10/security/commoncap.c 2008-11-18 03:38:45.000000000 -0500
36652 +@@ -26,10 +26,13 @@
36653 + #include <linux/sched.h>
36654 + #include <linux/prctl.h>
36655 + #include <linux/securebits.h>
36656 ++#include <linux/grsecurity.h>
36657 ++
36658 ++extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
36659 +
36660 + int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
36661 + {
36662 +- NETLINK_CB(skb).eff_cap = current->cap_effective;
36663 ++ NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
36664 + return 0;
36665 + }
36666 +
36667 +@@ -51,7 +54,15 @@ EXPORT_SYMBOL(cap_netlink_recv);
36668 + int cap_capable (struct task_struct *tsk, int cap)
36669 + {
36670 + /* Derived from include/linux/sched.h:capable. */
36671 +- if (cap_raised(tsk->cap_effective, cap))
36672 ++ if (cap_raised (tsk->cap_effective, cap))
36673 ++ return 0;
36674 ++ return -EPERM;
36675 ++}
36676 ++
36677 ++int cap_capable_nolog (struct task_struct *tsk, int cap)
36678 ++{
36679 ++ /* tsk = current for all callers */
36680 ++ if (cap_raised(tsk->cap_effective, cap) && gr_is_capable_nolog(cap))
36681 + return 0;
36682 + return -EPERM;
36683 + }
36684 +@@ -379,8 +390,11 @@ void cap_bprm_apply_creds (struct linux_
36685 + }
36686 + }
36687 +
36688 +- current->suid = current->euid = current->fsuid = bprm->e_uid;
36689 +- current->sgid = current->egid = current->fsgid = bprm->e_gid;
36690 ++ if (!gr_check_user_change(-1, bprm->e_uid, bprm->e_uid))
36691 ++ current->suid = current->euid = current->fsuid = bprm->e_uid;
36692 ++
36693 ++ if (!gr_check_group_change(-1, bprm->e_gid, bprm->e_gid))
36694 ++ current->sgid = current->egid = current->fsgid = bprm->e_gid;
36695 +
36696 + /* For init, we want to retain the capabilities set
36697 + * in the init_task struct. Thus we skip the usual
36698 +@@ -393,6 +407,8 @@ void cap_bprm_apply_creds (struct linux_
36699 + cap_clear(current->cap_effective);
36700 + }
36701 +
36702 ++ gr_handle_chroot_caps(current);
36703 ++
36704 + /* AUD: Audit candidate if current->cap_effective is set */
36705 +
36706 + current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
36707 +@@ -705,7 +721,7 @@ int cap_vm_enough_memory(struct mm_struc
36708 + {
36709 + int cap_sys_admin = 0;
36710 +
36711 +- if (cap_capable(current, CAP_SYS_ADMIN) == 0)
36712 ++ if (cap_capable_nolog(current, CAP_SYS_ADMIN) == 0)
36713 + cap_sys_admin = 1;
36714 + return __vm_enough_memory(mm, pages, cap_sys_admin);
36715 + }
36716 +diff -urNp linux-2.6.27.10/security/Kconfig linux-2.6.27.10/security/Kconfig
36717 +--- linux-2.6.27.10/security/Kconfig 2008-11-07 12:55:34.000000000 -0500
36718 ++++ linux-2.6.27.10/security/Kconfig 2008-11-18 03:38:45.000000000 -0500
36719 +@@ -4,6 +4,447 @@
36720 +
36721 + menu "Security options"
36722 +
36723 ++source grsecurity/Kconfig
36724 ++
36725 ++menu "PaX"
36726 ++
36727 ++config PAX
36728 ++ bool "Enable various PaX features"
36729 ++ depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
36730 ++ help
36731 ++ This allows you to enable various PaX features. PaX adds
36732 ++ intrusion prevention mechanisms to the kernel that reduce
36733 ++ the risks posed by exploitable memory corruption bugs.
36734 ++
36735 ++menu "PaX Control"
36736 ++ depends on PAX
36737 ++
36738 ++config PAX_SOFTMODE
36739 ++ bool 'Support soft mode'
36740 ++ help
36741 ++ Enabling this option will allow you to run PaX in soft mode, that
36742 ++ is, PaX features will not be enforced by default, only on executables
36743 ++ marked explicitly. You must also enable PT_PAX_FLAGS support as it
36744 ++ is the only way to mark executables for soft mode use.
36745 ++
36746 ++ Soft mode can be activated by using the "pax_softmode=1" kernel command
36747 ++ line option on boot. Furthermore you can control various PaX features
36748 ++ at runtime via the entries in /proc/sys/kernel/pax.
36749 ++
36750 ++config PAX_EI_PAX
36751 ++ bool 'Use legacy ELF header marking'
36752 ++ help
36753 ++ Enabling this option will allow you to control PaX features on
36754 ++ a per executable basis via the 'chpax' utility available at
36755 ++ http://pax.grsecurity.net/. The control flags will be read from
36756 ++ an otherwise reserved part of the ELF header. This marking has
36757 ++ numerous drawbacks (no support for soft-mode, toolchain does not
36758 ++ know about the non-standard use of the ELF header) therefore it
36759 ++ has been deprecated in favour of PT_PAX_FLAGS support.
36760 ++
36761 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36762 ++ program header then you MUST enable this option otherwise they
36763 ++ will not get any protection.
36764 ++
36765 ++ Note that if you enable PT_PAX_FLAGS marking support as well,
36766 ++ the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
36767 ++
36768 ++config PAX_PT_PAX_FLAGS
36769 ++ bool 'Use ELF program header marking'
36770 ++ help
36771 ++ Enabling this option will allow you to control PaX features on
36772 ++ a per executable basis via the 'paxctl' utility available at
36773 ++ http://pax.grsecurity.net/. The control flags will be read from
36774 ++ a PaX specific ELF program header (PT_PAX_FLAGS). This marking
36775 ++ has the benefits of supporting both soft mode and being fully
36776 ++ integrated into the toolchain (the binutils patch is available
36777 ++ from http://pax.grsecurity.net).
36778 ++
36779 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36780 ++ program header then you MUST enable the EI_PAX marking support
36781 ++ otherwise they will not get any protection.
36782 ++
36783 ++ Note that if you enable the legacy EI_PAX marking support as well,
36784 ++ the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
36785 ++
36786 ++choice
36787 ++ prompt 'MAC system integration'
36788 ++ default PAX_HAVE_ACL_FLAGS
36789 ++ help
36790 ++ Mandatory Access Control systems have the option of controlling
36791 ++ PaX flags on a per executable basis, choose the method supported
36792 ++ by your particular system.
36793 ++
36794 ++ - "none": if your MAC system does not interact with PaX,
36795 ++ - "direct": if your MAC system defines pax_set_initial_flags() itself,
36796 ++ - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
36797 ++
36798 ++ NOTE: this option is for developers/integrators only.
36799 ++
36800 ++ config PAX_NO_ACL_FLAGS
36801 ++ bool 'none'
36802 ++
36803 ++ config PAX_HAVE_ACL_FLAGS
36804 ++ bool 'direct'
36805 ++
36806 ++ config PAX_HOOK_ACL_FLAGS
36807 ++ bool 'hook'
36808 ++endchoice
36809 ++
36810 ++endmenu
36811 ++
36812 ++menu "Non-executable pages"
36813 ++ depends on PAX
36814 ++
36815 ++config PAX_NOEXEC
36816 ++ bool "Enforce non-executable pages"
36817 ++ 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)
36818 ++ help
36819 ++ By design some architectures do not allow for protecting memory
36820 ++ pages against execution or even if they do, Linux does not make
36821 ++ use of this feature. In practice this means that if a page is
36822 ++ readable (such as the stack or heap) it is also executable.
36823 ++
36824 ++ There is a well known exploit technique that makes use of this
36825 ++ fact and a common programming mistake where an attacker can
36826 ++ introduce code of his choice somewhere in the attacked program's
36827 ++ memory (typically the stack or the heap) and then execute it.
36828 ++
36829 ++ If the attacked program was running with different (typically
36830 ++ higher) privileges than that of the attacker, then he can elevate
36831 ++ his own privilege level (e.g. get a root shell, write to files for
36832 ++ which he does not have write access to, etc).
36833 ++
36834 ++ Enabling this option will let you choose from various features
36835 ++ that prevent the injection and execution of 'foreign' code in
36836 ++ a program.
36837 ++
36838 ++ This will also break programs that rely on the old behaviour and
36839 ++ expect that dynamically allocated memory via the malloc() family
36840 ++ of functions is executable (which it is not). Notable examples
36841 ++ are the XFree86 4.x server, the java runtime and wine.
36842 ++
36843 ++config PAX_PAGEEXEC
36844 ++ bool "Paging based non-executable pages"
36845 ++ 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)
36846 ++ help
36847 ++ This implementation is based on the paging feature of the CPU.
36848 ++ On i386 without hardware non-executable bit support there is a
36849 ++ variable but usually low performance impact, however on Intel's
36850 ++ P4 core based CPUs it is very high so you should not enable this
36851 ++ for kernels meant to be used on such CPUs.
36852 ++
36853 ++ On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
36854 ++ with hardware non-executable bit support there is no performance
36855 ++ impact, on ppc the impact is negligible.
36856 ++
36857 ++ Note that several architectures require various emulations due to
36858 ++ badly designed userland ABIs, this will cause a performance impact
36859 ++ but will disappear as soon as userland is fixed (e.g., ppc users
36860 ++ can make use of the secure-plt feature found in binutils).
36861 ++
36862 ++config PAX_SEGMEXEC
36863 ++ bool "Segmentation based non-executable pages"
36864 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32
36865 ++ help
36866 ++ This implementation is based on the segmentation feature of the
36867 ++ CPU and has a very small performance impact, however applications
36868 ++ will be limited to a 1.5 GB address space instead of the normal
36869 ++ 3 GB.
36870 ++
36871 ++config PAX_EMUTRAMP
36872 ++ bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86)
36873 ++ default y if PARISC || PPC32
36874 ++ help
36875 ++ There are some programs and libraries that for one reason or
36876 ++ another attempt to execute special small code snippets from
36877 ++ non-executable memory pages. Most notable examples are the
36878 ++ signal handler return code generated by the kernel itself and
36879 ++ the GCC trampolines.
36880 ++
36881 ++ If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
36882 ++ such programs will no longer work under your kernel.
36883 ++
36884 ++ As a remedy you can say Y here and use the 'chpax' or 'paxctl'
36885 ++ utilities to enable trampoline emulation for the affected programs
36886 ++ yet still have the protection provided by the non-executable pages.
36887 ++
36888 ++ On parisc and ppc you MUST enable this option and EMUSIGRT as
36889 ++ well, otherwise your system will not even boot.
36890 ++
36891 ++ Alternatively you can say N here and use the 'chpax' or 'paxctl'
36892 ++ utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
36893 ++ for the affected files.
36894 ++
36895 ++ NOTE: enabling this feature *may* open up a loophole in the
36896 ++ protection provided by non-executable pages that an attacker
36897 ++ could abuse. Therefore the best solution is to not have any
36898 ++ files on your system that would require this option. This can
36899 ++ be achieved by not using libc5 (which relies on the kernel
36900 ++ signal handler return code) and not using or rewriting programs
36901 ++ that make use of the nested function implementation of GCC.
36902 ++ Skilled users can just fix GCC itself so that it implements
36903 ++ nested function calls in a way that does not interfere with PaX.
36904 ++
36905 ++config PAX_EMUSIGRT
36906 ++ bool "Automatically emulate sigreturn trampolines"
36907 ++ depends on PAX_EMUTRAMP && (PARISC || PPC32)
36908 ++ default y
36909 ++ help
36910 ++ Enabling this option will have the kernel automatically detect
36911 ++ and emulate signal return trampolines executing on the stack
36912 ++ that would otherwise lead to task termination.
36913 ++
36914 ++ This solution is intended as a temporary one for users with
36915 ++ legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
36916 ++ Modula-3 runtime, etc) or executables linked to such, basically
36917 ++ everything that does not specify its own SA_RESTORER function in
36918 ++ normal executable memory like glibc 2.1+ does.
36919 ++
36920 ++ On parisc and ppc you MUST enable this option, otherwise your
36921 ++ system will not even boot.
36922 ++
36923 ++ NOTE: this feature cannot be disabled on a per executable basis
36924 ++ and since it *does* open up a loophole in the protection provided
36925 ++ by non-executable pages, the best solution is to not have any
36926 ++ files on your system that would require this option.
36927 ++
36928 ++config PAX_MPROTECT
36929 ++ bool "Restrict mprotect()"
36930 ++ depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64
36931 ++ help
36932 ++ Enabling this option will prevent programs from
36933 ++ - changing the executable status of memory pages that were
36934 ++ not originally created as executable,
36935 ++ - making read-only executable pages writable again,
36936 ++ - creating executable pages from anonymous memory.
36937 ++
36938 ++ You should say Y here to complete the protection provided by
36939 ++ the enforcement of non-executable pages.
36940 ++
36941 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
36942 ++ this feature on a per file basis.
36943 ++
36944 ++config PAX_NOELFRELOCS
36945 ++ bool "Disallow ELF text relocations"
36946 ++ depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86)
36947 ++ help
36948 ++ Non-executable pages and mprotect() restrictions are effective
36949 ++ in preventing the introduction of new executable code into an
36950 ++ attacked task's address space. There remain only two venues
36951 ++ for this kind of attack: if the attacker can execute already
36952 ++ existing code in the attacked task then he can either have it
36953 ++ create and mmap() a file containing his code or have it mmap()
36954 ++ an already existing ELF library that does not have position
36955 ++ independent code in it and use mprotect() on it to make it
36956 ++ writable and copy his code there. While protecting against
36957 ++ the former approach is beyond PaX, the latter can be prevented
36958 ++ by having only PIC ELF libraries on one's system (which do not
36959 ++ need to relocate their code). If you are sure this is your case,
36960 ++ then enable this option otherwise be careful as you may not even
36961 ++ be able to boot or log on your system (for example, some PAM
36962 ++ modules are erroneously compiled as non-PIC by default).
36963 ++
36964 ++ NOTE: if you are using dynamic ELF executables (as suggested
36965 ++ when using ASLR) then you must have made sure that you linked
36966 ++ your files using the PIC version of crt1 (the et_dyn.tar.gz package
36967 ++ referenced there has already been updated to support this).
36968 ++
36969 ++config PAX_ETEXECRELOCS
36970 ++ bool "Allow ELF ET_EXEC text relocations"
36971 ++ depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
36972 ++ default y
36973 ++ help
36974 ++ On some architectures there are incorrectly created applications
36975 ++ that require text relocations and would not work without enabling
36976 ++ this option. If you are an alpha, ia64 or parisc user, you should
36977 ++ enable this option and disable it once you have made sure that
36978 ++ none of your applications need it.
36979 ++
36980 ++config PAX_EMUPLT
36981 ++ bool "Automatically emulate ELF PLT"
36982 ++ depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
36983 ++ default y
36984 ++ help
36985 ++ Enabling this option will have the kernel automatically detect
36986 ++ and emulate the Procedure Linkage Table entries in ELF files.
36987 ++ On some architectures such entries are in writable memory, and
36988 ++ become non-executable leading to task termination. Therefore
36989 ++ it is mandatory that you enable this option on alpha, parisc,
36990 ++ ppc (if secure-plt is not used throughout in userland), sparc
36991 ++ and sparc64, otherwise your system would not even boot.
36992 ++
36993 ++ NOTE: this feature *does* open up a loophole in the protection
36994 ++ provided by the non-executable pages, therefore the proper
36995 ++ solution is to modify the toolchain to produce a PLT that does
36996 ++ not need to be writable.
36997 ++
36998 ++config PAX_DLRESOLVE
36999 ++ bool
37000 ++ depends on PAX_EMUPLT && (SPARC32 || SPARC64)
37001 ++ default y
37002 ++
37003 ++config PAX_SYSCALL
37004 ++ bool
37005 ++ depends on PAX_PAGEEXEC && PPC32
37006 ++ default y
37007 ++
37008 ++config PAX_KERNEXEC
37009 ++ bool "Enforce non-executable kernel pages"
37010 ++ depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT
37011 ++ help
37012 ++ This is the kernel land equivalent of PAGEEXEC and MPROTECT,
37013 ++ that is, enabling this option will make it harder to inject
37014 ++ and execute 'foreign' code in kernel memory itself.
37015 ++
37016 ++endmenu
37017 ++
37018 ++menu "Address Space Layout Randomization"
37019 ++ depends on PAX
37020 ++
37021 ++config PAX_ASLR
37022 ++ bool "Address Space Layout Randomization"
37023 ++ depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
37024 ++ help
37025 ++ Many if not most exploit techniques rely on the knowledge of
37026 ++ certain addresses in the attacked program. The following options
37027 ++ will allow the kernel to apply a certain amount of randomization
37028 ++ to specific parts of the program thereby forcing an attacker to
37029 ++ guess them in most cases. Any failed guess will most likely crash
37030 ++ the attacked program which allows the kernel to detect such attempts
37031 ++ and react on them. PaX itself provides no reaction mechanisms,
37032 ++ instead it is strongly encouraged that you make use of Nergal's
37033 ++ segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
37034 ++ (http://www.grsecurity.net/) built-in crash detection features or
37035 ++ develop one yourself.
37036 ++
37037 ++ By saying Y here you can choose to randomize the following areas:
37038 ++ - top of the task's kernel stack
37039 ++ - top of the task's userland stack
37040 ++ - base address for mmap() requests that do not specify one
37041 ++ (this includes all libraries)
37042 ++ - base address of the main executable
37043 ++
37044 ++ It is strongly recommended to say Y here as address space layout
37045 ++ randomization has negligible impact on performance yet it provides
37046 ++ a very effective protection.
37047 ++
37048 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
37049 ++ this feature on a per file basis.
37050 ++
37051 ++config PAX_RANDKSTACK
37052 ++ bool "Randomize kernel stack base"
37053 ++ depends on PAX_ASLR && X86_TSC && X86_32
37054 ++ help
37055 ++ By saying Y here the kernel will randomize every task's kernel
37056 ++ stack on every system call. This will not only force an attacker
37057 ++ to guess it but also prevent him from making use of possible
37058 ++ leaked information about it.
37059 ++
37060 ++ Since the kernel stack is a rather scarce resource, randomization
37061 ++ may cause unexpected stack overflows, therefore you should very
37062 ++ carefully test your system. Note that once enabled in the kernel
37063 ++ configuration, this feature cannot be disabled on a per file basis.
37064 ++
37065 ++config PAX_RANDUSTACK
37066 ++ bool "Randomize user stack base"
37067 ++ depends on PAX_ASLR
37068 ++ help
37069 ++ By saying Y here the kernel will randomize every task's userland
37070 ++ stack. The randomization is done in two steps where the second
37071 ++ one may apply a big amount of shift to the top of the stack and
37072 ++ cause problems for programs that want to use lots of memory (more
37073 ++ than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
37074 ++ For this reason the second step can be controlled by 'chpax' or
37075 ++ 'paxctl' on a per file basis.
37076 ++
37077 ++config PAX_RANDMMAP
37078 ++ bool "Randomize mmap() base"
37079 ++ depends on PAX_ASLR
37080 ++ help
37081 ++ By saying Y here the kernel will use a randomized base address for
37082 ++ mmap() requests that do not specify one themselves. As a result
37083 ++ all dynamically loaded libraries will appear at random addresses
37084 ++ and therefore be harder to exploit by a technique where an attacker
37085 ++ attempts to execute library code for his purposes (e.g. spawn a
37086 ++ shell from an exploited program that is running at an elevated
37087 ++ privilege level).
37088 ++
37089 ++ Furthermore, if a program is relinked as a dynamic ELF file, its
37090 ++ base address will be randomized as well, completing the full
37091 ++ randomization of the address space layout. Attacking such programs
37092 ++ becomes a guess game. You can find an example of doing this at
37093 ++ http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
37094 ++ http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
37095 ++
37096 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
37097 ++ feature on a per file basis.
37098 ++
37099 ++endmenu
37100 ++
37101 ++menu "Miscellaneous hardening features"
37102 ++
37103 ++config PAX_MEMORY_SANITIZE
37104 ++ bool "Sanitize all freed memory"
37105 ++ help
37106 ++ By saying Y here the kernel will erase memory pages as soon as they
37107 ++ are freed. This in turn reduces the lifetime of data stored in the
37108 ++ pages, making it less likely that sensitive information such as
37109 ++ passwords, cryptographic secrets, etc stay in memory for too long.
37110 ++
37111 ++ This is especially useful for programs whose runtime is short, long
37112 ++ lived processes and the kernel itself benefit from this as long as
37113 ++ they operate on whole memory pages and ensure timely freeing of pages
37114 ++ that may hold sensitive information.
37115 ++
37116 ++ The tradeoff is performance impact, on a single CPU system kernel
37117 ++ compilation sees a 3% slowdown, other systems and workloads may vary
37118 ++ and you are advised to test this feature on your expected workload
37119 ++ before deploying it.
37120 ++
37121 ++ Note that this feature does not protect data stored in live pages,
37122 ++ e.g., process memory swapped to disk may stay there for a long time.
37123 ++
37124 ++config PAX_MEMORY_UDEREF
37125 ++ bool "Prevent invalid userland pointer dereference"
37126 ++ depends on X86_32 && !COMPAT_VDSO && !UML_X86
37127 ++ help
37128 ++ By saying Y here the kernel will be prevented from dereferencing
37129 ++ userland pointers in contexts where the kernel expects only kernel
37130 ++ pointers. This is both a useful runtime debugging feature and a
37131 ++ security measure that prevents exploiting a class of kernel bugs.
37132 ++
37133 ++ The tradeoff is that some virtualization solutions may experience
37134 ++ a huge slowdown and therefore you should not enable this feature
37135 ++ for kernels meant to run in such environments. Whether a given VM
37136 ++ solution is affected or not is best determined by simply trying it
37137 ++ out, the performance impact will be obvious right on boot as this
37138 ++ mechanism engages from very early on. A good rule of thumb is that
37139 ++ VMs running on CPUs without hardware virtualization support (i.e.,
37140 ++ the majority of IA-32 CPUs) will likely experience the slowdown.
37141 ++
37142 ++config PAX_REFCOUNT
37143 ++ bool "Prevent various kernel object reference counter overflows"
37144 ++ depends on X86
37145 ++ help
37146 ++ By saying Y here the kernel will detect and prevent overflowing
37147 ++ various (but not all) kinds of object reference counters. Such
37148 ++ overflows can normally occur due to bugs only and are often, if
37149 ++ not always, exploitable.
37150 ++
37151 ++ The tradeoff is that data structures protected by an oveflowed
37152 ++ refcount will never be freed and therefore will leak memory. Note
37153 ++ that this leak also happens even without this protection but in
37154 ++ that case the overflow can eventually trigger the freeing of the
37155 ++ data structure while it is still being used elsewhere, resulting
37156 ++ in the exploitable situation that this feature prevents.
37157 ++
37158 ++ Since this has a negligible performance impact, you should enable
37159 ++ this feature.
37160 ++endmenu
37161 ++
37162 ++endmenu
37163 ++
37164 + config KEYS
37165 + bool "Enable access key retention support"
37166 + help
37167 +diff -urNp linux-2.6.27.10/sound/core/oss/pcm_oss.c linux-2.6.27.10/sound/core/oss/pcm_oss.c
37168 +--- linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-07 12:55:34.000000000 -0500
37169 ++++ linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-18 03:38:45.000000000 -0500
37170 +@@ -2911,8 +2911,8 @@ static void snd_pcm_oss_proc_done(struct
37171 + }
37172 + }
37173 + #else /* !CONFIG_SND_VERBOSE_PROCFS */
37174 +-#define snd_pcm_oss_proc_init(pcm)
37175 +-#define snd_pcm_oss_proc_done(pcm)
37176 ++#define snd_pcm_oss_proc_init(pcm) do {} while (0)
37177 ++#define snd_pcm_oss_proc_done(pcm) do {} while (0)
37178 + #endif /* CONFIG_SND_VERBOSE_PROCFS */
37179 +
37180 + /*
37181 +diff -urNp linux-2.6.27.10/sound/core/seq/seq_lock.h linux-2.6.27.10/sound/core/seq/seq_lock.h
37182 +--- linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-07 12:55:34.000000000 -0500
37183 ++++ linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-18 03:38:45.000000000 -0500
37184 +@@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
37185 + #else /* SMP || CONFIG_SND_DEBUG */
37186 +
37187 + typedef spinlock_t snd_use_lock_t; /* dummy */
37188 +-#define snd_use_lock_init(lockp) /**/
37189 +-#define snd_use_lock_use(lockp) /**/
37190 +-#define snd_use_lock_free(lockp) /**/
37191 +-#define snd_use_lock_sync(lockp) /**/
37192 ++#define snd_use_lock_init(lockp) do {} while (0)
37193 ++#define snd_use_lock_use(lockp) do {} while (0)
37194 ++#define snd_use_lock_free(lockp) do {} while (0)
37195 ++#define snd_use_lock_sync(lockp) do {} while (0)
37196 +
37197 + #endif /* SMP || CONFIG_SND_DEBUG */
37198 +
37199 +diff -urNp linux-2.6.27.10/sound/pci/ac97/ac97_patch.c linux-2.6.27.10/sound/pci/ac97/ac97_patch.c
37200 +--- linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-07 12:55:34.000000000 -0500
37201 ++++ linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-18 03:38:45.000000000 -0500
37202 +@@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a
37203 + { AC97_VIDEO, 0x9f1f },
37204 + { AC97_AUX, 0x9f1f },
37205 + { AC97_PCM, 0x9f1f },
37206 +- { } /* terminator */
37207 ++ { 0, 0 } /* terminator */
37208 + };
37209 +
37210 + static int patch_ad1819(struct snd_ac97 * ac97)
37211 +@@ -3668,7 +3668,7 @@ static struct snd_ac97_res_table lm4550_
37212 + { AC97_AUX, 0x1f1f },
37213 + { AC97_PCM, 0x1f1f },
37214 + { AC97_REC_GAIN, 0x0f0f },
37215 +- { } /* terminator */
37216 ++ { 0, 0 } /* terminator */
37217 + };
37218 +
37219 + static int patch_lm4550(struct snd_ac97 *ac97)
37220 +diff -urNp linux-2.6.27.10/sound/pci/ens1370.c linux-2.6.27.10/sound/pci/ens1370.c
37221 +--- linux-2.6.27.10/sound/pci/ens1370.c 2008-11-07 12:55:34.000000000 -0500
37222 ++++ linux-2.6.27.10/sound/pci/ens1370.c 2008-11-18 03:38:45.000000000 -0500
37223 +@@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci
37224 + { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */
37225 + { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */
37226 + #endif
37227 +- { 0, }
37228 ++ { 0, 0, 0, 0, 0, 0, 0 }
37229 + };
37230 +
37231 + MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
37232 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0.c linux-2.6.27.10/sound/pci/intel8x0.c
37233 +--- linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-07 12:55:34.000000000 -0500
37234 ++++ linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-18 03:38:45.000000000 -0500
37235 +@@ -437,7 +437,7 @@ static struct pci_device_id snd_intel8x0
37236 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37237 + { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
37238 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37239 +- { 0, }
37240 ++ { 0, 0, 0, 0, 0, 0, 0 }
37241 + };
37242 +
37243 + MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
37244 +@@ -2076,7 +2076,7 @@ static struct ac97_quirk ac97_quirks[] _
37245 + .type = AC97_TUNE_HP_ONLY
37246 + },
37247 + #endif
37248 +- { } /* terminator */
37249 ++ { 0, 0, 0, 0, NULL, 0 } /* terminator */
37250 + };
37251 +
37252 + static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
37253 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0m.c linux-2.6.27.10/sound/pci/intel8x0m.c
37254 +--- linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-07 12:55:34.000000000 -0500
37255 ++++ linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-18 03:38:45.000000000 -0500
37256 +@@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0
37257 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37258 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37259 + #endif
37260 +- { 0, }
37261 ++ { 0, 0, 0, 0, 0, 0, 0 }
37262 + };
37263 +
37264 + MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
37265 +@@ -1257,7 +1257,7 @@ static struct shortname_table {
37266 + { 0x5455, "ALi M5455" },
37267 + { 0x746d, "AMD AMD8111" },
37268 + #endif
37269 +- { 0 },
37270 ++ { 0, NULL },
37271 + };
37272 +
37273 + static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
37274 +diff -urNp linux-2.6.27.10/virt/kvm/kvm_main.c linux-2.6.27.10/virt/kvm/kvm_main.c
37275 +--- linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-07 12:55:34.000000000 -0500
37276 ++++ linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-18 03:38:45.000000000 -0500
37277 +@@ -1469,6 +1469,9 @@ static struct miscdevice kvm_dev = {
37278 + KVM_MINOR,
37279 + "kvm",
37280 + &kvm_chardev_ops,
37281 ++ {NULL, NULL},
37282 ++ NULL,
37283 ++ NULL
37284 + };
37285 +
37286 + static void hardware_enable(void *junk)
37287
37288 Added: hardened/2.6/tags/2.6.27-6/4421_grsec-remove-localversion-grsec.patch
37289 ===================================================================
37290 --- hardened/2.6/tags/2.6.27-6/4421_grsec-remove-localversion-grsec.patch (rev 0)
37291 +++ hardened/2.6/tags/2.6.27-6/4421_grsec-remove-localversion-grsec.patch 2009-01-24 20:35:40 UTC (rev 1483)
37292 @@ -0,0 +1,9 @@
37293 +From: Kerin Millar <kerframil@×××××.com>
37294 +
37295 +Remove grsecurity's localversion-grsec file as it is inconsistent with
37296 +Gentoo's kernel practices and naming scheme.
37297 +
37298 +--- a/localversion-grsec 2008-02-24 14:26:59.000000000 +0000
37299 ++++ b/localversion-grsec 1970-01-01 01:00:00.000000000 +0100
37300 +@@ -1 +0,0 @@
37301 +--grsec
37302
37303 Added: hardened/2.6/tags/2.6.27-6/4422_grsec-mute-warnings.patch
37304 ===================================================================
37305 --- hardened/2.6/tags/2.6.27-6/4422_grsec-mute-warnings.patch (rev 0)
37306 +++ hardened/2.6/tags/2.6.27-6/4422_grsec-mute-warnings.patch 2009-01-24 20:35:40 UTC (rev 1483)
37307 @@ -0,0 +1,28 @@
37308 +From: Gordon Malm <gengor@g.o>
37309 +
37310 +Updated patch for kernel series 2.6.24.
37311 +
37312 +The credits/description from the original version of this patch remain accurate
37313 +and are included below.
37314 +
37315 +---
37316 +From: Alexander Gabert <gaberta@××××××××.de>
37317 +
37318 +This patch removes the warnings introduced by grsec patch 2.1.9 and later.
37319 +It removes the -W options added by the patch and restores the original
37320 +warning flags of vanilla kernel versions.
37321 +
37322 +Acked-by: Christian Heim <phreak@g.o>
37323 +---
37324 +
37325 +--- a/Makefile
37326 ++++ b/Makefile
37327 +@@ -214,7 +214,7 @@
37328 +
37329 + HOSTCC = gcc
37330 + HOSTCXX = g++
37331 +-HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
37332 ++HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
37333 + HOSTCXXFLAGS = -O2
37334 +
37335 + # Decide whether to build built-in, modular, or both.
37336
37337 Added: hardened/2.6/tags/2.6.27-6/4425_grsec-pax-without-grsec.patch
37338 ===================================================================
37339 --- hardened/2.6/tags/2.6.27-6/4425_grsec-pax-without-grsec.patch (rev 0)
37340 +++ hardened/2.6/tags/2.6.27-6/4425_grsec-pax-without-grsec.patch 2009-01-24 20:35:40 UTC (rev 1483)
37341 @@ -0,0 +1,47 @@
37342 +From: Gordon Malm <gengor@g.o>
37343 +
37344 +Allow PaX options to be selected without first selecting CONFIG_GRKERNSEC.
37345 +
37346 +This patch has been updated to keep current with newer kernel versions.
37347 +The original version of this patch contained no credits/description.
37348 +
37349 +--- a/arch/x86/mm/fault.c
37350 ++++ b/arch/x86/mm/fault.c
37351 +@@ -433,10 +433,12 @@ static void show_fault_oops(struct pt_re
37352 + if (init_mm.start_code <= address && address < init_mm.end_code)
37353 + #endif
37354 + {
37355 ++#ifdef CONFIG_GRKERNSEC
37356 + if (current->signal->curr_ip)
37357 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37358 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37359 + else
37360 ++#endif
37361 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37362 + current->comm, task_pid_nr(current), current->uid, current->euid);
37363 + }
37364 +--- a/fs/exec.c
37365 ++++ b/fs/exec.c
37366 +@@ -1691,9 +1691,11 @@ void pax_report_fault(struct pt_regs *re
37367 + }
37368 + up_read(&mm->mmap_sem);
37369 + }
37370 ++#ifdef CONFIG_GRKERNSEC
37371 + if (tsk->signal->curr_ip)
37372 + 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);
37373 + else
37374 ++#endif
37375 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
37376 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
37377 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
37378 +--- a/security/Kconfig
37379 ++++ b/security/Kconfig
37380 +@@ -10,7 +10,7 @@ menu "PaX"
37381 +
37382 + config PAX
37383 + bool "Enable various PaX features"
37384 +- depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37385 ++ depends on (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37386 + help
37387 + This allows you to enable various PaX features. PaX adds
37388 + intrusion prevention mechanisms to the kernel that reduce
37389
37390 Added: hardened/2.6/tags/2.6.27-6/4430_grsec-kconfig-default-gids.patch
37391 ===================================================================
37392 --- hardened/2.6/tags/2.6.27-6/4430_grsec-kconfig-default-gids.patch (rev 0)
37393 +++ hardened/2.6/tags/2.6.27-6/4430_grsec-kconfig-default-gids.patch 2009-01-24 20:35:40 UTC (rev 1483)
37394 @@ -0,0 +1,76 @@
37395 +From: Kerin Millar <kerframil@×××××.com>
37396 +
37397 +grsecurity contains a number of options which allow certain protections
37398 +to be applied to or exempted from members of a given group. However, the
37399 +default GIDs specified in the upstream patch are entirely arbitrary and
37400 +there is no telling which (if any) groups the GIDs will correlate with
37401 +on an end-user's system. Because some users don't pay a great deal of
37402 +attention to the finer points of kernel configuration, it is probably
37403 +wise to specify some reasonable defaults so as to stop careless users
37404 +from shooting themselves in the foot.
37405 +
37406 +--- a/grsecurity/Kconfig
37407 ++++ b/grsecurity/Kconfig
37408 +@@ -352,7 +564,7 @@
37409 + config GRKERNSEC_PROC_GID
37410 + int "GID for special group"
37411 + depends on GRKERNSEC_PROC_USERGROUP
37412 +- default 1001
37413 ++ default 10
37414 +
37415 + config GRKERNSEC_PROC_ADD
37416 + bool "Additional restrictions"
37417 +@@ -547,7 +759,7 @@
37418 + config GRKERNSEC_AUDIT_GID
37419 + int "GID for auditing"
37420 + depends on GRKERNSEC_AUDIT_GROUP
37421 +- default 1007
37422 ++ default 100
37423 +
37424 + config GRKERNSEC_EXECLOG
37425 + bool "Exec logging"
37426 +@@ -700,7 +912,7 @@
37427 + config GRKERNSEC_TPE_GID
37428 + int "GID for untrusted users"
37429 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
37430 +- default 1005
37431 ++ default 100
37432 + help
37433 + If you have selected the "Invert GID option" above, setting this
37434 + GID determines what group TPE restrictions will be *disabled* for.
37435 +@@ -712,7 +924,7 @@
37436 + config GRKERNSEC_TPE_GID
37437 + int "GID for trusted users"
37438 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
37439 +- default 1005
37440 ++ default 10
37441 + help
37442 + If you have selected the "Invert GID option" above, setting this
37443 + GID determines what group TPE restrictions will be *disabled* for.
37444 +@@ -754,7 +966,7 @@
37445 + config GRKERNSEC_SOCKET_ALL_GID
37446 + int "GID to deny all sockets for"
37447 + depends on GRKERNSEC_SOCKET_ALL
37448 +- default 1004
37449 ++ default 65534
37450 + help
37451 + Here you can choose the GID to disable socket access for. Remember to
37452 + add the users you want socket access disabled for to the GID
37453 +@@ -775,7 +987,7 @@
37454 + config GRKERNSEC_SOCKET_CLIENT_GID
37455 + int "GID to deny client sockets for"
37456 + depends on GRKERNSEC_SOCKET_CLIENT
37457 +- default 1003
37458 ++ default 65534
37459 + help
37460 + Here you can choose the GID to disable client socket access for.
37461 + Remember to add the users you want client socket access disabled for to
37462 +@@ -793,7 +1005,7 @@
37463 + config GRKERNSEC_SOCKET_SERVER_GID
37464 + int "GID to deny server sockets for"
37465 + depends on GRKERNSEC_SOCKET_SERVER
37466 +- default 1002
37467 ++ default 65534
37468 + help
37469 + Here you can choose the GID to disable server socket access for.
37470 + Remember to add the users you want server socket access disabled for to
37471
37472 Added: hardened/2.6/tags/2.6.27-6/4435_grsec-kconfig-gentoo.patch
37473 ===================================================================
37474 --- hardened/2.6/tags/2.6.27-6/4435_grsec-kconfig-gentoo.patch (rev 0)
37475 +++ hardened/2.6/tags/2.6.27-6/4435_grsec-kconfig-gentoo.patch 2009-01-24 20:35:40 UTC (rev 1483)
37476 @@ -0,0 +1,243 @@
37477 +From: Gordon Malm <gengor@g.o>
37478 +From: Kerin Millar <kerframil@×××××.com>
37479 +
37480 +Add Hardened Gentoo [server/workstation] predefined grsecurity
37481 +levels. They're designed to provide a comparitively high level of
37482 +security while remaining generally suitable for as great a majority
37483 +of the userbase as possible (particularly new users).
37484 +
37485 +Make Hardened Gentoo [workstation] predefined grsecurity level the
37486 +default. The Hardened Gentoo [server] level is more restrictive
37487 +and conflicts with some software and thus would be less suitable.
37488 +
37489 +The original version of this patch was conceived and created by:
37490 +Ned Ludd <solar@g.o>
37491 +
37492 +--- a/grsecurity/Kconfig
37493 ++++ b/grsecurity/Kconfig
37494 +@@ -20,7 +20,7 @@ config GRKERNSEC
37495 + choice
37496 + prompt "Security Level"
37497 + depends on GRKERNSEC
37498 +- default GRKERNSEC_CUSTOM
37499 ++ default GRKERNSEC_HARDENED_WORKSTATION
37500 +
37501 + config GRKERNSEC_LOW
37502 + bool "Low"
37503 +@@ -183,6 +183,216 @@ config GRKERNSEC_HIGH
37504 + - Mount/unmount/remount logging
37505 + - Kernel symbol hiding
37506 + - Prevention of memory exhaustion-based exploits
37507 ++
37508 ++config GRKERNSEC_HARDENED_SERVER
37509 ++ bool "Hardened Gentoo [server]"
37510 ++ select GRKERNSEC_AUDIT_MOUNT
37511 ++ select GRKERNSEC_BRUTE
37512 ++ select GRKERNSEC_CHROOT
37513 ++ select GRKERNSEC_CHROOT_CAPS
37514 ++ select GRKERNSEC_CHROOT_CHDIR
37515 ++ select GRKERNSEC_CHROOT_CHMOD
37516 ++ select GRKERNSEC_CHROOT_DOUBLE
37517 ++ select GRKERNSEC_CHROOT_FCHDIR
37518 ++ select GRKERNSEC_CHROOT_FINDTASK
37519 ++ select GRKERNSEC_CHROOT_MKNOD
37520 ++ select GRKERNSEC_CHROOT_MOUNT
37521 ++ select GRKERNSEC_CHROOT_NICE
37522 ++ select GRKERNSEC_CHROOT_PIVOT
37523 ++ select GRKERNSEC_CHROOT_SHMAT
37524 ++ select GRKERNSEC_CHROOT_SYSCTL
37525 ++ select GRKERNSEC_CHROOT_UNIX
37526 ++ select GRKERNSEC_DMESG
37527 ++ select GRKERNSEC_EXECVE
37528 ++ select GRKERNSEC_FIFO
37529 ++ select GRKERNSEC_FORKFAIL
37530 ++ select GRKERNSEC_HIDESYM
37531 ++ select GRKERNSEC_IO if (X86)
37532 ++ select GRKERNSEC_KMEM
37533 ++ select GRKERNSEC_LINK
37534 ++ select GRKERNSEC_MODSTOP if (MODULES)
37535 ++ select GRKERNSEC_PROC
37536 ++ select GRKERNSEC_PROC_ADD
37537 ++ select GRKERNSEC_PROC_IPADDR
37538 ++ select GRKERNSEC_PROC_MEMMAP
37539 ++ select GRKERNSEC_PROC_USERGROUP
37540 ++ select GRKERNSEC_RANDNET
37541 ++ select GRKERNSEC_RESLOG
37542 ++ select GRKERNSEC_SIGNAL
37543 ++# select GRKERNSEC_SOCKET
37544 ++# select GRKERNSEC_SOCKET_SERVER
37545 ++ select GRKERNSEC_SYSCTL
37546 ++ select GRKERNSEC_SYSCTL_ON
37547 ++ select GRKERNSEC_TIME
37548 ++ select PAX
37549 ++ select PAX_ASLR
37550 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37551 ++ select PAX_EI_PAX
37552 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37553 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37554 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37555 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37556 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
37557 ++ select PAX_MEMORY_SANITIZE
37558 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37559 ++ select PAX_MPROTECT if (!PPC64)
37560 ++ select PAX_HAVE_ACL_FLAGS
37561 ++ select PAX_NOELFRELOCS if (X86)
37562 ++ select PAX_NOEXEC
37563 ++ select PAX_PAGEEXEC
37564 ++ select PAX_PT_PAX_FLAGS
37565 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37566 ++ select PAX_RANDMMAP
37567 ++ select PAX_RANDUSTACK
37568 ++ select PAX_REFCOUNT if (X86)
37569 ++ select PAX_SEGMEXEC if (X86_32)
37570 ++ select PAX_SYSCALL if (PPC32)
37571 ++ help
37572 ++ If you say Y here, a configuration will be used that is endorsed by
37573 ++ the Hardened Gentoo project. Therefore, many of the protections
37574 ++ made available by grsecurity and PaX will be enabled.
37575 ++
37576 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37577 ++ a high level of security while minimizing incompatibilities with the
37578 ++ majority of available software. For further information, please
37579 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37580 ++ well as the Hardened Gentoo Primer at
37581 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37582 ++
37583 ++ This Hardened Gentoo [server] level is identical to the
37584 ++ Hardened Gentoo [workstation] level, but with the GRKERNSEC_IO,
37585 ++ PAX_KERNEXEC and PAX_NOELFRELOCS security features enabled.
37586 ++ Accordingly, this is the preferred security level if the system will
37587 ++ not be utilizing software incompatible with the aforementioned
37588 ++ grsecurity/PaX features.
37589 ++
37590 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37591 ++ PaX features on problematic binaries on an individual basis. Note that
37592 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37593 ++ Translated, this means that if you wish to toggle PaX features on
37594 ++ binaries provided by applications that are distributed only in binary
37595 ++ format (rather than being built locally from sources), you will need to
37596 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37597 ++ headers.
37598 ++
37599 ++ When this level is selected, some options cannot be changed. However,
37600 ++ you may opt to fully customize the options that are selected by
37601 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37602 ++ to inherit the options selected by the "Hardened Gentoo [server]"
37603 ++ security level as a starting point for further configuration. To
37604 ++ accomplish this, select this security level then exit the menuconfig
37605 ++ interface, saving changes when prompted. Then, run make menuconfig
37606 ++ again and select the "Custom" level.
37607 ++
37608 ++ Note that this security level probably should not be used if the
37609 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37610 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37611 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37612 ++ impact on performance.
37613 ++
37614 ++config GRKERNSEC_HARDENED_WORKSTATION
37615 ++ bool "Hardened Gentoo [workstation]"
37616 ++ select GRKERNSEC_AUDIT_MOUNT
37617 ++ select GRKERNSEC_BRUTE
37618 ++ select GRKERNSEC_CHROOT
37619 ++ select GRKERNSEC_CHROOT_CAPS
37620 ++ select GRKERNSEC_CHROOT_CHDIR
37621 ++ select GRKERNSEC_CHROOT_CHMOD
37622 ++ select GRKERNSEC_CHROOT_DOUBLE
37623 ++ select GRKERNSEC_CHROOT_FCHDIR
37624 ++ select GRKERNSEC_CHROOT_FINDTASK
37625 ++ select GRKERNSEC_CHROOT_MKNOD
37626 ++ select GRKERNSEC_CHROOT_MOUNT
37627 ++ select GRKERNSEC_CHROOT_NICE
37628 ++ select GRKERNSEC_CHROOT_PIVOT
37629 ++ select GRKERNSEC_CHROOT_SHMAT
37630 ++ select GRKERNSEC_CHROOT_SYSCTL
37631 ++ select GRKERNSEC_CHROOT_UNIX
37632 ++ select GRKERNSEC_DMESG
37633 ++ select GRKERNSEC_EXECVE
37634 ++ select GRKERNSEC_FIFO
37635 ++ select GRKERNSEC_FORKFAIL
37636 ++ select GRKERNSEC_HIDESYM
37637 ++ select GRKERNSEC_KMEM
37638 ++ select GRKERNSEC_LINK
37639 ++ select GRKERNSEC_MODSTOP if (MODULES)
37640 ++ select GRKERNSEC_PROC
37641 ++ select GRKERNSEC_PROC_ADD
37642 ++ select GRKERNSEC_PROC_IPADDR
37643 ++ select GRKERNSEC_PROC_MEMMAP
37644 ++ select GRKERNSEC_PROC_USERGROUP
37645 ++ select GRKERNSEC_RANDNET
37646 ++ select GRKERNSEC_RESLOG
37647 ++ select GRKERNSEC_SIGNAL
37648 ++# select GRKERNSEC_SOCKET
37649 ++# select GRKERNSEC_SOCKET_SERVER
37650 ++ select GRKERNSEC_SYSCTL
37651 ++ select GRKERNSEC_SYSCTL_ON
37652 ++ select GRKERNSEC_TIME
37653 ++ select PAX
37654 ++ select PAX_ASLR
37655 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37656 ++ select PAX_EI_PAX
37657 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37658 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37659 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37660 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37661 ++ select PAX_MEMORY_SANITIZE
37662 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37663 ++ select PAX_MPROTECT if (!PPC64)
37664 ++ select PAX_HAVE_ACL_FLAGS
37665 ++ select PAX_NOEXEC
37666 ++ select PAX_PAGEEXEC
37667 ++ select PAX_PT_PAX_FLAGS
37668 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37669 ++ select PAX_RANDMMAP
37670 ++ select PAX_RANDUSTACK
37671 ++ select PAX_REFCOUNT if (X86)
37672 ++ select PAX_SEGMEXEC if (X86_32)
37673 ++ select PAX_SYSCALL if (PPC32)
37674 ++ help
37675 ++ If you say Y here, a configuration will be used that is endorsed by
37676 ++ the Hardened Gentoo project. Therefore, many of the protections
37677 ++ made available by grsecurity and PaX will be enabled.
37678 ++
37679 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37680 ++ a high level of security while minimizing incompatibilities with the
37681 ++ majority of available software. For further information, please
37682 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37683 ++ well as the Hardened Gentoo Primer at
37684 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37685 ++
37686 ++ This Hardened Gentoo [workstation] level is designed for machines
37687 ++ which are intended to run software not compatible with the
37688 ++ GRKERNSEC_IO, PAX_KERNEXEC and PAX_NOELFRELOCS features of grsecurity.
37689 ++ Accordingly, this security level is suitable for use with the X server
37690 ++ "Xorg" and/or any system that will act as host OS to the virtualization
37691 ++ softwares vmware-server or virtualbox.
37692 ++
37693 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37694 ++ PaX features on problematic binaries on an individual basis. Note that
37695 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37696 ++ Translated, this means that if you wish to toggle PaX features on
37697 ++ binaries provided by applications that are distributed only in binary
37698 ++ format (rather than being built locally from sources), you will need to
37699 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37700 ++ headers.
37701 ++
37702 ++ When this level is selected, some options cannot be changed. However,
37703 ++ you may opt to fully customize the options that are selected by
37704 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37705 ++ to inherit the options selected by the "Hardened Gentoo [workstation]"
37706 ++ security level as a starting point for further configuration. To
37707 ++ accomplish this, select this security level then exit the menuconfig
37708 ++ interface, saving changes when prompted. Then, run make menuconfig
37709 ++ again and select the "Custom" level.
37710 ++
37711 ++ Note that this security level probably should not be used if the
37712 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37713 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37714 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37715 ++ impact on performance.
37716 ++
37717 + config GRKERNSEC_CUSTOM
37718 + bool "Custom"
37719 + help
37720
37721 Added: hardened/2.6/tags/2.6.27-6/4440_selinux-avc_audit-log-curr_ip.patch
37722 ===================================================================
37723 --- hardened/2.6/tags/2.6.27-6/4440_selinux-avc_audit-log-curr_ip.patch (rev 0)
37724 +++ hardened/2.6/tags/2.6.27-6/4440_selinux-avc_audit-log-curr_ip.patch 2009-01-24 20:35:40 UTC (rev 1483)
37725 @@ -0,0 +1,65 @@
37726 +From: Gordon Malm <gengor@g.o>
37727 +
37728 +This is a reworked version of the original
37729 +*_selinux-avc_audit-log-curr_ip.patch carried in earlier releases of
37730 +hardened-sources.
37731 +
37732 +Dropping the patch, or simply fixing the #ifdef of the original patch
37733 +could break automated logging setups so this route was necessary.
37734 +
37735 +Suggestions for improving the help text are welcome.
37736 +
37737 +The original patch's description is still accurate and included below.
37738 +
37739 +---
37740 +Provides support for a new field ipaddr within the SELinux
37741 +AVC audit log, relying in task_struct->curr_ip (ipv4 only)
37742 +provided by grSecurity patch to be applied before.
37743 +
37744 +Signed-off-by: Lorenzo Hernandez Garcia-Hierro <lorenzo@×××.org>
37745 +---
37746 +
37747 +--- a/grsecurity/Kconfig
37748 ++++ b/grsecurity/Kconfig
37749 +@@ -1044,6 +1044,27 @@ endmenu
37750 + menu "Logging Options"
37751 + depends on GRKERNSEC
37752 +
37753 ++config GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37754 ++ def_bool n
37755 ++ prompt "Add source IP address to SELinux AVC log messages"
37756 ++ depends on GRKERNSEC && SECURITY_SELINUX
37757 ++ help
37758 ++ If you say Y here, a new field "ipaddr=" will be added to many SELinux
37759 ++ AVC log messages. The value of this field in any given message
37760 ++ represents the source IP address of the remote machine/user that created
37761 ++ the offending process.
37762 ++
37763 ++ This information is sourced from task_struct->curr_ip provided by
37764 ++ grsecurity's GRKERNSEC top-level configuration option. One limitation
37765 ++ is that only IPv4 is supported.
37766 ++
37767 ++ In many instances SELinux AVC log messages already log a superior level
37768 ++ of information that also includes source port and destination ip/port.
37769 ++ Additionally, SELinux's AVC log code supports IPv6.
37770 ++
37771 ++ However, grsecurity's task_struct->curr_ip will sometimes (often?)
37772 ++ provide the offender's IP address where stock SELinux logging fails to.
37773 ++
37774 + config GRKERNSEC_FLOODTIME
37775 + int "Seconds in between log messages (minimum)"
37776 + default 10
37777 +--- a/security/selinux/avc.c
37778 ++++ b/security/selinux/avc.c
37779 +@@ -202,6 +202,11 @@ static void avc_dump_query(struct audit_
37780 + char *scontext;
37781 + u32 scontext_len;
37782 +
37783 ++#ifdef CONFIG_GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37784 ++ if (current->signal->curr_ip)
37785 ++ audit_log_format(ab, "ipaddr=%u.%u.%u.%u ", NIPQUAD(current->signal->curr_ip));
37786 ++#endif
37787 ++
37788 + rc = security_sid_to_context(ssid, &scontext, &scontext_len);
37789 + if (rc)
37790 + audit_log_format(ab, "ssid=%d", ssid);
37791
37792 Added: hardened/2.6/tags/2.6.27-6/4445_disable-compat_vdso.patch
37793 ===================================================================
37794 --- hardened/2.6/tags/2.6.27-6/4445_disable-compat_vdso.patch (rev 0)
37795 +++ hardened/2.6/tags/2.6.27-6/4445_disable-compat_vdso.patch 2009-01-24 20:35:40 UTC (rev 1483)
37796 @@ -0,0 +1,74 @@
37797 +From: Gordon Malm <gengor@g.o>
37798 +From: Kerin Millar <kerframil@×××××.com>
37799 +
37800 +COMPAT_VDSO is inappropriate for any modern Hardened Gentoo system. It
37801 +conflicts with various parts of PaX, crashing the system if enabled
37802 +while PaX's NOEXEC or UDEREF features are active. Moreover, it prevents
37803 +a number of important PaX options from appearing in the configuration
37804 +menu, including all PaX NOEXEC implementations. Unfortunately, the
37805 +reason for the disappearance of these PaX configuration options is
37806 +often far from obvious to inexperienced users.
37807 +
37808 +Therefore, we disable the COMPAT_VDSO menu entry entirely. However,
37809 +COMPAT_VDSO operation can still be enabled via bootparam and sysctl
37810 +interfaces. Consequently, we must also disable the ability to select
37811 +COMPAT_VDSO operation at boot or runtime. Here we patch the kernel so
37812 +that selecting COMPAT_VDSO operation at boot/runtime has no effect if
37813 +conflicting PaX options are enabled, leaving VDSO_ENABLED operation
37814 +intact.
37815 +
37816 +Closes bug: http://bugs.gentoo.org/show_bug.cgi?id=210138
37817 +
37818 +--- a/arch/x86/Kconfig
37819 ++++ b/arch/x86/Kconfig
37820 +@@ -1215,16 +1215,7 @@ config HOTPLUG_CPU
37821 +
37822 + config COMPAT_VDSO
37823 + def_bool n
37824 +- prompt "Compat VDSO support"
37825 + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
37826 +- help
37827 +- Map the 32-bit VDSO to the predictable old-style address too.
37828 +- ---help---
37829 +- Say N here if you are running a sufficiently recent glibc
37830 +- version (2.3.3 or later), to remove the high-mapped
37831 +- VDSO mapping and to exclusively use the randomized VDSO.
37832 +-
37833 +- If unsure, say Y.
37834 +
37835 + endmenu
37836 +
37837 +--- a/arch/x86/vdso/vdso32-setup.c
37838 ++++ b/arch/x86/vdso/vdso32-setup.c
37839 +@@ -333,17 +333,21 @@ int arch_setup_additional_pages(struct l
37840 +
37841 + map_compat_vdso(compat);
37842 +
37843 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37844 + if (compat)
37845 + addr = VDSO_HIGH_BASE;
37846 + else {
37847 ++#endif
37848 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
37849 + if (IS_ERR_VALUE(addr)) {
37850 + ret = addr;
37851 + goto up_fail;
37852 + }
37853 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37854 + }
37855 +
37856 + if (compat_uses_vma || !compat) {
37857 ++#endif
37858 + /*
37859 + * MAYWRITE to allow gdb to COW and set breakpoints
37860 + *
37861 +@@ -361,7 +365,9 @@ int arch_setup_additional_pages(struct l
37862 +
37863 + if (ret)
37864 + goto up_fail;
37865 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37866 + }
37867 ++#endif
37868 +
37869 + current->mm->context.vdso = addr;
37870 + current_thread_info()->sysenter_return =
37871
37872 Added: hardened/2.6/tags/2.6.27-6/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
37873 ===================================================================
37874 --- hardened/2.6/tags/2.6.27-6/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch (rev 0)
37875 +++ hardened/2.6/tags/2.6.27-6/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch 2009-01-24 20:35:40 UTC (rev 1483)
37876 @@ -0,0 +1,21 @@
37877 +From: Gordon Malm <gengor@g.o>
37878 +
37879 +Add offender's IP to PAX_REFCOUNT log messages if it is available.
37880 +
37881 +--- a/fs/exec.c
37882 ++++ b/fs/exec.c
37883 +@@ -1710,7 +1710,13 @@ void pax_report_fault(struct pt_regs *re
37884 + #ifdef CONFIG_PAX_REFCOUNT
37885 + void pax_report_refcount_overflow(struct pt_regs *regs)
37886 + {
37887 +- printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37888 ++#ifdef CONFIG_GRKERNSEC
37889 ++ if (current->signal->curr_ip)
37890 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37891 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37892 ++ else
37893 ++#endif
37894 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37895 + current->comm, task_pid_nr(current), current->uid, current->euid);
37896 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
37897 + show_registers(regs);
37898
37899 Added: hardened/2.6/tags/2.6.27-6/4455_pax-2.6.27.10-test29-to-test30.patch
37900 ===================================================================
37901 --- hardened/2.6/tags/2.6.27-6/4455_pax-2.6.27.10-test29-to-test30.patch (rev 0)
37902 +++ hardened/2.6/tags/2.6.27-6/4455_pax-2.6.27.10-test29-to-test30.patch 2009-01-24 20:35:40 UTC (rev 1483)
37903 @@ -0,0 +1,19 @@
37904 +From: Gordon Malm <gengor@g.o>
37905 +
37906 +PaX: Add changes from pax-2.6.27.11-test30 which are not
37907 +integrated into main grsecurity-2.6.27.X patch.
37908 +
37909 +--- a/arch/x86/mm/ioremap.c
37910 ++++ b/arch/x86/mm/ioremap.c
37911 +@@ -449,7 +449,11 @@ static inline pmd_t * __init early_iorem
37912 +
37913 + static inline pte_t * __init early_ioremap_pte(unsigned long addr)
37914 + {
37915 ++#ifdef CONFIG_X86_32
37916 + return &bm_pte[pte_index(addr)];
37917 ++#else
37918 ++ return &level1_fixmap_pgt[pte_index(addr)];
37919 ++#endif
37920 + }
37921 +
37922 + void __init early_ioremap_init(void)
37923
37924 Added: hardened/2.6/tags/2.6.27-6/4460_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
37925 ===================================================================
37926 --- hardened/2.6/tags/2.6.27-6/4460_pax-revert-fix-false-RLIMIT_STACK-warnings.patch (rev 0)
37927 +++ hardened/2.6/tags/2.6.27-6/4460_pax-revert-fix-false-RLIMIT_STACK-warnings.patch 2009-01-24 20:35:40 UTC (rev 1483)
37928 @@ -0,0 +1,33 @@
37929 +From: Gordon Malm <gengor@g.o>
37930 +
37931 +Revert RLIMIT_STACK false-positives-avoidance change in PaX for now.
37932 +
37933 +Fixes random segmentation faults, bugs 253773 and 254843.
37934 +
37935 +--- a/arch/x86/mm/fault.c
37936 ++++ b/arch/x86/mm/fault.c
37937 +@@ -852,14 +852,16 @@ not_pax_fault:
37938 + goto good_area;
37939 + if (!(vma->vm_flags & VM_GROWSDOWN))
37940 + goto bad_area;
37941 +- /*
37942 +- * Accessing the stack below %sp is always a bug.
37943 +- * The large cushion allows instructions like enter
37944 +- * and pusha to work. ("enter $65535,$31" pushes
37945 +- * 32 pointers and then decrements %sp by 65535.)
37946 +- */
37947 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
37948 +- goto bad_area;
37949 ++ if (error_code & PF_USER) {
37950 ++ /*
37951 ++ * Accessing the stack below %sp is always a bug.
37952 ++ * The large cushion allows instructions like enter
37953 ++ * and pusha to work. ("enter $65535,$31" pushes
37954 ++ * 32 pointers and then decrements %sp by 65535.)
37955 ++ */
37956 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
37957 ++ goto bad_area;
37958 ++ }
37959 +
37960 + #ifdef CONFIG_PAX_SEGMEXEC
37961 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)