Gentoo Archives: gentoo-commits

From: "Gordon Malm (gengor)" <gengor@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1480 - in hardened/2.6/tags: . 2.6.27-5
Date: Tue, 20 Jan 2009 21:36:22
Message-Id: E1LPOCa-0004tz-U2@stork.gentoo.org
1 Author: gengor
2 Date: 2009-01-20 21:32:04 +0000 (Tue, 20 Jan 2009)
3 New Revision: 1480
4
5 Added:
6 hardened/2.6/tags/2.6.27-5/
7 hardened/2.6/tags/2.6.27-5/0000_README
8 hardened/2.6/tags/2.6.27-5/1500_sctp-avoid_memory_overflow_with_bad_stream_ID.patch
9 hardened/2.6/tags/2.6.27-5/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
10 hardened/2.6/tags/2.6.27-5/4421_grsec-remove-localversion-grsec.patch
11 hardened/2.6/tags/2.6.27-5/4422_grsec-mute-warnings.patch
12 hardened/2.6/tags/2.6.27-5/4425_grsec-pax-without-grsec.patch
13 hardened/2.6/tags/2.6.27-5/4430_grsec-kconfig-default-gids.patch
14 hardened/2.6/tags/2.6.27-5/4435_grsec-kconfig-gentoo.patch
15 hardened/2.6/tags/2.6.27-5/4440_selinux-avc_audit-log-curr_ip.patch
16 hardened/2.6/tags/2.6.27-5/4445_disable-compat_vdso.patch
17 hardened/2.6/tags/2.6.27-5/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
18 Log:
19 Tag 2.6.27-5 hardened-extras patchset
20
21 Added: hardened/2.6/tags/2.6.27-5/0000_README
22 ===================================================================
23 --- hardened/2.6/tags/2.6.27-5/0000_README (rev 0)
24 +++ hardened/2.6/tags/2.6.27-5/0000_README 2009-01-20 21:32:04 UTC (rev 1480)
25 @@ -0,0 +1,51 @@
26 +README
27 +-----------------------------------------------------------------------------
28 +
29 +Individual Patch Descriptions:
30 +-----------------------------------------------------------------------------
31 +Patch: 1500_sctp-avoid_memory_overflow_with_bad_stream_ID.patch
32 +From: Wei Yongjun <yjwei@××××××××××.com>
33 +Desc: Avoid memory overflow while FWD-TSN chunk received with bad stream ID
34 + (bug #254907)
35 +
36 +Patch: 4420_grsec-2.1.12-2.6.27.10-200812271347.patch
37 +From: http://www.grsecurity.net
38 +Desc: hardened-sources base patch from upstream grsecurity
39 +
40 +Patch: 4421_grsec-remove-localversion-grsec.patch
41 +From: Kerin Millar <kerframil@×××××.com>
42 +Desc: Removes grsecurity's localversion-grsec file
43 +
44 +Patch: 4422_grsec-mute-warnings.patch
45 +From: Alexander Gabert <gaberta@××××××××.de>
46 + Gordon Malm <gengor@g.o>
47 +Desc: Removes verbose compile warning settings from grsecurity, restores
48 + mainline Linux kernel behavior
49 +
50 +Patch: 4425_grsec-pax-without-grsec.patch
51 +From: Gordon Malm <gengor@g.o>
52 +Desc: Allows PaX features to be selected without enabling GRKERNSEC
53 +
54 +Patch: 4430_grsec-kconfig-default-gids.patch
55 +From: Kerin Millar <kerframil@×××××.com>
56 +Desc: Sets sane(r) default GIDs on various grsecurity group-dependent
57 + features
58 +
59 +Patch: 4435_grsec-kconfig-gentoo.patch
60 +From: Gordon Malm <gengor@g.o>
61 + Kerin Millar <kerframil@×××××.com>
62 +Desc: Adds Hardened Gentoo [server/workstation] security levels, sets
63 + Hardened Gentoo [workstation] as default
64 +
65 +Patch: 4440_selinux-avc_audit-log-curr_ip.patch
66 +From: Gordon Malm <gengor@g.o>
67 +Desc: Configurable option to add src IP address to SELinux log messages
68 +
69 +Patch: 4445_disable-compat_vdso.patch
70 +From: Gordon Malm <gengor@g.o>
71 + Kerin Millar <kerframil@×××××.com>
72 +Desc: Disables VDSO_COMPAT operation completely
73 +
74 +Patch: 4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
75 +From: Gordon Malm <gengor@g.o>
76 +Desc: Add offender's IP to PAX_REFCOUNT log messages if it is available
77
78 Added: hardened/2.6/tags/2.6.27-5/1500_sctp-avoid_memory_overflow_with_bad_stream_ID.patch
79 ===================================================================
80 --- hardened/2.6/tags/2.6.27-5/1500_sctp-avoid_memory_overflow_with_bad_stream_ID.patch (rev 0)
81 +++ hardened/2.6/tags/2.6.27-5/1500_sctp-avoid_memory_overflow_with_bad_stream_ID.patch 2009-01-20 21:32:04 UTC (rev 1480)
82 @@ -0,0 +1,80 @@
83 +Added-By: Gordon Malm <gengor@g.o>
84 +
85 +Note: Re-diffed to eliminate failed hunks.
86 +
87 +---
88 +
89 +From: Wei Yongjun <yjwei@××××××××××.com>
90 +Date: Fri, 26 Dec 2008 00:58:11 +0000 (-0800)
91 +Subject: sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID
92 +X-Git-Tag: v2.6.29-rc1~581^2~75
93 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=9fcb95a105758b81ef0131cd18e2db5149f13e95
94 +
95 +sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID
96 +
97 +If FWD-TSN chunk is received with bad stream ID, the sctp will not do the
98 +validity check, this may cause memory overflow when overwrite the TSN of
99 +the stream ID.
100 +
101 +The FORWARD-TSN chunk is like this:
102 +
103 +FORWARD-TSN chunk
104 + Type = 192
105 + Flags = 0
106 + Length = 172
107 + NewTSN = 99
108 + Stream = 10000
109 + StreamSequence = 0xFFFF
110 +
111 +This patch fix this problem by discard the chunk if stream ID is not
112 +less than MIS.
113 +
114 +Signed-off-by: Wei Yongjun <yjwei@××××××××××.com>
115 +Signed-off-by: Vlad Yasevich <vladislav.yasevich@××.com>
116 +Signed-off-by: David S. Miller <davem@×××××××××.net>
117 +---
118 +
119 +--- a/net/sctp/sm_statefuns.c
120 ++++ b/net/sctp/sm_statefuns.c
121 +@@ -3641,6 +3641,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(c
122 + {
123 + struct sctp_chunk *chunk = arg;
124 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
125 ++ struct sctp_fwdtsn_skip *skip;
126 + __u16 len;
127 + __u32 tsn;
128 +
129 +@@ -3670,6 +3671,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(c
130 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
131 + goto discard_noforce;
132 +
133 ++ /* Silently discard the chunk if stream-id is not valid */
134 ++ sctp_walk_fwdtsn(skip, chunk) {
135 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
136 ++ goto discard_noforce;
137 ++ }
138 ++
139 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
140 + if (len > sizeof(struct sctp_fwdtsn_hdr))
141 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
142 +@@ -3701,6 +3708,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_f
143 + {
144 + struct sctp_chunk *chunk = arg;
145 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
146 ++ struct sctp_fwdtsn_skip *skip;
147 + __u16 len;
148 + __u32 tsn;
149 +
150 +@@ -3730,6 +3738,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_f
151 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
152 + goto gen_shutdown;
153 +
154 ++ /* Silently discard the chunk if stream-id is not valid */
155 ++ sctp_walk_fwdtsn(skip, chunk) {
156 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
157 ++ goto gen_shutdown;
158 ++ }
159 ++
160 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
161 + if (len > sizeof(struct sctp_fwdtsn_hdr))
162 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
163
164 Added: hardened/2.6/tags/2.6.27-5/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
165 ===================================================================
166 --- hardened/2.6/tags/2.6.27-5/4420_grsec-2.1.12-2.6.27.10-200812271347.patch (rev 0)
167 +++ hardened/2.6/tags/2.6.27-5/4420_grsec-2.1.12-2.6.27.10-200812271347.patch 2009-01-20 21:32:04 UTC (rev 1480)
168 @@ -0,0 +1,37200 @@
169 + !
170 + -~*~-
171 + /!\
172 + /%;@\
173 + o/@,%\o
174 + /%;`@,\
175 + o/@'%',\o
176 + '^^^N^^^`
177 +
178 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/elf.h linux-2.6.27.10/arch/alpha/include/asm/elf.h
179 +--- linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
180 ++++ linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
181 +@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
182 +
183 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
184 +
185 ++#ifdef CONFIG_PAX_ASLR
186 ++#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
187 ++
188 ++#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
189 ++#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
190 ++#endif
191 ++
192 + /* $0 is set by ld.so to a pointer to a function which might be
193 + registered using atexit. This provides a mean for the dynamic
194 + linker to call DT_FINI functions for shared libraries that have
195 +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
196 +--- linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
197 ++++ linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
198 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
199 + D(10) KM_IRQ1,
200 + D(11) KM_SOFTIRQ0,
201 + D(12) KM_SOFTIRQ1,
202 +-D(13) KM_TYPE_NR
203 ++D(13) KM_CLEARPAGE,
204 ++D(14) KM_TYPE_NR
205 + };
206 +
207 + #undef D
208 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/pgtable.h linux-2.6.27.10/arch/alpha/include/asm/pgtable.h
209 +--- linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
210 ++++ linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
211 +@@ -101,6 +101,17 @@ struct vm_area_struct;
212 + #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
213 + #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
214 + #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
215 ++
216 ++#ifdef CONFIG_PAX_PAGEEXEC
217 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
218 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
219 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
220 ++#else
221 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
222 ++# define PAGE_COPY_NOEXEC PAGE_COPY
223 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
224 ++#endif
225 ++
226 + #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
227 +
228 + #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
229 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/module.c linux-2.6.27.10/arch/alpha/kernel/module.c
230 +--- linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
231 ++++ linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
232 +@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
233 +
234 + /* The small sections were sorted to the end of the segment.
235 + The following should definitely cover them. */
236 +- gp = (u64)me->module_core + me->core_size - 0x8000;
237 ++ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
238 + got = sechdrs[me->arch.gotsecindex].sh_addr;
239 +
240 + for (i = 0; i < n; i++) {
241 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/osf_sys.c linux-2.6.27.10/arch/alpha/kernel/osf_sys.c
242 +--- linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-07 12:55:34.000000000 -0500
243 ++++ linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-18 03:38:43.000000000 -0500
244 +@@ -1232,6 +1232,10 @@ arch_get_unmapped_area(struct file *filp
245 + merely specific addresses, but regions of memory -- perhaps
246 + this feature should be incorporated into all ports? */
247 +
248 ++#ifdef CONFIG_PAX_RANDMMAP
249 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
250 ++#endif
251 ++
252 + if (addr) {
253 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
254 + if (addr != (unsigned long) -ENOMEM)
255 +@@ -1239,8 +1243,8 @@ arch_get_unmapped_area(struct file *filp
256 + }
257 +
258 + /* Next, try allocating at TASK_UNMAPPED_BASE. */
259 +- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
260 +- len, limit);
261 ++ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
262 ++
263 + if (addr != (unsigned long) -ENOMEM)
264 + return addr;
265 +
266 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/ptrace.c linux-2.6.27.10/arch/alpha/kernel/ptrace.c
267 +--- linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
268 ++++ linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-18 03:38:43.000000000 -0500
269 +@@ -15,6 +15,7 @@
270 + #include <linux/slab.h>
271 + #include <linux/security.h>
272 + #include <linux/signal.h>
273 ++#include <linux/grsecurity.h>
274 +
275 + #include <asm/uaccess.h>
276 + #include <asm/pgtable.h>
277 +@@ -266,6 +267,9 @@ long arch_ptrace(struct task_struct *chi
278 + size_t copied;
279 + long ret;
280 +
281 ++ if (gr_handle_ptrace(child, request))
282 ++ return -EPERM;
283 ++
284 + switch (request) {
285 + /* When I and D space are separate, these will need to be fixed. */
286 + case PTRACE_PEEKTEXT: /* read word at location addr. */
287 +diff -urNp linux-2.6.27.10/arch/alpha/mm/fault.c linux-2.6.27.10/arch/alpha/mm/fault.c
288 +--- linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
289 ++++ linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
290 +@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
291 + __reload_thread(pcb);
292 + }
293 +
294 ++#ifdef CONFIG_PAX_PAGEEXEC
295 ++/*
296 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
297 ++ *
298 ++ * returns 1 when task should be killed
299 ++ * 2 when patched PLT trampoline was detected
300 ++ * 3 when unpatched PLT trampoline was detected
301 ++ */
302 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
303 ++{
304 ++
305 ++#ifdef CONFIG_PAX_EMUPLT
306 ++ int err;
307 ++
308 ++ do { /* PaX: patched PLT emulation #1 */
309 ++ unsigned int ldah, ldq, jmp;
310 ++
311 ++ err = get_user(ldah, (unsigned int *)regs->pc);
312 ++ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
313 ++ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
314 ++
315 ++ if (err)
316 ++ break;
317 ++
318 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
319 ++ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
320 ++ jmp == 0x6BFB0000U)
321 ++ {
322 ++ unsigned long r27, addr;
323 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
324 ++ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
325 ++
326 ++ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
327 ++ err = get_user(r27, (unsigned long *)addr);
328 ++ if (err)
329 ++ break;
330 ++
331 ++ regs->r27 = r27;
332 ++ regs->pc = r27;
333 ++ return 2;
334 ++ }
335 ++ } while (0);
336 ++
337 ++ do { /* PaX: patched PLT emulation #2 */
338 ++ unsigned int ldah, lda, br;
339 ++
340 ++ err = get_user(ldah, (unsigned int *)regs->pc);
341 ++ err |= get_user(lda, (unsigned int *)(regs->pc+4));
342 ++ err |= get_user(br, (unsigned int *)(regs->pc+8));
343 ++
344 ++ if (err)
345 ++ break;
346 ++
347 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
348 ++ (lda & 0xFFFF0000U) == 0xA77B0000U &&
349 ++ (br & 0xFFE00000U) == 0xC3E00000U)
350 ++ {
351 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
352 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
353 ++ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
354 ++
355 ++ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
356 ++ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
357 ++ return 2;
358 ++ }
359 ++ } while (0);
360 ++
361 ++ do { /* PaX: unpatched PLT emulation */
362 ++ unsigned int br;
363 ++
364 ++ err = get_user(br, (unsigned int *)regs->pc);
365 ++
366 ++ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
367 ++ unsigned int br2, ldq, nop, jmp;
368 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
369 ++
370 ++ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
371 ++ err = get_user(br2, (unsigned int *)addr);
372 ++ err |= get_user(ldq, (unsigned int *)(addr+4));
373 ++ err |= get_user(nop, (unsigned int *)(addr+8));
374 ++ err |= get_user(jmp, (unsigned int *)(addr+12));
375 ++ err |= get_user(resolver, (unsigned long *)(addr+16));
376 ++
377 ++ if (err)
378 ++ break;
379 ++
380 ++ if (br2 == 0xC3600000U &&
381 ++ ldq == 0xA77B000CU &&
382 ++ nop == 0x47FF041FU &&
383 ++ jmp == 0x6B7B0000U)
384 ++ {
385 ++ regs->r28 = regs->pc+4;
386 ++ regs->r27 = addr+16;
387 ++ regs->pc = resolver;
388 ++ return 3;
389 ++ }
390 ++ }
391 ++ } while (0);
392 ++#endif
393 ++
394 ++ return 1;
395 ++}
396 ++
397 ++void pax_report_insns(void *pc, void *sp)
398 ++{
399 ++ unsigned long i;
400 ++
401 ++ printk(KERN_ERR "PAX: bytes at PC: ");
402 ++ for (i = 0; i < 5; i++) {
403 ++ unsigned int c;
404 ++ if (get_user(c, (unsigned int *)pc+i))
405 ++ printk(KERN_CONT "???????? ");
406 ++ else
407 ++ printk(KERN_CONT "%08x ", c);
408 ++ }
409 ++ printk("\n");
410 ++}
411 ++#endif
412 +
413 + /*
414 + * This routine handles page faults. It determines the address,
415 +@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
416 + good_area:
417 + si_code = SEGV_ACCERR;
418 + if (cause < 0) {
419 +- if (!(vma->vm_flags & VM_EXEC))
420 ++ if (!(vma->vm_flags & VM_EXEC)) {
421 ++
422 ++#ifdef CONFIG_PAX_PAGEEXEC
423 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
424 ++ goto bad_area;
425 ++
426 ++ up_read(&mm->mmap_sem);
427 ++ switch (pax_handle_fetch_fault(regs)) {
428 ++
429 ++#ifdef CONFIG_PAX_EMUPLT
430 ++ case 2:
431 ++ case 3:
432 ++ return;
433 ++#endif
434 ++
435 ++ }
436 ++ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
437 ++ do_group_exit(SIGKILL);
438 ++#else
439 + goto bad_area;
440 ++#endif
441 ++
442 ++ }
443 + } else if (!cause) {
444 + /* Allow reads even for write-only mappings */
445 + if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
446 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/elf.h linux-2.6.27.10/arch/arm/include/asm/elf.h
447 +--- linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
448 ++++ linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
449 +@@ -87,7 +87,14 @@ extern char elf_platform[];
450 + the loader. We need to make sure that it is out of the way of the program
451 + that it will "exec", and that there is sufficient room for the brk. */
452 +
453 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
454 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
455 ++
456 ++#ifdef CONFIG_PAX_ASLR
457 ++#define PAX_ELF_ET_DYN_BASE 0x00008000UL
458 ++
459 ++#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
460 ++#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
461 ++#endif
462 +
463 + /* When the program starts, a1 contains a pointer to a function to be
464 + registered with atexit, as per the SVR4 ABI. A value of 0 means we
465 +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
466 +--- linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
467 ++++ linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
468 +@@ -18,6 +18,7 @@ enum km_type {
469 + KM_IRQ1,
470 + KM_SOFTIRQ0,
471 + KM_SOFTIRQ1,
472 ++ KM_CLEARPAGE,
473 + KM_TYPE_NR
474 + };
475 +
476 +diff -urNp linux-2.6.27.10/arch/arm/mm/mmap.c linux-2.6.27.10/arch/arm/mm/mmap.c
477 +--- linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
478 ++++ linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
479 +@@ -60,6 +60,10 @@ arch_get_unmapped_area(struct file *filp
480 + if (len > TASK_SIZE)
481 + return -ENOMEM;
482 +
483 ++#ifdef CONFIG_PAX_RANDMMAP
484 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
485 ++#endif
486 ++
487 + if (addr) {
488 + if (do_align)
489 + addr = COLOUR_ALIGN(addr, pgoff);
490 +@@ -72,10 +76,10 @@ arch_get_unmapped_area(struct file *filp
491 + return addr;
492 + }
493 + if (len > mm->cached_hole_size) {
494 +- start_addr = addr = mm->free_area_cache;
495 ++ start_addr = addr = mm->free_area_cache;
496 + } else {
497 +- start_addr = addr = TASK_UNMAPPED_BASE;
498 +- mm->cached_hole_size = 0;
499 ++ start_addr = addr = mm->mmap_base;
500 ++ mm->cached_hole_size = 0;
501 + }
502 +
503 + full_search:
504 +@@ -91,8 +95,8 @@ full_search:
505 + * Start a new search - just in case we missed
506 + * some holes.
507 + */
508 +- if (start_addr != TASK_UNMAPPED_BASE) {
509 +- start_addr = addr = TASK_UNMAPPED_BASE;
510 ++ if (start_addr != mm->mmap_base) {
511 ++ start_addr = addr = mm->mmap_base;
512 + mm->cached_hole_size = 0;
513 + goto full_search;
514 + }
515 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/elf.h linux-2.6.27.10/arch/avr32/include/asm/elf.h
516 +--- linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
517 ++++ linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
518 +@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
519 + the loader. We need to make sure that it is out of the way of the program
520 + that it will "exec", and that there is sufficient room for the brk. */
521 +
522 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
523 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
524 +
525 ++#ifdef CONFIG_PAX_ASLR
526 ++#define PAX_ELF_ET_DYN_BASE 0x00001000UL
527 ++
528 ++#define PAX_DELTA_MMAP_LEN 15
529 ++#define PAX_DELTA_STACK_LEN 15
530 ++#endif
531 +
532 + /* This yields a mask that user programs can use to figure out what
533 + instruction set this CPU supports. This could be done in user space,
534 +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
535 +--- linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
536 ++++ linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
537 +@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
538 + D(11) KM_IRQ1,
539 + D(12) KM_SOFTIRQ0,
540 + D(13) KM_SOFTIRQ1,
541 +-D(14) KM_TYPE_NR
542 ++D(14) KM_CLEARPAGE,
543 ++D(15) KM_TYPE_NR
544 + };
545 +
546 + #undef D
547 +diff -urNp linux-2.6.27.10/arch/avr32/mm/fault.c linux-2.6.27.10/arch/avr32/mm/fault.c
548 +--- linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
549 ++++ linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
550 +@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
551 +
552 + int exception_trace = 1;
553 +
554 ++#ifdef CONFIG_PAX_PAGEEXEC
555 ++void pax_report_insns(void *pc, void *sp)
556 ++{
557 ++ unsigned long i;
558 ++
559 ++ printk(KERN_ERR "PAX: bytes at PC: ");
560 ++ for (i = 0; i < 20; i++) {
561 ++ unsigned char c;
562 ++ if (get_user(c, (unsigned char *)pc+i))
563 ++ printk(KERN_CONT "???????? ");
564 ++ else
565 ++ printk(KERN_CONT "%02x ", c);
566 ++ }
567 ++ printk("\n");
568 ++}
569 ++#endif
570 ++
571 + /*
572 + * This routine handles page faults. It determines the address and the
573 + * problem, and then passes it off to one of the appropriate routines.
574 +@@ -157,6 +174,16 @@ bad_area:
575 + up_read(&mm->mmap_sem);
576 +
577 + if (user_mode(regs)) {
578 ++
579 ++#ifdef CONFIG_PAX_PAGEEXEC
580 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
581 ++ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
582 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
583 ++ do_group_exit(SIGKILL);
584 ++ }
585 ++ }
586 ++#endif
587 ++
588 + if (exception_trace && printk_ratelimit())
589 + printk("%s%s[%d]: segfault at %08lx pc %08lx "
590 + "sp %08lx ecr %lu\n",
591 +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
592 +--- linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
593 ++++ linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
594 +@@ -15,6 +15,7 @@ enum km_type {
595 + KM_IRQ1,
596 + KM_SOFTIRQ0,
597 + KM_SOFTIRQ1,
598 ++ KM_CLEARPAGE,
599 + KM_TYPE_NR
600 + };
601 +
602 +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
603 +--- linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
604 ++++ linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
605 +@@ -15,6 +15,7 @@ enum km_type {
606 + KM_IRQ1,
607 + KM_SOFTIRQ0,
608 + KM_SOFTIRQ1,
609 ++ KM_CLEARPAGE,
610 + KM_TYPE_NR
611 + };
612 +
613 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c
614 +--- linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-07 12:55:34.000000000 -0500
615 ++++ linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-18 03:38:43.000000000 -0500
616 +@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
617 +
618 + #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
619 +
620 ++#ifdef CONFIG_PAX_ASLR
621 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
622 ++
623 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
624 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
625 ++#endif
626 ++
627 + /* Ugly but avoids duplication */
628 + #include "../../../fs/binfmt_elf.c"
629 +
630 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/ia32priv.h linux-2.6.27.10/arch/ia64/ia32/ia32priv.h
631 +--- linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-07 12:55:34.000000000 -0500
632 ++++ linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-18 03:38:43.000000000 -0500
633 +@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
634 + #define ELF_DATA ELFDATA2LSB
635 + #define ELF_ARCH EM_386
636 +
637 +-#define IA32_STACK_TOP IA32_PAGE_OFFSET
638 ++#ifdef CONFIG_PAX_RANDUSTACK
639 ++#define __IA32_DELTA_STACK (current->mm->delta_stack)
640 ++#else
641 ++#define __IA32_DELTA_STACK 0UL
642 ++#endif
643 ++
644 ++#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
645 ++
646 + #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
647 + #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
648 +
649 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/elf.h linux-2.6.27.10/arch/ia64/include/asm/elf.h
650 +--- linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
651 ++++ linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
652 +@@ -43,6 +43,13 @@
653 + */
654 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
655 +
656 ++#ifdef CONFIG_PAX_ASLR
657 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
658 ++
659 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
660 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
661 ++#endif
662 ++
663 + #define PT_IA_64_UNWIND 0x70000001
664 +
665 + /* IA-64 relocations: */
666 +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
667 +--- linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
668 ++++ linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
669 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
670 + D(10) KM_IRQ1,
671 + D(11) KM_SOFTIRQ0,
672 + D(12) KM_SOFTIRQ1,
673 +-D(13) KM_TYPE_NR
674 ++D(13) KM_CLEARPAGE,
675 ++D(14) KM_TYPE_NR
676 + };
677 +
678 + #undef D
679 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/pgtable.h linux-2.6.27.10/arch/ia64/include/asm/pgtable.h
680 +--- linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
681 ++++ linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
682 +@@ -143,6 +143,17 @@
683 + #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
684 + #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
685 + #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
686 ++
687 ++#ifdef CONFIG_PAX_PAGEEXEC
688 ++# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
689 ++# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
690 ++# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
691 ++#else
692 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
693 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
694 ++# define PAGE_COPY_NOEXEC PAGE_COPY
695 ++#endif
696 ++
697 + #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
698 + #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
699 + #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
700 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/module.c linux-2.6.27.10/arch/ia64/kernel/module.c
701 +--- linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
702 ++++ linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
703 +@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
704 + void
705 + module_free (struct module *mod, void *module_region)
706 + {
707 +- if (mod && mod->arch.init_unw_table &&
708 +- module_region == mod->module_init) {
709 ++ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
710 + unw_remove_unwind_table(mod->arch.init_unw_table);
711 + mod->arch.init_unw_table = NULL;
712 + }
713 +@@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
714 + }
715 +
716 + static inline int
717 ++in_init_rx (const struct module *mod, uint64_t addr)
718 ++{
719 ++ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
720 ++}
721 ++
722 ++static inline int
723 ++in_init_rw (const struct module *mod, uint64_t addr)
724 ++{
725 ++ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
726 ++}
727 ++
728 ++static inline int
729 + in_init (const struct module *mod, uint64_t addr)
730 + {
731 +- return addr - (uint64_t) mod->module_init < mod->init_size;
732 ++ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
733 ++}
734 ++
735 ++static inline int
736 ++in_core_rx (const struct module *mod, uint64_t addr)
737 ++{
738 ++ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
739 ++}
740 ++
741 ++static inline int
742 ++in_core_rw (const struct module *mod, uint64_t addr)
743 ++{
744 ++ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
745 + }
746 +
747 + static inline int
748 + in_core (const struct module *mod, uint64_t addr)
749 + {
750 +- return addr - (uint64_t) mod->module_core < mod->core_size;
751 ++ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
752 + }
753 +
754 + static inline int
755 +@@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_
756 + break;
757 +
758 + case RV_BDREL:
759 +- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
760 ++ if (in_init_rx(mod, val))
761 ++ val -= (uint64_t) mod->module_init_rx;
762 ++ else if (in_init_rw(mod, val))
763 ++ val -= (uint64_t) mod->module_init_rw;
764 ++ else if (in_core_rx(mod, val))
765 ++ val -= (uint64_t) mod->module_core_rx;
766 ++ else if (in_core_rw(mod, val))
767 ++ val -= (uint64_t) mod->module_core_rw;
768 + break;
769 +
770 + case RV_LTV:
771 +@@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
772 + * addresses have been selected...
773 + */
774 + uint64_t gp;
775 +- if (mod->core_size > MAX_LTOFF)
776 ++ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
777 + /*
778 + * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
779 + * at the end of the module.
780 + */
781 +- gp = mod->core_size - MAX_LTOFF / 2;
782 ++ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
783 + else
784 +- gp = mod->core_size / 2;
785 +- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
786 ++ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
787 ++ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
788 + mod->arch.gp = gp;
789 + DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
790 + }
791 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c
792 +--- linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-07 12:55:34.000000000 -0500
793 ++++ linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-18 03:38:43.000000000 -0500
794 +@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
795 + if (REGION_NUMBER(addr) == RGN_HPAGE)
796 + addr = 0;
797 + #endif
798 ++
799 ++#ifdef CONFIG_PAX_RANDMMAP
800 ++ if ((mm->pax_flags & MF_PAX_RANDMMAP) && addr && filp)
801 ++ addr = mm->free_area_cache;
802 ++ else
803 ++#endif
804 ++
805 + if (!addr)
806 + addr = mm->free_area_cache;
807 +
808 +@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
809 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
810 + /* At this point: (!vma || addr < vma->vm_end). */
811 + if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
812 +- if (start_addr != TASK_UNMAPPED_BASE) {
813 ++ if (start_addr != mm->mmap_base) {
814 + /* Start a new search --- just in case we missed some holes. */
815 +- addr = TASK_UNMAPPED_BASE;
816 ++ addr = mm->mmap_base;
817 + goto full_search;
818 + }
819 + return -ENOMEM;
820 +diff -urNp linux-2.6.27.10/arch/ia64/mm/fault.c linux-2.6.27.10/arch/ia64/mm/fault.c
821 +--- linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
822 ++++ linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
823 +@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
824 + return pte_present(pte);
825 + }
826 +
827 ++#ifdef CONFIG_PAX_PAGEEXEC
828 ++void pax_report_insns(void *pc, void *sp)
829 ++{
830 ++ unsigned long i;
831 ++
832 ++ printk(KERN_ERR "PAX: bytes at PC: ");
833 ++ for (i = 0; i < 8; i++) {
834 ++ unsigned int c;
835 ++ if (get_user(c, (unsigned int *)pc+i))
836 ++ printk(KERN_CONT "???????? ");
837 ++ else
838 ++ printk(KERN_CONT "%08x ", c);
839 ++ }
840 ++ printk("\n");
841 ++}
842 ++#endif
843 ++
844 + void __kprobes
845 + ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
846 + {
847 +@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
848 + mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
849 + | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
850 +
851 +- if ((vma->vm_flags & mask) != mask)
852 ++ if ((vma->vm_flags & mask) != mask) {
853 ++
854 ++#ifdef CONFIG_PAX_PAGEEXEC
855 ++ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
856 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
857 ++ goto bad_area;
858 ++
859 ++ up_read(&mm->mmap_sem);
860 ++ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
861 ++ do_group_exit(SIGKILL);
862 ++ }
863 ++#endif
864 ++
865 + goto bad_area;
866 +
867 ++ }
868 ++
869 + survive:
870 + /*
871 + * If for any reason at all we couldn't handle the fault, make
872 +diff -urNp linux-2.6.27.10/arch/ia64/mm/init.c linux-2.6.27.10/arch/ia64/mm/init.c
873 +--- linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-07 12:55:34.000000000 -0500
874 ++++ linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-18 03:38:43.000000000 -0500
875 +@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
876 + vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
877 + vma->vm_end = vma->vm_start + PAGE_SIZE;
878 + vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
879 ++
880 ++#ifdef CONFIG_PAX_PAGEEXEC
881 ++ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
882 ++ vma->vm_flags &= ~VM_EXEC;
883 ++
884 ++#ifdef CONFIG_PAX_MPROTECT
885 ++ if (current->mm->pax_flags & MF_PAX_MPROTECT)
886 ++ vma->vm_flags &= ~VM_MAYEXEC;
887 ++#endif
888 ++
889 ++ }
890 ++#endif
891 ++
892 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
893 + down_write(&current->mm->mmap_sem);
894 + if (insert_vm_struct(current->mm, vma)) {
895 +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
896 +--- linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
897 ++++ linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
898 +@@ -15,6 +15,7 @@ enum km_type {
899 + KM_IRQ1,
900 + KM_SOFTIRQ0,
901 + KM_SOFTIRQ1,
902 ++ KM_CLEARPAGE,
903 + KM_TYPE_NR
904 + };
905 +
906 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c
907 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-07 12:55:34.000000000 -0500
908 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-18 03:38:43.000000000 -0500
909 +@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
910 + #undef ELF_ET_DYN_BASE
911 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
912 +
913 ++#ifdef CONFIG_PAX_ASLR
914 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
915 ++
916 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
917 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
918 ++#endif
919 ++
920 + #include <asm/processor.h>
921 + #include <linux/module.h>
922 + #include <linux/elfcore.h>
923 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c
924 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-07 12:55:34.000000000 -0500
925 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-18 03:38:43.000000000 -0500
926 +@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
927 + #undef ELF_ET_DYN_BASE
928 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
929 +
930 ++#ifdef CONFIG_PAX_ASLR
931 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
932 ++
933 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
934 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
935 ++#endif
936 ++
937 + #include <asm/processor.h>
938 + #include <linux/module.h>
939 + #include <linux/elfcore.h>
940 +diff -urNp linux-2.6.27.10/arch/mips/kernel/process.c linux-2.6.27.10/arch/mips/kernel/process.c
941 +--- linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-07 12:55:34.000000000 -0500
942 ++++ linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-18 03:38:43.000000000 -0500
943 +@@ -458,15 +458,3 @@ unsigned long get_wchan(struct task_stru
944 + out:
945 + return pc;
946 + }
947 +-
948 +-/*
949 +- * Don't forget that the stack pointer must be aligned on a 8 bytes
950 +- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
951 +- */
952 +-unsigned long arch_align_stack(unsigned long sp)
953 +-{
954 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
955 +- sp -= get_random_int() & ~PAGE_MASK;
956 +-
957 +- return sp & ALMASK;
958 +-}
959 +diff -urNp linux-2.6.27.10/arch/mips/kernel/syscall.c linux-2.6.27.10/arch/mips/kernel/syscall.c
960 +--- linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-07 12:55:34.000000000 -0500
961 ++++ linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-18 03:38:43.000000000 -0500
962 +@@ -100,6 +100,11 @@ unsigned long arch_get_unmapped_area(str
963 + do_color_align = 0;
964 + if (filp || (flags & MAP_SHARED))
965 + do_color_align = 1;
966 ++
967 ++#ifdef CONFIG_PAX_RANDMMAP
968 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
969 ++#endif
970 ++
971 + if (addr) {
972 + if (do_color_align)
973 + addr = COLOUR_ALIGN(addr, pgoff);
974 +@@ -110,7 +115,7 @@ unsigned long arch_get_unmapped_area(str
975 + (!vmm || addr + len <= vmm->vm_start))
976 + return addr;
977 + }
978 +- addr = TASK_UNMAPPED_BASE;
979 ++ addr = current->mm->mmap_base;
980 + if (do_color_align)
981 + addr = COLOUR_ALIGN(addr, pgoff);
982 + else
983 +diff -urNp linux-2.6.27.10/arch/mips/mm/fault.c linux-2.6.27.10/arch/mips/mm/fault.c
984 +--- linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
985 ++++ linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
986 +@@ -26,6 +26,23 @@
987 + #include <asm/ptrace.h>
988 + #include <asm/highmem.h> /* For VMALLOC_END */
989 +
990 ++#ifdef CONFIG_PAX_PAGEEXEC
991 ++void pax_report_insns(void *pc)
992 ++{
993 ++ unsigned long i;
994 ++
995 ++ printk(KERN_ERR "PAX: bytes at PC: ");
996 ++ for (i = 0; i < 5; i++) {
997 ++ unsigned int c;
998 ++ if (get_user(c, (unsigned int *)pc+i))
999 ++ printk(KERN_CONT "???????? ");
1000 ++ else
1001 ++ printk(KERN_CONT "%08x ", c);
1002 ++ }
1003 ++ printk("\n");
1004 ++}
1005 ++#endif
1006 ++
1007 + /*
1008 + * This routine handles page faults. It determines the address,
1009 + * and the problem, and then passes it off to one of the appropriate
1010 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/module.c linux-2.6.27.10/arch/parisc/kernel/module.c
1011 +--- linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
1012 ++++ linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
1013 +@@ -75,16 +75,38 @@
1014 +
1015 + /* three functions to determine where in the module core
1016 + * or init pieces the location is */
1017 ++static inline int in_init_rx(struct module *me, void *loc)
1018 ++{
1019 ++ return (loc >= me->module_init_rx &&
1020 ++ loc < (me->module_init_rx + me->init_size_rx));
1021 ++}
1022 ++
1023 ++static inline int in_init_rw(struct module *me, void *loc)
1024 ++{
1025 ++ return (loc >= me->module_init_rw &&
1026 ++ loc < (me->module_init_rw + me->init_size_rw));
1027 ++}
1028 ++
1029 + static inline int in_init(struct module *me, void *loc)
1030 + {
1031 +- return (loc >= me->module_init &&
1032 +- loc <= (me->module_init + me->init_size));
1033 ++ return in_init_rx(me, loc) || in_init_rw(me, loc);
1034 ++}
1035 ++
1036 ++static inline int in_core_rx(struct module *me, void *loc)
1037 ++{
1038 ++ return (loc >= me->module_core_rx &&
1039 ++ loc < (me->module_core_rx + me->core_size_rx));
1040 ++}
1041 ++
1042 ++static inline int in_core_rw(struct module *me, void *loc)
1043 ++{
1044 ++ return (loc >= me->module_core_rw &&
1045 ++ loc < (me->module_core_rw + me->core_size_rw));
1046 + }
1047 +
1048 + static inline int in_core(struct module *me, void *loc)
1049 + {
1050 +- return (loc >= me->module_core &&
1051 +- loc <= (me->module_core + me->core_size));
1052 ++ return in_core_rx(me, loc) || in_core_rw(me, loc);
1053 + }
1054 +
1055 + static inline int in_local(struct module *me, void *loc)
1056 +@@ -298,21 +320,21 @@ int module_frob_arch_sections(CONST Elf_
1057 + }
1058 +
1059 + /* align things a bit */
1060 +- me->core_size = ALIGN(me->core_size, 16);
1061 +- me->arch.got_offset = me->core_size;
1062 +- me->core_size += gots * sizeof(struct got_entry);
1063 +-
1064 +- me->core_size = ALIGN(me->core_size, 16);
1065 +- me->arch.fdesc_offset = me->core_size;
1066 +- me->core_size += fdescs * sizeof(Elf_Fdesc);
1067 +-
1068 +- me->core_size = ALIGN(me->core_size, 16);
1069 +- me->arch.stub_offset = me->core_size;
1070 +- me->core_size += stubs * sizeof(struct stub_entry);
1071 +-
1072 +- me->init_size = ALIGN(me->init_size, 16);
1073 +- me->arch.init_stub_offset = me->init_size;
1074 +- me->init_size += init_stubs * sizeof(struct stub_entry);
1075 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1076 ++ me->arch.got_offset = me->core_size_rw;
1077 ++ me->core_size_rw += gots * sizeof(struct got_entry);
1078 ++
1079 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1080 ++ me->arch.fdesc_offset = me->core_size_rw;
1081 ++ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1082 ++
1083 ++ me->core_size_rx = ALIGN(me->core_size_rx, 16);
1084 ++ me->arch.stub_offset = me->core_size_rx;
1085 ++ me->core_size_rx += stubs * sizeof(struct stub_entry);
1086 ++
1087 ++ me->init_size_rx = ALIGN(me->init_size_rx, 16);
1088 ++ me->arch.init_stub_offset = me->init_size_rx;
1089 ++ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
1090 +
1091 + me->arch.got_max = gots;
1092 + me->arch.fdesc_max = fdescs;
1093 +@@ -332,7 +354,7 @@ static Elf64_Word get_got(struct module
1094 +
1095 + BUG_ON(value == 0);
1096 +
1097 +- got = me->module_core + me->arch.got_offset;
1098 ++ got = me->module_core_rw + me->arch.got_offset;
1099 + for (i = 0; got[i].addr; i++)
1100 + if (got[i].addr == value)
1101 + goto out;
1102 +@@ -350,7 +372,7 @@ static Elf64_Word get_got(struct module
1103 + #ifdef CONFIG_64BIT
1104 + static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1105 + {
1106 +- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1107 ++ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1108 +
1109 + if (!value) {
1110 + printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1111 +@@ -368,7 +390,7 @@ static Elf_Addr get_fdesc(struct module
1112 +
1113 + /* Create new one */
1114 + fdesc->addr = value;
1115 +- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1116 ++ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1117 + return (Elf_Addr)fdesc;
1118 + }
1119 + #endif /* CONFIG_64BIT */
1120 +@@ -388,12 +410,12 @@ static Elf_Addr get_stub(struct module *
1121 + if(init_section) {
1122 + i = me->arch.init_stub_count++;
1123 + BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
1124 +- stub = me->module_init + me->arch.init_stub_offset +
1125 ++ stub = me->module_init_rx + me->arch.init_stub_offset +
1126 + i * sizeof(struct stub_entry);
1127 + } else {
1128 + i = me->arch.stub_count++;
1129 + BUG_ON(me->arch.stub_count > me->arch.stub_max);
1130 +- stub = me->module_core + me->arch.stub_offset +
1131 ++ stub = me->module_core_rx + me->arch.stub_offset +
1132 + i * sizeof(struct stub_entry);
1133 + }
1134 +
1135 +@@ -761,7 +783,7 @@ register_unwind_table(struct module *me,
1136 +
1137 + table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1138 + end = table + sechdrs[me->arch.unwind_section].sh_size;
1139 +- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1140 ++ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1141 +
1142 + DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1143 + me->arch.unwind_section, table, end, gp);
1144 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c
1145 +--- linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-07 12:55:34.000000000 -0500
1146 ++++ linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-18 03:38:43.000000000 -0500
1147 +@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1148 + if (flags & MAP_FIXED)
1149 + return addr;
1150 + if (!addr)
1151 +- addr = TASK_UNMAPPED_BASE;
1152 ++ addr = current->mm->mmap_base;
1153 +
1154 + if (filp) {
1155 + addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1156 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/traps.c linux-2.6.27.10/arch/parisc/kernel/traps.c
1157 +--- linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:36.000000000 -0500
1158 ++++ linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:46.000000000 -0500
1159 +@@ -731,9 +731,7 @@ void handle_interruption(int code, struc
1160 +
1161 + down_read(&current->mm->mmap_sem);
1162 + vma = find_vma(current->mm,regs->iaoq[0]);
1163 +- if (vma && (regs->iaoq[0] >= vma->vm_start)
1164 +- && (vma->vm_flags & VM_EXEC)) {
1165 +-
1166 ++ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1167 + fault_address = regs->iaoq[0];
1168 + fault_space = regs->iasq[0];
1169 +
1170 +diff -urNp linux-2.6.27.10/arch/parisc/mm/fault.c linux-2.6.27.10/arch/parisc/mm/fault.c
1171 +--- linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1172 ++++ linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1173 +@@ -16,6 +16,7 @@
1174 + #include <linux/sched.h>
1175 + #include <linux/interrupt.h>
1176 + #include <linux/module.h>
1177 ++#include <linux/unistd.h>
1178 +
1179 + #include <asm/uaccess.h>
1180 + #include <asm/traps.h>
1181 +@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1182 + static unsigned long
1183 + parisc_acctyp(unsigned long code, unsigned int inst)
1184 + {
1185 +- if (code == 6 || code == 16)
1186 ++ if (code == 6 || code == 7 || code == 16)
1187 + return VM_EXEC;
1188 +
1189 + switch (inst & 0xf0000000) {
1190 +@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
1191 + }
1192 + #endif
1193 +
1194 ++#ifdef CONFIG_PAX_PAGEEXEC
1195 ++/*
1196 ++ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1197 ++ *
1198 ++ * returns 1 when task should be killed
1199 ++ * 2 when rt_sigreturn trampoline was detected
1200 ++ * 3 when unpatched PLT trampoline was detected
1201 ++ */
1202 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1203 ++{
1204 ++
1205 ++#ifdef CONFIG_PAX_EMUPLT
1206 ++ int err;
1207 ++
1208 ++ do { /* PaX: unpatched PLT emulation */
1209 ++ unsigned int bl, depwi;
1210 ++
1211 ++ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1212 ++ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1213 ++
1214 ++ if (err)
1215 ++ break;
1216 ++
1217 ++ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1218 ++ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1219 ++
1220 ++ err = get_user(ldw, (unsigned int *)addr);
1221 ++ err |= get_user(bv, (unsigned int *)(addr+4));
1222 ++ err |= get_user(ldw2, (unsigned int *)(addr+8));
1223 ++
1224 ++ if (err)
1225 ++ break;
1226 ++
1227 ++ if (ldw == 0x0E801096U &&
1228 ++ bv == 0xEAC0C000U &&
1229 ++ ldw2 == 0x0E881095U)
1230 ++ {
1231 ++ unsigned int resolver, map;
1232 ++
1233 ++ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1234 ++ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1235 ++ if (err)
1236 ++ break;
1237 ++
1238 ++ regs->gr[20] = instruction_pointer(regs)+8;
1239 ++ regs->gr[21] = map;
1240 ++ regs->gr[22] = resolver;
1241 ++ regs->iaoq[0] = resolver | 3UL;
1242 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1243 ++ return 3;
1244 ++ }
1245 ++ }
1246 ++ } while (0);
1247 ++#endif
1248 ++
1249 ++#ifdef CONFIG_PAX_EMUTRAMP
1250 ++
1251 ++#ifndef CONFIG_PAX_EMUSIGRT
1252 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1253 ++ return 1;
1254 ++#endif
1255 ++
1256 ++ do { /* PaX: rt_sigreturn emulation */
1257 ++ unsigned int ldi1, ldi2, bel, nop;
1258 ++
1259 ++ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1260 ++ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1261 ++ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1262 ++ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1263 ++
1264 ++ if (err)
1265 ++ break;
1266 ++
1267 ++ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1268 ++ ldi2 == 0x3414015AU &&
1269 ++ bel == 0xE4008200U &&
1270 ++ nop == 0x08000240U)
1271 ++ {
1272 ++ regs->gr[25] = (ldi1 & 2) >> 1;
1273 ++ regs->gr[20] = __NR_rt_sigreturn;
1274 ++ regs->gr[31] = regs->iaoq[1] + 16;
1275 ++ regs->sr[0] = regs->iasq[1];
1276 ++ regs->iaoq[0] = 0x100UL;
1277 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1278 ++ regs->iasq[0] = regs->sr[2];
1279 ++ regs->iasq[1] = regs->sr[2];
1280 ++ return 2;
1281 ++ }
1282 ++ } while (0);
1283 ++#endif
1284 ++
1285 ++ return 1;
1286 ++}
1287 ++
1288 ++void pax_report_insns(void *pc, void *sp)
1289 ++{
1290 ++ unsigned long i;
1291 ++
1292 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1293 ++ for (i = 0; i < 5; i++) {
1294 ++ unsigned int c;
1295 ++ if (get_user(c, (unsigned int *)pc+i))
1296 ++ printk(KERN_CONT "???????? ");
1297 ++ else
1298 ++ printk(KERN_CONT "%08x ", c);
1299 ++ }
1300 ++ printk("\n");
1301 ++}
1302 ++#endif
1303 ++
1304 + void do_page_fault(struct pt_regs *regs, unsigned long code,
1305 + unsigned long address)
1306 + {
1307 +@@ -165,8 +276,33 @@ good_area:
1308 +
1309 + acc_type = parisc_acctyp(code,regs->iir);
1310 +
1311 +- if ((vma->vm_flags & acc_type) != acc_type)
1312 ++ if ((vma->vm_flags & acc_type) != acc_type) {
1313 ++
1314 ++#ifdef CONFIG_PAX_PAGEEXEC
1315 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1316 ++ (address & ~3UL) == instruction_pointer(regs))
1317 ++ {
1318 ++ up_read(&mm->mmap_sem);
1319 ++ switch (pax_handle_fetch_fault(regs)) {
1320 ++
1321 ++#ifdef CONFIG_PAX_EMUPLT
1322 ++ case 3:
1323 ++ return;
1324 ++#endif
1325 ++
1326 ++#ifdef CONFIG_PAX_EMUTRAMP
1327 ++ case 2:
1328 ++ return;
1329 ++#endif
1330 ++
1331 ++ }
1332 ++ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1333 ++ do_group_exit(SIGKILL);
1334 ++ }
1335 ++#endif
1336 ++
1337 + goto bad_area;
1338 ++ }
1339 +
1340 + /*
1341 + * If for any reason at all we couldn't handle the fault, make
1342 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/elf.h linux-2.6.27.10/arch/powerpc/include/asm/elf.h
1343 +--- linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
1344 ++++ linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
1345 +@@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
1346 +
1347 + #define ELF_ET_DYN_BASE (0x20000000)
1348 +
1349 ++#ifdef CONFIG_PAX_ASLR
1350 ++#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
1351 ++
1352 ++#ifdef __powerpc64__
1353 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1354 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1355 ++#else
1356 ++#define PAX_DELTA_MMAP_LEN 15
1357 ++#define PAX_DELTA_STACK_LEN 15
1358 ++#endif
1359 ++#endif
1360 ++
1361 + /*
1362 + * Our registers are always unsigned longs, whether we're a 32 bit
1363 + * process or 64 bit, on either a 64 bit or 32 bit kernel.
1364 +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
1365 +--- linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1366 ++++ linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1367 +@@ -26,6 +26,7 @@ enum km_type {
1368 + KM_SOFTIRQ1,
1369 + KM_PPC_SYNC_PAGE,
1370 + KM_PPC_SYNC_ICACHE,
1371 ++ KM_CLEARPAGE,
1372 + KM_TYPE_NR
1373 + };
1374 +
1375 +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
1376 +--- linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-07 12:55:34.000000000 -0500
1377 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-18 03:39:50.000000000 -0500
1378 +@@ -170,15 +170,18 @@ do { \
1379 + * stack by default, so in the absense of a PT_GNU_STACK program header
1380 + * we turn execute permission off.
1381 + */
1382 +-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1383 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1384 ++#define VM_STACK_DEFAULT_FLAGS32 \
1385 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1386 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1387 +
1388 + #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1389 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1390 +
1391 ++#ifndef CONFIG_PAX_PAGEEXEC
1392 + #define VM_STACK_DEFAULT_FLAGS \
1393 + (test_thread_flag(TIF_32BIT) ? \
1394 + VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
1395 ++#endif
1396 +
1397 + #include <asm-generic/page.h>
1398 +
1399 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page.h linux-2.6.27.10/arch/powerpc/include/asm/page.h
1400 +--- linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-07 12:55:34.000000000 -0500
1401 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-18 03:39:50.000000000 -0500
1402 +@@ -100,8 +100,9 @@ extern phys_addr_t kernstart_addr;
1403 + * and needs to be executable. This means the whole heap ends
1404 + * up being executable.
1405 + */
1406 +-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1407 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1408 ++#define VM_DATA_DEFAULT_FLAGS32 \
1409 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1410 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1411 +
1412 + #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1413 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1414 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/module_32.c linux-2.6.27.10/arch/powerpc/kernel/module_32.c
1415 +--- linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
1416 ++++ linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-18 03:38:43.000000000 -0500
1417 +@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr
1418 + me->arch.core_plt_section = i;
1419 + }
1420 + if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
1421 +- printk("Module doesn't contain .plt or .init.plt sections.\n");
1422 ++ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
1423 + return -ENOEXEC;
1424 + }
1425 +
1426 +@@ -199,11 +199,16 @@ static uint32_t do_plt_call(void *locati
1427 +
1428 + DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
1429 + /* Init, or core PLT? */
1430 +- if (location >= mod->module_core
1431 +- && location < mod->module_core + mod->core_size)
1432 ++ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
1433 ++ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
1434 + entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
1435 +- else
1436 ++ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
1437 ++ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
1438 + entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
1439 ++ else {
1440 ++ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
1441 ++ return ~0UL;
1442 ++ }
1443 +
1444 + /* Find this entry, or if that fails, the next avail. entry */
1445 + while (entry->jump[0]) {
1446 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_32.c linux-2.6.27.10/arch/powerpc/kernel/signal_32.c
1447 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
1448 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-18 03:38:43.000000000 -0500
1449 +@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
1450 + /* Save user registers on the stack */
1451 + frame = &rt_sf->uc.uc_mcontext;
1452 + addr = frame;
1453 +- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
1454 ++ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1455 + if (save_user_regs(regs, frame, 0))
1456 + goto badframe;
1457 + regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
1458 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_64.c linux-2.6.27.10/arch/powerpc/kernel/signal_64.c
1459 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
1460 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-18 03:38:43.000000000 -0500
1461 +@@ -434,7 +434,7 @@ int handle_rt_signal64(int signr, struct
1462 + current->thread.fpscr.val = 0;
1463 +
1464 + /* Set up to return from userspace. */
1465 +- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
1466 ++ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1467 + regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
1468 + } else {
1469 + err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
1470 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/vdso.c linux-2.6.27.10/arch/powerpc/kernel/vdso.c
1471 +--- linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-07 12:55:34.000000000 -0500
1472 ++++ linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-18 03:38:43.000000000 -0500
1473 +@@ -212,7 +212,7 @@ int arch_setup_additional_pages(struct l
1474 + vdso_base = VDSO32_MBASE;
1475 + #endif
1476 +
1477 +- current->mm->context.vdso_base = 0;
1478 ++ current->mm->context.vdso_base = ~0UL;
1479 +
1480 + /* vDSO has a problem and was disabled, just don't "enable" it for the
1481 + * process
1482 +@@ -229,7 +229,7 @@ int arch_setup_additional_pages(struct l
1483 + */
1484 + down_write(&mm->mmap_sem);
1485 + vdso_base = get_unmapped_area(NULL, vdso_base,
1486 +- vdso_pages << PAGE_SHIFT, 0, 0);
1487 ++ vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
1488 + if (IS_ERR_VALUE(vdso_base)) {
1489 + rc = vdso_base;
1490 + goto fail_mmapsem;
1491 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/fault.c linux-2.6.27.10/arch/powerpc/mm/fault.c
1492 +--- linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1493 ++++ linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1494 +@@ -29,6 +29,10 @@
1495 + #include <linux/module.h>
1496 + #include <linux/kprobes.h>
1497 + #include <linux/kdebug.h>
1498 ++#include <linux/slab.h>
1499 ++#include <linux/pagemap.h>
1500 ++#include <linux/compiler.h>
1501 ++#include <linux/unistd.h>
1502 +
1503 + #include <asm/page.h>
1504 + #include <asm/pgtable.h>
1505 +@@ -62,6 +66,363 @@ static inline int notify_page_fault(stru
1506 + }
1507 + #endif
1508 +
1509 ++#ifdef CONFIG_PAX_EMUSIGRT
1510 ++void pax_syscall_close(struct vm_area_struct *vma)
1511 ++{
1512 ++ vma->vm_mm->call_syscall = 0UL;
1513 ++}
1514 ++
1515 ++static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1516 ++{
1517 ++ unsigned int *kaddr;
1518 ++
1519 ++ vmf->page = alloc_page(GFP_HIGHUSER);
1520 ++ if (!vmf->page)
1521 ++ return VM_FAULT_OOM;
1522 ++
1523 ++ kaddr = kmap(vmf->page);
1524 ++ memset(kaddr, 0, PAGE_SIZE);
1525 ++ kaddr[0] = 0x44000002U; /* sc */
1526 ++ __flush_dcache_icache(kaddr);
1527 ++ kunmap(vmf->page);
1528 ++ return VM_FAULT_MAJOR;
1529 ++}
1530 ++
1531 ++static struct vm_operations_struct pax_vm_ops = {
1532 ++ .close = pax_syscall_close,
1533 ++ .fault = pax_syscall_fault
1534 ++};
1535 ++
1536 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
1537 ++{
1538 ++ int ret;
1539 ++
1540 ++ vma->vm_mm = current->mm;
1541 ++ vma->vm_start = addr;
1542 ++ vma->vm_end = addr + PAGE_SIZE;
1543 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
1544 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1545 ++ vma->vm_ops = &pax_vm_ops;
1546 ++
1547 ++ ret = insert_vm_struct(current->mm, vma);
1548 ++ if (ret)
1549 ++ return ret;
1550 ++
1551 ++ ++current->mm->total_vm;
1552 ++ return 0;
1553 ++}
1554 ++#endif
1555 ++
1556 ++#ifdef CONFIG_PAX_PAGEEXEC
1557 ++/*
1558 ++ * PaX: decide what to do with offenders (regs->nip = fault address)
1559 ++ *
1560 ++ * returns 1 when task should be killed
1561 ++ * 2 when patched GOT trampoline was detected
1562 ++ * 3 when patched PLT trampoline was detected
1563 ++ * 4 when unpatched PLT trampoline was detected
1564 ++ * 5 when sigreturn trampoline was detected
1565 ++ * 6 when rt_sigreturn trampoline was detected
1566 ++ */
1567 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1568 ++{
1569 ++
1570 ++#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
1571 ++ int err;
1572 ++#endif
1573 ++
1574 ++#ifdef CONFIG_PAX_EMUPLT
1575 ++ do { /* PaX: patched GOT emulation */
1576 ++ unsigned int blrl;
1577 ++
1578 ++ err = get_user(blrl, (unsigned int *)regs->nip);
1579 ++
1580 ++ if (!err && blrl == 0x4E800021U) {
1581 ++ unsigned long temp = regs->nip;
1582 ++
1583 ++ regs->nip = regs->link & 0xFFFFFFFCUL;
1584 ++ regs->link = temp + 4UL;
1585 ++ return 2;
1586 ++ }
1587 ++ } while (0);
1588 ++
1589 ++ do { /* PaX: patched PLT emulation #1 */
1590 ++ unsigned int b;
1591 ++
1592 ++ err = get_user(b, (unsigned int *)regs->nip);
1593 ++
1594 ++ if (!err && (b & 0xFC000003U) == 0x48000000U) {
1595 ++ regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
1596 ++ return 3;
1597 ++ }
1598 ++ } while (0);
1599 ++
1600 ++ do { /* PaX: unpatched PLT emulation #1 */
1601 ++ unsigned int li, b;
1602 ++
1603 ++ err = get_user(li, (unsigned int *)regs->nip);
1604 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1605 ++
1606 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1607 ++ unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1608 ++ unsigned long addr = b | 0xFC000000UL;
1609 ++
1610 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1611 ++ err = get_user(rlwinm, (unsigned int *)addr);
1612 ++ err |= get_user(add, (unsigned int *)(addr+4));
1613 ++ err |= get_user(li2, (unsigned int *)(addr+8));
1614 ++ err |= get_user(addis2, (unsigned int *)(addr+12));
1615 ++ err |= get_user(mtctr, (unsigned int *)(addr+16));
1616 ++ err |= get_user(li3, (unsigned int *)(addr+20));
1617 ++ err |= get_user(addis3, (unsigned int *)(addr+24));
1618 ++ err |= get_user(bctr, (unsigned int *)(addr+28));
1619 ++
1620 ++ if (err)
1621 ++ break;
1622 ++
1623 ++ if (rlwinm == 0x556C083CU &&
1624 ++ add == 0x7D6C5A14U &&
1625 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1626 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1627 ++ mtctr == 0x7D8903A6U &&
1628 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1629 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1630 ++ bctr == 0x4E800420U)
1631 ++ {
1632 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1633 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1634 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1635 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1636 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1637 ++ regs->nip = regs->ctr;
1638 ++ return 4;
1639 ++ }
1640 ++ }
1641 ++ } while (0);
1642 ++
1643 ++#if 0
1644 ++ do { /* PaX: unpatched PLT emulation #2 */
1645 ++ unsigned int lis, lwzu, b, bctr;
1646 ++
1647 ++ err = get_user(lis, (unsigned int *)regs->nip);
1648 ++ err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
1649 ++ err |= get_user(b, (unsigned int *)(regs->nip+8));
1650 ++ err |= get_user(bctr, (unsigned int *)(regs->nip+12));
1651 ++
1652 ++ if (err)
1653 ++ break;
1654 ++
1655 ++ if ((lis & 0xFFFF0000U) == 0x39600000U &&
1656 ++ (lwzu & 0xU) == 0xU &&
1657 ++ (b & 0xFC000003U) == 0x48000000U &&
1658 ++ bctr == 0x4E800420U)
1659 ++ {
1660 ++ unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1661 ++ unsigned long addr = b | 0xFC000000UL;
1662 ++
1663 ++ addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1664 ++ err = get_user(addis, (unsigned int *)addr);
1665 ++ err |= get_user(addi, (unsigned int *)(addr+4));
1666 ++ err |= get_user(rlwinm, (unsigned int *)(addr+8));
1667 ++ err |= get_user(add, (unsigned int *)(addr+12));
1668 ++ err |= get_user(li2, (unsigned int *)(addr+16));
1669 ++ err |= get_user(addis2, (unsigned int *)(addr+20));
1670 ++ err |= get_user(mtctr, (unsigned int *)(addr+24));
1671 ++ err |= get_user(li3, (unsigned int *)(addr+28));
1672 ++ err |= get_user(addis3, (unsigned int *)(addr+32));
1673 ++ err |= get_user(bctr, (unsigned int *)(addr+36));
1674 ++
1675 ++ if (err)
1676 ++ break;
1677 ++
1678 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1679 ++ (addi & 0xFFFF0000U) == 0x396B0000U &&
1680 ++ rlwinm == 0x556C083CU &&
1681 ++ add == 0x7D6C5A14U &&
1682 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1683 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1684 ++ mtctr == 0x7D8903A6U &&
1685 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1686 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1687 ++ bctr == 0x4E800420U)
1688 ++ {
1689 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1690 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1691 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1692 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1693 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1694 ++ regs->nip = regs->ctr;
1695 ++ return 4;
1696 ++ }
1697 ++ }
1698 ++ } while (0);
1699 ++#endif
1700 ++
1701 ++ do { /* PaX: unpatched PLT emulation #3 */
1702 ++ unsigned int li, b;
1703 ++
1704 ++ err = get_user(li, (unsigned int *)regs->nip);
1705 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1706 ++
1707 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1708 ++ unsigned int addis, lwz, mtctr, bctr;
1709 ++ unsigned long addr = b | 0xFC000000UL;
1710 ++
1711 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1712 ++ err = get_user(addis, (unsigned int *)addr);
1713 ++ err |= get_user(lwz, (unsigned int *)(addr+4));
1714 ++ err |= get_user(mtctr, (unsigned int *)(addr+8));
1715 ++ err |= get_user(bctr, (unsigned int *)(addr+12));
1716 ++
1717 ++ if (err)
1718 ++ break;
1719 ++
1720 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1721 ++ (lwz & 0xFFFF0000U) == 0x816B0000U &&
1722 ++ mtctr == 0x7D6903A6U &&
1723 ++ bctr == 0x4E800420U)
1724 ++ {
1725 ++ unsigned int r11;
1726 ++
1727 ++ addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1728 ++ addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1729 ++
1730 ++ err = get_user(r11, (unsigned int *)addr);
1731 ++ if (err)
1732 ++ break;
1733 ++
1734 ++ regs->gpr[PT_R11] = r11;
1735 ++ regs->ctr = r11;
1736 ++ regs->nip = r11;
1737 ++ return 4;
1738 ++ }
1739 ++ }
1740 ++ } while (0);
1741 ++#endif
1742 ++
1743 ++#ifdef CONFIG_PAX_EMUSIGRT
1744 ++ do { /* PaX: sigreturn emulation */
1745 ++ unsigned int li, sc;
1746 ++
1747 ++ err = get_user(li, (unsigned int *)regs->nip);
1748 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1749 ++
1750 ++ if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
1751 ++ struct vm_area_struct *vma;
1752 ++ unsigned long call_syscall;
1753 ++
1754 ++ down_read(&current->mm->mmap_sem);
1755 ++ call_syscall = current->mm->call_syscall;
1756 ++ up_read(&current->mm->mmap_sem);
1757 ++ if (likely(call_syscall))
1758 ++ goto emulate;
1759 ++
1760 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1761 ++
1762 ++ down_write(&current->mm->mmap_sem);
1763 ++ if (current->mm->call_syscall) {
1764 ++ call_syscall = current->mm->call_syscall;
1765 ++ up_write(&current->mm->mmap_sem);
1766 ++ if (vma)
1767 ++ kmem_cache_free(vm_area_cachep, vma);
1768 ++ goto emulate;
1769 ++ }
1770 ++
1771 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1772 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1773 ++ up_write(&current->mm->mmap_sem);
1774 ++ if (vma)
1775 ++ kmem_cache_free(vm_area_cachep, vma);
1776 ++ return 1;
1777 ++ }
1778 ++
1779 ++ if (pax_insert_vma(vma, call_syscall)) {
1780 ++ up_write(&current->mm->mmap_sem);
1781 ++ kmem_cache_free(vm_area_cachep, vma);
1782 ++ return 1;
1783 ++ }
1784 ++
1785 ++ current->mm->call_syscall = call_syscall;
1786 ++ up_write(&current->mm->mmap_sem);
1787 ++
1788 ++emulate:
1789 ++ regs->gpr[PT_R0] = __NR_sigreturn;
1790 ++ regs->nip = call_syscall;
1791 ++ return 5;
1792 ++ }
1793 ++ } while (0);
1794 ++
1795 ++ do { /* PaX: rt_sigreturn emulation */
1796 ++ unsigned int li, sc;
1797 ++
1798 ++ err = get_user(li, (unsigned int *)regs->nip);
1799 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1800 ++
1801 ++ if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
1802 ++ struct vm_area_struct *vma;
1803 ++ unsigned int call_syscall;
1804 ++
1805 ++ down_read(&current->mm->mmap_sem);
1806 ++ call_syscall = current->mm->call_syscall;
1807 ++ up_read(&current->mm->mmap_sem);
1808 ++ if (likely(call_syscall))
1809 ++ goto rt_emulate;
1810 ++
1811 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1812 ++
1813 ++ down_write(&current->mm->mmap_sem);
1814 ++ if (current->mm->call_syscall) {
1815 ++ call_syscall = current->mm->call_syscall;
1816 ++ up_write(&current->mm->mmap_sem);
1817 ++ if (vma)
1818 ++ kmem_cache_free(vm_area_cachep, vma);
1819 ++ goto rt_emulate;
1820 ++ }
1821 ++
1822 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1823 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1824 ++ up_write(&current->mm->mmap_sem);
1825 ++ if (vma)
1826 ++ kmem_cache_free(vm_area_cachep, vma);
1827 ++ return 1;
1828 ++ }
1829 ++
1830 ++ if (pax_insert_vma(vma, call_syscall)) {
1831 ++ up_write(&current->mm->mmap_sem);
1832 ++ kmem_cache_free(vm_area_cachep, vma);
1833 ++ return 1;
1834 ++ }
1835 ++
1836 ++ current->mm->call_syscall = call_syscall;
1837 ++ up_write(&current->mm->mmap_sem);
1838 ++
1839 ++rt_emulate:
1840 ++ regs->gpr[PT_R0] = __NR_rt_sigreturn;
1841 ++ regs->nip = call_syscall;
1842 ++ return 6;
1843 ++ }
1844 ++ } while (0);
1845 ++#endif
1846 ++
1847 ++ return 1;
1848 ++}
1849 ++
1850 ++void pax_report_insns(void *pc, void *sp)
1851 ++{
1852 ++ unsigned long i;
1853 ++
1854 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1855 ++ for (i = 0; i < 5; i++) {
1856 ++ unsigned int c;
1857 ++ if (get_user(c, (unsigned int *)pc+i))
1858 ++ printk(KERN_CONT "???????? ");
1859 ++ else
1860 ++ printk(KERN_CONT "%08x ", c);
1861 ++ }
1862 ++ printk("\n");
1863 ++}
1864 ++#endif
1865 ++
1866 + /*
1867 + * Check whether the instruction at regs->nip is a store using
1868 + * an update addressing form which will update r1.
1869 +@@ -132,7 +493,7 @@ int __kprobes do_page_fault(struct pt_re
1870 + * indicate errors in DSISR but can validly be set in SRR1.
1871 + */
1872 + if (trap == 0x400)
1873 +- error_code &= 0x48200000;
1874 ++ error_code &= 0x58200000;
1875 + else
1876 + is_write = error_code & DSISR_ISSTORE;
1877 + #else
1878 +@@ -331,6 +692,37 @@ bad_area:
1879 + bad_area_nosemaphore:
1880 + /* User mode accesses cause a SIGSEGV */
1881 + if (user_mode(regs)) {
1882 ++
1883 ++#ifdef CONFIG_PAX_PAGEEXEC
1884 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1885 ++#ifdef CONFIG_PPC64
1886 ++ if (is_exec && (error_code & DSISR_PROTFAULT)) {
1887 ++#else
1888 ++ if (is_exec && regs->nip == address) {
1889 ++#endif
1890 ++ switch (pax_handle_fetch_fault(regs)) {
1891 ++
1892 ++#ifdef CONFIG_PAX_EMUPLT
1893 ++ case 2:
1894 ++ case 3:
1895 ++ case 4:
1896 ++ return 0;
1897 ++#endif
1898 ++
1899 ++#ifdef CONFIG_PAX_EMUSIGRT
1900 ++ case 5:
1901 ++ case 6:
1902 ++ return 0;
1903 ++#endif
1904 ++
1905 ++ }
1906 ++
1907 ++ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
1908 ++ do_group_exit(SIGKILL);
1909 ++ }
1910 ++ }
1911 ++#endif
1912 ++
1913 + _exception(SIGSEGV, regs, code, address);
1914 + return 0;
1915 + }
1916 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/mmap.c linux-2.6.27.10/arch/powerpc/mm/mmap.c
1917 +--- linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
1918 ++++ linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
1919 +@@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str
1920 + */
1921 + if (mmap_is_legacy()) {
1922 + mm->mmap_base = TASK_UNMAPPED_BASE;
1923 ++
1924 ++#ifdef CONFIG_PAX_RANDMMAP
1925 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1926 ++ mm->mmap_base += mm->delta_mmap;
1927 ++#endif
1928 ++
1929 + mm->get_unmapped_area = arch_get_unmapped_area;
1930 + mm->unmap_area = arch_unmap_area;
1931 + } else {
1932 + mm->mmap_base = mmap_base();
1933 ++
1934 ++#ifdef CONFIG_PAX_RANDMMAP
1935 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1936 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1937 ++#endif
1938 ++
1939 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1940 + mm->unmap_area = arch_unmap_area_topdown;
1941 + }
1942 +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
1943 +--- linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1944 ++++ linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1945 +@@ -16,6 +16,7 @@ enum km_type {
1946 + KM_IRQ1,
1947 + KM_SOFTIRQ0,
1948 + KM_SOFTIRQ1,
1949 ++ KM_CLEARPAGE,
1950 + KM_TYPE_NR
1951 + };
1952 +
1953 +diff -urNp linux-2.6.27.10/arch/s390/kernel/module.c linux-2.6.27.10/arch/s390/kernel/module.c
1954 +--- linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
1955 ++++ linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
1956 +@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
1957 +
1958 + /* Increase core size by size of got & plt and set start
1959 + offsets for got and plt. */
1960 +- me->core_size = ALIGN(me->core_size, 4);
1961 +- me->arch.got_offset = me->core_size;
1962 +- me->core_size += me->arch.got_size;
1963 +- me->arch.plt_offset = me->core_size;
1964 +- me->core_size += me->arch.plt_size;
1965 ++ me->core_size_rw = ALIGN(me->core_size_rw, 4);
1966 ++ me->arch.got_offset = me->core_size_rw;
1967 ++ me->core_size_rw += me->arch.got_size;
1968 ++ me->arch.plt_offset = me->core_size_rx;
1969 ++ me->core_size_rx += me->arch.plt_size;
1970 + return 0;
1971 + }
1972 +
1973 +@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1974 + if (info->got_initialized == 0) {
1975 + Elf_Addr *gotent;
1976 +
1977 +- gotent = me->module_core + me->arch.got_offset +
1978 ++ gotent = me->module_core_rw + me->arch.got_offset +
1979 + info->got_offset;
1980 + *gotent = val;
1981 + info->got_initialized = 1;
1982 +@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1983 + else if (r_type == R_390_GOTENT ||
1984 + r_type == R_390_GOTPLTENT)
1985 + *(unsigned int *) loc =
1986 +- (val + (Elf_Addr) me->module_core - loc) >> 1;
1987 ++ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
1988 + else if (r_type == R_390_GOT64 ||
1989 + r_type == R_390_GOTPLT64)
1990 + *(unsigned long *) loc = val;
1991 +@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1992 + case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
1993 + if (info->plt_initialized == 0) {
1994 + unsigned int *ip;
1995 +- ip = me->module_core + me->arch.plt_offset +
1996 ++ ip = me->module_core_rx + me->arch.plt_offset +
1997 + info->plt_offset;
1998 + #ifndef CONFIG_64BIT
1999 + ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
2000 +@@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2001 + val = me->arch.plt_offset - me->arch.got_offset +
2002 + info->plt_offset + rela->r_addend;
2003 + else
2004 +- val = (Elf_Addr) me->module_core +
2005 ++ val = (Elf_Addr) me->module_core_rx +
2006 + me->arch.plt_offset + info->plt_offset +
2007 + rela->r_addend - loc;
2008 + if (r_type == R_390_PLT16DBL)
2009 +@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2010 + case R_390_GOTOFF32: /* 32 bit offset to GOT. */
2011 + case R_390_GOTOFF64: /* 64 bit offset to GOT. */
2012 + val = val + rela->r_addend -
2013 +- ((Elf_Addr) me->module_core + me->arch.got_offset);
2014 ++ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
2015 + if (r_type == R_390_GOTOFF16)
2016 + *(unsigned short *) loc = val;
2017 + else if (r_type == R_390_GOTOFF32)
2018 +@@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2019 + break;
2020 + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
2021 + case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
2022 +- val = (Elf_Addr) me->module_core + me->arch.got_offset +
2023 ++ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
2024 + rela->r_addend - loc;
2025 + if (r_type == R_390_GOTPC)
2026 + *(unsigned int *) loc = val;
2027 +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
2028 +--- linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2029 ++++ linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2030 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
2031 + D(10) KM_IRQ1,
2032 + D(11) KM_SOFTIRQ0,
2033 + D(12) KM_SOFTIRQ1,
2034 +-D(13) KM_TYPE_NR
2035 ++D(13) KM_CLEARPAGE,
2036 ++D(14) KM_TYPE_NR
2037 + };
2038 +
2039 + #undef D
2040 +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
2041 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-07 12:55:34.000000000 -0500
2042 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-18 03:39:50.000000000 -0500
2043 +@@ -119,6 +119,13 @@ typedef struct {
2044 +
2045 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
2046 +
2047 ++#ifdef CONFIG_PAX_ASLR
2048 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
2049 ++
2050 ++#define PAX_DELTA_MMAP_LEN 16
2051 ++#define PAX_DELTA_STACK_LEN 16
2052 ++#endif
2053 ++
2054 + /* This yields a mask that user programs can use to figure out what
2055 + instruction set this cpu supports. This can NOT be done in userspace
2056 + on Sparc. */
2057 +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
2058 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-07 12:55:34.000000000 -0500
2059 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-18 03:39:50.000000000 -0500
2060 +@@ -163,6 +163,12 @@ typedef struct {
2061 + #define ELF_ET_DYN_BASE 0x0000010000000000UL
2062 + #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
2063 +
2064 ++#ifdef CONFIG_PAX_ASLR
2065 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
2066 ++
2067 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 )
2068 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 )
2069 ++#endif
2070 +
2071 + /* This yields a mask that user programs can use to figure out what
2072 + instruction set this cpu supports. */
2073 +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
2074 +--- linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2075 ++++ linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2076 +@@ -19,6 +19,7 @@ enum km_type {
2077 + KM_IRQ1,
2078 + KM_SOFTIRQ0,
2079 + KM_SOFTIRQ1,
2080 ++ KM_CLEARPAGE,
2081 + KM_TYPE_NR
2082 + };
2083 +
2084 +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
2085 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
2086 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-18 03:39:50.000000000 -0500
2087 +@@ -47,6 +47,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
2088 + BTFIXUPDEF_INT(page_none)
2089 + BTFIXUPDEF_INT(page_copy)
2090 + BTFIXUPDEF_INT(page_readonly)
2091 ++
2092 ++#ifdef CONFIG_PAX_PAGEEXEC
2093 ++BTFIXUPDEF_INT(page_shared_noexec)
2094 ++BTFIXUPDEF_INT(page_copy_noexec)
2095 ++BTFIXUPDEF_INT(page_readonly_noexec)
2096 ++#endif
2097 ++
2098 + BTFIXUPDEF_INT(page_kernel)
2099 +
2100 + #define PMD_SHIFT SUN4C_PMD_SHIFT
2101 +@@ -68,6 +75,16 @@ extern pgprot_t PAGE_SHARED;
2102 + #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
2103 + #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
2104 +
2105 ++#ifdef CONFIG_PAX_PAGEEXEC
2106 ++extern pgprot_t PAGE_SHARED_NOEXEC;
2107 ++# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
2108 ++# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
2109 ++#else
2110 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2111 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2112 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2113 ++#endif
2114 ++
2115 + extern unsigned long page_kernel;
2116 +
2117 + #ifdef MODULE
2118 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h
2119 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-07 12:55:34.000000000 -0500
2120 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-18 03:39:50.000000000 -0500
2121 +@@ -115,6 +115,13 @@
2122 + SRMMU_EXEC | SRMMU_REF)
2123 + #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
2124 + SRMMU_EXEC | SRMMU_REF)
2125 ++
2126 ++#ifdef CONFIG_PAX_PAGEEXEC
2127 ++#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
2128 ++#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2129 ++#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2130 ++#endif
2131 ++
2132 + #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
2133 + SRMMU_DIRTY | SRMMU_REF)
2134 +
2135 +diff -urNp linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c
2136 +--- linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2137 ++++ linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2138 +@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
2139 + if (ARCH_SUN4C_SUN4 && len > 0x20000000)
2140 + return -ENOMEM;
2141 + if (!addr)
2142 +- addr = TASK_UNMAPPED_BASE;
2143 ++ addr = current->mm->mmap_base;
2144 +
2145 + if (flags & MAP_SHARED)
2146 + addr = COLOUR_ALIGN(addr);
2147 +diff -urNp linux-2.6.27.10/arch/sparc/Makefile linux-2.6.27.10/arch/sparc/Makefile
2148 +--- linux-2.6.27.10/arch/sparc/Makefile 2008-11-07 12:55:34.000000000 -0500
2149 ++++ linux-2.6.27.10/arch/sparc/Makefile 2008-11-18 03:38:43.000000000 -0500
2150 +@@ -37,7 +37,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
2151 + # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
2152 + INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
2153 + CORE_Y := $(core-y)
2154 +-CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
2155 ++CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
2156 + CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
2157 + DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
2158 + NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
2159 +diff -urNp linux-2.6.27.10/arch/sparc/mm/fault.c linux-2.6.27.10/arch/sparc/mm/fault.c
2160 +--- linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2161 ++++ linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2162 +@@ -21,6 +21,9 @@
2163 + #include <linux/interrupt.h>
2164 + #include <linux/module.h>
2165 + #include <linux/kdebug.h>
2166 ++#include <linux/slab.h>
2167 ++#include <linux/pagemap.h>
2168 ++#include <linux/compiler.h>
2169 +
2170 + #include <asm/system.h>
2171 + #include <asm/page.h>
2172 +@@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str
2173 + return safe_compute_effective_address(regs, insn);
2174 + }
2175 +
2176 ++#ifdef CONFIG_PAX_PAGEEXEC
2177 ++void pax_emuplt_close(struct vm_area_struct *vma)
2178 ++{
2179 ++ vma->vm_mm->call_dl_resolve = 0UL;
2180 ++}
2181 ++
2182 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2183 ++{
2184 ++ unsigned int *kaddr;
2185 ++
2186 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2187 ++ if (!vmf->page)
2188 ++ return VM_FAULT_OOM;
2189 ++
2190 ++ kaddr = kmap(vmf->page);
2191 ++ memset(kaddr, 0, PAGE_SIZE);
2192 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2193 ++ flush_dcache_page(vmf->page);
2194 ++ kunmap(vmf->page);
2195 ++ return VM_FAULT_MAJOR;
2196 ++}
2197 ++
2198 ++static struct vm_operations_struct pax_vm_ops = {
2199 ++ .close = pax_emuplt_close,
2200 ++ .fault = pax_emuplt_fault
2201 ++};
2202 ++
2203 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2204 ++{
2205 ++ int ret;
2206 ++
2207 ++ vma->vm_mm = current->mm;
2208 ++ vma->vm_start = addr;
2209 ++ vma->vm_end = addr + PAGE_SIZE;
2210 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2211 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2212 ++ vma->vm_ops = &pax_vm_ops;
2213 ++
2214 ++ ret = insert_vm_struct(current->mm, vma);
2215 ++ if (ret)
2216 ++ return ret;
2217 ++
2218 ++ ++current->mm->total_vm;
2219 ++ return 0;
2220 ++}
2221 ++
2222 ++/*
2223 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
2224 ++ *
2225 ++ * returns 1 when task should be killed
2226 ++ * 2 when patched PLT trampoline was detected
2227 ++ * 3 when unpatched PLT trampoline was detected
2228 ++ */
2229 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2230 ++{
2231 ++
2232 ++#ifdef CONFIG_PAX_EMUPLT
2233 ++ int err;
2234 ++
2235 ++ do { /* PaX: patched PLT emulation #1 */
2236 ++ unsigned int sethi1, sethi2, jmpl;
2237 ++
2238 ++ err = get_user(sethi1, (unsigned int *)regs->pc);
2239 ++ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
2240 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
2241 ++
2242 ++ if (err)
2243 ++ break;
2244 ++
2245 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2246 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2247 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2248 ++ {
2249 ++ unsigned int addr;
2250 ++
2251 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2252 ++ addr = regs->u_regs[UREG_G1];
2253 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2254 ++ regs->pc = addr;
2255 ++ regs->npc = addr+4;
2256 ++ return 2;
2257 ++ }
2258 ++ } while (0);
2259 ++
2260 ++ { /* PaX: patched PLT emulation #2 */
2261 ++ unsigned int ba;
2262 ++
2263 ++ err = get_user(ba, (unsigned int *)regs->pc);
2264 ++
2265 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2266 ++ unsigned int addr;
2267 ++
2268 ++ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2269 ++ regs->pc = addr;
2270 ++ regs->npc = addr+4;
2271 ++ return 2;
2272 ++ }
2273 ++ }
2274 ++
2275 ++ do { /* PaX: patched PLT emulation #3 */
2276 ++ unsigned int sethi, jmpl, nop;
2277 ++
2278 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2279 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
2280 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2281 ++
2282 ++ if (err)
2283 ++ break;
2284 ++
2285 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2286 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2287 ++ nop == 0x01000000U)
2288 ++ {
2289 ++ unsigned int addr;
2290 ++
2291 ++ addr = (sethi & 0x003FFFFFU) << 10;
2292 ++ regs->u_regs[UREG_G1] = addr;
2293 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2294 ++ regs->pc = addr;
2295 ++ regs->npc = addr+4;
2296 ++ return 2;
2297 ++ }
2298 ++ } while (0);
2299 ++
2300 ++ do { /* PaX: unpatched PLT emulation step 1 */
2301 ++ unsigned int sethi, ba, nop;
2302 ++
2303 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2304 ++ err |= get_user(ba, (unsigned int *)(regs->pc+4));
2305 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2306 ++
2307 ++ if (err)
2308 ++ break;
2309 ++
2310 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2311 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2312 ++ nop == 0x01000000U)
2313 ++ {
2314 ++ unsigned int addr, save, call;
2315 ++
2316 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2317 ++ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2318 ++ else
2319 ++ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
2320 ++
2321 ++ err = get_user(save, (unsigned int *)addr);
2322 ++ err |= get_user(call, (unsigned int *)(addr+4));
2323 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2324 ++ if (err)
2325 ++ break;
2326 ++
2327 ++ if (save == 0x9DE3BFA8U &&
2328 ++ (call & 0xC0000000U) == 0x40000000U &&
2329 ++ nop == 0x01000000U)
2330 ++ {
2331 ++ struct vm_area_struct *vma;
2332 ++ unsigned long call_dl_resolve;
2333 ++
2334 ++ down_read(&current->mm->mmap_sem);
2335 ++ call_dl_resolve = current->mm->call_dl_resolve;
2336 ++ up_read(&current->mm->mmap_sem);
2337 ++ if (likely(call_dl_resolve))
2338 ++ goto emulate;
2339 ++
2340 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2341 ++
2342 ++ down_write(&current->mm->mmap_sem);
2343 ++ if (current->mm->call_dl_resolve) {
2344 ++ call_dl_resolve = current->mm->call_dl_resolve;
2345 ++ up_write(&current->mm->mmap_sem);
2346 ++ if (vma)
2347 ++ kmem_cache_free(vm_area_cachep, vma);
2348 ++ goto emulate;
2349 ++ }
2350 ++
2351 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2352 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2353 ++ up_write(&current->mm->mmap_sem);
2354 ++ if (vma)
2355 ++ kmem_cache_free(vm_area_cachep, vma);
2356 ++ return 1;
2357 ++ }
2358 ++
2359 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2360 ++ up_write(&current->mm->mmap_sem);
2361 ++ kmem_cache_free(vm_area_cachep, vma);
2362 ++ return 1;
2363 ++ }
2364 ++
2365 ++ current->mm->call_dl_resolve = call_dl_resolve;
2366 ++ up_write(&current->mm->mmap_sem);
2367 ++
2368 ++emulate:
2369 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2370 ++ regs->pc = call_dl_resolve;
2371 ++ regs->npc = addr+4;
2372 ++ return 3;
2373 ++ }
2374 ++ }
2375 ++ } while (0);
2376 ++
2377 ++ do { /* PaX: unpatched PLT emulation step 2 */
2378 ++ unsigned int save, call, nop;
2379 ++
2380 ++ err = get_user(save, (unsigned int *)(regs->pc-4));
2381 ++ err |= get_user(call, (unsigned int *)regs->pc);
2382 ++ err |= get_user(nop, (unsigned int *)(regs->pc+4));
2383 ++ if (err)
2384 ++ break;
2385 ++
2386 ++ if (save == 0x9DE3BFA8U &&
2387 ++ (call & 0xC0000000U) == 0x40000000U &&
2388 ++ nop == 0x01000000U)
2389 ++ {
2390 ++ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
2391 ++
2392 ++ regs->u_regs[UREG_RETPC] = regs->pc;
2393 ++ regs->pc = dl_resolve;
2394 ++ regs->npc = dl_resolve+4;
2395 ++ return 3;
2396 ++ }
2397 ++ } while (0);
2398 ++#endif
2399 ++
2400 ++ return 1;
2401 ++}
2402 ++
2403 ++void pax_report_insns(void *pc, void *sp)
2404 ++{
2405 ++ unsigned long i;
2406 ++
2407 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2408 ++ for (i = 0; i < 5; i++) {
2409 ++ unsigned int c;
2410 ++ if (get_user(c, (unsigned int *)pc+i))
2411 ++ printk(KERN_CONT "???????? ");
2412 ++ else
2413 ++ printk(KERN_CONT "%08x ", c);
2414 ++ }
2415 ++ printk("\n");
2416 ++}
2417 ++#endif
2418 ++
2419 + asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
2420 + unsigned long address)
2421 + {
2422 +@@ -231,6 +477,24 @@ good_area:
2423 + if(!(vma->vm_flags & VM_WRITE))
2424 + goto bad_area;
2425 + } else {
2426 ++
2427 ++#ifdef CONFIG_PAX_PAGEEXEC
2428 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
2429 ++ up_read(&mm->mmap_sem);
2430 ++ switch (pax_handle_fetch_fault(regs)) {
2431 ++
2432 ++#ifdef CONFIG_PAX_EMUPLT
2433 ++ case 2:
2434 ++ case 3:
2435 ++ return;
2436 ++#endif
2437 ++
2438 ++ }
2439 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
2440 ++ do_group_exit(SIGKILL);
2441 ++ }
2442 ++#endif
2443 ++
2444 + /* Allow reads even for write-only mappings */
2445 + if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
2446 + goto bad_area;
2447 +diff -urNp linux-2.6.27.10/arch/sparc/mm/init.c linux-2.6.27.10/arch/sparc/mm/init.c
2448 +--- linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-07 12:55:34.000000000 -0500
2449 ++++ linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-18 03:38:43.000000000 -0500
2450 +@@ -312,6 +312,9 @@ extern void device_scan(void);
2451 + pgprot_t PAGE_SHARED __read_mostly;
2452 + EXPORT_SYMBOL(PAGE_SHARED);
2453 +
2454 ++pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
2455 ++EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
2456 ++
2457 + void __init paging_init(void)
2458 + {
2459 + switch(sparc_cpu_model) {
2460 +@@ -337,17 +340,17 @@ void __init paging_init(void)
2461 +
2462 + /* Initialize the protection map with non-constant, MMU dependent values. */
2463 + protection_map[0] = PAGE_NONE;
2464 +- protection_map[1] = PAGE_READONLY;
2465 +- protection_map[2] = PAGE_COPY;
2466 +- protection_map[3] = PAGE_COPY;
2467 ++ protection_map[1] = PAGE_READONLY_NOEXEC;
2468 ++ protection_map[2] = PAGE_COPY_NOEXEC;
2469 ++ protection_map[3] = PAGE_COPY_NOEXEC;
2470 + protection_map[4] = PAGE_READONLY;
2471 + protection_map[5] = PAGE_READONLY;
2472 + protection_map[6] = PAGE_COPY;
2473 + protection_map[7] = PAGE_COPY;
2474 + protection_map[8] = PAGE_NONE;
2475 +- protection_map[9] = PAGE_READONLY;
2476 +- protection_map[10] = PAGE_SHARED;
2477 +- protection_map[11] = PAGE_SHARED;
2478 ++ protection_map[9] = PAGE_READONLY_NOEXEC;
2479 ++ protection_map[10] = PAGE_SHARED_NOEXEC;
2480 ++ protection_map[11] = PAGE_SHARED_NOEXEC;
2481 + protection_map[12] = PAGE_READONLY;
2482 + protection_map[13] = PAGE_READONLY;
2483 + protection_map[14] = PAGE_SHARED;
2484 +diff -urNp linux-2.6.27.10/arch/sparc/mm/srmmu.c linux-2.6.27.10/arch/sparc/mm/srmmu.c
2485 +--- linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-07 12:55:34.000000000 -0500
2486 ++++ linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-18 03:38:43.000000000 -0500
2487 +@@ -2163,6 +2163,13 @@ void __init ld_mmu_srmmu(void)
2488 + PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
2489 + BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2490 + BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2491 ++
2492 ++#ifdef CONFIG_PAX_PAGEEXEC
2493 ++ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
2494 ++ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
2495 ++ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
2496 ++#endif
2497 ++
2498 + BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2499 + page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2500 +
2501 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/Makefile linux-2.6.27.10/arch/sparc64/kernel/Makefile
2502 +--- linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-07 12:55:34.000000000 -0500
2503 ++++ linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-18 03:38:43.000000000 -0500
2504 +@@ -3,7 +3,7 @@
2505 + #
2506 +
2507 + EXTRA_AFLAGS := -ansi
2508 +-EXTRA_CFLAGS := -Werror
2509 ++#EXTRA_CFLAGS := -Werror
2510 +
2511 + extra-y := head.o init_task.o vmlinux.lds
2512 +
2513 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c
2514 +--- linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2515 ++++ linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2516 +@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
2517 + /* We do not accept a shared mapping if it would violate
2518 + * cache aliasing constraints.
2519 + */
2520 +- if ((flags & MAP_SHARED) &&
2521 ++ if ((filp || (flags & MAP_SHARED)) &&
2522 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2523 + return -EINVAL;
2524 + return addr;
2525 +@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
2526 + if (filp || (flags & MAP_SHARED))
2527 + do_color_align = 1;
2528 +
2529 ++#ifdef CONFIG_PAX_RANDMMAP
2530 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
2531 ++#endif
2532 ++
2533 + if (addr) {
2534 + if (do_color_align)
2535 + addr = COLOUR_ALIGN(addr, pgoff);
2536 +@@ -152,9 +156,9 @@ unsigned long arch_get_unmapped_area(str
2537 + }
2538 +
2539 + if (len > mm->cached_hole_size) {
2540 +- start_addr = addr = mm->free_area_cache;
2541 ++ start_addr = addr = mm->free_area_cache;
2542 + } else {
2543 +- start_addr = addr = TASK_UNMAPPED_BASE;
2544 ++ start_addr = addr = mm->mmap_base;
2545 + mm->cached_hole_size = 0;
2546 + }
2547 +
2548 +@@ -174,8 +178,8 @@ full_search:
2549 + vma = find_vma(mm, VA_EXCLUDE_END);
2550 + }
2551 + if (unlikely(task_size < addr)) {
2552 +- if (start_addr != TASK_UNMAPPED_BASE) {
2553 +- start_addr = addr = TASK_UNMAPPED_BASE;
2554 ++ if (start_addr != mm->mmap_base) {
2555 ++ start_addr = addr = mm->mmap_base;
2556 + mm->cached_hole_size = 0;
2557 + goto full_search;
2558 + }
2559 +@@ -215,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
2560 + /* We do not accept a shared mapping if it would violate
2561 + * cache aliasing constraints.
2562 + */
2563 +- if ((flags & MAP_SHARED) &&
2564 ++ if ((filp || (flags & MAP_SHARED)) &&
2565 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2566 + return -EINVAL;
2567 + return addr;
2568 +@@ -378,6 +382,12 @@ void arch_pick_mmap_layout(struct mm_str
2569 + current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
2570 + sysctl_legacy_va_layout) {
2571 + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2572 ++
2573 ++#ifdef CONFIG_PAX_RANDMMAP
2574 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2575 ++ mm->mmap_base += mm->delta_mmap;
2576 ++#endif
2577 ++
2578 + mm->get_unmapped_area = arch_get_unmapped_area;
2579 + mm->unmap_area = arch_unmap_area;
2580 + } else {
2581 +@@ -392,6 +402,12 @@ void arch_pick_mmap_layout(struct mm_str
2582 + gap = (task_size / 6 * 5);
2583 +
2584 + mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
2585 ++
2586 ++#ifdef CONFIG_PAX_RANDMMAP
2587 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2588 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2589 ++#endif
2590 ++
2591 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2592 + mm->unmap_area = arch_unmap_area_topdown;
2593 + }
2594 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/fault.c linux-2.6.27.10/arch/sparc64/mm/fault.c
2595 +--- linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2596 ++++ linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2597 +@@ -19,6 +19,9 @@
2598 + #include <linux/interrupt.h>
2599 + #include <linux/kprobes.h>
2600 + #include <linux/kdebug.h>
2601 ++#include <linux/slab.h>
2602 ++#include <linux/pagemap.h>
2603 ++#include <linux/compiler.h>
2604 +
2605 + #include <asm/page.h>
2606 + #include <asm/pgtable.h>
2607 +@@ -261,6 +264,367 @@ cannot_handle:
2608 + unhandled_fault (address, current, regs);
2609 + }
2610 +
2611 ++#ifdef CONFIG_PAX_PAGEEXEC
2612 ++#ifdef CONFIG_PAX_EMUPLT
2613 ++static void pax_emuplt_close(struct vm_area_struct *vma)
2614 ++{
2615 ++ vma->vm_mm->call_dl_resolve = 0UL;
2616 ++}
2617 ++
2618 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2619 ++{
2620 ++ unsigned int *kaddr;
2621 ++
2622 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2623 ++ if (!vmf->page)
2624 ++ return VM_FAULT_OOM;
2625 ++
2626 ++ kaddr = kmap(vmf->page);
2627 ++ memset(kaddr, 0, PAGE_SIZE);
2628 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2629 ++ flush_dcache_page(vmf->page);
2630 ++ kunmap(vmf->page);
2631 ++ return VM_FAULT_MAJOR;
2632 ++}
2633 ++
2634 ++static struct vm_operations_struct pax_vm_ops = {
2635 ++ .close = pax_emuplt_close,
2636 ++ .fault = pax_emuplt_fault
2637 ++};
2638 ++
2639 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2640 ++{
2641 ++ int ret;
2642 ++
2643 ++ vma->vm_mm = current->mm;
2644 ++ vma->vm_start = addr;
2645 ++ vma->vm_end = addr + PAGE_SIZE;
2646 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2647 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2648 ++ vma->vm_ops = &pax_vm_ops;
2649 ++
2650 ++ ret = insert_vm_struct(current->mm, vma);
2651 ++ if (ret)
2652 ++ return ret;
2653 ++
2654 ++ ++current->mm->total_vm;
2655 ++ return 0;
2656 ++}
2657 ++#endif
2658 ++
2659 ++/*
2660 ++ * PaX: decide what to do with offenders (regs->tpc = fault address)
2661 ++ *
2662 ++ * returns 1 when task should be killed
2663 ++ * 2 when patched PLT trampoline was detected
2664 ++ * 3 when unpatched PLT trampoline was detected
2665 ++ */
2666 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2667 ++{
2668 ++
2669 ++#ifdef CONFIG_PAX_EMUPLT
2670 ++ int err;
2671 ++
2672 ++ do { /* PaX: patched PLT emulation #1 */
2673 ++ unsigned int sethi1, sethi2, jmpl;
2674 ++
2675 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2676 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2677 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
2678 ++
2679 ++ if (err)
2680 ++ break;
2681 ++
2682 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2683 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2684 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2685 ++ {
2686 ++ unsigned long addr;
2687 ++
2688 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2689 ++ addr = regs->u_regs[UREG_G1];
2690 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2691 ++ regs->tpc = addr;
2692 ++ regs->tnpc = addr+4;
2693 ++ return 2;
2694 ++ }
2695 ++ } while (0);
2696 ++
2697 ++ { /* PaX: patched PLT emulation #2 */
2698 ++ unsigned int ba;
2699 ++
2700 ++ err = get_user(ba, (unsigned int *)regs->tpc);
2701 ++
2702 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2703 ++ unsigned long addr;
2704 ++
2705 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2706 ++ regs->tpc = addr;
2707 ++ regs->tnpc = addr+4;
2708 ++ return 2;
2709 ++ }
2710 ++ }
2711 ++
2712 ++ do { /* PaX: patched PLT emulation #3 */
2713 ++ unsigned int sethi, jmpl, nop;
2714 ++
2715 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2716 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
2717 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2718 ++
2719 ++ if (err)
2720 ++ break;
2721 ++
2722 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2723 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2724 ++ nop == 0x01000000U)
2725 ++ {
2726 ++ unsigned long addr;
2727 ++
2728 ++ addr = (sethi & 0x003FFFFFU) << 10;
2729 ++ regs->u_regs[UREG_G1] = addr;
2730 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2731 ++ regs->tpc = addr;
2732 ++ regs->tnpc = addr+4;
2733 ++ return 2;
2734 ++ }
2735 ++ } while (0);
2736 ++
2737 ++ do { /* PaX: patched PLT emulation #4 */
2738 ++ unsigned int mov1, call, mov2;
2739 ++
2740 ++ err = get_user(mov1, (unsigned int *)regs->tpc);
2741 ++ err |= get_user(call, (unsigned int *)(regs->tpc+4));
2742 ++ err |= get_user(mov2, (unsigned int *)(regs->tpc+8));
2743 ++
2744 ++ if (err)
2745 ++ break;
2746 ++
2747 ++ if (mov1 == 0x8210000FU &&
2748 ++ (call & 0xC0000000U) == 0x40000000U &&
2749 ++ mov2 == 0x9E100001U)
2750 ++ {
2751 ++ unsigned long addr;
2752 ++
2753 ++ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
2754 ++ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2755 ++ regs->tpc = addr;
2756 ++ regs->tnpc = addr+4;
2757 ++ return 2;
2758 ++ }
2759 ++ } while (0);
2760 ++
2761 ++ do { /* PaX: patched PLT emulation #5 */
2762 ++ unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop;
2763 ++
2764 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2765 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2766 ++ err |= get_user(or1, (unsigned int *)(regs->tpc+8));
2767 ++ err |= get_user(or2, (unsigned int *)(regs->tpc+12));
2768 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+16));
2769 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
2770 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
2771 ++
2772 ++ if (err)
2773 ++ break;
2774 ++
2775 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2776 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2777 ++ (or1 & 0xFFFFE000U) == 0x82106000U &&
2778 ++ (or2 & 0xFFFFE000U) == 0x8A116000U &&
2779 ++ sllx == 0x83287020 &&
2780 ++ jmpl == 0x81C04005U &&
2781 ++ nop == 0x01000000U)
2782 ++ {
2783 ++ unsigned long addr;
2784 ++
2785 ++ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
2786 ++ regs->u_regs[UREG_G1] <<= 32;
2787 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
2788 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2789 ++ regs->tpc = addr;
2790 ++ regs->tnpc = addr+4;
2791 ++ return 2;
2792 ++ }
2793 ++ } while (0);
2794 ++
2795 ++ do { /* PaX: patched PLT emulation #6 */
2796 ++ unsigned int sethi1, sethi2, sllx, or, jmpl, nop;
2797 ++
2798 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2799 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2800 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+8));
2801 ++ err |= get_user(or, (unsigned int *)(regs->tpc+12));
2802 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+16));
2803 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+20));
2804 ++
2805 ++ if (err)
2806 ++ break;
2807 ++
2808 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2809 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2810 ++ sllx == 0x83287020 &&
2811 ++ (or & 0xFFFFE000U) == 0x8A116000U &&
2812 ++ jmpl == 0x81C04005U &&
2813 ++ nop == 0x01000000U)
2814 ++ {
2815 ++ unsigned long addr;
2816 ++
2817 ++ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
2818 ++ regs->u_regs[UREG_G1] <<= 32;
2819 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
2820 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2821 ++ regs->tpc = addr;
2822 ++ regs->tnpc = addr+4;
2823 ++ return 2;
2824 ++ }
2825 ++ } while (0);
2826 ++
2827 ++ do { /* PaX: patched PLT emulation #7 */
2828 ++ unsigned int sethi, ba, nop;
2829 ++
2830 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2831 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2832 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2833 ++
2834 ++ if (err)
2835 ++ break;
2836 ++
2837 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2838 ++ (ba & 0xFFF00000U) == 0x30600000U &&
2839 ++ nop == 0x01000000U)
2840 ++ {
2841 ++ unsigned long addr;
2842 ++
2843 ++ addr = (sethi & 0x003FFFFFU) << 10;
2844 ++ regs->u_regs[UREG_G1] = addr;
2845 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2846 ++ regs->tpc = addr;
2847 ++ regs->tnpc = addr+4;
2848 ++ return 2;
2849 ++ }
2850 ++ } while (0);
2851 ++
2852 ++ do { /* PaX: unpatched PLT emulation step 1 */
2853 ++ unsigned int sethi, ba, nop;
2854 ++
2855 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2856 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2857 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2858 ++
2859 ++ if (err)
2860 ++ break;
2861 ++
2862 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2863 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2864 ++ nop == 0x01000000U)
2865 ++ {
2866 ++ unsigned long addr;
2867 ++ unsigned int save, call;
2868 ++
2869 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2870 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2871 ++ else
2872 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2873 ++
2874 ++ err = get_user(save, (unsigned int *)addr);
2875 ++ err |= get_user(call, (unsigned int *)(addr+4));
2876 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2877 ++ if (err)
2878 ++ break;
2879 ++
2880 ++ if (save == 0x9DE3BFA8U &&
2881 ++ (call & 0xC0000000U) == 0x40000000U &&
2882 ++ nop == 0x01000000U)
2883 ++ {
2884 ++ struct vm_area_struct *vma;
2885 ++ unsigned long call_dl_resolve;
2886 ++
2887 ++ down_read(&current->mm->mmap_sem);
2888 ++ call_dl_resolve = current->mm->call_dl_resolve;
2889 ++ up_read(&current->mm->mmap_sem);
2890 ++ if (likely(call_dl_resolve))
2891 ++ goto emulate;
2892 ++
2893 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2894 ++
2895 ++ down_write(&current->mm->mmap_sem);
2896 ++ if (current->mm->call_dl_resolve) {
2897 ++ call_dl_resolve = current->mm->call_dl_resolve;
2898 ++ up_write(&current->mm->mmap_sem);
2899 ++ if (vma)
2900 ++ kmem_cache_free(vm_area_cachep, vma);
2901 ++ goto emulate;
2902 ++ }
2903 ++
2904 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2905 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2906 ++ up_write(&current->mm->mmap_sem);
2907 ++ if (vma)
2908 ++ kmem_cache_free(vm_area_cachep, vma);
2909 ++ return 1;
2910 ++ }
2911 ++
2912 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2913 ++ up_write(&current->mm->mmap_sem);
2914 ++ kmem_cache_free(vm_area_cachep, vma);
2915 ++ return 1;
2916 ++ }
2917 ++
2918 ++ current->mm->call_dl_resolve = call_dl_resolve;
2919 ++ up_write(&current->mm->mmap_sem);
2920 ++
2921 ++emulate:
2922 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2923 ++ regs->tpc = call_dl_resolve;
2924 ++ regs->tnpc = addr+4;
2925 ++ return 3;
2926 ++ }
2927 ++ }
2928 ++ } while (0);
2929 ++
2930 ++ do { /* PaX: unpatched PLT emulation step 2 */
2931 ++ unsigned int save, call, nop;
2932 ++
2933 ++ err = get_user(save, (unsigned int *)(regs->tpc-4));
2934 ++ err |= get_user(call, (unsigned int *)regs->tpc);
2935 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
2936 ++ if (err)
2937 ++ break;
2938 ++
2939 ++ if (save == 0x9DE3BFA8U &&
2940 ++ (call & 0xC0000000U) == 0x40000000U &&
2941 ++ nop == 0x01000000U)
2942 ++ {
2943 ++ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2944 ++
2945 ++ regs->u_regs[UREG_RETPC] = regs->tpc;
2946 ++ regs->tpc = dl_resolve;
2947 ++ regs->tnpc = dl_resolve+4;
2948 ++ return 3;
2949 ++ }
2950 ++ } while (0);
2951 ++#endif
2952 ++
2953 ++ return 1;
2954 ++}
2955 ++
2956 ++void pax_report_insns(void *pc, void *sp)
2957 ++{
2958 ++ unsigned long i;
2959 ++
2960 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2961 ++ for (i = 0; i < 5; i++) {
2962 ++ unsigned int c;
2963 ++ if (get_user(c, (unsigned int *)pc+i))
2964 ++ printk(KERN_CONT "???????? ");
2965 ++ else
2966 ++ printk(KERN_CONT "%08x ", c);
2967 ++ }
2968 ++ printk("\n");
2969 ++}
2970 ++#endif
2971 ++
2972 + asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
2973 + {
2974 + struct mm_struct *mm = current->mm;
2975 +@@ -302,8 +666,10 @@ asmlinkage void __kprobes do_sparc64_fau
2976 + goto intr_or_no_mm;
2977 +
2978 + if (test_thread_flag(TIF_32BIT)) {
2979 +- if (!(regs->tstate & TSTATE_PRIV))
2980 ++ if (!(regs->tstate & TSTATE_PRIV)) {
2981 + regs->tpc &= 0xffffffff;
2982 ++ regs->tnpc &= 0xffffffff;
2983 ++ }
2984 + address &= 0xffffffff;
2985 + }
2986 +
2987 +@@ -320,6 +686,29 @@ asmlinkage void __kprobes do_sparc64_fau
2988 + if (!vma)
2989 + goto bad_area;
2990 +
2991 ++#ifdef CONFIG_PAX_PAGEEXEC
2992 ++ /* PaX: detect ITLB misses on non-exec pages */
2993 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
2994 ++ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
2995 ++ {
2996 ++ if (address != regs->tpc)
2997 ++ goto good_area;
2998 ++
2999 ++ up_read(&mm->mmap_sem);
3000 ++ switch (pax_handle_fetch_fault(regs)) {
3001 ++
3002 ++#ifdef CONFIG_PAX_EMUPLT
3003 ++ case 2:
3004 ++ case 3:
3005 ++ return;
3006 ++#endif
3007 ++
3008 ++ }
3009 ++ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
3010 ++ do_group_exit(SIGKILL);
3011 ++ }
3012 ++#endif
3013 ++
3014 + /* Pure DTLB misses do not tell us whether the fault causing
3015 + * load/store/atomic was a write or not, it only says that there
3016 + * was no match. So in such a case we (carefully) read the
3017 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/Makefile linux-2.6.27.10/arch/sparc64/mm/Makefile
3018 +--- linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-07 12:55:34.000000000 -0500
3019 ++++ linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-18 03:38:43.000000000 -0500
3020 +@@ -2,7 +2,7 @@
3021 + #
3022 +
3023 + EXTRA_AFLAGS := -ansi
3024 +-EXTRA_CFLAGS := -Werror
3025 ++#EXTRA_CFLAGS := -Werror
3026 +
3027 + obj-y := ultra.o tlb.o tsb.o fault.o init.o generic.o
3028 +
3029 +diff -urNp linux-2.6.27.10/arch/um/sys-i386/syscalls.c linux-2.6.27.10/arch/um/sys-i386/syscalls.c
3030 +--- linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-07 12:55:34.000000000 -0500
3031 ++++ linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-18 03:38:43.000000000 -0500
3032 +@@ -10,6 +10,21 @@
3033 + #include "asm/uaccess.h"
3034 + #include "asm/unistd.h"
3035 +
3036 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
3037 ++{
3038 ++ unsigned long pax_task_size = TASK_SIZE;
3039 ++
3040 ++#ifdef CONFIG_PAX_SEGMEXEC
3041 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
3042 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
3043 ++#endif
3044 ++
3045 ++ if (len > pax_task_size || addr > pax_task_size - len)
3046 ++ return -EINVAL;
3047 ++
3048 ++ return 0;
3049 ++}
3050 ++
3051 + /*
3052 + * Perform the select(nd, in, out, ex, tv) and mmap() system
3053 + * calls. Linux/i386 didn't use to be able to handle more than
3054 +diff -urNp linux-2.6.27.10/arch/x86/boot/bitops.h linux-2.6.27.10/arch/x86/boot/bitops.h
3055 +--- linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-07 12:55:34.000000000 -0500
3056 ++++ linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-18 03:38:44.000000000 -0500
3057 +@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
3058 + u8 v;
3059 + const u32 *p = (const u32 *)addr;
3060 +
3061 +- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
3062 ++ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
3063 + return v;
3064 + }
3065 +
3066 +@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
3067 +
3068 + static inline void set_bit(int nr, void *addr)
3069 + {
3070 +- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
3071 ++ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
3072 + }
3073 +
3074 + #endif /* BOOT_BITOPS_H */
3075 +diff -urNp linux-2.6.27.10/arch/x86/boot/boot.h linux-2.6.27.10/arch/x86/boot/boot.h
3076 +--- linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-07 12:55:34.000000000 -0500
3077 ++++ linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-18 03:38:44.000000000 -0500
3078 +@@ -80,7 +80,7 @@ static inline void io_delay(void)
3079 + static inline u16 ds(void)
3080 + {
3081 + u16 seg;
3082 +- asm("movw %%ds,%0" : "=rm" (seg));
3083 ++ asm volatile("movw %%ds,%0" : "=rm" (seg));
3084 + return seg;
3085 + }
3086 +
3087 +@@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t
3088 + static inline int memcmp(const void *s1, const void *s2, size_t len)
3089 + {
3090 + u8 diff;
3091 +- asm("repe; cmpsb; setnz %0"
3092 ++ asm volatile("repe; cmpsb; setnz %0"
3093 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
3094 + return diff;
3095 + }
3096 +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
3097 +--- linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-07 12:55:34.000000000 -0500
3098 ++++ linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-18 03:38:44.000000000 -0500
3099 +@@ -70,7 +70,7 @@ startup_32:
3100 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
3101 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
3102 + #else
3103 +- movl $LOAD_PHYSICAL_ADDR, %ebx
3104 ++ movl $____LOAD_PHYSICAL_ADDR, %ebx
3105 + #endif
3106 +
3107 + /* Replace the compressed data size with the uncompressed size */
3108 +@@ -105,7 +105,7 @@ startup_32:
3109 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
3110 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
3111 + #else
3112 +- movl $LOAD_PHYSICAL_ADDR, %ebp
3113 ++ movl $____LOAD_PHYSICAL_ADDR, %ebp
3114 + #endif
3115 +
3116 + /*
3117 +@@ -159,16 +159,15 @@ relocated:
3118 + * and where it was actually loaded.
3119 + */
3120 + movl %ebp, %ebx
3121 +- subl $LOAD_PHYSICAL_ADDR, %ebx
3122 ++ subl $____LOAD_PHYSICAL_ADDR, %ebx
3123 + jz 2f /* Nothing to be done if loaded at compiled addr. */
3124 + /*
3125 + * Process relocations.
3126 + */
3127 +
3128 + 1: subl $4, %edi
3129 +- movl 0(%edi), %ecx
3130 +- testl %ecx, %ecx
3131 +- jz 2f
3132 ++ movl (%edi), %ecx
3133 ++ jecxz 2f
3134 + addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
3135 + jmp 1b
3136 + 2:
3137 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/misc.c linux-2.6.27.10/arch/x86/boot/compressed/misc.c
3138 +--- linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-07 12:55:34.000000000 -0500
3139 ++++ linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-18 03:38:44.000000000 -0500
3140 +@@ -371,7 +371,7 @@ static void parse_elf(void *output)
3141 + case PT_LOAD:
3142 + #ifdef CONFIG_RELOCATABLE
3143 + dest = output;
3144 +- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
3145 ++ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
3146 + #else
3147 + dest = (void *)(phdr->p_paddr);
3148 + #endif
3149 +@@ -423,7 +423,7 @@ asmlinkage void decompress_kernel(void *
3150 + if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))
3151 + error("Destination address too large");
3152 + #ifndef CONFIG_RELOCATABLE
3153 +- if ((u32)output != LOAD_PHYSICAL_ADDR)
3154 ++ if ((u32)output != ____LOAD_PHYSICAL_ADDR)
3155 + error("Wrong destination address");
3156 + #endif
3157 + #endif
3158 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/relocs.c linux-2.6.27.10/arch/x86/boot/compressed/relocs.c
3159 +--- linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-07 12:55:34.000000000 -0500
3160 ++++ linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-18 03:38:44.000000000 -0500
3161 +@@ -10,8 +10,11 @@
3162 + #define USE_BSD
3163 + #include <endian.h>
3164 +
3165 ++#include "../../../../include/linux/autoconf.h"
3166 ++
3167 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
3168 + static Elf32_Ehdr ehdr;
3169 ++static Elf32_Phdr *phdr;
3170 + static unsigned long reloc_count, reloc_idx;
3171 + static unsigned long *relocs;
3172 +
3173 +@@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp)
3174 + }
3175 + }
3176 +
3177 ++static void read_phdrs(FILE *fp)
3178 ++{
3179 ++ int i;
3180 ++
3181 ++ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
3182 ++ if (!phdr) {
3183 ++ die("Unable to allocate %d program headers\n",
3184 ++ ehdr.e_phnum);
3185 ++ }
3186 ++ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
3187 ++ die("Seek to %d failed: %s\n",
3188 ++ ehdr.e_phoff, strerror(errno));
3189 ++ }
3190 ++ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
3191 ++ die("Cannot read ELF program headers: %s\n",
3192 ++ strerror(errno));
3193 ++ }
3194 ++ for(i = 0; i < ehdr.e_phnum; i++) {
3195 ++ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
3196 ++ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
3197 ++ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
3198 ++ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
3199 ++ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
3200 ++ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
3201 ++ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
3202 ++ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
3203 ++ }
3204 ++
3205 ++}
3206 ++
3207 + static void read_shdrs(FILE *fp)
3208 + {
3209 + int i;
3210 +@@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp)
3211 + static void read_relocs(FILE *fp)
3212 + {
3213 + int i,j;
3214 ++ uint32_t base;
3215 ++
3216 + for (i = 0; i < ehdr.e_shnum; i++) {
3217 + struct section *sec = &secs[i];
3218 + if (sec->shdr.sh_type != SHT_REL) {
3219 +@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
3220 + die("Cannot read symbol table: %s\n",
3221 + strerror(errno));
3222 + }
3223 ++ base = 0;
3224 ++ for (j = 0; j < ehdr.e_phnum; j++) {
3225 ++ if (phdr[j].p_type != PT_LOAD )
3226 ++ continue;
3227 ++ 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)
3228 ++ continue;
3229 ++ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
3230 ++ break;
3231 ++ }
3232 + for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
3233 + Elf32_Rel *rel = &sec->reltab[j];
3234 +- rel->r_offset = elf32_to_cpu(rel->r_offset);
3235 ++ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
3236 + rel->r_info = elf32_to_cpu(rel->r_info);
3237 + }
3238 + }
3239 +@@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El
3240 + if (sym->st_shndx == SHN_ABS) {
3241 + continue;
3242 + }
3243 ++ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
3244 ++ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10))
3245 ++ continue;
3246 ++#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
3247 ++ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
3248 ++ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
3249 ++ continue;
3250 ++ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
3251 ++ continue;
3252 ++ if (!strcmp(sec_name(sym->st_shndx), ".text.head")) {
3253 ++ if (strcmp(sym_name(sym_strtab, sym), "__init_end") &&
3254 ++ strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET"))
3255 ++ continue;
3256 ++ }
3257 ++ if (!strcmp(sec_name(sym->st_shndx), ".text"))
3258 ++ continue;
3259 ++#endif
3260 + if (r_type == R_386_PC32) {
3261 + /* PC relative relocations don't need to be adjusted */
3262 + }
3263 +@@ -631,6 +692,7 @@ int main(int argc, char **argv)
3264 + fname, strerror(errno));
3265 + }
3266 + read_ehdr(fp);
3267 ++ read_phdrs(fp);
3268 + read_shdrs(fp);
3269 + read_strtabs(fp);
3270 + read_symtabs(fp);
3271 +diff -urNp linux-2.6.27.10/arch/x86/boot/cpucheck.c linux-2.6.27.10/arch/x86/boot/cpucheck.c
3272 +--- linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-07 12:55:34.000000000 -0500
3273 ++++ linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-18 03:38:44.000000000 -0500
3274 +@@ -74,7 +74,7 @@ static int has_fpu(void)
3275 + u16 fcw = -1, fsw = -1;
3276 + u32 cr0;
3277 +
3278 +- asm("movl %%cr0,%0" : "=r" (cr0));
3279 ++ asm volatile("movl %%cr0,%0" : "=r" (cr0));
3280 + if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
3281 + cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
3282 + asm volatile("movl %0,%%cr0" : : "r" (cr0));
3283 +@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
3284 + {
3285 + u32 f0, f1;
3286 +
3287 +- asm("pushfl ; "
3288 ++ asm volatile("pushfl ; "
3289 + "pushfl ; "
3290 + "popl %0 ; "
3291 + "movl %0,%1 ; "
3292 +@@ -115,7 +115,7 @@ static void get_flags(void)
3293 + set_bit(X86_FEATURE_FPU, cpu.flags);
3294 +
3295 + if (has_eflag(X86_EFLAGS_ID)) {
3296 +- asm("cpuid"
3297 ++ asm volatile("cpuid"
3298 + : "=a" (max_intel_level),
3299 + "=b" (cpu_vendor[0]),
3300 + "=d" (cpu_vendor[1]),
3301 +@@ -124,7 +124,7 @@ static void get_flags(void)
3302 +
3303 + if (max_intel_level >= 0x00000001 &&
3304 + max_intel_level <= 0x0000ffff) {
3305 +- asm("cpuid"
3306 ++ asm volatile("cpuid"
3307 + : "=a" (tfms),
3308 + "=c" (cpu.flags[4]),
3309 + "=d" (cpu.flags[0])
3310 +@@ -136,7 +136,7 @@ static void get_flags(void)
3311 + cpu.model += ((tfms >> 16) & 0xf) << 4;
3312 + }
3313 +
3314 +- asm("cpuid"
3315 ++ asm volatile("cpuid"
3316 + : "=a" (max_amd_level)
3317 + : "a" (0x80000000)
3318 + : "ebx", "ecx", "edx");
3319 +@@ -144,7 +144,7 @@ static void get_flags(void)
3320 + if (max_amd_level >= 0x80000001 &&
3321 + max_amd_level <= 0x8000ffff) {
3322 + u32 eax = 0x80000001;
3323 +- asm("cpuid"
3324 ++ asm volatile("cpuid"
3325 + : "+a" (eax),
3326 + "=c" (cpu.flags[6]),
3327 + "=d" (cpu.flags[1])
3328 +@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3329 + u32 ecx = MSR_K7_HWCR;
3330 + u32 eax, edx;
3331 +
3332 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3333 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3334 + eax &= ~(1 << 15);
3335 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3336 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3337 +
3338 + get_flags(); /* Make sure it really did something */
3339 + err = check_flags();
3340 +@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3341 + u32 ecx = MSR_VIA_FCR;
3342 + u32 eax, edx;
3343 +
3344 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3345 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3346 + eax |= (1<<1)|(1<<7);
3347 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3348 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3349 +
3350 + set_bit(X86_FEATURE_CX8, cpu.flags);
3351 + err = check_flags();
3352 +@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
3353 + u32 eax, edx;
3354 + u32 level = 1;
3355 +
3356 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3357 +- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3358 +- asm("cpuid"
3359 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3360 ++ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3361 ++ asm volatile("cpuid"
3362 + : "+a" (level), "=d" (cpu.flags[0])
3363 + : : "ecx", "ebx");
3364 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3365 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3366 +
3367 + err = check_flags();
3368 + }
3369 +diff -urNp linux-2.6.27.10/arch/x86/boot/edd.c linux-2.6.27.10/arch/x86/boot/edd.c
3370 +--- linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-07 12:55:34.000000000 -0500
3371 ++++ linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-18 03:38:44.000000000 -0500
3372 +@@ -76,7 +76,7 @@ static int get_edd_info(u8 devno, struct
3373 + ax = 0x4100;
3374 + bx = EDDMAGIC1;
3375 + dx = devno;
3376 +- asm("pushfl; stc; int $0x13; setc %%al; popfl"
3377 ++ asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
3378 + : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
3379 + : : "esi", "edi");
3380 +
3381 +@@ -95,7 +95,7 @@ static int get_edd_info(u8 devno, struct
3382 + ei->params.length = sizeof(ei->params);
3383 + ax = 0x4800;
3384 + dx = devno;
3385 +- asm("pushfl; int $0x13; popfl"
3386 ++ asm volatile("pushfl; int $0x13; popfl"
3387 + : "+a" (ax), "+d" (dx), "=m" (ei->params)
3388 + : "S" (&ei->params)
3389 + : "ebx", "ecx", "edi");
3390 +@@ -106,7 +106,7 @@ static int get_edd_info(u8 devno, struct
3391 + ax = 0x0800;
3392 + dx = devno;
3393 + di = 0;
3394 +- asm("pushw %%es; "
3395 ++ asm volatile("pushw %%es; "
3396 + "movw %%di,%%es; "
3397 + "pushfl; stc; int $0x13; setc %%al; popfl; "
3398 + "popw %%es"
3399 +diff -urNp linux-2.6.27.10/arch/x86/boot/main.c linux-2.6.27.10/arch/x86/boot/main.c
3400 +--- linux-2.6.27.10/arch/x86/boot/main.c 2008-11-07 12:55:34.000000000 -0500
3401 ++++ linux-2.6.27.10/arch/x86/boot/main.c 2008-11-18 03:38:44.000000000 -0500
3402 +@@ -78,7 +78,7 @@ static void query_ist(void)
3403 + if (cpu.level < 6)
3404 + return;
3405 +
3406 +- asm("int $0x15"
3407 ++ asm volatile("int $0x15"
3408 + : "=a" (boot_params.ist_info.signature),
3409 + "=b" (boot_params.ist_info.command),
3410 + "=c" (boot_params.ist_info.event),
3411 +diff -urNp linux-2.6.27.10/arch/x86/boot/mca.c linux-2.6.27.10/arch/x86/boot/mca.c
3412 +--- linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-07 12:55:34.000000000 -0500
3413 ++++ linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-18 03:38:44.000000000 -0500
3414 +@@ -19,7 +19,7 @@ int query_mca(void)
3415 + u8 err;
3416 + u16 es, bx, len;
3417 +
3418 +- asm("pushw %%es ; "
3419 ++ asm volatile("pushw %%es ; "
3420 + "int $0x15 ; "
3421 + "setc %0 ; "
3422 + "movw %%es, %1 ; "
3423 +diff -urNp linux-2.6.27.10/arch/x86/boot/memory.c linux-2.6.27.10/arch/x86/boot/memory.c
3424 +--- linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-07 12:55:34.000000000 -0500
3425 ++++ linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-18 03:38:44.000000000 -0500
3426 +@@ -30,7 +30,7 @@ static int detect_memory_e820(void)
3427 + /* Important: %edx is clobbered by some BIOSes,
3428 + so it must be either used for the error output
3429 + or explicitly marked clobbered. */
3430 +- asm("int $0x15; setc %0"
3431 ++ asm volatile("int $0x15; setc %0"
3432 + : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
3433 + "=m" (*desc)
3434 + : "D" (desc), "d" (SMAP), "a" (0xe820));
3435 +@@ -65,7 +65,7 @@ static int detect_memory_e801(void)
3436 +
3437 + bx = cx = dx = 0;
3438 + ax = 0xe801;
3439 +- asm("stc; int $0x15; setc %0"
3440 ++ asm volatile("stc; int $0x15; setc %0"
3441 + : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
3442 +
3443 + if (err)
3444 +@@ -95,7 +95,7 @@ static int detect_memory_88(void)
3445 + u8 err;
3446 +
3447 + ax = 0x8800;
3448 +- asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3449 ++ asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3450 +
3451 + boot_params.screen_info.ext_mem_k = ax;
3452 +
3453 +diff -urNp linux-2.6.27.10/arch/x86/boot/video.c linux-2.6.27.10/arch/x86/boot/video.c
3454 +--- linux-2.6.27.10/arch/x86/boot/video.c 2008-11-07 12:55:34.000000000 -0500
3455 ++++ linux-2.6.27.10/arch/x86/boot/video.c 2008-11-18 03:38:44.000000000 -0500
3456 +@@ -23,7 +23,7 @@ static void store_cursor_position(void)
3457 +
3458 + ax = 0x0300;
3459 + bx = 0;
3460 +- asm(INT10
3461 ++ asm volatile(INT10
3462 + : "=d" (curpos), "+a" (ax), "+b" (bx)
3463 + : : "ecx", "esi", "edi");
3464 +
3465 +@@ -38,7 +38,7 @@ static void store_video_mode(void)
3466 + /* N.B.: the saving of the video page here is a bit silly,
3467 + since we pretty much assume page 0 everywhere. */
3468 + ax = 0x0f00;
3469 +- asm(INT10
3470 ++ asm volatile(INT10
3471 + : "+a" (ax), "=b" (page)
3472 + : : "ecx", "edx", "esi", "edi");
3473 +
3474 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vesa.c linux-2.6.27.10/arch/x86/boot/video-vesa.c
3475 +--- linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-07 12:55:34.000000000 -0500
3476 ++++ linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-18 03:38:44.000000000 -0500
3477 +@@ -41,7 +41,7 @@ static int vesa_probe(void)
3478 +
3479 + ax = 0x4f00;
3480 + di = (size_t)&vginfo;
3481 +- asm(INT10
3482 ++ asm volatile(INT10
3483 + : "+a" (ax), "+D" (di), "=m" (vginfo)
3484 + : : "ebx", "ecx", "edx", "esi");
3485 +
3486 +@@ -68,7 +68,7 @@ static int vesa_probe(void)
3487 + ax = 0x4f01;
3488 + cx = mode;
3489 + di = (size_t)&vminfo;
3490 +- asm(INT10
3491 ++ asm volatile(INT10
3492 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3493 + : : "ebx", "edx", "esi");
3494 +
3495 +@@ -123,7 +123,7 @@ static int vesa_set_mode(struct mode_inf
3496 + ax = 0x4f01;
3497 + cx = vesa_mode;
3498 + di = (size_t)&vminfo;
3499 +- asm(INT10
3500 ++ asm volatile(INT10
3501 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3502 + : : "ebx", "edx", "esi");
3503 +
3504 +@@ -203,19 +203,20 @@ static void vesa_dac_set_8bits(void)
3505 + /* Save the VESA protected mode info */
3506 + static void vesa_store_pm_info(void)
3507 + {
3508 +- u16 ax, bx, di, es;
3509 ++ u16 ax, bx, cx, di, es;
3510 +
3511 + ax = 0x4f0a;
3512 +- bx = di = 0;
3513 +- asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3514 +- : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
3515 +- : : "ecx", "esi");
3516 ++ bx = cx = di = 0;
3517 ++ asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3518 ++ : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
3519 ++ : : "esi");
3520 +
3521 + if (ax != 0x004f)
3522 + return;
3523 +
3524 + boot_params.screen_info.vesapm_seg = es;
3525 + boot_params.screen_info.vesapm_off = di;
3526 ++ boot_params.screen_info.vesapm_size = cx;
3527 + }
3528 +
3529 + /*
3530 +@@ -269,7 +270,7 @@ void vesa_store_edid(void)
3531 + /* Note: The VBE DDC spec is different from the main VESA spec;
3532 + we genuinely have to assume all registers are destroyed here. */
3533 +
3534 +- asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3535 ++ asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3536 + : "+a" (ax), "+b" (bx)
3537 + : "c" (cx), "D" (di)
3538 + : "esi");
3539 +@@ -285,7 +286,7 @@ void vesa_store_edid(void)
3540 + cx = 0; /* Controller 0 */
3541 + dx = 0; /* EDID block number */
3542 + di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
3543 +- asm(INT10
3544 ++ asm volatile(INT10
3545 + : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
3546 + : "c" (cx), "D" (di)
3547 + : "esi");
3548 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vga.c linux-2.6.27.10/arch/x86/boot/video-vga.c
3549 +--- linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-07 12:55:34.000000000 -0500
3550 ++++ linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-18 03:38:44.000000000 -0500
3551 +@@ -225,7 +225,7 @@ static int vga_probe(void)
3552 + };
3553 + u8 vga_flag;
3554 +
3555 +- asm(INT10
3556 ++ asm volatile(INT10
3557 + : "=b" (ega_bx)
3558 + : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
3559 + : "ecx", "edx", "esi", "edi");
3560 +@@ -237,7 +237,7 @@ static int vga_probe(void)
3561 + /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
3562 + if ((u8)ega_bx != 0x10) {
3563 + /* EGA/VGA */
3564 +- asm(INT10
3565 ++ asm volatile(INT10
3566 + : "=a" (vga_flag)
3567 + : "a" (0x1a00)
3568 + : "ebx", "ecx", "edx", "esi", "edi");
3569 +diff -urNp linux-2.6.27.10/arch/x86/boot/voyager.c linux-2.6.27.10/arch/x86/boot/voyager.c
3570 +--- linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-07 12:55:34.000000000 -0500
3571 ++++ linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-18 03:38:44.000000000 -0500
3572 +@@ -23,7 +23,7 @@ int query_voyager(void)
3573 +
3574 + data_ptr[0] = 0xff; /* Flag on config not found(?) */
3575 +
3576 +- asm("pushw %%es ; "
3577 ++ asm volatile("pushw %%es ; "
3578 + "int $0x15 ; "
3579 + "setc %0 ; "
3580 + "movw %%es, %1 ; "
3581 +diff -urNp linux-2.6.27.10/arch/x86/ia32/ia32_signal.c linux-2.6.27.10/arch/x86/ia32/ia32_signal.c
3582 +--- linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-07 12:55:34.000000000 -0500
3583 ++++ linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-18 03:38:44.000000000 -0500
3584 +@@ -535,6 +535,7 @@ int ia32_setup_rt_frame(int sig, struct
3585 + __NR_ia32_rt_sigreturn,
3586 + 0x80cd,
3587 + 0,
3588 ++ 0
3589 + };
3590 +
3591 + frame = get_sigframe(ka, regs, sizeof(*frame));
3592 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig linux-2.6.27.10/arch/x86/Kconfig
3593 +--- linux-2.6.27.10/arch/x86/Kconfig 2008-11-17 20:03:30.000000000 -0500
3594 ++++ linux-2.6.27.10/arch/x86/Kconfig 2008-11-18 03:38:44.000000000 -0500
3595 +@@ -912,7 +912,7 @@ config PAGE_OFFSET
3596 + hex
3597 + default 0xB0000000 if VMSPLIT_3G_OPT
3598 + default 0x80000000 if VMSPLIT_2G
3599 +- default 0x78000000 if VMSPLIT_2G_OPT
3600 ++ default 0x70000000 if VMSPLIT_2G_OPT
3601 + default 0x40000000 if VMSPLIT_1G
3602 + default 0xC0000000
3603 + depends on X86_32
3604 +@@ -1293,8 +1293,7 @@ config KEXEC_JUMP
3605 + config PHYSICAL_START
3606 + hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
3607 + default "0x1000000" if X86_NUMAQ
3608 +- default "0x200000" if X86_64
3609 +- default "0x100000"
3610 ++ default "0x200000"
3611 + help
3612 + This gives the physical address where the kernel is loaded.
3613 +
3614 +@@ -1386,9 +1385,9 @@ config HOTPLUG_CPU
3615 + suspend.
3616 +
3617 + config COMPAT_VDSO
3618 +- def_bool y
3619 ++ def_bool n
3620 + prompt "Compat VDSO support"
3621 +- depends on X86_32 || IA32_EMULATION
3622 ++ depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
3623 + help
3624 + Map the 32-bit VDSO to the predictable old-style address too.
3625 + ---help---
3626 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.cpu linux-2.6.27.10/arch/x86/Kconfig.cpu
3627 +--- linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-07 12:55:34.000000000 -0500
3628 ++++ linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-18 03:38:44.000000000 -0500
3629 +@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
3630 +
3631 + config X86_F00F_BUG
3632 + def_bool y
3633 +- depends on M586MMX || M586TSC || M586 || M486 || M386
3634 ++ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
3635 +
3636 + config X86_WP_WORKS_OK
3637 + def_bool y
3638 +@@ -360,7 +360,7 @@ config X86_POPAD_OK
3639 +
3640 + config X86_ALIGNMENT_16
3641 + def_bool y
3642 +- depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3643 ++ depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3644 +
3645 + config X86_INTEL_USERCOPY
3646 + def_bool y
3647 +@@ -406,7 +406,7 @@ config X86_CMPXCHG64
3648 + # generates cmov.
3649 + config X86_CMOV
3650 + def_bool y
3651 +- depends on (MK7 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3652 ++ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3653 +
3654 + config X86_MINIMUM_CPU_FAMILY
3655 + int
3656 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.debug linux-2.6.27.10/arch/x86/Kconfig.debug
3657 +--- linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-07 12:55:34.000000000 -0500
3658 ++++ linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-18 03:38:44.000000000 -0500
3659 +@@ -94,7 +94,7 @@ config X86_PTDUMP
3660 + config DEBUG_RODATA
3661 + bool "Write protect kernel read-only data structures"
3662 + default y
3663 +- depends on DEBUG_KERNEL
3664 ++ depends on DEBUG_KERNEL && BROKEN
3665 + help
3666 + Mark the kernel read-only data as write-protected in the pagetables,
3667 + in order to catch accidental (and incorrect) writes to such const
3668 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/boot.c linux-2.6.27.10/arch/x86/kernel/acpi/boot.c
3669 +--- linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:36.000000000 -0500
3670 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:46.000000000 -0500
3671 +@@ -1640,7 +1640,7 @@ static struct dmi_system_id __initdata a
3672 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
3673 + },
3674 + },
3675 +- {}
3676 ++ { NULL, NULL, {{0, NULL}}, NULL}
3677 + };
3678 +
3679 + /*
3680 +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
3681 +--- linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-07 12:55:34.000000000 -0500
3682 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-18 03:38:44.000000000 -0500
3683 +@@ -104,7 +104,7 @@ _start:
3684 + movl %eax, %ecx
3685 + orl %edx, %ecx
3686 + jz 1f
3687 +- movl $0xc0000080, %ecx
3688 ++ mov $MSR_EFER, %ecx
3689 + wrmsr
3690 + 1:
3691 +
3692 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c
3693 +--- linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-07 12:55:34.000000000 -0500
3694 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-18 11:45:34.000000000 -0500
3695 +@@ -37,6 +37,10 @@ int acpi_save_state_mem(void)
3696 + {
3697 + struct wakeup_header *header;
3698 +
3699 ++#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC)
3700 ++ unsigned long cr0;
3701 ++#endif
3702 ++
3703 + if (!acpi_realmode) {
3704 + printk(KERN_ERR "Could not allocate memory during boot, "
3705 + "S3 disabled\n");
3706 +@@ -99,8 +103,18 @@ int acpi_save_state_mem(void)
3707 + header->trampoline_segment = setup_trampoline() >> 4;
3708 + #ifdef CONFIG_SMP
3709 + stack_start.sp = temp_stack + 4096;
3710 ++
3711 ++#ifdef CONFIG_PAX_KERNEXEC
3712 ++ pax_open_kernel(cr0);
3713 ++#endif
3714 ++
3715 + early_gdt_descr.address =
3716 + (unsigned long)get_cpu_gdt_table(smp_processor_id());
3717 ++
3718 ++#ifdef CONFIG_PAX_KERNEXEC
3719 ++ pax_close_kernel(cr0);
3720 ++#endif
3721 ++
3722 + #endif
3723 + initial_code = (unsigned long)wakeup_long64;
3724 + saved_magic = 0x123456789abcdef0;
3725 +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
3726 +--- linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-07 12:55:34.000000000 -0500
3727 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-18 03:38:44.000000000 -0500
3728 +@@ -30,13 +30,11 @@ wakeup_pmode_return:
3729 + # and restore the stack ... but you need gdt for this to work
3730 + movl saved_context_esp, %esp
3731 +
3732 +- movl %cs:saved_magic, %eax
3733 +- cmpl $0x12345678, %eax
3734 ++ cmpl $0x12345678, saved_magic
3735 + jne bogus_magic
3736 +
3737 + # jump to place where we left off
3738 +- movl saved_eip, %eax
3739 +- jmp *%eax
3740 ++ jmp *(saved_eip)
3741 +
3742 + bogus_magic:
3743 + jmp bogus_magic
3744 +diff -urNp linux-2.6.27.10/arch/x86/kernel/alternative.c linux-2.6.27.10/arch/x86/kernel/alternative.c
3745 +--- linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-07 12:55:34.000000000 -0500
3746 ++++ linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-18 03:38:44.000000000 -0500
3747 +@@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc
3748 +
3749 + BUG_ON(p->len > MAX_PATCH_LEN);
3750 + /* prep the buffer with the original instructions */
3751 +- memcpy(insnbuf, p->instr, p->len);
3752 ++ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
3753 + used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
3754 + (unsigned long)p->instr, p->len);
3755 +
3756 +@@ -473,11 +473,26 @@ void __init alternative_instructions(voi
3757 + * instructions. And on the local CPU you need to be protected again NMI or MCE
3758 + * handlers seeing an inconsistent instruction while you patch.
3759 + */
3760 +-void *text_poke_early(void *addr, const void *opcode, size_t len)
3761 ++void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len)
3762 + {
3763 + unsigned long flags;
3764 ++
3765 ++#ifdef CONFIG_PAX_KERNEXEC
3766 ++ unsigned long cr0;
3767 ++#endif
3768 ++
3769 + local_irq_save(flags);
3770 +- memcpy(addr, opcode, len);
3771 ++
3772 ++#ifdef CONFIG_PAX_KERNEXEC
3773 ++ pax_open_kernel(cr0);
3774 ++#endif
3775 ++
3776 ++ memcpy(ktla_ktva(addr), opcode, len);
3777 ++
3778 ++#ifdef CONFIG_PAX_KERNEXEC
3779 ++ pax_close_kernel(cr0);
3780 ++#endif
3781 ++
3782 + local_irq_restore(flags);
3783 + sync_core();
3784 + /* Could also do a CLFLUSH here to speed up CPU recovery; but
3785 +@@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const
3786 + */
3787 + void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
3788 + {
3789 +- unsigned long flags;
3790 +- char *vaddr;
3791 +- int nr_pages = 2;
3792 ++ unsigned char *vaddr = ktla_ktva(addr);
3793 + struct page *pages[2];
3794 +- int i;
3795 ++ size_t i;
3796 ++
3797 ++ if (!core_kernel_text((unsigned long)addr)
3798 +
3799 +- if (!core_kernel_text((unsigned long)addr)) {
3800 +- pages[0] = vmalloc_to_page(addr);
3801 +- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
3802 ++#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
3803 ++ && (vaddr < MODULES_VADDR || MODULES_END < vaddr)
3804 ++#endif
3805 ++
3806 ++ ) {
3807 ++ pages[0] = vmalloc_to_page(vaddr);
3808 ++ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
3809 + } else {
3810 +- pages[0] = virt_to_page(addr);
3811 ++ pages[0] = virt_to_page(vaddr);
3812 + WARN_ON(!PageReserved(pages[0]));
3813 +- pages[1] = virt_to_page(addr + PAGE_SIZE);
3814 ++ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
3815 + }
3816 + BUG_ON(!pages[0]);
3817 +- if (!pages[1])
3818 +- nr_pages = 1;
3819 +- vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
3820 +- BUG_ON(!vaddr);
3821 +- local_irq_save(flags);
3822 +- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
3823 +- local_irq_restore(flags);
3824 +- vunmap(vaddr);
3825 +- sync_core();
3826 +- /* Could also do a CLFLUSH here to speed up CPU recovery; but
3827 +- that causes hangs on some VIA CPUs. */
3828 ++ text_poke_early(addr, opcode, len);
3829 + for (i = 0; i < len; i++)
3830 +- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
3831 ++ BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]);
3832 + return addr;
3833 + }
3834 +diff -urNp linux-2.6.27.10/arch/x86/kernel/apm_32.c linux-2.6.27.10/arch/x86/kernel/apm_32.c
3835 +--- linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-07 12:55:34.000000000 -0500
3836 ++++ linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-18 03:38:44.000000000 -0500
3837 +@@ -408,7 +408,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq
3838 + static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
3839 + static struct apm_user *user_list;
3840 + static DEFINE_SPINLOCK(user_list_lock);
3841 +-static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
3842 ++static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } };
3843 +
3844 + static const char driver_version[] = "1.16ac"; /* no spaces */
3845 +
3846 +@@ -603,19 +603,42 @@ static u8 apm_bios_call(u32 func, u32 eb
3847 + struct desc_struct save_desc_40;
3848 + struct desc_struct *gdt;
3849 +
3850 ++#ifdef CONFIG_PAX_KERNEXEC
3851 ++ unsigned long cr0;
3852 ++#endif
3853 ++
3854 + cpus = apm_save_cpus();
3855 +
3856 + cpu = get_cpu();
3857 + gdt = get_cpu_gdt_table(cpu);
3858 + save_desc_40 = gdt[0x40 / 8];
3859 ++
3860 ++#ifdef CONFIG_PAX_KERNEXEC
3861 ++ pax_open_kernel(cr0);
3862 ++#endif
3863 ++
3864 + gdt[0x40 / 8] = bad_bios_desc;
3865 +
3866 ++#ifdef CONFIG_PAX_KERNEXEC
3867 ++ pax_close_kernel(cr0);
3868 ++#endif
3869 ++
3870 + apm_irq_save(flags);
3871 + APM_DO_SAVE_SEGS;
3872 + apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
3873 + APM_DO_RESTORE_SEGS;
3874 + apm_irq_restore(flags);
3875 ++
3876 ++#ifdef CONFIG_PAX_KERNEXEC
3877 ++ pax_open_kernel(cr0);
3878 ++#endif
3879 ++
3880 + gdt[0x40 / 8] = save_desc_40;
3881 ++
3882 ++#ifdef CONFIG_PAX_KERNEXEC
3883 ++ pax_close_kernel(cr0);
3884 ++#endif
3885 ++
3886 + put_cpu();
3887 + apm_restore_cpus(cpus);
3888 +
3889 +@@ -646,19 +669,42 @@ static u8 apm_bios_call_simple(u32 func,
3890 + struct desc_struct save_desc_40;
3891 + struct desc_struct *gdt;
3892 +
3893 ++#ifdef CONFIG_PAX_KERNEXEC
3894 ++ unsigned long cr0;
3895 ++#endif
3896 ++
3897 + cpus = apm_save_cpus();
3898 +
3899 + cpu = get_cpu();
3900 + gdt = get_cpu_gdt_table(cpu);
3901 + save_desc_40 = gdt[0x40 / 8];
3902 ++
3903 ++#ifdef CONFIG_PAX_KERNEXEC
3904 ++ pax_open_kernel(cr0);
3905 ++#endif
3906 ++
3907 + gdt[0x40 / 8] = bad_bios_desc;
3908 +
3909 ++#ifdef CONFIG_PAX_KERNEXEC
3910 ++ pax_close_kernel(cr0);
3911 ++#endif
3912 ++
3913 + apm_irq_save(flags);
3914 + APM_DO_SAVE_SEGS;
3915 + error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
3916 + APM_DO_RESTORE_SEGS;
3917 + apm_irq_restore(flags);
3918 ++
3919 ++#ifdef CONFIG_PAX_KERNEXEC
3920 ++ pax_open_kernel(cr0);
3921 ++#endif
3922 ++
3923 + gdt[0x40 / 8] = save_desc_40;
3924 ++
3925 ++#ifdef CONFIG_PAX_KERNEXEC
3926 ++ pax_close_kernel(cr0);
3927 ++#endif
3928 ++
3929 + put_cpu();
3930 + apm_restore_cpus(cpus);
3931 + return error;
3932 +@@ -930,7 +976,7 @@ recalc:
3933 +
3934 + static void apm_power_off(void)
3935 + {
3936 +- unsigned char po_bios_call[] = {
3937 ++ const unsigned char po_bios_call[] = {
3938 + 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
3939 + 0x8e, 0xd0, /* movw ax,ss */
3940 + 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
3941 +@@ -1877,7 +1923,10 @@ static const struct file_operations apm_
3942 + static struct miscdevice apm_device = {
3943 + APM_MINOR_DEV,
3944 + "apm_bios",
3945 +- &apm_bios_fops
3946 ++ &apm_bios_fops,
3947 ++ {NULL, NULL},
3948 ++ NULL,
3949 ++ NULL
3950 + };
3951 +
3952 +
3953 +@@ -2198,7 +2247,7 @@ static struct dmi_system_id __initdata a
3954 + { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
3955 + },
3956 +
3957 +- { }
3958 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
3959 + };
3960 +
3961 + /*
3962 +@@ -2216,6 +2265,10 @@ static int __init apm_init(void)
3963 + struct desc_struct *gdt;
3964 + int err;
3965 +
3966 ++#ifdef CONFIG_PAX_KERNEXEC
3967 ++ unsigned long cr0;
3968 ++#endif
3969 ++
3970 + dmi_check_system(apm_dmi_table);
3971 +
3972 + if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) {
3973 +@@ -2289,9 +2342,18 @@ static int __init apm_init(void)
3974 + * This is for buggy BIOS's that refer to (real mode) segment 0x40
3975 + * even though they are called in protected mode.
3976 + */
3977 ++
3978 ++#ifdef CONFIG_PAX_KERNEXEC
3979 ++ pax_open_kernel(cr0);
3980 ++#endif
3981 ++
3982 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
3983 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
3984 +
3985 ++#ifdef CONFIG_PAX_KERNEXEC
3986 ++ pax_close_kernel(cr0);
3987 ++#endif
3988 ++
3989 + /*
3990 + * Set up the long jump entry point to the APM BIOS, which is called
3991 + * from inline assembly.
3992 +@@ -2310,6 +2372,11 @@ static int __init apm_init(void)
3993 + * code to that CPU.
3994 + */
3995 + gdt = get_cpu_gdt_table(0);
3996 ++
3997 ++#ifdef CONFIG_PAX_KERNEXEC
3998 ++ pax_open_kernel(cr0);
3999 ++#endif
4000 ++
4001 + set_base(gdt[APM_CS >> 3],
4002 + __va((unsigned long)apm_info.bios.cseg << 4));
4003 + set_base(gdt[APM_CS_16 >> 3],
4004 +@@ -2317,6 +2384,10 @@ static int __init apm_init(void)
4005 + set_base(gdt[APM_DS >> 3],
4006 + __va((unsigned long)apm_info.bios.dseg << 4));
4007 +
4008 ++#ifdef CONFIG_PAX_KERNEXEC
4009 ++ pax_close_kernel(cr0);
4010 ++#endif
4011 ++
4012 + proc_create("apm", 0, NULL, &apm_file_ops);
4013 +
4014 + kapmd_task = kthread_create(apm, NULL, "kapmd");
4015 +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
4016 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-07 12:55:34.000000000 -0500
4017 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-18 03:38:44.000000000 -0500
4018 +@@ -100,6 +100,7 @@ void foo(void)
4019 + DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
4020 + DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
4021 + DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
4022 ++ DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE);
4023 +
4024 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
4025 +
4026 +@@ -113,6 +114,7 @@ void foo(void)
4027 + OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
4028 + OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
4029 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
4030 ++ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
4031 + #endif
4032 +
4033 + #ifdef CONFIG_XEN
4034 +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
4035 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-07 12:55:34.000000000 -0500
4036 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-18 03:38:44.000000000 -0500
4037 +@@ -122,6 +122,7 @@ int main(void)
4038 + ENTRY(cr8);
4039 + BLANK();
4040 + #undef ENTRY
4041 ++ DEFINE(TSS_size, sizeof(struct tss_struct));
4042 + DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
4043 + BLANK();
4044 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
4045 +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
4046 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-07 12:55:34.000000000 -0500
4047 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-18 03:38:44.000000000 -0500
4048 +@@ -37,22 +37,6 @@
4049 +
4050 + #include "cpu.h"
4051 +
4052 +-/* We need valid kernel segments for data and code in long mode too
4053 +- * IRET will check the segment types kkeil 2000/10/28
4054 +- * Also sysret mandates a special GDT layout
4055 +- */
4056 +-/* The TLS descriptors are currently at a different place compared to i386.
4057 +- Hopefully nobody expects them at a fixed place (Wine?) */
4058 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
4059 +- [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
4060 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
4061 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
4062 +- [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
4063 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
4064 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
4065 +-} };
4066 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
4067 +-
4068 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
4069 +
4070 + /* Current gdt points %fs at the "master" per-cpu area: after this,
4071 +@@ -457,15 +441,13 @@ cpumask_t cpu_initialized __cpuinitdata
4072 + struct x8664_pda **_cpu_pda __read_mostly;
4073 + EXPORT_SYMBOL(_cpu_pda);
4074 +
4075 +-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
4076 ++struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table };
4077 +
4078 + char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
4079 +
4080 + unsigned long __supported_pte_mask __read_mostly = ~0UL;
4081 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
4082 +
4083 +-static int do_not_nx __cpuinitdata;
4084 +-
4085 + /* noexec=on|off
4086 + Control non executable mappings for 64bit processes.
4087 +
4088 +@@ -478,9 +460,7 @@ static int __init nonx_setup(char *str)
4089 + return -EINVAL;
4090 + if (!strncmp(str, "on", 2)) {
4091 + __supported_pte_mask |= _PAGE_NX;
4092 +- do_not_nx = 0;
4093 + } else if (!strncmp(str, "off", 3)) {
4094 +- do_not_nx = 1;
4095 + __supported_pte_mask &= ~_PAGE_NX;
4096 + }
4097 + return 0;
4098 +@@ -576,7 +556,7 @@ void __cpuinit check_efer(void)
4099 + unsigned long efer;
4100 +
4101 + rdmsrl(MSR_EFER, efer);
4102 +- if (!(efer & EFER_NX) || do_not_nx)
4103 ++ if (!(efer & EFER_NX))
4104 + __supported_pte_mask &= ~_PAGE_NX;
4105 + }
4106 +
4107 +@@ -598,7 +578,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist
4108 + void __cpuinit cpu_init(void)
4109 + {
4110 + int cpu = stack_smp_processor_id();
4111 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4112 ++ struct tss_struct *t = init_tss + cpu;
4113 + struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
4114 + unsigned long v;
4115 + char *estacks = NULL;
4116 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common.c linux-2.6.27.10/arch/x86/kernel/cpu/common.c
4117 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-07 12:55:34.000000000 -0500
4118 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-18 03:38:44.000000000 -0500
4119 +@@ -4,7 +4,6 @@
4120 + #include <linux/smp.h>
4121 + #include <linux/module.h>
4122 + #include <linux/percpu.h>
4123 +-#include <linux/bootmem.h>
4124 + #include <asm/processor.h>
4125 + #include <asm/i387.h>
4126 + #include <asm/msr.h>
4127 +@@ -22,42 +21,6 @@
4128 +
4129 + #include "cpu.h"
4130 +
4131 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
4132 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
4133 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
4134 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
4135 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
4136 +- /*
4137 +- * Segments used for calling PnP BIOS have byte granularity.
4138 +- * They code segments and data segments have fixed 64k limits,
4139 +- * the transfer segment sizes are set at run time.
4140 +- */
4141 +- /* 32-bit code */
4142 +- [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
4143 +- /* 16-bit code */
4144 +- [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
4145 +- /* 16-bit data */
4146 +- [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
4147 +- /* 16-bit data */
4148 +- [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
4149 +- /* 16-bit data */
4150 +- [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
4151 +- /*
4152 +- * The APM segments have byte granularity and their bases
4153 +- * are set at run time. All have 64k limits.
4154 +- */
4155 +- /* 32-bit code */
4156 +- [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
4157 +- /* 16-bit code */
4158 +- [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
4159 +- /* data */
4160 +- [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
4161 +-
4162 +- [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
4163 +- [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
4164 +-} };
4165 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
4166 +-
4167 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
4168 +
4169 + static int cachesize_override __cpuinitdata = -1;
4170 +@@ -493,6 +456,10 @@ static void __cpuinit identify_cpu(struc
4171 + * we do "generic changes."
4172 + */
4173 +
4174 ++#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4175 ++ setup_clear_cpu_cap(X86_FEATURE_SEP);
4176 ++#endif
4177 ++
4178 + /* If the model name is still unset, do table lookup. */
4179 + if (!c->x86_model_id[0]) {
4180 + char *p;
4181 +@@ -629,7 +596,7 @@ static __init int setup_disablecpuid(cha
4182 + }
4183 + __setup("clearcpuid=", setup_disablecpuid);
4184 +
4185 +-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
4186 ++cpumask_t cpu_initialized = CPU_MASK_NONE;
4187 +
4188 + void __init early_cpu_init(void)
4189 + {
4190 +@@ -658,7 +625,7 @@ void switch_to_new_gdt(void)
4191 + {
4192 + struct desc_ptr gdt_descr;
4193 +
4194 +- gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
4195 ++ gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id());
4196 + gdt_descr.size = GDT_SIZE - 1;
4197 + load_gdt(&gdt_descr);
4198 + asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory");
4199 +@@ -674,7 +641,7 @@ void __cpuinit cpu_init(void)
4200 + {
4201 + int cpu = smp_processor_id();
4202 + struct task_struct *curr = current;
4203 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4204 ++ struct tss_struct *t = init_tss + cpu;
4205 + struct thread_struct *thread = &curr->thread;
4206 +
4207 + if (cpu_test_and_set(cpu, cpu_initialized)) {
4208 +@@ -729,7 +696,7 @@ void __cpuinit cpu_init(void)
4209 + }
4210 +
4211 + #ifdef CONFIG_HOTPLUG_CPU
4212 +-void __cpuinit cpu_uninit(void)
4213 ++void cpu_uninit(void)
4214 + {
4215 + int cpu = raw_smp_processor_id();
4216 + cpu_clear(cpu, cpu_initialized);
4217 +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
4218 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-07 12:55:34.000000000 -0500
4219 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-18 03:38:44.000000000 -0500
4220 +@@ -560,7 +560,7 @@ static const struct dmi_system_id sw_any
4221 + DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
4222 + },
4223 + },
4224 +- { }
4225 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
4226 + };
4227 + #endif
4228 +
4229 +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
4230 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-07 12:55:34.000000000 -0500
4231 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-18 03:38:44.000000000 -0500
4232 +@@ -225,7 +225,7 @@ static struct cpu_model models[] =
4233 + { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
4234 + { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
4235 +
4236 +- { NULL, }
4237 ++ { NULL, NULL, 0, NULL}
4238 + };
4239 + #undef _BANIAS
4240 + #undef BANIAS
4241 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/intel.c linux-2.6.27.10/arch/x86/kernel/cpu/intel.c
4242 +--- linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-07 12:55:34.000000000 -0500
4243 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-18 03:38:44.000000000 -0500
4244 +@@ -107,7 +107,7 @@ static void __cpuinit trap_init_f00f_bug
4245 + * Update the IDT descriptor and reload the IDT so that
4246 + * it uses the read-only mapped virtual address.
4247 + */
4248 +- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
4249 ++ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
4250 + load_idt(&idt_descr);
4251 + }
4252 + #endif
4253 +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
4254 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-07 12:55:34.000000000 -0500
4255 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-18 03:38:44.000000000 -0500
4256 +@@ -681,6 +681,7 @@ static struct miscdevice mce_log_device
4257 + MISC_MCELOG_MINOR,
4258 + "mcelog",
4259 + &mce_chrdev_ops,
4260 ++ {NULL, NULL}, NULL, NULL
4261 + };
4262 +
4263 + static unsigned long old_cr4 __initdata;
4264 +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
4265 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-07 12:55:34.000000000 -0500
4266 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-18 03:38:44.000000000 -0500
4267 +@@ -31,11 +31,11 @@ static struct fixed_range_block fixed_ra
4268 + { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */
4269 + { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */
4270 + { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */
4271 +- {}
4272 ++ { 0, 0 }
4273 + };
4274 +
4275 + static unsigned long smp_changes_mask;
4276 +-static struct mtrr_state mtrr_state = {};
4277 ++static struct mtrr_state mtrr_state;
4278 + static int mtrr_state_set;
4279 + u64 mtrr_tom2;
4280 +
4281 +diff -urNp linux-2.6.27.10/arch/x86/kernel/crash.c linux-2.6.27.10/arch/x86/kernel/crash.c
4282 +--- linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-07 12:55:34.000000000 -0500
4283 ++++ linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-18 03:38:44.000000000 -0500
4284 +@@ -59,7 +59,7 @@ static int crash_nmi_callback(struct not
4285 + local_irq_disable();
4286 +
4287 + #ifdef CONFIG_X86_32
4288 +- if (!user_mode_vm(regs)) {
4289 ++ if (!user_mode(regs)) {
4290 + crash_fixup_ss_esp(&fixed_regs, regs);
4291 + regs = &fixed_regs;
4292 + }
4293 +diff -urNp linux-2.6.27.10/arch/x86/kernel/doublefault_32.c linux-2.6.27.10/arch/x86/kernel/doublefault_32.c
4294 +--- linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-07 12:55:34.000000000 -0500
4295 ++++ linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-18 03:38:44.000000000 -0500
4296 +@@ -11,7 +11,7 @@
4297 +
4298 + #define DOUBLEFAULT_STACKSIZE (1024)
4299 + static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
4300 +-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
4301 ++#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
4302 +
4303 + #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
4304 +
4305 +@@ -21,7 +21,7 @@ static void doublefault_fn(void)
4306 + unsigned long gdt, tss;
4307 +
4308 + store_gdt(&gdt_desc);
4309 +- gdt = gdt_desc.address;
4310 ++ gdt = (unsigned long)gdt_desc.address;
4311 +
4312 + printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
4313 +
4314 +@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach
4315 + /* 0x2 bit is always set */
4316 + .flags = X86_EFLAGS_SF | 0x2,
4317 + .sp = STACK_START,
4318 +- .es = __USER_DS,
4319 ++ .es = __KERNEL_DS,
4320 + .cs = __KERNEL_CS,
4321 + .ss = __KERNEL_DS,
4322 +- .ds = __USER_DS,
4323 ++ .ds = __KERNEL_DS,
4324 + .fs = __KERNEL_PERCPU,
4325 +
4326 + .__cr3 = __pa(swapper_pg_dir)
4327 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_32.c linux-2.6.27.10/arch/x86/kernel/efi_32.c
4328 +--- linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-07 12:55:34.000000000 -0500
4329 ++++ linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-18 03:38:44.000000000 -0500
4330 +@@ -38,70 +38,38 @@
4331 + */
4332 +
4333 + static unsigned long efi_rt_eflags;
4334 +-static pgd_t efi_bak_pg_dir_pointer[2];
4335 ++static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
4336 +
4337 +-void efi_call_phys_prelog(void)
4338 ++void __init efi_call_phys_prelog(void)
4339 + {
4340 +- unsigned long cr4;
4341 +- unsigned long temp;
4342 + struct desc_ptr gdt_descr;
4343 +
4344 + local_irq_save(efi_rt_eflags);
4345 +
4346 +- /*
4347 +- * If I don't have PAE, I should just duplicate two entries in page
4348 +- * directory. If I have PAE, I just need to duplicate one entry in
4349 +- * page directory.
4350 +- */
4351 +- cr4 = read_cr4_safe();
4352 +
4353 +- if (cr4 & X86_CR4_PAE) {
4354 +- efi_bak_pg_dir_pointer[0].pgd =
4355 +- swapper_pg_dir[pgd_index(0)].pgd;
4356 +- swapper_pg_dir[0].pgd =
4357 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4358 +- } else {
4359 +- efi_bak_pg_dir_pointer[0].pgd =
4360 +- swapper_pg_dir[pgd_index(0)].pgd;
4361 +- efi_bak_pg_dir_pointer[1].pgd =
4362 +- swapper_pg_dir[pgd_index(0x400000)].pgd;
4363 +- swapper_pg_dir[pgd_index(0)].pgd =
4364 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4365 +- temp = PAGE_OFFSET + 0x400000;
4366 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4367 +- swapper_pg_dir[pgd_index(temp)].pgd;
4368 +- }
4369 ++ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
4370 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
4371 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
4372 +
4373 + /*
4374 + * After the lock is released, the original page table is restored.
4375 + */
4376 + __flush_tlb_all();
4377 +
4378 +- gdt_descr.address = __pa(get_cpu_gdt_table(0));
4379 ++ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
4380 + gdt_descr.size = GDT_SIZE - 1;
4381 + load_gdt(&gdt_descr);
4382 + }
4383 +
4384 +-void efi_call_phys_epilog(void)
4385 ++void __init efi_call_phys_epilog(void)
4386 + {
4387 +- unsigned long cr4;
4388 + struct desc_ptr gdt_descr;
4389 +
4390 +- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
4391 ++ gdt_descr.address = get_cpu_gdt_table(0);
4392 + gdt_descr.size = GDT_SIZE - 1;
4393 + load_gdt(&gdt_descr);
4394 +
4395 +- cr4 = read_cr4_safe();
4396 +-
4397 +- if (cr4 & X86_CR4_PAE) {
4398 +- swapper_pg_dir[pgd_index(0)].pgd =
4399 +- efi_bak_pg_dir_pointer[0].pgd;
4400 +- } else {
4401 +- swapper_pg_dir[pgd_index(0)].pgd =
4402 +- efi_bak_pg_dir_pointer[0].pgd;
4403 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4404 +- efi_bak_pg_dir_pointer[1].pgd;
4405 +- }
4406 ++ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
4407 +
4408 + /*
4409 + * After the lock is released, the original page table is restored.
4410 +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
4411 +--- linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-07 12:55:34.000000000 -0500
4412 ++++ linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-18 03:38:44.000000000 -0500
4413 +@@ -6,6 +6,7 @@
4414 + */
4415 +
4416 + #include <linux/linkage.h>
4417 ++#include <linux/init.h>
4418 + #include <asm/page.h>
4419 +
4420 + /*
4421 +@@ -20,7 +21,7 @@
4422 + * service functions will comply with gcc calling convention, too.
4423 + */
4424 +
4425 +-.text
4426 ++__INIT
4427 + ENTRY(efi_call_phys)
4428 + /*
4429 + * 0. The function can only be called in Linux kernel. So CS has been
4430 +@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
4431 + * The mapping of lower virtual memory has been created in prelog and
4432 + * epilog.
4433 + */
4434 +- movl $1f, %edx
4435 +- subl $__PAGE_OFFSET, %edx
4436 +- jmp *%edx
4437 ++ jmp 1f-__PAGE_OFFSET
4438 + 1:
4439 +
4440 + /*
4441 +@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
4442 + * parameter 2, ..., param n. To make things easy, we save the return
4443 + * address of efi_call_phys in a global variable.
4444 + */
4445 +- popl %edx
4446 +- movl %edx, saved_return_addr
4447 +- /* get the function pointer into ECX*/
4448 +- popl %ecx
4449 +- movl %ecx, efi_rt_function_ptr
4450 +- movl $2f, %edx
4451 +- subl $__PAGE_OFFSET, %edx
4452 +- pushl %edx
4453 ++ popl (saved_return_addr)
4454 ++ popl (efi_rt_function_ptr)
4455 +
4456 + /*
4457 + * 3. Clear PG bit in %CR0.
4458 +@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
4459 + /*
4460 + * 5. Call the physical function.
4461 + */
4462 +- jmp *%ecx
4463 ++ call *(efi_rt_function_ptr-__PAGE_OFFSET)
4464 +
4465 +-2:
4466 + /*
4467 + * 6. After EFI runtime service returns, control will return to
4468 + * following instruction. We'd better readjust stack pointer first.
4469 +@@ -88,34 +80,27 @@ ENTRY(efi_call_phys)
4470 + movl %cr0, %edx
4471 + orl $0x80000000, %edx
4472 + movl %edx, %cr0
4473 +- jmp 1f
4474 +-1:
4475 ++
4476 + /*
4477 + * 8. Now restore the virtual mode from flat mode by
4478 + * adding EIP with PAGE_OFFSET.
4479 + */
4480 +- movl $1f, %edx
4481 +- jmp *%edx
4482 ++ jmp 1f+__PAGE_OFFSET
4483 + 1:
4484 +
4485 + /*
4486 + * 9. Balance the stack. And because EAX contain the return value,
4487 + * we'd better not clobber it.
4488 + */
4489 +- leal efi_rt_function_ptr, %edx
4490 +- movl (%edx), %ecx
4491 +- pushl %ecx
4492 ++ pushl (efi_rt_function_ptr)
4493 +
4494 + /*
4495 +- * 10. Push the saved return address onto the stack and return.
4496 ++ * 10. Return to the saved return address.
4497 + */
4498 +- leal saved_return_addr, %edx
4499 +- movl (%edx), %ecx
4500 +- pushl %ecx
4501 +- ret
4502 ++ jmpl *(saved_return_addr)
4503 + .previous
4504 +
4505 +-.data
4506 ++__INITDATA
4507 + saved_return_addr:
4508 + .long 0
4509 + efi_rt_function_ptr:
4510 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_32.S linux-2.6.27.10/arch/x86/kernel/entry_32.S
4511 +--- linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-07 12:55:34.000000000 -0500
4512 ++++ linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-18 03:38:44.000000000 -0500
4513 +@@ -101,7 +101,7 @@
4514 + #define resume_userspace_sig resume_userspace
4515 + #endif
4516 +
4517 +-#define SAVE_ALL \
4518 ++#define __SAVE_ALL(_DS) \
4519 + cld; \
4520 + pushl %fs; \
4521 + CFI_ADJUST_CFA_OFFSET 4;\
4522 +@@ -133,12 +133,26 @@
4523 + pushl %ebx; \
4524 + CFI_ADJUST_CFA_OFFSET 4;\
4525 + CFI_REL_OFFSET ebx, 0;\
4526 +- movl $(__USER_DS), %edx; \
4527 ++ movl $(_DS), %edx; \
4528 + movl %edx, %ds; \
4529 + movl %edx, %es; \
4530 + movl $(__KERNEL_PERCPU), %edx; \
4531 + movl %edx, %fs
4532 +
4533 ++#ifdef CONFIG_PAX_KERNEXEC
4534 ++#define SAVE_ALL \
4535 ++ __SAVE_ALL(__KERNEL_DS); \
4536 ++ GET_CR0_INTO_EDX; \
4537 ++ movl %edx, %esi; \
4538 ++ orl $X86_CR0_WP, %edx; \
4539 ++ xorl %edx, %esi; \
4540 ++ SET_CR0_FROM_EDX
4541 ++#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4542 ++#define SAVE_ALL __SAVE_ALL(__KERNEL_DS)
4543 ++#else
4544 ++#define SAVE_ALL __SAVE_ALL(__USER_DS)
4545 ++#endif
4546 ++
4547 + #define RESTORE_INT_REGS \
4548 + popl %ebx; \
4549 + CFI_ADJUST_CFA_OFFSET -4;\
4550 +@@ -229,6 +243,11 @@ ENTRY(ret_from_fork)
4551 + CFI_ADJUST_CFA_OFFSET 4
4552 + popfl
4553 + CFI_ADJUST_CFA_OFFSET -4
4554 ++
4555 ++#ifdef CONFIG_PAX_KERNEXEC
4556 ++ xorl %esi, %esi
4557 ++#endif
4558 ++
4559 + jmp syscall_exit
4560 + CFI_ENDPROC
4561 + END(ret_from_fork)
4562 +@@ -252,7 +271,17 @@ check_userspace:
4563 + movb PT_CS(%esp), %al
4564 + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
4565 + cmpl $USER_RPL, %eax
4566 ++
4567 ++#ifdef CONFIG_PAX_KERNEXEC
4568 ++ jae resume_userspace
4569 ++
4570 ++ GET_CR0_INTO_EDX
4571 ++ xorl %esi, %edx
4572 ++ SET_CR0_FROM_EDX
4573 ++ jmp resume_kernel
4574 ++#else
4575 + jb resume_kernel # not returning to v8086 or userspace
4576 ++#endif
4577 +
4578 + ENTRY(resume_userspace)
4579 + LOCKDEP_SYS_EXIT
4580 +@@ -314,10 +343,9 @@ sysenter_past_esp:
4581 + /*CFI_REL_OFFSET cs, 0*/
4582 + /*
4583 + * Push current_thread_info()->sysenter_return to the stack.
4584 +- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
4585 +- * pushed above; +8 corresponds to copy_thread's esp0 setting.
4586 + */
4587 +- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
4588 ++ GET_THREAD_INFO(%ebp)
4589 ++ pushl TI_sysenter_return(%ebp)
4590 + CFI_ADJUST_CFA_OFFSET 4
4591 + CFI_REL_OFFSET eip, 0
4592 +
4593 +@@ -330,9 +358,17 @@ sysenter_past_esp:
4594 + * Load the potential sixth argument from user stack.
4595 + * Careful about security.
4596 + */
4597 ++ movl PT_OLDESP(%esp),%ebp
4598 ++
4599 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4600 ++ mov PT_OLDSS(%esp),%ds
4601 ++1: movl %ds:(%ebp),%ebp
4602 ++#else
4603 + cmpl $__PAGE_OFFSET-3,%ebp
4604 + jae syscall_fault
4605 + 1: movl (%ebp),%ebp
4606 ++#endif
4607 ++
4608 + movl %ebp,PT_EBP(%esp)
4609 + .section __ex_table,"a"
4610 + .align 4
4611 +@@ -356,12 +392,23 @@ sysenter_do_call:
4612 + testw $_TIF_ALLWORK_MASK, %cx
4613 + jne sysexit_audit
4614 + sysenter_exit:
4615 ++
4616 ++#ifdef CONFIG_PAX_RANDKSTACK
4617 ++ pushl %eax
4618 ++ CFI_ADJUST_CFA_OFFSET 4
4619 ++ call pax_randomize_kstack
4620 ++ popl %eax
4621 ++ CFI_ADJUST_CFA_OFFSET -4
4622 ++#endif
4623 ++
4624 + /* if something modifies registers it must also disable sysexit */
4625 + movl PT_EIP(%esp), %edx
4626 + movl PT_OLDESP(%esp), %ecx
4627 + xorl %ebp,%ebp
4628 + TRACE_IRQS_ON
4629 + 1: mov PT_FS(%esp), %fs
4630 ++2: mov PT_DS(%esp), %ds
4631 ++3: mov PT_ES(%esp), %es
4632 + ENABLE_INTERRUPTS_SYSEXIT
4633 +
4634 + #ifdef CONFIG_AUDITSYSCALL
4635 +@@ -404,11 +451,17 @@ sysexit_audit:
4636 +
4637 + CFI_ENDPROC
4638 + .pushsection .fixup,"ax"
4639 +-2: movl $0,PT_FS(%esp)
4640 ++4: movl $0,PT_FS(%esp)
4641 ++ jmp 1b
4642 ++5: movl $0,PT_DS(%esp)
4643 ++ jmp 1b
4644 ++6: movl $0,PT_ES(%esp)
4645 + jmp 1b
4646 + .section __ex_table,"a"
4647 + .align 4
4648 +- .long 1b,2b
4649 ++ .long 1b,4b
4650 ++ .long 2b,5b
4651 ++ .long 3b,6b
4652 + .popsection
4653 + ENDPROC(ia32_sysenter_target)
4654 +
4655 +@@ -438,6 +491,10 @@ syscall_exit:
4656 + testw $_TIF_ALLWORK_MASK, %cx # current->work
4657 + jne syscall_exit_work
4658 +
4659 ++#ifdef CONFIG_PAX_RANDKSTACK
4660 ++ call pax_randomize_kstack
4661 ++#endif
4662 ++
4663 + restore_all:
4664 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
4665 + # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
4666 +@@ -531,25 +588,19 @@ work_resched:
4667 +
4668 + work_notifysig: # deal with pending signals and
4669 + # notify-resume requests
4670 ++ movl %esp, %eax
4671 + #ifdef CONFIG_VM86
4672 + testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
4673 +- movl %esp, %eax
4674 +- jne work_notifysig_v86 # returning to kernel-space or
4675 ++ jz 1f # returning to kernel-space or
4676 + # vm86-space
4677 +- xorl %edx, %edx
4678 +- call do_notify_resume
4679 +- jmp resume_userspace_sig
4680 +
4681 +- ALIGN
4682 +-work_notifysig_v86:
4683 + pushl %ecx # save ti_flags for do_notify_resume
4684 + CFI_ADJUST_CFA_OFFSET 4
4685 + call save_v86_state # %eax contains pt_regs pointer
4686 + popl %ecx
4687 + CFI_ADJUST_CFA_OFFSET -4
4688 + movl %eax, %esp
4689 +-#else
4690 +- movl %esp, %eax
4691 ++1:
4692 + #endif
4693 + xorl %edx, %edx
4694 + call do_notify_resume
4695 +@@ -595,17 +646,24 @@ syscall_badsys:
4696 + END(syscall_badsys)
4697 + CFI_ENDPROC
4698 +
4699 +-#define FIXUP_ESPFIX_STACK \
4700 +- /* since we are on a wrong stack, we cant make it a C code :( */ \
4701 +- PER_CPU(gdt_page, %ebx); \
4702 +- GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
4703 +- addl %esp, %eax; \
4704 +- pushl $__KERNEL_DS; \
4705 +- CFI_ADJUST_CFA_OFFSET 4; \
4706 +- pushl %eax; \
4707 +- CFI_ADJUST_CFA_OFFSET 4; \
4708 +- lss (%esp), %esp; \
4709 ++.macro FIXUP_ESPFIX_STACK
4710 ++ /* since we are on a wrong stack, we cant make it a C code :( */
4711 ++#ifdef CONFIG_SMP
4712 ++ movl PER_CPU_VAR(cpu_number), %ebx;
4713 ++ shll $PAGE_SHIFT_asm, %ebx;
4714 ++ addl $cpu_gdt_table, %ebx;
4715 ++#else
4716 ++ movl $cpu_gdt_table, %ebx;
4717 ++#endif
4718 ++ GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah);
4719 ++ addl %esp, %eax;
4720 ++ pushl $__KERNEL_DS;
4721 ++ CFI_ADJUST_CFA_OFFSET 4;
4722 ++ pushl %eax;
4723 ++ CFI_ADJUST_CFA_OFFSET 4;
4724 ++ lss (%esp), %esp;
4725 + CFI_ADJUST_CFA_OFFSET -8;
4726 ++.endm
4727 + #define UNWIND_ESPFIX_STACK \
4728 + movl %ss, %eax; \
4729 + /* see if on espfix stack */ \
4730 +@@ -622,7 +680,7 @@ END(syscall_badsys)
4731 + * Build the entry stubs and pointer table with
4732 + * some assembler magic.
4733 + */
4734 +-.section .rodata,"a"
4735 ++.section .rodata,"a",@progbits
4736 + ENTRY(interrupt)
4737 + .text
4738 +
4739 +@@ -722,12 +780,21 @@ error_code:
4740 + popl %ecx
4741 + CFI_ADJUST_CFA_OFFSET -4
4742 + /*CFI_REGISTER es, ecx*/
4743 ++
4744 ++#ifdef CONFIG_PAX_KERNEXEC
4745 ++ GET_CR0_INTO_EDX
4746 ++ movl %edx, %esi
4747 ++ orl $X86_CR0_WP, %edx
4748 ++ xorl %edx, %esi
4749 ++ SET_CR0_FROM_EDX
4750 ++#endif
4751 ++
4752 + movl PT_FS(%esp), %edi # get the function address
4753 + movl PT_ORIG_EAX(%esp), %edx # get the error code
4754 + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
4755 + mov %ecx, PT_FS(%esp)
4756 + /*CFI_REL_OFFSET fs, ES*/
4757 +- movl $(__USER_DS), %ecx
4758 ++ movl $(__KERNEL_DS), %ecx
4759 + movl %ecx, %ds
4760 + movl %ecx, %es
4761 + movl %esp,%eax # pt_regs pointer
4762 +@@ -861,6 +928,13 @@ nmi_stack_correct:
4763 + xorl %edx,%edx # zero error code
4764 + movl %esp,%eax # pt_regs pointer
4765 + call do_nmi
4766 ++
4767 ++#ifdef CONFIG_PAX_KERNEXEC
4768 ++ GET_CR0_INTO_EDX
4769 ++ xorl %esi, %edx
4770 ++ SET_CR0_FROM_EDX
4771 ++#endif
4772 ++
4773 + jmp restore_nocheck_notrace
4774 + CFI_ENDPROC
4775 +
4776 +@@ -901,6 +975,13 @@ nmi_espfix_stack:
4777 + FIXUP_ESPFIX_STACK # %eax == %esp
4778 + xorl %edx,%edx # zero error code
4779 + call do_nmi
4780 ++
4781 ++#ifdef CONFIG_PAX_KERNEXEC
4782 ++ GET_CR0_INTO_EDX
4783 ++ xorl %esi, %edx
4784 ++ SET_CR0_FROM_EDX
4785 ++#endif
4786 ++
4787 + RESTORE_REGS
4788 + lss 12+4(%esp), %esp # back to espfix stack
4789 + CFI_ADJUST_CFA_OFFSET -24
4790 +@@ -1226,7 +1307,6 @@ END(mcount)
4791 + #endif /* CONFIG_DYNAMIC_FTRACE */
4792 + #endif /* CONFIG_FTRACE */
4793 +
4794 +-.section .rodata,"a"
4795 + #include "syscall_table_32.S"
4796 +
4797 + syscall_table_size=(.-sys_call_table)
4798 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_64.S linux-2.6.27.10/arch/x86/kernel/entry_64.S
4799 +--- linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-07 12:55:34.000000000 -0500
4800 ++++ linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-18 03:38:44.000000000 -0500
4801 +@@ -930,17 +930,18 @@ END(spurious_interrupt)
4802 + xorl %ebx,%ebx
4803 + 1:
4804 + .if \ist
4805 +- movq %gs:pda_data_offset, %rbp
4806 ++ imul $TSS_size, %gs:pda_cpunumber, %ebp
4807 ++ lea init_tss(%rbp), %rbp
4808 + .endif
4809 + movq %rsp,%rdi
4810 + movq ORIG_RAX(%rsp),%rsi
4811 + movq $-1,ORIG_RAX(%rsp)
4812 + .if \ist
4813 +- subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4814 ++ subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4815 + .endif
4816 + call \sym
4817 + .if \ist
4818 +- addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4819 ++ addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4820 + .endif
4821 + DISABLE_INTERRUPTS(CLBR_NONE)
4822 + .if \irqtrace
4823 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ftrace.c linux-2.6.27.10/arch/x86/kernel/ftrace.c
4824 +--- linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-11-07 12:55:34.000000000 -0500
4825 ++++ linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-12-10 22:28:27.000000000 -0500
4826 +@@ -103,9 +103,9 @@ notrace int ftrace_update_ftrace_func(ft
4827 + unsigned char old[MCOUNT_INSN_SIZE], *new;
4828 + int ret;
4829 +
4830 +- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
4831 ++ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
4832 + new = ftrace_call_replace(ip, (unsigned long)func);
4833 +- ret = ftrace_modify_code(ip, old, new);
4834 ++ ret = ftrace_modify_code(ktla_ktva(ip), old, new);
4835 +
4836 + return ret;
4837 + }
4838 +@@ -120,9 +120,9 @@ notrace int ftrace_mcount_set(unsigned l
4839 + * Replace the mcount stub with a pointer to the
4840 + * ip recorder function.
4841 + */
4842 +- memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
4843 ++ memcpy(old, ktla_ktva(mcount_call), MCOUNT_INSN_SIZE);
4844 + new = ftrace_call_replace(ip, *addr);
4845 +- *addr = ftrace_modify_code(ip, old, new);
4846 ++ *addr = ftrace_modify_code(ktla_ktva(ip), old, new);
4847 +
4848 + return 0;
4849 + }
4850 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head32.c linux-2.6.27.10/arch/x86/kernel/head32.c
4851 +--- linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-07 12:55:34.000000000 -0500
4852 ++++ linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-18 03:38:44.000000000 -0500
4853 +@@ -12,10 +12,11 @@
4854 + #include <asm/sections.h>
4855 + #include <asm/e820.h>
4856 + #include <asm/bios_ebda.h>
4857 ++#include <asm/boot.h>
4858 +
4859 + void __init i386_start_kernel(void)
4860 + {
4861 +- reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
4862 ++ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS");
4863 +
4864 + #ifdef CONFIG_BLK_DEV_INITRD
4865 + /* Reserve INITRD */
4866 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_32.S linux-2.6.27.10/arch/x86/kernel/head_32.S
4867 +--- linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-07 12:55:34.000000000 -0500
4868 ++++ linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-18 03:38:44.000000000 -0500
4869 +@@ -19,6 +19,7 @@
4870 + #include <asm/asm-offsets.h>
4871 + #include <asm/setup.h>
4872 + #include <asm/processor-flags.h>
4873 ++#include <asm/msr-index.h>
4874 +
4875 + /* Physical address */
4876 + #define pa(X) ((X) - __PAGE_OFFSET)
4877 +@@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
4878 + LOW_PAGES = LOW_PAGES + 0x1000000
4879 + #endif
4880 +
4881 +-#if PTRS_PER_PMD > 1
4882 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
4883 +-#else
4884 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
4885 +-#endif
4886 ++PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE)
4887 + BOOTBITMAP_SIZE = LOW_PAGES / 8
4888 + ALLOCATOR_SLOP = 4
4889 +
4890 + INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
4891 +
4892 + /*
4893 ++ * Real beginning of normal "text" segment
4894 ++ */
4895 ++ENTRY(stext)
4896 ++ENTRY(_stext)
4897 ++
4898 ++.section .text.startup,"ax",@progbits
4899 ++ ljmp $(__BOOT_CS),$phys_startup_32
4900 ++
4901 ++/*
4902 + * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
4903 + * %esi points to the real-mode code as a 32-bit pointer.
4904 + * CS and DS must be 4 GB flat segments, but we don't depend on
4905 +@@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE +
4906 + * can.
4907 + */
4908 + .section .text.head,"ax",@progbits
4909 ++
4910 ++#ifdef CONFIG_PAX_KERNEXEC
4911 ++/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
4912 ++.fill 4096,1,0xcc
4913 ++#endif
4914 ++
4915 + ENTRY(startup_32)
4916 + /* test KEEP_SEGMENTS flag to see if the bootloader is asking
4917 + us to not reload segments */
4918 +@@ -99,6 +111,56 @@ ENTRY(startup_32)
4919 + movl %eax,%gs
4920 + 2:
4921 +
4922 ++ movl $pa(cpu_gdt_table),%edi
4923 ++ movl $__per_cpu_start,%eax
4924 ++ movw %ax,__KERNEL_PERCPU + 2(%edi)
4925 ++ rorl $16,%eax
4926 ++ movb %al,__KERNEL_PERCPU + 4(%edi)
4927 ++ movb %ah,__KERNEL_PERCPU + 7(%edi)
4928 ++ movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax
4929 ++ subl $__per_cpu_start,%eax
4930 ++ movw %ax,__KERNEL_PERCPU + 0(%edi)
4931 ++
4932 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4933 ++ /* check for VMware */
4934 ++ movl $0x564d5868,%eax
4935 ++ xorl %ebx,%ebx
4936 ++ movl $0xa,%ecx
4937 ++ movl $0x5658,%edx
4938 ++ in (%dx),%eax
4939 ++ cmpl $0x564d5868,%ebx
4940 ++ jz 2f
4941 ++
4942 ++ movl $NR_CPUS,%ecx
4943 ++ movl $pa(cpu_gdt_table),%edi
4944 ++1:
4945 ++ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
4946 ++ addl $PAGE_SIZE_asm,%edi
4947 ++ loop 1b
4948 ++2:
4949 ++#endif
4950 ++
4951 ++#ifdef CONFIG_PAX_KERNEXEC
4952 ++ movl $pa(boot_gdt),%edi
4953 ++ movl $KERNEL_TEXT_OFFSET,%eax
4954 ++ movw %ax,__BOOT_CS + 2(%edi)
4955 ++ rorl $16,%eax
4956 ++ movb %al,__BOOT_CS + 4(%edi)
4957 ++ movb %ah,__BOOT_CS + 7(%edi)
4958 ++ rorl $16,%eax
4959 ++
4960 ++ movl $NR_CPUS,%ecx
4961 ++ movl $pa(cpu_gdt_table),%edi
4962 ++1:
4963 ++ movw %ax,__KERNEL_CS + 2(%edi)
4964 ++ rorl $16,%eax
4965 ++ movb %al,__KERNEL_CS + 4(%edi)
4966 ++ movb %ah,__KERNEL_CS + 7(%edi)
4967 ++ rorl $16,%eax
4968 ++ addl $PAGE_SIZE_asm,%edi
4969 ++ loop 1b
4970 ++#endif
4971 ++
4972 + /*
4973 + * Clear BSS first so that there are no surprises...
4974 + */
4975 +@@ -142,9 +204,7 @@ ENTRY(startup_32)
4976 + cmpl $num_subarch_entries, %eax
4977 + jae bad_subarch
4978 +
4979 +- movl pa(subarch_entries)(,%eax,4), %eax
4980 +- subl $__PAGE_OFFSET, %eax
4981 +- jmp *%eax
4982 ++ jmp *pa(subarch_entries)(,%eax,4)
4983 +
4984 + bad_subarch:
4985 + WEAK(lguest_entry)
4986 +@@ -156,9 +216,9 @@ WEAK(xen_entry)
4987 + __INITDATA
4988 +
4989 + subarch_entries:
4990 +- .long default_entry /* normal x86/PC */
4991 +- .long lguest_entry /* lguest hypervisor */
4992 +- .long xen_entry /* Xen hypervisor */
4993 ++ .long pa(default_entry) /* normal x86/PC */
4994 ++ .long pa(lguest_entry) /* lguest hypervisor */
4995 ++ .long pa(xen_entry) /* Xen hypervisor */
4996 + num_subarch_entries = (. - subarch_entries) / 4
4997 + .previous
4998 + #endif /* CONFIG_PARAVIRT */
4999 +@@ -172,7 +232,7 @@ num_subarch_entries = (. - subarch_entri
5000 + *
5001 + * Note that the stack is not yet set up!
5002 + */
5003 +-#define PTE_ATTR 0x007 /* PRESENT+RW+USER */
5004 ++#define PTE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
5005 + #define PDE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
5006 + #define PGD_ATTR 0x001 /* PRESENT (no other attributes) */
5007 +
5008 +@@ -224,8 +284,7 @@ default_entry:
5009 + movl %eax, pa(max_pfn_mapped)
5010 +
5011 + /* Do early initialization of the fixmap area */
5012 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
5013 +- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
5014 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
5015 + #else /* Not PAE */
5016 +
5017 + page_pde_offset = (__PAGE_OFFSET >> 20);
5018 +@@ -257,8 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
5019 + movl %eax, pa(max_pfn_mapped)
5020 +
5021 + /* Do early initialization of the fixmap area */
5022 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
5023 +- movl %eax,pa(swapper_pg_dir+0xffc)
5024 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_dir+0xffc)
5025 + #endif
5026 + jmp 3f
5027 + /*
5028 +@@ -322,13 +380,16 @@ ENTRY(startup_32_smp)
5029 + jnc 6f
5030 +
5031 + /* Setup EFER (Extended Feature Enable Register) */
5032 +- movl $0xc0000080, %ecx
5033 ++ movl $MSR_EFER, %ecx
5034 + rdmsr
5035 +
5036 + btsl $11, %eax
5037 + /* Make changes effective */
5038 + wrmsr
5039 +
5040 ++ btsl $63-32,pa(__supported_pte_mask+4)
5041 ++ movl $1,pa(nx_enabled)
5042 ++
5043 + 6:
5044 +
5045 + /*
5046 +@@ -354,9 +415,7 @@ ENTRY(startup_32_smp)
5047 +
5048 + #ifdef CONFIG_SMP
5049 + cmpb $0, ready
5050 +- jz 1f /* Initial CPU cleans BSS */
5051 +- jmp checkCPUtype
5052 +-1:
5053 ++ jnz checkCPUtype /* Initial CPU cleans BSS */
5054 + #endif /* CONFIG_SMP */
5055 +
5056 + /*
5057 +@@ -433,12 +492,12 @@ is386: movl $2,%ecx # set MP
5058 + ljmp $(__KERNEL_CS),$1f
5059 + 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
5060 + movl %eax,%ss # after changing gdt.
5061 +- movl %eax,%fs # gets reset once there's real percpu
5062 +-
5063 +- movl $(__USER_DS),%eax # DS/ES contains default USER segment
5064 + movl %eax,%ds
5065 + movl %eax,%es
5066 +
5067 ++ movl $(__KERNEL_PERCPU), %eax
5068 ++ movl %eax,%fs # set this cpu's percpu
5069 ++
5070 + xorl %eax,%eax # Clear GS and LDT
5071 + movl %eax,%gs
5072 + lldt %ax
5073 +@@ -448,12 +507,6 @@ is386: movl $2,%ecx # set MP
5074 + #ifdef CONFIG_SMP
5075 + movb ready, %cl
5076 + movb $1, ready
5077 +- cmpb $0,%cl # the first CPU calls start_kernel
5078 +- je 1f
5079 +- movl $(__KERNEL_PERCPU), %eax
5080 +- movl %eax,%fs # set this cpu's percpu
5081 +- movl (stack_start), %esp
5082 +-1:
5083 + #endif /* CONFIG_SMP */
5084 + jmp *(initial_code)
5085 +
5086 +@@ -539,15 +592,15 @@ early_page_fault:
5087 + jmp early_fault
5088 +
5089 + early_fault:
5090 +- cld
5091 + #ifdef CONFIG_PRINTK
5092 ++ cmpl $2,%ss:early_recursion_flag
5093 ++ je hlt_loop
5094 ++ incl %ss:early_recursion_flag
5095 ++ cld
5096 + pusha
5097 + movl $(__KERNEL_DS),%eax
5098 + movl %eax,%ds
5099 + movl %eax,%es
5100 +- cmpl $2,early_recursion_flag
5101 +- je hlt_loop
5102 +- incl early_recursion_flag
5103 + movl %cr2,%eax
5104 + pushl %eax
5105 + pushl %edx /* trapno */
5106 +@@ -557,8 +610,8 @@ early_fault:
5107 + #else
5108 + call printk
5109 + #endif
5110 +-#endif
5111 + call dump_stack
5112 ++#endif
5113 + hlt_loop:
5114 + hlt
5115 + jmp hlt_loop
5116 +@@ -566,8 +619,11 @@ hlt_loop:
5117 + /* This is the default interrupt "handler" :-) */
5118 + ALIGN
5119 + ignore_int:
5120 +- cld
5121 + #ifdef CONFIG_PRINTK
5122 ++ cmpl $2,%ss:early_recursion_flag
5123 ++ je hlt_loop
5124 ++ incl %ss:early_recursion_flag
5125 ++ cld
5126 + pushl %eax
5127 + pushl %ecx
5128 + pushl %edx
5129 +@@ -576,9 +632,6 @@ ignore_int:
5130 + movl $(__KERNEL_DS),%eax
5131 + movl %eax,%ds
5132 + movl %eax,%es
5133 +- cmpl $2,early_recursion_flag
5134 +- je hlt_loop
5135 +- incl early_recursion_flag
5136 + pushl 16(%esp)
5137 + pushl 24(%esp)
5138 + pushl 32(%esp)
5139 +@@ -603,36 +656,41 @@ ignore_int:
5140 + ENTRY(initial_code)
5141 + .long i386_start_kernel
5142 +
5143 +-.section .text
5144 +-/*
5145 +- * Real beginning of normal "text" segment
5146 +- */
5147 +-ENTRY(stext)
5148 +-ENTRY(_stext)
5149 +-
5150 + /*
5151 + * BSS section
5152 + */
5153 +-.section ".bss.page_aligned","wa"
5154 +- .align PAGE_SIZE_asm
5155 + #ifdef CONFIG_X86_PAE
5156 ++.section .swapper_pg_pmd,"a",@progbits
5157 + swapper_pg_pmd:
5158 + .fill 1024*KPMDS,4,0
5159 + #else
5160 ++.section .swapper_pg_dir,"a",@progbits
5161 + ENTRY(swapper_pg_dir)
5162 + .fill 1024,4,0
5163 + #endif
5164 + swapper_pg_fixmap:
5165 + .fill 1024,4,0
5166 ++
5167 ++.section .empty_zero_page,"a",@progbits
5168 + ENTRY(empty_zero_page)
5169 + .fill 4096,1,0
5170 ++
5171 ++/*
5172 ++ * The IDT has to be page-aligned to simplify the Pentium
5173 ++ * F0 0F bug workaround.. We have a special link segment
5174 ++ * for this.
5175 ++ */
5176 ++.section .idt,"a",@progbits
5177 ++ENTRY(idt_table)
5178 ++ .fill 256,8,0
5179 ++
5180 + /*
5181 + * This starts the data section.
5182 + */
5183 ++.data
5184 ++
5185 + #ifdef CONFIG_X86_PAE
5186 +-.section ".data.page_aligned","wa"
5187 +- /* Page-aligned for the benefit of paravirt? */
5188 +- .align PAGE_SIZE_asm
5189 ++.section .swapper_pg_dir,"a",@progbits
5190 + ENTRY(swapper_pg_dir)
5191 + .long pa(swapper_pg_pmd+PGD_ATTR),0 /* low identity map */
5192 + # if KPMDS == 3
5193 +@@ -655,11 +713,12 @@ ENTRY(swapper_pg_dir)
5194 +
5195 + .data
5196 + ENTRY(stack_start)
5197 +- .long init_thread_union+THREAD_SIZE
5198 ++ .long init_thread_union+THREAD_SIZE-8
5199 + .long __BOOT_DS
5200 +
5201 + ready: .byte 0
5202 +
5203 ++.section .rodata,"a",@progbits
5204 + early_recursion_flag:
5205 + .long 0
5206 +
5207 +@@ -695,7 +754,7 @@ fault_msg:
5208 + .word 0 # 32 bit align gdt_desc.address
5209 + boot_gdt_descr:
5210 + .word __BOOT_DS+7
5211 +- .long boot_gdt - __PAGE_OFFSET
5212 ++ .long pa(boot_gdt)
5213 +
5214 + .word 0 # 32-bit align idt_desc.address
5215 + idt_descr:
5216 +@@ -706,7 +765,7 @@ idt_descr:
5217 + .word 0 # 32 bit align gdt_desc.address
5218 + ENTRY(early_gdt_descr)
5219 + .word GDT_ENTRIES*8-1
5220 +- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
5221 ++ .long cpu_gdt_table /* Overwritten for secondary CPUs */
5222 +
5223 + /*
5224 + * The boot_gdt must mirror the equivalent in setup.S and is
5225 +@@ -715,5 +774,59 @@ ENTRY(early_gdt_descr)
5226 + .align L1_CACHE_BYTES
5227 + ENTRY(boot_gdt)
5228 + .fill GDT_ENTRY_BOOT_CS,8,0
5229 +- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
5230 +- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
5231 ++ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
5232 ++ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
5233 ++
5234 ++ .align PAGE_SIZE_asm
5235 ++ENTRY(cpu_gdt_table)
5236 ++ .rept NR_CPUS
5237 ++ .quad 0x0000000000000000 /* NULL descriptor */
5238 ++ .quad 0x0000000000000000 /* 0x0b reserved */
5239 ++ .quad 0x0000000000000000 /* 0x13 reserved */
5240 ++ .quad 0x0000000000000000 /* 0x1b reserved */
5241 ++ .quad 0x0000000000000000 /* 0x20 unused */
5242 ++ .quad 0x0000000000000000 /* 0x28 unused */
5243 ++ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
5244 ++ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
5245 ++ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
5246 ++ .quad 0x0000000000000000 /* 0x4b reserved */
5247 ++ .quad 0x0000000000000000 /* 0x53 reserved */
5248 ++ .quad 0x0000000000000000 /* 0x5b reserved */
5249 ++
5250 ++ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
5251 ++ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
5252 ++ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
5253 ++ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
5254 ++
5255 ++ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
5256 ++ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
5257 ++
5258 ++ /*
5259 ++ * Segments used for calling PnP BIOS have byte granularity.
5260 ++ * The code segments and data segments have fixed 64k limits,
5261 ++ * the transfer segment sizes are set at run time.
5262 ++ */
5263 ++ .quad 0x00409b000000ffff /* 0x90 32-bit code */
5264 ++ .quad 0x00009b000000ffff /* 0x98 16-bit code */
5265 ++ .quad 0x000093000000ffff /* 0xa0 16-bit data */
5266 ++ .quad 0x0000930000000000 /* 0xa8 16-bit data */
5267 ++ .quad 0x0000930000000000 /* 0xb0 16-bit data */
5268 ++
5269 ++ /*
5270 ++ * The APM segments have byte granularity and their bases
5271 ++ * are set at run time. All have 64k limits.
5272 ++ */
5273 ++ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
5274 ++ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
5275 ++ .quad 0x004093000000ffff /* 0xc8 APM DS data */
5276 ++
5277 ++ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
5278 ++ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
5279 ++ .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */
5280 ++ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */
5281 ++ .quad 0x0000000000000000 /* 0xf0 - unused */
5282 ++ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
5283 ++
5284 ++ /* Be sure this is zeroed to avoid false validations in Xen */
5285 ++ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
5286 ++ .endr
5287 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head64.c linux-2.6.27.10/arch/x86/kernel/head64.c
5288 +--- linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-07 12:55:34.000000000 -0500
5289 ++++ linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-18 03:38:44.000000000 -0500
5290 +@@ -93,6 +93,8 @@ void __init x86_64_start_kernel(char * r
5291 + /* clear bss before set_intr_gate with early_idt_handler */
5292 + clear_bss();
5293 +
5294 ++ x86_64_init_pda();
5295 ++
5296 + /* Make NULL pointers segfault */
5297 + zap_identity_mappings();
5298 +
5299 +@@ -110,8 +112,6 @@ void __init x86_64_start_kernel(char * r
5300 +
5301 + early_printk("Kernel alive\n");
5302 +
5303 +- x86_64_init_pda();
5304 +-
5305 + early_printk("Kernel really alive\n");
5306 +
5307 + x86_64_start_reservations(real_mode_data);
5308 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_64.S linux-2.6.27.10/arch/x86/kernel/head_64.S
5309 +--- linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-07 12:55:34.000000000 -0500
5310 ++++ linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-18 03:38:44.000000000 -0500
5311 +@@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
5312 + L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
5313 + L4_START_KERNEL = pgd_index(__START_KERNEL_map)
5314 + L3_START_KERNEL = pud_index(__START_KERNEL_map)
5315 ++L4_VMALLOC_START = pgd_index(VMALLOC_START)
5316 ++L3_VMALLOC_START = pud_index(VMALLOC_START)
5317 ++L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
5318 ++L3_VMEMMAP_START = pud_index(VMEMMAP_START)
5319 +
5320 + .text
5321 + .section .text.head
5322 +@@ -85,14 +89,17 @@ startup_64:
5323 + */
5324 + addq %rbp, init_level4_pgt + 0(%rip)
5325 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
5326 ++ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
5327 ++ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
5328 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
5329 +
5330 + addq %rbp, level3_ident_pgt + 0(%rip)
5331 +
5332 +- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
5333 +- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
5334 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
5335 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
5336 +
5337 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
5338 ++ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
5339 +
5340 + /* Add an Identity mapping if I am above 1G */
5341 + leaq _text(%rip), %rdi
5342 +@@ -187,6 +194,10 @@ ENTRY(secondary_startup_64)
5343 + btl $20,%edi /* No Execute supported? */
5344 + jnc 1f
5345 + btsl $_EFER_NX, %eax
5346 ++ leaq init_level4_pgt(%rip), %rdi
5347 ++ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
5348 ++ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
5349 ++ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
5350 + 1: wrmsr /* Make changes effective */
5351 +
5352 + /* Setup cr0 */
5353 +@@ -257,16 +268,16 @@ ENTRY(secondary_startup_64)
5354 + .align 8
5355 + ENTRY(initial_code)
5356 + .quad x86_64_start_kernel
5357 +- __FINITDATA
5358 +
5359 + ENTRY(stack_start)
5360 + .quad init_thread_union+THREAD_SIZE-8
5361 + .word 0
5362 ++ __FINITDATA
5363 +
5364 + bad_address:
5365 + jmp bad_address
5366 +
5367 +- .section ".init.text","ax"
5368 ++ __INIT
5369 + #ifdef CONFIG_EARLY_PRINTK
5370 + .globl early_idt_handlers
5371 + early_idt_handlers:
5372 +@@ -311,18 +322,23 @@ ENTRY(early_idt_handler)
5373 + #endif /* EARLY_PRINTK */
5374 + 1: hlt
5375 + jmp 1b
5376 ++ .previous
5377 +
5378 + #ifdef CONFIG_EARLY_PRINTK
5379 ++ __INITDATA
5380 + early_recursion_flag:
5381 + .long 0
5382 ++ .previous
5383 +
5384 ++ .section .rodata,"a",@progbits
5385 + early_idt_msg:
5386 + .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
5387 + early_idt_ripmsg:
5388 + .asciz "RIP %s\n"
5389 +-#endif /* CONFIG_EARLY_PRINTK */
5390 + .previous
5391 ++#endif /* CONFIG_EARLY_PRINTK */
5392 +
5393 ++ .section .rodata,"a",@progbits
5394 + .balign PAGE_SIZE
5395 +
5396 + #define NEXT_PAGE(name) \
5397 +@@ -347,6 +363,10 @@ NEXT_PAGE(init_level4_pgt)
5398 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5399 + .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
5400 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5401 ++ .org init_level4_pgt + L4_VMALLOC_START*8, 0
5402 ++ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
5403 ++ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
5404 ++ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
5405 + .org init_level4_pgt + L4_START_KERNEL*8, 0
5406 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
5407 + .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
5408 +@@ -355,6 +375,12 @@ NEXT_PAGE(level3_ident_pgt)
5409 + .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5410 + .fill 511,8,0
5411 +
5412 ++NEXT_PAGE(level3_vmalloc_pgt)
5413 ++ .fill 512,8,0
5414 ++
5415 ++NEXT_PAGE(level3_vmemmap_pgt)
5416 ++ .fill 512,8,0
5417 ++
5418 + NEXT_PAGE(level3_kernel_pgt)
5419 + .fill L3_START_KERNEL,8,0
5420 + /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
5421 +@@ -364,12 +390,16 @@ NEXT_PAGE(level3_kernel_pgt)
5422 + NEXT_PAGE(level2_fixmap_pgt)
5423 + .fill 506,8,0
5424 + .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
5425 +- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
5426 +- .fill 5,8,0
5427 ++ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
5428 ++ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
5429 ++ .fill 4,8,0
5430 +
5431 + NEXT_PAGE(level1_fixmap_pgt)
5432 + .fill 512,8,0
5433 +
5434 ++NEXT_PAGE(level1_vsyscall_pgt)
5435 ++ .fill 512,8,0
5436 ++
5437 + NEXT_PAGE(level2_ident_pgt)
5438 + /* Since I easily can, map the first 1G.
5439 + * Don't set NX because code runs from these pages.
5440 +@@ -396,19 +426,39 @@ NEXT_PAGE(level2_spare_pgt)
5441 + #undef PMDS
5442 + #undef NEXT_PAGE
5443 +
5444 +- .data
5445 ++ .align PAGE_SIZE
5446 ++ENTRY(cpu_gdt_table)
5447 ++ .rept NR_CPUS
5448 ++ .quad 0x0000000000000000 /* NULL descriptor */
5449 ++ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
5450 ++ .quad 0x00af9b000000ffff /* __KERNEL_CS */
5451 ++ .quad 0x00cf93000000ffff /* __KERNEL_DS */
5452 ++ .quad 0x00cffb000000ffff /* __USER32_CS */
5453 ++ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
5454 ++ .quad 0x00affb000000ffff /* __USER_CS */
5455 ++ .quad 0x0 /* unused */
5456 ++ .quad 0,0 /* TSS */
5457 ++ .quad 0,0 /* LDT */
5458 ++ .quad 0,0,0 /* three TLS descriptors */
5459 ++ .quad 0x0000f40000000000 /* node/CPU stored in limit */
5460 ++ /* asm/segment.h:GDT_ENTRIES must match this */
5461 ++
5462 ++ /* zero the remaining page */
5463 ++ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
5464 ++ .endr
5465 ++
5466 + .align 16
5467 + .globl early_gdt_descr
5468 + early_gdt_descr:
5469 + .word GDT_ENTRIES*8-1
5470 +- .quad per_cpu__gdt_page
5471 ++ .quad cpu_gdt_table
5472 +
5473 + ENTRY(phys_base)
5474 + /* This must match the first entry in level2_kernel_pgt */
5475 + .quad 0x0000000000000000
5476 +
5477 + #include "../../x86/xen/xen-head.S"
5478 +-
5479 ++
5480 + .section .bss, "aw", @nobits
5481 + .align L1_CACHE_BYTES
5482 + ENTRY(idt_table)
5483 +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
5484 +--- linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-07 12:55:34.000000000 -0500
5485 ++++ linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-18 03:38:44.000000000 -0500
5486 +@@ -10,8 +10,12 @@
5487 + EXPORT_SYMBOL(mcount);
5488 + #endif
5489 +
5490 ++EXPORT_SYMBOL_GPL(cpu_gdt_table);
5491 ++
5492 + /* Networking helper routines. */
5493 + EXPORT_SYMBOL(csum_partial_copy_generic);
5494 ++EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
5495 ++EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
5496 +
5497 + EXPORT_SYMBOL(__get_user_1);
5498 + EXPORT_SYMBOL(__get_user_2);
5499 +@@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr);
5500 +
5501 + EXPORT_SYMBOL(csum_partial);
5502 + EXPORT_SYMBOL(empty_zero_page);
5503 ++
5504 ++#ifdef CONFIG_PAX_KERNEXEC
5505 ++EXPORT_SYMBOL(KERNEL_TEXT_OFFSET);
5506 ++#endif
5507 +diff -urNp linux-2.6.27.10/arch/x86/kernel/init_task.c linux-2.6.27.10/arch/x86/kernel/init_task.c
5508 +--- linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-07 12:55:34.000000000 -0500
5509 ++++ linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-18 03:38:44.000000000 -0500
5510 +@@ -42,5 +42,5 @@ EXPORT_SYMBOL(init_task);
5511 + * section. Since TSS's are completely CPU-local, we want them
5512 + * on exact cacheline boundaries, to eliminate cacheline ping-pong.
5513 + */
5514 +-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
5515 +-
5516 ++struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
5517 ++EXPORT_SYMBOL(init_tss);
5518 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ioport.c linux-2.6.27.10/arch/x86/kernel/ioport.c
5519 +--- linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-07 12:55:34.000000000 -0500
5520 ++++ linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-18 03:38:44.000000000 -0500
5521 +@@ -14,6 +14,7 @@
5522 + #include <linux/slab.h>
5523 + #include <linux/thread_info.h>
5524 + #include <linux/syscalls.h>
5525 ++#include <linux/grsecurity.h>
5526 +
5527 + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
5528 + static void set_bitmap(unsigned long *bitmap, unsigned int base,
5529 +@@ -40,6 +41,12 @@ asmlinkage long sys_ioperm(unsigned long
5530 +
5531 + if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
5532 + return -EINVAL;
5533 ++#ifdef CONFIG_GRKERNSEC_IO
5534 ++ if (turn_on) {
5535 ++ gr_handle_ioperm();
5536 ++ return -EPERM;
5537 ++ }
5538 ++#endif
5539 + if (turn_on && !capable(CAP_SYS_RAWIO))
5540 + return -EPERM;
5541 +
5542 +@@ -66,7 +73,7 @@ asmlinkage long sys_ioperm(unsigned long
5543 + * because the ->io_bitmap_max value must match the bitmap
5544 + * contents:
5545 + */
5546 +- tss = &per_cpu(init_tss, get_cpu());
5547 ++ tss = init_tss + get_cpu();
5548 +
5549 + set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
5550 +
5551 +@@ -121,8 +128,13 @@ static int do_iopl(unsigned int level, s
5552 + return -EINVAL;
5553 + /* Trying to gain more privileges? */
5554 + if (level > old) {
5555 ++#ifdef CONFIG_GRKERNSEC_IO
5556 ++ gr_handle_iopl();
5557 ++ return -EPERM;
5558 ++#else
5559 + if (!capable(CAP_SYS_RAWIO))
5560 + return -EPERM;
5561 ++#endif
5562 + }
5563 + regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
5564 +
5565 +diff -urNp linux-2.6.27.10/arch/x86/kernel/irq_32.c linux-2.6.27.10/arch/x86/kernel/irq_32.c
5566 +--- linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-07 12:55:34.000000000 -0500
5567 ++++ linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-18 03:38:44.000000000 -0500
5568 +@@ -116,7 +116,7 @@ execute_on_irq_stack(int overflow, struc
5569 + return 0;
5570 +
5571 + /* build the stack frame on the IRQ stack */
5572 +- isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
5573 ++ isp = (u32 *) ((char*)irqctx + sizeof(*irqctx) - 8);
5574 + irqctx->tinfo.task = curctx->tinfo.task;
5575 + irqctx->tinfo.previous_esp = current_stack_pointer;
5576 +
5577 +@@ -197,7 +197,7 @@ asmlinkage void do_softirq(void)
5578 + irqctx->tinfo.previous_esp = current_stack_pointer;
5579 +
5580 + /* build the stack frame on the softirq stack */
5581 +- isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
5582 ++ isp = (u32*) ((char*)irqctx + sizeof(*irqctx) - 8);
5583 +
5584 + call_on_stack(__do_softirq, isp);
5585 + /*
5586 +diff -urNp linux-2.6.27.10/arch/x86/kernel/kprobes.c linux-2.6.27.10/arch/x86/kernel/kprobes.c
5587 +--- linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
5588 ++++ linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-18 04:48:35.000000000 -0500
5589 +@@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f
5590 + char op;
5591 + s32 raddr;
5592 + } __attribute__((packed)) * jop;
5593 +- jop = (struct __arch_jmp_op *)from;
5594 ++
5595 ++#ifdef CONFIG_PAX_KERNEXEC
5596 ++ unsigned long cr0;
5597 ++#endif
5598 ++
5599 ++ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
5600 ++
5601 ++#ifdef CONFIG_PAX_KERNEXEC
5602 ++ pax_open_kernel(cr0);
5603 ++#endif
5604 ++
5605 + jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
5606 + jop->op = RELATIVEJUMP_INSTRUCTION;
5607 ++
5608 ++#ifdef CONFIG_PAX_KERNEXEC
5609 ++ pax_close_kernel(cr0);
5610 ++#endif
5611 ++
5612 + }
5613 +
5614 + /*
5615 +@@ -342,16 +357,29 @@ static void __kprobes fix_riprel(struct
5616 +
5617 + static void __kprobes arch_copy_kprobe(struct kprobe *p)
5618 + {
5619 +- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5620 ++
5621 ++#ifdef CONFIG_PAX_KERNEXEC
5622 ++ unsigned long cr0;
5623 ++#endif
5624 ++
5625 ++#ifdef CONFIG_PAX_KERNEXEC
5626 ++ pax_open_kernel(cr0);
5627 ++#endif
5628 ++
5629 ++ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5630 ++
5631 ++#ifdef CONFIG_PAX_KERNEXEC
5632 ++ pax_close_kernel(cr0);
5633 ++#endif
5634 +
5635 + fix_riprel(p);
5636 +
5637 +- if (can_boost(p->addr))
5638 ++ if (can_boost(ktla_ktva(p->addr)))
5639 + p->ainsn.boostable = 0;
5640 + else
5641 + p->ainsn.boostable = -1;
5642 +
5643 +- p->opcode = *p->addr;
5644 ++ p->opcode = *(ktla_ktva(p->addr));
5645 + }
5646 +
5647 + int __kprobes arch_prepare_kprobe(struct kprobe *p)
5648 +@@ -428,7 +456,7 @@ static void __kprobes prepare_singlestep
5649 + if (p->opcode == BREAKPOINT_INSTRUCTION)
5650 + regs->ip = (unsigned long)p->addr;
5651 + else
5652 +- regs->ip = (unsigned long)p->ainsn.insn;
5653 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5654 + }
5655 +
5656 + void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
5657 +@@ -449,7 +477,7 @@ static void __kprobes setup_singlestep(s
5658 + if (p->ainsn.boostable == 1 && !p->post_handler) {
5659 + /* Boost up -- we can execute copied instructions directly */
5660 + reset_current_kprobe();
5661 +- regs->ip = (unsigned long)p->ainsn.insn;
5662 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5663 + preempt_enable_no_resched();
5664 + return;
5665 + }
5666 +@@ -519,7 +547,7 @@ static int __kprobes kprobe_handler(stru
5667 + struct kprobe_ctlblk *kcb;
5668 +
5669 + addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
5670 +- if (*addr != BREAKPOINT_INSTRUCTION) {
5671 ++ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
5672 + /*
5673 + * The breakpoint instruction was removed right
5674 + * after we hit it. Another cpu has removed
5675 +@@ -770,7 +798,7 @@ static void __kprobes resume_execution(s
5676 + struct pt_regs *regs, struct kprobe_ctlblk *kcb)
5677 + {
5678 + unsigned long *tos = stack_addr(regs);
5679 +- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
5680 ++ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
5681 + unsigned long orig_ip = (unsigned long)p->addr;
5682 + kprobe_opcode_t *insn = p->ainsn.insn;
5683 +
5684 +@@ -953,7 +981,7 @@ int __kprobes kprobe_exceptions_notify(s
5685 + struct die_args *args = data;
5686 + int ret = NOTIFY_DONE;
5687 +
5688 +- if (args->regs && user_mode_vm(args->regs))
5689 ++ if (args->regs && user_mode(args->regs))
5690 + return ret;
5691 +
5692 + switch (val) {
5693 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ldt.c linux-2.6.27.10/arch/x86/kernel/ldt.c
5694 +--- linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-07 12:55:34.000000000 -0500
5695 ++++ linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-18 03:38:44.000000000 -0500
5696 +@@ -63,13 +63,13 @@ static int alloc_ldt(mm_context_t *pc, i
5697 + if (reload) {
5698 + #ifdef CONFIG_SMP
5699 + preempt_disable();
5700 +- load_LDT(pc);
5701 ++ load_LDT_nolock(pc);
5702 + if (!cpus_equal(current->mm->cpu_vm_mask,
5703 + cpumask_of_cpu(smp_processor_id())))
5704 + smp_call_function(flush_ldt, current->mm, 1);
5705 + preempt_enable();
5706 + #else
5707 +- load_LDT(pc);
5708 ++ load_LDT_nolock(pc);
5709 + #endif
5710 + }
5711 + if (oldsize) {
5712 +@@ -108,6 +108,24 @@ int init_new_context(struct task_struct
5713 + retval = copy_ldt(&mm->context, &old_mm->context);
5714 + mutex_unlock(&old_mm->context.lock);
5715 + }
5716 ++
5717 ++ if (tsk == current) {
5718 ++ mm->context.vdso = ~0UL;
5719 ++
5720 ++#ifdef CONFIG_X86_32
5721 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
5722 ++ mm->context.user_cs_base = 0UL;
5723 ++ mm->context.user_cs_limit = ~0UL;
5724 ++
5725 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
5726 ++ cpus_clear(mm->context.cpu_user_cs_mask);
5727 ++#endif
5728 ++
5729 ++#endif
5730 ++#endif
5731 ++
5732 ++ }
5733 ++
5734 + return retval;
5735 + }
5736 +
5737 +@@ -221,6 +239,13 @@ static int write_ldt(void __user *ptr, u
5738 + }
5739 + }
5740 +
5741 ++#ifdef CONFIG_PAX_SEGMEXEC
5742 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
5743 ++ error = -EINVAL;
5744 ++ goto out_unlock;
5745 ++ }
5746 ++#endif
5747 ++
5748 + fill_ldt(&ldt, &ldt_info);
5749 + if (oldmode)
5750 + ldt.avl = 0;
5751 +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
5752 +--- linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-07 12:55:34.000000000 -0500
5753 ++++ linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-18 03:38:44.000000000 -0500
5754 +@@ -34,7 +34,7 @@ static u32 kexec_pmd1[1024] PAGE_ALIGNED
5755 + static u32 kexec_pte0[1024] PAGE_ALIGNED;
5756 + static u32 kexec_pte1[1024] PAGE_ALIGNED;
5757 +
5758 +-static void set_idt(void *newidt, __u16 limit)
5759 ++static void set_idt(struct desc_struct *newidt, __u16 limit)
5760 + {
5761 + struct desc_ptr curidt;
5762 +
5763 +@@ -46,7 +46,7 @@ static void set_idt(void *newidt, __u16
5764 + }
5765 +
5766 +
5767 +-static void set_gdt(void *newgdt, __u16 limit)
5768 ++static void set_gdt(struct desc_struct *newgdt, __u16 limit)
5769 + {
5770 + struct desc_ptr curgdt;
5771 +
5772 +@@ -145,7 +145,7 @@ void machine_kexec(struct kimage *image)
5773 + }
5774 +
5775 + control_page = page_address(image->control_code_page);
5776 +- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
5777 ++ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
5778 +
5779 + relocate_kernel_ptr = control_page;
5780 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
5781 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_32.c linux-2.6.27.10/arch/x86/kernel/module_32.c
5782 +--- linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
5783 ++++ linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-18 03:38:44.000000000 -0500
5784 +@@ -23,6 +23,9 @@
5785 + #include <linux/kernel.h>
5786 + #include <linux/bug.h>
5787 +
5788 ++#include <asm/desc.h>
5789 ++#include <asm/pgtable.h>
5790 ++
5791 + #if 0
5792 + #define DEBUGP printk
5793 + #else
5794 +@@ -33,9 +36,31 @@ void *module_alloc(unsigned long size)
5795 + {
5796 + if (size == 0)
5797 + return NULL;
5798 ++
5799 ++#ifdef CONFIG_PAX_KERNEXEC
5800 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
5801 ++#else
5802 + return vmalloc_exec(size);
5803 ++#endif
5804 ++
5805 + }
5806 +
5807 ++#ifdef CONFIG_PAX_KERNEXEC
5808 ++void *module_alloc_exec(unsigned long size)
5809 ++{
5810 ++ struct vm_struct *area;
5811 ++
5812 ++ if (size == 0)
5813 ++ return NULL;
5814 ++
5815 ++ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END);
5816 ++ if (area)
5817 ++ return area->addr;
5818 ++
5819 ++ return NULL;
5820 ++}
5821 ++EXPORT_SYMBOL(module_alloc_exec);
5822 ++#endif
5823 +
5824 + /* Free memory returned from module_alloc */
5825 + void module_free(struct module *mod, void *module_region)
5826 +@@ -45,6 +70,45 @@ void module_free(struct module *mod, voi
5827 + table entries. */
5828 + }
5829 +
5830 ++#ifdef CONFIG_PAX_KERNEXEC
5831 ++void module_free_exec(struct module *mod, void *module_region)
5832 ++{
5833 ++ struct vm_struct **p, *tmp;
5834 ++
5835 ++ if (!module_region)
5836 ++ return;
5837 ++
5838 ++ if ((PAGE_SIZE-1) & (unsigned long)module_region) {
5839 ++ printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region);
5840 ++ WARN_ON(1);
5841 ++ return;
5842 ++ }
5843 ++
5844 ++ write_lock(&vmlist_lock);
5845 ++ for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next)
5846 ++ if (tmp->addr == module_region)
5847 ++ break;
5848 ++
5849 ++ if (tmp) {
5850 ++ unsigned long cr0;
5851 ++
5852 ++ pax_open_kernel(cr0);
5853 ++ memset(tmp->addr, 0xCC, tmp->size);
5854 ++ pax_close_kernel(cr0);
5855 ++
5856 ++ *p = tmp->next;
5857 ++ kfree(tmp);
5858 ++ }
5859 ++ write_unlock(&vmlist_lock);
5860 ++
5861 ++ if (!tmp) {
5862 ++ printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n",
5863 ++ module_region);
5864 ++ WARN_ON(1);
5865 ++ }
5866 ++}
5867 ++#endif
5868 ++
5869 + /* We don't need anything special. */
5870 + int module_frob_arch_sections(Elf_Ehdr *hdr,
5871 + Elf_Shdr *sechdrs,
5872 +@@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5873 + unsigned int i;
5874 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
5875 + Elf32_Sym *sym;
5876 +- uint32_t *location;
5877 ++ uint32_t *plocation, location;
5878 ++
5879 ++#ifdef CONFIG_PAX_KERNEXEC
5880 ++ unsigned long cr0;
5881 ++#endif
5882 +
5883 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5884 + sechdrs[relsec].sh_info);
5885 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
5886 + /* This is where to make the change */
5887 +- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
5888 +- + rel[i].r_offset;
5889 ++ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
5890 ++ location = (uint32_t)plocation;
5891 ++ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
5892 ++ plocation = ktla_ktva((void *)plocation);
5893 + /* This is the symbol it is referring to. Note that all
5894 + undefined symbols have been resolved. */
5895 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
5896 +@@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5897 +
5898 + switch (ELF32_R_TYPE(rel[i].r_info)) {
5899 + case R_386_32:
5900 ++
5901 ++#ifdef CONFIG_PAX_KERNEXEC
5902 ++ pax_open_kernel(cr0);
5903 ++#endif
5904 ++
5905 + /* We add the value into the location given */
5906 +- *location += sym->st_value;
5907 ++ *plocation += sym->st_value;
5908 ++
5909 ++#ifdef CONFIG_PAX_KERNEXEC
5910 ++ pax_close_kernel(cr0);
5911 ++#endif
5912 ++
5913 + break;
5914 + case R_386_PC32:
5915 ++
5916 ++#ifdef CONFIG_PAX_KERNEXEC
5917 ++ pax_open_kernel(cr0);
5918 ++#endif
5919 ++
5920 + /* Add the value, subtract its postition */
5921 +- *location += sym->st_value - (uint32_t)location;
5922 ++ *plocation += sym->st_value - location;
5923 ++
5924 ++#ifdef CONFIG_PAX_KERNEXEC
5925 ++ pax_close_kernel(cr0);
5926 ++#endif
5927 ++
5928 + break;
5929 + default:
5930 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
5931 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_64.c linux-2.6.27.10/arch/x86/kernel/module_64.c
5932 +--- linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-07 12:55:34.000000000 -0500
5933 ++++ linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-18 03:38:44.000000000 -0500
5934 +@@ -40,7 +40,7 @@ void module_free(struct module *mod, voi
5935 + table entries. */
5936 + }
5937 +
5938 +-void *module_alloc(unsigned long size)
5939 ++static void *__module_alloc(unsigned long size, pgprot_t prot)
5940 + {
5941 + struct vm_struct *area;
5942 +
5943 +@@ -54,8 +54,31 @@ void *module_alloc(unsigned long size)
5944 + if (!area)
5945 + return NULL;
5946 +
5947 +- return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
5948 ++ return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot);
5949 ++}
5950 ++
5951 ++#ifdef CONFIG_PAX_KERNEXEC
5952 ++void *module_alloc(unsigned long size)
5953 ++{
5954 ++ return __module_alloc(size, PAGE_KERNEL);
5955 ++}
5956 ++
5957 ++void module_free_exec(struct module *mod, void *module_region)
5958 ++{
5959 ++ module_free(mod, module_region);
5960 ++}
5961 ++
5962 ++void *module_alloc_exec(unsigned long size)
5963 ++{
5964 ++ return __module_alloc(size, PAGE_KERNEL_RX);
5965 + }
5966 ++#else
5967 ++void *module_alloc(unsigned long size)
5968 ++{
5969 ++ return __module_alloc(size, PAGE_KERNEL_EXEC);
5970 ++}
5971 ++#endif
5972 ++
5973 + #endif
5974 +
5975 + /* We don't need anything special. */
5976 +@@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
5977 + Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
5978 + Elf64_Sym *sym;
5979 + void *loc;
5980 +- u64 val;
5981 ++ u64 val;
5982 ++
5983 ++#ifdef CONFIG_PAX_KERNEXEC
5984 ++ unsigned long cr0;
5985 ++#endif
5986 +
5987 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5988 + sechdrs[relsec].sh_info);
5989 +@@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd
5990 + case R_X86_64_NONE:
5991 + break;
5992 + case R_X86_64_64:
5993 ++
5994 ++#ifdef CONFIG_PAX_KERNEXEC
5995 ++ pax_open_kernel(cr0);
5996 ++#endif
5997 ++
5998 + *(u64 *)loc = val;
5999 ++
6000 ++#ifdef CONFIG_PAX_KERNEXEC
6001 ++ pax_close_kernel(cr0);
6002 ++#endif
6003 ++
6004 + break;
6005 + case R_X86_64_32:
6006 ++
6007 ++#ifdef CONFIG_PAX_KERNEXEC
6008 ++ pax_open_kernel(cr0);
6009 ++#endif
6010 ++
6011 + *(u32 *)loc = val;
6012 ++
6013 ++#ifdef CONFIG_PAX_KERNEXEC
6014 ++ pax_close_kernel(cr0);
6015 ++#endif
6016 ++
6017 + if (val != *(u32 *)loc)
6018 + goto overflow;
6019 + break;
6020 + case R_X86_64_32S:
6021 ++
6022 ++#ifdef CONFIG_PAX_KERNEXEC
6023 ++ pax_open_kernel(cr0);
6024 ++#endif
6025 ++
6026 + *(s32 *)loc = val;
6027 ++
6028 ++#ifdef CONFIG_PAX_KERNEXEC
6029 ++ pax_close_kernel(cr0);
6030 ++#endif
6031 ++
6032 + if ((s64)val != *(s32 *)loc)
6033 + goto overflow;
6034 + break;
6035 + case R_X86_64_PC32:
6036 + val -= (u64)loc;
6037 ++
6038 ++#ifdef CONFIG_PAX_KERNEXEC
6039 ++ pax_open_kernel(cr0);
6040 ++#endif
6041 ++
6042 + *(u32 *)loc = val;
6043 ++
6044 ++#ifdef CONFIG_PAX_KERNEXEC
6045 ++ pax_close_kernel(cr0);
6046 ++#endif
6047 ++
6048 + #if 0
6049 + if ((s64)val != *(s32 *)loc)
6050 + goto overflow;
6051 +diff -urNp linux-2.6.27.10/arch/x86/kernel/paravirt.c linux-2.6.27.10/arch/x86/kernel/paravirt.c
6052 +--- linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-07 12:55:34.000000000 -0500
6053 ++++ linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-18 03:38:44.000000000 -0500
6054 +@@ -44,7 +44,7 @@ void _paravirt_nop(void)
6055 + {
6056 + }
6057 +
6058 +-static void __init default_banner(void)
6059 ++static void default_banner(void)
6060 + {
6061 + printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
6062 + pv_info.name);
6063 +@@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn
6064 + if (insn_len > len || start == NULL)
6065 + insn_len = len;
6066 + else
6067 +- memcpy(insnbuf, start, insn_len);
6068 ++ memcpy(insnbuf, ktla_ktva(start), insn_len);
6069 +
6070 + return insn_len;
6071 + }
6072 +@@ -279,21 +279,21 @@ void __init paravirt_use_bytelocks(void)
6073 + #endif
6074 + }
6075 +
6076 +-struct pv_info pv_info = {
6077 ++struct pv_info pv_info __read_only = {
6078 + .name = "bare hardware",
6079 + .paravirt_enabled = 0,
6080 + .kernel_rpl = 0,
6081 + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
6082 + };
6083 +
6084 +-struct pv_init_ops pv_init_ops = {
6085 ++struct pv_init_ops pv_init_ops __read_only = {
6086 + .patch = native_patch,
6087 + .banner = default_banner,
6088 + .arch_setup = paravirt_nop,
6089 + .memory_setup = machine_specific_memory_setup,
6090 + };
6091 +
6092 +-struct pv_time_ops pv_time_ops = {
6093 ++struct pv_time_ops pv_time_ops __read_only = {
6094 + .time_init = hpet_time_init,
6095 + .get_wallclock = native_get_wallclock,
6096 + .set_wallclock = native_set_wallclock,
6097 +@@ -301,7 +301,7 @@ struct pv_time_ops pv_time_ops = {
6098 + .get_tsc_khz = native_calibrate_tsc,
6099 + };
6100 +
6101 +-struct pv_irq_ops pv_irq_ops = {
6102 ++struct pv_irq_ops pv_irq_ops __read_only = {
6103 + .init_IRQ = native_init_IRQ,
6104 + .save_fl = native_save_fl,
6105 + .restore_fl = native_restore_fl,
6106 +@@ -314,7 +314,7 @@ struct pv_irq_ops pv_irq_ops = {
6107 + #endif
6108 + };
6109 +
6110 +-struct pv_cpu_ops pv_cpu_ops = {
6111 ++struct pv_cpu_ops pv_cpu_ops __read_only = {
6112 + .cpuid = native_cpuid,
6113 + .get_debugreg = native_get_debugreg,
6114 + .set_debugreg = native_set_debugreg,
6115 +@@ -371,7 +371,7 @@ struct pv_cpu_ops pv_cpu_ops = {
6116 + },
6117 + };
6118 +
6119 +-struct pv_apic_ops pv_apic_ops = {
6120 ++struct pv_apic_ops pv_apic_ops __read_only = {
6121 + #ifdef CONFIG_X86_LOCAL_APIC
6122 + .apic_write = native_apic_write,
6123 + .apic_read = native_apic_read,
6124 +@@ -381,7 +381,7 @@ struct pv_apic_ops pv_apic_ops = {
6125 + #endif
6126 + };
6127 +
6128 +-struct pv_mmu_ops pv_mmu_ops = {
6129 ++struct pv_mmu_ops pv_mmu_ops __read_only = {
6130 + #ifndef CONFIG_X86_64
6131 + .pagetable_setup_start = native_pagetable_setup_start,
6132 + .pagetable_setup_done = native_pagetable_setup_done,
6133 +@@ -461,7 +461,7 @@ struct pv_mmu_ops pv_mmu_ops = {
6134 + .set_fixmap = native_set_fixmap,
6135 + };
6136 +
6137 +-struct pv_lock_ops pv_lock_ops = {
6138 ++struct pv_lock_ops pv_lock_ops __read_only = {
6139 + #ifdef CONFIG_SMP
6140 + .spin_is_locked = __ticket_spin_is_locked,
6141 + .spin_is_contended = __ticket_spin_is_contended,
6142 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_32.c linux-2.6.27.10/arch/x86/kernel/process_32.c
6143 +--- linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-07 12:55:34.000000000 -0500
6144 ++++ linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-18 03:38:44.000000000 -0500
6145 +@@ -62,8 +62,10 @@ asmlinkage void ret_from_fork(void) __as
6146 + DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
6147 + EXPORT_PER_CPU_SYMBOL(current_task);
6148 +
6149 ++#ifdef CONFIG_SMP
6150 + DEFINE_PER_CPU(int, cpu_number);
6151 + EXPORT_PER_CPU_SYMBOL(cpu_number);
6152 ++#endif
6153 +
6154 + /*
6155 + * Return saved PC of a blocked thread.
6156 +@@ -71,6 +73,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
6157 + unsigned long thread_saved_pc(struct task_struct *tsk)
6158 + {
6159 + return ((unsigned long *)tsk->thread.sp)[3];
6160 ++//XXX return tsk->thread.eip;
6161 + }
6162 +
6163 + #ifdef CONFIG_HOTPLUG_CPU
6164 +@@ -162,7 +165,7 @@ void __show_registers(struct pt_regs *re
6165 + unsigned long sp;
6166 + unsigned short ss, gs;
6167 +
6168 +- if (user_mode_vm(regs)) {
6169 ++ if (user_mode(regs)) {
6170 + sp = regs->sp;
6171 + ss = regs->ss & 0xffff;
6172 + savesegment(gs, gs);
6173 +@@ -239,8 +242,8 @@ int kernel_thread(int (*fn)(void *), voi
6174 + regs.bx = (unsigned long) fn;
6175 + regs.dx = (unsigned long) arg;
6176 +
6177 +- regs.ds = __USER_DS;
6178 +- regs.es = __USER_DS;
6179 ++ regs.ds = __KERNEL_DS;
6180 ++ regs.es = __KERNEL_DS;
6181 + regs.fs = __KERNEL_PERCPU;
6182 + regs.orig_ax = -1;
6183 + regs.ip = (unsigned long) kernel_thread_helper;
6184 +@@ -262,7 +265,7 @@ void exit_thread(void)
6185 + struct task_struct *tsk = current;
6186 + struct thread_struct *t = &tsk->thread;
6187 + int cpu = get_cpu();
6188 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6189 ++ struct tss_struct *tss = init_tss + cpu;
6190 +
6191 + kfree(t->io_bitmap_ptr);
6192 + t->io_bitmap_ptr = NULL;
6193 +@@ -283,6 +286,7 @@ void flush_thread(void)
6194 + {
6195 + struct task_struct *tsk = current;
6196 +
6197 ++ loadsegment(gs, 0);
6198 + tsk->thread.debugreg0 = 0;
6199 + tsk->thread.debugreg1 = 0;
6200 + tsk->thread.debugreg2 = 0;
6201 +@@ -322,7 +326,7 @@ int copy_thread(int nr, unsigned long cl
6202 + struct task_struct *tsk;
6203 + int err;
6204 +
6205 +- childregs = task_pt_regs(p);
6206 ++ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
6207 + *childregs = *regs;
6208 + childregs->ax = 0;
6209 + childregs->sp = sp;
6210 +@@ -351,6 +355,7 @@ int copy_thread(int nr, unsigned long cl
6211 + * Set a new TLS for the child thread?
6212 + */
6213 + if (clone_flags & CLONE_SETTLS)
6214 ++//XXX needs set_fs()?
6215 + err = do_set_thread_area(p, -1,
6216 + (struct user_desc __user *)childregs->si, 0);
6217 +
6218 +@@ -550,7 +555,7 @@ struct task_struct * __switch_to(struct
6219 + struct thread_struct *prev = &prev_p->thread,
6220 + *next = &next_p->thread;
6221 + int cpu = smp_processor_id();
6222 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6223 ++ struct tss_struct *tss = init_tss + cpu;
6224 +
6225 + /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
6226 +
6227 +@@ -578,6 +583,11 @@ struct task_struct * __switch_to(struct
6228 + */
6229 + savesegment(gs, prev->gs);
6230 +
6231 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
6232 ++ if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit))
6233 ++ __set_fs(task_thread_info(next_p)->addr_limit, cpu);
6234 ++#endif
6235 ++
6236 + /*
6237 + * Load the per-thread Thread-Local Storage descriptor.
6238 + */
6239 +@@ -716,15 +726,27 @@ unsigned long get_wchan(struct task_stru
6240 + return 0;
6241 + }
6242 +
6243 +-unsigned long arch_align_stack(unsigned long sp)
6244 ++#ifdef CONFIG_PAX_RANDKSTACK
6245 ++asmlinkage void pax_randomize_kstack(void)
6246 + {
6247 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6248 +- sp -= get_random_int() % 8192;
6249 +- return sp & ~0xf;
6250 +-}
6251 ++ struct thread_struct *thread = &current->thread;
6252 ++ unsigned long time;
6253 +
6254 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6255 +-{
6256 +- unsigned long range_end = mm->brk + 0x02000000;
6257 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6258 ++ if (!randomize_va_space)
6259 ++ return;
6260 ++
6261 ++ rdtscl(time);
6262 ++
6263 ++ /* P4 seems to return a 0 LSB, ignore it */
6264 ++#ifdef CONFIG_MPENTIUM4
6265 ++ time &= 0x1EUL;
6266 ++ time <<= 2;
6267 ++#else
6268 ++ time &= 0xFUL;
6269 ++ time <<= 3;
6270 ++#endif
6271 ++
6272 ++ thread->sp0 ^= time;
6273 ++ load_sp0(init_tss + smp_processor_id(), thread);
6274 + }
6275 ++#endif
6276 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_64.c linux-2.6.27.10/arch/x86/kernel/process_64.c
6277 +--- linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-07 12:55:34.000000000 -0500
6278 ++++ linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-18 03:38:44.000000000 -0500
6279 +@@ -119,6 +119,8 @@ static inline void play_dead(void)
6280 + void cpu_idle(void)
6281 + {
6282 + current_thread_info()->status |= TS_POLLING;
6283 ++ current->stack_canary = pax_get_random_long();
6284 ++ write_pda(stack_canary, current->stack_canary);
6285 + /* endless idle loop with no priority at all */
6286 + while (1) {
6287 + tick_nohz_stop_sched_tick(1);
6288 +@@ -228,7 +230,7 @@ void exit_thread(void)
6289 + struct thread_struct *t = &me->thread;
6290 +
6291 + if (me->thread.io_bitmap_ptr) {
6292 +- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
6293 ++ struct tss_struct *tss = init_tss + get_cpu();
6294 +
6295 + kfree(t->io_bitmap_ptr);
6296 + t->io_bitmap_ptr = NULL;
6297 +@@ -541,7 +543,7 @@ __switch_to(struct task_struct *prev_p,
6298 + struct thread_struct *prev = &prev_p->thread;
6299 + struct thread_struct *next = &next_p->thread;
6300 + int cpu = smp_processor_id();
6301 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6302 ++ struct tss_struct *tss = init_tss + cpu;
6303 + unsigned fsindex, gsindex;
6304 +
6305 + /* we're going to use this soon, after a few expensive things */
6306 +@@ -630,7 +632,6 @@ __switch_to(struct task_struct *prev_p,
6307 + (unsigned long)task_stack_page(next_p) +
6308 + THREAD_SIZE - PDA_STACKOFFSET);
6309 + #ifdef CONFIG_CC_STACKPROTECTOR
6310 +- write_pda(stack_canary, next_p->stack_canary);
6311 + /*
6312 + * Build time only check to make sure the stack_canary is at
6313 + * offset 40 in the pda; this is a gcc ABI requirement
6314 +@@ -729,12 +730,11 @@ unsigned long get_wchan(struct task_stru
6315 + if (!p || p == current || p->state==TASK_RUNNING)
6316 + return 0;
6317 + stack = (unsigned long)task_stack_page(p);
6318 +- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
6319 ++ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
6320 + return 0;
6321 + fp = *(u64 *)(p->thread.sp);
6322 + do {
6323 +- if (fp < (unsigned long)stack ||
6324 +- fp >= (unsigned long)stack+THREAD_SIZE)
6325 ++ if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
6326 + return 0;
6327 + ip = *(u64 *)(fp+8);
6328 + if (!in_sched_functions(ip))
6329 +@@ -844,16 +844,3 @@ long sys_arch_prctl(int code, unsigned l
6330 + {
6331 + return do_arch_prctl(current, code, addr);
6332 + }
6333 +-
6334 +-unsigned long arch_align_stack(unsigned long sp)
6335 +-{
6336 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6337 +- sp -= get_random_int() % 8192;
6338 +- return sp & ~0xf;
6339 +-}
6340 +-
6341 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6342 +-{
6343 +- unsigned long range_end = mm->brk + 0x02000000;
6344 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6345 +-}
6346 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ptrace.c linux-2.6.27.10/arch/x86/kernel/ptrace.c
6347 +--- linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
6348 ++++ linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-18 03:38:44.000000000 -0500
6349 +@@ -1369,7 +1369,7 @@ void send_sigtrap(struct task_struct *ts
6350 + info.si_code = TRAP_BRKPT;
6351 +
6352 + /* User-mode ip? */
6353 +- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
6354 ++ info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL;
6355 +
6356 + /* Send us the fake SIGTRAP */
6357 + force_sig_info(SIGTRAP, &info, tsk);
6358 +diff -urNp linux-2.6.27.10/arch/x86/kernel/reboot.c linux-2.6.27.10/arch/x86/kernel/reboot.c
6359 +--- linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-07 12:55:34.000000000 -0500
6360 ++++ linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-18 03:38:44.000000000 -0500
6361 +@@ -28,7 +28,7 @@ void (*pm_power_off)(void);
6362 + EXPORT_SYMBOL(pm_power_off);
6363 +
6364 + static const struct desc_ptr no_idt = {};
6365 +-static int reboot_mode;
6366 ++static unsigned short reboot_mode;
6367 + enum reboot_type reboot_type = BOOT_KBD;
6368 + int reboot_force;
6369 +
6370 +@@ -193,7 +193,7 @@ static struct dmi_system_id __initdata r
6371 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
6372 + },
6373 + },
6374 +- { }
6375 ++ { NULL, NULL, {{0, NULL}}, NULL}
6376 + };
6377 +
6378 + static int __init reboot_init(void)
6379 +@@ -209,12 +209,12 @@ core_initcall(reboot_init);
6380 + controller to pulse the CPU reset line, which is more thorough, but
6381 + doesn't work with at least one type of 486 motherboard. It is easy
6382 + to stop this code working; hence the copious comments. */
6383 +-static const unsigned long long
6384 +-real_mode_gdt_entries [3] =
6385 ++static struct desc_struct
6386 ++real_mode_gdt_entries [3] __read_only =
6387 + {
6388 +- 0x0000000000000000ULL, /* Null descriptor */
6389 +- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
6390 +- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
6391 ++ {{{0x00000000, 0x00000000}}}, /* Null descriptor */
6392 ++ {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */
6393 ++ {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */
6394 + };
6395 +
6396 + static const struct desc_ptr
6397 +@@ -263,7 +263,7 @@ static const unsigned char jump_to_bios
6398 + * specified by the code and length parameters.
6399 + * We assume that length will aways be less that 100!
6400 + */
6401 +-void machine_real_restart(const unsigned char *code, int length)
6402 ++void machine_real_restart(const unsigned char *code, unsigned int length)
6403 + {
6404 + local_irq_disable();
6405 +
6406 +@@ -283,8 +283,8 @@ void machine_real_restart(const unsigned
6407 + /* Remap the kernel at virtual address zero, as well as offset zero
6408 + from the kernel segment. This assumes the kernel segment starts at
6409 + virtual address PAGE_OFFSET. */
6410 +- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6411 +- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
6412 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6413 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
6414 +
6415 + /*
6416 + * Use `swapper_pg_dir' as our page directory.
6417 +@@ -296,16 +296,15 @@ void machine_real_restart(const unsigned
6418 + boot)". This seems like a fairly standard thing that gets set by
6419 + REBOOT.COM programs, and the previous reset routine did this
6420 + too. */
6421 +- *((unsigned short *)0x472) = reboot_mode;
6422 ++ *(unsigned short *)(__va(0x472)) = reboot_mode;
6423 +
6424 + /* For the switch to real mode, copy some code to low memory. It has
6425 + to be in the first 64k because it is running in 16-bit mode, and it
6426 + has to have the same physical and virtual address, because it turns
6427 + off paging. Copy it near the end of the first page, out of the way
6428 + of BIOS variables. */
6429 +- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
6430 +- real_mode_switch, sizeof (real_mode_switch));
6431 +- memcpy((void *)(0x1000 - 100), code, length);
6432 ++ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
6433 ++ memcpy(__va(0x1000 - 100), code, length);
6434 +
6435 + /* Set up the IDT for real mode. */
6436 + load_idt(&real_mode_idt);
6437 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup.c linux-2.6.27.10/arch/x86/kernel/setup.c
6438 +--- linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:11.000000000 -0500
6439 ++++ linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:21.000000000 -0500
6440 +@@ -578,6 +578,7 @@ static struct x86_quirks default_x86_qui
6441 +
6442 + struct x86_quirks *x86_quirks __initdata = &default_x86_quirks;
6443 +
6444 ++#ifdef CONFIG_X86_RESERVE_LOW_64K
6445 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
6446 + {
6447 + printk(KERN_NOTICE
6448 +@@ -589,6 +590,7 @@ static int __init dmi_low_memory_corrupt
6449 +
6450 + return 0;
6451 + }
6452 ++#endif
6453 +
6454 + /* List of systems that have known low memory corruption BIOS problems */
6455 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
6456 +@@ -685,8 +687,8 @@ void __init setup_arch(char **cmdline_p)
6457 +
6458 + if (!boot_params.hdr.root_flags)
6459 + root_mountflags &= ~MS_RDONLY;
6460 +- init_mm.start_code = (unsigned long) _text;
6461 +- init_mm.end_code = (unsigned long) _etext;
6462 ++ init_mm.start_code = ktla_ktva((unsigned long) _text);
6463 ++ init_mm.end_code = ktla_ktva((unsigned long) _etext);
6464 + init_mm.end_data = (unsigned long) _edata;
6465 + #ifdef CONFIG_X86_32
6466 + init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
6467 +@@ -694,9 +696,9 @@ void __init setup_arch(char **cmdline_p)
6468 + init_mm.brk = (unsigned long) &_end;
6469 + #endif
6470 +
6471 +- code_resource.start = virt_to_phys(_text);
6472 +- code_resource.end = virt_to_phys(_etext)-1;
6473 +- data_resource.start = virt_to_phys(_etext);
6474 ++ code_resource.start = virt_to_phys(ktla_ktva(_text));
6475 ++ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
6476 ++ data_resource.start = virt_to_phys(_data);
6477 + data_resource.end = virt_to_phys(_edata)-1;
6478 + bss_resource.start = virt_to_phys(&__bss_start);
6479 + bss_resource.end = virt_to_phys(&__bss_stop)-1;
6480 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup_percpu.c linux-2.6.27.10/arch/x86/kernel/setup_percpu.c
6481 +--- linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-07 12:55:34.000000000 -0500
6482 ++++ linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-18 03:38:44.000000000 -0500
6483 +@@ -166,7 +166,11 @@ void __init setup_per_cpu_areas(void)
6484 + else
6485 + ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
6486 + #endif
6487 ++#ifdef CONFIG_X86_32
6488 ++ __per_cpu_offset[cpu] = ptr - __per_cpu_start;
6489 ++#else
6490 + per_cpu_offset(cpu) = ptr - __per_cpu_start;
6491 ++#endif
6492 + memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
6493 +
6494 + }
6495 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_32.c linux-2.6.27.10/arch/x86/kernel/signal_32.c
6496 +--- linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
6497 ++++ linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-18 03:38:44.000000000 -0500
6498 +@@ -378,9 +378,9 @@ setup_frame(int sig, struct k_sigaction
6499 + }
6500 +
6501 + if (current->mm->context.vdso)
6502 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6503 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6504 + else
6505 +- restorer = &frame->retcode;
6506 ++ restorer = (void __user *)&frame->retcode;
6507 + if (ka->sa.sa_flags & SA_RESTORER)
6508 + restorer = ka->sa.sa_restorer;
6509 +
6510 +@@ -460,7 +460,7 @@ static int setup_rt_frame(int sig, struc
6511 + goto give_sigsegv;
6512 +
6513 + /* Set up to return from userspace. */
6514 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6515 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6516 + if (ka->sa.sa_flags & SA_RESTORER)
6517 + restorer = ka->sa.sa_restorer;
6518 + err |= __put_user(restorer, &frame->pretcode);
6519 +@@ -590,7 +590,7 @@ static void do_signal(struct pt_regs *re
6520 + * X86_32: vm86 regs switched out by assembly code before reaching
6521 + * here, so testing against kernel CS suffices.
6522 + */
6523 +- if (!user_mode(regs))
6524 ++ if (!user_mode_novm(regs))
6525 + return;
6526 +
6527 + if (current_thread_info()->status & TS_RESTORE_SIGMASK)
6528 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_64.c linux-2.6.27.10/arch/x86/kernel/signal_64.c
6529 +--- linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
6530 ++++ linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-18 03:38:44.000000000 -0500
6531 +@@ -312,8 +312,8 @@ static int setup_rt_frame(int sig, struc
6532 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
6533 + err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
6534 + if (sizeof(*set) == 16) {
6535 +- __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6536 +- __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6537 ++ err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6538 ++ err |= __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6539 + } else
6540 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
6541 +
6542 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpboot.c linux-2.6.27.10/arch/x86/kernel/smpboot.c
6543 +--- linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:11.000000000 -0500
6544 ++++ linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:21.000000000 -0500
6545 +@@ -814,6 +814,11 @@ static int __cpuinit do_boot_cpu(int api
6546 + .cpu = cpu,
6547 + .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
6548 + };
6549 ++
6550 ++#ifdef CONFIG_PAX_KERNEXEC
6551 ++ unsigned long cr0;
6552 ++#endif
6553 ++
6554 + INIT_WORK(&c_idle.work, do_fork_idle);
6555 +
6556 + #ifdef CONFIG_X86_64
6557 +@@ -864,7 +869,17 @@ do_rest:
6558 + cpu_pda(cpu)->pcurrent = c_idle.idle;
6559 + clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
6560 + #endif
6561 ++
6562 ++#ifdef CONFIG_PAX_KERNEXEC
6563 ++ pax_open_kernel(cr0);
6564 ++#endif
6565 ++
6566 + early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
6567 ++
6568 ++#ifdef CONFIG_PAX_KERNEXEC
6569 ++ pax_close_kernel(cr0);
6570 ++#endif
6571 ++
6572 + initial_code = (unsigned long)start_secondary;
6573 + stack_start.sp = (void *) c_idle.idle->thread.sp;
6574 +
6575 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpcommon.c linux-2.6.27.10/arch/x86/kernel/smpcommon.c
6576 +--- linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-07 12:55:34.000000000 -0500
6577 ++++ linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-18 03:38:44.000000000 -0500
6578 +@@ -3,9 +3,10 @@
6579 + */
6580 + #include <linux/module.h>
6581 + #include <asm/smp.h>
6582 ++#include <asm/sections.h>
6583 +
6584 + #ifdef CONFIG_X86_32
6585 +-DEFINE_PER_CPU(unsigned long, this_cpu_off);
6586 ++DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start;
6587 + EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6588 +
6589 + /*
6590 +@@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6591 + */
6592 + __cpuinit void init_gdt(int cpu)
6593 + {
6594 +- struct desc_struct gdt;
6595 ++ struct desc_struct d, *gdt = get_cpu_gdt_table(cpu);
6596 ++ unsigned long base, limit;
6597 +
6598 +- pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF,
6599 +- 0x2 | DESCTYPE_S, 0x8);
6600 +- gdt.s = 1;
6601 ++ base = per_cpu_offset(cpu);
6602 ++ limit = PERCPU_ENOUGH_ROOM - 1;
6603 ++ if (limit < 64*1024)
6604 ++ pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4);
6605 ++ else
6606 ++ pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC);
6607 +
6608 +- write_gdt_entry(get_cpu_gdt_table(cpu),
6609 +- GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
6610 ++ write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
6611 +
6612 +- per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
6613 ++ per_cpu(this_cpu_off, cpu) = base;
6614 + per_cpu(cpu_number, cpu) = cpu;
6615 + }
6616 + #endif
6617 +diff -urNp linux-2.6.27.10/arch/x86/kernel/step.c linux-2.6.27.10/arch/x86/kernel/step.c
6618 +--- linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-07 12:55:34.000000000 -0500
6619 ++++ linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-18 03:38:44.000000000 -0500
6620 +@@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc
6621 + * and APM bios ones we just ignore here.
6622 + */
6623 + if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) {
6624 +- u32 *desc;
6625 ++ struct desc_struct *desc;
6626 + unsigned long base;
6627 +
6628 +- seg &= ~7UL;
6629 ++ seg >>= 3;
6630 +
6631 + mutex_lock(&child->mm->context.lock);
6632 +- if (unlikely((seg >> 3) >= child->mm->context.size))
6633 +- addr = -1L; /* bogus selector, access would fault */
6634 ++ if (unlikely(seg >= child->mm->context.size))
6635 ++ addr = -EINVAL;
6636 + else {
6637 +- desc = child->mm->context.ldt + seg;
6638 +- base = ((desc[0] >> 16) |
6639 +- ((desc[1] & 0xff) << 16) |
6640 +- (desc[1] & 0xff000000));
6641 ++ desc = &child->mm->context.ldt[seg];
6642 ++ base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000);
6643 +
6644 + /* 16-bit code segment? */
6645 +- if (!((desc[1] >> 22) & 1))
6646 ++ if (!((desc->b >> 22) & 1))
6647 + addr &= 0xffff;
6648 + addr += base;
6649 + }
6650 +@@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t
6651 + unsigned char opcode[15];
6652 + unsigned long addr = convert_ip_to_linear(child, regs);
6653 +
6654 ++ if (addr == -EINVAL)
6655 ++ return 0;
6656 ++
6657 + copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
6658 + for (i = 0; i < copied; i++) {
6659 + switch (opcode[i]) {
6660 +@@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t
6661 +
6662 + #ifdef CONFIG_X86_64
6663 + case 0x40 ... 0x4f:
6664 +- if (regs->cs != __USER_CS)
6665 ++ if ((regs->cs & 0xffff) != __USER_CS)
6666 + /* 32-bit mode: register increment */
6667 + return 0;
6668 + /* 64-bit mode: REX prefix */
6669 +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
6670 +--- linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-07 12:55:34.000000000 -0500
6671 ++++ linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-18 03:38:44.000000000 -0500
6672 +@@ -1,3 +1,4 @@
6673 ++.section .rodata,"a",@progbits
6674 + ENTRY(sys_call_table)
6675 + .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
6676 + .long sys_exit
6677 +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
6678 +--- linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-07 12:55:34.000000000 -0500
6679 ++++ linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-18 03:38:44.000000000 -0500
6680 +@@ -22,6 +22,21 @@
6681 + #include <linux/uaccess.h>
6682 + #include <linux/unistd.h>
6683 +
6684 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6685 ++{
6686 ++ unsigned long pax_task_size = TASK_SIZE;
6687 ++
6688 ++#ifdef CONFIG_PAX_SEGMEXEC
6689 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6690 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6691 ++#endif
6692 ++
6693 ++ if (len > pax_task_size || addr > pax_task_size - len)
6694 ++ return -EINVAL;
6695 ++
6696 ++ return 0;
6697 ++}
6698 ++
6699 + asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
6700 + unsigned long prot, unsigned long flags,
6701 + unsigned long fd, unsigned long pgoff)
6702 +@@ -81,6 +96,205 @@ out:
6703 + return err;
6704 + }
6705 +
6706 ++unsigned long
6707 ++arch_get_unmapped_area(struct file *filp, unsigned long addr,
6708 ++ unsigned long len, unsigned long pgoff, unsigned long flags)
6709 ++{
6710 ++ struct mm_struct *mm = current->mm;
6711 ++ struct vm_area_struct *vma;
6712 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
6713 ++
6714 ++#ifdef CONFIG_PAX_SEGMEXEC
6715 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6716 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6717 ++#endif
6718 ++
6719 ++ if (len > pax_task_size)
6720 ++ return -ENOMEM;
6721 ++
6722 ++ if (flags & MAP_FIXED)
6723 ++ return addr;
6724 ++
6725 ++#ifdef CONFIG_PAX_RANDMMAP
6726 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6727 ++#endif
6728 ++
6729 ++ if (addr) {
6730 ++ addr = PAGE_ALIGN(addr);
6731 ++ vma = find_vma(mm, addr);
6732 ++ if (pax_task_size - len >= addr &&
6733 ++ (!vma || addr + len <= vma->vm_start))
6734 ++ return addr;
6735 ++ }
6736 ++ if (len > mm->cached_hole_size) {
6737 ++ start_addr = addr = mm->free_area_cache;
6738 ++ } else {
6739 ++ start_addr = addr = mm->mmap_base;
6740 ++ mm->cached_hole_size = 0;
6741 ++ }
6742 ++
6743 ++#ifdef CONFIG_PAX_PAGEEXEC
6744 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
6745 ++ start_addr = 0x00110000UL;
6746 ++
6747 ++#ifdef CONFIG_PAX_RANDMMAP
6748 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6749 ++ start_addr += mm->delta_mmap & 0x03FFF000UL;
6750 ++#endif
6751 ++
6752 ++ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
6753 ++ start_addr = addr = mm->mmap_base;
6754 ++ else
6755 ++ addr = start_addr;
6756 ++ }
6757 ++#endif
6758 ++
6759 ++full_search:
6760 ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
6761 ++ /* At this point: (!vma || addr < vma->vm_end). */
6762 ++ if (pax_task_size - len < addr) {
6763 ++ /*
6764 ++ * Start a new search - just in case we missed
6765 ++ * some holes.
6766 ++ */
6767 ++ if (start_addr != mm->mmap_base) {
6768 ++ start_addr = addr = mm->mmap_base;
6769 ++ mm->cached_hole_size = 0;
6770 ++ goto full_search;
6771 ++ }
6772 ++ return -ENOMEM;
6773 ++ }
6774 ++ if (!vma || addr + len <= vma->vm_start) {
6775 ++ /*
6776 ++ * Remember the place where we stopped the search:
6777 ++ */
6778 ++ mm->free_area_cache = addr + len;
6779 ++ return addr;
6780 ++ }
6781 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6782 ++ mm->cached_hole_size = vma->vm_start - addr;
6783 ++ addr = vma->vm_end;
6784 ++ if (mm->start_brk <= addr && addr < mm->mmap_base) {
6785 ++ start_addr = addr = mm->mmap_base;
6786 ++ mm->cached_hole_size = 0;
6787 ++ goto full_search;
6788 ++ }
6789 ++ }
6790 ++}
6791 ++
6792 ++unsigned long
6793 ++arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6794 ++ const unsigned long len, const unsigned long pgoff,
6795 ++ const unsigned long flags)
6796 ++{
6797 ++ struct vm_area_struct *vma;
6798 ++ struct mm_struct *mm = current->mm;
6799 ++ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
6800 ++
6801 ++#ifdef CONFIG_PAX_SEGMEXEC
6802 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6803 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6804 ++#endif
6805 ++
6806 ++ /* requested length too big for entire address space */
6807 ++ if (len > pax_task_size)
6808 ++ return -ENOMEM;
6809 ++
6810 ++ if (flags & MAP_FIXED)
6811 ++ return addr;
6812 ++
6813 ++#ifdef CONFIG_PAX_PAGEEXEC
6814 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
6815 ++ goto bottomup;
6816 ++#endif
6817 ++
6818 ++#ifdef CONFIG_PAX_RANDMMAP
6819 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6820 ++#endif
6821 ++
6822 ++ /* requesting a specific address */
6823 ++ if (addr) {
6824 ++ addr = PAGE_ALIGN(addr);
6825 ++ vma = find_vma(mm, addr);
6826 ++ if (pax_task_size - len >= addr &&
6827 ++ (!vma || addr + len <= vma->vm_start))
6828 ++ return addr;
6829 ++ }
6830 ++
6831 ++ /* check if free_area_cache is useful for us */
6832 ++ if (len <= mm->cached_hole_size) {
6833 ++ mm->cached_hole_size = 0;
6834 ++ mm->free_area_cache = mm->mmap_base;
6835 ++ }
6836 ++
6837 ++ /* either no address requested or can't fit in requested address hole */
6838 ++ addr = mm->free_area_cache;
6839 ++
6840 ++ /* make sure it can fit in the remaining address space */
6841 ++ if (addr > len) {
6842 ++ vma = find_vma(mm, addr-len);
6843 ++ if (!vma || addr <= vma->vm_start)
6844 ++ /* remember the address as a hint for next time */
6845 ++ return (mm->free_area_cache = addr-len);
6846 ++ }
6847 ++
6848 ++ if (mm->mmap_base < len)
6849 ++ goto bottomup;
6850 ++
6851 ++ addr = mm->mmap_base-len;
6852 ++
6853 ++ do {
6854 ++ /*
6855 ++ * Lookup failure means no vma is above this address,
6856 ++ * else if new region fits below vma->vm_start,
6857 ++ * return with success:
6858 ++ */
6859 ++ vma = find_vma(mm, addr);
6860 ++ if (!vma || addr+len <= vma->vm_start)
6861 ++ /* remember the address as a hint for next time */
6862 ++ return (mm->free_area_cache = addr);
6863 ++
6864 ++ /* remember the largest hole we saw so far */
6865 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6866 ++ mm->cached_hole_size = vma->vm_start - addr;
6867 ++
6868 ++ /* try just below the current vma->vm_start */
6869 ++ addr = vma->vm_start-len;
6870 ++ } while (len < vma->vm_start);
6871 ++
6872 ++bottomup:
6873 ++ /*
6874 ++ * A failed mmap() very likely causes application failure,
6875 ++ * so fall back to the bottom-up function here. This scenario
6876 ++ * can happen with large stack limits and large mmap()
6877 ++ * allocations.
6878 ++ */
6879 ++
6880 ++#ifdef CONFIG_PAX_SEGMEXEC
6881 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6882 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
6883 ++ else
6884 ++#endif
6885 ++
6886 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6887 ++
6888 ++#ifdef CONFIG_PAX_RANDMMAP
6889 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6890 ++ mm->mmap_base += mm->delta_mmap;
6891 ++#endif
6892 ++
6893 ++ mm->free_area_cache = mm->mmap_base;
6894 ++ mm->cached_hole_size = ~0UL;
6895 ++ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6896 ++ /*
6897 ++ * Restore the topdown base:
6898 ++ */
6899 ++ mm->mmap_base = base;
6900 ++ mm->free_area_cache = base;
6901 ++ mm->cached_hole_size = ~0UL;
6902 ++
6903 ++ return addr;
6904 ++}
6905 +
6906 + struct sel_arg_struct {
6907 + unsigned long n;
6908 +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
6909 +--- linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-07 12:55:34.000000000 -0500
6910 ++++ linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-18 03:38:44.000000000 -0500
6911 +@@ -45,8 +45,8 @@ out:
6912 + return error;
6913 + }
6914 +
6915 +-static void find_start_end(unsigned long flags, unsigned long *begin,
6916 +- unsigned long *end)
6917 ++static void find_start_end(struct mm_struct *mm, unsigned long flags,
6918 ++ unsigned long *begin, unsigned long *end)
6919 + {
6920 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
6921 + unsigned long new_begin;
6922 +@@ -65,7 +65,7 @@ static void find_start_end(unsigned long
6923 + *begin = new_begin;
6924 + }
6925 + } else {
6926 +- *begin = TASK_UNMAPPED_BASE;
6927 ++ *begin = mm->mmap_base;
6928 + *end = TASK_SIZE;
6929 + }
6930 + }
6931 +@@ -82,11 +82,15 @@ arch_get_unmapped_area(struct file *filp
6932 + if (flags & MAP_FIXED)
6933 + return addr;
6934 +
6935 +- find_start_end(flags, &begin, &end);
6936 ++ find_start_end(mm, flags, &begin, &end);
6937 +
6938 + if (len > end)
6939 + return -ENOMEM;
6940 +
6941 ++#ifdef CONFIG_PAX_RANDMMAP
6942 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6943 ++#endif
6944 ++
6945 + if (addr) {
6946 + addr = PAGE_ALIGN(addr);
6947 + vma = find_vma(mm, addr);
6948 +@@ -141,7 +145,7 @@ arch_get_unmapped_area_topdown(struct fi
6949 + {
6950 + struct vm_area_struct *vma;
6951 + struct mm_struct *mm = current->mm;
6952 +- unsigned long addr = addr0;
6953 ++ unsigned long base = mm->mmap_base, addr = addr0;
6954 +
6955 + /* requested length too big for entire address space */
6956 + if (len > TASK_SIZE)
6957 +@@ -154,6 +158,10 @@ arch_get_unmapped_area_topdown(struct fi
6958 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
6959 + goto bottomup;
6960 +
6961 ++#ifdef CONFIG_PAX_RANDMMAP
6962 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6963 ++#endif
6964 ++
6965 + /* requesting a specific address */
6966 + if (addr) {
6967 + addr = PAGE_ALIGN(addr);
6968 +@@ -211,13 +219,21 @@ bottomup:
6969 + * can happen with large stack limits and large mmap()
6970 + * allocations.
6971 + */
6972 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6973 ++
6974 ++#ifdef CONFIG_PAX_RANDMMAP
6975 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6976 ++ mm->mmap_base += mm->delta_mmap;
6977 ++#endif
6978 ++
6979 ++ mm->free_area_cache = mm->mmap_base;
6980 + mm->cached_hole_size = ~0UL;
6981 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
6982 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6983 + /*
6984 + * Restore the topdown base:
6985 + */
6986 +- mm->free_area_cache = mm->mmap_base;
6987 ++ mm->mmap_base = base;
6988 ++ mm->free_area_cache = base;
6989 + mm->cached_hole_size = ~0UL;
6990 +
6991 + return addr;
6992 +diff -urNp linux-2.6.27.10/arch/x86/kernel/time_32.c linux-2.6.27.10/arch/x86/kernel/time_32.c
6993 +--- linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-07 12:55:34.000000000 -0500
6994 ++++ linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-18 03:38:44.000000000 -0500
6995 +@@ -49,20 +49,30 @@ unsigned long profile_pc(struct pt_regs
6996 + if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs) &&
6997 + in_lock_functions(pc)) {
6998 + #ifdef CONFIG_FRAME_POINTER
6999 +- return *(unsigned long *)(regs->bp + 4);
7000 ++ return ktla_ktva(*(unsigned long *)(regs->bp + 4));
7001 + #else
7002 + unsigned long *sp = (unsigned long *)&regs->sp;
7003 +
7004 + /* Return address is either directly at stack pointer
7005 + or above a saved flags. Eflags has bits 22-31 zero,
7006 + kernel addresses don't. */
7007 ++
7008 ++#ifdef CONFIG_PAX_KERNEXEC
7009 ++ return ktla_ktva(sp[0]);
7010 ++#else
7011 + if (sp[0] >> 22)
7012 + return sp[0];
7013 + if (sp[1] >> 22)
7014 + return sp[1];
7015 + #endif
7016 ++
7017 ++#endif
7018 + }
7019 + #endif
7020 ++
7021 ++ if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs))
7022 ++ pc = ktla_ktva(pc);
7023 ++
7024 + return pc;
7025 + }
7026 + EXPORT_SYMBOL(profile_pc);
7027 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tlb_32.c linux-2.6.27.10/arch/x86/kernel/tlb_32.c
7028 +--- linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-07 12:55:34.000000000 -0500
7029 ++++ linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-18 03:38:44.000000000 -0500
7030 +@@ -5,7 +5,7 @@
7031 + #include <asm/tlbflush.h>
7032 +
7033 + DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate)
7034 +- ____cacheline_aligned = { &init_mm, 0, };
7035 ++ ____cacheline_aligned = { &init_mm, 0, {0} };
7036 +
7037 + /* must come after the send_IPI functions above for inlining */
7038 + #include <mach_ipi.h>
7039 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tls.c linux-2.6.27.10/arch/x86/kernel/tls.c
7040 +--- linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-07 12:55:34.000000000 -0500
7041 ++++ linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-18 03:38:44.000000000 -0500
7042 +@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struc
7043 + if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
7044 + return -EINVAL;
7045 +
7046 ++#ifdef CONFIG_PAX_SEGMEXEC
7047 ++ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
7048 ++ return -EINVAL;
7049 ++#endif
7050 ++
7051 + set_tls_desc(p, idx, &info, 1);
7052 +
7053 + return 0;
7054 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_32.c linux-2.6.27.10/arch/x86/kernel/traps_32.c
7055 +--- linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-11-07 12:55:34.000000000 -0500
7056 ++++ linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-12-10 22:28:27.000000000 -0500
7057 +@@ -70,14 +70,6 @@ asmlinkage int system_call(void);
7058 + /* Do we ignore FPU interrupts ? */
7059 + char ignore_fpu_irq;
7060 +
7061 +-/*
7062 +- * The IDT has to be page-aligned to simplify the Pentium
7063 +- * F0 0F bug workaround.. We have a special link segment
7064 +- * for this.
7065 +- */
7066 +-gate_desc idt_table[256]
7067 +- __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
7068 +-
7069 + int panic_on_unrecovered_nmi;
7070 + int kstack_depth_to_print = 24;
7071 + static unsigned int code_bytes = 64;
7072 +@@ -320,21 +312,22 @@ void show_registers(struct pt_regs *regs
7073 + * When in-kernel, we also print out the stack and code at the
7074 + * time of the fault..
7075 + */
7076 +- if (!user_mode_vm(regs)) {
7077 ++ if (!user_mode(regs)) {
7078 + unsigned int code_prologue = code_bytes * 43 / 64;
7079 + unsigned int code_len = code_bytes;
7080 + unsigned char c;
7081 + u8 *ip;
7082 ++ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
7083 +
7084 + printk("\n" KERN_EMERG "Stack: ");
7085 + show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
7086 +
7087 + printk(KERN_EMERG "Code: ");
7088 +
7089 +- ip = (u8 *)regs->ip - code_prologue;
7090 ++ ip = (u8 *)regs->ip - code_prologue + cs_base;
7091 + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
7092 + /* try starting at EIP */
7093 +- ip = (u8 *)regs->ip;
7094 ++ ip = (u8 *)regs->ip + cs_base;
7095 + code_len = code_len - code_prologue + 1;
7096 + }
7097 + for (i = 0; i < code_len; i++, ip++) {
7098 +@@ -343,7 +336,7 @@ void show_registers(struct pt_regs *regs
7099 + printk(" Bad EIP value.");
7100 + break;
7101 + }
7102 +- if (ip == (u8 *)regs->ip)
7103 ++ if (ip == (u8 *)regs->ip + cs_base)
7104 + printk("<%02x> ", c);
7105 + else
7106 + printk("%02x ", c);
7107 +@@ -356,6 +349,7 @@ int is_valid_bugaddr(unsigned long ip)
7108 + {
7109 + unsigned short ud2;
7110 +
7111 ++ ip = ktla_ktva(ip);
7112 + if (ip < PAGE_OFFSET)
7113 + return 0;
7114 + if (probe_kernel_address((unsigned short *)ip, ud2))
7115 +@@ -469,7 +463,7 @@ void die(const char *str, struct pt_regs
7116 + static inline void
7117 + die_if_kernel(const char *str, struct pt_regs *regs, long err)
7118 + {
7119 +- if (!user_mode_vm(regs))
7120 ++ if (!user_mode(regs))
7121 + die(str, regs, err);
7122 + }
7123 +
7124 +@@ -479,13 +473,13 @@ do_trap(int trapnr, int signr, char *str
7125 + {
7126 + struct task_struct *tsk = current;
7127 +
7128 +- if (regs->flags & X86_VM_MASK) {
7129 ++ if (v8086_mode(regs)) {
7130 + if (vm86)
7131 + goto vm86_trap;
7132 + goto trap_signal;
7133 + }
7134 +
7135 +- if (!user_mode(regs))
7136 ++ if (!user_mode_novm(regs))
7137 + goto kernel_trap;
7138 +
7139 + trap_signal:
7140 +@@ -513,6 +507,12 @@ kernel_trap:
7141 + tsk->thread.trap_no = trapnr;
7142 + die(str, regs, error_code);
7143 + }
7144 ++
7145 ++#ifdef CONFIG_PAX_REFCOUNT
7146 ++ if (trapnr == 4)
7147 ++ pax_report_refcount_overflow(regs);
7148 ++#endif
7149 ++
7150 + return;
7151 +
7152 + vm86_trap:
7153 +@@ -595,7 +595,7 @@ do_general_protection(struct pt_regs *re
7154 + int cpu;
7155 +
7156 + cpu = get_cpu();
7157 +- tss = &per_cpu(init_tss, cpu);
7158 ++ tss = init_tss + cpu;
7159 + thread = &current->thread;
7160 +
7161 + /*
7162 +@@ -627,13 +627,29 @@ do_general_protection(struct pt_regs *re
7163 + }
7164 + put_cpu();
7165 +
7166 +- if (regs->flags & X86_VM_MASK)
7167 ++ if (v8086_mode(regs))
7168 + goto gp_in_vm86;
7169 +
7170 + tsk = current;
7171 +- if (!user_mode(regs))
7172 ++ if (!user_mode_novm(regs))
7173 + goto gp_in_kernel;
7174 +
7175 ++#ifdef CONFIG_PAX_PAGEEXEC
7176 ++ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
7177 ++ struct mm_struct *mm = tsk->mm;
7178 ++ unsigned long limit;
7179 ++
7180 ++ down_write(&mm->mmap_sem);
7181 ++ limit = mm->context.user_cs_limit;
7182 ++ if (limit < TASK_SIZE) {
7183 ++ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
7184 ++ up_write(&mm->mmap_sem);
7185 ++ return;
7186 ++ }
7187 ++ up_write(&mm->mmap_sem);
7188 ++ }
7189 ++#endif
7190 ++
7191 + tsk->thread.error_code = error_code;
7192 + tsk->thread.trap_no = 13;
7193 +
7194 +@@ -664,6 +680,13 @@ gp_in_kernel:
7195 + if (notify_die(DIE_GPF, "general protection fault", regs,
7196 + error_code, 13, SIGSEGV) == NOTIFY_STOP)
7197 + return;
7198 ++
7199 ++#ifdef CONFIG_PAX_KERNEXEC
7200 ++ if ((regs->cs & 0xFFFF) == __KERNEL_CS)
7201 ++ die("PAX: suspicious general protection fault", regs, error_code);
7202 ++ else
7203 ++#endif
7204 ++
7205 + die("general protection fault", regs, error_code);
7206 + }
7207 +
7208 +@@ -766,7 +789,7 @@ void notrace __kprobes die_nmi(char *str
7209 + * If we are in kernel we are probably nested up pretty bad
7210 + * and might aswell get out now while we still can:
7211 + */
7212 +- if (!user_mode_vm(regs)) {
7213 ++ if (!user_mode(regs)) {
7214 + current->thread.trap_no = 2;
7215 + crash_kexec(regs);
7216 + }
7217 +@@ -915,7 +938,7 @@ void __kprobes do_debug(struct pt_regs *
7218 + goto clear_dr7;
7219 + }
7220 +
7221 +- if (regs->flags & X86_VM_MASK)
7222 ++ if (v8086_mode(regs))
7223 + goto debug_vm86;
7224 +
7225 + /* Save debug status register where ptrace can see it */
7226 +@@ -931,7 +954,7 @@ void __kprobes do_debug(struct pt_regs *
7227 + * check for kernel mode by just checking the CPL
7228 + * of CS.
7229 + */
7230 +- if (!user_mode(regs))
7231 ++ if (!user_mode_novm(regs))
7232 + goto clear_TF_reenable;
7233 + }
7234 +
7235 +@@ -1086,7 +1109,7 @@ void do_simd_coprocessor_error(struct pt
7236 + * Handle strange cache flush from user space exception
7237 + * in all other cases. This is undocumented behaviour.
7238 + */
7239 +- if (regs->flags & X86_VM_MASK) {
7240 ++ if (v8086_mode(regs)) {
7241 + handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
7242 + return;
7243 + }
7244 +@@ -1106,19 +1129,14 @@ void do_spurious_interrupt_bug(struct pt
7245 +
7246 + unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
7247 + {
7248 +- struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
7249 + unsigned long base = (kesp - uesp) & -THREAD_SIZE;
7250 + unsigned long new_kesp = kesp - base;
7251 + unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
7252 +- __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
7253 ++ struct desc_struct ss;
7254 +
7255 + /* Set up base for espfix segment */
7256 +- desc &= 0x00f0ff0000000000ULL;
7257 +- desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
7258 +- ((((__u64)base) << 32) & 0xff00000000000000ULL) |
7259 +- ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
7260 +- (lim_pages & 0xffff);
7261 +- *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
7262 ++ pack_descriptor(&ss, base, lim_pages, 0x93, 0xC);
7263 ++ write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S);
7264 +
7265 + return new_kesp;
7266 + }
7267 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_64.c linux-2.6.27.10/arch/x86/kernel/traps_64.c
7268 +--- linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-07 12:55:34.000000000 -0500
7269 ++++ linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-18 03:38:44.000000000 -0500
7270 +@@ -634,6 +634,12 @@ kernel_trap:
7271 + tsk->thread.trap_no = trapnr;
7272 + die(str, regs, error_code);
7273 + }
7274 ++
7275 ++#ifdef CONFIG_PAX_REFCOUNT
7276 ++ if (trapnr == 4)
7277 ++ pax_report_refcount_overflow(regs);
7278 ++#endif
7279 ++
7280 + return;
7281 + }
7282 +
7283 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tsc.c linux-2.6.27.10/arch/x86/kernel/tsc.c
7284 +--- linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-17 20:03:30.000000000 -0500
7285 ++++ linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-18 03:38:44.000000000 -0500
7286 +@@ -554,7 +554,7 @@ static struct dmi_system_id __initdata b
7287 + DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
7288 + },
7289 + },
7290 +- {}
7291 ++ { NULL, NULL, {{0, NULL}}, NULL}
7292 + };
7293 +
7294 + /*
7295 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vm86_32.c linux-2.6.27.10/arch/x86/kernel/vm86_32.c
7296 +--- linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-07 12:55:34.000000000 -0500
7297 ++++ linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-18 03:38:44.000000000 -0500
7298 +@@ -147,7 +147,7 @@ struct pt_regs *save_v86_state(struct ke
7299 + do_exit(SIGSEGV);
7300 + }
7301 +
7302 +- tss = &per_cpu(init_tss, get_cpu());
7303 ++ tss = init_tss + get_cpu();
7304 + current->thread.sp0 = current->thread.saved_sp0;
7305 + current->thread.sysenter_cs = __KERNEL_CS;
7306 + load_sp0(tss, &current->thread);
7307 +@@ -324,7 +324,7 @@ static void do_sys_vm86(struct kernel_vm
7308 + tsk->thread.saved_fs = info->regs32->fs;
7309 + savesegment(gs, tsk->thread.saved_gs);
7310 +
7311 +- tss = &per_cpu(init_tss, get_cpu());
7312 ++ tss = init_tss + get_cpu();
7313 + tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
7314 + if (cpu_has_sep)
7315 + tsk->thread.sysenter_cs = 0;
7316 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmi_32.c linux-2.6.27.10/arch/x86/kernel/vmi_32.c
7317 +--- linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:11.000000000 -0500
7318 ++++ linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:21.000000000 -0500
7319 +@@ -102,18 +102,43 @@ static unsigned patch_internal(int call,
7320 + {
7321 + u64 reloc;
7322 + struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
7323 ++
7324 ++#ifdef CONFIG_PAX_KERNEXEC
7325 ++ unsigned long cr0;
7326 ++#endif
7327 ++
7328 + reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
7329 + switch(rel->type) {
7330 + case VMI_RELOCATION_CALL_REL:
7331 + BUG_ON(len < 5);
7332 ++
7333 ++#ifdef CONFIG_PAX_KERNEXEC
7334 ++ pax_open_kernel(cr0);
7335 ++#endif
7336 ++
7337 + *(char *)insnbuf = MNEM_CALL;
7338 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7339 ++
7340 ++#ifdef CONFIG_PAX_KERNEXEC
7341 ++ pax_close_kernel(cr0);
7342 ++#endif
7343 ++
7344 + return 5;
7345 +
7346 + case VMI_RELOCATION_JUMP_REL:
7347 + BUG_ON(len < 5);
7348 ++
7349 ++#ifdef CONFIG_PAX_KERNEXEC
7350 ++ pax_open_kernel(cr0);
7351 ++#endif
7352 ++
7353 + *(char *)insnbuf = MNEM_JMP;
7354 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7355 ++
7356 ++#ifdef CONFIG_PAX_KERNEXEC
7357 ++ pax_close_kernel(cr0);
7358 ++#endif
7359 ++
7360 + return 5;
7361 +
7362 + case VMI_RELOCATION_NOP:
7363 +@@ -516,14 +541,14 @@ static void vmi_set_pud(pud_t *pudp, pud
7364 +
7365 + static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
7366 + {
7367 +- const pte_t pte = { .pte = 0 };
7368 ++ const pte_t pte = __pte(0ULL);
7369 + vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
7370 + vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
7371 + }
7372 +
7373 + static void vmi_pmd_clear(pmd_t *pmd)
7374 + {
7375 +- const pte_t pte = { .pte = 0 };
7376 ++ const pte_t pte = __pte(0ULL);
7377 + vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD);
7378 + vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
7379 + }
7380 +@@ -552,8 +577,8 @@ vmi_startup_ipi_hook(int phys_apicid, un
7381 + ap.ss = __KERNEL_DS;
7382 + ap.esp = (unsigned long) start_esp;
7383 +
7384 +- ap.ds = __USER_DS;
7385 +- ap.es = __USER_DS;
7386 ++ ap.ds = __KERNEL_DS;
7387 ++ ap.es = __KERNEL_DS;
7388 + ap.fs = __KERNEL_PERCPU;
7389 + ap.gs = 0;
7390 +
7391 +@@ -748,12 +773,20 @@ static inline int __init activate_vmi(vo
7392 + u64 reloc;
7393 + const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc;
7394 +
7395 ++#ifdef CONFIG_PAX_KERNEXEC
7396 ++ unsigned long cr0;
7397 ++#endif
7398 ++
7399 + if (call_vrom_func(vmi_rom, vmi_init) != 0) {
7400 + printk(KERN_ERR "VMI ROM failed to initialize!");
7401 + return 0;
7402 + }
7403 + savesegment(cs, kernel_cs);
7404 +
7405 ++#ifdef CONFIG_PAX_KERNEXEC
7406 ++ pax_open_kernel(cr0);
7407 ++#endif
7408 ++
7409 + pv_info.paravirt_enabled = 1;
7410 + pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK;
7411 + pv_info.name = "vmi";
7412 +@@ -943,6 +976,10 @@ static inline int __init activate_vmi(vo
7413 +
7414 + para_fill(pv_irq_ops.safe_halt, Halt);
7415 +
7416 ++#ifdef CONFIG_PAX_KERNEXEC
7417 ++ pax_close_kernel(cr0);
7418 ++#endif
7419 ++
7420 + /*
7421 + * Alternative instruction rewriting doesn't happen soon enough
7422 + * to convert VMI_IRET to a call instead of a jump; so we have
7423 +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
7424 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-07 12:55:34.000000000 -0500
7425 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-18 03:38:44.000000000 -0500
7426 +@@ -15,6 +15,20 @@
7427 + #include <asm/page.h>
7428 + #include <asm/cache.h>
7429 + #include <asm/boot.h>
7430 ++#include <asm/segment.h>
7431 ++
7432 ++#ifdef CONFIG_X86_PAE
7433 ++#define PMD_SHIFT 21
7434 ++#else
7435 ++#define PMD_SHIFT 22
7436 ++#endif
7437 ++#define PMD_SIZE (1 << PMD_SHIFT)
7438 ++
7439 ++#ifdef CONFIG_PAX_KERNEXEC
7440 ++#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1)))
7441 ++#else
7442 ++#define __KERNEL_TEXT_OFFSET 0
7443 ++#endif
7444 +
7445 + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
7446 + OUTPUT_ARCH(i386)
7447 +@@ -22,81 +36,23 @@ ENTRY(phys_startup_32)
7448 + jiffies = jiffies_64;
7449 +
7450 + PHDRS {
7451 +- text PT_LOAD FLAGS(5); /* R_E */
7452 +- data PT_LOAD FLAGS(7); /* RWE */
7453 +- note PT_NOTE FLAGS(0); /* ___ */
7454 ++ initdata PT_LOAD FLAGS(6); /* RW_ */
7455 ++ percpu PT_LOAD FLAGS(6); /* RW_ */
7456 ++ inittext PT_LOAD FLAGS(5); /* R_E */
7457 ++ text PT_LOAD FLAGS(5); /* R_E */
7458 ++ rodata PT_LOAD FLAGS(4); /* R__ */
7459 ++ data PT_LOAD FLAGS(6); /* RW_ */
7460 ++ note PT_NOTE FLAGS(0); /* ___ */
7461 + }
7462 + SECTIONS
7463 + {
7464 +- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
7465 +- phys_startup_32 = startup_32 - LOAD_OFFSET;
7466 +-
7467 +- .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
7468 +- _text = .; /* Text and read-only data */
7469 +- *(.text.head)
7470 +- } :text = 0x9090
7471 +-
7472 +- /* read-only */
7473 +- .text : AT(ADDR(.text) - LOAD_OFFSET) {
7474 +- . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7475 +- *(.text.page_aligned)
7476 +- TEXT_TEXT
7477 +- SCHED_TEXT
7478 +- LOCK_TEXT
7479 +- KPROBES_TEXT
7480 +- *(.fixup)
7481 +- *(.gnu.warning)
7482 +- _etext = .; /* End of text section */
7483 +- } :text = 0x9090
7484 +-
7485 +- NOTES :text :note
7486 ++ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
7487 +
7488 +- . = ALIGN(16); /* Exception table */
7489 +- __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7490 +- __start___ex_table = .;
7491 +- *(__ex_table)
7492 +- __stop___ex_table = .;
7493 +- } :text = 0x9090
7494 +-
7495 +- RODATA
7496 +-
7497 +- /* writeable */
7498 +- . = ALIGN(PAGE_SIZE);
7499 +- .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7500 +- DATA_DATA
7501 +- CONSTRUCTORS
7502 +- } :data
7503 +-
7504 +- . = ALIGN(PAGE_SIZE);
7505 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7506 +- __nosave_begin = .;
7507 +- *(.data.nosave)
7508 +- . = ALIGN(PAGE_SIZE);
7509 +- __nosave_end = .;
7510 +- }
7511 +-
7512 +- . = ALIGN(PAGE_SIZE);
7513 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7514 +- *(.data.page_aligned)
7515 +- *(.data.idt)
7516 +- }
7517 +-
7518 +- . = ALIGN(32);
7519 +- .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7520 +- *(.data.cacheline_aligned)
7521 +- }
7522 +-
7523 +- /* rarely changed data like cpu maps */
7524 +- . = ALIGN(32);
7525 +- .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7526 +- *(.data.read_mostly)
7527 +- _edata = .; /* End of data section */
7528 +- }
7529 +-
7530 +- . = ALIGN(THREAD_SIZE); /* init_task */
7531 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7532 +- *(.data.init_task)
7533 +- }
7534 ++ .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) {
7535 ++ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET;
7536 ++ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
7537 ++ *(.text.startup)
7538 ++ } :initdata
7539 +
7540 + /* might get freed after init */
7541 + . = ALIGN(PAGE_SIZE);
7542 +@@ -114,14 +70,8 @@ SECTIONS
7543 + . = ALIGN(PAGE_SIZE);
7544 +
7545 + /* will be freed after init */
7546 +- . = ALIGN(PAGE_SIZE); /* Init code and data */
7547 +- .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
7548 +- __init_begin = .;
7549 +- _sinittext = .;
7550 +- INIT_TEXT
7551 +- _einittext = .;
7552 +- }
7553 + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
7554 ++ __init_begin = .;
7555 + INIT_DATA
7556 + }
7557 + . = ALIGN(16);
7558 +@@ -161,11 +111,6 @@ SECTIONS
7559 + *(.parainstructions)
7560 + __parainstructions_end = .;
7561 + }
7562 +- /* .exit.text is discard at runtime, not link time, to deal with references
7563 +- from .altinstructions and .eh_frame */
7564 +- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
7565 +- EXIT_TEXT
7566 +- }
7567 + .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
7568 + EXIT_DATA
7569 + }
7570 +@@ -178,17 +123,136 @@ SECTIONS
7571 + }
7572 + #endif
7573 + . = ALIGN(PAGE_SIZE);
7574 +- .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
7575 +- __per_cpu_start = .;
7576 ++ per_cpu_start = .;
7577 ++ .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) {
7578 ++ __per_cpu_start = . + per_cpu_start;
7579 ++ LONG(0)
7580 + *(.data.percpu)
7581 + *(.data.percpu.shared_aligned)
7582 +- __per_cpu_end = .;
7583 +- }
7584 ++ __per_cpu_end = . + per_cpu_start;
7585 ++ } :percpu
7586 ++ . += per_cpu_start;
7587 + . = ALIGN(PAGE_SIZE);
7588 + /* freed after init ends here */
7589 +
7590 ++ . = ALIGN(PAGE_SIZE); /* Init code and data */
7591 ++ .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7592 ++ _sinittext = .;
7593 ++ INIT_TEXT
7594 ++ _einittext = .;
7595 ++ } :inittext
7596 ++
7597 ++ /* .exit.text is discard at runtime, not link time, to deal with references
7598 ++ from .altinstructions and .eh_frame */
7599 ++ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7600 ++ EXIT_TEXT
7601 ++ }
7602 ++
7603 ++ .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7604 ++ BYTE(0)
7605 ++ . = ALIGN(2*PMD_SIZE) - 1;
7606 ++ }
7607 ++
7608 ++ /* freed after init ends here */
7609 ++
7610 ++ .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7611 ++ __init_end = . + __KERNEL_TEXT_OFFSET;
7612 ++ KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET;
7613 ++ _text = .; /* Text and read-only data */
7614 ++ *(.text.head)
7615 ++ } :text = 0x9090
7616 ++
7617 ++ /* read-only */
7618 ++ .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7619 ++ . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7620 ++ *(.text.page_aligned)
7621 ++ TEXT_TEXT
7622 ++ SCHED_TEXT
7623 ++ LOCK_TEXT
7624 ++ KPROBES_TEXT
7625 ++ *(.fixup)
7626 ++ *(.gnu.warning)
7627 ++ _etext = .; /* End of text section */
7628 ++ } :text = 0x9090
7629 ++
7630 ++ . += __KERNEL_TEXT_OFFSET;
7631 ++
7632 ++ . = ALIGN(4096); /* Exception table */
7633 ++ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7634 ++ __start___ex_table = .;
7635 ++ *(__ex_table)
7636 ++ __stop___ex_table = .;
7637 ++ } :rodata
7638 ++
7639 ++ NOTES :rodata :note
7640 ++
7641 ++ RO_DATA(PAGE_SIZE)
7642 ++
7643 ++ . = ALIGN(PAGE_SIZE);
7644 ++ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
7645 ++ *(.idt)
7646 ++ . = ALIGN(PAGE_SIZE);
7647 ++ *(.empty_zero_page)
7648 ++ *(.swapper_pg_pmd)
7649 ++ *(.swapper_pg_dir)
7650 ++ }
7651 ++
7652 ++#ifdef CONFIG_PAX_KERNEXEC
7653 ++
7654 ++#ifdef CONFIG_MODULES
7655 ++ . = ALIGN(PAGE_SIZE);
7656 ++ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
7657 ++ MODULES_VADDR = .;
7658 ++ BYTE(0)
7659 ++ . += (6 * 1024 * 1024);
7660 ++ . = ALIGN( PMD_SIZE) - 1;
7661 ++ MODULES_END = .;
7662 ++ }
7663 ++#else
7664 ++ . = ALIGN(PMD_SIZE) - 1;
7665 ++#endif
7666 ++
7667 ++#endif
7668 ++
7669 ++ /* writeable */
7670 ++ . = ALIGN(PAGE_SIZE);
7671 ++ .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7672 ++ _data = .;
7673 ++ DATA_DATA
7674 ++ CONSTRUCTORS
7675 ++ } :data
7676 ++
7677 ++ . = ALIGN(PAGE_SIZE);
7678 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7679 ++ __nosave_begin = .;
7680 ++ *(.data.nosave)
7681 ++ . = ALIGN(PAGE_SIZE);
7682 ++ __nosave_end = .;
7683 ++ }
7684 ++
7685 ++ . = ALIGN(PAGE_SIZE);
7686 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7687 ++ *(.data.page_aligned)
7688 ++ }
7689 ++
7690 ++ . = ALIGN(32);
7691 ++ .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7692 ++ *(.data.cacheline_aligned)
7693 ++ }
7694 ++
7695 ++ /* rarely changed data like cpu maps */
7696 ++ . = ALIGN(32);
7697 ++ .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7698 ++ *(.data.read_mostly)
7699 ++ _edata = .; /* End of data section */
7700 ++ }
7701 ++
7702 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7703 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7704 ++ *(.data.init_task)
7705 ++ }
7706 ++
7707 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7708 +- __init_end = .;
7709 + __bss_start = .; /* BSS */
7710 + *(.bss.page_aligned)
7711 + *(.bss)
7712 +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
7713 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-07 12:55:34.000000000 -0500
7714 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-18 03:38:44.000000000 -0500
7715 +@@ -16,7 +16,7 @@ jiffies_64 = jiffies;
7716 + _proxy_pda = 1;
7717 + PHDRS {
7718 + text PT_LOAD FLAGS(5); /* R_E */
7719 +- data PT_LOAD FLAGS(7); /* RWE */
7720 ++ data PT_LOAD FLAGS(6); /* RW_ */
7721 + user PT_LOAD FLAGS(7); /* RWE */
7722 + data.init PT_LOAD FLAGS(7); /* RWE */
7723 + note PT_NOTE FLAGS(0); /* ___ */
7724 +@@ -49,17 +49,20 @@ SECTIONS
7725 + __stop___ex_table = .;
7726 + } :text = 0x9090
7727 +
7728 +- RODATA
7729 ++ RO_DATA(PAGE_SIZE)
7730 +
7731 ++#ifdef CONFIG_PAX_KERNEXEC
7732 ++ . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */
7733 ++#else
7734 + . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
7735 ++#endif
7736 + /* Data */
7737 ++ _data = .;
7738 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
7739 + DATA_DATA
7740 + CONSTRUCTORS
7741 + } :data
7742 +
7743 +- _edata = .; /* End of data section */
7744 +-
7745 + . = ALIGN(PAGE_SIZE);
7746 + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
7747 + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7748 +@@ -70,9 +73,27 @@ SECTIONS
7749 + *(.data.read_mostly)
7750 + }
7751 +
7752 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7753 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7754 ++ *(.data.init_task)
7755 ++ }
7756 ++
7757 ++ . = ALIGN(PAGE_SIZE);
7758 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7759 ++ *(.data.page_aligned)
7760 ++ }
7761 ++
7762 ++ . = ALIGN(PAGE_SIZE);
7763 ++ __nosave_begin = .;
7764 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7765 ++ . = ALIGN(PAGE_SIZE);
7766 ++ __nosave_end = .;
7767 ++
7768 ++ _edata = .; /* End of data section */
7769 ++
7770 + #define VSYSCALL_ADDR (-10*1024*1024)
7771 +-#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7772 +-#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7773 ++#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7774 ++#define VSYSCALL_VIRT_ADDR ((ADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7775 +
7776 + #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
7777 + #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
7778 +@@ -120,23 +141,13 @@ SECTIONS
7779 + #undef VVIRT_OFFSET
7780 + #undef VVIRT
7781 +
7782 +- . = ALIGN(THREAD_SIZE); /* init_task */
7783 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7784 +- *(.data.init_task)
7785 +- }:data.init
7786 +-
7787 +- . = ALIGN(PAGE_SIZE);
7788 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7789 +- *(.data.page_aligned)
7790 +- }
7791 +-
7792 + /* might get freed after init */
7793 + . = ALIGN(PAGE_SIZE);
7794 + __smp_alt_begin = .;
7795 + __smp_locks = .;
7796 + .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
7797 + *(.smp_locks)
7798 +- }
7799 ++ } :data.init
7800 + __smp_locks_end = .;
7801 + . = ALIGN(PAGE_SIZE);
7802 + __smp_alt_end = .;
7803 +@@ -213,16 +224,11 @@ SECTIONS
7804 + . = ALIGN(PAGE_SIZE);
7805 + __init_end = .;
7806 +
7807 +- . = ALIGN(PAGE_SIZE);
7808 +- __nosave_begin = .;
7809 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7810 +- . = ALIGN(PAGE_SIZE);
7811 +- __nosave_end = .;
7812 +-
7813 + __bss_start = .; /* BSS */
7814 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7815 + *(.bss.page_aligned)
7816 + *(.bss)
7817 ++ . = ALIGN(2*1024*1024);
7818 + }
7819 + __bss_stop = .;
7820 +
7821 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c
7822 +--- linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-07 12:55:34.000000000 -0500
7823 ++++ linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-18 03:38:44.000000000 -0500
7824 +@@ -236,13 +236,13 @@ static ctl_table kernel_table2[] = {
7825 + .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
7826 + .mode = 0644,
7827 + .proc_handler = vsyscall_sysctl_change },
7828 +- {}
7829 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7830 + };
7831 +
7832 + static ctl_table kernel_root_table2[] = {
7833 + { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555,
7834 + .child = kernel_table2 },
7835 +- {}
7836 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7837 + };
7838 + #endif
7839 +
7840 +diff -urNp linux-2.6.27.10/arch/x86/kvm/svm.c linux-2.6.27.10/arch/x86/kvm/svm.c
7841 +--- linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-07 12:55:34.000000000 -0500
7842 ++++ linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-18 03:38:44.000000000 -0500
7843 +@@ -1515,7 +1515,19 @@ static void reload_tss(struct kvm_vcpu *
7844 + int cpu = raw_smp_processor_id();
7845 +
7846 + struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
7847 ++
7848 ++#ifdef CONFIG_PAX_KERNEXEC
7849 ++ unsigned long cr0;
7850 ++
7851 ++ pax_open_kernel(cr0);
7852 ++#endif
7853 ++
7854 + svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
7855 ++
7856 ++#ifdef CONFIG_PAX_KERNEXEC
7857 ++ pax_close_kernel(cr0);
7858 ++#endif
7859 ++
7860 + load_TR_desc();
7861 + }
7862 +
7863 +diff -urNp linux-2.6.27.10/arch/x86/kvm/vmx.c linux-2.6.27.10/arch/x86/kvm/vmx.c
7864 +--- linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-07 12:55:34.000000000 -0500
7865 ++++ linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-18 03:38:44.000000000 -0500
7866 +@@ -115,7 +115,7 @@ static struct vmcs_config {
7867 + u32 vmentry_ctrl;
7868 + } vmcs_config;
7869 +
7870 +-struct vmx_capability {
7871 ++static struct vmx_capability {
7872 + u32 ept;
7873 + u32 vpid;
7874 + } vmx_capability;
7875 +@@ -484,9 +484,23 @@ static void reload_tss(void)
7876 + struct descriptor_table gdt;
7877 + struct desc_struct *descs;
7878 +
7879 ++#ifdef CONFIG_PAX_KERNEXEC
7880 ++ unsigned long cr0;
7881 ++#endif
7882 ++
7883 + kvm_get_gdt(&gdt);
7884 + descs = (void *)gdt.base;
7885 ++
7886 ++#ifdef CONFIG_PAX_KERNEXEC
7887 ++ pax_open_kernel(cr0);
7888 ++#endif
7889 ++
7890 + descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
7891 ++
7892 ++#ifdef CONFIG_PAX_KERNEXEC
7893 ++ pax_close_kernel(cr0);
7894 ++#endif
7895 ++
7896 + load_TR_desc();
7897 + }
7898 +
7899 +@@ -3069,7 +3083,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
7900 + (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
7901 + (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)) == 0;
7902 +
7903 +- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
7904 ++ asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS));
7905 + vmx->launched = 1;
7906 +
7907 + intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
7908 +diff -urNp linux-2.6.27.10/arch/x86/kvm/x86.c linux-2.6.27.10/arch/x86/kvm/x86.c
7909 +--- linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-07 12:55:34.000000000 -0500
7910 ++++ linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-18 03:38:44.000000000 -0500
7911 +@@ -63,35 +63,35 @@ static int kvm_dev_ioctl_get_supported_c
7912 + struct kvm_x86_ops *kvm_x86_ops;
7913 +
7914 + struct kvm_stats_debugfs_item debugfs_entries[] = {
7915 +- { "pf_fixed", VCPU_STAT(pf_fixed) },
7916 +- { "pf_guest", VCPU_STAT(pf_guest) },
7917 +- { "tlb_flush", VCPU_STAT(tlb_flush) },
7918 +- { "invlpg", VCPU_STAT(invlpg) },
7919 +- { "exits", VCPU_STAT(exits) },
7920 +- { "io_exits", VCPU_STAT(io_exits) },
7921 +- { "mmio_exits", VCPU_STAT(mmio_exits) },
7922 +- { "signal_exits", VCPU_STAT(signal_exits) },
7923 +- { "irq_window", VCPU_STAT(irq_window_exits) },
7924 +- { "nmi_window", VCPU_STAT(nmi_window_exits) },
7925 +- { "halt_exits", VCPU_STAT(halt_exits) },
7926 +- { "halt_wakeup", VCPU_STAT(halt_wakeup) },
7927 +- { "hypercalls", VCPU_STAT(hypercalls) },
7928 +- { "request_irq", VCPU_STAT(request_irq_exits) },
7929 +- { "irq_exits", VCPU_STAT(irq_exits) },
7930 +- { "host_state_reload", VCPU_STAT(host_state_reload) },
7931 +- { "efer_reload", VCPU_STAT(efer_reload) },
7932 +- { "fpu_reload", VCPU_STAT(fpu_reload) },
7933 +- { "insn_emulation", VCPU_STAT(insn_emulation) },
7934 +- { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
7935 +- { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
7936 +- { "mmu_pte_write", VM_STAT(mmu_pte_write) },
7937 +- { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
7938 +- { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
7939 +- { "mmu_flooded", VM_STAT(mmu_flooded) },
7940 +- { "mmu_recycled", VM_STAT(mmu_recycled) },
7941 +- { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
7942 +- { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
7943 +- { "largepages", VM_STAT(lpages) },
7944 ++ { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
7945 ++ { "pf_guest", VCPU_STAT(pf_guest), NULL },
7946 ++ { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
7947 ++ { "invlpg", VCPU_STAT(invlpg), NULL },
7948 ++ { "exits", VCPU_STAT(exits), NULL },
7949 ++ { "io_exits", VCPU_STAT(io_exits), NULL },
7950 ++ { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
7951 ++ { "signal_exits", VCPU_STAT(signal_exits), NULL },
7952 ++ { "irq_window", VCPU_STAT(irq_window_exits), NULL },
7953 ++ { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
7954 ++ { "halt_exits", VCPU_STAT(halt_exits), NULL },
7955 ++ { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
7956 ++ { "hypercalls", VCPU_STAT(hypercalls), NULL },
7957 ++ { "request_irq", VCPU_STAT(request_irq_exits), NULL },
7958 ++ { "irq_exits", VCPU_STAT(irq_exits), NULL },
7959 ++ { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
7960 ++ { "efer_reload", VCPU_STAT(efer_reload), NULL },
7961 ++ { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
7962 ++ { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
7963 ++ { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
7964 ++ { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
7965 ++ { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
7966 ++ { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
7967 ++ { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
7968 ++ { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
7969 ++ { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
7970 ++ { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
7971 ++ { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
7972 ++ { "largepages", VM_STAT(lpages), NULL },
7973 + { NULL }
7974 + };
7975 +
7976 +@@ -1274,7 +1274,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
7977 + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
7978 + struct kvm_interrupt *irq)
7979 + {
7980 +- if (irq->irq < 0 || irq->irq >= 256)
7981 ++ if (irq->irq >= 256)
7982 + return -EINVAL;
7983 + if (irqchip_in_kernel(vcpu->kvm))
7984 + return -ENXIO;
7985 +diff -urNp linux-2.6.27.10/arch/x86/lib/checksum_32.S linux-2.6.27.10/arch/x86/lib/checksum_32.S
7986 +--- linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-07 12:55:34.000000000 -0500
7987 ++++ linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-18 03:38:44.000000000 -0500
7988 +@@ -28,7 +28,8 @@
7989 + #include <linux/linkage.h>
7990 + #include <asm/dwarf2.h>
7991 + #include <asm/errno.h>
7992 +-
7993 ++#include <asm/segment.h>
7994 ++
7995 + /*
7996 + * computes a partial checksum, e.g. for TCP/UDP fragments
7997 + */
7998 +@@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic (
7999 +
8000 + #define ARGBASE 16
8001 + #define FP 12
8002 +-
8003 +-ENTRY(csum_partial_copy_generic)
8004 ++
8005 ++ENTRY(csum_partial_copy_generic_to_user)
8006 + CFI_STARTPROC
8007 ++ pushl $(__USER_DS)
8008 ++ CFI_ADJUST_CFA_OFFSET 4
8009 ++ popl %es
8010 ++ CFI_ADJUST_CFA_OFFSET -4
8011 ++ jmp csum_partial_copy_generic
8012 ++
8013 ++ENTRY(csum_partial_copy_generic_from_user)
8014 ++ pushl $(__USER_DS)
8015 ++ CFI_ADJUST_CFA_OFFSET 4
8016 ++ popl %ds
8017 ++ CFI_ADJUST_CFA_OFFSET -4
8018 ++
8019 ++ENTRY(csum_partial_copy_generic)
8020 + subl $4,%esp
8021 + CFI_ADJUST_CFA_OFFSET 4
8022 + pushl %edi
8023 +@@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic)
8024 + jmp 4f
8025 + SRC(1: movw (%esi), %bx )
8026 + addl $2, %esi
8027 +-DST( movw %bx, (%edi) )
8028 ++DST( movw %bx, %es:(%edi) )
8029 + addl $2, %edi
8030 + addw %bx, %ax
8031 + adcl $0, %eax
8032 +@@ -343,30 +357,30 @@ DST( movw %bx, (%edi) )
8033 + SRC(1: movl (%esi), %ebx )
8034 + SRC( movl 4(%esi), %edx )
8035 + adcl %ebx, %eax
8036 +-DST( movl %ebx, (%edi) )
8037 ++DST( movl %ebx, %es:(%edi) )
8038 + adcl %edx, %eax
8039 +-DST( movl %edx, 4(%edi) )
8040 ++DST( movl %edx, %es:4(%edi) )
8041 +
8042 + SRC( movl 8(%esi), %ebx )
8043 + SRC( movl 12(%esi), %edx )
8044 + adcl %ebx, %eax
8045 +-DST( movl %ebx, 8(%edi) )
8046 ++DST( movl %ebx, %es:8(%edi) )
8047 + adcl %edx, %eax
8048 +-DST( movl %edx, 12(%edi) )
8049 ++DST( movl %edx, %es:12(%edi) )
8050 +
8051 + SRC( movl 16(%esi), %ebx )
8052 + SRC( movl 20(%esi), %edx )
8053 + adcl %ebx, %eax
8054 +-DST( movl %ebx, 16(%edi) )
8055 ++DST( movl %ebx, %es:16(%edi) )
8056 + adcl %edx, %eax
8057 +-DST( movl %edx, 20(%edi) )
8058 ++DST( movl %edx, %es:20(%edi) )
8059 +
8060 + SRC( movl 24(%esi), %ebx )
8061 + SRC( movl 28(%esi), %edx )
8062 + adcl %ebx, %eax
8063 +-DST( movl %ebx, 24(%edi) )
8064 ++DST( movl %ebx, %es:24(%edi) )
8065 + adcl %edx, %eax
8066 +-DST( movl %edx, 28(%edi) )
8067 ++DST( movl %edx, %es:28(%edi) )
8068 +
8069 + lea 32(%esi), %esi
8070 + lea 32(%edi), %edi
8071 +@@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) )
8072 + shrl $2, %edx # This clears CF
8073 + SRC(3: movl (%esi), %ebx )
8074 + adcl %ebx, %eax
8075 +-DST( movl %ebx, (%edi) )
8076 ++DST( movl %ebx, %es:(%edi) )
8077 + lea 4(%esi), %esi
8078 + lea 4(%edi), %edi
8079 + dec %edx
8080 +@@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) )
8081 + jb 5f
8082 + SRC( movw (%esi), %cx )
8083 + leal 2(%esi), %esi
8084 +-DST( movw %cx, (%edi) )
8085 ++DST( movw %cx, %es:(%edi) )
8086 + leal 2(%edi), %edi
8087 + je 6f
8088 + shll $16,%ecx
8089 + SRC(5: movb (%esi), %cl )
8090 +-DST( movb %cl, (%edi) )
8091 ++DST( movb %cl, %es:(%edi) )
8092 + 6: addl %ecx, %eax
8093 + adcl $0, %eax
8094 + 7:
8095 +@@ -408,7 +422,7 @@ DST( movb %cl, (%edi) )
8096 +
8097 + 6001:
8098 + movl ARGBASE+20(%esp), %ebx # src_err_ptr
8099 +- movl $-EFAULT, (%ebx)
8100 ++ movl $-EFAULT, %ss:(%ebx)
8101 +
8102 + # zero the complete destination - computing the rest
8103 + # is too much work
8104 +@@ -421,11 +435,19 @@ DST( movb %cl, (%edi) )
8105 +
8106 + 6002:
8107 + movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8108 +- movl $-EFAULT,(%ebx)
8109 ++ movl $-EFAULT,%ss:(%ebx)
8110 + jmp 5000b
8111 +
8112 + .previous
8113 +
8114 ++ pushl %ss
8115 ++ CFI_ADJUST_CFA_OFFSET 4
8116 ++ popl %ds
8117 ++ CFI_ADJUST_CFA_OFFSET -4
8118 ++ pushl %ss
8119 ++ CFI_ADJUST_CFA_OFFSET 4
8120 ++ popl %es
8121 ++ CFI_ADJUST_CFA_OFFSET -4
8122 + popl %ebx
8123 + CFI_ADJUST_CFA_OFFSET -4
8124 + CFI_RESTORE ebx
8125 +@@ -439,26 +461,41 @@ DST( movb %cl, (%edi) )
8126 + CFI_ADJUST_CFA_OFFSET -4
8127 + ret
8128 + CFI_ENDPROC
8129 +-ENDPROC(csum_partial_copy_generic)
8130 ++ENDPROC(csum_partial_copy_generic_to_user)
8131 +
8132 + #else
8133 +
8134 + /* Version for PentiumII/PPro */
8135 +
8136 + #define ROUND1(x) \
8137 ++ nop; nop; nop; \
8138 + SRC(movl x(%esi), %ebx ) ; \
8139 + addl %ebx, %eax ; \
8140 +- DST(movl %ebx, x(%edi) ) ;
8141 ++ DST(movl %ebx, %es:x(%edi)) ;
8142 +
8143 + #define ROUND(x) \
8144 ++ nop; nop; nop; \
8145 + SRC(movl x(%esi), %ebx ) ; \
8146 + adcl %ebx, %eax ; \
8147 +- DST(movl %ebx, x(%edi) ) ;
8148 ++ DST(movl %ebx, %es:x(%edi)) ;
8149 +
8150 + #define ARGBASE 12
8151 +-
8152 +-ENTRY(csum_partial_copy_generic)
8153 ++
8154 ++ENTRY(csum_partial_copy_generic_to_user)
8155 + CFI_STARTPROC
8156 ++ pushl $(__USER_DS)
8157 ++ CFI_ADJUST_CFA_OFFSET 4
8158 ++ popl %es
8159 ++ CFI_ADJUST_CFA_OFFSET -4
8160 ++ jmp csum_partial_copy_generic
8161 ++
8162 ++ENTRY(csum_partial_copy_generic_from_user)
8163 ++ pushl $(__USER_DS)
8164 ++ CFI_ADJUST_CFA_OFFSET 4
8165 ++ popl %ds
8166 ++ CFI_ADJUST_CFA_OFFSET -4
8167 ++
8168 ++ENTRY(csum_partial_copy_generic)
8169 + pushl %ebx
8170 + CFI_ADJUST_CFA_OFFSET 4
8171 + CFI_REL_OFFSET ebx, 0
8172 +@@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic)
8173 + subl %ebx, %edi
8174 + lea -1(%esi),%edx
8175 + andl $-32,%edx
8176 +- lea 3f(%ebx,%ebx), %ebx
8177 ++ lea 3f(%ebx,%ebx,2), %ebx
8178 + testl %esi, %esi
8179 + jmp *%ebx
8180 + 1: addl $64,%esi
8181 +@@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic)
8182 + jb 5f
8183 + SRC( movw (%esi), %dx )
8184 + leal 2(%esi), %esi
8185 +-DST( movw %dx, (%edi) )
8186 ++DST( movw %dx, %es:(%edi) )
8187 + leal 2(%edi), %edi
8188 + je 6f
8189 + shll $16,%edx
8190 + 5:
8191 + SRC( movb (%esi), %dl )
8192 +-DST( movb %dl, (%edi) )
8193 ++DST( movb %dl, %es:(%edi) )
8194 + 6: addl %edx, %eax
8195 + adcl $0, %eax
8196 + 7:
8197 + .section .fixup, "ax"
8198 + 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
8199 +- movl $-EFAULT, (%ebx)
8200 ++ movl $-EFAULT, %ss:(%ebx)
8201 + # zero the complete destination (computing the rest is too much work)
8202 + movl ARGBASE+8(%esp),%edi # dst
8203 + movl ARGBASE+12(%esp),%ecx # len
8204 +@@ -523,10 +560,18 @@ DST( movb %dl, (%edi) )
8205 + rep; stosb
8206 + jmp 7b
8207 + 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8208 +- movl $-EFAULT, (%ebx)
8209 ++ movl $-EFAULT, %ss:(%ebx)
8210 + jmp 7b
8211 + .previous
8212 +
8213 ++ pushl %ss
8214 ++ CFI_ADJUST_CFA_OFFSET 4
8215 ++ popl %ds
8216 ++ CFI_ADJUST_CFA_OFFSET -4
8217 ++ pushl %ss
8218 ++ CFI_ADJUST_CFA_OFFSET 4
8219 ++ popl %es
8220 ++ CFI_ADJUST_CFA_OFFSET -4
8221 + popl %esi
8222 + CFI_ADJUST_CFA_OFFSET -4
8223 + CFI_RESTORE esi
8224 +@@ -538,7 +583,7 @@ DST( movb %dl, (%edi) )
8225 + CFI_RESTORE ebx
8226 + ret
8227 + CFI_ENDPROC
8228 +-ENDPROC(csum_partial_copy_generic)
8229 ++ENDPROC(csum_partial_copy_generic_to_user)
8230 +
8231 + #undef ROUND
8232 + #undef ROUND1
8233 +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
8234 +--- linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-07 12:55:34.000000000 -0500
8235 ++++ linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-18 03:38:44.000000000 -0500
8236 +@@ -44,7 +44,7 @@ ENDPROC(clear_page)
8237 +
8238 + #include <asm/cpufeature.h>
8239 +
8240 +- .section .altinstr_replacement,"ax"
8241 ++ .section .altinstr_replacement,"a"
8242 + 1: .byte 0xeb /* jmp <disp8> */
8243 + .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
8244 + 2:
8245 +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
8246 +--- linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-07 12:55:34.000000000 -0500
8247 ++++ linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-18 03:38:44.000000000 -0500
8248 +@@ -104,7 +104,7 @@ ENDPROC(copy_page)
8249 +
8250 + #include <asm/cpufeature.h>
8251 +
8252 +- .section .altinstr_replacement,"ax"
8253 ++ .section .altinstr_replacement,"a"
8254 + 1: .byte 0xeb /* jmp <disp8> */
8255 + .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
8256 + 2:
8257 +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
8258 +--- linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-07 12:55:34.000000000 -0500
8259 ++++ linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-18 03:38:44.000000000 -0500
8260 +@@ -21,7 +21,7 @@
8261 + .byte 0xe9 /* 32bit jump */
8262 + .long \orig-1f /* by default jump to orig */
8263 + 1:
8264 +- .section .altinstr_replacement,"ax"
8265 ++ .section .altinstr_replacement,"a"
8266 + 2: .byte 0xe9 /* near jump with 32bit immediate */
8267 + .long \alt-1b /* offset */ /* or alternatively to alt */
8268 + .previous
8269 +@@ -106,6 +106,8 @@ ENDPROC(__copy_from_user_inatomic)
8270 + ENTRY(bad_from_user)
8271 + bad_from_user:
8272 + CFI_STARTPROC
8273 ++ testl %edx,%edx
8274 ++ js bad_to_user
8275 + movl %edx,%ecx
8276 + xorl %eax,%eax
8277 + rep
8278 +diff -urNp linux-2.6.27.10/arch/x86/lib/getuser.S linux-2.6.27.10/arch/x86/lib/getuser.S
8279 +--- linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-07 12:55:34.000000000 -0500
8280 ++++ linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-18 03:38:44.000000000 -0500
8281 +@@ -33,6 +33,7 @@
8282 + #include <asm/asm-offsets.h>
8283 + #include <asm/thread_info.h>
8284 + #include <asm/asm.h>
8285 ++#include <asm/segment.h>
8286 +
8287 + .text
8288 + ENTRY(__get_user_1)
8289 +@@ -40,7 +41,19 @@ ENTRY(__get_user_1)
8290 + GET_THREAD_INFO(%_ASM_DX)
8291 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8292 + jae bad_get_user
8293 ++
8294 ++#ifdef CONFIG_X86_32
8295 ++ pushl $(__USER_DS)
8296 ++ popl %ds
8297 ++#endif
8298 ++
8299 + 1: movzb (%_ASM_AX),%edx
8300 ++
8301 ++#ifdef CONFIG_X86_32
8302 ++ pushl %ss
8303 ++ pop %ds
8304 ++#endif
8305 ++
8306 + xor %eax,%eax
8307 + ret
8308 + CFI_ENDPROC
8309 +@@ -53,7 +66,19 @@ ENTRY(__get_user_2)
8310 + GET_THREAD_INFO(%_ASM_DX)
8311 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8312 + jae bad_get_user
8313 ++
8314 ++#ifdef CONFIG_X86_32
8315 ++ pushl $(__USER_DS)
8316 ++ popl %ds
8317 ++#endif
8318 ++
8319 + 2: movzwl -1(%_ASM_AX),%edx
8320 ++
8321 ++#ifdef CONFIG_X86_32
8322 ++ pushl %ss
8323 ++ pop %ds
8324 ++#endif
8325 ++
8326 + xor %eax,%eax
8327 + ret
8328 + CFI_ENDPROC
8329 +@@ -66,7 +91,19 @@ ENTRY(__get_user_4)
8330 + GET_THREAD_INFO(%_ASM_DX)
8331 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8332 + jae bad_get_user
8333 ++
8334 ++#ifdef CONFIG_X86_32
8335 ++ pushl $(__USER_DS)
8336 ++ popl %ds
8337 ++#endif
8338 ++
8339 + 3: mov -3(%_ASM_AX),%edx
8340 ++
8341 ++#ifdef CONFIG_X86_32
8342 ++ pushl %ss
8343 ++ pop %ds
8344 ++#endif
8345 ++
8346 + xor %eax,%eax
8347 + ret
8348 + CFI_ENDPROC
8349 +@@ -89,6 +126,12 @@ ENDPROC(__get_user_8)
8350 +
8351 + bad_get_user:
8352 + CFI_STARTPROC
8353 ++
8354 ++#ifdef CONFIG_X86_32
8355 ++ pushl %ss
8356 ++ pop %ds
8357 ++#endif
8358 ++
8359 + xor %edx,%edx
8360 + mov $(-EFAULT),%_ASM_AX
8361 + ret
8362 +diff -urNp linux-2.6.27.10/arch/x86/lib/memcpy_64.S linux-2.6.27.10/arch/x86/lib/memcpy_64.S
8363 +--- linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-07 12:55:34.000000000 -0500
8364 ++++ linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-18 03:38:44.000000000 -0500
8365 +@@ -114,7 +114,7 @@ ENDPROC(__memcpy)
8366 + /* Some CPUs run faster using the string copy instructions.
8367 + It is also a lot simpler. Use this when possible */
8368 +
8369 +- .section .altinstr_replacement,"ax"
8370 ++ .section .altinstr_replacement,"a"
8371 + 1: .byte 0xeb /* jmp <disp8> */
8372 + .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
8373 + 2:
8374 +diff -urNp linux-2.6.27.10/arch/x86/lib/memset_64.S linux-2.6.27.10/arch/x86/lib/memset_64.S
8375 +--- linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-07 12:55:34.000000000 -0500
8376 ++++ linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-18 03:38:44.000000000 -0500
8377 +@@ -118,7 +118,7 @@ ENDPROC(__memset)
8378 +
8379 + #include <asm/cpufeature.h>
8380 +
8381 +- .section .altinstr_replacement,"ax"
8382 ++ .section .altinstr_replacement,"a"
8383 + 1: .byte 0xeb /* jmp <disp8> */
8384 + .byte (memset_c - memset) - (2f - 1b) /* offset */
8385 + 2:
8386 +diff -urNp linux-2.6.27.10/arch/x86/lib/mmx_32.c linux-2.6.27.10/arch/x86/lib/mmx_32.c
8387 +--- linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-07 12:55:34.000000000 -0500
8388 ++++ linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-18 03:38:44.000000000 -0500
8389 +@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
8390 + {
8391 + void *p;
8392 + int i;
8393 ++ unsigned long cr0;
8394 +
8395 + if (unlikely(in_interrupt()))
8396 + return __memcpy(to, from, len);
8397 +@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
8398 + kernel_fpu_begin();
8399 +
8400 + __asm__ __volatile__ (
8401 +- "1: prefetch (%0)\n" /* This set is 28 bytes */
8402 +- " prefetch 64(%0)\n"
8403 +- " prefetch 128(%0)\n"
8404 +- " prefetch 192(%0)\n"
8405 +- " prefetch 256(%0)\n"
8406 ++ "1: prefetch (%1)\n" /* This set is 28 bytes */
8407 ++ " prefetch 64(%1)\n"
8408 ++ " prefetch 128(%1)\n"
8409 ++ " prefetch 192(%1)\n"
8410 ++ " prefetch 256(%1)\n"
8411 + "2: \n"
8412 + ".section .fixup, \"ax\"\n"
8413 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8414 ++ "3: \n"
8415 ++
8416 ++#ifdef CONFIG_PAX_KERNEXEC
8417 ++ " movl %%cr0, %0\n"
8418 ++ " movl %0, %%eax\n"
8419 ++ " andl $0xFFFEFFFF, %%eax\n"
8420 ++ " movl %%eax, %%cr0\n"
8421 ++#endif
8422 ++
8423 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8424 ++
8425 ++#ifdef CONFIG_PAX_KERNEXEC
8426 ++ " movl %0, %%cr0\n"
8427 ++#endif
8428 ++
8429 + " jmp 2b\n"
8430 + ".previous\n"
8431 + _ASM_EXTABLE(1b, 3b)
8432 +- : : "r" (from));
8433 ++ : "=&r" (cr0) : "r" (from) : "ax");
8434 +
8435 + for ( ; i > 5; i--) {
8436 + __asm__ __volatile__ (
8437 +- "1: prefetch 320(%0)\n"
8438 +- "2: movq (%0), %%mm0\n"
8439 +- " movq 8(%0), %%mm1\n"
8440 +- " movq 16(%0), %%mm2\n"
8441 +- " movq 24(%0), %%mm3\n"
8442 +- " movq %%mm0, (%1)\n"
8443 +- " movq %%mm1, 8(%1)\n"
8444 +- " movq %%mm2, 16(%1)\n"
8445 +- " movq %%mm3, 24(%1)\n"
8446 +- " movq 32(%0), %%mm0\n"
8447 +- " movq 40(%0), %%mm1\n"
8448 +- " movq 48(%0), %%mm2\n"
8449 +- " movq 56(%0), %%mm3\n"
8450 +- " movq %%mm0, 32(%1)\n"
8451 +- " movq %%mm1, 40(%1)\n"
8452 +- " movq %%mm2, 48(%1)\n"
8453 +- " movq %%mm3, 56(%1)\n"
8454 ++ "1: prefetch 320(%1)\n"
8455 ++ "2: movq (%1), %%mm0\n"
8456 ++ " movq 8(%1), %%mm1\n"
8457 ++ " movq 16(%1), %%mm2\n"
8458 ++ " movq 24(%1), %%mm3\n"
8459 ++ " movq %%mm0, (%2)\n"
8460 ++ " movq %%mm1, 8(%2)\n"
8461 ++ " movq %%mm2, 16(%2)\n"
8462 ++ " movq %%mm3, 24(%2)\n"
8463 ++ " movq 32(%1), %%mm0\n"
8464 ++ " movq 40(%1), %%mm1\n"
8465 ++ " movq 48(%1), %%mm2\n"
8466 ++ " movq 56(%1), %%mm3\n"
8467 ++ " movq %%mm0, 32(%2)\n"
8468 ++ " movq %%mm1, 40(%2)\n"
8469 ++ " movq %%mm2, 48(%2)\n"
8470 ++ " movq %%mm3, 56(%2)\n"
8471 + ".section .fixup, \"ax\"\n"
8472 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8473 ++ "3:\n"
8474 ++
8475 ++#ifdef CONFIG_PAX_KERNEXEC
8476 ++ " movl %%cr0, %0\n"
8477 ++ " movl %0, %%eax\n"
8478 ++ " andl $0xFFFEFFFF, %%eax\n"
8479 ++ " movl %%eax, %%cr0\n"
8480 ++#endif
8481 ++
8482 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8483 ++
8484 ++#ifdef CONFIG_PAX_KERNEXEC
8485 ++ " movl %0, %%cr0\n"
8486 ++#endif
8487 ++
8488 + " jmp 2b\n"
8489 + ".previous\n"
8490 + _ASM_EXTABLE(1b, 3b)
8491 +- : : "r" (from), "r" (to) : "memory");
8492 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8493 +
8494 + from += 64;
8495 + to += 64;
8496 +@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
8497 + static void fast_copy_page(void *to, void *from)
8498 + {
8499 + int i;
8500 ++ unsigned long cr0;
8501 +
8502 + kernel_fpu_begin();
8503 +
8504 +@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
8505 + * but that is for later. -AV
8506 + */
8507 + __asm__ __volatile__(
8508 +- "1: prefetch (%0)\n"
8509 +- " prefetch 64(%0)\n"
8510 +- " prefetch 128(%0)\n"
8511 +- " prefetch 192(%0)\n"
8512 +- " prefetch 256(%0)\n"
8513 ++ "1: prefetch (%1)\n"
8514 ++ " prefetch 64(%1)\n"
8515 ++ " prefetch 128(%1)\n"
8516 ++ " prefetch 192(%1)\n"
8517 ++ " prefetch 256(%1)\n"
8518 + "2: \n"
8519 + ".section .fixup, \"ax\"\n"
8520 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8521 ++ "3: \n"
8522 ++
8523 ++#ifdef CONFIG_PAX_KERNEXEC
8524 ++ " movl %%cr0, %0\n"
8525 ++ " movl %0, %%eax\n"
8526 ++ " andl $0xFFFEFFFF, %%eax\n"
8527 ++ " movl %%eax, %%cr0\n"
8528 ++#endif
8529 ++
8530 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8531 ++
8532 ++#ifdef CONFIG_PAX_KERNEXEC
8533 ++ " movl %0, %%cr0\n"
8534 ++#endif
8535 ++
8536 + " jmp 2b\n"
8537 + ".previous\n"
8538 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8539 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8540 +
8541 + for (i = 0; i < (4096-320)/64; i++) {
8542 + __asm__ __volatile__ (
8543 +- "1: prefetch 320(%0)\n"
8544 +- "2: movq (%0), %%mm0\n"
8545 +- " movntq %%mm0, (%1)\n"
8546 +- " movq 8(%0), %%mm1\n"
8547 +- " movntq %%mm1, 8(%1)\n"
8548 +- " movq 16(%0), %%mm2\n"
8549 +- " movntq %%mm2, 16(%1)\n"
8550 +- " movq 24(%0), %%mm3\n"
8551 +- " movntq %%mm3, 24(%1)\n"
8552 +- " movq 32(%0), %%mm4\n"
8553 +- " movntq %%mm4, 32(%1)\n"
8554 +- " movq 40(%0), %%mm5\n"
8555 +- " movntq %%mm5, 40(%1)\n"
8556 +- " movq 48(%0), %%mm6\n"
8557 +- " movntq %%mm6, 48(%1)\n"
8558 +- " movq 56(%0), %%mm7\n"
8559 +- " movntq %%mm7, 56(%1)\n"
8560 ++ "1: prefetch 320(%1)\n"
8561 ++ "2: movq (%1), %%mm0\n"
8562 ++ " movntq %%mm0, (%2)\n"
8563 ++ " movq 8(%1), %%mm1\n"
8564 ++ " movntq %%mm1, 8(%2)\n"
8565 ++ " movq 16(%1), %%mm2\n"
8566 ++ " movntq %%mm2, 16(%2)\n"
8567 ++ " movq 24(%1), %%mm3\n"
8568 ++ " movntq %%mm3, 24(%2)\n"
8569 ++ " movq 32(%1), %%mm4\n"
8570 ++ " movntq %%mm4, 32(%2)\n"
8571 ++ " movq 40(%1), %%mm5\n"
8572 ++ " movntq %%mm5, 40(%2)\n"
8573 ++ " movq 48(%1), %%mm6\n"
8574 ++ " movntq %%mm6, 48(%2)\n"
8575 ++ " movq 56(%1), %%mm7\n"
8576 ++ " movntq %%mm7, 56(%2)\n"
8577 + ".section .fixup, \"ax\"\n"
8578 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8579 ++ "3:\n"
8580 ++
8581 ++#ifdef CONFIG_PAX_KERNEXEC
8582 ++ " movl %%cr0, %0\n"
8583 ++ " movl %0, %%eax\n"
8584 ++ " andl $0xFFFEFFFF, %%eax\n"
8585 ++ " movl %%eax, %%cr0\n"
8586 ++#endif
8587 ++
8588 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8589 ++
8590 ++#ifdef CONFIG_PAX_KERNEXEC
8591 ++ " movl %0, %%cr0\n"
8592 ++#endif
8593 ++
8594 + " jmp 2b\n"
8595 + ".previous\n"
8596 +- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
8597 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8598 +
8599 + from += 64;
8600 + to += 64;
8601 +@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
8602 + static void fast_copy_page(void *to, void *from)
8603 + {
8604 + int i;
8605 ++ unsigned long cr0;
8606 +
8607 + kernel_fpu_begin();
8608 +
8609 + __asm__ __volatile__ (
8610 +- "1: prefetch (%0)\n"
8611 +- " prefetch 64(%0)\n"
8612 +- " prefetch 128(%0)\n"
8613 +- " prefetch 192(%0)\n"
8614 +- " prefetch 256(%0)\n"
8615 ++ "1: prefetch (%1)\n"
8616 ++ " prefetch 64(%1)\n"
8617 ++ " prefetch 128(%1)\n"
8618 ++ " prefetch 192(%1)\n"
8619 ++ " prefetch 256(%1)\n"
8620 + "2: \n"
8621 + ".section .fixup, \"ax\"\n"
8622 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8623 ++ "3: \n"
8624 ++
8625 ++#ifdef CONFIG_PAX_KERNEXEC
8626 ++ " movl %%cr0, %0\n"
8627 ++ " movl %0, %%eax\n"
8628 ++ " andl $0xFFFEFFFF, %%eax\n"
8629 ++ " movl %%eax, %%cr0\n"
8630 ++#endif
8631 ++
8632 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8633 ++
8634 ++#ifdef CONFIG_PAX_KERNEXEC
8635 ++ " movl %0, %%cr0\n"
8636 ++#endif
8637 ++
8638 + " jmp 2b\n"
8639 + ".previous\n"
8640 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8641 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8642 +
8643 + for (i = 0; i < 4096/64; i++) {
8644 + __asm__ __volatile__ (
8645 +- "1: prefetch 320(%0)\n"
8646 +- "2: movq (%0), %%mm0\n"
8647 +- " movq 8(%0), %%mm1\n"
8648 +- " movq 16(%0), %%mm2\n"
8649 +- " movq 24(%0), %%mm3\n"
8650 +- " movq %%mm0, (%1)\n"
8651 +- " movq %%mm1, 8(%1)\n"
8652 +- " movq %%mm2, 16(%1)\n"
8653 +- " movq %%mm3, 24(%1)\n"
8654 +- " movq 32(%0), %%mm0\n"
8655 +- " movq 40(%0), %%mm1\n"
8656 +- " movq 48(%0), %%mm2\n"
8657 +- " movq 56(%0), %%mm3\n"
8658 +- " movq %%mm0, 32(%1)\n"
8659 +- " movq %%mm1, 40(%1)\n"
8660 +- " movq %%mm2, 48(%1)\n"
8661 +- " movq %%mm3, 56(%1)\n"
8662 ++ "1: prefetch 320(%1)\n"
8663 ++ "2: movq (%1), %%mm0\n"
8664 ++ " movq 8(%1), %%mm1\n"
8665 ++ " movq 16(%1), %%mm2\n"
8666 ++ " movq 24(%1), %%mm3\n"
8667 ++ " movq %%mm0, (%2)\n"
8668 ++ " movq %%mm1, 8(%2)\n"
8669 ++ " movq %%mm2, 16(%2)\n"
8670 ++ " movq %%mm3, 24(%2)\n"
8671 ++ " movq 32(%1), %%mm0\n"
8672 ++ " movq 40(%1), %%mm1\n"
8673 ++ " movq 48(%1), %%mm2\n"
8674 ++ " movq 56(%1), %%mm3\n"
8675 ++ " movq %%mm0, 32(%2)\n"
8676 ++ " movq %%mm1, 40(%2)\n"
8677 ++ " movq %%mm2, 48(%2)\n"
8678 ++ " movq %%mm3, 56(%2)\n"
8679 + ".section .fixup, \"ax\"\n"
8680 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8681 ++ "3:\n"
8682 ++
8683 ++#ifdef CONFIG_PAX_KERNEXEC
8684 ++ " movl %%cr0, %0\n"
8685 ++ " movl %0, %%eax\n"
8686 ++ " andl $0xFFFEFFFF, %%eax\n"
8687 ++ " movl %%eax, %%cr0\n"
8688 ++#endif
8689 ++
8690 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8691 ++
8692 ++#ifdef CONFIG_PAX_KERNEXEC
8693 ++ " movl %0, %%cr0\n"
8694 ++#endif
8695 ++
8696 + " jmp 2b\n"
8697 + ".previous\n"
8698 + _ASM_EXTABLE(1b, 3b)
8699 +- : : "r" (from), "r" (to) : "memory");
8700 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8701 +
8702 + from += 64;
8703 + to += 64;
8704 +diff -urNp linux-2.6.27.10/arch/x86/lib/putuser.S linux-2.6.27.10/arch/x86/lib/putuser.S
8705 +--- linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-07 12:55:34.000000000 -0500
8706 ++++ linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-18 03:38:44.000000000 -0500
8707 +@@ -15,6 +15,7 @@
8708 + #include <asm/thread_info.h>
8709 + #include <asm/errno.h>
8710 + #include <asm/asm.h>
8711 ++#include <asm/segment.h>
8712 +
8713 +
8714 + /*
8715 +@@ -39,7 +40,19 @@ ENTRY(__put_user_1)
8716 + ENTER
8717 + cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
8718 + jae bad_put_user
8719 ++
8720 ++#ifdef CONFIG_X86_32
8721 ++ pushl $(__USER_DS)
8722 ++ popl %ds
8723 ++#endif
8724 ++
8725 + 1: movb %al,(%_ASM_CX)
8726 ++
8727 ++#ifdef CONFIG_X86_32
8728 ++ pushl %ss
8729 ++ popl %ds
8730 ++#endif
8731 ++
8732 + xor %eax,%eax
8733 + EXIT
8734 + ENDPROC(__put_user_1)
8735 +@@ -50,7 +63,19 @@ ENTRY(__put_user_2)
8736 + sub $1,%_ASM_BX
8737 + cmp %_ASM_BX,%_ASM_CX
8738 + jae bad_put_user
8739 ++
8740 ++#ifdef CONFIG_X86_32
8741 ++ pushl $(__USER_DS)
8742 ++ popl %ds
8743 ++#endif
8744 ++
8745 + 2: movw %ax,(%_ASM_CX)
8746 ++
8747 ++#ifdef CONFIG_X86_32
8748 ++ pushl %ss
8749 ++ popl %ds
8750 ++#endif
8751 ++
8752 + xor %eax,%eax
8753 + EXIT
8754 + ENDPROC(__put_user_2)
8755 +@@ -61,7 +86,19 @@ ENTRY(__put_user_4)
8756 + sub $3,%_ASM_BX
8757 + cmp %_ASM_BX,%_ASM_CX
8758 + jae bad_put_user
8759 ++
8760 ++#ifdef CONFIG_X86_32
8761 ++ pushl $(__USER_DS)
8762 ++ popl %ds
8763 ++#endif
8764 ++
8765 + 3: movl %eax,(%_ASM_CX)
8766 ++
8767 ++#ifdef CONFIG_X86_32
8768 ++ pushl %ss
8769 ++ popl %ds
8770 ++#endif
8771 ++
8772 + xor %eax,%eax
8773 + EXIT
8774 + ENDPROC(__put_user_4)
8775 +@@ -72,16 +109,34 @@ ENTRY(__put_user_8)
8776 + sub $7,%_ASM_BX
8777 + cmp %_ASM_BX,%_ASM_CX
8778 + jae bad_put_user
8779 ++
8780 ++#ifdef CONFIG_X86_32
8781 ++ pushl $(__USER_DS)
8782 ++ popl %ds
8783 ++#endif
8784 ++
8785 + 4: mov %_ASM_AX,(%_ASM_CX)
8786 + #ifdef CONFIG_X86_32
8787 + 5: movl %edx,4(%_ASM_CX)
8788 + #endif
8789 ++
8790 ++#ifdef CONFIG_X86_32
8791 ++ pushl %ss
8792 ++ popl %ds
8793 ++#endif
8794 ++
8795 + xor %eax,%eax
8796 + EXIT
8797 + ENDPROC(__put_user_8)
8798 +
8799 + bad_put_user:
8800 + CFI_STARTPROC
8801 ++
8802 ++#ifdef CONFIG_X86_32
8803 ++ pushl %ss
8804 ++ popl %ds
8805 ++#endif
8806 ++
8807 + movl $-EFAULT,%eax
8808 + EXIT
8809 + END(bad_put_user)
8810 +diff -urNp linux-2.6.27.10/arch/x86/lib/usercopy_32.c linux-2.6.27.10/arch/x86/lib/usercopy_32.c
8811 +--- linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-07 12:55:34.000000000 -0500
8812 ++++ linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-18 03:38:44.000000000 -0500
8813 +@@ -29,31 +29,38 @@ static inline int __movsl_is_ok(unsigned
8814 + * Copy a null terminated string from userspace.
8815 + */
8816 +
8817 +-#define __do_strncpy_from_user(dst, src, count, res) \
8818 +-do { \
8819 +- int __d0, __d1, __d2; \
8820 +- might_sleep(); \
8821 +- __asm__ __volatile__( \
8822 +- " testl %1,%1\n" \
8823 +- " jz 2f\n" \
8824 +- "0: lodsb\n" \
8825 +- " stosb\n" \
8826 +- " testb %%al,%%al\n" \
8827 +- " jz 1f\n" \
8828 +- " decl %1\n" \
8829 +- " jnz 0b\n" \
8830 +- "1: subl %1,%0\n" \
8831 +- "2:\n" \
8832 +- ".section .fixup,\"ax\"\n" \
8833 +- "3: movl %5,%0\n" \
8834 +- " jmp 2b\n" \
8835 +- ".previous\n" \
8836 +- _ASM_EXTABLE(0b,3b) \
8837 +- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
8838 +- "=&D" (__d2) \
8839 +- : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
8840 +- : "memory"); \
8841 +-} while (0)
8842 ++static long __do_strncpy_from_user(char *dst, const char __user *src, long count)
8843 ++{
8844 ++ int __d0, __d1, __d2;
8845 ++ long res = -EFAULT;
8846 ++
8847 ++ might_sleep();
8848 ++ __asm__ __volatile__(
8849 ++ " movw %w10,%%ds\n"
8850 ++ " testl %1,%1\n"
8851 ++ " jz 2f\n"
8852 ++ "0: lodsb\n"
8853 ++ " stosb\n"
8854 ++ " testb %%al,%%al\n"
8855 ++ " jz 1f\n"
8856 ++ " decl %1\n"
8857 ++ " jnz 0b\n"
8858 ++ "1: subl %1,%0\n"
8859 ++ "2:\n"
8860 ++ " pushl %%ss\n"
8861 ++ " popl %%ds\n"
8862 ++ ".section .fixup,\"ax\"\n"
8863 ++ "3: movl %5,%0\n"
8864 ++ " jmp 2b\n"
8865 ++ ".previous\n"
8866 ++ _ASM_EXTABLE(0b,3b)
8867 ++ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),
8868 ++ "=&D" (__d2)
8869 ++ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst),
8870 ++ "r"(__USER_DS)
8871 ++ : "memory");
8872 ++ return res;
8873 ++}
8874 +
8875 + /**
8876 + * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
8877 +@@ -78,9 +85,7 @@ do { \
8878 + long
8879 + __strncpy_from_user(char *dst, const char __user *src, long count)
8880 + {
8881 +- long res;
8882 +- __do_strncpy_from_user(dst, src, count, res);
8883 +- return res;
8884 ++ return __do_strncpy_from_user(dst, src, count);
8885 + }
8886 + EXPORT_SYMBOL(__strncpy_from_user);
8887 +
8888 +@@ -107,7 +112,7 @@ strncpy_from_user(char *dst, const char
8889 + {
8890 + long res = -EFAULT;
8891 + if (access_ok(VERIFY_READ, src, 1))
8892 +- __do_strncpy_from_user(dst, src, count, res);
8893 ++ res = __do_strncpy_from_user(dst, src, count);
8894 + return res;
8895 + }
8896 + EXPORT_SYMBOL(strncpy_from_user);
8897 +@@ -116,24 +121,30 @@ EXPORT_SYMBOL(strncpy_from_user);
8898 + * Zero Userspace
8899 + */
8900 +
8901 +-#define __do_clear_user(addr,size) \
8902 +-do { \
8903 +- int __d0; \
8904 +- might_sleep(); \
8905 +- __asm__ __volatile__( \
8906 +- "0: rep; stosl\n" \
8907 +- " movl %2,%0\n" \
8908 +- "1: rep; stosb\n" \
8909 +- "2:\n" \
8910 +- ".section .fixup,\"ax\"\n" \
8911 +- "3: lea 0(%2,%0,4),%0\n" \
8912 +- " jmp 2b\n" \
8913 +- ".previous\n" \
8914 +- _ASM_EXTABLE(0b,3b) \
8915 +- _ASM_EXTABLE(1b,2b) \
8916 +- : "=&c"(size), "=&D" (__d0) \
8917 +- : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
8918 +-} while (0)
8919 ++static unsigned long __do_clear_user(void __user *addr, unsigned long size)
8920 ++{
8921 ++ int __d0;
8922 ++
8923 ++ might_sleep();
8924 ++ __asm__ __volatile__(
8925 ++ " movw %w6,%%es\n"
8926 ++ "0: rep; stosl\n"
8927 ++ " movl %2,%0\n"
8928 ++ "1: rep; stosb\n"
8929 ++ "2:\n"
8930 ++ " pushl %%ss\n"
8931 ++ " popl %%es\n"
8932 ++ ".section .fixup,\"ax\"\n"
8933 ++ "3: lea 0(%2,%0,4),%0\n"
8934 ++ " jmp 2b\n"
8935 ++ ".previous\n"
8936 ++ _ASM_EXTABLE(0b,3b)
8937 ++ _ASM_EXTABLE(1b,2b)
8938 ++ : "=&c"(size), "=&D" (__d0)
8939 ++ : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0),
8940 ++ "r"(__USER_DS));
8941 ++ return size;
8942 ++}
8943 +
8944 + /**
8945 + * clear_user: - Zero a block of memory in user space.
8946 +@@ -150,7 +161,7 @@ clear_user(void __user *to, unsigned lon
8947 + {
8948 + might_sleep();
8949 + if (access_ok(VERIFY_WRITE, to, n))
8950 +- __do_clear_user(to, n);
8951 ++ n = __do_clear_user(to, n);
8952 + return n;
8953 + }
8954 + EXPORT_SYMBOL(clear_user);
8955 +@@ -169,8 +180,7 @@ EXPORT_SYMBOL(clear_user);
8956 + unsigned long
8957 + __clear_user(void __user *to, unsigned long n)
8958 + {
8959 +- __do_clear_user(to, n);
8960 +- return n;
8961 ++ return __do_clear_user(to, n);
8962 + }
8963 + EXPORT_SYMBOL(__clear_user);
8964 +
8965 +@@ -193,14 +203,17 @@ long strnlen_user(const char __user *s,
8966 + might_sleep();
8967 +
8968 + __asm__ __volatile__(
8969 ++ " movw %w8,%%es\n"
8970 + " testl %0, %0\n"
8971 + " jz 3f\n"
8972 +- " andl %0,%%ecx\n"
8973 ++ " movl %0,%%ecx\n"
8974 + "0: repne; scasb\n"
8975 + " setne %%al\n"
8976 + " subl %%ecx,%0\n"
8977 + " addl %0,%%eax\n"
8978 + "1:\n"
8979 ++ " pushl %%ss\n"
8980 ++ " popl %%es\n"
8981 + ".section .fixup,\"ax\"\n"
8982 + "2: xorl %%eax,%%eax\n"
8983 + " jmp 1b\n"
8984 +@@ -212,7 +225,7 @@ long strnlen_user(const char __user *s,
8985 + " .long 0b,2b\n"
8986 + ".previous"
8987 + :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
8988 +- :"0" (n), "1" (s), "2" (0), "3" (mask)
8989 ++ :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS)
8990 + :"cc");
8991 + return res & mask;
8992 + }
8993 +@@ -220,10 +233,11 @@ EXPORT_SYMBOL(strnlen_user);
8994 +
8995 + #ifdef CONFIG_X86_INTEL_USERCOPY
8996 + static unsigned long
8997 +-__copy_user_intel(void __user *to, const void *from, unsigned long size)
8998 ++__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
8999 + {
9000 + int d0, d1;
9001 + __asm__ __volatile__(
9002 ++ " movw %w6, %%es\n"
9003 + " .align 2,0x90\n"
9004 + "1: movl 32(%4), %%eax\n"
9005 + " cmpl $67, %0\n"
9006 +@@ -232,36 +246,36 @@ __copy_user_intel(void __user *to, const
9007 + " .align 2,0x90\n"
9008 + "3: movl 0(%4), %%eax\n"
9009 + "4: movl 4(%4), %%edx\n"
9010 +- "5: movl %%eax, 0(%3)\n"
9011 +- "6: movl %%edx, 4(%3)\n"
9012 ++ "5: movl %%eax, %%es:0(%3)\n"
9013 ++ "6: movl %%edx, %%es:4(%3)\n"
9014 + "7: movl 8(%4), %%eax\n"
9015 + "8: movl 12(%4),%%edx\n"
9016 +- "9: movl %%eax, 8(%3)\n"
9017 +- "10: movl %%edx, 12(%3)\n"
9018 ++ "9: movl %%eax, %%es:8(%3)\n"
9019 ++ "10: movl %%edx, %%es:12(%3)\n"
9020 + "11: movl 16(%4), %%eax\n"
9021 + "12: movl 20(%4), %%edx\n"
9022 +- "13: movl %%eax, 16(%3)\n"
9023 +- "14: movl %%edx, 20(%3)\n"
9024 ++ "13: movl %%eax, %%es:16(%3)\n"
9025 ++ "14: movl %%edx, %%es:20(%3)\n"
9026 + "15: movl 24(%4), %%eax\n"
9027 + "16: movl 28(%4), %%edx\n"
9028 +- "17: movl %%eax, 24(%3)\n"
9029 +- "18: movl %%edx, 28(%3)\n"
9030 ++ "17: movl %%eax, %%es:24(%3)\n"
9031 ++ "18: movl %%edx, %%es:28(%3)\n"
9032 + "19: movl 32(%4), %%eax\n"
9033 + "20: movl 36(%4), %%edx\n"
9034 +- "21: movl %%eax, 32(%3)\n"
9035 +- "22: movl %%edx, 36(%3)\n"
9036 ++ "21: movl %%eax, %%es:32(%3)\n"
9037 ++ "22: movl %%edx, %%es:36(%3)\n"
9038 + "23: movl 40(%4), %%eax\n"
9039 + "24: movl 44(%4), %%edx\n"
9040 +- "25: movl %%eax, 40(%3)\n"
9041 +- "26: movl %%edx, 44(%3)\n"
9042 ++ "25: movl %%eax, %%es:40(%3)\n"
9043 ++ "26: movl %%edx, %%es:44(%3)\n"
9044 + "27: movl 48(%4), %%eax\n"
9045 + "28: movl 52(%4), %%edx\n"
9046 +- "29: movl %%eax, 48(%3)\n"
9047 +- "30: movl %%edx, 52(%3)\n"
9048 ++ "29: movl %%eax, %%es:48(%3)\n"
9049 ++ "30: movl %%edx, %%es:52(%3)\n"
9050 + "31: movl 56(%4), %%eax\n"
9051 + "32: movl 60(%4), %%edx\n"
9052 +- "33: movl %%eax, 56(%3)\n"
9053 +- "34: movl %%edx, 60(%3)\n"
9054 ++ "33: movl %%eax, %%es:56(%3)\n"
9055 ++ "34: movl %%edx, %%es:60(%3)\n"
9056 + " addl $-64, %0\n"
9057 + " addl $64, %4\n"
9058 + " addl $64, %3\n"
9059 +@@ -275,6 +289,8 @@ __copy_user_intel(void __user *to, const
9060 + "36: movl %%eax, %0\n"
9061 + "37: rep; movsb\n"
9062 + "100:\n"
9063 ++ " pushl %%ss\n"
9064 ++ " popl %%es\n"
9065 + ".section .fixup,\"ax\"\n"
9066 + "101: lea 0(%%eax,%0,4),%0\n"
9067 + " jmp 100b\n"
9068 +@@ -321,7 +337,117 @@ __copy_user_intel(void __user *to, const
9069 + " .long 99b,101b\n"
9070 + ".previous"
9071 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9072 +- : "1"(to), "2"(from), "0"(size)
9073 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9074 ++ : "eax", "edx", "memory");
9075 ++ return size;
9076 ++}
9077 ++
9078 ++static unsigned long
9079 ++__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
9080 ++{
9081 ++ int d0, d1;
9082 ++ __asm__ __volatile__(
9083 ++ " movw %w6, %%ds\n"
9084 ++ " .align 2,0x90\n"
9085 ++ "1: movl 32(%4), %%eax\n"
9086 ++ " cmpl $67, %0\n"
9087 ++ " jbe 3f\n"
9088 ++ "2: movl 64(%4), %%eax\n"
9089 ++ " .align 2,0x90\n"
9090 ++ "3: movl 0(%4), %%eax\n"
9091 ++ "4: movl 4(%4), %%edx\n"
9092 ++ "5: movl %%eax, %%es:0(%3)\n"
9093 ++ "6: movl %%edx, %%es:4(%3)\n"
9094 ++ "7: movl 8(%4), %%eax\n"
9095 ++ "8: movl 12(%4),%%edx\n"
9096 ++ "9: movl %%eax, %%es:8(%3)\n"
9097 ++ "10: movl %%edx, %%es:12(%3)\n"
9098 ++ "11: movl 16(%4), %%eax\n"
9099 ++ "12: movl 20(%4), %%edx\n"
9100 ++ "13: movl %%eax, %%es:16(%3)\n"
9101 ++ "14: movl %%edx, %%es:20(%3)\n"
9102 ++ "15: movl 24(%4), %%eax\n"
9103 ++ "16: movl 28(%4), %%edx\n"
9104 ++ "17: movl %%eax, %%es:24(%3)\n"
9105 ++ "18: movl %%edx, %%es:28(%3)\n"
9106 ++ "19: movl 32(%4), %%eax\n"
9107 ++ "20: movl 36(%4), %%edx\n"
9108 ++ "21: movl %%eax, %%es:32(%3)\n"
9109 ++ "22: movl %%edx, %%es:36(%3)\n"
9110 ++ "23: movl 40(%4), %%eax\n"
9111 ++ "24: movl 44(%4), %%edx\n"
9112 ++ "25: movl %%eax, %%es:40(%3)\n"
9113 ++ "26: movl %%edx, %%es:44(%3)\n"
9114 ++ "27: movl 48(%4), %%eax\n"
9115 ++ "28: movl 52(%4), %%edx\n"
9116 ++ "29: movl %%eax, %%es:48(%3)\n"
9117 ++ "30: movl %%edx, %%es:52(%3)\n"
9118 ++ "31: movl 56(%4), %%eax\n"
9119 ++ "32: movl 60(%4), %%edx\n"
9120 ++ "33: movl %%eax, %%es:56(%3)\n"
9121 ++ "34: movl %%edx, %%es:60(%3)\n"
9122 ++ " addl $-64, %0\n"
9123 ++ " addl $64, %4\n"
9124 ++ " addl $64, %3\n"
9125 ++ " cmpl $63, %0\n"
9126 ++ " ja 1b\n"
9127 ++ "35: movl %0, %%eax\n"
9128 ++ " shrl $2, %0\n"
9129 ++ " andl $3, %%eax\n"
9130 ++ " cld\n"
9131 ++ "99: rep; movsl\n"
9132 ++ "36: movl %%eax, %0\n"
9133 ++ "37: rep; movsb\n"
9134 ++ "100:\n"
9135 ++ " pushl %%ss\n"
9136 ++ " popl %%ds\n"
9137 ++ ".section .fixup,\"ax\"\n"
9138 ++ "101: lea 0(%%eax,%0,4),%0\n"
9139 ++ " jmp 100b\n"
9140 ++ ".previous\n"
9141 ++ ".section __ex_table,\"a\"\n"
9142 ++ " .align 4\n"
9143 ++ " .long 1b,100b\n"
9144 ++ " .long 2b,100b\n"
9145 ++ " .long 3b,100b\n"
9146 ++ " .long 4b,100b\n"
9147 ++ " .long 5b,100b\n"
9148 ++ " .long 6b,100b\n"
9149 ++ " .long 7b,100b\n"
9150 ++ " .long 8b,100b\n"
9151 ++ " .long 9b,100b\n"
9152 ++ " .long 10b,100b\n"
9153 ++ " .long 11b,100b\n"
9154 ++ " .long 12b,100b\n"
9155 ++ " .long 13b,100b\n"
9156 ++ " .long 14b,100b\n"
9157 ++ " .long 15b,100b\n"
9158 ++ " .long 16b,100b\n"
9159 ++ " .long 17b,100b\n"
9160 ++ " .long 18b,100b\n"
9161 ++ " .long 19b,100b\n"
9162 ++ " .long 20b,100b\n"
9163 ++ " .long 21b,100b\n"
9164 ++ " .long 22b,100b\n"
9165 ++ " .long 23b,100b\n"
9166 ++ " .long 24b,100b\n"
9167 ++ " .long 25b,100b\n"
9168 ++ " .long 26b,100b\n"
9169 ++ " .long 27b,100b\n"
9170 ++ " .long 28b,100b\n"
9171 ++ " .long 29b,100b\n"
9172 ++ " .long 30b,100b\n"
9173 ++ " .long 31b,100b\n"
9174 ++ " .long 32b,100b\n"
9175 ++ " .long 33b,100b\n"
9176 ++ " .long 34b,100b\n"
9177 ++ " .long 35b,100b\n"
9178 ++ " .long 36b,100b\n"
9179 ++ " .long 37b,100b\n"
9180 ++ " .long 99b,101b\n"
9181 ++ ".previous"
9182 ++ : "=&c"(size), "=&D" (d0), "=&S" (d1)
9183 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9184 + : "eax", "edx", "memory");
9185 + return size;
9186 + }
9187 +@@ -331,6 +457,7 @@ __copy_user_zeroing_intel(void *to, cons
9188 + {
9189 + int d0, d1;
9190 + __asm__ __volatile__(
9191 ++ " movw %w6, %%ds\n"
9192 + " .align 2,0x90\n"
9193 + "0: movl 32(%4), %%eax\n"
9194 + " cmpl $67, %0\n"
9195 +@@ -339,36 +466,36 @@ __copy_user_zeroing_intel(void *to, cons
9196 + " .align 2,0x90\n"
9197 + "2: movl 0(%4), %%eax\n"
9198 + "21: movl 4(%4), %%edx\n"
9199 +- " movl %%eax, 0(%3)\n"
9200 +- " movl %%edx, 4(%3)\n"
9201 ++ " movl %%eax, %%es:0(%3)\n"
9202 ++ " movl %%edx, %%es:4(%3)\n"
9203 + "3: movl 8(%4), %%eax\n"
9204 + "31: movl 12(%4),%%edx\n"
9205 +- " movl %%eax, 8(%3)\n"
9206 +- " movl %%edx, 12(%3)\n"
9207 ++ " movl %%eax, %%es:8(%3)\n"
9208 ++ " movl %%edx, %%es:12(%3)\n"
9209 + "4: movl 16(%4), %%eax\n"
9210 + "41: movl 20(%4), %%edx\n"
9211 +- " movl %%eax, 16(%3)\n"
9212 +- " movl %%edx, 20(%3)\n"
9213 ++ " movl %%eax, %%es:16(%3)\n"
9214 ++ " movl %%edx, %%es:20(%3)\n"
9215 + "10: movl 24(%4), %%eax\n"
9216 + "51: movl 28(%4), %%edx\n"
9217 +- " movl %%eax, 24(%3)\n"
9218 +- " movl %%edx, 28(%3)\n"
9219 ++ " movl %%eax, %%es:24(%3)\n"
9220 ++ " movl %%edx, %%es:28(%3)\n"
9221 + "11: movl 32(%4), %%eax\n"
9222 + "61: movl 36(%4), %%edx\n"
9223 +- " movl %%eax, 32(%3)\n"
9224 +- " movl %%edx, 36(%3)\n"
9225 ++ " movl %%eax, %%es:32(%3)\n"
9226 ++ " movl %%edx, %%es:36(%3)\n"
9227 + "12: movl 40(%4), %%eax\n"
9228 + "71: movl 44(%4), %%edx\n"
9229 +- " movl %%eax, 40(%3)\n"
9230 +- " movl %%edx, 44(%3)\n"
9231 ++ " movl %%eax, %%es:40(%3)\n"
9232 ++ " movl %%edx, %%es:44(%3)\n"
9233 + "13: movl 48(%4), %%eax\n"
9234 + "81: movl 52(%4), %%edx\n"
9235 +- " movl %%eax, 48(%3)\n"
9236 +- " movl %%edx, 52(%3)\n"
9237 ++ " movl %%eax, %%es:48(%3)\n"
9238 ++ " movl %%edx, %%es:52(%3)\n"
9239 + "14: movl 56(%4), %%eax\n"
9240 + "91: movl 60(%4), %%edx\n"
9241 +- " movl %%eax, 56(%3)\n"
9242 +- " movl %%edx, 60(%3)\n"
9243 ++ " movl %%eax, %%es:56(%3)\n"
9244 ++ " movl %%edx, %%es:60(%3)\n"
9245 + " addl $-64, %0\n"
9246 + " addl $64, %4\n"
9247 + " addl $64, %3\n"
9248 +@@ -382,6 +509,8 @@ __copy_user_zeroing_intel(void *to, cons
9249 + " movl %%eax,%0\n"
9250 + "7: rep; movsb\n"
9251 + "8:\n"
9252 ++ " pushl %%ss\n"
9253 ++ " popl %%ds\n"
9254 + ".section .fixup,\"ax\"\n"
9255 + "9: lea 0(%%eax,%0,4),%0\n"
9256 + "16: pushl %0\n"
9257 +@@ -416,7 +545,7 @@ __copy_user_zeroing_intel(void *to, cons
9258 + " .long 7b,16b\n"
9259 + ".previous"
9260 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9261 +- : "1"(to), "2"(from), "0"(size)
9262 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9263 + : "eax", "edx", "memory");
9264 + return size;
9265 + }
9266 +@@ -432,6 +561,7 @@ static unsigned long __copy_user_zeroing
9267 + int d0, d1;
9268 +
9269 + __asm__ __volatile__(
9270 ++ " movw %w6, %%ds\n"
9271 + " .align 2,0x90\n"
9272 + "0: movl 32(%4), %%eax\n"
9273 + " cmpl $67, %0\n"
9274 +@@ -440,36 +570,36 @@ static unsigned long __copy_user_zeroing
9275 + " .align 2,0x90\n"
9276 + "2: movl 0(%4), %%eax\n"
9277 + "21: movl 4(%4), %%edx\n"
9278 +- " movnti %%eax, 0(%3)\n"
9279 +- " movnti %%edx, 4(%3)\n"
9280 ++ " movnti %%eax, %%es:0(%3)\n"
9281 ++ " movnti %%edx, %%es:4(%3)\n"
9282 + "3: movl 8(%4), %%eax\n"
9283 + "31: movl 12(%4),%%edx\n"
9284 +- " movnti %%eax, 8(%3)\n"
9285 +- " movnti %%edx, 12(%3)\n"
9286 ++ " movnti %%eax, %%es:8(%3)\n"
9287 ++ " movnti %%edx, %%es:12(%3)\n"
9288 + "4: movl 16(%4), %%eax\n"
9289 + "41: movl 20(%4), %%edx\n"
9290 +- " movnti %%eax, 16(%3)\n"
9291 +- " movnti %%edx, 20(%3)\n"
9292 ++ " movnti %%eax, %%es:16(%3)\n"
9293 ++ " movnti %%edx, %%es:20(%3)\n"
9294 + "10: movl 24(%4), %%eax\n"
9295 + "51: movl 28(%4), %%edx\n"
9296 +- " movnti %%eax, 24(%3)\n"
9297 +- " movnti %%edx, 28(%3)\n"
9298 ++ " movnti %%eax, %%es:24(%3)\n"
9299 ++ " movnti %%edx, %%es:28(%3)\n"
9300 + "11: movl 32(%4), %%eax\n"
9301 + "61: movl 36(%4), %%edx\n"
9302 +- " movnti %%eax, 32(%3)\n"
9303 +- " movnti %%edx, 36(%3)\n"
9304 ++ " movnti %%eax, %%es:32(%3)\n"
9305 ++ " movnti %%edx, %%es:36(%3)\n"
9306 + "12: movl 40(%4), %%eax\n"
9307 + "71: movl 44(%4), %%edx\n"
9308 +- " movnti %%eax, 40(%3)\n"
9309 +- " movnti %%edx, 44(%3)\n"
9310 ++ " movnti %%eax, %%es:40(%3)\n"
9311 ++ " movnti %%edx, %%es:44(%3)\n"
9312 + "13: movl 48(%4), %%eax\n"
9313 + "81: movl 52(%4), %%edx\n"
9314 +- " movnti %%eax, 48(%3)\n"
9315 +- " movnti %%edx, 52(%3)\n"
9316 ++ " movnti %%eax, %%es:48(%3)\n"
9317 ++ " movnti %%edx, %%es:52(%3)\n"
9318 + "14: movl 56(%4), %%eax\n"
9319 + "91: movl 60(%4), %%edx\n"
9320 +- " movnti %%eax, 56(%3)\n"
9321 +- " movnti %%edx, 60(%3)\n"
9322 ++ " movnti %%eax, %%es:56(%3)\n"
9323 ++ " movnti %%edx, %%es:60(%3)\n"
9324 + " addl $-64, %0\n"
9325 + " addl $64, %4\n"
9326 + " addl $64, %3\n"
9327 +@@ -484,6 +614,8 @@ static unsigned long __copy_user_zeroing
9328 + " movl %%eax,%0\n"
9329 + "7: rep; movsb\n"
9330 + "8:\n"
9331 ++ " pushl %%ss\n"
9332 ++ " popl %%ds\n"
9333 + ".section .fixup,\"ax\"\n"
9334 + "9: lea 0(%%eax,%0,4),%0\n"
9335 + "16: pushl %0\n"
9336 +@@ -518,7 +650,7 @@ static unsigned long __copy_user_zeroing
9337 + " .long 7b,16b\n"
9338 + ".previous"
9339 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9340 +- : "1"(to), "2"(from), "0"(size)
9341 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9342 + : "eax", "edx", "memory");
9343 + return size;
9344 + }
9345 +@@ -529,6 +661,7 @@ static unsigned long __copy_user_intel_n
9346 + int d0, d1;
9347 +
9348 + __asm__ __volatile__(
9349 ++ " movw %w6, %%ds\n"
9350 + " .align 2,0x90\n"
9351 + "0: movl 32(%4), %%eax\n"
9352 + " cmpl $67, %0\n"
9353 +@@ -537,36 +670,36 @@ static unsigned long __copy_user_intel_n
9354 + " .align 2,0x90\n"
9355 + "2: movl 0(%4), %%eax\n"
9356 + "21: movl 4(%4), %%edx\n"
9357 +- " movnti %%eax, 0(%3)\n"
9358 +- " movnti %%edx, 4(%3)\n"
9359 ++ " movnti %%eax, %%es:0(%3)\n"
9360 ++ " movnti %%edx, %%es:4(%3)\n"
9361 + "3: movl 8(%4), %%eax\n"
9362 + "31: movl 12(%4),%%edx\n"
9363 +- " movnti %%eax, 8(%3)\n"
9364 +- " movnti %%edx, 12(%3)\n"
9365 ++ " movnti %%eax, %%es:8(%3)\n"
9366 ++ " movnti %%edx, %%es:12(%3)\n"
9367 + "4: movl 16(%4), %%eax\n"
9368 + "41: movl 20(%4), %%edx\n"
9369 +- " movnti %%eax, 16(%3)\n"
9370 +- " movnti %%edx, 20(%3)\n"
9371 ++ " movnti %%eax, %%es:16(%3)\n"
9372 ++ " movnti %%edx, %%es:20(%3)\n"
9373 + "10: movl 24(%4), %%eax\n"
9374 + "51: movl 28(%4), %%edx\n"
9375 +- " movnti %%eax, 24(%3)\n"
9376 +- " movnti %%edx, 28(%3)\n"
9377 ++ " movnti %%eax, %%es:24(%3)\n"
9378 ++ " movnti %%edx, %%es:28(%3)\n"
9379 + "11: movl 32(%4), %%eax\n"
9380 + "61: movl 36(%4), %%edx\n"
9381 +- " movnti %%eax, 32(%3)\n"
9382 +- " movnti %%edx, 36(%3)\n"
9383 ++ " movnti %%eax, %%es:32(%3)\n"
9384 ++ " movnti %%edx, %%es:36(%3)\n"
9385 + "12: movl 40(%4), %%eax\n"
9386 + "71: movl 44(%4), %%edx\n"
9387 +- " movnti %%eax, 40(%3)\n"
9388 +- " movnti %%edx, 44(%3)\n"
9389 ++ " movnti %%eax, %%es:40(%3)\n"
9390 ++ " movnti %%edx, %%es:44(%3)\n"
9391 + "13: movl 48(%4), %%eax\n"
9392 + "81: movl 52(%4), %%edx\n"
9393 +- " movnti %%eax, 48(%3)\n"
9394 +- " movnti %%edx, 52(%3)\n"
9395 ++ " movnti %%eax, %%es:48(%3)\n"
9396 ++ " movnti %%edx, %%es:52(%3)\n"
9397 + "14: movl 56(%4), %%eax\n"
9398 + "91: movl 60(%4), %%edx\n"
9399 +- " movnti %%eax, 56(%3)\n"
9400 +- " movnti %%edx, 60(%3)\n"
9401 ++ " movnti %%eax, %%es:56(%3)\n"
9402 ++ " movnti %%edx, %%es:60(%3)\n"
9403 + " addl $-64, %0\n"
9404 + " addl $64, %4\n"
9405 + " addl $64, %3\n"
9406 +@@ -581,6 +714,8 @@ static unsigned long __copy_user_intel_n
9407 + " movl %%eax,%0\n"
9408 + "7: rep; movsb\n"
9409 + "8:\n"
9410 ++ " pushl %%ss\n"
9411 ++ " popl %%ds\n"
9412 + ".section .fixup,\"ax\"\n"
9413 + "9: lea 0(%%eax,%0,4),%0\n"
9414 + "16: jmp 8b\n"
9415 +@@ -609,7 +744,7 @@ static unsigned long __copy_user_intel_n
9416 + " .long 7b,16b\n"
9417 + ".previous"
9418 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9419 +- : "1"(to), "2"(from), "0"(size)
9420 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9421 + : "eax", "edx", "memory");
9422 + return size;
9423 + }
9424 +@@ -622,90 +757,146 @@ static unsigned long __copy_user_intel_n
9425 + */
9426 + unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
9427 + unsigned long size);
9428 +-unsigned long __copy_user_intel(void __user *to, const void *from,
9429 ++unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
9430 ++ unsigned long size);
9431 ++unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
9432 + unsigned long size);
9433 + unsigned long __copy_user_zeroing_intel_nocache(void *to,
9434 + const void __user *from, unsigned long size);
9435 + #endif /* CONFIG_X86_INTEL_USERCOPY */
9436 +
9437 + /* Generic arbitrary sized copy. */
9438 +-#define __copy_user(to, from, size) \
9439 +-do { \
9440 +- int __d0, __d1, __d2; \
9441 +- __asm__ __volatile__( \
9442 +- " cmp $7,%0\n" \
9443 +- " jbe 1f\n" \
9444 +- " movl %1,%0\n" \
9445 +- " negl %0\n" \
9446 +- " andl $7,%0\n" \
9447 +- " subl %0,%3\n" \
9448 +- "4: rep; movsb\n" \
9449 +- " movl %3,%0\n" \
9450 +- " shrl $2,%0\n" \
9451 +- " andl $3,%3\n" \
9452 +- " .align 2,0x90\n" \
9453 +- "0: rep; movsl\n" \
9454 +- " movl %3,%0\n" \
9455 +- "1: rep; movsb\n" \
9456 +- "2:\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) \
9471 +- : "memory"); \
9472 +-} while (0)
9473 +-
9474 +-#define __copy_user_zeroing(to, from, size) \
9475 +-do { \
9476 +- int __d0, __d1, __d2; \
9477 +- __asm__ __volatile__( \
9478 +- " cmp $7,%0\n" \
9479 +- " jbe 1f\n" \
9480 +- " movl %1,%0\n" \
9481 +- " negl %0\n" \
9482 +- " andl $7,%0\n" \
9483 +- " subl %0,%3\n" \
9484 +- "4: rep; movsb\n" \
9485 +- " movl %3,%0\n" \
9486 +- " shrl $2,%0\n" \
9487 +- " andl $3,%3\n" \
9488 +- " .align 2,0x90\n" \
9489 +- "0: rep; movsl\n" \
9490 +- " movl %3,%0\n" \
9491 +- "1: rep; movsb\n" \
9492 +- "2:\n" \
9493 +- ".section .fixup,\"ax\"\n" \
9494 +- "5: addl %3,%0\n" \
9495 +- " jmp 6f\n" \
9496 +- "3: lea 0(%3,%0,4),%0\n" \
9497 +- "6: pushl %0\n" \
9498 +- " pushl %%eax\n" \
9499 +- " xorl %%eax,%%eax\n" \
9500 +- " rep; stosb\n" \
9501 +- " popl %%eax\n" \
9502 +- " popl %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,6b\n" \
9510 +- ".previous" \
9511 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
9512 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
9513 +- : "memory"); \
9514 +-} while (0)
9515 ++static unsigned long
9516 ++__generic_copy_to_user(void __user *to, const void *from, unsigned long size)
9517 ++{
9518 ++ int __d0, __d1, __d2;
9519 ++
9520 ++ __asm__ __volatile__(
9521 ++ " movw %w8,%%es\n"
9522 ++ " cmp $7,%0\n"
9523 ++ " jbe 1f\n"
9524 ++ " movl %1,%0\n"
9525 ++ " negl %0\n"
9526 ++ " andl $7,%0\n"
9527 ++ " subl %0,%3\n"
9528 ++ "4: rep; movsb\n"
9529 ++ " movl %3,%0\n"
9530 ++ " shrl $2,%0\n"
9531 ++ " andl $3,%3\n"
9532 ++ " .align 2,0x90\n"
9533 ++ "0: rep; movsl\n"
9534 ++ " movl %3,%0\n"
9535 ++ "1: rep; movsb\n"
9536 ++ "2:\n"
9537 ++ " pushl %%ss\n"
9538 ++ " popl %%es\n"
9539 ++ ".section .fixup,\"ax\"\n"
9540 ++ "5: addl %3,%0\n"
9541 ++ " jmp 2b\n"
9542 ++ "3: lea 0(%3,%0,4),%0\n"
9543 ++ " jmp 2b\n"
9544 ++ ".previous\n"
9545 ++ ".section __ex_table,\"a\"\n"
9546 ++ " .align 4\n"
9547 ++ " .long 4b,5b\n"
9548 ++ " .long 0b,3b\n"
9549 ++ " .long 1b,2b\n"
9550 ++ ".previous"
9551 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9552 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9553 ++ : "memory");
9554 ++ return size;
9555 ++}
9556 ++
9557 ++static unsigned long
9558 ++__generic_copy_from_user(void *to, const void __user *from, unsigned long size)
9559 ++{
9560 ++ int __d0, __d1, __d2;
9561 ++
9562 ++ __asm__ __volatile__(
9563 ++ " movw %w8,%%ds\n"
9564 ++ " cmp $7,%0\n"
9565 ++ " jbe 1f\n"
9566 ++ " movl %1,%0\n"
9567 ++ " negl %0\n"
9568 ++ " andl $7,%0\n"
9569 ++ " subl %0,%3\n"
9570 ++ "4: rep; movsb\n"
9571 ++ " movl %3,%0\n"
9572 ++ " shrl $2,%0\n"
9573 ++ " andl $3,%3\n"
9574 ++ " .align 2,0x90\n"
9575 ++ "0: rep; movsl\n"
9576 ++ " movl %3,%0\n"
9577 ++ "1: rep; movsb\n"
9578 ++ "2:\n"
9579 ++ " pushl %%ss\n"
9580 ++ " popl %%ds\n"
9581 ++ ".section .fixup,\"ax\"\n"
9582 ++ "5: addl %3,%0\n"
9583 ++ " jmp 2b\n"
9584 ++ "3: lea 0(%3,%0,4),%0\n"
9585 ++ " jmp 2b\n"
9586 ++ ".previous\n"
9587 ++ ".section __ex_table,\"a\"\n"
9588 ++ " .align 4\n"
9589 ++ " .long 4b,5b\n"
9590 ++ " .long 0b,3b\n"
9591 ++ " .long 1b,2b\n"
9592 ++ ".previous"
9593 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9594 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9595 ++ : "memory");
9596 ++ return size;
9597 ++}
9598 ++
9599 ++static unsigned long
9600 ++__copy_user_zeroing(void *to, const void __user *from, unsigned long size)
9601 ++{
9602 ++ int __d0, __d1, __d2;
9603 ++
9604 ++ __asm__ __volatile__(
9605 ++ " movw %w8,%%ds\n"
9606 ++ " cmp $7,%0\n"
9607 ++ " jbe 1f\n"
9608 ++ " movl %1,%0\n"
9609 ++ " negl %0\n"
9610 ++ " andl $7,%0\n"
9611 ++ " subl %0,%3\n"
9612 ++ "4: rep; movsb\n"
9613 ++ " movl %3,%0\n"
9614 ++ " shrl $2,%0\n"
9615 ++ " andl $3,%3\n"
9616 ++ " .align 2,0x90\n"
9617 ++ "0: rep; movsl\n"
9618 ++ " movl %3,%0\n"
9619 ++ "1: rep; movsb\n"
9620 ++ "2:\n"
9621 ++ " pushl %%ss\n"
9622 ++ " popl %%ds\n"
9623 ++ ".section .fixup,\"ax\"\n"
9624 ++ "5: addl %3,%0\n"
9625 ++ " jmp 6f\n"
9626 ++ "3: lea 0(%3,%0,4),%0\n"
9627 ++ "6: pushl %0\n"
9628 ++ " pushl %%eax\n"
9629 ++ " xorl %%eax,%%eax\n"
9630 ++ " rep; stosb\n"
9631 ++ " popl %%eax\n"
9632 ++ " popl %0\n"
9633 ++ " jmp 2b\n"
9634 ++ ".previous\n"
9635 ++ ".section __ex_table,\"a\"\n"
9636 ++ " .align 4\n"
9637 ++ " .long 4b,5b\n"
9638 ++ " .long 0b,3b\n"
9639 ++ " .long 1b,6b\n"
9640 ++ ".previous"
9641 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9642 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9643 ++ : "memory");
9644 ++ return size;
9645 ++}
9646 +
9647 + unsigned long __copy_to_user_ll(void __user *to, const void *from,
9648 + unsigned long n)
9649 +@@ -768,9 +959,9 @@ survive:
9650 + }
9651 + #endif
9652 + if (movsl_is_ok(to, from, n))
9653 +- __copy_user(to, from, n);
9654 ++ n = __generic_copy_to_user(to, from, n);
9655 + else
9656 +- n = __copy_user_intel(to, from, n);
9657 ++ n = __generic_copy_to_user_intel(to, from, n);
9658 + return n;
9659 + }
9660 + EXPORT_SYMBOL(__copy_to_user_ll);
9661 +@@ -779,7 +970,7 @@ unsigned long __copy_from_user_ll(void *
9662 + unsigned long n)
9663 + {
9664 + if (movsl_is_ok(to, from, n))
9665 +- __copy_user_zeroing(to, from, n);
9666 ++ n = __copy_user_zeroing(to, from, n);
9667 + else
9668 + n = __copy_user_zeroing_intel(to, from, n);
9669 + return n;
9670 +@@ -790,10 +981,9 @@ unsigned long __copy_from_user_ll_nozero
9671 + unsigned long n)
9672 + {
9673 + if (movsl_is_ok(to, from, n))
9674 +- __copy_user(to, from, n);
9675 ++ n = __generic_copy_from_user(to, from, n);
9676 + else
9677 +- n = __copy_user_intel((void __user *)to,
9678 +- (const void *)from, n);
9679 ++ n = __generic_copy_from_user_intel(to, from, n);
9680 + return n;
9681 + }
9682 + EXPORT_SYMBOL(__copy_from_user_ll_nozero);
9683 +@@ -802,12 +992,12 @@ unsigned long __copy_from_user_ll_nocach
9684 + unsigned long n)
9685 + {
9686 + #ifdef CONFIG_X86_INTEL_USERCOPY
9687 +- if (n > 64 && cpu_has_xmm2)
9688 ++ if ( n > 64 && cpu_has_xmm2)
9689 + n = __copy_user_zeroing_intel_nocache(to, from, n);
9690 + else
9691 +- __copy_user_zeroing(to, from, n);
9692 ++ n = __copy_user_zeroing(to, from, n);
9693 + #else
9694 +- __copy_user_zeroing(to, from, n);
9695 ++ n = __copy_user_zeroing(to, from, n);
9696 + #endif
9697 + return n;
9698 + }
9699 +@@ -817,12 +1007,12 @@ unsigned long __copy_from_user_ll_nocach
9700 + unsigned long n)
9701 + {
9702 + #ifdef CONFIG_X86_INTEL_USERCOPY
9703 +- if (n > 64 && cpu_has_xmm2)
9704 ++ if ( n > 64 && cpu_has_xmm2)
9705 + n = __copy_user_intel_nocache(to, from, n);
9706 + else
9707 +- __copy_user(to, from, n);
9708 ++ n = __generic_copy_from_user(to, from, n);
9709 + #else
9710 +- __copy_user(to, from, n);
9711 ++ n = __generic_copy_from_user(to, from, n);
9712 + #endif
9713 + return n;
9714 + }
9715 +@@ -871,8 +1061,35 @@ copy_from_user(void *to, const void __us
9716 + {
9717 + if (access_ok(VERIFY_READ, from, n))
9718 + n = __copy_from_user(to, from, n);
9719 +- else
9720 ++ else if ((long)n > 0)
9721 + memset(to, 0, n);
9722 + return n;
9723 + }
9724 + EXPORT_SYMBOL(copy_from_user);
9725 ++
9726 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
9727 ++void __set_fs(mm_segment_t x, int cpu)
9728 ++{
9729 ++ unsigned long limit = x.seg;
9730 ++ struct desc_struct d;
9731 ++
9732 ++ current_thread_info()->addr_limit = x;
9733 ++ if (likely(limit))
9734 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
9735 ++ pack_descriptor(&d, 0UL, limit, 0xF3, 0xC);
9736 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S);
9737 ++}
9738 ++
9739 ++void set_fs(mm_segment_t x)
9740 ++{
9741 ++ __set_fs(x, get_cpu());
9742 ++ put_cpu_no_resched();
9743 ++}
9744 ++#else
9745 ++void set_fs(mm_segment_t x)
9746 ++{
9747 ++ current_thread_info()->addr_limit = x;
9748 ++}
9749 ++#endif
9750 ++
9751 ++EXPORT_SYMBOL(set_fs);
9752 +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
9753 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-07 12:55:34.000000000 -0500
9754 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-18 03:38:44.000000000 -0500
9755 +@@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg
9756 + __u8 cmos[4];
9757 + ClickMap_t *map;
9758 + unsigned long map_addr;
9759 +- unsigned long old;
9760 ++ pte_t old;
9761 +
9762 + if (region >= CLICK_ENTRIES) {
9763 + printk("Voyager: Illegal ClickMap region %d\n", region);
9764 +@@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg
9765 +
9766 + /* steal page 0 for this */
9767 + old = pg0[0];
9768 +- pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9769 ++ pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9770 + local_flush_tlb();
9771 + /* now clear everything out but page 0 */
9772 + map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
9773 +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
9774 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-07 12:55:34.000000000 -0500
9775 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-18 03:38:44.000000000 -0500
9776 +@@ -510,6 +510,10 @@ static void __init do_boot_cpu(__u8 cpu)
9777 + __u32 *hijack_vector;
9778 + __u32 start_phys_address = setup_trampoline();
9779 +
9780 ++#ifdef CONFIG_PAX_KERNEXEC
9781 ++ unsigned long cr0;
9782 ++#endif
9783 ++
9784 + /* There's a clever trick to this: The linux trampoline is
9785 + * compiled to begin at absolute location zero, so make the
9786 + * address zero but have the data segment selector compensate
9787 +@@ -529,7 +533,17 @@ static void __init do_boot_cpu(__u8 cpu)
9788 +
9789 + init_gdt(cpu);
9790 + per_cpu(current_task, cpu) = idle;
9791 +- early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
9792 ++
9793 ++#ifdef CONFIG_PAX_KERNEXEC
9794 ++ pax_open_kernel(cr0);
9795 ++#endif
9796 ++
9797 ++ early_gdt_descr.address = get_cpu_gdt_table(cpu);
9798 ++
9799 ++#ifdef CONFIG_PAX_KERNEXEC
9800 ++ pax_close_kernel(cr0);
9801 ++#endif
9802 ++
9803 + irq_ctx_init(cpu);
9804 +
9805 + /* Note: Don't modify initial ss override */
9806 +@@ -1141,7 +1155,7 @@ void smp_local_timer_interrupt(void)
9807 + per_cpu(prof_counter, cpu);
9808 + }
9809 +
9810 +- update_process_times(user_mode_vm(get_irq_regs()));
9811 ++ update_process_times(user_mode(get_irq_regs()));
9812 + }
9813 +
9814 + if (((1 << cpu) & voyager_extended_vic_processors) == 0)
9815 +diff -urNp linux-2.6.27.10/arch/x86/Makefile linux-2.6.27.10/arch/x86/Makefile
9816 +--- linux-2.6.27.10/arch/x86/Makefile 2008-11-07 12:55:34.000000000 -0500
9817 ++++ linux-2.6.27.10/arch/x86/Makefile 2008-11-18 03:38:44.000000000 -0500
9818 +@@ -232,3 +232,12 @@ endef
9819 + CLEAN_FILES += arch/x86/boot/fdimage \
9820 + arch/x86/boot/image.iso \
9821 + arch/x86/boot/mtools.conf
9822 ++
9823 ++define OLD_LD
9824 ++
9825 ++*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9826 ++*** Please upgrade your binutils to 2.18 or newer
9827 ++endef
9828 ++
9829 ++archprepare:
9830 ++ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
9831 +diff -urNp linux-2.6.27.10/arch/x86/mm/discontig_32.c linux-2.6.27.10/arch/x86/mm/discontig_32.c
9832 +--- linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:36.000000000 -0500
9833 ++++ linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:46.000000000 -0500
9834 +@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
9835 + }
9836 + #endif
9837 +
9838 +-extern unsigned long find_max_low_pfn(void);
9839 + extern unsigned long highend_pfn, highstart_pfn;
9840 +
9841 + #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
9842 +diff -urNp linux-2.6.27.10/arch/x86/mm/extable.c linux-2.6.27.10/arch/x86/mm/extable.c
9843 +--- linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-07 12:55:34.000000000 -0500
9844 ++++ linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-18 03:38:44.000000000 -0500
9845 +@@ -1,14 +1,62 @@
9846 + #include <linux/module.h>
9847 + #include <linux/spinlock.h>
9848 ++#include <linux/sort.h>
9849 + #include <asm/uaccess.h>
9850 +
9851 ++/*
9852 ++ * The exception table needs to be sorted so that the binary
9853 ++ * search that we use to find entries in it works properly.
9854 ++ * This is used both for the kernel exception table and for
9855 ++ * the exception tables of modules that get loaded.
9856 ++ */
9857 ++static int cmp_ex(const void *a, const void *b)
9858 ++{
9859 ++ const struct exception_table_entry *x = a, *y = b;
9860 ++
9861 ++ /* avoid overflow */
9862 ++ if (x->insn > y->insn)
9863 ++ return 1;
9864 ++ if (x->insn < y->insn)
9865 ++ return -1;
9866 ++ return 0;
9867 ++}
9868 ++
9869 ++static void swap_ex(void *a, void *b, int size)
9870 ++{
9871 ++ struct exception_table_entry t, *x = a, *y = b;
9872 ++
9873 ++#ifdef CONFIG_PAX_KERNEXEC
9874 ++ unsigned long cr0;
9875 ++#endif
9876 ++
9877 ++ t = *x;
9878 ++
9879 ++#ifdef CONFIG_PAX_KERNEXEC
9880 ++ pax_open_kernel(cr0);
9881 ++#endif
9882 ++
9883 ++ *x = *y;
9884 ++ *y = t;
9885 ++
9886 ++#ifdef CONFIG_PAX_KERNEXEC
9887 ++ pax_close_kernel(cr0);
9888 ++#endif
9889 ++
9890 ++}
9891 ++
9892 ++void sort_extable(struct exception_table_entry *start,
9893 ++ struct exception_table_entry *finish)
9894 ++{
9895 ++ sort(start, finish - start, sizeof(struct exception_table_entry),
9896 ++ cmp_ex, swap_ex);
9897 ++}
9898 +
9899 + int fixup_exception(struct pt_regs *regs)
9900 + {
9901 + const struct exception_table_entry *fixup;
9902 +
9903 + #ifdef CONFIG_PNPBIOS
9904 +- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
9905 ++ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
9906 + extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
9907 + extern u32 pnp_bios_is_utter_crap;
9908 + pnp_bios_is_utter_crap = 1;
9909 +diff -urNp linux-2.6.27.10/arch/x86/mm/fault.c linux-2.6.27.10/arch/x86/mm/fault.c
9910 +--- linux-2.6.27.10/arch/x86/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
9911 ++++ linux-2.6.27.10/arch/x86/mm/fault.c 2008-12-10 22:28:27.000000000 -0500
9912 +@@ -26,6 +26,8 @@
9913 + #include <linux/kprobes.h>
9914 + #include <linux/uaccess.h>
9915 + #include <linux/kdebug.h>
9916 ++#include <linux/unistd.h>
9917 ++#include <linux/compiler.h>
9918 +
9919 + #include <asm/system.h>
9920 + #include <asm/desc.h>
9921 +@@ -66,7 +68,7 @@ static inline int notify_page_fault(stru
9922 + int ret = 0;
9923 +
9924 + /* kprobe_running() needs smp_processor_id() */
9925 +- if (!user_mode_vm(regs)) {
9926 ++ if (!user_mode(regs)) {
9927 + preempt_disable();
9928 + if (kprobe_running() && kprobe_fault_handler(regs, 14))
9929 + ret = 1;
9930 +@@ -264,6 +266,30 @@ bad:
9931 + #endif
9932 + }
9933 +
9934 ++#ifdef CONFIG_PAX_EMUTRAMP
9935 ++static int pax_handle_fetch_fault(struct pt_regs *regs);
9936 ++#endif
9937 ++
9938 ++#ifdef CONFIG_PAX_PAGEEXEC
9939 ++static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
9940 ++{
9941 ++ pgd_t *pgd;
9942 ++ pud_t *pud;
9943 ++ pmd_t *pmd;
9944 ++
9945 ++ pgd = pgd_offset(mm, address);
9946 ++ if (!pgd_present(*pgd))
9947 ++ return NULL;
9948 ++ pud = pud_offset(pgd, address);
9949 ++ if (!pud_present(*pud))
9950 ++ return NULL;
9951 ++ pmd = pmd_offset(pud, address);
9952 ++ if (!pmd_present(*pmd))
9953 ++ return NULL;
9954 ++ return pmd;
9955 ++}
9956 ++#endif
9957 ++
9958 + #ifdef CONFIG_X86_32
9959 + static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
9960 + {
9961 +@@ -350,7 +376,7 @@ static int is_errata93(struct pt_regs *r
9962 + static int is_errata100(struct pt_regs *regs, unsigned long address)
9963 + {
9964 + #ifdef CONFIG_X86_64
9965 +- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
9966 ++ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) &&
9967 + (address >> 32))
9968 + return 1;
9969 + #endif
9970 +@@ -387,14 +413,31 @@ static void show_fault_oops(struct pt_re
9971 + #endif
9972 +
9973 + #ifdef CONFIG_X86_PAE
9974 +- if (error_code & PF_INSTR) {
9975 ++ if (nx_enabled && (error_code & PF_INSTR)) {
9976 + unsigned int level;
9977 + pte_t *pte = lookup_address(address, &level);
9978 +
9979 + if (pte && pte_present(*pte) && !pte_exec(*pte))
9980 + printk(KERN_CRIT "kernel tried to execute "
9981 + "NX-protected page - exploit attempt? "
9982 +- "(uid: %d)\n", current->uid);
9983 ++ "(uid: %d, task: %s, pid: %d)\n",
9984 ++ current->uid, current->comm, task_pid_nr(current));
9985 ++ }
9986 ++#endif
9987 ++
9988 ++#ifdef CONFIG_PAX_KERNEXEC
9989 ++#ifdef CONFIG_MODULES
9990 ++ if (init_mm.start_code <= address && address < (unsigned long)MODULES_END)
9991 ++#else
9992 ++ if (init_mm.start_code <= address && address < init_mm.end_code)
9993 ++#endif
9994 ++ {
9995 ++ if (current->signal->curr_ip)
9996 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
9997 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
9998 ++ else
9999 ++ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
10000 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
10001 + }
10002 + #endif
10003 +
10004 +@@ -586,13 +629,22 @@ void __kprobes do_page_fault(struct pt_r
10005 + struct task_struct *tsk;
10006 + struct mm_struct *mm;
10007 + struct vm_area_struct *vma;
10008 +- unsigned long address;
10009 + int write, si_code;
10010 + int fault;
10011 + #ifdef CONFIG_X86_64
10012 + unsigned long flags;
10013 + #endif
10014 +
10015 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10016 ++ pte_t *pte;
10017 ++ pmd_t *pmd;
10018 ++ spinlock_t *ptl;
10019 ++ unsigned char pte_mask;
10020 ++#endif
10021 ++
10022 ++ /* get the address */
10023 ++ const unsigned long address = read_cr2();
10024 ++
10025 + /*
10026 + * We can fault from pretty much anywhere, with unknown IRQ state.
10027 + */
10028 +@@ -602,9 +654,6 @@ void __kprobes do_page_fault(struct pt_r
10029 + mm = tsk->mm;
10030 + prefetchw(&mm->mmap_sem);
10031 +
10032 +- /* get the address */
10033 +- address = read_cr2();
10034 +-
10035 + si_code = SEGV_MAPERR;
10036 +
10037 + if (notify_page_fault(regs))
10038 +@@ -657,7 +706,7 @@ void __kprobes do_page_fault(struct pt_r
10039 + * atomic region then we must not take the fault.
10040 + */
10041 + if (in_atomic() || !mm)
10042 +- goto bad_area_nosemaphore;
10043 ++ goto bad_area_nopax;
10044 + #else /* CONFIG_X86_64 */
10045 + if (likely(regs->flags & X86_EFLAGS_IF))
10046 + local_irq_enable();
10047 +@@ -670,13 +719,13 @@ void __kprobes do_page_fault(struct pt_r
10048 + * atomic region then we must not take the fault.
10049 + */
10050 + if (unlikely(in_atomic() || !mm))
10051 +- goto bad_area_nosemaphore;
10052 ++ goto bad_area_nopax;
10053 +
10054 + /*
10055 + * User-mode registers count as a user access even for any
10056 + * potential system fault or CPU buglet.
10057 + */
10058 +- if (user_mode_vm(regs))
10059 ++ if (user_mode(regs))
10060 + error_code |= PF_USER;
10061 + again:
10062 + #endif
10063 +@@ -698,10 +747,104 @@ again:
10064 + if (!down_read_trylock(&mm->mmap_sem)) {
10065 + if ((error_code & PF_USER) == 0 &&
10066 + !search_exception_tables(regs->ip))
10067 +- goto bad_area_nosemaphore;
10068 ++ goto bad_area_nopax;
10069 + down_read(&mm->mmap_sem);
10070 + }
10071 +
10072 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10073 ++ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
10074 ++ !(mm->pax_flags & MF_PAX_PAGEEXEC))
10075 ++ goto not_pax_fault;
10076 ++
10077 ++ /* PaX: it's our fault, let's handle it if we can */
10078 ++
10079 ++ /* PaX: take a look at read faults before acquiring any locks */
10080 ++ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
10081 ++ /* instruction fetch attempt from a protected page in user mode */
10082 ++ up_read(&mm->mmap_sem);
10083 ++
10084 ++#ifdef CONFIG_PAX_EMUTRAMP
10085 ++ switch (pax_handle_fetch_fault(regs)) {
10086 ++ case 2:
10087 ++ return;
10088 ++ }
10089 ++#endif
10090 ++
10091 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10092 ++ do_group_exit(SIGKILL);
10093 ++ }
10094 ++
10095 ++ pmd = pax_get_pmd(mm, address);
10096 ++ if (unlikely(!pmd))
10097 ++ goto not_pax_fault;
10098 ++
10099 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
10100 ++ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
10101 ++ pte_unmap_unlock(pte, ptl);
10102 ++ goto not_pax_fault;
10103 ++ }
10104 ++
10105 ++ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
10106 ++ /* write attempt to a protected page in user mode */
10107 ++ pte_unmap_unlock(pte, ptl);
10108 ++ goto not_pax_fault;
10109 ++ }
10110 ++
10111 ++#ifdef CONFIG_SMP
10112 ++ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
10113 ++#else
10114 ++ if (likely(address > get_limit(regs->cs)))
10115 ++#endif
10116 ++ {
10117 ++ set_pte(pte, pte_mkread(*pte));
10118 ++ __flush_tlb_one(address);
10119 ++ pte_unmap_unlock(pte, ptl);
10120 ++ up_read(&mm->mmap_sem);
10121 ++ return;
10122 ++ }
10123 ++
10124 ++ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
10125 ++
10126 ++ /*
10127 ++ * PaX: fill DTLB with user rights and retry
10128 ++ */
10129 ++ __asm__ __volatile__ (
10130 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10131 ++ "movw %w4,%%es\n"
10132 ++#endif
10133 ++ "orb %2,(%1)\n"
10134 ++#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
10135 ++/*
10136 ++ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
10137 ++ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
10138 ++ * page fault when examined during a TLB load attempt. this is true not only
10139 ++ * for PTEs holding a non-present entry but also present entries that will
10140 ++ * raise a page fault (such as those set up by PaX, or the copy-on-write
10141 ++ * mechanism). in effect it means that we do *not* need to flush the TLBs
10142 ++ * for our target pages since their PTEs are simply not in the TLBs at all.
10143 ++
10144 ++ * the best thing in omitting it is that we gain around 15-20% speed in the
10145 ++ * fast path of the page fault handler and can get rid of tracing since we
10146 ++ * can no longer flush unintended entries.
10147 ++ */
10148 ++ "invlpg (%0)\n"
10149 ++#endif
10150 ++ "testb $0,%%es:(%0)\n"
10151 ++ "xorb %3,(%1)\n"
10152 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10153 ++ "pushl %%ss\n"
10154 ++ "popl %%es\n"
10155 ++#endif
10156 ++ :
10157 ++ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS)
10158 ++ : "memory", "cc");
10159 ++ pte_unmap_unlock(pte, ptl);
10160 ++ up_read(&mm->mmap_sem);
10161 ++ return;
10162 ++
10163 ++not_pax_fault:
10164 ++#endif
10165 ++
10166 + vma = find_vma(mm, address);
10167 + if (!vma)
10168 + goto bad_area;
10169 +@@ -709,16 +852,20 @@ again:
10170 + goto good_area;
10171 + if (!(vma->vm_flags & VM_GROWSDOWN))
10172 + goto bad_area;
10173 +- if (error_code & PF_USER) {
10174 +- /*
10175 +- * Accessing the stack below %sp is always a bug.
10176 +- * The large cushion allows instructions like enter
10177 +- * and pusha to work. ("enter $65535,$31" pushes
10178 +- * 32 pointers and then decrements %sp by 65535.)
10179 +- */
10180 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10181 +- goto bad_area;
10182 +- }
10183 ++ /*
10184 ++ * Accessing the stack below %sp is always a bug.
10185 ++ * The large cushion allows instructions like enter
10186 ++ * and pusha to work. ("enter $65535,$31" pushes
10187 ++ * 32 pointers and then decrements %sp by 65535.)
10188 ++ */
10189 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10190 ++ goto bad_area;
10191 ++
10192 ++#ifdef CONFIG_PAX_SEGMEXEC
10193 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)
10194 ++ goto bad_area;
10195 ++#endif
10196 ++
10197 + if (expand_stack(vma, address))
10198 + goto bad_area;
10199 + /*
10200 +@@ -728,6 +875,8 @@ again:
10201 + good_area:
10202 + si_code = SEGV_ACCERR;
10203 + write = 0;
10204 ++ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
10205 ++ goto bad_area;
10206 + switch (error_code & (PF_PROT|PF_WRITE)) {
10207 + default: /* 3: write, present */
10208 + /* fall through */
10209 +@@ -785,6 +934,54 @@ bad_area:
10210 + up_read(&mm->mmap_sem);
10211 +
10212 + bad_area_nosemaphore:
10213 ++
10214 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10215 ++ if (mm && (error_code & PF_USER)) {
10216 ++ unsigned long ip = regs->ip;
10217 ++
10218 ++ if (v8086_mode(regs))
10219 ++ ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff);
10220 ++
10221 ++ /*
10222 ++ * It's possible to have interrupts off here.
10223 ++ */
10224 ++ local_irq_enable();
10225 ++
10226 ++#ifdef CONFIG_PAX_PAGEEXEC
10227 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
10228 ++ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) {
10229 ++
10230 ++#ifdef CONFIG_PAX_EMUTRAMP
10231 ++ switch (pax_handle_fetch_fault(regs)) {
10232 ++ case 2:
10233 ++ return;
10234 ++ }
10235 ++#endif
10236 ++
10237 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10238 ++ do_group_exit(SIGKILL);
10239 ++ }
10240 ++#endif
10241 ++
10242 ++#ifdef CONFIG_PAX_SEGMEXEC
10243 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) {
10244 ++
10245 ++#ifdef CONFIG_PAX_EMUTRAMP
10246 ++ switch (pax_handle_fetch_fault(regs)) {
10247 ++ case 2:
10248 ++ return;
10249 ++ }
10250 ++#endif
10251 ++
10252 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10253 ++ do_group_exit(SIGKILL);
10254 ++ }
10255 ++#endif
10256 ++
10257 ++ }
10258 ++#endif
10259 ++
10260 ++bad_area_nopax:
10261 + /* User mode accesses just cause a SIGSEGV */
10262 + if (error_code & PF_USER) {
10263 + /*
10264 +@@ -863,7 +1060,7 @@ no_context:
10265 + #ifdef CONFIG_X86_32
10266 + die("Oops", regs, error_code);
10267 + bust_spinlocks(0);
10268 +- do_exit(SIGKILL);
10269 ++ do_group_exit(SIGKILL);
10270 + #else
10271 + if (__die("Oops", regs, error_code))
10272 + regs = NULL;
10273 +@@ -877,17 +1074,17 @@ no_context:
10274 + * us unable to handle the page fault gracefully.
10275 + */
10276 + out_of_memory:
10277 +- up_read(&mm->mmap_sem);
10278 + if (is_global_init(tsk)) {
10279 + yield();
10280 + #ifdef CONFIG_X86_32
10281 +- down_read(&mm->mmap_sem);
10282 + goto survive;
10283 + #else
10284 ++ up_read(&mm->mmap_sem);
10285 + goto again;
10286 + #endif
10287 + }
10288 +
10289 ++ up_read(&mm->mmap_sem);
10290 + printk("VM: killing process %s\n", tsk->comm);
10291 + if (error_code & PF_USER)
10292 + do_group_exit(SIGKILL);
10293 +@@ -959,3 +1156,174 @@ void vmalloc_sync_all(void)
10294 + }
10295 + #endif
10296 + }
10297 ++
10298 ++#ifdef CONFIG_PAX_EMUTRAMP
10299 ++static int pax_handle_fetch_fault_32(struct pt_regs *regs)
10300 ++{
10301 ++ int err;
10302 ++
10303 ++ do { /* PaX: gcc trampoline emulation #1 */
10304 ++ unsigned char mov1, mov2;
10305 ++ unsigned short jmp;
10306 ++ unsigned int addr1, addr2;
10307 ++
10308 ++#ifdef CONFIG_X86_64
10309 ++ if ((regs->ip + 11) >> 32)
10310 ++ break;
10311 ++#endif
10312 ++
10313 ++ err = get_user(mov1, (unsigned char __user *)regs->ip);
10314 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10315 ++ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
10316 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10317 ++ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
10318 ++
10319 ++ if (err)
10320 ++ break;
10321 ++
10322 ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
10323 ++ regs->cx = addr1;
10324 ++ regs->ax = addr2;
10325 ++ regs->ip = addr2;
10326 ++ return 2;
10327 ++ }
10328 ++ } while (0);
10329 ++
10330 ++ do { /* PaX: gcc trampoline emulation #2 */
10331 ++ unsigned char mov, jmp;
10332 ++ unsigned int addr1, addr2;
10333 ++
10334 ++#ifdef CONFIG_X86_64
10335 ++ if ((regs->ip + 9) >> 32)
10336 ++ break;
10337 ++#endif
10338 ++
10339 ++ err = get_user(mov, (unsigned char __user *)regs->ip);
10340 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10341 ++ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
10342 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10343 ++
10344 ++ if (err)
10345 ++ break;
10346 ++
10347 ++ if (mov == 0xB9 && jmp == 0xE9) {
10348 ++ regs->cx = addr1;
10349 ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
10350 ++ return 2;
10351 ++ }
10352 ++ } while (0);
10353 ++
10354 ++ return 1; /* PaX in action */
10355 ++}
10356 ++
10357 ++#ifdef CONFIG_X86_64
10358 ++static int pax_handle_fetch_fault_64(struct pt_regs *regs)
10359 ++{
10360 ++ int err;
10361 ++
10362 ++ do { /* PaX: gcc trampoline emulation #1 */
10363 ++ unsigned short mov1, mov2, jmp1;
10364 ++ unsigned char jmp2;
10365 ++ unsigned int addr1;
10366 ++ unsigned long addr2;
10367 ++
10368 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10369 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
10370 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
10371 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
10372 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
10373 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
10374 ++
10375 ++ if (err)
10376 ++ break;
10377 ++
10378 ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10379 ++ regs->r11 = addr1;
10380 ++ regs->r10 = addr2;
10381 ++ regs->ip = addr1;
10382 ++ return 2;
10383 ++ }
10384 ++ } while (0);
10385 ++
10386 ++ do { /* PaX: gcc trampoline emulation #2 */
10387 ++ unsigned short mov1, mov2, jmp1;
10388 ++ unsigned char jmp2;
10389 ++ unsigned long addr1, addr2;
10390 ++
10391 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10392 ++ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
10393 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
10394 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
10395 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
10396 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
10397 ++
10398 ++ if (err)
10399 ++ break;
10400 ++
10401 ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10402 ++ regs->r11 = addr1;
10403 ++ regs->r10 = addr2;
10404 ++ regs->ip = addr1;
10405 ++ return 2;
10406 ++ }
10407 ++ } while (0);
10408 ++
10409 ++ return 1; /* PaX in action */
10410 ++}
10411 ++#endif
10412 ++
10413 ++/*
10414 ++ * PaX: decide what to do with offenders (regs->ip = fault address)
10415 ++ *
10416 ++ * returns 1 when task should be killed
10417 ++ * 2 when gcc trampoline was detected
10418 ++ */
10419 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
10420 ++{
10421 ++ if (v8086_mode(regs))
10422 ++ return 1;
10423 ++
10424 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
10425 ++ return 1;
10426 ++
10427 ++#ifdef CONFIG_X86_32
10428 ++ return pax_handle_fetch_fault_32(regs);
10429 ++#else
10430 ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
10431 ++ return pax_handle_fetch_fault_32(regs);
10432 ++ else
10433 ++ return pax_handle_fetch_fault_64(regs);
10434 ++#endif
10435 ++}
10436 ++#endif
10437 ++
10438 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10439 ++void pax_report_insns(void *pc, void *sp)
10440 ++{
10441 ++ long i;
10442 ++
10443 ++ printk(KERN_ERR "PAX: bytes at PC: ");
10444 ++ for (i = 0; i < 20; i++) {
10445 ++ unsigned char c;
10446 ++ if (get_user(c, (unsigned char __user *)pc+i))
10447 ++ printk(KERN_CONT "?? ");
10448 ++ else
10449 ++ printk(KERN_CONT "%02x ", c);
10450 ++ }
10451 ++ printk("\n");
10452 ++
10453 ++ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
10454 ++ for (i = -1; i < 80 / sizeof(long); i++) {
10455 ++ unsigned long c;
10456 ++ if (get_user(c, (unsigned long __user *)sp+i))
10457 ++#ifdef CONFIG_X86_32
10458 ++ printk(KERN_CONT "???????? ");
10459 ++#else
10460 ++ printk(KERN_CONT "???????????????? ");
10461 ++#endif
10462 ++ else
10463 ++ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
10464 ++ }
10465 ++ printk("\n");
10466 ++}
10467 ++#endif
10468 +diff -urNp linux-2.6.27.10/arch/x86/mm/highmem_32.c linux-2.6.27.10/arch/x86/mm/highmem_32.c
10469 +--- linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-07 12:55:34.000000000 -0500
10470 ++++ linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-18 03:38:44.000000000 -0500
10471 +@@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page
10472 + enum fixed_addresses idx;
10473 + unsigned long vaddr;
10474 +
10475 ++#ifdef CONFIG_PAX_KERNEXEC
10476 ++ unsigned long cr0;
10477 ++#endif
10478 ++
10479 + /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
10480 + pagefault_disable();
10481 +
10482 +@@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page
10483 + idx = type + KM_TYPE_NR*smp_processor_id();
10484 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10485 + BUG_ON(!pte_none(*(kmap_pte-idx)));
10486 ++
10487 ++#ifdef CONFIG_PAX_KERNEXEC
10488 ++ pax_open_kernel(cr0);
10489 ++#endif
10490 ++
10491 + set_pte(kmap_pte-idx, mk_pte(page, prot));
10492 ++
10493 ++#ifdef CONFIG_PAX_KERNEXEC
10494 ++ pax_close_kernel(cr0);
10495 ++#endif
10496 ++
10497 + arch_flush_lazy_mmu_mode();
10498 +
10499 + return (void *)vaddr;
10500 +@@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km
10501 + unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
10502 + enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
10503 +
10504 ++#ifdef CONFIG_PAX_KERNEXEC
10505 ++ unsigned long cr0;
10506 ++#endif
10507 ++
10508 + /*
10509 + * Force other mappings to Oops if they'll try to access this pte
10510 + * without first remap it. Keeping stale mappings around is a bad idea
10511 + * also, in case the page changes cacheability attributes or becomes
10512 + * a protected page in a hypervisor.
10513 + */
10514 +- if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
10515 ++ if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) {
10516 ++
10517 ++#ifdef CONFIG_PAX_KERNEXEC
10518 ++ pax_open_kernel(cr0);
10519 ++#endif
10520 ++
10521 + kpte_clear_flush(kmap_pte-idx, vaddr);
10522 +- else {
10523 ++
10524 ++#ifdef CONFIG_PAX_KERNEXEC
10525 ++ pax_close_kernel(cr0);
10526 ++#endif
10527 ++
10528 ++ } else {
10529 + #ifdef CONFIG_DEBUG_HIGHMEM
10530 + BUG_ON(vaddr < PAGE_OFFSET);
10531 + BUG_ON(vaddr >= (unsigned long)high_memory);
10532 +@@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn,
10533 + enum fixed_addresses idx;
10534 + unsigned long vaddr;
10535 +
10536 ++#ifdef CONFIG_PAX_KERNEXEC
10537 ++ unsigned long cr0;
10538 ++#endif
10539 ++
10540 + pagefault_disable();
10541 +
10542 + idx = type + KM_TYPE_NR*smp_processor_id();
10543 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10544 ++
10545 ++#ifdef CONFIG_PAX_KERNEXEC
10546 ++ pax_open_kernel(cr0);
10547 ++#endif
10548 ++
10549 + set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
10550 ++
10551 ++#ifdef CONFIG_PAX_KERNEXEC
10552 ++ pax_close_kernel(cr0);
10553 ++#endif
10554 ++
10555 + arch_flush_lazy_mmu_mode();
10556 +
10557 + return (void*) vaddr;
10558 +diff -urNp linux-2.6.27.10/arch/x86/mm/hugetlbpage.c linux-2.6.27.10/arch/x86/mm/hugetlbpage.c
10559 +--- linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-07 12:55:34.000000000 -0500
10560 ++++ linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-18 03:38:44.000000000 -0500
10561 +@@ -263,13 +263,18 @@ static unsigned long hugetlb_get_unmappe
10562 + struct hstate *h = hstate_file(file);
10563 + struct mm_struct *mm = current->mm;
10564 + struct vm_area_struct *vma;
10565 +- unsigned long start_addr;
10566 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
10567 ++
10568 ++#ifdef CONFIG_PAX_SEGMEXEC
10569 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10570 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10571 ++#endif
10572 +
10573 + if (len > mm->cached_hole_size) {
10574 +- start_addr = mm->free_area_cache;
10575 ++ start_addr = mm->free_area_cache;
10576 + } else {
10577 +- start_addr = TASK_UNMAPPED_BASE;
10578 +- mm->cached_hole_size = 0;
10579 ++ start_addr = mm->mmap_base;
10580 ++ mm->cached_hole_size = 0;
10581 + }
10582 +
10583 + full_search:
10584 +@@ -277,13 +282,13 @@ full_search:
10585 +
10586 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
10587 + /* At this point: (!vma || addr < vma->vm_end). */
10588 +- if (TASK_SIZE - len < addr) {
10589 ++ if (pax_task_size - len < addr) {
10590 + /*
10591 + * Start a new search - just in case we missed
10592 + * some holes.
10593 + */
10594 +- if (start_addr != TASK_UNMAPPED_BASE) {
10595 +- start_addr = TASK_UNMAPPED_BASE;
10596 ++ if (start_addr != mm->mmap_base) {
10597 ++ start_addr = mm->mmap_base;
10598 + mm->cached_hole_size = 0;
10599 + goto full_search;
10600 + }
10601 +@@ -306,9 +311,8 @@ static unsigned long hugetlb_get_unmappe
10602 + struct hstate *h = hstate_file(file);
10603 + struct mm_struct *mm = current->mm;
10604 + struct vm_area_struct *vma, *prev_vma;
10605 +- unsigned long base = mm->mmap_base, addr = addr0;
10606 ++ unsigned long base = mm->mmap_base, addr;
10607 + unsigned long largest_hole = mm->cached_hole_size;
10608 +- int first_time = 1;
10609 +
10610 + /* don't allow allocations above current base */
10611 + if (mm->free_area_cache > base)
10612 +@@ -318,7 +322,7 @@ static unsigned long hugetlb_get_unmappe
10613 + largest_hole = 0;
10614 + mm->free_area_cache = base;
10615 + }
10616 +-try_again:
10617 ++
10618 + /* make sure it can fit in the remaining address space */
10619 + if (mm->free_area_cache < len)
10620 + goto fail;
10621 +@@ -360,22 +364,26 @@ try_again:
10622 +
10623 + fail:
10624 + /*
10625 +- * if hint left us with no space for the requested
10626 +- * mapping then try again:
10627 +- */
10628 +- if (first_time) {
10629 +- mm->free_area_cache = base;
10630 +- largest_hole = 0;
10631 +- first_time = 0;
10632 +- goto try_again;
10633 +- }
10634 +- /*
10635 + * A failed mmap() very likely causes application failure,
10636 + * so fall back to the bottom-up function here. This scenario
10637 + * can happen with large stack limits and large mmap()
10638 + * allocations.
10639 + */
10640 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
10641 ++
10642 ++#ifdef CONFIG_PAX_SEGMEXEC
10643 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10644 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
10645 ++ else
10646 ++#endif
10647 ++
10648 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
10649 ++
10650 ++#ifdef CONFIG_PAX_RANDMMAP
10651 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
10652 ++ mm->mmap_base += mm->delta_mmap;
10653 ++#endif
10654 ++
10655 ++ mm->free_area_cache = mm->mmap_base;
10656 + mm->cached_hole_size = ~0UL;
10657 + addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
10658 + len, pgoff, flags);
10659 +@@ -383,6 +391,7 @@ fail:
10660 + /*
10661 + * Restore the topdown base:
10662 + */
10663 ++ mm->mmap_base = base;
10664 + mm->free_area_cache = base;
10665 + mm->cached_hole_size = ~0UL;
10666 +
10667 +@@ -396,10 +405,17 @@ hugetlb_get_unmapped_area(struct file *f
10668 + struct hstate *h = hstate_file(file);
10669 + struct mm_struct *mm = current->mm;
10670 + struct vm_area_struct *vma;
10671 ++ unsigned long pax_task_size = TASK_SIZE;
10672 +
10673 + if (len & ~huge_page_mask(h))
10674 + return -EINVAL;
10675 +- if (len > TASK_SIZE)
10676 ++
10677 ++#ifdef CONFIG_PAX_SEGMEXEC
10678 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10679 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10680 ++#endif
10681 ++
10682 ++ if (len > pax_task_size)
10683 + return -ENOMEM;
10684 +
10685 + if (flags & MAP_FIXED) {
10686 +@@ -411,7 +427,7 @@ hugetlb_get_unmapped_area(struct file *f
10687 + if (addr) {
10688 + addr = ALIGN(addr, huge_page_size(h));
10689 + vma = find_vma(mm, addr);
10690 +- if (TASK_SIZE - len >= addr &&
10691 ++ if (pax_task_size - len >= addr &&
10692 + (!vma || addr + len <= vma->vm_start))
10693 + return addr;
10694 + }
10695 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_32.c linux-2.6.27.10/arch/x86/mm/init_32.c
10696 +--- linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-07 12:55:34.000000000 -0500
10697 ++++ linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-18 03:38:44.000000000 -0500
10698 +@@ -47,6 +47,7 @@
10699 + #include <asm/paravirt.h>
10700 + #include <asm/setup.h>
10701 + #include <asm/cacheflush.h>
10702 ++#include <asm/desc.h>
10703 +
10704 + unsigned int __VMALLOC_RESERVE = 128 << 20;
10705 +
10706 +@@ -80,35 +81,6 @@ static __init void *alloc_low_page(unsig
10707 + }
10708 +
10709 + /*
10710 +- * Creates a middle page table and puts a pointer to it in the
10711 +- * given global directory entry. This only returns the gd entry
10712 +- * in non-PAE compilation mode, since the middle layer is folded.
10713 +- */
10714 +-static pmd_t * __init one_md_table_init(pgd_t *pgd)
10715 +-{
10716 +- pud_t *pud;
10717 +- pmd_t *pmd_table;
10718 +-
10719 +-#ifdef CONFIG_X86_PAE
10720 +- unsigned long phys;
10721 +- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
10722 +- if (after_init_bootmem)
10723 +- pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
10724 +- else
10725 +- pmd_table = (pmd_t *)alloc_low_page(&phys);
10726 +- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
10727 +- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
10728 +- pud = pud_offset(pgd, 0);
10729 +- BUG_ON(pmd_table != pmd_offset(pud, 0));
10730 +- }
10731 +-#endif
10732 +- pud = pud_offset(pgd, 0);
10733 +- pmd_table = pmd_offset(pud, 0);
10734 +-
10735 +- return pmd_table;
10736 +-}
10737 +-
10738 +-/*
10739 + * Create a page table and place a pointer to it in a middle page
10740 + * directory entry:
10741 + */
10742 +@@ -130,7 +102,11 @@ static pte_t * __init one_page_table_ini
10743 + }
10744 +
10745 + paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
10746 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10747 ++ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
10748 ++#else
10749 + set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
10750 ++#endif
10751 + BUG_ON(page_table != pte_offset_kernel(pmd, 0));
10752 + }
10753 +
10754 +@@ -152,6 +128,7 @@ page_table_range_init(unsigned long star
10755 + int pgd_idx, pmd_idx;
10756 + unsigned long vaddr;
10757 + pgd_t *pgd;
10758 ++ pud_t *pud;
10759 + pmd_t *pmd;
10760 +
10761 + vaddr = start;
10762 +@@ -160,8 +137,13 @@ page_table_range_init(unsigned long star
10763 + pgd = pgd_base + pgd_idx;
10764 +
10765 + for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
10766 +- pmd = one_md_table_init(pgd);
10767 +- pmd = pmd + pmd_index(vaddr);
10768 ++ pud = pud_offset(pgd, vaddr);
10769 ++ pmd = pmd_offset(pud, vaddr);
10770 ++
10771 ++#ifdef CONFIG_X86_PAE
10772 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10773 ++#endif
10774 ++
10775 + for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
10776 + pmd++, pmd_idx++) {
10777 + one_page_table_init(pmd);
10778 +@@ -172,11 +154,23 @@ page_table_range_init(unsigned long star
10779 + }
10780 + }
10781 +
10782 +-static inline int is_kernel_text(unsigned long addr)
10783 ++static inline int is_kernel_text(unsigned long start, unsigned long end)
10784 + {
10785 +- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
10786 +- return 1;
10787 +- return 0;
10788 ++ unsigned long etext;
10789 ++
10790 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
10791 ++ etext = ktva_ktla((unsigned long)&MODULES_END);
10792 ++#else
10793 ++ etext = (unsigned long)&_etext;
10794 ++#endif
10795 ++
10796 ++ if ((start > ktla_ktva(etext) ||
10797 ++ end <= ktla_ktva((unsigned long)_stext)) &&
10798 ++ (start > ktla_ktva((unsigned long)_einittext) ||
10799 ++ end <= ktla_ktva((unsigned long)_sinittext)) &&
10800 ++ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
10801 ++ return 0;
10802 ++ return 1;
10803 + }
10804 +
10805 + /*
10806 +@@ -189,9 +183,10 @@ static void __init kernel_physical_mappi
10807 + unsigned long end_pfn,
10808 + int use_pse)
10809 + {
10810 +- int pgd_idx, pmd_idx, pte_ofs;
10811 ++ unsigned int pgd_idx, pmd_idx, pte_ofs;
10812 + unsigned long pfn;
10813 + pgd_t *pgd;
10814 ++ pud_t *pud;
10815 + pmd_t *pmd;
10816 + pte_t *pte;
10817 + unsigned pages_2m = 0, pages_4k = 0;
10818 +@@ -202,8 +197,13 @@ static void __init kernel_physical_mappi
10819 + pfn = start_pfn;
10820 + pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10821 + pgd = pgd_base + pgd_idx;
10822 +- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
10823 +- pmd = one_md_table_init(pgd);
10824 ++ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
10825 ++ pud = pud_offset(pgd, 0);
10826 ++ pmd = pmd_offset(pud, 0);
10827 ++
10828 ++#ifdef CONFIG_X86_PAE
10829 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10830 ++#endif
10831 +
10832 + if (pfn >= end_pfn)
10833 + continue;
10834 +@@ -215,21 +215,16 @@ static void __init kernel_physical_mappi
10835 + #endif
10836 + for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
10837 + pmd++, pmd_idx++) {
10838 +- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
10839 ++ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
10840 +
10841 + /*
10842 + * Map with big pages if possible, otherwise
10843 + * create normal page tables:
10844 + */
10845 + if (use_pse) {
10846 +- unsigned int addr2;
10847 + pgprot_t prot = PAGE_KERNEL_LARGE;
10848 +
10849 +- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
10850 +- PAGE_OFFSET + PAGE_SIZE-1;
10851 +-
10852 +- if (is_kernel_text(addr) ||
10853 +- is_kernel_text(addr2))
10854 ++ if (is_kernel_text(address, address + PMD_SIZE))
10855 + prot = PAGE_KERNEL_LARGE_EXEC;
10856 +
10857 + pages_2m++;
10858 +@@ -243,10 +238,10 @@ static void __init kernel_physical_mappi
10859 + pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10860 + pte += pte_ofs;
10861 + for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
10862 +- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
10863 ++ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
10864 + pgprot_t prot = PAGE_KERNEL;
10865 +
10866 +- if (is_kernel_text(addr))
10867 ++ if (is_kernel_text(address, address + PAGE_SIZE))
10868 + prot = PAGE_KERNEL_EXEC;
10869 +
10870 + pages_4k++;
10871 +@@ -270,7 +265,9 @@ static void __init kernel_physical_mappi
10872 + */
10873 + int devmem_is_allowed(unsigned long pagenr)
10874 + {
10875 +- if (pagenr <= 256)
10876 ++ if (!pagenr)
10877 ++ return 1;
10878 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
10879 + return 1;
10880 + if (!page_is_ram(pagenr))
10881 + return 1;
10882 +@@ -404,7 +401,7 @@ void __init native_pagetable_setup_start
10883 +
10884 + pud = pud_offset(pgd, va);
10885 + pmd = pmd_offset(pud, va);
10886 +- if (!pmd_present(*pmd))
10887 ++ if (!pmd_present(*pmd) || pmd_huge(*pmd))
10888 + break;
10889 +
10890 + pte = pte_offset_kernel(pmd, va);
10891 +@@ -456,9 +453,7 @@ static void __init early_ioremap_page_ta
10892 +
10893 + static void __init pagetable_init(void)
10894 + {
10895 +- pgd_t *pgd_base = swapper_pg_dir;
10896 +-
10897 +- permanent_kmaps_init(pgd_base);
10898 ++ permanent_kmaps_init(swapper_pg_dir);
10899 + }
10900 +
10901 + #ifdef CONFIG_ACPI_SLEEP
10902 +@@ -466,12 +461,12 @@ static void __init pagetable_init(void)
10903 + * ACPI suspend needs this for resume, because things like the intel-agp
10904 + * driver might have split up a kernel 4MB mapping.
10905 + */
10906 +-char swsusp_pg_dir[PAGE_SIZE]
10907 ++pgd_t swsusp_pg_dir[PTRS_PER_PGD]
10908 + __attribute__ ((aligned(PAGE_SIZE)));
10909 +
10910 + static inline void save_pg_dir(void)
10911 + {
10912 +- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
10913 ++ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
10914 + }
10915 + #else /* !CONFIG_ACPI_SLEEP */
10916 + static inline void save_pg_dir(void)
10917 +@@ -501,13 +496,11 @@ void zap_low_mappings(void)
10918 +
10919 + int nx_enabled;
10920 +
10921 +-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
10922 ++pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
10923 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
10924 +
10925 + #ifdef CONFIG_X86_PAE
10926 +
10927 +-static int disable_nx __initdata;
10928 +-
10929 + /*
10930 + * noexec = on|off
10931 + *
10932 +@@ -516,40 +509,33 @@ static int disable_nx __initdata;
10933 + * on Enable
10934 + * off Disable
10935 + */
10936 ++#if !defined(CONFIG_PAX_PAGEEXEC)
10937 + static int __init noexec_setup(char *str)
10938 + {
10939 + if (!str || !strcmp(str, "on")) {
10940 +- if (cpu_has_nx) {
10941 +- __supported_pte_mask |= _PAGE_NX;
10942 +- disable_nx = 0;
10943 +- }
10944 ++ if (cpu_has_nx)
10945 ++ nx_enabled = 1;
10946 + } else {
10947 +- if (!strcmp(str, "off")) {
10948 +- disable_nx = 1;
10949 +- __supported_pte_mask &= ~_PAGE_NX;
10950 +- } else {
10951 ++ if (!strcmp(str, "off"))
10952 ++ nx_enabled = 0;
10953 ++ else
10954 + return -EINVAL;
10955 +- }
10956 + }
10957 +
10958 + return 0;
10959 + }
10960 + early_param("noexec", noexec_setup);
10961 ++#endif
10962 +
10963 + static void __init set_nx(void)
10964 + {
10965 +- unsigned int v[4], l, h;
10966 +-
10967 +- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
10968 +- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
10969 ++ if (!nx_enabled && cpu_has_nx) {
10970 ++ unsigned l, h;
10971 +
10972 +- if ((v[3] & (1 << 20)) && !disable_nx) {
10973 +- rdmsr(MSR_EFER, l, h);
10974 +- l |= EFER_NX;
10975 +- wrmsr(MSR_EFER, l, h);
10976 +- nx_enabled = 1;
10977 +- __supported_pte_mask |= _PAGE_NX;
10978 +- }
10979 ++ __supported_pte_mask &= ~_PAGE_NX;
10980 ++ rdmsr(MSR_EFER, l, h);
10981 ++ l &= ~EFER_NX;
10982 ++ wrmsr(MSR_EFER, l, h);
10983 + }
10984 + }
10985 + #endif
10986 +@@ -920,7 +906,7 @@ void __init mem_init(void)
10987 + set_highmem_pages_init();
10988 +
10989 + codesize = (unsigned long) &_etext - (unsigned long) &_text;
10990 +- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
10991 ++ datasize = (unsigned long) &_edata - (unsigned long) &_data;
10992 + initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
10993 +
10994 + kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
10995 +@@ -966,10 +952,10 @@ void __init mem_init(void)
10996 + ((unsigned long)&__init_end -
10997 + (unsigned long)&__init_begin) >> 10,
10998 +
10999 +- (unsigned long)&_etext, (unsigned long)&_edata,
11000 +- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
11001 ++ (unsigned long)&_data, (unsigned long)&_edata,
11002 ++ ((unsigned long)&_edata - (unsigned long)&_data) >> 10,
11003 +
11004 +- (unsigned long)&_text, (unsigned long)&_etext,
11005 ++ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
11006 + ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
11007 +
11008 + #ifdef CONFIG_HIGHMEM
11009 +@@ -1099,6 +1085,46 @@ void free_init_pages(char *what, unsigne
11010 +
11011 + void free_initmem(void)
11012 + {
11013 ++
11014 ++#ifdef CONFIG_PAX_KERNEXEC
11015 ++ /* PaX: limit KERNEL_CS to actual size */
11016 ++ unsigned long addr, limit;
11017 ++ struct desc_struct d;
11018 ++ int cpu;
11019 ++ pgd_t *pgd;
11020 ++ pud_t *pud;
11021 ++ pmd_t *pmd;
11022 ++
11023 ++#ifdef CONFIG_MODULES
11024 ++ limit = ktva_ktla((unsigned long)&MODULES_END);
11025 ++#else
11026 ++ limit = (unsigned long)&_etext;
11027 ++#endif
11028 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
11029 ++
11030 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
11031 ++ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
11032 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
11033 ++ }
11034 ++
11035 ++ /* PaX: make KERNEL_CS read-only */
11036 ++ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) {
11037 ++ pgd = pgd_offset_k(addr);
11038 ++ pud = pud_offset(pgd, addr);
11039 ++ pmd = pmd_offset(pud, addr);
11040 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11041 ++ }
11042 ++#ifdef CONFIG_X86_PAE
11043 ++ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
11044 ++ pgd = pgd_offset_k(addr);
11045 ++ pud = pud_offset(pgd, addr);
11046 ++ pmd = pmd_offset(pud, addr);
11047 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11048 ++ }
11049 ++#endif
11050 ++ flush_tlb_all();
11051 ++#endif
11052 ++
11053 + free_init_pages("unused kernel memory",
11054 + (unsigned long)(&__init_begin),
11055 + (unsigned long)(&__init_end));
11056 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_64.c linux-2.6.27.10/arch/x86/mm/init_64.c
11057 +--- linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:16:51.000000000 -0500
11058 ++++ linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:13:45.000000000 -0500
11059 +@@ -118,6 +118,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
11060 + pmd_t *pmd;
11061 + pte_t *pte;
11062 +
11063 ++#ifdef CONFIG_PAX_KERNEXEC
11064 ++ unsigned long cr0;
11065 ++#endif
11066 ++
11067 + pud = pud_page + pud_index(vaddr);
11068 + if (pud_none(*pud)) {
11069 + pmd = (pmd_t *) spp_getpage();
11070 +@@ -142,8 +146,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
11071 + if (!pte_none(*pte) && pte_val(new_pte) &&
11072 + pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
11073 + pte_ERROR(*pte);
11074 ++
11075 ++#ifdef CONFIG_PAX_KERNEXEC
11076 ++ pax_open_kernel(cr0);
11077 ++#endif
11078 ++
11079 + set_pte(pte, new_pte);
11080 +
11081 ++#ifdef CONFIG_PAX_KERNEXEC
11082 ++ pax_close_kernel(cr0);
11083 ++#endif
11084 ++
11085 + /*
11086 + * It's enough to flush this one mapping.
11087 + * (PGE mappings get flushed as well)
11088 +@@ -184,14 +197,12 @@ static void __init __init_extra_mapping(
11089 + pgd = pgd_offset_k((unsigned long)__va(phys));
11090 + if (pgd_none(*pgd)) {
11091 + pud = (pud_t *) spp_getpage();
11092 +- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
11093 +- _PAGE_USER));
11094 ++ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
11095 + }
11096 + pud = pud_offset(pgd, (unsigned long)__va(phys));
11097 + if (pud_none(*pud)) {
11098 + pmd = (pmd_t *) spp_getpage();
11099 +- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
11100 +- _PAGE_USER));
11101 ++ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
11102 + }
11103 + pmd = pmd_offset(pud, phys);
11104 + BUG_ON(!pmd_none(*pmd));
11105 +@@ -754,7 +765,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to
11106 + */
11107 + int devmem_is_allowed(unsigned long pagenr)
11108 + {
11109 +- if (pagenr <= 256)
11110 ++ if (!pagenr)
11111 ++ return 1;
11112 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11113 + return 1;
11114 + if (!page_is_ram(pagenr))
11115 + return 1;
11116 +@@ -842,6 +855,39 @@ void free_init_pages(char *what, unsigne
11117 +
11118 + void free_initmem(void)
11119 + {
11120 ++
11121 ++#ifdef CONFIG_PAX_KERNEXEC
11122 ++ unsigned long addr, end;
11123 ++ pgd_t *pgd;
11124 ++ pud_t *pud;
11125 ++ pmd_t *pmd;
11126 ++
11127 ++ /* PaX: make kernel code/rodata read-only, rest non-executable */
11128 ++ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
11129 ++ pgd = pgd_offset_k(addr);
11130 ++ pud = pud_offset(pgd, addr);
11131 ++ pmd = pmd_offset(pud, addr);
11132 ++ if ((unsigned long)_text <= addr && addr < (unsigned long)_data)
11133 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11134 ++ else
11135 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11136 ++ }
11137 ++
11138 ++ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
11139 ++ end = addr + KERNEL_IMAGE_SIZE;
11140 ++ for (; addr < end; addr += PMD_SIZE) {
11141 ++ pgd = pgd_offset_k(addr);
11142 ++ pud = pud_offset(pgd, addr);
11143 ++ pmd = pmd_offset(pud, addr);
11144 ++ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data)))
11145 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11146 ++ else
11147 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11148 ++ }
11149 ++
11150 ++ flush_tlb_all();
11151 ++#endif
11152 ++
11153 + free_init_pages("unused kernel memory",
11154 + (unsigned long)(&__init_begin),
11155 + (unsigned long)(&__init_end));
11156 +@@ -1014,7 +1060,7 @@ int in_gate_area_no_task(unsigned long a
11157 +
11158 + const char *arch_vma_name(struct vm_area_struct *vma)
11159 + {
11160 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11161 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11162 + return "[vdso]";
11163 + if (vma == &gate_vma)
11164 + return "[vsyscall]";
11165 +diff -urNp linux-2.6.27.10/arch/x86/mm/ioremap.c linux-2.6.27.10/arch/x86/mm/ioremap.c
11166 +--- linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-07 12:55:34.000000000 -0500
11167 ++++ linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-18 03:38:44.000000000 -0500
11168 +@@ -63,8 +63,8 @@ int page_is_ram(unsigned long pagenr)
11169 + * Second special case: Some BIOSen report the PC BIOS
11170 + * area (640->1Mb) as ram even though it is not.
11171 + */
11172 +- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
11173 +- pagenr < (BIOS_END >> PAGE_SHIFT))
11174 ++ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
11175 ++ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11176 + return 0;
11177 +
11178 + for (i = 0; i < e820.nr_map; i++) {
11179 +@@ -217,6 +217,8 @@ static void __iomem *__ioremap_caller(re
11180 + break;
11181 + }
11182 +
11183 ++ prot = canon_pgprot(prot);
11184 ++
11185 + /*
11186 + * Ok, go for it..
11187 + */
11188 +diff -urNp linux-2.6.27.10/arch/x86/mm/mmap.c linux-2.6.27.10/arch/x86/mm/mmap.c
11189 +--- linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
11190 ++++ linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-18 03:38:44.000000000 -0500
11191 +@@ -36,7 +36,7 @@
11192 + * Leave an at least ~128 MB hole.
11193 + */
11194 + #define MIN_GAP (128*1024*1024)
11195 +-#define MAX_GAP (TASK_SIZE/6*5)
11196 ++#define MAX_GAP (pax_task_size/6*5)
11197 +
11198 + /*
11199 + * True on X86_32 or when emulating IA32 on X86_64
11200 +@@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void)
11201 + return rnd << PAGE_SHIFT;
11202 + }
11203 +
11204 +-static unsigned long mmap_base(void)
11205 ++static unsigned long mmap_base(struct mm_struct *mm)
11206 + {
11207 + unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
11208 ++ unsigned long pax_task_size = TASK_SIZE;
11209 ++
11210 ++#ifdef CONFIG_PAX_SEGMEXEC
11211 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11212 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11213 ++#endif
11214 +
11215 + if (gap < MIN_GAP)
11216 + gap = MIN_GAP;
11217 + else if (gap > MAX_GAP)
11218 + gap = MAX_GAP;
11219 +
11220 +- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
11221 ++ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
11222 + }
11223 +
11224 + /*
11225 + * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
11226 + * does, but not when emulating X86_32
11227 + */
11228 +-static unsigned long mmap_legacy_base(void)
11229 ++static unsigned long mmap_legacy_base(struct mm_struct *mm)
11230 + {
11231 +- if (mmap_is_ia32())
11232 ++ if (mmap_is_ia32()) {
11233 ++
11234 ++#ifdef CONFIG_PAX_SEGMEXEC
11235 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11236 ++ return SEGMEXEC_TASK_UNMAPPED_BASE;
11237 ++ else
11238 ++#endif
11239 ++
11240 + return TASK_UNMAPPED_BASE;
11241 +- else
11242 ++ } else
11243 + return TASK_UNMAPPED_BASE + mmap_rnd();
11244 + }
11245 +
11246 +@@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo
11247 + void arch_pick_mmap_layout(struct mm_struct *mm)
11248 + {
11249 + if (mmap_is_legacy()) {
11250 +- mm->mmap_base = mmap_legacy_base();
11251 ++ mm->mmap_base = mmap_legacy_base(mm);
11252 ++
11253 ++#ifdef CONFIG_PAX_RANDMMAP
11254 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11255 ++ mm->mmap_base += mm->delta_mmap;
11256 ++#endif
11257 ++
11258 + mm->get_unmapped_area = arch_get_unmapped_area;
11259 + mm->unmap_area = arch_unmap_area;
11260 + } else {
11261 +- mm->mmap_base = mmap_base();
11262 ++ mm->mmap_base = mmap_base(mm);
11263 ++
11264 ++#ifdef CONFIG_PAX_RANDMMAP
11265 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11266 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11267 ++#endif
11268 ++
11269 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11270 + mm->unmap_area = arch_unmap_area_topdown;
11271 + }
11272 +diff -urNp linux-2.6.27.10/arch/x86/mm/pageattr.c linux-2.6.27.10/arch/x86/mm/pageattr.c
11273 +--- linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-07 12:55:34.000000000 -0500
11274 ++++ linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-18 03:38:44.000000000 -0500
11275 +@@ -20,6 +20,7 @@
11276 + #include <asm/pgalloc.h>
11277 + #include <asm/proto.h>
11278 + #include <asm/pat.h>
11279 ++#include <asm/desc.h>
11280 +
11281 + /*
11282 + * The current flushing context - we pass it instead of 5 arguments:
11283 +@@ -213,7 +214,7 @@ static inline pgprot_t static_protection
11284 + * Does not cover __inittext since that is gone later on. On
11285 + * 64bit we do not enforce !NX on the low mapping
11286 + */
11287 +- if (within(address, (unsigned long)_text, (unsigned long)_etext))
11288 ++ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
11289 + pgprot_val(forbidden) |= _PAGE_NX;
11290 +
11291 + /*
11292 +@@ -275,8 +276,20 @@ EXPORT_SYMBOL_GPL(lookup_address);
11293 + */
11294 + static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
11295 + {
11296 ++
11297 ++#ifdef CONFIG_PAX_KERNEXEC
11298 ++ unsigned long cr0;
11299 ++
11300 ++ pax_open_kernel(cr0);
11301 ++#endif
11302 ++
11303 + /* change init_mm */
11304 + set_pte_atomic(kpte, pte);
11305 ++
11306 ++#ifdef CONFIG_PAX_KERNEXEC
11307 ++ pax_close_kernel(cr0);
11308 ++#endif
11309 ++
11310 + #ifdef CONFIG_X86_32
11311 + if (!SHARED_KERNEL_PMD) {
11312 + struct page *page;
11313 +diff -urNp linux-2.6.27.10/arch/x86/mm/pat.c linux-2.6.27.10/arch/x86/mm/pat.c
11314 +--- linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-07 12:55:34.000000000 -0500
11315 ++++ linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-18 03:38:44.000000000 -0500
11316 +@@ -396,7 +396,7 @@ pgprot_t phys_mem_access_prot(struct fil
11317 + return vma_prot;
11318 + }
11319 +
11320 +-#ifdef CONFIG_STRICT_DEVMEM
11321 ++#ifndef CONFIG_STRICT_DEVMEM
11322 + /* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
11323 + static inline int range_is_allowed(unsigned long pfn, unsigned long size)
11324 + {
11325 +diff -urNp linux-2.6.27.10/arch/x86/mm/pgtable_32.c linux-2.6.27.10/arch/x86/mm/pgtable_32.c
11326 +--- linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-07 12:55:34.000000000 -0500
11327 ++++ linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-18 03:38:44.000000000 -0500
11328 +@@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr,
11329 + pmd_t *pmd;
11330 + pte_t *pte;
11331 +
11332 ++#ifdef CONFIG_PAX_KERNEXEC
11333 ++ unsigned long cr0;
11334 ++#endif
11335 ++
11336 + pgd = swapper_pg_dir + pgd_index(vaddr);
11337 + if (pgd_none(*pgd)) {
11338 + BUG();
11339 +@@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr,
11340 + return;
11341 + }
11342 + pte = pte_offset_kernel(pmd, vaddr);
11343 ++
11344 ++#ifdef CONFIG_PAX_KERNEXEC
11345 ++ pax_open_kernel(cr0);
11346 ++#endif
11347 ++
11348 + if (pte_val(pteval))
11349 + set_pte_present(&init_mm, vaddr, pte, pteval);
11350 + else
11351 + pte_clear(&init_mm, vaddr, pte);
11352 +
11353 ++#ifdef CONFIG_PAX_KERNEXEC
11354 ++ pax_close_kernel(cr0);
11355 ++#endif
11356 ++
11357 + /*
11358 + * It's enough to flush this one mapping.
11359 + * (PGE mappings get flushed as well)
11360 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/backtrace.c linux-2.6.27.10/arch/x86/oprofile/backtrace.c
11361 +--- linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-07 12:55:34.000000000 -0500
11362 ++++ linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-18 03:38:44.000000000 -0500
11363 +@@ -37,7 +37,7 @@ static void backtrace_address(void *data
11364 + unsigned int *depth = data;
11365 +
11366 + if ((*depth)--)
11367 +- oprofile_add_trace(addr);
11368 ++ oprofile_add_trace(ktla_ktva(addr));
11369 + }
11370 +
11371 + static struct stacktrace_ops backtrace_ops = {
11372 +@@ -79,7 +79,7 @@ x86_backtrace(struct pt_regs * const reg
11373 + struct frame_head *head = (struct frame_head *)frame_pointer(regs);
11374 + unsigned long stack = kernel_trap_sp(regs);
11375 +
11376 +- if (!user_mode_vm(regs)) {
11377 ++ if (!user_mode(regs)) {
11378 + if (depth)
11379 + dump_trace(NULL, regs, (unsigned long *)stack, 0,
11380 + &backtrace_ops, &depth);
11381 +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
11382 +--- linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-07 12:55:34.000000000 -0500
11383 ++++ linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-18 03:38:44.000000000 -0500
11384 +@@ -47,7 +47,7 @@ static inline void setup_num_counters(vo
11385 + #endif
11386 + }
11387 +
11388 +-static int inline addr_increment(void)
11389 ++static inline int addr_increment(void)
11390 + {
11391 + #ifdef CONFIG_SMP
11392 + return smp_num_siblings == 2 ? 2 : 1;
11393 +diff -urNp linux-2.6.27.10/arch/x86/pci/common.c linux-2.6.27.10/arch/x86/pci/common.c
11394 +--- linux-2.6.27.10/arch/x86/pci/common.c 2008-11-07 12:55:34.000000000 -0500
11395 ++++ linux-2.6.27.10/arch/x86/pci/common.c 2008-11-18 03:38:44.000000000 -0500
11396 +@@ -362,7 +362,7 @@ static struct dmi_system_id __devinitdat
11397 + DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
11398 + },
11399 + },
11400 +- {}
11401 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
11402 + };
11403 +
11404 + void __init dmi_check_pciprobe(void)
11405 +diff -urNp linux-2.6.27.10/arch/x86/pci/fixup.c linux-2.6.27.10/arch/x86/pci/fixup.c
11406 +--- linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-07 12:55:34.000000000 -0500
11407 ++++ linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-18 03:38:44.000000000 -0500
11408 +@@ -365,7 +365,7 @@ static struct dmi_system_id __devinitdat
11409 + DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
11410 + },
11411 + },
11412 +- {}
11413 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11414 + };
11415 +
11416 + /*
11417 +@@ -436,7 +436,7 @@ static struct dmi_system_id __devinitdat
11418 + DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
11419 + },
11420 + },
11421 +- { }
11422 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11423 + };
11424 +
11425 + static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
11426 +diff -urNp linux-2.6.27.10/arch/x86/pci/irq.c linux-2.6.27.10/arch/x86/pci/irq.c
11427 +--- linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-07 12:55:34.000000000 -0500
11428 ++++ linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-18 03:38:44.000000000 -0500
11429 +@@ -544,7 +544,7 @@ static __init int intel_router_probe(str
11430 + static struct pci_device_id __initdata pirq_440gx[] = {
11431 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
11432 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
11433 +- { },
11434 ++ { PCI_DEVICE(0, 0) }
11435 + };
11436 +
11437 + /* 440GX has a proprietary PIRQ router -- don't use it */
11438 +@@ -1131,7 +1131,7 @@ static struct dmi_system_id __initdata p
11439 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
11440 + },
11441 + },
11442 +- { }
11443 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11444 + };
11445 +
11446 + int __init pcibios_irq_init(void)
11447 +diff -urNp linux-2.6.27.10/arch/x86/pci/pcbios.c linux-2.6.27.10/arch/x86/pci/pcbios.c
11448 +--- linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-07 12:55:34.000000000 -0500
11449 ++++ linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-18 03:38:44.000000000 -0500
11450 +@@ -57,50 +57,120 @@ union bios32 {
11451 + static struct {
11452 + unsigned long address;
11453 + unsigned short segment;
11454 +-} bios32_indirect = { 0, __KERNEL_CS };
11455 ++} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
11456 +
11457 + /*
11458 + * Returns the entry point for the given service, NULL on error
11459 + */
11460 +
11461 +-static unsigned long bios32_service(unsigned long service)
11462 ++static unsigned long __devinit bios32_service(unsigned long service)
11463 + {
11464 + unsigned char return_code; /* %al */
11465 + unsigned long address; /* %ebx */
11466 + unsigned long length; /* %ecx */
11467 + unsigned long entry; /* %edx */
11468 + unsigned long flags;
11469 ++ struct desc_struct d, *gdt;
11470 ++
11471 ++#ifdef CONFIG_PAX_KERNEXEC
11472 ++ unsigned long cr0;
11473 ++#endif
11474 +
11475 + local_irq_save(flags);
11476 +- __asm__("lcall *(%%edi); cld"
11477 ++
11478 ++ gdt = get_cpu_gdt_table(smp_processor_id());
11479 ++
11480 ++#ifdef CONFIG_PAX_KERNEXEC
11481 ++ pax_open_kernel(cr0);
11482 ++#endif
11483 ++
11484 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
11485 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11486 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
11487 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11488 ++
11489 ++#ifdef CONFIG_PAX_KERNEXEC
11490 ++ pax_close_kernel(cr0);
11491 ++#endif
11492 ++
11493 ++ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
11494 + : "=a" (return_code),
11495 + "=b" (address),
11496 + "=c" (length),
11497 + "=d" (entry)
11498 + : "0" (service),
11499 + "1" (0),
11500 +- "D" (&bios32_indirect));
11501 ++ "D" (&bios32_indirect),
11502 ++ "r"(__PCIBIOS_DS)
11503 ++ : "memory");
11504 ++
11505 ++#ifdef CONFIG_PAX_KERNEXEC
11506 ++ pax_open_kernel(cr0);
11507 ++#endif
11508 ++
11509 ++ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
11510 ++ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
11511 ++ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
11512 ++ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
11513 ++
11514 ++#ifdef CONFIG_PAX_KERNEXEC
11515 ++ pax_close_kernel(cr0);
11516 ++#endif
11517 ++
11518 + local_irq_restore(flags);
11519 +
11520 + switch (return_code) {
11521 +- case 0:
11522 +- return address + entry;
11523 +- case 0x80: /* Not present */
11524 +- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11525 +- return 0;
11526 +- default: /* Shouldn't happen */
11527 +- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11528 +- service, return_code);
11529 ++ case 0: {
11530 ++ int cpu;
11531 ++ unsigned char flags;
11532 ++
11533 ++ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
11534 ++ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
11535 ++ printk(KERN_WARNING "bios32_service: not valid\n");
11536 + return 0;
11537 ++ }
11538 ++ address = address + PAGE_OFFSET;
11539 ++ length += 16UL; /* some BIOSs underreport this... */
11540 ++ flags = 4;
11541 ++ if (length >= 64*1024*1024) {
11542 ++ length >>= PAGE_SHIFT;
11543 ++ flags |= 8;
11544 ++ }
11545 ++
11546 ++#ifdef CONFIG_PAX_KERNEXEC
11547 ++ pax_open_kernel(cr0);
11548 ++#endif
11549 ++
11550 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
11551 ++ gdt = get_cpu_gdt_table(cpu);
11552 ++ pack_descriptor(&d, address, length, 0x9b, flags);
11553 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11554 ++ pack_descriptor(&d, address, length, 0x93, flags);
11555 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11556 ++ }
11557 ++
11558 ++#ifdef CONFIG_PAX_KERNEXEC
11559 ++ pax_close_kernel(cr0);
11560 ++#endif
11561 ++
11562 ++ return entry;
11563 ++ }
11564 ++ case 0x80: /* Not present */
11565 ++ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11566 ++ return 0;
11567 ++ default: /* Shouldn't happen */
11568 ++ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11569 ++ service, return_code);
11570 ++ return 0;
11571 + }
11572 + }
11573 +
11574 + static struct {
11575 + unsigned long address;
11576 + unsigned short segment;
11577 +-} pci_indirect = { 0, __KERNEL_CS };
11578 ++} pci_indirect __read_only = { 0, __PCIBIOS_CS };
11579 +
11580 +-static int pci_bios_present;
11581 ++static int pci_bios_present __read_only;
11582 +
11583 + static int __devinit check_pcibios(void)
11584 + {
11585 +@@ -109,11 +179,13 @@ static int __devinit check_pcibios(void)
11586 + unsigned long flags, pcibios_entry;
11587 +
11588 + if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
11589 +- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
11590 ++ pci_indirect.address = pcibios_entry;
11591 +
11592 + local_irq_save(flags);
11593 +- __asm__(
11594 +- "lcall *(%%edi); cld\n\t"
11595 ++ __asm__("movw %w6, %%ds\n\t"
11596 ++ "lcall *%%ss:(%%edi); cld\n\t"
11597 ++ "push %%ss\n\t"
11598 ++ "pop %%ds\n\t"
11599 + "jc 1f\n\t"
11600 + "xor %%ah, %%ah\n"
11601 + "1:"
11602 +@@ -122,7 +194,8 @@ static int __devinit check_pcibios(void)
11603 + "=b" (ebx),
11604 + "=c" (ecx)
11605 + : "1" (PCIBIOS_PCI_BIOS_PRESENT),
11606 +- "D" (&pci_indirect)
11607 ++ "D" (&pci_indirect),
11608 ++ "r" (__PCIBIOS_DS)
11609 + : "memory");
11610 + local_irq_restore(flags);
11611 +
11612 +@@ -166,7 +239,10 @@ static int pci_bios_read(unsigned int se
11613 +
11614 + switch (len) {
11615 + case 1:
11616 +- __asm__("lcall *(%%esi); cld\n\t"
11617 ++ __asm__("movw %w6, %%ds\n\t"
11618 ++ "lcall *%%ss:(%%esi); cld\n\t"
11619 ++ "push %%ss\n\t"
11620 ++ "pop %%ds\n\t"
11621 + "jc 1f\n\t"
11622 + "xor %%ah, %%ah\n"
11623 + "1:"
11624 +@@ -175,7 +251,8 @@ static int pci_bios_read(unsigned int se
11625 + : "1" (PCIBIOS_READ_CONFIG_BYTE),
11626 + "b" (bx),
11627 + "D" ((long)reg),
11628 +- "S" (&pci_indirect));
11629 ++ "S" (&pci_indirect),
11630 ++ "r" (__PCIBIOS_DS));
11631 + /*
11632 + * Zero-extend the result beyond 8 bits, do not trust the
11633 + * BIOS having done it:
11634 +@@ -183,7 +260,10 @@ static int pci_bios_read(unsigned int se
11635 + *value &= 0xff;
11636 + break;
11637 + case 2:
11638 +- __asm__("lcall *(%%esi); cld\n\t"
11639 ++ __asm__("movw %w6, %%ds\n\t"
11640 ++ "lcall *%%ss:(%%esi); cld\n\t"
11641 ++ "push %%ss\n\t"
11642 ++ "pop %%ds\n\t"
11643 + "jc 1f\n\t"
11644 + "xor %%ah, %%ah\n"
11645 + "1:"
11646 +@@ -192,7 +272,8 @@ static int pci_bios_read(unsigned int se
11647 + : "1" (PCIBIOS_READ_CONFIG_WORD),
11648 + "b" (bx),
11649 + "D" ((long)reg),
11650 +- "S" (&pci_indirect));
11651 ++ "S" (&pci_indirect),
11652 ++ "r" (__PCIBIOS_DS));
11653 + /*
11654 + * Zero-extend the result beyond 16 bits, do not trust the
11655 + * BIOS having done it:
11656 +@@ -200,7 +281,10 @@ static int pci_bios_read(unsigned int se
11657 + *value &= 0xffff;
11658 + break;
11659 + case 4:
11660 +- __asm__("lcall *(%%esi); cld\n\t"
11661 ++ __asm__("movw %w6, %%ds\n\t"
11662 ++ "lcall *%%ss:(%%esi); cld\n\t"
11663 ++ "push %%ss\n\t"
11664 ++ "pop %%ds\n\t"
11665 + "jc 1f\n\t"
11666 + "xor %%ah, %%ah\n"
11667 + "1:"
11668 +@@ -209,7 +293,8 @@ static int pci_bios_read(unsigned int se
11669 + : "1" (PCIBIOS_READ_CONFIG_DWORD),
11670 + "b" (bx),
11671 + "D" ((long)reg),
11672 +- "S" (&pci_indirect));
11673 ++ "S" (&pci_indirect),
11674 ++ "r" (__PCIBIOS_DS));
11675 + break;
11676 + }
11677 +
11678 +@@ -232,7 +317,10 @@ static int pci_bios_write(unsigned int s
11679 +
11680 + switch (len) {
11681 + case 1:
11682 +- __asm__("lcall *(%%esi); cld\n\t"
11683 ++ __asm__("movw %w6, %%ds\n\t"
11684 ++ "lcall *%%ss:(%%esi); cld\n\t"
11685 ++ "push %%ss\n\t"
11686 ++ "pop %%ds\n\t"
11687 + "jc 1f\n\t"
11688 + "xor %%ah, %%ah\n"
11689 + "1:"
11690 +@@ -241,10 +329,14 @@ static int pci_bios_write(unsigned int s
11691 + "c" (value),
11692 + "b" (bx),
11693 + "D" ((long)reg),
11694 +- "S" (&pci_indirect));
11695 ++ "S" (&pci_indirect),
11696 ++ "r" (__PCIBIOS_DS));
11697 + break;
11698 + case 2:
11699 +- __asm__("lcall *(%%esi); cld\n\t"
11700 ++ __asm__("movw %w6, %%ds\n\t"
11701 ++ "lcall *%%ss:(%%esi); cld\n\t"
11702 ++ "push %%ss\n\t"
11703 ++ "pop %%ds\n\t"
11704 + "jc 1f\n\t"
11705 + "xor %%ah, %%ah\n"
11706 + "1:"
11707 +@@ -253,10 +345,14 @@ static int pci_bios_write(unsigned int s
11708 + "c" (value),
11709 + "b" (bx),
11710 + "D" ((long)reg),
11711 +- "S" (&pci_indirect));
11712 ++ "S" (&pci_indirect),
11713 ++ "r" (__PCIBIOS_DS));
11714 + break;
11715 + case 4:
11716 +- __asm__("lcall *(%%esi); cld\n\t"
11717 ++ __asm__("movw %w6, %%ds\n\t"
11718 ++ "lcall *%%ss:(%%esi); cld\n\t"
11719 ++ "push %%ss\n\t"
11720 ++ "pop %%ds\n\t"
11721 + "jc 1f\n\t"
11722 + "xor %%ah, %%ah\n"
11723 + "1:"
11724 +@@ -265,7 +361,8 @@ static int pci_bios_write(unsigned int s
11725 + "c" (value),
11726 + "b" (bx),
11727 + "D" ((long)reg),
11728 +- "S" (&pci_indirect));
11729 ++ "S" (&pci_indirect),
11730 ++ "r" (__PCIBIOS_DS));
11731 + break;
11732 + }
11733 +
11734 +@@ -369,10 +466,13 @@ struct irq_routing_table * pcibios_get_i
11735 +
11736 + DBG("PCI: Fetching IRQ routing table... ");
11737 + __asm__("push %%es\n\t"
11738 ++ "movw %w8, %%ds\n\t"
11739 + "push %%ds\n\t"
11740 + "pop %%es\n\t"
11741 +- "lcall *(%%esi); cld\n\t"
11742 ++ "lcall *%%ss:(%%esi); cld\n\t"
11743 + "pop %%es\n\t"
11744 ++ "push %%ss\n\t"
11745 ++ "pop %%ds\n"
11746 + "jc 1f\n\t"
11747 + "xor %%ah, %%ah\n"
11748 + "1:"
11749 +@@ -383,7 +483,8 @@ struct irq_routing_table * pcibios_get_i
11750 + "1" (0),
11751 + "D" ((long) &opt),
11752 + "S" (&pci_indirect),
11753 +- "m" (opt)
11754 ++ "m" (opt),
11755 ++ "r" (__PCIBIOS_DS)
11756 + : "memory");
11757 + DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
11758 + if (ret & 0xff00)
11759 +@@ -407,7 +508,10 @@ int pcibios_set_irq_routing(struct pci_d
11760 + {
11761 + int ret;
11762 +
11763 +- __asm__("lcall *(%%esi); cld\n\t"
11764 ++ __asm__("movw %w5, %%ds\n\t"
11765 ++ "lcall *%%ss:(%%esi); cld\n\t"
11766 ++ "push %%ss\n\t"
11767 ++ "pop %%ds\n"
11768 + "jc 1f\n\t"
11769 + "xor %%ah, %%ah\n"
11770 + "1:"
11771 +@@ -415,7 +519,8 @@ int pcibios_set_irq_routing(struct pci_d
11772 + : "0" (PCIBIOS_SET_PCI_HW_INT),
11773 + "b" ((dev->bus->number << 8) | dev->devfn),
11774 + "c" ((irq << 8) | (pin + 10)),
11775 +- "S" (&pci_indirect));
11776 ++ "S" (&pci_indirect),
11777 ++ "r" (__PCIBIOS_DS));
11778 + return !(ret & 0xff00);
11779 + }
11780 + EXPORT_SYMBOL(pcibios_set_irq_routing);
11781 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_32.c linux-2.6.27.10/arch/x86/power/cpu_32.c
11782 +--- linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-07 12:55:34.000000000 -0500
11783 ++++ linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-18 03:38:44.000000000 -0500
11784 +@@ -66,7 +66,7 @@ static void do_fpu_end(void)
11785 + static void fix_processor_context(void)
11786 + {
11787 + int cpu = smp_processor_id();
11788 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11789 ++ struct tss_struct *t = init_tss + cpu;
11790 +
11791 + set_tss_desc(cpu, t); /*
11792 + * This just modifies memory; should not be
11793 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_64.c linux-2.6.27.10/arch/x86/power/cpu_64.c
11794 +--- linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-07 12:55:34.000000000 -0500
11795 ++++ linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-18 03:38:44.000000000 -0500
11796 +@@ -136,7 +136,11 @@ void restore_processor_state(void)
11797 + static void fix_processor_context(void)
11798 + {
11799 + int cpu = smp_processor_id();
11800 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11801 ++ struct tss_struct *t = init_tss + cpu;
11802 ++
11803 ++#ifdef CONFIG_PAX_KERNEXEC
11804 ++ unsigned long cr0;
11805 ++#endif
11806 +
11807 + /*
11808 + * This just modifies memory; should not be necessary. But... This
11809 +@@ -145,8 +149,16 @@ static void fix_processor_context(void)
11810 + */
11811 + set_tss_desc(cpu, t);
11812 +
11813 ++#ifdef CONFIG_PAX_KERNEXEC
11814 ++ pax_open_kernel(cr0);
11815 ++#endif
11816 ++
11817 + get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
11818 +
11819 ++#ifdef CONFIG_PAX_KERNEXEC
11820 ++ pax_close_kernel(cr0);
11821 ++#endif
11822 ++
11823 + syscall_init(); /* This sets MSR_*STAR and related */
11824 + load_TR_desc(); /* This does ltr */
11825 + load_LDT(&current->active_mm->context); /* This does lldt */
11826 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c
11827 +--- linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-07 12:55:34.000000000 -0500
11828 ++++ linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-18 03:38:44.000000000 -0500
11829 +@@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m
11830 + void enable_sep_cpu(void)
11831 + {
11832 + int cpu = get_cpu();
11833 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
11834 ++ struct tss_struct *tss = init_tss + cpu;
11835 +
11836 + if (!boot_cpu_has(X86_FEATURE_SEP)) {
11837 + put_cpu();
11838 +@@ -249,7 +249,7 @@ static int __init gate_vma_init(void)
11839 + gate_vma.vm_start = FIXADDR_USER_START;
11840 + gate_vma.vm_end = FIXADDR_USER_END;
11841 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
11842 +- gate_vma.vm_page_prot = __P101;
11843 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
11844 + /*
11845 + * Make sure the vDSO gets into every core dump.
11846 + * Dumping its contents makes post-mortem fully interpretable later
11847 +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l
11848 + if (compat)
11849 + addr = VDSO_HIGH_BASE;
11850 + else {
11851 +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
11852 ++ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
11853 + if (IS_ERR_VALUE(addr)) {
11854 + ret = addr;
11855 + goto up_fail;
11856 +@@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l
11857 + goto up_fail;
11858 + }
11859 +
11860 +- current->mm->context.vdso = (void *)addr;
11861 ++ current->mm->context.vdso = addr;
11862 + current_thread_info()->sysenter_return =
11863 + VDSO32_SYMBOL(addr, SYSENTER_RETURN);
11864 +
11865 +@@ -384,7 +384,7 @@ static ctl_table abi_table2[] = {
11866 + .mode = 0644,
11867 + .proc_handler = proc_dointvec
11868 + },
11869 +- {}
11870 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11871 + };
11872 +
11873 + static ctl_table abi_root_table2[] = {
11874 +@@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = {
11875 + .mode = 0555,
11876 + .child = abi_table2
11877 + },
11878 +- {}
11879 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11880 + };
11881 +
11882 + static __init int ia32_binfmt_init(void)
11883 +@@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init);
11884 +
11885 + const char *arch_vma_name(struct vm_area_struct *vma)
11886 + {
11887 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11888 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11889 + return "[vdso]";
11890 ++
11891 ++#ifdef CONFIG_PAX_SEGMEXEC
11892 ++ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
11893 ++ return "[vdso]";
11894 ++#endif
11895 ++
11896 + return NULL;
11897 + }
11898 +
11899 +@@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru
11900 + struct mm_struct *mm = tsk->mm;
11901 +
11902 + /* Check to see if this task was created in compat vdso mode */
11903 +- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
11904 ++ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
11905 + return &gate_vma;
11906 + return NULL;
11907 + }
11908 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vma.c linux-2.6.27.10/arch/x86/vdso/vma.c
11909 +--- linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-07 12:55:34.000000000 -0500
11910 ++++ linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-18 03:38:44.000000000 -0500
11911 +@@ -123,7 +123,7 @@ int arch_setup_additional_pages(struct l
11912 + if (ret)
11913 + goto up_fail;
11914 +
11915 +- current->mm->context.vdso = (void *)addr;
11916 ++ current->mm->context.vdso = addr;
11917 + up_fail:
11918 + up_write(&mm->mmap_sem);
11919 + return ret;
11920 +diff -urNp linux-2.6.27.10/arch/x86/xen/enlighten.c linux-2.6.27.10/arch/x86/xen/enlighten.c
11921 +--- linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:37.000000000 -0500
11922 ++++ linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:46.000000000 -0500
11923 +@@ -343,7 +343,7 @@ static void xen_set_ldt(const void *addr
11924 + static void xen_load_gdt(const struct desc_ptr *dtr)
11925 + {
11926 + unsigned long *frames;
11927 +- unsigned long va = dtr->address;
11928 ++ unsigned long va = (unsigned long)dtr->address;
11929 + unsigned int size = dtr->size + 1;
11930 + unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
11931 + int f;
11932 +@@ -358,7 +358,7 @@ static void xen_load_gdt(const struct de
11933 + mcs = xen_mc_entry(sizeof(*frames) * pages);
11934 + frames = mcs.args;
11935 +
11936 +- for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
11937 ++ for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) {
11938 + frames[f] = virt_to_mfn(va);
11939 + make_lowmem_page_readonly((void *)va);
11940 + }
11941 +@@ -467,7 +467,7 @@ static void xen_write_idt_entry(gate_des
11942 +
11943 + preempt_disable();
11944 +
11945 +- start = __get_cpu_var(idt_desc).address;
11946 ++ start = (unsigned long)__get_cpu_var(idt_desc).address;
11947 + end = start + __get_cpu_var(idt_desc).size + 1;
11948 +
11949 + xen_mc_flush();
11950 +@@ -1574,6 +1574,8 @@ static __init pgd_t *xen_setup_kernel_pa
11951 + convert_pfn_mfn(init_level4_pgt);
11952 + convert_pfn_mfn(level3_ident_pgt);
11953 + convert_pfn_mfn(level3_kernel_pgt);
11954 ++ convert_pfn_mfn(level3_vmalloc_pgt);
11955 ++ convert_pfn_mfn(level3_vmemmap_pgt);
11956 +
11957 + l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
11958 + l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
11959 +@@ -1592,9 +1594,12 @@ static __init pgd_t *xen_setup_kernel_pa
11960 + set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
11961 + set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
11962 + set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
11963 ++ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
11964 ++ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
11965 + set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
11966 + set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
11967 + set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
11968 ++ set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
11969 +
11970 + /* Pin down new L4 */
11971 + pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
11972 +diff -urNp linux-2.6.27.10/arch/x86/xen/smp.c linux-2.6.27.10/arch/x86/xen/smp.c
11973 +--- linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-07 12:55:34.000000000 -0500
11974 ++++ linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-18 03:38:44.000000000 -0500
11975 +@@ -170,11 +170,6 @@ static void __init xen_smp_prepare_boot_
11976 + {
11977 + BUG_ON(smp_processor_id() != 0);
11978 + native_smp_prepare_boot_cpu();
11979 +-
11980 +- /* We've switched to the "real" per-cpu gdt, so make sure the
11981 +- old memory can be recycled */
11982 +- make_lowmem_page_readwrite(&per_cpu_var(gdt_page));
11983 +-
11984 + xen_setup_vcpu_info_placement();
11985 + }
11986 +
11987 +@@ -232,8 +227,8 @@ cpu_initialize_context(unsigned int cpu,
11988 + gdt = get_cpu_gdt_table(cpu);
11989 +
11990 + ctxt->flags = VGCF_IN_KERNEL;
11991 +- ctxt->user_regs.ds = __USER_DS;
11992 +- ctxt->user_regs.es = __USER_DS;
11993 ++ ctxt->user_regs.ds = __KERNEL_DS;
11994 ++ ctxt->user_regs.es = __KERNEL_DS;
11995 + ctxt->user_regs.ss = __KERNEL_DS;
11996 + #ifdef CONFIG_X86_32
11997 + ctxt->user_regs.fs = __KERNEL_PERCPU;
11998 +diff -urNp linux-2.6.27.10/crypto/async_tx/async_tx.c linux-2.6.27.10/crypto/async_tx/async_tx.c
11999 +--- linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-07 12:55:34.000000000 -0500
12000 ++++ linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-18 03:38:44.000000000 -0500
12001 +@@ -358,8 +358,8 @@ async_tx_init(void)
12002 + err:
12003 + printk(KERN_ERR "async_tx: initialization failure\n");
12004 +
12005 +- while (--cap >= 0)
12006 +- free_percpu(channel_table[cap]);
12007 ++ while (cap)
12008 ++ free_percpu(channel_table[--cap]);
12009 +
12010 + return 1;
12011 + }
12012 +diff -urNp linux-2.6.27.10/crypto/lrw.c linux-2.6.27.10/crypto/lrw.c
12013 +--- linux-2.6.27.10/crypto/lrw.c 2008-11-07 12:55:34.000000000 -0500
12014 ++++ linux-2.6.27.10/crypto/lrw.c 2008-11-18 03:38:44.000000000 -0500
12015 +@@ -54,7 +54,7 @@ static int setkey(struct crypto_tfm *par
12016 + struct priv *ctx = crypto_tfm_ctx(parent);
12017 + struct crypto_cipher *child = ctx->child;
12018 + int err, i;
12019 +- be128 tmp = { 0 };
12020 ++ be128 tmp = { 0, 0 };
12021 + int bsize = crypto_cipher_blocksize(child);
12022 +
12023 + crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
12024 +diff -urNp linux-2.6.27.10/Documentation/dontdiff linux-2.6.27.10/Documentation/dontdiff
12025 +--- linux-2.6.27.10/Documentation/dontdiff 2008-11-07 12:55:34.000000000 -0500
12026 ++++ linux-2.6.27.10/Documentation/dontdiff 2008-11-18 03:39:50.000000000 -0500
12027 +@@ -3,6 +3,7 @@
12028 + *.bin
12029 + *.cpio
12030 + *.css
12031 ++*.dbg
12032 + *.dvi
12033 + *.eps
12034 + *.fw.gen.S
12035 +@@ -53,9 +54,14 @@ COPYING
12036 + CREDITS
12037 + CVS
12038 + ChangeSet
12039 ++GPATH
12040 ++GRTAGS
12041 ++GSYMS
12042 ++GTAGS
12043 + Image
12044 + Kerntypes
12045 + MODS.txt
12046 ++Module.markers
12047 + Module.symvers
12048 + PENDING
12049 + SCCS
12050 +@@ -66,7 +72,6 @@ aic7*reg_print.c*
12051 + aic7*seq.h*
12052 + aicasm
12053 + aicdb.h*
12054 +-asm
12055 + asm-offsets.h
12056 + asm_offsets.h
12057 + autoconf.h*
12058 +@@ -74,6 +79,7 @@ bbootsect
12059 + bin2c
12060 + binkernel.spec
12061 + bootsect
12062 ++bounds.h
12063 + bsetup
12064 + btfixupprep
12065 + build
12066 +@@ -90,6 +96,7 @@ config_data.gz*
12067 + conmakehash
12068 + consolemap_deftbl.c*
12069 + crc32table.h*
12070 ++cpustr.h
12071 + cscope.*
12072 + defkeymap.c*
12073 + devlist.h*
12074 +@@ -138,6 +145,7 @@ miboot*
12075 + mk_elfconfig
12076 + mkboot
12077 + mkbugboot
12078 ++mkcpustr
12079 + mkdep
12080 + mkprep
12081 + mktables
12082 +@@ -179,16 +187,21 @@ times.h*
12083 + tkparse
12084 + trix_boot.h
12085 + utsrelease.h*
12086 +-vdso.lds
12087 ++vdso*.lds
12088 + version.h*
12089 + vmlinux
12090 + vmlinux-*
12091 + vmlinux.aout
12092 +-vmlinux*.lds*
12093 ++vmlinux.bin.all
12094 ++vmlinux*.lds
12095 ++vmlinux.relocs
12096 + vmlinux*.scr
12097 +-vsyscall.lds
12098 ++vsyscall*.lds
12099 ++wakeup.elf
12100 ++wakeup.lds
12101 + wanxlfw.inc
12102 + uImage
12103 + unifdef
12104 ++utsrelease.h
12105 + zImage*
12106 + zconf.hash.c
12107 +diff -urNp linux-2.6.27.10/drivers/acpi/blacklist.c linux-2.6.27.10/drivers/acpi/blacklist.c
12108 +--- linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-07 12:55:34.000000000 -0500
12109 ++++ linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-18 03:38:44.000000000 -0500
12110 +@@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b
12111 + {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
12112 + "Incorrect _ADR", 1},
12113 +
12114 +- {""}
12115 ++ {"", "", 0, 0, 0, all_versions, 0}
12116 + };
12117 +
12118 + #if CONFIG_ACPI_BLACKLIST_YEAR
12119 +diff -urNp linux-2.6.27.10/drivers/acpi/osl.c linux-2.6.27.10/drivers/acpi/osl.c
12120 +--- linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:16:51.000000000 -0500
12121 ++++ linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:13:45.000000000 -0500
12122 +@@ -494,6 +494,8 @@ acpi_os_read_memory(acpi_physical_addres
12123 + void __iomem *virt_addr;
12124 +
12125 + virt_addr = ioremap(phys_addr, width);
12126 ++ if (!virt_addr)
12127 ++ return AE_NO_MEMORY;
12128 + if (!value)
12129 + value = &dummy;
12130 +
12131 +@@ -522,6 +524,8 @@ acpi_os_write_memory(acpi_physical_addre
12132 + void __iomem *virt_addr;
12133 +
12134 + virt_addr = ioremap(phys_addr, width);
12135 ++ if (!virt_addr)
12136 ++ return AE_NO_MEMORY;
12137 +
12138 + switch (width) {
12139 + case 8:
12140 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_core.c linux-2.6.27.10/drivers/acpi/processor_core.c
12141 +--- linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-07 12:55:34.000000000 -0500
12142 ++++ linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-18 03:38:44.000000000 -0500
12143 +@@ -667,7 +667,7 @@ static int __cpuinit acpi_processor_star
12144 + return 0;
12145 + }
12146 +
12147 +- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
12148 ++ BUG_ON(pr->id >= nr_cpu_ids);
12149 +
12150 + /*
12151 + * Buggy BIOS check
12152 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_idle.c linux-2.6.27.10/drivers/acpi/processor_idle.c
12153 +--- linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-07 12:55:34.000000000 -0500
12154 ++++ linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-18 03:38:44.000000000 -0500
12155 +@@ -182,7 +182,7 @@ static struct dmi_system_id __cpuinitdat
12156 + DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
12157 + DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
12158 + (void *)2},
12159 +- {},
12160 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL},
12161 + };
12162 +
12163 + static inline u32 ticks_elapsed(u32 t1, u32 t2)
12164 +diff -urNp linux-2.6.27.10/drivers/acpi/tables/tbfadt.c linux-2.6.27.10/drivers/acpi/tables/tbfadt.c
12165 +--- linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-07 12:55:34.000000000 -0500
12166 ++++ linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-18 03:38:44.000000000 -0500
12167 +@@ -48,7 +48,7 @@
12168 + ACPI_MODULE_NAME("tbfadt")
12169 +
12170 + /* Local prototypes */
12171 +-static void inline
12172 ++static inline void
12173 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12174 + u8 bit_width, u64 address);
12175 +
12176 +@@ -122,7 +122,7 @@ static struct acpi_fadt_info fadt_info_t
12177 + *
12178 + ******************************************************************************/
12179 +
12180 +-static void inline
12181 ++static inline void
12182 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12183 + u8 bit_width, u64 address)
12184 + {
12185 +diff -urNp linux-2.6.27.10/drivers/ata/ahci.c linux-2.6.27.10/drivers/ata/ahci.c
12186 +--- linux-2.6.27.10/drivers/ata/ahci.c 2008-11-07 12:55:34.000000000 -0500
12187 ++++ linux-2.6.27.10/drivers/ata/ahci.c 2008-11-18 03:38:44.000000000 -0500
12188 +@@ -591,7 +591,7 @@ static const struct pci_device_id ahci_p
12189 + { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
12190 + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
12191 +
12192 +- { } /* terminate list */
12193 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12194 + };
12195 +
12196 +
12197 +diff -urNp linux-2.6.27.10/drivers/ata/ata_piix.c linux-2.6.27.10/drivers/ata/ata_piix.c
12198 +--- linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-07 12:55:34.000000000 -0500
12199 ++++ linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-18 03:38:44.000000000 -0500
12200 +@@ -284,7 +284,7 @@ static const struct pci_device_id piix_p
12201 + /* SATA Controller IDE (PCH) */
12202 + { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
12203 +
12204 +- { } /* terminate list */
12205 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12206 + };
12207 +
12208 + static struct pci_driver piix_pci_driver = {
12209 +@@ -587,7 +587,7 @@ static const struct ich_laptop ich_lapto
12210 + { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
12211 + { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
12212 + /* end marker */
12213 +- { 0, }
12214 ++ { 0, 0, 0 }
12215 + };
12216 +
12217 + /**
12218 +@@ -1143,7 +1143,7 @@ static int piix_broken_suspend(void)
12219 + },
12220 + },
12221 +
12222 +- { } /* terminate list */
12223 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL } /* terminate list */
12224 + };
12225 + static const char *oemstrs[] = {
12226 + "Tecra M3,",
12227 +diff -urNp linux-2.6.27.10/drivers/ata/libata-core.c linux-2.6.27.10/drivers/ata/libata-core.c
12228 +--- linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:11.000000000 -0500
12229 ++++ linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:21.000000000 -0500
12230 +@@ -746,7 +746,7 @@ static const struct ata_xfer_ent {
12231 + { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
12232 + { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
12233 + { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
12234 +- { -1, },
12235 ++ { -1, 0, 0 }
12236 + };
12237 +
12238 + /**
12239 +@@ -2917,7 +2917,7 @@ static const struct ata_timing ata_timin
12240 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
12241 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
12242 +
12243 +- { 0xFF }
12244 ++ { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
12245 + };
12246 +
12247 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
12248 +@@ -4073,7 +4073,7 @@ static const struct ata_blacklist_entry
12249 + { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
12250 +
12251 + /* End Marker */
12252 +- { }
12253 ++ { NULL, NULL, 0 }
12254 + };
12255 +
12256 + static int strn_pattern_cmp(const char *patt, const char *name, int wildchar)
12257 +diff -urNp linux-2.6.27.10/drivers/char/agp/frontend.c linux-2.6.27.10/drivers/char/agp/frontend.c
12258 +--- linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-07 12:55:34.000000000 -0500
12259 ++++ linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-18 03:38:44.000000000 -0500
12260 +@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
12261 + if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
12262 + return -EFAULT;
12263 +
12264 +- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
12265 ++ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
12266 + return -EFAULT;
12267 +
12268 + client = agp_find_client_by_pid(reserve.pid);
12269 +diff -urNp linux-2.6.27.10/drivers/char/agp/intel-agp.c linux-2.6.27.10/drivers/char/agp/intel-agp.c
12270 +--- linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-07 12:55:34.000000000 -0500
12271 ++++ linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-18 03:38:44.000000000 -0500
12272 +@@ -2332,7 +2332,7 @@ static struct pci_device_id agp_intel_pc
12273 + ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
12274 + ID(PCI_DEVICE_ID_INTEL_Q45_HB),
12275 + ID(PCI_DEVICE_ID_INTEL_G45_HB),
12276 +- { }
12277 ++ { 0, 0, 0, 0, 0, 0, 0 }
12278 + };
12279 +
12280 + MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
12281 +diff -urNp linux-2.6.27.10/drivers/char/hpet.c linux-2.6.27.10/drivers/char/hpet.c
12282 +--- linux-2.6.27.10/drivers/char/hpet.c 2008-11-07 12:55:34.000000000 -0500
12283 ++++ linux-2.6.27.10/drivers/char/hpet.c 2008-11-18 03:38:44.000000000 -0500
12284 +@@ -959,7 +959,7 @@ static struct acpi_driver hpet_acpi_driv
12285 + },
12286 + };
12287 +
12288 +-static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
12289 ++static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
12290 +
12291 + static int __init hpet_init(void)
12292 + {
12293 +diff -urNp linux-2.6.27.10/drivers/char/keyboard.c linux-2.6.27.10/drivers/char/keyboard.c
12294 +--- linux-2.6.27.10/drivers/char/keyboard.c 2008-11-07 12:55:34.000000000 -0500
12295 ++++ linux-2.6.27.10/drivers/char/keyboard.c 2008-11-18 03:38:44.000000000 -0500
12296 +@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
12297 + kbd->kbdmode == VC_MEDIUMRAW) &&
12298 + value != KVAL(K_SAK))
12299 + return; /* SAK is allowed even in raw mode */
12300 ++
12301 ++#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
12302 ++ {
12303 ++ void *func = fn_handler[value];
12304 ++ if (func == fn_show_state || func == fn_show_ptregs ||
12305 ++ func == fn_show_mem)
12306 ++ return;
12307 ++ }
12308 ++#endif
12309 ++
12310 + fn_handler[value](vc);
12311 + }
12312 +
12313 +@@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_
12314 + .evbit = { BIT_MASK(EV_SND) },
12315 + },
12316 +
12317 +- { }, /* Terminating entry */
12318 ++ { 0 }, /* Terminating entry */
12319 + };
12320 +
12321 + MODULE_DEVICE_TABLE(input, kbd_ids);
12322 +diff -urNp linux-2.6.27.10/drivers/char/mem.c linux-2.6.27.10/drivers/char/mem.c
12323 +--- linux-2.6.27.10/drivers/char/mem.c 2008-11-07 12:55:34.000000000 -0500
12324 ++++ linux-2.6.27.10/drivers/char/mem.c 2008-11-18 03:38:44.000000000 -0500
12325 +@@ -27,6 +27,7 @@
12326 + #include <linux/splice.h>
12327 + #include <linux/pfn.h>
12328 + #include <linux/smp_lock.h>
12329 ++#include <linux/grsecurity.h>
12330 +
12331 + #include <asm/uaccess.h>
12332 + #include <asm/io.h>
12333 +@@ -35,6 +36,10 @@
12334 + # include <linux/efi.h>
12335 + #endif
12336 +
12337 ++#ifdef CONFIG_GRKERNSEC
12338 ++extern struct file_operations grsec_fops;
12339 ++#endif
12340 ++
12341 + /*
12342 + * Architectures vary in how they handle caching for addresses
12343 + * outside of main memory.
12344 +@@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f
12345 + if (!valid_phys_addr_range(p, count))
12346 + return -EFAULT;
12347 +
12348 ++#ifdef CONFIG_GRKERNSEC_KMEM
12349 ++ gr_handle_mem_write();
12350 ++ return -EPERM;
12351 ++#endif
12352 ++
12353 + written = 0;
12354 +
12355 + #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
12356 +@@ -350,6 +360,11 @@ static int mmap_mem(struct file * file,
12357 + &vma->vm_page_prot))
12358 + return -EINVAL;
12359 +
12360 ++#ifdef CONFIG_GRKERNSEC_KMEM
12361 ++ if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
12362 ++ return -EPERM;
12363 ++#endif
12364 ++
12365 + vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
12366 + size,
12367 + vma->vm_page_prot);
12368 +@@ -588,6 +603,11 @@ static ssize_t write_kmem(struct file *
12369 + ssize_t written;
12370 + char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
12371 +
12372 ++#ifdef CONFIG_GRKERNSEC_KMEM
12373 ++ gr_handle_kmem_write();
12374 ++ return -EPERM;
12375 ++#endif
12376 ++
12377 + if (p < (unsigned long) high_memory) {
12378 +
12379 + wrote = count;
12380 +@@ -791,6 +811,16 @@ static loff_t memory_lseek(struct file *
12381 +
12382 + static int open_port(struct inode * inode, struct file * filp)
12383 + {
12384 ++#ifdef CONFIG_GRKERNSEC_KMEM
12385 ++ gr_handle_open_port();
12386 ++ return -EPERM;
12387 ++#endif
12388 ++
12389 ++ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12390 ++}
12391 ++
12392 ++static int open_mem(struct inode * inode, struct file * filp)
12393 ++{
12394 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12395 + }
12396 +
12397 +@@ -798,7 +828,6 @@ static int open_port(struct inode * inod
12398 + #define full_lseek null_lseek
12399 + #define write_zero write_null
12400 + #define read_full read_zero
12401 +-#define open_mem open_port
12402 + #define open_kmem open_mem
12403 + #define open_oldmem open_mem
12404 +
12405 +@@ -938,6 +967,11 @@ static int memory_open(struct inode * in
12406 + filp->f_op = &oldmem_fops;
12407 + break;
12408 + #endif
12409 ++#ifdef CONFIG_GRKERNSEC
12410 ++ case 13:
12411 ++ filp->f_op = &grsec_fops;
12412 ++ break;
12413 ++#endif
12414 + default:
12415 + unlock_kernel();
12416 + return -ENXIO;
12417 +@@ -974,6 +1008,9 @@ static const struct {
12418 + #ifdef CONFIG_CRASH_DUMP
12419 + {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
12420 + #endif
12421 ++#ifdef CONFIG_GRKERNSEC
12422 ++ {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops},
12423 ++#endif
12424 + };
12425 +
12426 + static struct class *mem_class;
12427 +diff -urNp linux-2.6.27.10/drivers/char/nvram.c linux-2.6.27.10/drivers/char/nvram.c
12428 +--- linux-2.6.27.10/drivers/char/nvram.c 2008-11-07 12:55:34.000000000 -0500
12429 ++++ linux-2.6.27.10/drivers/char/nvram.c 2008-11-18 03:38:44.000000000 -0500
12430 +@@ -433,7 +433,10 @@ static const struct file_operations nvra
12431 + static struct miscdevice nvram_dev = {
12432 + NVRAM_MINOR,
12433 + "nvram",
12434 +- &nvram_fops
12435 ++ &nvram_fops,
12436 ++ {NULL, NULL},
12437 ++ NULL,
12438 ++ NULL
12439 + };
12440 +
12441 + static int __init
12442 +diff -urNp linux-2.6.27.10/drivers/char/random.c linux-2.6.27.10/drivers/char/random.c
12443 +--- linux-2.6.27.10/drivers/char/random.c 2008-11-07 12:55:34.000000000 -0500
12444 ++++ linux-2.6.27.10/drivers/char/random.c 2008-11-18 03:38:44.000000000 -0500
12445 +@@ -249,8 +249,13 @@
12446 + /*
12447 + * Configuration information
12448 + */
12449 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12450 ++#define INPUT_POOL_WORDS 512
12451 ++#define OUTPUT_POOL_WORDS 128
12452 ++#else
12453 + #define INPUT_POOL_WORDS 128
12454 + #define OUTPUT_POOL_WORDS 32
12455 ++#endif
12456 + #define SEC_XFER_SIZE 512
12457 +
12458 + /*
12459 +@@ -287,10 +292,17 @@ static struct poolinfo {
12460 + int poolwords;
12461 + int tap1, tap2, tap3, tap4, tap5;
12462 + } poolinfo_table[] = {
12463 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12464 ++ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
12465 ++ { 512, 411, 308, 208, 104, 1 },
12466 ++ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
12467 ++ { 128, 103, 76, 51, 25, 1 },
12468 ++#else
12469 + /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
12470 + { 128, 103, 76, 51, 25, 1 },
12471 + /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
12472 + { 32, 26, 20, 14, 7, 1 },
12473 ++#endif
12474 + #if 0
12475 + /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
12476 + { 2048, 1638, 1231, 819, 411, 1 },
12477 +@@ -1166,7 +1178,7 @@ EXPORT_SYMBOL(generate_random_uuid);
12478 + #include <linux/sysctl.h>
12479 +
12480 + static int min_read_thresh = 8, min_write_thresh;
12481 +-static int max_read_thresh = INPUT_POOL_WORDS * 32;
12482 ++static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
12483 + static int max_write_thresh = INPUT_POOL_WORDS * 32;
12484 + static char sysctl_bootid[16];
12485 +
12486 +diff -urNp linux-2.6.27.10/drivers/char/tpm/tpm.c linux-2.6.27.10/drivers/char/tpm/tpm.c
12487 +--- linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-07 12:55:34.000000000 -0500
12488 ++++ linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-18 03:38:44.000000000 -0500
12489 +@@ -1037,7 +1037,7 @@ ssize_t tpm_write(struct file *file, con
12490 +
12491 + mutex_lock(&chip->buffer_mutex);
12492 +
12493 +- if (in_size > TPM_BUFSIZE)
12494 ++ if (in_size > (unsigned int)TPM_BUFSIZE)
12495 + in_size = TPM_BUFSIZE;
12496 +
12497 + if (copy_from_user
12498 +diff -urNp linux-2.6.27.10/drivers/char/vt_ioctl.c linux-2.6.27.10/drivers/char/vt_ioctl.c
12499 +--- linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-07 12:55:34.000000000 -0500
12500 ++++ linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-18 03:38:44.000000000 -0500
12501 +@@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
12502 + case KDSKBENT:
12503 + if (!perm)
12504 + return -EPERM;
12505 ++
12506 ++#ifdef CONFIG_GRKERNSEC
12507 ++ if (!capable(CAP_SYS_TTY_CONFIG))
12508 ++ return -EPERM;
12509 ++#endif
12510 ++
12511 + if (!i && v == K_NOSUCHMAP) {
12512 + /* deallocate map */
12513 + key_map = key_maps[s];
12514 +@@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
12515 + goto reterr;
12516 + }
12517 +
12518 ++#ifdef CONFIG_GRKERNSEC
12519 ++ if (!capable(CAP_SYS_TTY_CONFIG)) {
12520 ++ ret = -EPERM;
12521 ++ goto reterr;
12522 ++ }
12523 ++#endif
12524 ++
12525 + q = func_table[i];
12526 + first_free = funcbufptr + (funcbufsize - funcbufleft);
12527 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
12528 +diff -urNp linux-2.6.27.10/drivers/edac/edac_core.h linux-2.6.27.10/drivers/edac/edac_core.h
12529 +--- linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-07 12:55:34.000000000 -0500
12530 ++++ linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-18 03:38:44.000000000 -0500
12531 +@@ -85,11 +85,11 @@ extern int edac_debug_level;
12532 +
12533 + #else /* !CONFIG_EDAC_DEBUG */
12534 +
12535 +-#define debugf0( ... )
12536 +-#define debugf1( ... )
12537 +-#define debugf2( ... )
12538 +-#define debugf3( ... )
12539 +-#define debugf4( ... )
12540 ++#define debugf0( ... ) do {} while (0)
12541 ++#define debugf1( ... ) do {} while (0)
12542 ++#define debugf2( ... ) do {} while (0)
12543 ++#define debugf3( ... ) do {} while (0)
12544 ++#define debugf4( ... ) do {} while (0)
12545 +
12546 + #endif /* !CONFIG_EDAC_DEBUG */
12547 +
12548 +diff -urNp linux-2.6.27.10/drivers/firmware/dmi_scan.c linux-2.6.27.10/drivers/firmware/dmi_scan.c
12549 +--- linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-07 12:55:34.000000000 -0500
12550 ++++ linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-18 03:38:44.000000000 -0500
12551 +@@ -384,11 +384,6 @@ void __init dmi_scan_machine(void)
12552 + }
12553 + }
12554 + else {
12555 +- /*
12556 +- * no iounmap() for that ioremap(); it would be a no-op, but
12557 +- * it's so early in setup that sucker gets confused into doing
12558 +- * what it shouldn't if we actually call it.
12559 +- */
12560 + p = dmi_ioremap(0xF0000, 0x10000);
12561 + if (p == NULL)
12562 + goto out;
12563 +diff -urNp linux-2.6.27.10/drivers/hwmon/fscpos.c linux-2.6.27.10/drivers/hwmon/fscpos.c
12564 +--- linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-07 12:55:34.000000000 -0500
12565 ++++ linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-18 03:38:44.000000000 -0500
12566 +@@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client
12567 + unsigned long v = simple_strtoul(buf, NULL, 10);
12568 +
12569 + /* Range: 0..255 */
12570 +- if (v < 0) v = 0;
12571 + if (v > 255) v = 255;
12572 +
12573 + mutex_lock(&data->update_lock);
12574 +diff -urNp linux-2.6.27.10/drivers/hwmon/k8temp.c linux-2.6.27.10/drivers/hwmon/k8temp.c
12575 +--- linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-07 12:55:34.000000000 -0500
12576 ++++ linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-18 03:38:44.000000000 -0500
12577 +@@ -130,7 +130,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
12578 +
12579 + static struct pci_device_id k8temp_ids[] = {
12580 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
12581 +- { 0 },
12582 ++ { 0, 0, 0, 0, 0, 0, 0 },
12583 + };
12584 +
12585 + MODULE_DEVICE_TABLE(pci, k8temp_ids);
12586 +diff -urNp linux-2.6.27.10/drivers/hwmon/sis5595.c linux-2.6.27.10/drivers/hwmon/sis5595.c
12587 +--- linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-07 12:55:34.000000000 -0500
12588 ++++ linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-18 03:38:44.000000000 -0500
12589 +@@ -698,7 +698,7 @@ static struct sis5595_data *sis5595_upda
12590 +
12591 + static struct pci_device_id sis5595_pci_ids[] = {
12592 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12593 +- { 0, }
12594 ++ { 0, 0, 0, 0, 0, 0, 0 }
12595 + };
12596 +
12597 + MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
12598 +diff -urNp linux-2.6.27.10/drivers/hwmon/via686a.c linux-2.6.27.10/drivers/hwmon/via686a.c
12599 +--- linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-07 12:55:34.000000000 -0500
12600 ++++ linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-18 03:38:44.000000000 -0500
12601 +@@ -768,7 +768,7 @@ static struct via686a_data *via686a_upda
12602 +
12603 + static struct pci_device_id via686a_pci_ids[] = {
12604 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
12605 +- { 0, }
12606 ++ { 0, 0, 0, 0, 0, 0, 0 }
12607 + };
12608 +
12609 + MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
12610 +diff -urNp linux-2.6.27.10/drivers/hwmon/vt8231.c linux-2.6.27.10/drivers/hwmon/vt8231.c
12611 +--- linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-07 12:55:34.000000000 -0500
12612 ++++ linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-18 03:38:44.000000000 -0500
12613 +@@ -698,7 +698,7 @@ static struct platform_driver vt8231_dri
12614 +
12615 + static struct pci_device_id vt8231_pci_ids[] = {
12616 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
12617 +- { 0, }
12618 ++ { 0, 0, 0, 0, 0, 0, 0 }
12619 + };
12620 +
12621 + MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
12622 +diff -urNp linux-2.6.27.10/drivers/hwmon/w83791d.c linux-2.6.27.10/drivers/hwmon/w83791d.c
12623 +--- linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-07 12:55:34.000000000 -0500
12624 ++++ linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-18 03:38:44.000000000 -0500
12625 +@@ -289,8 +289,8 @@ static int w83791d_detect(struct i2c_cli
12626 + struct i2c_board_info *info);
12627 + static int w83791d_remove(struct i2c_client *client);
12628 +
12629 +-static int w83791d_read(struct i2c_client *client, u8 register);
12630 +-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
12631 ++static int w83791d_read(struct i2c_client *client, u8 reg);
12632 ++static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
12633 + static struct w83791d_data *w83791d_update_device(struct device *dev);
12634 +
12635 + #ifdef DEBUG
12636 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c
12637 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-07 12:55:34.000000000 -0500
12638 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-18 03:38:44.000000000 -0500
12639 +@@ -576,7 +576,7 @@ static struct pci_device_id i801_ids[] =
12640 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
12641 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
12642 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
12643 +- { 0, }
12644 ++ { 0, 0, 0, 0, 0, 0, 0 }
12645 + };
12646 +
12647 + MODULE_DEVICE_TABLE (pci, i801_ids);
12648 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c
12649 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-07 12:55:34.000000000 -0500
12650 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-18 03:38:44.000000000 -0500
12651 +@@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat
12652 + .ident = "IBM",
12653 + .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
12654 + },
12655 +- { },
12656 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL },
12657 + };
12658 +
12659 + static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
12660 +@@ -424,7 +424,7 @@ static struct pci_device_id piix4_ids[]
12661 + PCI_DEVICE_ID_SERVERWORKS_CSB6) },
12662 + { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
12663 + PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
12664 +- { 0, }
12665 ++ { 0, 0, 0, 0, 0, 0, 0 }
12666 + };
12667 +
12668 + MODULE_DEVICE_TABLE (pci, piix4_ids);
12669 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c
12670 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-07 12:55:34.000000000 -0500
12671 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-18 03:38:44.000000000 -0500
12672 +@@ -472,7 +472,7 @@ static struct i2c_adapter sis630_adapter
12673 + static struct pci_device_id sis630_ids[] __devinitdata = {
12674 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12675 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
12676 +- { 0, }
12677 ++ { 0, 0, 0, 0, 0, 0, 0 }
12678 + };
12679 +
12680 + MODULE_DEVICE_TABLE (pci, sis630_ids);
12681 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c
12682 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-07 12:55:34.000000000 -0500
12683 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-18 03:38:44.000000000 -0500
12684 +@@ -248,7 +248,7 @@ static struct i2c_adapter sis96x_adapter
12685 +
12686 + static struct pci_device_id sis96x_ids[] = {
12687 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
12688 +- { 0, }
12689 ++ { 0, 0, 0, 0, 0, 0, 0 }
12690 + };
12691 +
12692 + MODULE_DEVICE_TABLE (pci, sis96x_ids);
12693 +diff -urNp linux-2.6.27.10/drivers/ieee1394/dv1394.c linux-2.6.27.10/drivers/ieee1394/dv1394.c
12694 +--- linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-07 12:55:34.000000000 -0500
12695 ++++ linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-18 03:38:44.000000000 -0500
12696 +@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
12697 + based upon DIF section and sequence
12698 + */
12699 +
12700 +-static void inline
12701 ++static inline void
12702 + frame_put_packet (struct frame *f, struct packet *p)
12703 + {
12704 + int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
12705 +@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_c
12706 + /* default SYT offset is 3 cycles */
12707 + init->syt_offset = 3;
12708 +
12709 +- if ( (init->channel > 63) || (init->channel < 0) )
12710 ++ if (init->channel > 63)
12711 + init->channel = 63;
12712 +
12713 + chan_mask = (u64)1 << init->channel;
12714 +@@ -2174,7 +2174,7 @@ static struct ieee1394_device_id dv1394_
12715 + .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
12716 + .version = AVC_SW_VERSION_ENTRY & 0xffffff
12717 + },
12718 +- { }
12719 ++ { 0, 0, 0, 0, 0, 0 }
12720 + };
12721 +
12722 + MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
12723 +diff -urNp linux-2.6.27.10/drivers/ieee1394/eth1394.c linux-2.6.27.10/drivers/ieee1394/eth1394.c
12724 +--- linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-07 12:55:34.000000000 -0500
12725 ++++ linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-18 03:38:44.000000000 -0500
12726 +@@ -451,7 +451,7 @@ static struct ieee1394_device_id eth1394
12727 + .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
12728 + .version = ETHER1394_GASP_VERSION,
12729 + },
12730 +- {}
12731 ++ { 0, 0, 0, 0, 0, 0 }
12732 + };
12733 +
12734 + MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
12735 +diff -urNp linux-2.6.27.10/drivers/ieee1394/hosts.c linux-2.6.27.10/drivers/ieee1394/hosts.c
12736 +--- linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-07 12:55:34.000000000 -0500
12737 ++++ linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-18 03:38:44.000000000 -0500
12738 +@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
12739 + }
12740 +
12741 + static struct hpsb_host_driver dummy_driver = {
12742 ++ .name = "dummy",
12743 + .transmit_packet = dummy_transmit_packet,
12744 + .devctl = dummy_devctl,
12745 + .isoctl = dummy_isoctl
12746 +diff -urNp linux-2.6.27.10/drivers/ieee1394/ohci1394.c linux-2.6.27.10/drivers/ieee1394/ohci1394.c
12747 +--- linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-07 12:55:34.000000000 -0500
12748 ++++ linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-18 03:38:44.000000000 -0500
12749 +@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
12750 + printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
12751 +
12752 + /* Module Parameters */
12753 +-static int phys_dma = 1;
12754 ++static int phys_dma;
12755 + module_param(phys_dma, int, 0444);
12756 +-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
12757 ++MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
12758 +
12759 + static void dma_trm_tasklet(unsigned long data);
12760 + static void dma_trm_reset(struct dma_trm_ctx *d);
12761 +@@ -3437,7 +3437,7 @@ static struct pci_device_id ohci1394_pci
12762 + .subvendor = PCI_ANY_ID,
12763 + .subdevice = PCI_ANY_ID,
12764 + },
12765 +- { 0, },
12766 ++ { 0, 0, 0, 0, 0, 0, 0 },
12767 + };
12768 +
12769 + MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl);
12770 +diff -urNp linux-2.6.27.10/drivers/ieee1394/raw1394.c linux-2.6.27.10/drivers/ieee1394/raw1394.c
12771 +--- linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-07 12:55:34.000000000 -0500
12772 ++++ linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-18 03:38:44.000000000 -0500
12773 +@@ -2968,7 +2968,7 @@ static struct ieee1394_device_id raw1394
12774 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12775 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12776 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
12777 +- {}
12778 ++ { 0, 0, 0, 0, 0, 0 }
12779 + };
12780 +
12781 + MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
12782 +diff -urNp linux-2.6.27.10/drivers/ieee1394/sbp2.c linux-2.6.27.10/drivers/ieee1394/sbp2.c
12783 +--- linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:37.000000000 -0500
12784 ++++ linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:46.000000000 -0500
12785 +@@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id
12786 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12787 + .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
12788 + .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
12789 +- {}
12790 ++ { 0, 0, 0, 0, 0, 0 }
12791 + };
12792 + MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
12793 +
12794 +@@ -2135,7 +2135,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
12795 + MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
12796 + MODULE_LICENSE("GPL");
12797 +
12798 +-static int sbp2_module_init(void)
12799 ++static int __init sbp2_module_init(void)
12800 + {
12801 + int ret;
12802 +
12803 +diff -urNp linux-2.6.27.10/drivers/ieee1394/video1394.c linux-2.6.27.10/drivers/ieee1394/video1394.c
12804 +--- linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-07 12:55:34.000000000 -0500
12805 ++++ linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-18 03:38:44.000000000 -0500
12806 +@@ -893,7 +893,7 @@ static long video1394_ioctl(struct file
12807 + if (unlikely(d == NULL))
12808 + return -EFAULT;
12809 +
12810 +- if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) {
12811 ++ if (unlikely(v.buffer>=d->num_desc - 1)) {
12812 + PRINT(KERN_ERR, ohci->host->id,
12813 + "Buffer %d out of range",v.buffer);
12814 + return -EINVAL;
12815 +@@ -959,7 +959,7 @@ static long video1394_ioctl(struct file
12816 + if (unlikely(d == NULL))
12817 + return -EFAULT;
12818 +
12819 +- if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) {
12820 ++ if (unlikely(v.buffer>d->num_desc - 1)) {
12821 + PRINT(KERN_ERR, ohci->host->id,
12822 + "Buffer %d out of range",v.buffer);
12823 + return -EINVAL;
12824 +@@ -1030,7 +1030,7 @@ static long video1394_ioctl(struct file
12825 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12826 + if (d == NULL) return -EFAULT;
12827 +
12828 +- if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
12829 ++ if (v.buffer>=d->num_desc - 1) {
12830 + PRINT(KERN_ERR, ohci->host->id,
12831 + "Buffer %d out of range",v.buffer);
12832 + return -EINVAL;
12833 +@@ -1137,7 +1137,7 @@ static long video1394_ioctl(struct file
12834 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12835 + if (d == NULL) return -EFAULT;
12836 +
12837 +- if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
12838 ++ if (v.buffer>=d->num_desc-1) {
12839 + PRINT(KERN_ERR, ohci->host->id,
12840 + "Buffer %d out of range",v.buffer);
12841 + return -EINVAL;
12842 +@@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13
12843 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12844 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
12845 + },
12846 +- { }
12847 ++ { 0, 0, 0, 0, 0, 0 }
12848 + };
12849 +
12850 + MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
12851 +diff -urNp linux-2.6.27.10/drivers/input/keyboard/atkbd.c linux-2.6.27.10/drivers/input/keyboard/atkbd.c
12852 +--- linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:37.000000000 -0500
12853 ++++ linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:46.000000000 -0500
12854 +@@ -1148,7 +1148,7 @@ static struct serio_device_id atkbd_seri
12855 + .id = SERIO_ANY,
12856 + .extra = SERIO_ANY,
12857 + },
12858 +- { 0 }
12859 ++ { 0, 0, 0, 0 }
12860 + };
12861 +
12862 + MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
12863 +diff -urNp linux-2.6.27.10/drivers/input/mouse/lifebook.c linux-2.6.27.10/drivers/input/mouse/lifebook.c
12864 +--- linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-07 12:55:34.000000000 -0500
12865 ++++ linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-18 03:38:44.000000000 -0500
12866 +@@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo
12867 + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
12868 + },
12869 + },
12870 +- { }
12871 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
12872 + };
12873 +
12874 + static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
12875 +diff -urNp linux-2.6.27.10/drivers/input/mouse/psmouse-base.c linux-2.6.27.10/drivers/input/mouse/psmouse-base.c
12876 +--- linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-07 12:55:34.000000000 -0500
12877 ++++ linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-18 03:38:44.000000000 -0500
12878 +@@ -1328,7 +1328,7 @@ static struct serio_device_id psmouse_se
12879 + .id = SERIO_ANY,
12880 + .extra = SERIO_ANY,
12881 + },
12882 +- { 0 }
12883 ++ { 0, 0, 0, 0 }
12884 + };
12885 +
12886 + MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
12887 +diff -urNp linux-2.6.27.10/drivers/input/mouse/synaptics.c linux-2.6.27.10/drivers/input/mouse/synaptics.c
12888 +--- linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-07 12:55:34.000000000 -0500
12889 ++++ linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-18 03:38:45.000000000 -0500
12890 +@@ -417,7 +417,7 @@ static void synaptics_process_packet(str
12891 + break;
12892 + case 2:
12893 + if (SYN_MODEL_PEN(priv->model_id))
12894 +- ; /* Nothing, treat a pen as a single finger */
12895 ++ break; /* Nothing, treat a pen as a single finger */
12896 + break;
12897 + case 4 ... 15:
12898 + if (SYN_CAP_PALMDETECT(priv->capabilities))
12899 +@@ -624,7 +624,7 @@ static const struct dmi_system_id toshib
12900 + DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
12901 + },
12902 + },
12903 +- { }
12904 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12905 + };
12906 + #endif
12907 +
12908 +diff -urNp linux-2.6.27.10/drivers/input/mousedev.c linux-2.6.27.10/drivers/input/mousedev.c
12909 +--- linux-2.6.27.10/drivers/input/mousedev.c 2008-11-07 12:55:34.000000000 -0500
12910 ++++ linux-2.6.27.10/drivers/input/mousedev.c 2008-11-18 03:38:45.000000000 -0500
12911 +@@ -1064,7 +1064,7 @@ static struct input_handler mousedev_han
12912 +
12913 + #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
12914 + static struct miscdevice psaux_mouse = {
12915 +- PSMOUSE_MINOR, "psaux", &mousedev_fops
12916 ++ PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
12917 + };
12918 + static int psaux_registered;
12919 + #endif
12920 +diff -urNp linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h
12921 +--- linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:51.000000000 -0500
12922 ++++ linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:00.000000000 -0500
12923 +@@ -143,7 +143,7 @@ static struct dmi_system_id __initdata i
12924 + DMI_MATCH(DMI_PRODUCT_VERSION, "M606"),
12925 + },
12926 + },
12927 +- { }
12928 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12929 + };
12930 +
12931 + /*
12932 +@@ -351,7 +351,7 @@ static struct dmi_system_id __initdata i
12933 + DMI_MATCH(DMI_PRODUCT_NAME, "HEL80I"),
12934 + },
12935 + },
12936 +- { }
12937 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12938 + };
12939 +
12940 + #ifdef CONFIG_PNP
12941 +@@ -363,7 +363,7 @@ static struct dmi_system_id __initdata i
12942 + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
12943 + },
12944 + },
12945 +- { }
12946 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12947 + };
12948 + #endif
12949 +
12950 +@@ -430,7 +430,7 @@ static struct dmi_system_id __initdata i
12951 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
12952 + },
12953 + },
12954 +- { }
12955 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12956 + };
12957 +
12958 + #endif /* CONFIG_X86 */
12959 +diff -urNp linux-2.6.27.10/drivers/input/serio/serio_raw.c linux-2.6.27.10/drivers/input/serio/serio_raw.c
12960 +--- linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-07 12:55:34.000000000 -0500
12961 ++++ linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-18 03:38:45.000000000 -0500
12962 +@@ -373,7 +373,7 @@ static struct serio_device_id serio_raw_
12963 + .id = SERIO_ANY,
12964 + .extra = SERIO_ANY,
12965 + },
12966 +- { 0 }
12967 ++ { 0, 0, 0, 0 }
12968 + };
12969 +
12970 + MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
12971 +diff -urNp linux-2.6.27.10/drivers/md/bitmap.c linux-2.6.27.10/drivers/md/bitmap.c
12972 +--- linux-2.6.27.10/drivers/md/bitmap.c 2008-11-07 12:55:34.000000000 -0500
12973 ++++ linux-2.6.27.10/drivers/md/bitmap.c 2008-11-18 03:38:45.000000000 -0500
12974 +@@ -57,7 +57,7 @@
12975 + # if DEBUG > 0
12976 + # define PRINTK(x...) printk(KERN_DEBUG x)
12977 + # else
12978 +-# define PRINTK(x...)
12979 ++# define PRINTK(x...) do {} while (0)
12980 + # endif
12981 + #endif
12982 +
12983 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2000.c linux-2.6.27.10/drivers/mtd/devices/doc2000.c
12984 +--- linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-07 12:55:34.000000000 -0500
12985 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-18 03:38:45.000000000 -0500
12986 +@@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt
12987 +
12988 + /* The ECC will not be calculated correctly if less than 512 is written */
12989 + /* DBB-
12990 +- if (len != 0x200 && eccbuf)
12991 ++ if (len != 0x200)
12992 + printk(KERN_WARNING
12993 + "ECC needs a full sector write (adr: %lx size %lx)\n",
12994 + (long) to, (long) len);
12995 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2001.c linux-2.6.27.10/drivers/mtd/devices/doc2001.c
12996 +--- linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-07 12:55:34.000000000 -0500
12997 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-18 03:38:45.000000000 -0500
12998 +@@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt
12999 + /* Don't allow read past end of device */
13000 + if (from >= this->totlen)
13001 + return -EINVAL;
13002 ++ if (!len)
13003 ++ return -EINVAL;
13004 +
13005 + /* Don't allow a single read to cross a 512-byte block boundary */
13006 + if (from + len > ((from | 0x1ff) + 1))
13007 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/slram.c linux-2.6.27.10/drivers/mtd/devices/slram.c
13008 +--- linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-07 12:55:34.000000000 -0500
13009 ++++ linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-18 03:38:45.000000000 -0500
13010 +@@ -273,7 +273,7 @@ static int parse_cmdline(char *devname,
13011 + }
13012 + T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
13013 + devname, devstart, devlength);
13014 +- if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
13015 ++ if (devlength % SLRAM_BLK_SZ != 0) {
13016 + E("slram: Illegal start / length parameter.\n");
13017 + return(-EINVAL);
13018 + }
13019 +diff -urNp linux-2.6.27.10/drivers/mtd/ubi/build.c linux-2.6.27.10/drivers/mtd/ubi/build.c
13020 +--- linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-07 12:55:34.000000000 -0500
13021 ++++ linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-18 03:38:45.000000000 -0500
13022 +@@ -1104,7 +1104,7 @@ static int __init bytes_str_to_int(const
13023 + unsigned long result;
13024 +
13025 + result = simple_strtoul(str, &endp, 0);
13026 +- if (str == endp || result < 0) {
13027 ++ if (str == endp) {
13028 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
13029 + str);
13030 + return -EINVAL;
13031 +diff -urNp linux-2.6.27.10/drivers/net/eepro100.c linux-2.6.27.10/drivers/net/eepro100.c
13032 +--- linux-2.6.27.10/drivers/net/eepro100.c 2008-11-07 12:55:34.000000000 -0500
13033 ++++ linux-2.6.27.10/drivers/net/eepro100.c 2008-11-18 03:38:45.000000000 -0500
13034 +@@ -47,7 +47,7 @@ static int rxdmacount /* = 0 */;
13035 + # define rx_align(skb) skb_reserve((skb), 2)
13036 + # define RxFD_ALIGNMENT __attribute__ ((aligned (2), packed))
13037 + #else
13038 +-# define rx_align(skb)
13039 ++# define rx_align(skb) do {} while (0)
13040 + # define RxFD_ALIGNMENT
13041 + #endif
13042 +
13043 +@@ -2334,33 +2334,33 @@ static void __devexit eepro100_remove_on
13044 + }
13045 +
13046 + static struct pci_device_id eepro100_pci_tbl[] = {
13047 +- { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, },
13048 +- { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, },
13049 +- { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, },
13050 +- { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, },
13051 +- { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, },
13052 +- { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, },
13053 +- { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, },
13054 +- { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, },
13055 +- { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, },
13056 +- { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, },
13057 +- { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, },
13058 +- { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, },
13059 +- { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, },
13060 +- { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, },
13061 +- { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, },
13062 +- { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, },
13063 +- { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, },
13064 +- { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, },
13065 +- { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, },
13066 +- { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, },
13067 +- { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, },
13068 +- { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, },
13069 +- { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, },
13070 +- { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, },
13071 +- { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, },
13072 +- { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, },
13073 +- { 0,}
13074 ++ { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13075 ++ { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13076 ++ { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13077 ++ { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13078 ++ { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13079 ++ { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13080 ++ { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13081 ++ { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13082 ++ { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13083 ++ { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13084 ++ { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13085 ++ { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13086 ++ { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13087 ++ { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13088 ++ { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13089 ++ { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13090 ++ { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13091 ++ { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13092 ++ { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13093 ++ { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13094 ++ { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13095 ++ { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13096 ++ { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13097 ++ { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13098 ++ { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13099 ++ { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13100 ++ { 0, 0, 0, 0, 0, 0, 0 }
13101 + };
13102 + MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
13103 +
13104 +diff -urNp linux-2.6.27.10/drivers/net/irda/vlsi_ir.c linux-2.6.27.10/drivers/net/irda/vlsi_ir.c
13105 +--- linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-07 12:55:34.000000000 -0500
13106 ++++ linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-18 03:38:45.000000000 -0500
13107 +@@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s
13108 + /* no race - tx-ring already empty */
13109 + vlsi_set_baud(idev, iobase);
13110 + netif_wake_queue(ndev);
13111 +- }
13112 +- else
13113 +- ;
13114 ++ } else {
13115 + /* keep the speed change pending like it would
13116 + * for any len>0 packet. tx completion interrupt
13117 + * will apply it when the tx ring becomes empty.
13118 + */
13119 ++ }
13120 + spin_unlock_irqrestore(&idev->lock, flags);
13121 + dev_kfree_skb_any(skb);
13122 + return 0;
13123 +diff -urNp linux-2.6.27.10/drivers/net/pcnet32.c linux-2.6.27.10/drivers/net/pcnet32.c
13124 +--- linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-07 12:55:34.000000000 -0500
13125 ++++ linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-18 03:38:45.000000000 -0500
13126 +@@ -78,7 +78,7 @@ static int cards_found;
13127 + /*
13128 + * VLB I/O addresses
13129 + */
13130 +-static unsigned int pcnet32_portlist[] __initdata =
13131 ++static unsigned int pcnet32_portlist[] __devinitdata =
13132 + { 0x300, 0x320, 0x340, 0x360, 0 };
13133 +
13134 + static int pcnet32_debug = 0;
13135 +diff -urNp linux-2.6.27.10/drivers/net/tg3.h linux-2.6.27.10/drivers/net/tg3.h
13136 +--- linux-2.6.27.10/drivers/net/tg3.h 2008-11-07 12:55:34.000000000 -0500
13137 ++++ linux-2.6.27.10/drivers/net/tg3.h 2008-11-18 03:38:45.000000000 -0500
13138 +@@ -102,6 +102,7 @@
13139 + #define CHIPREV_ID_5750_A0 0x4000
13140 + #define CHIPREV_ID_5750_A1 0x4001
13141 + #define CHIPREV_ID_5750_A3 0x4003
13142 ++#define CHIPREV_ID_5750_C1 0x4201
13143 + #define CHIPREV_ID_5750_C2 0x4202
13144 + #define CHIPREV_ID_5752_A0_HW 0x5000
13145 + #define CHIPREV_ID_5752_A0 0x6000
13146 +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
13147 +--- linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-11-17 20:03:30.000000000 -0500
13148 ++++ linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-12-27 13:44:22.000000000 -0500
13149 +@@ -785,7 +785,7 @@ static int iwl3945_send_cmd_sync(struct
13150 + IWL_ERROR("Error: Response NULL in '%s'\n",
13151 + get_cmd_string(cmd->id));
13152 + ret = -EIO;
13153 +- goto out;
13154 ++ goto cancel;
13155 + }
13156 +
13157 + ret = 0;
13158 +diff -urNp linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c
13159 +--- linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-07 12:55:34.000000000 -0500
13160 ++++ linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-18 03:38:45.000000000 -0500
13161 +@@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_
13162 +
13163 + void compaq_nvram_init (void __iomem *rom_start)
13164 + {
13165 ++
13166 ++#ifndef CONFIG_PAX_KERNEXEC
13167 + if (rom_start) {
13168 + compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
13169 + }
13170 ++#endif
13171 ++
13172 + dbg("int15 entry = %p\n", compaq_int15_entry_point);
13173 +
13174 + /* initialize our int15 lock */
13175 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c
13176 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-07 12:55:34.000000000 -0500
13177 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-18 03:38:45.000000000 -0500
13178 +@@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i
13179 + .port_type = PCIE_RC_PORT,
13180 + .service_type = PCIE_PORT_SERVICE_AER,
13181 + },
13182 +- { /* end: all zeroes */ }
13183 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13184 + };
13185 +
13186 + static struct pci_error_handlers aer_error_handlers = {
13187 +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
13188 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-07 12:55:34.000000000 -0500
13189 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-18 03:38:45.000000000 -0500
13190 +@@ -663,7 +663,7 @@ static void aer_isr_one_error(struct pci
13191 + struct aer_err_source *e_src)
13192 + {
13193 + struct device *s_device;
13194 +- struct aer_err_info e_info = {0, 0, 0,};
13195 ++ struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}};
13196 + int i;
13197 + u16 id;
13198 +
13199 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c
13200 +--- linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-07 12:55:34.000000000 -0500
13201 ++++ linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-18 03:38:45.000000000 -0500
13202 +@@ -264,7 +264,7 @@ static void pcie_portdrv_err_resume(stru
13203 + static const struct pci_device_id port_pci_ids[] = { {
13204 + /* handle any PCI-Express port */
13205 + PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
13206 +- }, { /* end: all zeroes */ }
13207 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13208 + };
13209 + MODULE_DEVICE_TABLE(pci, port_pci_ids);
13210 +
13211 +diff -urNp linux-2.6.27.10/drivers/pci/proc.c linux-2.6.27.10/drivers/pci/proc.c
13212 +--- linux-2.6.27.10/drivers/pci/proc.c 2008-11-07 12:55:34.000000000 -0500
13213 ++++ linux-2.6.27.10/drivers/pci/proc.c 2008-11-18 03:38:45.000000000 -0500
13214 +@@ -470,7 +470,16 @@ static const struct file_operations proc
13215 + static int __init pci_proc_init(void)
13216 + {
13217 + struct pci_dev *dev = NULL;
13218 ++
13219 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
13220 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
13221 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
13222 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
13223 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
13224 ++#endif
13225 ++#else
13226 + proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
13227 ++#endif
13228 + proc_create("devices", 0, proc_bus_pci_dir,
13229 + &proc_bus_pci_dev_operations);
13230 + proc_initialized = 1;
13231 +diff -urNp linux-2.6.27.10/drivers/pcmcia/ti113x.h linux-2.6.27.10/drivers/pcmcia/ti113x.h
13232 +--- linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-07 12:55:34.000000000 -0500
13233 ++++ linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-18 03:38:45.000000000 -0500
13234 +@@ -897,7 +897,7 @@ static struct pci_device_id ene_tune_tbl
13235 + DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
13236 + ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
13237 +
13238 +- {}
13239 ++ { 0, 0, 0, 0, 0, 0, 0 }
13240 + };
13241 +
13242 + static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
13243 +diff -urNp linux-2.6.27.10/drivers/pcmcia/yenta_socket.c linux-2.6.27.10/drivers/pcmcia/yenta_socket.c
13244 +--- linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-07 12:55:34.000000000 -0500
13245 ++++ linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-18 03:38:45.000000000 -0500
13246 +@@ -1358,7 +1358,7 @@ static struct pci_device_id yenta_table
13247 +
13248 + /* match any cardbus bridge */
13249 + CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
13250 +- { /* all zeroes */ }
13251 ++ { 0, 0, 0, 0, 0, 0, 0 }
13252 + };
13253 + MODULE_DEVICE_TABLE(pci, yenta_table);
13254 +
13255 +diff -urNp linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c
13256 +--- linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-07 12:55:34.000000000 -0500
13257 ++++ linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-18 03:38:45.000000000 -0500
13258 +@@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr
13259 + set_limit(gdt[(selname) >> 3], size); \
13260 + } while(0)
13261 +
13262 +-static struct desc_struct bad_bios_desc;
13263 ++static struct desc_struct bad_bios_desc __read_only;
13264 +
13265 + /*
13266 + * At some point we want to use this stack frame pointer to unwind
13267 +@@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func
13268 + struct desc_struct save_desc_40;
13269 + int cpu;
13270 +
13271 ++#ifdef CONFIG_PAX_KERNEXEC
13272 ++ unsigned long cr0;
13273 ++#endif
13274 ++
13275 + /*
13276 + * PnP BIOSes are generally not terribly re-entrant.
13277 + * Also, don't rely on them to save everything correctly.
13278 +@@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func
13279 +
13280 + cpu = get_cpu();
13281 + save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
13282 ++
13283 ++#ifdef CONFIG_PAX_KERNEXEC
13284 ++ pax_open_kernel(cr0);
13285 ++#endif
13286 ++
13287 + get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
13288 +
13289 ++#ifdef CONFIG_PAX_KERNEXEC
13290 ++ pax_close_kernel(cr0);
13291 ++#endif
13292 ++
13293 + /* On some boxes IRQ's during PnP BIOS calls are deadly. */
13294 + spin_lock_irqsave(&pnp_bios_lock, flags);
13295 +
13296 +@@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func
13297 + :"memory");
13298 + spin_unlock_irqrestore(&pnp_bios_lock, flags);
13299 +
13300 ++#ifdef CONFIG_PAX_KERNEXEC
13301 ++ pax_open_kernel(cr0);
13302 ++#endif
13303 ++
13304 + get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
13305 ++
13306 ++#ifdef CONFIG_PAX_KERNEXEC
13307 ++ pax_close_kernel(cr0);
13308 ++#endif
13309 ++
13310 + put_cpu();
13311 +
13312 + /* If we get here and this is set then the PnP BIOS faulted on us. */
13313 +@@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n
13314 + return status;
13315 + }
13316 +
13317 +-void pnpbios_calls_init(union pnp_bios_install_struct *header)
13318 ++void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
13319 + {
13320 + int i;
13321 +
13322 ++#ifdef CONFIG_PAX_KERNEXEC
13323 ++ unsigned long cr0;
13324 ++#endif
13325 ++
13326 + spin_lock_init(&pnp_bios_lock);
13327 + pnp_bios_callpoint.offset = header->fields.pm16offset;
13328 + pnp_bios_callpoint.segment = PNP_CS16;
13329 +
13330 ++#ifdef CONFIG_PAX_KERNEXEC
13331 ++ pax_open_kernel(cr0);
13332 ++#endif
13333 ++
13334 + bad_bios_desc.a = 0;
13335 +- bad_bios_desc.b = 0x00409200;
13336 ++ bad_bios_desc.b = 0x00409300;
13337 +
13338 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
13339 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
13340 +@@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i
13341 + set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
13342 + __va(header->fields.pm16dseg));
13343 + }
13344 ++
13345 ++#ifdef CONFIG_PAX_KERNEXEC
13346 ++ pax_close_kernel(cr0);
13347 ++#endif
13348 ++
13349 + }
13350 +diff -urNp linux-2.6.27.10/drivers/pnp/quirks.c linux-2.6.27.10/drivers/pnp/quirks.c
13351 +--- linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:16:51.000000000 -0500
13352 ++++ linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:13:46.000000000 -0500
13353 +@@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = {
13354 + /* PnP resources that might overlap PCI BARs */
13355 + {"PNP0c01", quirk_system_pci_resources},
13356 + {"PNP0c02", quirk_system_pci_resources},
13357 +- {""}
13358 ++ {"", NULL}
13359 + };
13360 +
13361 + void pnp_fixup_device(struct pnp_dev *dev)
13362 +diff -urNp linux-2.6.27.10/drivers/pnp/resource.c linux-2.6.27.10/drivers/pnp/resource.c
13363 +--- linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:16:51.000000000 -0500
13364 ++++ linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:13:46.000000000 -0500
13365 +@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
13366 + return 1;
13367 +
13368 + /* check if the resource is valid */
13369 +- if (*irq < 0 || *irq > 15)
13370 ++ if (*irq > 15)
13371 + return 0;
13372 +
13373 + /* check if the resource is reserved */
13374 +@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
13375 + return 1;
13376 +
13377 + /* check if the resource is valid */
13378 +- if (*dma < 0 || *dma == 4 || *dma > 7)
13379 ++ if (*dma == 4 || *dma > 7)
13380 + return 0;
13381 +
13382 + /* check if the resource is reserved */
13383 +diff -urNp linux-2.6.27.10/drivers/scsi/scsi_logging.h linux-2.6.27.10/drivers/scsi/scsi_logging.h
13384 +--- linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-07 12:55:34.000000000 -0500
13385 ++++ linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-18 03:38:45.000000000 -0500
13386 +@@ -51,7 +51,7 @@ do { \
13387 + } while (0); \
13388 + } while (0)
13389 + #else
13390 +-#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
13391 ++#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
13392 + #endif /* CONFIG_SCSI_LOGGING */
13393 +
13394 + /*
13395 +diff -urNp linux-2.6.27.10/drivers/serial/8250_pci.c linux-2.6.27.10/drivers/serial/8250_pci.c
13396 +--- linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-07 12:55:34.000000000 -0500
13397 ++++ linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-18 03:38:45.000000000 -0500
13398 +@@ -2859,7 +2859,7 @@ static struct pci_device_id serial_pci_t
13399 + PCI_ANY_ID, PCI_ANY_ID,
13400 + PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
13401 + 0xffff00, pbn_default },
13402 +- { 0, }
13403 ++ { 0, 0, 0, 0, 0, 0, 0 }
13404 + };
13405 +
13406 + static struct pci_driver serial_pci_driver = {
13407 +diff -urNp linux-2.6.27.10/drivers/usb/class/cdc-acm.c linux-2.6.27.10/drivers/usb/class/cdc-acm.c
13408 +--- linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:38:40.000000000 -0500
13409 ++++ linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:40:52.000000000 -0500
13410 +@@ -1381,7 +1381,7 @@ static struct usb_device_id acm_ids[] =
13411 + USB_CDC_ACM_PROTO_AT_CDMA) },
13412 +
13413 + /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
13414 +- { }
13415 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13416 + };
13417 +
13418 + MODULE_DEVICE_TABLE (usb, acm_ids);
13419 +diff -urNp linux-2.6.27.10/drivers/usb/class/usblp.c linux-2.6.27.10/drivers/usb/class/usblp.c
13420 +--- linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-07 12:55:34.000000000 -0500
13421 ++++ linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-18 03:38:45.000000000 -0500
13422 +@@ -227,7 +227,7 @@ static const struct quirk_printer_struct
13423 + { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
13424 + { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@×××.de> */
13425 + { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
13426 +- { 0, 0 }
13427 ++ { 0, 0, 0 }
13428 + };
13429 +
13430 + static int usblp_wwait(struct usblp *usblp, int nonblock);
13431 +@@ -1401,7 +1401,7 @@ static struct usb_device_id usblp_ids []
13432 + { USB_INTERFACE_INFO(7, 1, 2) },
13433 + { USB_INTERFACE_INFO(7, 1, 3) },
13434 + { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
13435 +- { } /* Terminating entry */
13436 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13437 + };
13438 +
13439 + MODULE_DEVICE_TABLE (usb, usblp_ids);
13440 +diff -urNp linux-2.6.27.10/drivers/usb/core/hub.c linux-2.6.27.10/drivers/usb/core/hub.c
13441 +--- linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-07 12:55:34.000000000 -0500
13442 ++++ linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-18 03:38:45.000000000 -0500
13443 +@@ -3111,7 +3111,7 @@ static struct usb_device_id hub_id_table
13444 + .bDeviceClass = USB_CLASS_HUB},
13445 + { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
13446 + .bInterfaceClass = USB_CLASS_HUB},
13447 +- { } /* Terminating entry */
13448 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13449 + };
13450 +
13451 + MODULE_DEVICE_TABLE (usb, hub_id_table);
13452 +diff -urNp linux-2.6.27.10/drivers/usb/host/ehci-pci.c linux-2.6.27.10/drivers/usb/host/ehci-pci.c
13453 +--- linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:37.000000000 -0500
13454 ++++ linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:46.000000000 -0500
13455 +@@ -414,7 +414,7 @@ static const struct pci_device_id pci_id
13456 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
13457 + .driver_data = (unsigned long) &ehci_pci_hc_driver,
13458 + },
13459 +- { /* end: all zeroes */ }
13460 ++ { 0, 0, 0, 0, 0, 0, 0 }
13461 + };
13462 + MODULE_DEVICE_TABLE(pci, pci_ids);
13463 +
13464 +diff -urNp linux-2.6.27.10/drivers/usb/host/uhci-hcd.c linux-2.6.27.10/drivers/usb/host/uhci-hcd.c
13465 +--- linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-07 12:55:34.000000000 -0500
13466 ++++ linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-18 03:38:45.000000000 -0500
13467 +@@ -928,7 +928,7 @@ static const struct pci_device_id uhci_p
13468 + /* handle any USB UHCI controller */
13469 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
13470 + .driver_data = (unsigned long) &uhci_driver,
13471 +- }, { /* end: all zeroes */ }
13472 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13473 + };
13474 +
13475 + MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
13476 +diff -urNp linux-2.6.27.10/drivers/usb/storage/debug.h linux-2.6.27.10/drivers/usb/storage/debug.h
13477 +--- linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-07 12:55:34.000000000 -0500
13478 ++++ linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-18 03:38:45.000000000 -0500
13479 +@@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
13480 + #define US_DEBUGPX(x...) printk( x )
13481 + #define US_DEBUG(x) x
13482 + #else
13483 +-#define US_DEBUGP(x...)
13484 +-#define US_DEBUGPX(x...)
13485 +-#define US_DEBUG(x)
13486 ++#define US_DEBUGP(x...) do {} while (0)
13487 ++#define US_DEBUGPX(x...) do {} while (0)
13488 ++#define US_DEBUG(x) do {} while (0)
13489 + #endif
13490 +
13491 + #endif
13492 +diff -urNp linux-2.6.27.10/drivers/usb/storage/usb.c linux-2.6.27.10/drivers/usb/storage/usb.c
13493 +--- linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-07 12:55:34.000000000 -0500
13494 ++++ linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-18 03:38:45.000000000 -0500
13495 +@@ -136,7 +136,7 @@ static struct usb_device_id storage_usb_
13496 + #undef UNUSUAL_DEV
13497 + #undef USUAL_DEV
13498 + /* Terminating entry */
13499 +- { }
13500 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13501 + };
13502 +
13503 + MODULE_DEVICE_TABLE (usb, storage_usb_ids);
13504 +@@ -176,7 +176,7 @@ static struct us_unusual_dev us_unusual_
13505 + # undef USUAL_DEV
13506 +
13507 + /* Terminating entry */
13508 +- { NULL }
13509 ++ { NULL, NULL, 0, 0, NULL }
13510 + };
13511 +
13512 +
13513 +diff -urNp linux-2.6.27.10/drivers/video/fbcmap.c linux-2.6.27.10/drivers/video/fbcmap.c
13514 +--- linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-07 12:55:34.000000000 -0500
13515 ++++ linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-18 03:38:45.000000000 -0500
13516 +@@ -250,8 +250,7 @@ int fb_set_user_cmap(struct fb_cmap_user
13517 + int rc, size = cmap->len * sizeof(u16);
13518 + struct fb_cmap umap;
13519 +
13520 +- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
13521 +- !info->fbops->fb_setcmap))
13522 ++ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap)
13523 + return -EINVAL;
13524 +
13525 + memset(&umap, 0, sizeof(struct fb_cmap));
13526 +diff -urNp linux-2.6.27.10/drivers/video/fbmem.c linux-2.6.27.10/drivers/video/fbmem.c
13527 +--- linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:37.000000000 -0500
13528 ++++ linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:46.000000000 -0500
13529 +@@ -395,7 +395,7 @@ static void fb_do_show_logo(struct fb_in
13530 + image->dx += image->width + 8;
13531 + }
13532 + } else if (rotate == FB_ROTATE_UD) {
13533 +- for (x = 0; x < num && image->dx >= 0; x++) {
13534 ++ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
13535 + info->fbops->fb_imageblit(info, image);
13536 + image->dx -= image->width + 8;
13537 + }
13538 +@@ -407,7 +407,7 @@ static void fb_do_show_logo(struct fb_in
13539 + image->dy += image->height + 8;
13540 + }
13541 + } else if (rotate == FB_ROTATE_CCW) {
13542 +- for (x = 0; x < num && image->dy >= 0; x++) {
13543 ++ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
13544 + info->fbops->fb_imageblit(info, image);
13545 + image->dy -= image->height + 8;
13546 + }
13547 +@@ -1083,7 +1083,7 @@ fb_ioctl(struct inode *inode, struct fil
13548 + return - EFAULT;
13549 + if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
13550 + return -EINVAL;
13551 +- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
13552 ++ if (con2fb.framebuffer >= FB_MAX)
13553 + return -EINVAL;
13554 + #ifdef CONFIG_KMOD
13555 + if (!registered_fb[con2fb.framebuffer])
13556 +diff -urNp linux-2.6.27.10/drivers/video/fbmon.c linux-2.6.27.10/drivers/video/fbmon.c
13557 +--- linux-2.6.27.10/drivers/video/fbmon.c 2008-11-07 12:55:34.000000000 -0500
13558 ++++ linux-2.6.27.10/drivers/video/fbmon.c 2008-11-18 03:38:45.000000000 -0500
13559 +@@ -45,7 +45,7 @@
13560 + #ifdef DEBUG
13561 + #define DPRINTK(fmt, args...) printk(fmt,## args)
13562 + #else
13563 +-#define DPRINTK(fmt, args...)
13564 ++#define DPRINTK(fmt, args...) do {} while (0)
13565 + #endif
13566 +
13567 + #define FBMON_FIX_HEADER 1
13568 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_accel.c linux-2.6.27.10/drivers/video/i810/i810_accel.c
13569 +--- linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-07 12:55:34.000000000 -0500
13570 ++++ linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-18 03:38:45.000000000 -0500
13571 +@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
13572 + }
13573 + }
13574 + printk("ringbuffer lockup!!!\n");
13575 ++ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
13576 + i810_report_error(mmio);
13577 + par->dev_flags |= LOCKUP;
13578 + info->pixmap.scan_align = 1;
13579 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_main.c linux-2.6.27.10/drivers/video/i810/i810_main.c
13580 +--- linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-07 12:55:34.000000000 -0500
13581 ++++ linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-18 03:38:45.000000000 -0500
13582 +@@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
13583 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
13584 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
13585 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
13586 +- { 0 },
13587 ++ { 0, 0, 0, 0, 0, 0, 0 },
13588 + };
13589 +
13590 + static struct pci_driver i810fb_driver = {
13591 +@@ -1509,7 +1509,7 @@ static int i810fb_cursor(struct fb_info
13592 + int size = ((cursor->image.width + 7) >> 3) *
13593 + cursor->image.height;
13594 + int i;
13595 +- u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
13596 ++ u8 *data = kmalloc(64 * 8, GFP_KERNEL);
13597 +
13598 + if (data == NULL)
13599 + return -ENOMEM;
13600 +diff -urNp linux-2.6.27.10/drivers/video/modedb.c linux-2.6.27.10/drivers/video/modedb.c
13601 +--- linux-2.6.27.10/drivers/video/modedb.c 2008-11-07 12:55:34.000000000 -0500
13602 ++++ linux-2.6.27.10/drivers/video/modedb.c 2008-11-18 03:38:45.000000000 -0500
13603 +@@ -38,232 +38,232 @@ static const struct fb_videomode modedb[
13604 + {
13605 + /* 640x400 @ 70 Hz, 31.5 kHz hsync */
13606 + NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
13607 +- 0, FB_VMODE_NONINTERLACED
13608 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13609 + }, {
13610 + /* 640x480 @ 60 Hz, 31.5 kHz hsync */
13611 + NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
13612 +- 0, FB_VMODE_NONINTERLACED
13613 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13614 + }, {
13615 + /* 800x600 @ 56 Hz, 35.15 kHz hsync */
13616 + NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
13617 +- 0, FB_VMODE_NONINTERLACED
13618 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13619 + }, {
13620 + /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
13621 + NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
13622 +- 0, FB_VMODE_INTERLACED
13623 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13624 + }, {
13625 + /* 640x400 @ 85 Hz, 37.86 kHz hsync */
13626 + NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
13627 +- FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13628 ++ FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13629 + }, {
13630 + /* 640x480 @ 72 Hz, 36.5 kHz hsync */
13631 + NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
13632 +- 0, FB_VMODE_NONINTERLACED
13633 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13634 + }, {
13635 + /* 640x480 @ 75 Hz, 37.50 kHz hsync */
13636 + NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
13637 +- 0, FB_VMODE_NONINTERLACED
13638 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13639 + }, {
13640 + /* 800x600 @ 60 Hz, 37.8 kHz hsync */
13641 + NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
13642 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13643 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13644 + }, {
13645 + /* 640x480 @ 85 Hz, 43.27 kHz hsync */
13646 + NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
13647 +- 0, FB_VMODE_NONINTERLACED
13648 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13649 + }, {
13650 + /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
13651 + NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
13652 +- 0, FB_VMODE_INTERLACED
13653 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13654 + }, {
13655 + /* 800x600 @ 72 Hz, 48.0 kHz hsync */
13656 + NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
13657 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13658 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13659 + }, {
13660 + /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
13661 + NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
13662 +- 0, FB_VMODE_NONINTERLACED
13663 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13664 + }, {
13665 + /* 640x480 @ 100 Hz, 53.01 kHz hsync */
13666 + NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
13667 +- 0, FB_VMODE_NONINTERLACED
13668 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13669 + }, {
13670 + /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
13671 + NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
13672 +- 0, FB_VMODE_NONINTERLACED
13673 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13674 + }, {
13675 + /* 800x600 @ 85 Hz, 55.84 kHz hsync */
13676 + NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
13677 +- 0, FB_VMODE_NONINTERLACED
13678 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13679 + }, {
13680 + /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
13681 + NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
13682 +- 0, FB_VMODE_NONINTERLACED
13683 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13684 + }, {
13685 + /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
13686 + NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
13687 +- 0, FB_VMODE_INTERLACED
13688 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13689 + }, {
13690 + /* 800x600 @ 100 Hz, 64.02 kHz hsync */
13691 + NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
13692 +- 0, FB_VMODE_NONINTERLACED
13693 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13694 + }, {
13695 + /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
13696 + NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
13697 +- 0, FB_VMODE_NONINTERLACED
13698 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13699 + }, {
13700 + /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
13701 + NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
13702 +- 0, FB_VMODE_NONINTERLACED
13703 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13704 + }, {
13705 + /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
13706 + NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
13707 +- 0, FB_VMODE_NONINTERLACED
13708 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13709 + }, {
13710 + /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
13711 + NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
13712 +- 0, FB_VMODE_NONINTERLACED
13713 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13714 + }, {
13715 + /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
13716 + NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
13717 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13718 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13719 + }, {
13720 + /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
13721 + NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
13722 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13723 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13724 + }, {
13725 + /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
13726 + NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
13727 +- 0, FB_VMODE_NONINTERLACED
13728 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13729 + }, {
13730 + /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
13731 + NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
13732 +- 0, FB_VMODE_NONINTERLACED
13733 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13734 + }, {
13735 + /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
13736 + NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
13737 +- 0, FB_VMODE_NONINTERLACED
13738 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13739 + }, {
13740 + /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
13741 + NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
13742 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13743 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13744 + }, {
13745 + /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
13746 + NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
13747 +- 0, FB_VMODE_NONINTERLACED
13748 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13749 + }, {
13750 + /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
13751 + NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
13752 +- 0, FB_VMODE_NONINTERLACED
13753 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13754 + }, {
13755 + /* 1024x768 @ 100Hz, 80.21 kHz hsync */
13756 + NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
13757 +- 0, FB_VMODE_NONINTERLACED
13758 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13759 + }, {
13760 + /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
13761 + NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
13762 +- 0, FB_VMODE_NONINTERLACED
13763 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13764 + }, {
13765 + /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
13766 + NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
13767 +- 0, FB_VMODE_NONINTERLACED
13768 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13769 + }, {
13770 + /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
13771 + NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
13772 +- 0, FB_VMODE_NONINTERLACED
13773 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13774 + }, {
13775 + /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
13776 + NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
13777 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13778 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13779 + }, {
13780 + /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
13781 + NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
13782 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13783 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13784 + }, {
13785 + /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
13786 + NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
13787 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13788 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13789 + }, {
13790 + /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
13791 + NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
13792 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13793 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13794 + }, {
13795 + /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
13796 + NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
13797 +- 0, FB_VMODE_NONINTERLACED
13798 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13799 + }, {
13800 + /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
13801 + NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
13802 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13803 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13804 + }, {
13805 + /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
13806 + NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
13807 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13808 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13809 + }, {
13810 + /* 512x384 @ 78 Hz, 31.50 kHz hsync */
13811 + NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
13812 +- 0, FB_VMODE_NONINTERLACED
13813 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13814 + }, {
13815 + /* 512x384 @ 85 Hz, 34.38 kHz hsync */
13816 + NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
13817 +- 0, FB_VMODE_NONINTERLACED
13818 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13819 + }, {
13820 + /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
13821 + NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
13822 +- 0, FB_VMODE_DOUBLE
13823 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13824 + }, {
13825 + /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
13826 + NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
13827 +- 0, FB_VMODE_DOUBLE
13828 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13829 + }, {
13830 + /* 320x240 @ 72 Hz, 36.5 kHz hsync */
13831 + NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
13832 +- 0, FB_VMODE_DOUBLE
13833 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13834 + }, {
13835 + /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
13836 + NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
13837 +- 0, FB_VMODE_DOUBLE
13838 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13839 + }, {
13840 + /* 400x300 @ 60 Hz, 37.8 kHz hsync */
13841 + NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
13842 +- 0, FB_VMODE_DOUBLE
13843 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13844 + }, {
13845 + /* 400x300 @ 72 Hz, 48.0 kHz hsync */
13846 + NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
13847 +- 0, FB_VMODE_DOUBLE
13848 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13849 + }, {
13850 + /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
13851 + NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
13852 +- 0, FB_VMODE_DOUBLE
13853 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13854 + }, {
13855 + /* 480x300 @ 60 Hz, 37.8 kHz hsync */
13856 + NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
13857 +- 0, FB_VMODE_DOUBLE
13858 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13859 + }, {
13860 + /* 480x300 @ 63 Hz, 39.6 kHz hsync */
13861 + NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
13862 +- 0, FB_VMODE_DOUBLE
13863 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13864 + }, {
13865 + /* 480x300 @ 72 Hz, 48.0 kHz hsync */
13866 + NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
13867 +- 0, FB_VMODE_DOUBLE
13868 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13869 + }, {
13870 + /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
13871 + NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
13872 + FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
13873 +- FB_VMODE_NONINTERLACED
13874 ++ FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13875 + }, {
13876 + /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
13877 + NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
13878 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13879 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13880 + }, {
13881 + /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
13882 + NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
13883 +- 0, FB_VMODE_NONINTERLACED
13884 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13885 + }, {
13886 + /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
13887 + NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
13888 +- 0, FB_VMODE_NONINTERLACED
13889 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13890 + },
13891 + };
13892 +
13893 +diff -urNp linux-2.6.27.10/drivers/video/uvesafb.c linux-2.6.27.10/drivers/video/uvesafb.c
13894 +--- linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-07 12:55:34.000000000 -0500
13895 ++++ linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-18 03:38:45.000000000 -0500
13896 +@@ -18,6 +18,7 @@
13897 + #include <linux/fb.h>
13898 + #include <linux/io.h>
13899 + #include <linux/mutex.h>
13900 ++#include <linux/moduleloader.h>
13901 + #include <video/edid.h>
13902 + #include <video/uvesafb.h>
13903 + #ifdef CONFIG_X86
13904 +@@ -117,7 +118,7 @@ static int uvesafb_helper_start(void)
13905 + NULL,
13906 + };
13907 +
13908 +- return call_usermodehelper(v86d_path, argv, envp, 1);
13909 ++ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
13910 + }
13911 +
13912 + /*
13913 +@@ -569,10 +570,34 @@ static int __devinit uvesafb_vbe_getpmi(
13914 + if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
13915 + par->pmi_setpal = par->ypan = 0;
13916 + } else {
13917 ++
13918 ++#ifdef CONFIG_PAX_KERNEXEC
13919 ++#ifdef CONFIG_MODULES
13920 ++ unsigned long cr0;
13921 ++
13922 ++ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
13923 ++#endif
13924 ++ if (!par->pmi_code) {
13925 ++ par->pmi_setpal = par->ypan = 0;
13926 ++ return 0;
13927 ++ }
13928 ++#endif
13929 ++
13930 + par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
13931 + + task->t.regs.edi);
13932 ++
13933 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13934 ++ pax_open_kernel(cr0);
13935 ++ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
13936 ++ pax_close_kernel(cr0);
13937 ++
13938 ++ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
13939 ++ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
13940 ++#else
13941 + par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
13942 + par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
13943 ++#endif
13944 ++
13945 + printk(KERN_INFO "uvesafb: protected mode interface info at "
13946 + "%04x:%04x\n",
13947 + (u16)task->t.regs.es, (u16)task->t.regs.edi);
13948 +@@ -1827,6 +1852,11 @@ out:
13949 + if (par->vbe_modes)
13950 + kfree(par->vbe_modes);
13951 +
13952 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13953 ++ if (par->pmi_code)
13954 ++ module_free_exec(NULL, par->pmi_code);
13955 ++#endif
13956 ++
13957 + framebuffer_release(info);
13958 + return err;
13959 + }
13960 +@@ -1853,6 +1883,12 @@ static int uvesafb_remove(struct platfor
13961 + kfree(par->vbe_state_orig);
13962 + if (par->vbe_state_saved)
13963 + kfree(par->vbe_state_saved);
13964 ++
13965 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13966 ++ if (par->pmi_code)
13967 ++ module_free_exec(NULL, par->pmi_code);
13968 ++#endif
13969 ++
13970 + }
13971 +
13972 + framebuffer_release(info);
13973 +diff -urNp linux-2.6.27.10/drivers/video/vesafb.c linux-2.6.27.10/drivers/video/vesafb.c
13974 +--- linux-2.6.27.10/drivers/video/vesafb.c 2008-11-07 12:55:34.000000000 -0500
13975 ++++ linux-2.6.27.10/drivers/video/vesafb.c 2008-11-18 03:38:45.000000000 -0500
13976 +@@ -9,6 +9,7 @@
13977 + */
13978 +
13979 + #include <linux/module.h>
13980 ++#include <linux/moduleloader.h>
13981 + #include <linux/kernel.h>
13982 + #include <linux/errno.h>
13983 + #include <linux/string.h>
13984 +@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
13985 + static int vram_total __initdata; /* Set total amount of memory */
13986 + static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
13987 + static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
13988 +-static void (*pmi_start)(void) __read_mostly;
13989 +-static void (*pmi_pal) (void) __read_mostly;
13990 ++static void (*pmi_start)(void) __read_only;
13991 ++static void (*pmi_pal) (void) __read_only;
13992 + static int depth __read_mostly;
13993 + static int vga_compat __read_mostly;
13994 + /* --------------------------------------------------------------------- */
13995 +@@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl
13996 + unsigned int size_vmode;
13997 + unsigned int size_remap;
13998 + unsigned int size_total;
13999 ++ void *pmi_code = NULL;
14000 +
14001 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
14002 + return -ENODEV;
14003 +@@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl
14004 + size_remap = size_total;
14005 + vesafb_fix.smem_len = size_remap;
14006 +
14007 +-#ifndef __i386__
14008 +- screen_info.vesapm_seg = 0;
14009 +-#endif
14010 +-
14011 + if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
14012 + printk(KERN_WARNING
14013 + "vesafb: cannot reserve video memory at 0x%lx\n",
14014 +@@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl
14015 + printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
14016 + vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
14017 +
14018 ++#ifdef __i386__
14019 ++
14020 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
14021 ++ pmi_code = module_alloc_exec(screen_info.vesapm_size);
14022 ++ if (!pmi_code)
14023 ++#elif !defined(CONFIG_PAX_KERNEXEC)
14024 ++ if (0)
14025 ++#endif
14026 ++
14027 ++#endif
14028 ++ screen_info.vesapm_seg = 0;
14029 ++
14030 + if (screen_info.vesapm_seg) {
14031 +- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
14032 +- screen_info.vesapm_seg,screen_info.vesapm_off);
14033 ++ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
14034 ++ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
14035 + }
14036 +
14037 + if (screen_info.vesapm_seg < 0xc000)
14038 +@@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl
14039 +
14040 + if (ypan || pmi_setpal) {
14041 + unsigned short *pmi_base;
14042 +- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
14043 +- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
14044 +- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
14045 ++
14046 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
14047 ++ unsigned long cr0;
14048 ++#endif
14049 ++
14050 ++ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
14051 ++
14052 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
14053 ++ pax_open_kernel(cr0);
14054 ++ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
14055 ++#else
14056 ++ pmi_code = pmi_base;
14057 ++#endif
14058 ++
14059 ++ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
14060 ++ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
14061 ++
14062 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
14063 ++ pmi_start = ktva_ktla(pmi_start);
14064 ++ pmi_pal = ktva_ktla(pmi_pal);
14065 ++ pax_close_kernel(cr0);
14066 ++#endif
14067 ++
14068 + printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
14069 + if (pmi_base[3]) {
14070 + printk(KERN_INFO "vesafb: pmi: ports = ");
14071 +@@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl
14072 + info->node, info->fix.id);
14073 + return 0;
14074 + err:
14075 ++
14076 ++#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
14077 ++ module_free_exec(NULL, pmi_code);
14078 ++#endif
14079 ++
14080 + if (info->screen_base)
14081 + iounmap(info->screen_base);
14082 + framebuffer_release(info);
14083 +diff -urNp linux-2.6.27.10/fs/9p/vfs_inode.c linux-2.6.27.10/fs/9p/vfs_inode.c
14084 +--- linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-07 12:55:34.000000000 -0500
14085 ++++ linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-18 03:38:45.000000000 -0500
14086 +@@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct
14087 + static void
14088 + v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
14089 + {
14090 +- char *s = nd_get_link(nd);
14091 ++ const char *s = nd_get_link(nd);
14092 +
14093 + P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
14094 + if (!IS_ERR(s))
14095 +diff -urNp linux-2.6.27.10/fs/aio.c linux-2.6.27.10/fs/aio.c
14096 +--- linux-2.6.27.10/fs/aio.c 2008-11-07 12:55:34.000000000 -0500
14097 ++++ linux-2.6.27.10/fs/aio.c 2008-11-18 03:38:45.000000000 -0500
14098 +@@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx
14099 + size += sizeof(struct io_event) * nr_events;
14100 + nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
14101 +
14102 +- if (nr_pages < 0)
14103 ++ if (nr_pages <= 0)
14104 + return -EINVAL;
14105 +
14106 + nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
14107 +diff -urNp linux-2.6.27.10/fs/autofs4/symlink.c linux-2.6.27.10/fs/autofs4/symlink.c
14108 +--- linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-07 12:55:34.000000000 -0500
14109 ++++ linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-18 03:38:45.000000000 -0500
14110 +@@ -15,7 +15,7 @@
14111 + static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
14112 + {
14113 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
14114 +- nd_set_link(nd, (char *)ino->u.symlink);
14115 ++ nd_set_link(nd, ino->u.symlink);
14116 + return NULL;
14117 + }
14118 +
14119 +diff -urNp linux-2.6.27.10/fs/befs/linuxvfs.c linux-2.6.27.10/fs/befs/linuxvfs.c
14120 +--- linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-07 12:55:34.000000000 -0500
14121 ++++ linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-18 03:38:45.000000000 -0500
14122 +@@ -490,7 +490,7 @@ static void befs_put_link(struct dentry
14123 + {
14124 + befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
14125 + if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
14126 +- char *link = nd_get_link(nd);
14127 ++ const char *link = nd_get_link(nd);
14128 + if (!IS_ERR(link))
14129 + kfree(link);
14130 + }
14131 +diff -urNp linux-2.6.27.10/fs/binfmt_aout.c linux-2.6.27.10/fs/binfmt_aout.c
14132 +--- linux-2.6.27.10/fs/binfmt_aout.c 2008-11-07 12:55:34.000000000 -0500
14133 ++++ linux-2.6.27.10/fs/binfmt_aout.c 2008-11-18 03:38:45.000000000 -0500
14134 +@@ -24,6 +24,7 @@
14135 + #include <linux/binfmts.h>
14136 + #include <linux/personality.h>
14137 + #include <linux/init.h>
14138 ++#include <linux/grsecurity.h>
14139 +
14140 + #include <asm/system.h>
14141 + #include <asm/uaccess.h>
14142 +@@ -124,18 +125,22 @@ static int aout_core_dump(long signr, st
14143 + /* If the size of the dump file exceeds the rlimit, then see what would happen
14144 + if we wrote the stack, but not the data area. */
14145 + #ifdef __sparc__
14146 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize + dump.u_ssize, 1);
14147 + if ((dump.u_dsize + dump.u_ssize) > limit)
14148 + dump.u_dsize = 0;
14149 + #else
14150 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
14151 + if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
14152 + dump.u_dsize = 0;
14153 + #endif
14154 +
14155 + /* Make sure we have enough room to write the stack and data areas. */
14156 + #ifdef __sparc__
14157 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize, 1);
14158 + if (dump.u_ssize > limit)
14159 + dump.u_ssize = 0;
14160 + #else
14161 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
14162 + if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
14163 + dump.u_ssize = 0;
14164 + #endif
14165 +@@ -291,6 +296,8 @@ static int load_aout_binary(struct linux
14166 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
14167 + if (rlim >= RLIM_INFINITY)
14168 + rlim = ~0;
14169 ++
14170 ++ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
14171 + if (ex.a_data + ex.a_bss > rlim)
14172 + return -ENOMEM;
14173 +
14174 +@@ -322,6 +329,28 @@ static int load_aout_binary(struct linux
14175 +
14176 + compute_creds(bprm);
14177 + current->flags &= ~PF_FORKNOEXEC;
14178 ++
14179 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14180 ++ current->mm->pax_flags = 0UL;
14181 ++#endif
14182 ++
14183 ++#ifdef CONFIG_PAX_PAGEEXEC
14184 ++ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
14185 ++ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
14186 ++
14187 ++#ifdef CONFIG_PAX_EMUTRAMP
14188 ++ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
14189 ++ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
14190 ++#endif
14191 ++
14192 ++#ifdef CONFIG_PAX_MPROTECT
14193 ++ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
14194 ++ current->mm->pax_flags |= MF_PAX_MPROTECT;
14195 ++#endif
14196 ++
14197 ++ }
14198 ++#endif
14199 ++
14200 + #ifdef __sparc__
14201 + if (N_MAGIC(ex) == NMAGIC) {
14202 + loff_t pos = fd_offset;
14203 +@@ -413,7 +442,7 @@ static int load_aout_binary(struct linux
14204 +
14205 + down_write(&current->mm->mmap_sem);
14206 + error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
14207 +- PROT_READ | PROT_WRITE | PROT_EXEC,
14208 ++ PROT_READ | PROT_WRITE,
14209 + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
14210 + fd_offset + ex.a_text);
14211 + up_write(&current->mm->mmap_sem);
14212 +diff -urNp linux-2.6.27.10/fs/binfmt_elf.c linux-2.6.27.10/fs/binfmt_elf.c
14213 +--- linux-2.6.27.10/fs/binfmt_elf.c 2008-11-07 12:55:34.000000000 -0500
14214 ++++ linux-2.6.27.10/fs/binfmt_elf.c 2008-12-21 00:51:06.000000000 -0500
14215 +@@ -38,10 +38,16 @@
14216 + #include <linux/random.h>
14217 + #include <linux/elf.h>
14218 + #include <linux/utsname.h>
14219 ++#include <linux/grsecurity.h>
14220 ++
14221 + #include <asm/uaccess.h>
14222 + #include <asm/param.h>
14223 + #include <asm/page.h>
14224 +
14225 ++#ifdef CONFIG_PAX_SEGMEXEC
14226 ++#include <asm/desc.h>
14227 ++#endif
14228 ++
14229 + static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
14230 + static int load_elf_library(struct file *);
14231 + static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
14232 +@@ -57,6 +63,10 @@ static int elf_core_dump(long signr, str
14233 + #define elf_core_dump NULL
14234 + #endif
14235 +
14236 ++#ifdef CONFIG_PAX_MPROTECT
14237 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
14238 ++#endif
14239 ++
14240 + #if ELF_EXEC_PAGESIZE > PAGE_SIZE
14241 + #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
14242 + #else
14243 +@@ -76,6 +86,11 @@ static struct linux_binfmt elf_format =
14244 + .load_binary = load_elf_binary,
14245 + .load_shlib = load_elf_library,
14246 + .core_dump = elf_core_dump,
14247 ++
14248 ++#ifdef CONFIG_PAX_MPROTECT
14249 ++ .handle_mprotect= elf_handle_mprotect,
14250 ++#endif
14251 ++
14252 + .min_coredump = ELF_EXEC_PAGESIZE,
14253 + .hasvdso = 1
14254 + };
14255 +@@ -84,6 +99,8 @@ static struct linux_binfmt elf_format =
14256 +
14257 + static int set_brk(unsigned long start, unsigned long end)
14258 + {
14259 ++ unsigned long e = end;
14260 ++
14261 + start = ELF_PAGEALIGN(start);
14262 + end = ELF_PAGEALIGN(end);
14263 + if (end > start) {
14264 +@@ -94,7 +111,7 @@ static int set_brk(unsigned long start,
14265 + if (BAD_ADDR(addr))
14266 + return addr;
14267 + }
14268 +- current->mm->start_brk = current->mm->brk = end;
14269 ++ current->mm->start_brk = current->mm->brk = e;
14270 + return 0;
14271 + }
14272 +
14273 +@@ -380,10 +397,10 @@ static unsigned long load_elf_interp(str
14274 + {
14275 + struct elf_phdr *elf_phdata;
14276 + struct elf_phdr *eppnt;
14277 +- unsigned long load_addr = 0;
14278 ++ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
14279 + int load_addr_set = 0;
14280 + unsigned long last_bss = 0, elf_bss = 0;
14281 +- unsigned long error = ~0UL;
14282 ++ unsigned long error = -EINVAL;
14283 + unsigned long total_size;
14284 + int retval, i, size;
14285 +
14286 +@@ -429,6 +446,11 @@ static unsigned long load_elf_interp(str
14287 + goto out_close;
14288 + }
14289 +
14290 ++#ifdef CONFIG_PAX_SEGMEXEC
14291 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14292 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14293 ++#endif
14294 ++
14295 + eppnt = elf_phdata;
14296 + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
14297 + if (eppnt->p_type == PT_LOAD) {
14298 +@@ -472,8 +494,8 @@ static unsigned long load_elf_interp(str
14299 + k = load_addr + eppnt->p_vaddr;
14300 + if (BAD_ADDR(k) ||
14301 + eppnt->p_filesz > eppnt->p_memsz ||
14302 +- eppnt->p_memsz > TASK_SIZE ||
14303 +- TASK_SIZE - eppnt->p_memsz < k) {
14304 ++ eppnt->p_memsz > pax_task_size ||
14305 ++ pax_task_size - eppnt->p_memsz < k) {
14306 + error = -ENOMEM;
14307 + goto out_close;
14308 + }
14309 +@@ -527,6 +549,177 @@ out:
14310 + return error;
14311 + }
14312 +
14313 ++#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
14314 ++static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
14315 ++{
14316 ++ unsigned long pax_flags = 0UL;
14317 ++
14318 ++#ifdef CONFIG_PAX_PAGEEXEC
14319 ++ if (elf_phdata->p_flags & PF_PAGEEXEC)
14320 ++ pax_flags |= MF_PAX_PAGEEXEC;
14321 ++#endif
14322 ++
14323 ++#ifdef CONFIG_PAX_SEGMEXEC
14324 ++ if (elf_phdata->p_flags & PF_SEGMEXEC)
14325 ++ pax_flags |= MF_PAX_SEGMEXEC;
14326 ++#endif
14327 ++
14328 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14329 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14330 ++ if (nx_enabled)
14331 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14332 ++ else
14333 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14334 ++ }
14335 ++#endif
14336 ++
14337 ++#ifdef CONFIG_PAX_EMUTRAMP
14338 ++ if (elf_phdata->p_flags & PF_EMUTRAMP)
14339 ++ pax_flags |= MF_PAX_EMUTRAMP;
14340 ++#endif
14341 ++
14342 ++#ifdef CONFIG_PAX_MPROTECT
14343 ++ if (elf_phdata->p_flags & PF_MPROTECT)
14344 ++ pax_flags |= MF_PAX_MPROTECT;
14345 ++#endif
14346 ++
14347 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14348 ++ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
14349 ++ pax_flags |= MF_PAX_RANDMMAP;
14350 ++#endif
14351 ++
14352 ++ return pax_flags;
14353 ++}
14354 ++#endif
14355 ++
14356 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14357 ++static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
14358 ++{
14359 ++ unsigned long pax_flags = 0UL;
14360 ++
14361 ++#ifdef CONFIG_PAX_PAGEEXEC
14362 ++ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
14363 ++ pax_flags |= MF_PAX_PAGEEXEC;
14364 ++#endif
14365 ++
14366 ++#ifdef CONFIG_PAX_SEGMEXEC
14367 ++ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
14368 ++ pax_flags |= MF_PAX_SEGMEXEC;
14369 ++#endif
14370 ++
14371 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14372 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14373 ++ if (nx_enabled)
14374 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14375 ++ else
14376 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14377 ++ }
14378 ++#endif
14379 ++
14380 ++#ifdef CONFIG_PAX_EMUTRAMP
14381 ++ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
14382 ++ pax_flags |= MF_PAX_EMUTRAMP;
14383 ++#endif
14384 ++
14385 ++#ifdef CONFIG_PAX_MPROTECT
14386 ++ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
14387 ++ pax_flags |= MF_PAX_MPROTECT;
14388 ++#endif
14389 ++
14390 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14391 ++ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
14392 ++ pax_flags |= MF_PAX_RANDMMAP;
14393 ++#endif
14394 ++
14395 ++ return pax_flags;
14396 ++}
14397 ++#endif
14398 ++
14399 ++#ifdef CONFIG_PAX_EI_PAX
14400 ++static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
14401 ++{
14402 ++ unsigned long pax_flags = 0UL;
14403 ++
14404 ++#ifdef CONFIG_PAX_PAGEEXEC
14405 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
14406 ++ pax_flags |= MF_PAX_PAGEEXEC;
14407 ++#endif
14408 ++
14409 ++#ifdef CONFIG_PAX_SEGMEXEC
14410 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
14411 ++ pax_flags |= MF_PAX_SEGMEXEC;
14412 ++#endif
14413 ++
14414 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14415 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14416 ++ if (nx_enabled)
14417 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14418 ++ else
14419 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14420 ++ }
14421 ++#endif
14422 ++
14423 ++#ifdef CONFIG_PAX_EMUTRAMP
14424 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
14425 ++ pax_flags |= MF_PAX_EMUTRAMP;
14426 ++#endif
14427 ++
14428 ++#ifdef CONFIG_PAX_MPROTECT
14429 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
14430 ++ pax_flags |= MF_PAX_MPROTECT;
14431 ++#endif
14432 ++
14433 ++#ifdef CONFIG_PAX_ASLR
14434 ++ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
14435 ++ pax_flags |= MF_PAX_RANDMMAP;
14436 ++#endif
14437 ++
14438 ++ return pax_flags;
14439 ++}
14440 ++#endif
14441 ++
14442 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14443 ++static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
14444 ++{
14445 ++ unsigned long pax_flags = 0UL;
14446 ++
14447 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14448 ++ unsigned long i;
14449 ++#endif
14450 ++
14451 ++#ifdef CONFIG_PAX_EI_PAX
14452 ++ pax_flags = pax_parse_ei_pax(elf_ex);
14453 ++#endif
14454 ++
14455 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14456 ++ for (i = 0UL; i < elf_ex->e_phnum; i++)
14457 ++ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
14458 ++ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
14459 ++ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
14460 ++ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
14461 ++ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
14462 ++ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
14463 ++ return -EINVAL;
14464 ++
14465 ++#ifdef CONFIG_PAX_SOFTMODE
14466 ++ if (pax_softmode)
14467 ++ pax_flags = pax_parse_softmode(&elf_phdata[i]);
14468 ++ else
14469 ++#endif
14470 ++
14471 ++ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
14472 ++ break;
14473 ++ }
14474 ++#endif
14475 ++
14476 ++ if (0 > pax_check_flags(&pax_flags))
14477 ++ return -EINVAL;
14478 ++
14479 ++ current->mm->pax_flags = pax_flags;
14480 ++ return 0;
14481 ++}
14482 ++#endif
14483 ++
14484 + /*
14485 + * These are the functions used to load ELF style executables and shared
14486 + * libraries. There is no binary dependent code anywhere else.
14487 +@@ -543,6 +736,11 @@ static unsigned long randomize_stack_top
14488 + {
14489 + unsigned int random_variable = 0;
14490 +
14491 ++#ifdef CONFIG_PAX_RANDUSTACK
14492 ++ if (randomize_va_space)
14493 ++ return stack_top - current->mm->delta_stack;
14494 ++#endif
14495 ++
14496 + if ((current->flags & PF_RANDOMIZE) &&
14497 + !(current->personality & ADDR_NO_RANDOMIZE)) {
14498 + random_variable = get_random_int() & STACK_RND_MASK;
14499 +@@ -561,7 +759,7 @@ static int load_elf_binary(struct linux_
14500 + unsigned long load_addr = 0, load_bias = 0;
14501 + int load_addr_set = 0;
14502 + char * elf_interpreter = NULL;
14503 +- unsigned long error;
14504 ++ unsigned long error = 0;
14505 + struct elf_phdr *elf_ppnt, *elf_phdata;
14506 + unsigned long elf_bss, elf_brk;
14507 + int elf_exec_fileno;
14508 +@@ -572,11 +770,11 @@ static int load_elf_binary(struct linux_
14509 + unsigned long start_code, end_code, start_data, end_data;
14510 + unsigned long reloc_func_desc = 0;
14511 + int executable_stack = EXSTACK_DEFAULT;
14512 +- unsigned long def_flags = 0;
14513 + struct {
14514 + struct elfhdr elf_ex;
14515 + struct elfhdr interp_elf_ex;
14516 + } *loc;
14517 ++ unsigned long pax_task_size = TASK_SIZE;
14518 +
14519 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
14520 + if (!loc) {
14521 +@@ -744,11 +942,80 @@ static int load_elf_binary(struct linux_
14522 +
14523 + /* OK, This is the point of no return */
14524 + current->flags &= ~PF_FORKNOEXEC;
14525 +- current->mm->def_flags = def_flags;
14526 ++
14527 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14528 ++ current->mm->pax_flags = 0UL;
14529 ++#endif
14530 ++
14531 ++#ifdef CONFIG_PAX_DLRESOLVE
14532 ++ current->mm->call_dl_resolve = 0UL;
14533 ++#endif
14534 ++
14535 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
14536 ++ current->mm->call_syscall = 0UL;
14537 ++#endif
14538 ++
14539 ++#ifdef CONFIG_PAX_ASLR
14540 ++ current->mm->delta_mmap = 0UL;
14541 ++ current->mm->delta_stack = 0UL;
14542 ++#endif
14543 ++
14544 ++ current->mm->def_flags = 0;
14545 ++
14546 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14547 ++ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
14548 ++ send_sig(SIGKILL, current, 0);
14549 ++ goto out_free_dentry;
14550 ++ }
14551 ++#endif
14552 ++
14553 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
14554 ++ pax_set_initial_flags(bprm);
14555 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
14556 ++ if (pax_set_initial_flags_func)
14557 ++ (pax_set_initial_flags_func)(bprm);
14558 ++#endif
14559 ++
14560 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
14561 ++ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
14562 ++ current->mm->context.user_cs_limit = PAGE_SIZE;
14563 ++ current->mm->def_flags |= VM_PAGEEXEC;
14564 ++ }
14565 ++#endif
14566 ++
14567 ++#ifdef CONFIG_PAX_SEGMEXEC
14568 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
14569 ++ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
14570 ++ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
14571 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14572 ++ }
14573 ++#endif
14574 ++
14575 ++#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
14576 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14577 ++ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
14578 ++ put_cpu_no_resched();
14579 ++ }
14580 ++#endif
14581 ++
14582 ++#ifdef CONFIG_PAX_ASLR
14583 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
14584 ++ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
14585 ++ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
14586 ++ }
14587 ++#endif
14588 +
14589 + /* Do this immediately, since STACK_TOP as used in setup_arg_pages
14590 + may depend on the personality. */
14591 + SET_PERSONALITY(loc->elf_ex, 0);
14592 ++
14593 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14594 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14595 ++ executable_stack = EXSTACK_DISABLE_X;
14596 ++ current->personality &= ~READ_IMPLIES_EXEC;
14597 ++ } else
14598 ++#endif
14599 ++
14600 + if (elf_read_implies_exec(loc->elf_ex, executable_stack))
14601 + current->personality |= READ_IMPLIES_EXEC;
14602 +
14603 +@@ -829,6 +1096,20 @@ static int load_elf_binary(struct linux_
14604 + #else
14605 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
14606 + #endif
14607 ++
14608 ++#ifdef CONFIG_PAX_RANDMMAP
14609 ++ /* PaX: randomize base address at the default exe base if requested */
14610 ++ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
14611 ++#ifdef CONFIG_SPARC64
14612 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
14613 ++#else
14614 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
14615 ++#endif
14616 ++ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
14617 ++ elf_flags |= MAP_FIXED;
14618 ++ }
14619 ++#endif
14620 ++
14621 + }
14622 +
14623 + error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
14624 +@@ -861,9 +1142,9 @@ static int load_elf_binary(struct linux_
14625 + * allowed task size. Note that p_filesz must always be
14626 + * <= p_memsz so it is only necessary to check p_memsz.
14627 + */
14628 +- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14629 +- elf_ppnt->p_memsz > TASK_SIZE ||
14630 +- TASK_SIZE - elf_ppnt->p_memsz < k) {
14631 ++ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14632 ++ elf_ppnt->p_memsz > pax_task_size ||
14633 ++ pax_task_size - elf_ppnt->p_memsz < k) {
14634 + /* set_brk can never work. Avoid overflows. */
14635 + send_sig(SIGKILL, current, 0);
14636 + retval = -EINVAL;
14637 +@@ -891,6 +1172,11 @@ static int load_elf_binary(struct linux_
14638 + start_data += load_bias;
14639 + end_data += load_bias;
14640 +
14641 ++#ifdef CONFIG_PAX_RANDMMAP
14642 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
14643 ++ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
14644 ++#endif
14645 ++
14646 + /* Calling set_brk effectively mmaps the pages that we need
14647 + * for the bss and break sections. We must do this before
14648 + * mapping in the interpreter, to make sure it doesn't wind
14649 +@@ -902,9 +1188,11 @@ static int load_elf_binary(struct linux_
14650 + goto out_free_dentry;
14651 + }
14652 + if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
14653 +- send_sig(SIGSEGV, current, 0);
14654 +- retval = -EFAULT; /* Nobody gets to see this, but.. */
14655 +- goto out_free_dentry;
14656 ++ /*
14657 ++ * This bss-zeroing can fail if the ELF
14658 ++ * file specifies odd protections. So
14659 ++ * we don't check the return value
14660 ++ */
14661 + }
14662 +
14663 + if (elf_interpreter) {
14664 +@@ -1141,8 +1429,10 @@ static int dump_seek(struct file *file,
14665 + unsigned long n = off;
14666 + if (n > PAGE_SIZE)
14667 + n = PAGE_SIZE;
14668 +- if (!dump_write(file, buf, n))
14669 ++ if (!dump_write(file, buf, n)) {
14670 ++ free_page((unsigned long)buf);
14671 + return 0;
14672 ++ }
14673 + off -= n;
14674 + }
14675 + free_page((unsigned long)buf);
14676 +@@ -1154,7 +1444,7 @@ static int dump_seek(struct file *file,
14677 + * Decide what to dump of a segment, part, all or none.
14678 + */
14679 + static unsigned long vma_dump_size(struct vm_area_struct *vma,
14680 +- unsigned long mm_flags)
14681 ++ unsigned long mm_flags, long signr)
14682 + {
14683 + /* The vma can be set up to tell us the answer directly. */
14684 + if (vma->vm_flags & VM_ALWAYSDUMP)
14685 +@@ -1180,7 +1470,7 @@ static unsigned long vma_dump_size(struc
14686 + if (vma->vm_file == NULL)
14687 + return 0;
14688 +
14689 +- if (FILTER(MAPPED_PRIVATE))
14690 ++ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
14691 + goto whole;
14692 +
14693 + /*
14694 +@@ -1266,8 +1556,11 @@ static int writenote(struct memelfnote *
14695 + #undef DUMP_WRITE
14696 +
14697 + #define DUMP_WRITE(addr, nr) \
14698 ++ do { \
14699 ++ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
14700 + if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
14701 +- goto end_coredump;
14702 ++ goto end_coredump; \
14703 ++ } while (0);
14704 + #define DUMP_SEEK(off) \
14705 + if (!dump_seek(file, (off))) \
14706 + goto end_coredump;
14707 +@@ -1973,7 +2266,7 @@ static int elf_core_dump(long signr, str
14708 + phdr.p_offset = offset;
14709 + phdr.p_vaddr = vma->vm_start;
14710 + phdr.p_paddr = 0;
14711 +- phdr.p_filesz = vma_dump_size(vma, mm_flags);
14712 ++ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
14713 + phdr.p_memsz = vma->vm_end - vma->vm_start;
14714 + offset += phdr.p_filesz;
14715 + phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
14716 +@@ -2005,7 +2298,7 @@ static int elf_core_dump(long signr, str
14717 + unsigned long addr;
14718 + unsigned long end;
14719 +
14720 +- end = vma->vm_start + vma_dump_size(vma, mm_flags);
14721 ++ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
14722 +
14723 + for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
14724 + struct page *page;
14725 +@@ -2025,6 +2318,7 @@ static int elf_core_dump(long signr, str
14726 + flush_cache_page(tmp_vma, addr,
14727 + page_to_pfn(page));
14728 + kaddr = kmap(page);
14729 ++ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
14730 + if ((size += PAGE_SIZE) > limit ||
14731 + !dump_write(file, kaddr,
14732 + PAGE_SIZE)) {
14733 +@@ -2055,6 +2349,99 @@ out:
14734 +
14735 + #endif /* USE_ELF_CORE_DUMP */
14736 +
14737 ++#ifdef CONFIG_PAX_MPROTECT
14738 ++/* PaX: non-PIC ELF libraries need relocations on their executable segments
14739 ++ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
14740 ++ * we'll remove VM_MAYWRITE for good on RELRO segments.
14741 ++ *
14742 ++ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
14743 ++ * basis because we want to allow the common case and not the special ones.
14744 ++ */
14745 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
14746 ++{
14747 ++ struct elfhdr elf_h;
14748 ++ struct elf_phdr elf_p;
14749 ++ unsigned long i;
14750 ++ unsigned long oldflags;
14751 ++ bool is_textrel_rw, is_textrel_rx, is_relro;
14752 ++
14753 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
14754 ++ return;
14755 ++
14756 ++ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
14757 ++ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
14758 ++
14759 ++#ifdef CONFIG_PAX_NOELFRELOCS
14760 ++ is_textrel_rw = false;
14761 ++ is_textrel_rx = false;
14762 ++#else
14763 ++ /* possible TEXTREL */
14764 ++ 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);
14765 ++ 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);
14766 ++#endif
14767 ++
14768 ++ /* possible RELRO */
14769 ++ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
14770 ++
14771 ++ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
14772 ++ return;
14773 ++
14774 ++ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
14775 ++ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
14776 ++
14777 ++#ifdef CONFIG_PAX_ETEXECRELOCS
14778 ++ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14779 ++#else
14780 ++ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
14781 ++#endif
14782 ++
14783 ++ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14784 ++ !elf_check_arch(&elf_h) ||
14785 ++ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
14786 ++ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
14787 ++ return;
14788 ++
14789 ++ for (i = 0UL; i < elf_h.e_phnum; i++) {
14790 ++ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
14791 ++ return;
14792 ++ switch (elf_p.p_type) {
14793 ++ case PT_DYNAMIC: {
14794 ++ elf_addr_t dyn_offset = 0UL;
14795 ++ elf_dyn dyn;
14796 ++
14797 ++ if (!is_textrel_rw && !is_textrel_rx)
14798 ++ continue;
14799 ++ dyn_offset = elf_p.p_offset;
14800 ++ i = 0UL;
14801 ++ do {
14802 ++ if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
14803 ++ return;
14804 ++ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
14805 ++ gr_log_textrel(vma);
14806 ++ if (is_textrel_rw)
14807 ++ vma->vm_flags |= VM_MAYWRITE;
14808 ++ else
14809 ++ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
14810 ++ vma->vm_flags &= ~VM_MAYWRITE;
14811 ++ return;
14812 ++ }
14813 ++ i++;
14814 ++ } while (dyn.d_tag != DT_NULL);
14815 ++ return;
14816 ++ }
14817 ++
14818 ++ case PT_GNU_RELRO:
14819 ++ if (!is_relro)
14820 ++ continue;
14821 ++ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) {
14822 ++ vma->vm_flags &= ~VM_MAYWRITE;
14823 ++ }
14824 ++ return;
14825 ++ }
14826 ++ }
14827 ++}
14828 ++#endif
14829 ++
14830 + static int __init init_elf_binfmt(void)
14831 + {
14832 + return register_binfmt(&elf_format);
14833 +diff -urNp linux-2.6.27.10/fs/binfmt_flat.c linux-2.6.27.10/fs/binfmt_flat.c
14834 +--- linux-2.6.27.10/fs/binfmt_flat.c 2008-11-07 12:55:34.000000000 -0500
14835 ++++ linux-2.6.27.10/fs/binfmt_flat.c 2008-11-18 03:38:45.000000000 -0500
14836 +@@ -561,7 +561,9 @@ static int load_flat_file(struct linux_b
14837 + realdatastart = (unsigned long) -ENOMEM;
14838 + printk("Unable to allocate RAM for process data, errno %d\n",
14839 + (int)-realdatastart);
14840 ++ down_write(&current->mm->mmap_sem);
14841 + do_munmap(current->mm, textpos, text_len);
14842 ++ up_write(&current->mm->mmap_sem);
14843 + ret = realdatastart;
14844 + goto err;
14845 + }
14846 +@@ -583,8 +585,10 @@ static int load_flat_file(struct linux_b
14847 + }
14848 + if (result >= (unsigned long)-4096) {
14849 + printk("Unable to read data+bss, errno %d\n", (int)-result);
14850 ++ down_write(&current->mm->mmap_sem);
14851 + do_munmap(current->mm, textpos, text_len);
14852 + do_munmap(current->mm, realdatastart, data_len + extra);
14853 ++ up_write(&current->mm->mmap_sem);
14854 + ret = result;
14855 + goto err;
14856 + }
14857 +@@ -657,8 +661,10 @@ static int load_flat_file(struct linux_b
14858 + }
14859 + if (result >= (unsigned long)-4096) {
14860 + printk("Unable to read code+data+bss, errno %d\n",(int)-result);
14861 ++ down_write(&current->mm->mmap_sem);
14862 + do_munmap(current->mm, textpos, text_len + data_len + extra +
14863 + MAX_SHARED_LIBS * sizeof(unsigned long));
14864 ++ up_write(&current->mm->mmap_sem);
14865 + ret = result;
14866 + goto err;
14867 + }
14868 +diff -urNp linux-2.6.27.10/fs/binfmt_misc.c linux-2.6.27.10/fs/binfmt_misc.c
14869 +--- linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:16:51.000000000 -0500
14870 ++++ linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:13:46.000000000 -0500
14871 +@@ -696,7 +696,7 @@ static int bm_fill_super(struct super_bl
14872 + static struct tree_descr bm_files[] = {
14873 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
14874 + [3] = {"register", &bm_register_operations, S_IWUSR},
14875 +- /* last one */ {""}
14876 ++ /* last one */ {"", NULL, 0}
14877 + };
14878 + int err = simple_fill_super(sb, 0x42494e4d, bm_files);
14879 + if (!err)
14880 +diff -urNp linux-2.6.27.10/fs/bio.c linux-2.6.27.10/fs/bio.c
14881 +--- linux-2.6.27.10/fs/bio.c 2008-11-07 12:55:34.000000000 -0500
14882 ++++ linux-2.6.27.10/fs/bio.c 2008-11-18 03:38:45.000000000 -0500
14883 +@@ -507,7 +507,7 @@ static int __bio_copy_iov(struct bio *bi
14884 +
14885 + while (bv_len && iov_idx < iov_count) {
14886 + unsigned int bytes;
14887 +- char *iov_addr;
14888 ++ char __user *iov_addr;
14889 +
14890 + bytes = min_t(unsigned int,
14891 + iov[iov_idx].iov_len - iov_off, bv_len);
14892 +diff -urNp linux-2.6.27.10/fs/buffer.c linux-2.6.27.10/fs/buffer.c
14893 +--- linux-2.6.27.10/fs/buffer.c 2008-11-07 12:55:34.000000000 -0500
14894 ++++ linux-2.6.27.10/fs/buffer.c 2008-11-18 03:38:45.000000000 -0500
14895 +@@ -41,6 +41,7 @@
14896 + #include <linux/bitops.h>
14897 + #include <linux/mpage.h>
14898 + #include <linux/bit_spinlock.h>
14899 ++#include <linux/grsecurity.h>
14900 +
14901 + static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
14902 +
14903 +@@ -2249,6 +2250,7 @@ int generic_cont_expand_simple(struct in
14904 +
14905 + err = -EFBIG;
14906 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
14907 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1);
14908 + if (limit != RLIM_INFINITY && size > (loff_t)limit) {
14909 + send_sig(SIGXFSZ, current, 0);
14910 + goto out;
14911 +diff -urNp linux-2.6.27.10/fs/cifs/cifs_uniupr.h linux-2.6.27.10/fs/cifs/cifs_uniupr.h
14912 +--- linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-07 12:55:34.000000000 -0500
14913 ++++ linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-18 03:38:45.000000000 -0500
14914 +@@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
14915 + {0x0490, 0x04cc, UniCaseRangeU0490},
14916 + {0x1e00, 0x1ffc, UniCaseRangeU1e00},
14917 + {0xff40, 0xff5a, UniCaseRangeUff40},
14918 +- {0}
14919 ++ {0, 0, NULL}
14920 + };
14921 + #endif
14922 +
14923 +diff -urNp linux-2.6.27.10/fs/cifs/link.c linux-2.6.27.10/fs/cifs/link.c
14924 +--- linux-2.6.27.10/fs/cifs/link.c 2008-11-07 12:55:34.000000000 -0500
14925 ++++ linux-2.6.27.10/fs/cifs/link.c 2008-11-18 03:38:45.000000000 -0500
14926 +@@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c
14927 +
14928 + void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
14929 + {
14930 +- char *p = nd_get_link(nd);
14931 ++ const char *p = nd_get_link(nd);
14932 + if (!IS_ERR(p))
14933 + kfree(p);
14934 + }
14935 +diff -urNp linux-2.6.27.10/fs/compat.c linux-2.6.27.10/fs/compat.c
14936 +--- linux-2.6.27.10/fs/compat.c 2008-11-07 12:55:34.000000000 -0500
14937 ++++ linux-2.6.27.10/fs/compat.c 2008-11-18 03:38:45.000000000 -0500
14938 +@@ -51,6 +51,7 @@
14939 + #include <linux/poll.h>
14940 + #include <linux/mm.h>
14941 + #include <linux/eventpoll.h>
14942 ++#include <linux/grsecurity.h>
14943 +
14944 + #include <asm/uaccess.h>
14945 + #include <asm/mmu_context.h>
14946 +@@ -1298,14 +1299,12 @@ static int compat_copy_strings(int argc,
14947 + if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
14948 + struct page *page;
14949 +
14950 +-#ifdef CONFIG_STACK_GROWSUP
14951 + ret = expand_stack_downwards(bprm->vma, pos);
14952 + if (ret < 0) {
14953 + /* We've exceed the stack rlimit. */
14954 + ret = -E2BIG;
14955 + goto out;
14956 + }
14957 +-#endif
14958 + ret = get_user_pages(current, bprm->mm, pos,
14959 + 1, 1, 1, &page, NULL);
14960 + if (ret <= 0) {
14961 +@@ -1351,6 +1350,11 @@ int compat_do_execve(char * filename,
14962 + compat_uptr_t __user *envp,
14963 + struct pt_regs * regs)
14964 + {
14965 ++#ifdef CONFIG_GRKERNSEC
14966 ++ struct file *old_exec_file;
14967 ++ struct acl_subject_label *old_acl;
14968 ++ struct rlimit old_rlim[RLIM_NLIMITS];
14969 ++#endif
14970 + struct linux_binprm *bprm;
14971 + struct file *file;
14972 + int retval;
14973 +@@ -1371,6 +1375,14 @@ int compat_do_execve(char * filename,
14974 + bprm->filename = filename;
14975 + bprm->interp = filename;
14976 +
14977 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
14978 ++ retval = -EAGAIN;
14979 ++ if (gr_handle_nproc())
14980 ++ goto out_file;
14981 ++ retval = -EACCES;
14982 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
14983 ++ goto out_file;
14984 ++
14985 + retval = bprm_mm_init(bprm);
14986 + if (retval)
14987 + goto out_file;
14988 +@@ -1404,8 +1416,36 @@ int compat_do_execve(char * filename,
14989 + if (retval < 0)
14990 + goto out;
14991 +
14992 ++ if (!gr_tpe_allow(file)) {
14993 ++ retval = -EACCES;
14994 ++ goto out;
14995 ++ }
14996 ++
14997 ++ if (gr_check_crash_exec(file)) {
14998 ++ retval = -EACCES;
14999 ++ goto out;
15000 ++ }
15001 ++
15002 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
15003 ++
15004 ++ gr_handle_exec_args(bprm, (char __user * __user *)argv);
15005 ++
15006 ++#ifdef CONFIG_GRKERNSEC
15007 ++ old_acl = current->acl;
15008 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
15009 ++ old_exec_file = current->exec_file;
15010 ++ get_file(file);
15011 ++ current->exec_file = file;
15012 ++#endif
15013 ++
15014 ++ gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
15015 ++
15016 + retval = search_binary_handler(bprm, regs);
15017 + if (retval >= 0) {
15018 ++#ifdef CONFIG_GRKERNSEC
15019 ++ if (old_exec_file)
15020 ++ fput(old_exec_file);
15021 ++#endif
15022 + /* execve success */
15023 + security_bprm_free(bprm);
15024 + acct_update_integrals(current);
15025 +@@ -1413,6 +1453,13 @@ int compat_do_execve(char * filename,
15026 + return retval;
15027 + }
15028 +
15029 ++#ifdef CONFIG_GRKERNSEC
15030 ++ current->acl = old_acl;
15031 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
15032 ++ fput(current->exec_file);
15033 ++ current->exec_file = old_exec_file;
15034 ++#endif
15035 ++
15036 + out:
15037 + if (bprm->security)
15038 + security_bprm_free(bprm);
15039 +diff -urNp linux-2.6.27.10/fs/compat_ioctl.c linux-2.6.27.10/fs/compat_ioctl.c
15040 +--- linux-2.6.27.10/fs/compat_ioctl.c 2008-11-07 12:55:34.000000000 -0500
15041 ++++ linux-2.6.27.10/fs/compat_ioctl.c 2008-11-18 03:38:45.000000000 -0500
15042 +@@ -1831,15 +1831,15 @@ struct ioctl_trans {
15043 + };
15044 +
15045 + #define HANDLE_IOCTL(cmd,handler) \
15046 +- { (cmd), (ioctl_trans_handler_t)(handler) },
15047 ++ { (cmd), (ioctl_trans_handler_t)(handler), NULL },
15048 +
15049 + /* pointer to compatible structure or no argument */
15050 + #define COMPATIBLE_IOCTL(cmd) \
15051 +- { (cmd), do_ioctl32_pointer },
15052 ++ { (cmd), do_ioctl32_pointer, NULL },
15053 +
15054 + /* argument is an unsigned long integer, not a pointer */
15055 + #define ULONG_IOCTL(cmd) \
15056 +- { (cmd), (ioctl_trans_handler_t)sys_ioctl },
15057 ++ { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL },
15058 +
15059 + /* ioctl should not be warned about even if it's not implemented.
15060 + Valid reasons to use this:
15061 +diff -urNp linux-2.6.27.10/fs/debugfs/inode.c linux-2.6.27.10/fs/debugfs/inode.c
15062 +--- linux-2.6.27.10/fs/debugfs/inode.c 2008-11-07 12:55:34.000000000 -0500
15063 ++++ linux-2.6.27.10/fs/debugfs/inode.c 2008-11-18 03:38:45.000000000 -0500
15064 +@@ -121,7 +121,7 @@ static inline int debugfs_positive(struc
15065 +
15066 + static int debug_fill_super(struct super_block *sb, void *data, int silent)
15067 + {
15068 +- static struct tree_descr debug_files[] = {{""}};
15069 ++ static struct tree_descr debug_files[] = {{"", NULL, 0}};
15070 +
15071 + return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
15072 + }
15073 +diff -urNp linux-2.6.27.10/fs/exec.c linux-2.6.27.10/fs/exec.c
15074 +--- linux-2.6.27.10/fs/exec.c 2008-12-21 01:16:51.000000000 -0500
15075 ++++ linux-2.6.27.10/fs/exec.c 2008-12-21 01:13:46.000000000 -0500
15076 +@@ -50,6 +50,13 @@
15077 + #include <linux/cn_proc.h>
15078 + #include <linux/audit.h>
15079 + #include <linux/tracehook.h>
15080 ++#include <linux/random.h>
15081 ++#include <linux/grsecurity.h>
15082 ++
15083 ++#ifdef CONFIG_PAX_REFCOUNT
15084 ++#include <linux/kallsyms.h>
15085 ++#include <linux/kdebug.h>
15086 ++#endif
15087 +
15088 + #include <asm/uaccess.h>
15089 + #include <asm/mmu_context.h>
15090 +@@ -64,6 +71,11 @@
15091 + #include <linux/a.out.h>
15092 + #endif
15093 +
15094 ++#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
15095 ++void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
15096 ++EXPORT_SYMBOL(pax_set_initial_flags_func);
15097 ++#endif
15098 ++
15099 + int core_uses_pid;
15100 + char core_pattern[CORENAME_MAX_SIZE] = "core";
15101 + int suid_dumpable = 0;
15102 +@@ -172,18 +184,10 @@ static struct page *get_arg_page(struct
15103 + int write)
15104 + {
15105 + struct page *page;
15106 +- int ret;
15107 +
15108 +-#ifdef CONFIG_STACK_GROWSUP
15109 +- if (write) {
15110 +- ret = expand_stack_downwards(bprm->vma, pos);
15111 +- if (ret < 0)
15112 +- return NULL;
15113 +- }
15114 +-#endif
15115 +- ret = get_user_pages(current, bprm->mm, pos,
15116 +- 1, write, 1, &page, NULL);
15117 +- if (ret <= 0)
15118 ++ if (0 > expand_stack_downwards(bprm->vma, pos))
15119 ++ return NULL;
15120 ++ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
15121 + return NULL;
15122 +
15123 + if (write) {
15124 +@@ -256,6 +260,11 @@ static int __bprm_mm_init(struct linux_b
15125 + vma->vm_start = vma->vm_end - PAGE_SIZE;
15126 +
15127 + vma->vm_flags = VM_STACK_FLAGS;
15128 ++
15129 ++#ifdef CONFIG_PAX_SEGMEXEC
15130 ++ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
15131 ++#endif
15132 ++
15133 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
15134 + err = insert_vm_struct(mm, vma);
15135 + if (err) {
15136 +@@ -268,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
15137 +
15138 + bprm->p = vma->vm_end - sizeof(void *);
15139 +
15140 ++#ifdef CONFIG_PAX_RANDUSTACK
15141 ++ if (randomize_va_space)
15142 ++ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
15143 ++#endif
15144 ++
15145 + return 0;
15146 +
15147 + err:
15148 +@@ -391,7 +405,7 @@ static int count(char __user * __user *
15149 + if (!p)
15150 + break;
15151 + argv++;
15152 +- if(++i > max)
15153 ++ if (++i > max)
15154 + return -E2BIG;
15155 + cond_resched();
15156 + }
15157 +@@ -531,6 +545,10 @@ static int shift_arg_pages(struct vm_are
15158 + if (vma != find_vma(mm, new_start))
15159 + return -EFAULT;
15160 +
15161 ++#ifdef CONFIG_PAX_SEGMEXEC
15162 ++ BUG_ON(pax_find_mirror_vma(vma));
15163 ++#endif
15164 ++
15165 + /*
15166 + * cover the whole range: [new_start, old_end)
15167 + */
15168 +@@ -619,6 +637,14 @@ int setup_arg_pages(struct linux_binprm
15169 + bprm->exec -= stack_shift;
15170 +
15171 + down_write(&mm->mmap_sem);
15172 ++
15173 ++ /* Move stack pages down in memory. */
15174 ++ if (stack_shift) {
15175 ++ ret = shift_arg_pages(vma, stack_shift);
15176 ++ if (ret)
15177 ++ goto out_unlock;
15178 ++ }
15179 ++
15180 + vm_flags = VM_STACK_FLAGS;
15181 +
15182 + /*
15183 +@@ -632,21 +658,24 @@ int setup_arg_pages(struct linux_binprm
15184 + vm_flags &= ~VM_EXEC;
15185 + vm_flags |= mm->def_flags;
15186 +
15187 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15188 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
15189 ++ vm_flags &= ~VM_EXEC;
15190 ++
15191 ++#ifdef CONFIG_PAX_MPROTECT
15192 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
15193 ++ vm_flags &= ~VM_MAYEXEC;
15194 ++#endif
15195 ++
15196 ++ }
15197 ++#endif
15198 ++
15199 + ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
15200 + vm_flags);
15201 + if (ret)
15202 + goto out_unlock;
15203 + BUG_ON(prev != vma);
15204 +
15205 +- /* Move stack pages down in memory. */
15206 +- if (stack_shift) {
15207 +- ret = shift_arg_pages(vma, stack_shift);
15208 +- if (ret) {
15209 +- up_write(&mm->mmap_sem);
15210 +- return ret;
15211 +- }
15212 +- }
15213 +-
15214 + #ifdef CONFIG_STACK_GROWSUP
15215 + stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
15216 + #else
15217 +@@ -658,7 +687,7 @@ int setup_arg_pages(struct linux_binprm
15218 +
15219 + out_unlock:
15220 + up_write(&mm->mmap_sem);
15221 +- return 0;
15222 ++ return ret;
15223 + }
15224 + EXPORT_SYMBOL(setup_arg_pages);
15225 +
15226 +@@ -1286,6 +1315,11 @@ int do_execve(char * filename,
15227 + char __user *__user *envp,
15228 + struct pt_regs * regs)
15229 + {
15230 ++#ifdef CONFIG_GRKERNSEC
15231 ++ struct file *old_exec_file;
15232 ++ struct acl_subject_label *old_acl;
15233 ++ struct rlimit old_rlim[RLIM_NLIMITS];
15234 ++#endif
15235 + struct linux_binprm *bprm;
15236 + struct file *file;
15237 + struct files_struct *displaced;
15238 +@@ -1305,6 +1339,20 @@ int do_execve(char * filename,
15239 + if (IS_ERR(file))
15240 + goto out_kfree;
15241 +
15242 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
15243 ++
15244 ++ if (gr_handle_nproc()) {
15245 ++ allow_write_access(file);
15246 ++ fput(file);
15247 ++ return -EAGAIN;
15248 ++ }
15249 ++
15250 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
15251 ++ allow_write_access(file);
15252 ++ fput(file);
15253 ++ return -EACCES;
15254 ++ }
15255 ++
15256 + sched_exec();
15257 +
15258 + bprm->file = file;
15259 +@@ -1344,9 +1392,39 @@ int do_execve(char * filename,
15260 + if (retval < 0)
15261 + goto out;
15262 +
15263 ++ if (!gr_tpe_allow(file)) {
15264 ++ retval = -EACCES;
15265 ++ goto out;
15266 ++ }
15267 ++
15268 ++ if (gr_check_crash_exec(file)) {
15269 ++ retval = -EACCES;
15270 ++ goto out;
15271 ++ }
15272 ++
15273 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
15274 ++
15275 ++ gr_handle_exec_args(bprm, argv);
15276 ++
15277 ++#ifdef CONFIG_GRKERNSEC
15278 ++ old_acl = current->acl;
15279 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
15280 ++ old_exec_file = current->exec_file;
15281 ++ get_file(file);
15282 ++ current->exec_file = file;
15283 ++#endif
15284 ++
15285 ++ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
15286 ++ if (retval < 0)
15287 ++ goto out_fail;
15288 ++
15289 + current->flags &= ~PF_KTHREAD;
15290 + retval = search_binary_handler(bprm,regs);
15291 + if (retval >= 0) {
15292 ++#ifdef CONFIG_GRKERNSEC
15293 ++ if (old_exec_file)
15294 ++ fput(old_exec_file);
15295 ++#endif
15296 + /* execve success */
15297 + security_bprm_free(bprm);
15298 + acct_update_integrals(current);
15299 +@@ -1356,6 +1434,14 @@ int do_execve(char * filename,
15300 + return retval;
15301 + }
15302 +
15303 ++out_fail:
15304 ++#ifdef CONFIG_GRKERNSEC
15305 ++ current->acl = old_acl;
15306 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
15307 ++ fput(current->exec_file);
15308 ++ current->exec_file = old_exec_file;
15309 ++#endif
15310 ++
15311 + out:
15312 + if (bprm->security)
15313 + security_bprm_free(bprm);
15314 +@@ -1519,6 +1605,125 @@ out:
15315 + return ispipe;
15316 + }
15317 +
15318 ++int pax_check_flags(unsigned long *flags)
15319 ++{
15320 ++ int retval = 0;
15321 ++
15322 ++#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
15323 ++ if (*flags & MF_PAX_SEGMEXEC)
15324 ++ {
15325 ++ *flags &= ~MF_PAX_SEGMEXEC;
15326 ++ retval = -EINVAL;
15327 ++ }
15328 ++#endif
15329 ++
15330 ++ if ((*flags & MF_PAX_PAGEEXEC)
15331 ++
15332 ++#ifdef CONFIG_PAX_PAGEEXEC
15333 ++ && (*flags & MF_PAX_SEGMEXEC)
15334 ++#endif
15335 ++
15336 ++ )
15337 ++ {
15338 ++ *flags &= ~MF_PAX_PAGEEXEC;
15339 ++ retval = -EINVAL;
15340 ++ }
15341 ++
15342 ++ if ((*flags & MF_PAX_MPROTECT)
15343 ++
15344 ++#ifdef CONFIG_PAX_MPROTECT
15345 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15346 ++#endif
15347 ++
15348 ++ )
15349 ++ {
15350 ++ *flags &= ~MF_PAX_MPROTECT;
15351 ++ retval = -EINVAL;
15352 ++ }
15353 ++
15354 ++ if ((*flags & MF_PAX_EMUTRAMP)
15355 ++
15356 ++#ifdef CONFIG_PAX_EMUTRAMP
15357 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15358 ++#endif
15359 ++
15360 ++ )
15361 ++ {
15362 ++ *flags &= ~MF_PAX_EMUTRAMP;
15363 ++ retval = -EINVAL;
15364 ++ }
15365 ++
15366 ++ return retval;
15367 ++}
15368 ++
15369 ++EXPORT_SYMBOL(pax_check_flags);
15370 ++
15371 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15372 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
15373 ++{
15374 ++ struct task_struct *tsk = current;
15375 ++ struct mm_struct *mm = current->mm;
15376 ++ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
15377 ++ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
15378 ++ char *path_exec = NULL;
15379 ++ char *path_fault = NULL;
15380 ++ unsigned long start = 0UL, end = 0UL, offset = 0UL;
15381 ++
15382 ++ if (buffer_exec && buffer_fault) {
15383 ++ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
15384 ++
15385 ++ down_read(&mm->mmap_sem);
15386 ++ vma = mm->mmap;
15387 ++ while (vma && (!vma_exec || !vma_fault)) {
15388 ++ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
15389 ++ vma_exec = vma;
15390 ++ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
15391 ++ vma_fault = vma;
15392 ++ vma = vma->vm_next;
15393 ++ }
15394 ++ if (vma_exec) {
15395 ++ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
15396 ++ if (IS_ERR(path_exec))
15397 ++ path_exec = "<path too long>";
15398 ++ }
15399 ++ if (vma_fault) {
15400 ++ start = vma_fault->vm_start;
15401 ++ end = vma_fault->vm_end;
15402 ++ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
15403 ++ if (vma_fault->vm_file) {
15404 ++ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
15405 ++ if (IS_ERR(path_fault))
15406 ++ path_fault = "<path too long>";
15407 ++ } else
15408 ++ path_fault = "<anonymous mapping>";
15409 ++ }
15410 ++ up_read(&mm->mmap_sem);
15411 ++ }
15412 ++ if (tsk->signal->curr_ip)
15413 ++ 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);
15414 ++ else
15415 ++ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
15416 ++ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
15417 ++ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
15418 ++ tsk->uid, tsk->euid, pc, sp);
15419 ++ free_page((unsigned long)buffer_exec);
15420 ++ free_page((unsigned long)buffer_fault);
15421 ++ pax_report_insns(pc, sp);
15422 ++ do_coredump(SIGKILL, SIGKILL, regs);
15423 ++}
15424 ++#endif
15425 ++
15426 ++#ifdef CONFIG_PAX_REFCOUNT
15427 ++void pax_report_refcount_overflow(struct pt_regs *regs)
15428 ++{
15429 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
15430 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
15431 ++ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
15432 ++ show_registers(regs);
15433 ++ force_sig_specific(SIGKILL, current);
15434 ++}
15435 ++#endif
15436 ++
15437 + static int zap_process(struct task_struct *start)
15438 + {
15439 + struct task_struct *t;
15440 +@@ -1765,6 +1970,10 @@ int do_coredump(long signr, int exit_cod
15441 + */
15442 + clear_thread_flag(TIF_SIGPENDING);
15443 +
15444 ++ if (signr == SIGKILL || signr == SIGILL)
15445 ++ gr_handle_brute_attach(current);
15446 ++ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
15447 ++
15448 + /*
15449 + * lock_kernel() because format_corename() is controlled by sysctl, which
15450 + * uses lock_kernel()
15451 +@@ -1785,6 +1994,8 @@ int do_coredump(long signr, int exit_cod
15452 +
15453 + if (ispipe) {
15454 + helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
15455 ++ if (!helper_argv)
15456 ++ goto fail_unlock;
15457 + /* Terminate the string before the first option */
15458 + delimit = strchr(corename, ' ');
15459 + if (delimit)
15460 +diff -urNp linux-2.6.27.10/fs/ext2/balloc.c linux-2.6.27.10/fs/ext2/balloc.c
15461 +--- linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:37.000000000 -0500
15462 ++++ linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:46.000000000 -0500
15463 +@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
15464 +
15465 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15466 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15467 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15468 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15469 + sbi->s_resuid != current->fsuid &&
15470 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15471 + return 0;
15472 +diff -urNp linux-2.6.27.10/fs/ext3/balloc.c linux-2.6.27.10/fs/ext3/balloc.c
15473 +--- linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:37.000000000 -0500
15474 ++++ linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:46.000000000 -0500
15475 +@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
15476 +
15477 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15478 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15479 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15480 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15481 + sbi->s_resuid != current->fsuid &&
15482 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15483 + return 0;
15484 +diff -urNp linux-2.6.27.10/fs/ext3/namei.c linux-2.6.27.10/fs/ext3/namei.c
15485 +--- linux-2.6.27.10/fs/ext3/namei.c 2008-11-07 12:55:34.000000000 -0500
15486 ++++ linux-2.6.27.10/fs/ext3/namei.c 2008-11-18 03:38:45.000000000 -0500
15487 +@@ -1173,9 +1173,9 @@ static struct ext3_dir_entry_2 *do_split
15488 + u32 hash2;
15489 + struct dx_map_entry *map;
15490 + char *data1 = (*bh)->b_data, *data2;
15491 +- unsigned split, move, size, i;
15492 ++ unsigned split, move, size;
15493 + struct ext3_dir_entry_2 *de = NULL, *de2;
15494 +- int err = 0;
15495 ++ int i, err = 0;
15496 +
15497 + bh2 = ext3_append (handle, dir, &newblock, &err);
15498 + if (!(bh2)) {
15499 +diff -urNp linux-2.6.27.10/fs/ext3/xattr.c linux-2.6.27.10/fs/ext3/xattr.c
15500 +--- linux-2.6.27.10/fs/ext3/xattr.c 2008-11-07 12:55:34.000000000 -0500
15501 ++++ linux-2.6.27.10/fs/ext3/xattr.c 2008-11-18 03:38:45.000000000 -0500
15502 +@@ -89,8 +89,8 @@
15503 + printk("\n"); \
15504 + } while (0)
15505 + #else
15506 +-# define ea_idebug(f...)
15507 +-# define ea_bdebug(f...)
15508 ++# define ea_idebug(f...) do {} while (0)
15509 ++# define ea_bdebug(f...) do {} while (0)
15510 + #endif
15511 +
15512 + static void ext3_xattr_cache_insert(struct buffer_head *);
15513 +diff -urNp linux-2.6.27.10/fs/ext4/balloc.c linux-2.6.27.10/fs/ext4/balloc.c
15514 +--- linux-2.6.27.10/fs/ext4/balloc.c 2008-11-07 12:55:34.000000000 -0500
15515 ++++ linux-2.6.27.10/fs/ext4/balloc.c 2008-11-18 03:38:45.000000000 -0500
15516 +@@ -1617,7 +1617,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct
15517 +
15518 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15519 +
15520 +- if (!capable(CAP_SYS_RESOURCE) &&
15521 ++ if (!capable_nolog(CAP_SYS_RESOURCE) &&
15522 + sbi->s_resuid != current->fsuid &&
15523 + (sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
15524 + root_blocks = ext4_r_blocks_count(sbi->s_es);
15525 +diff -urNp linux-2.6.27.10/fs/ext4/namei.c linux-2.6.27.10/fs/ext4/namei.c
15526 +--- linux-2.6.27.10/fs/ext4/namei.c 2008-11-07 12:55:34.000000000 -0500
15527 ++++ linux-2.6.27.10/fs/ext4/namei.c 2008-11-18 03:38:45.000000000 -0500
15528 +@@ -1176,9 +1176,9 @@ static struct ext4_dir_entry_2 *do_split
15529 + u32 hash2;
15530 + struct dx_map_entry *map;
15531 + char *data1 = (*bh)->b_data, *data2;
15532 +- unsigned split, move, size, i;
15533 ++ unsigned split, move, size;
15534 + struct ext4_dir_entry_2 *de = NULL, *de2;
15535 +- int err = 0;
15536 ++ int i, err = 0;
15537 +
15538 + bh2 = ext4_append (handle, dir, &newblock, &err);
15539 + if (!(bh2)) {
15540 +diff -urNp linux-2.6.27.10/fs/fcntl.c linux-2.6.27.10/fs/fcntl.c
15541 +--- linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:16:51.000000000 -0500
15542 ++++ linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:14:31.000000000 -0500
15543 +@@ -19,6 +19,7 @@
15544 + #include <linux/signal.h>
15545 + #include <linux/rcupdate.h>
15546 + #include <linux/pid_namespace.h>
15547 ++#include <linux/grsecurity.h>
15548 + #include <linux/smp_lock.h>
15549 +
15550 + #include <asm/poll.h>
15551 +@@ -266,6 +267,7 @@ static long do_fcntl(int fd, unsigned in
15552 + switch (cmd) {
15553 + case F_DUPFD:
15554 + case F_DUPFD_CLOEXEC:
15555 ++ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
15556 + if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15557 + break;
15558 + err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
15559 +@@ -410,7 +412,8 @@ static inline int sigio_perm(struct task
15560 + return (((fown->euid == 0) ||
15561 + (fown->euid == p->suid) || (fown->euid == p->uid) ||
15562 + (fown->uid == p->suid) || (fown->uid == p->uid)) &&
15563 +- !security_file_send_sigiotask(p, fown, sig));
15564 ++ !security_file_send_sigiotask(p, fown, sig) &&
15565 ++ !gr_check_protected_task(p) && !gr_pid_is_chrooted(p));
15566 + }
15567 +
15568 + static void send_sigio_to_task(struct task_struct *p,
15569 +diff -urNp linux-2.6.27.10/fs/file.c linux-2.6.27.10/fs/file.c
15570 +--- linux-2.6.27.10/fs/file.c 2008-11-07 12:55:34.000000000 -0500
15571 ++++ linux-2.6.27.10/fs/file.c 2008-11-18 03:38:45.000000000 -0500
15572 +@@ -19,6 +19,7 @@
15573 + #include <linux/spinlock.h>
15574 + #include <linux/rcupdate.h>
15575 + #include <linux/workqueue.h>
15576 ++#include <linux/grsecurity.h>
15577 +
15578 + struct fdtable_defer {
15579 + spinlock_t lock;
15580 +@@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi
15581 + * N.B. For clone tasks sharing a files structure, this test
15582 + * will limit the total number of files that can be opened.
15583 + */
15584 ++
15585 ++ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
15586 + if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15587 + return -EMFILE;
15588 +
15589 +diff -urNp linux-2.6.27.10/fs/fuse/control.c linux-2.6.27.10/fs/fuse/control.c
15590 +--- linux-2.6.27.10/fs/fuse/control.c 2008-11-07 12:55:34.000000000 -0500
15591 ++++ linux-2.6.27.10/fs/fuse/control.c 2008-11-18 03:38:45.000000000 -0500
15592 +@@ -159,7 +159,7 @@ void fuse_ctl_remove_conn(struct fuse_co
15593 +
15594 + static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
15595 + {
15596 +- struct tree_descr empty_descr = {""};
15597 ++ struct tree_descr empty_descr = {"", NULL, 0};
15598 + struct fuse_conn *fc;
15599 + int err;
15600 +
15601 +diff -urNp linux-2.6.27.10/fs/fuse/dir.c linux-2.6.27.10/fs/fuse/dir.c
15602 +--- linux-2.6.27.10/fs/fuse/dir.c 2008-11-07 12:55:34.000000000 -0500
15603 ++++ linux-2.6.27.10/fs/fuse/dir.c 2008-11-18 03:38:45.000000000 -0500
15604 +@@ -1072,7 +1072,7 @@ static char *read_link(struct dentry *de
15605 + return link;
15606 + }
15607 +
15608 +-static void free_link(char *link)
15609 ++static void free_link(const char *link)
15610 + {
15611 + if (!IS_ERR(link))
15612 + free_page((unsigned long) link);
15613 +diff -urNp linux-2.6.27.10/fs/hfs/inode.c linux-2.6.27.10/fs/hfs/inode.c
15614 +--- linux-2.6.27.10/fs/hfs/inode.c 2008-11-07 12:55:34.000000000 -0500
15615 ++++ linux-2.6.27.10/fs/hfs/inode.c 2008-11-18 03:38:45.000000000 -0500
15616 +@@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode,
15617 +
15618 + if (S_ISDIR(main_inode->i_mode)) {
15619 + if (fd.entrylength < sizeof(struct hfs_cat_dir))
15620 +- /* panic? */;
15621 ++ {/* panic? */}
15622 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15623 + sizeof(struct hfs_cat_dir));
15624 + if (rec.type != HFS_CDR_DIR ||
15625 +@@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode,
15626 + sizeof(struct hfs_cat_file));
15627 + } else {
15628 + if (fd.entrylength < sizeof(struct hfs_cat_file))
15629 +- /* panic? */;
15630 ++ {/* panic? */}
15631 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15632 + sizeof(struct hfs_cat_file));
15633 + if (rec.type != HFS_CDR_FIL ||
15634 +diff -urNp linux-2.6.27.10/fs/hfsplus/inode.c linux-2.6.27.10/fs/hfsplus/inode.c
15635 +--- linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-07 12:55:34.000000000 -0500
15636 ++++ linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-18 03:38:45.000000000 -0500
15637 +@@ -417,7 +417,7 @@ int hfsplus_cat_read_inode(struct inode
15638 + struct hfsplus_cat_folder *folder = &entry.folder;
15639 +
15640 + if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
15641 +- /* panic? */;
15642 ++ {/* panic? */}
15643 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15644 + sizeof(struct hfsplus_cat_folder));
15645 + hfsplus_get_perms(inode, &folder->permissions, 1);
15646 +@@ -434,7 +434,7 @@ int hfsplus_cat_read_inode(struct inode
15647 + struct hfsplus_cat_file *file = &entry.file;
15648 +
15649 + if (fd->entrylength < sizeof(struct hfsplus_cat_file))
15650 +- /* panic? */;
15651 ++ {/* panic? */}
15652 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15653 + sizeof(struct hfsplus_cat_file));
15654 +
15655 +@@ -490,7 +490,7 @@ int hfsplus_cat_write_inode(struct inode
15656 + struct hfsplus_cat_folder *folder = &entry.folder;
15657 +
15658 + if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
15659 +- /* panic? */;
15660 ++ {/* panic? */}
15661 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15662 + sizeof(struct hfsplus_cat_folder));
15663 + /* simple node checks? */
15664 +@@ -512,7 +512,7 @@ int hfsplus_cat_write_inode(struct inode
15665 + struct hfsplus_cat_file *file = &entry.file;
15666 +
15667 + if (fd.entrylength < sizeof(struct hfsplus_cat_file))
15668 +- /* panic? */;
15669 ++ {/* panic? */}
15670 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15671 + sizeof(struct hfsplus_cat_file));
15672 + hfsplus_inode_write_fork(inode, &file->data_fork);
15673 +diff -urNp linux-2.6.27.10/fs/jffs2/debug.h linux-2.6.27.10/fs/jffs2/debug.h
15674 +--- linux-2.6.27.10/fs/jffs2/debug.h 2008-11-07 12:55:34.000000000 -0500
15675 ++++ linux-2.6.27.10/fs/jffs2/debug.h 2008-11-18 03:38:45.000000000 -0500
15676 +@@ -52,13 +52,13 @@
15677 + #if CONFIG_JFFS2_FS_DEBUG > 0
15678 + #define D1(x) x
15679 + #else
15680 +-#define D1(x)
15681 ++#define D1(x) do {} while (0);
15682 + #endif
15683 +
15684 + #if CONFIG_JFFS2_FS_DEBUG > 1
15685 + #define D2(x) x
15686 + #else
15687 +-#define D2(x)
15688 ++#define D2(x) do {} while (0);
15689 + #endif
15690 +
15691 + /* The prefixes of JFFS2 messages */
15692 +@@ -114,73 +114,73 @@
15693 + #ifdef JFFS2_DBG_READINODE_MESSAGES
15694 + #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15695 + #else
15696 +-#define dbg_readinode(fmt, ...)
15697 ++#define dbg_readinode(fmt, ...) do {} while (0)
15698 + #endif
15699 + #ifdef JFFS2_DBG_READINODE2_MESSAGES
15700 + #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15701 + #else
15702 +-#define dbg_readinode2(fmt, ...)
15703 ++#define dbg_readinode2(fmt, ...) do {} while (0)
15704 + #endif
15705 +
15706 + /* Fragtree build debugging messages */
15707 + #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
15708 + #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15709 + #else
15710 +-#define dbg_fragtree(fmt, ...)
15711 ++#define dbg_fragtree(fmt, ...) do {} while (0)
15712 + #endif
15713 + #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
15714 + #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15715 + #else
15716 +-#define dbg_fragtree2(fmt, ...)
15717 ++#define dbg_fragtree2(fmt, ...) do {} while (0)
15718 + #endif
15719 +
15720 + /* Directory entry list manilulation debugging messages */
15721 + #ifdef JFFS2_DBG_DENTLIST_MESSAGES
15722 + #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15723 + #else
15724 +-#define dbg_dentlist(fmt, ...)
15725 ++#define dbg_dentlist(fmt, ...) do {} while (0)
15726 + #endif
15727 +
15728 + /* Print the messages about manipulating node_refs */
15729 + #ifdef JFFS2_DBG_NODEREF_MESSAGES
15730 + #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15731 + #else
15732 +-#define dbg_noderef(fmt, ...)
15733 ++#define dbg_noderef(fmt, ...) do {} while (0)
15734 + #endif
15735 +
15736 + /* Manipulations with the list of inodes (JFFS2 inocache) */
15737 + #ifdef JFFS2_DBG_INOCACHE_MESSAGES
15738 + #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15739 + #else
15740 +-#define dbg_inocache(fmt, ...)
15741 ++#define dbg_inocache(fmt, ...) do {} while (0)
15742 + #endif
15743 +
15744 + /* Summary debugging messages */
15745 + #ifdef JFFS2_DBG_SUMMARY_MESSAGES
15746 + #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15747 + #else
15748 +-#define dbg_summary(fmt, ...)
15749 ++#define dbg_summary(fmt, ...) do {} while (0)
15750 + #endif
15751 +
15752 + /* File system build messages */
15753 + #ifdef JFFS2_DBG_FSBUILD_MESSAGES
15754 + #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15755 + #else
15756 +-#define dbg_fsbuild(fmt, ...)
15757 ++#define dbg_fsbuild(fmt, ...) do {} while (0)
15758 + #endif
15759 +
15760 + /* Watch the object allocations */
15761 + #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
15762 + #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15763 + #else
15764 +-#define dbg_memalloc(fmt, ...)
15765 ++#define dbg_memalloc(fmt, ...) do {} while (0)
15766 + #endif
15767 +
15768 + /* Watch the XATTR subsystem */
15769 + #ifdef JFFS2_DBG_XATTR_MESSAGES
15770 + #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15771 + #else
15772 +-#define dbg_xattr(fmt, ...)
15773 ++#define dbg_xattr(fmt, ...) do {} while (0)
15774 + #endif
15775 +
15776 + /* "Sanity" checks */
15777 +diff -urNp linux-2.6.27.10/fs/jffs2/erase.c linux-2.6.27.10/fs/jffs2/erase.c
15778 +--- linux-2.6.27.10/fs/jffs2/erase.c 2008-11-07 12:55:34.000000000 -0500
15779 ++++ linux-2.6.27.10/fs/jffs2/erase.c 2008-11-18 03:38:45.000000000 -0500
15780 +@@ -431,7 +431,8 @@ static void jffs2_mark_erased_block(stru
15781 + struct jffs2_unknown_node marker = {
15782 + .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
15783 + .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15784 +- .totlen = cpu_to_je32(c->cleanmarker_size)
15785 ++ .totlen = cpu_to_je32(c->cleanmarker_size),
15786 ++ .hdr_crc = cpu_to_je32(0)
15787 + };
15788 +
15789 + jffs2_prealloc_raw_node_refs(c, jeb, 1);
15790 +diff -urNp linux-2.6.27.10/fs/jffs2/summary.h linux-2.6.27.10/fs/jffs2/summary.h
15791 +--- linux-2.6.27.10/fs/jffs2/summary.h 2008-11-07 12:55:34.000000000 -0500
15792 ++++ linux-2.6.27.10/fs/jffs2/summary.h 2008-11-18 03:38:45.000000000 -0500
15793 +@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
15794 +
15795 + #define jffs2_sum_active() (0)
15796 + #define jffs2_sum_init(a) (0)
15797 +-#define jffs2_sum_exit(a)
15798 +-#define jffs2_sum_disable_collecting(a)
15799 ++#define jffs2_sum_exit(a) do {} while (0)
15800 ++#define jffs2_sum_disable_collecting(a) do {} while (0)
15801 + #define jffs2_sum_is_disabled(a) (0)
15802 +-#define jffs2_sum_reset_collected(a)
15803 ++#define jffs2_sum_reset_collected(a) do {} while (0)
15804 + #define jffs2_sum_add_kvec(a,b,c,d) (0)
15805 +-#define jffs2_sum_move_collected(a,b)
15806 ++#define jffs2_sum_move_collected(a,b) do {} while (0)
15807 + #define jffs2_sum_write_sumnode(a) (0)
15808 +-#define jffs2_sum_add_padding_mem(a,b)
15809 +-#define jffs2_sum_add_inode_mem(a,b,c)
15810 +-#define jffs2_sum_add_dirent_mem(a,b,c)
15811 +-#define jffs2_sum_add_xattr_mem(a,b,c)
15812 +-#define jffs2_sum_add_xref_mem(a,b,c)
15813 ++#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
15814 ++#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
15815 ++#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
15816 ++#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
15817 ++#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
15818 + #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
15819 +
15820 + #endif /* CONFIG_JFFS2_SUMMARY */
15821 +diff -urNp linux-2.6.27.10/fs/jffs2/wbuf.c linux-2.6.27.10/fs/jffs2/wbuf.c
15822 +--- linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-07 12:55:34.000000000 -0500
15823 ++++ linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-18 03:38:45.000000000 -0500
15824 +@@ -1015,7 +1015,8 @@ static const struct jffs2_unknown_node o
15825 + {
15826 + .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
15827 + .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15828 +- .totlen = constant_cpu_to_je32(8)
15829 ++ .totlen = constant_cpu_to_je32(8),
15830 ++ .hdr_crc = constant_cpu_to_je32(0)
15831 + };
15832 +
15833 + /*
15834 +diff -urNp linux-2.6.27.10/fs/locks.c linux-2.6.27.10/fs/locks.c
15835 +--- linux-2.6.27.10/fs/locks.c 2008-11-07 12:55:34.000000000 -0500
15836 ++++ linux-2.6.27.10/fs/locks.c 2008-11-18 03:38:45.000000000 -0500
15837 +@@ -2005,16 +2005,16 @@ void locks_remove_flock(struct file *fil
15838 + return;
15839 +
15840 + if (filp->f_op && filp->f_op->flock) {
15841 +- struct file_lock fl = {
15842 ++ struct file_lock flock = {
15843 + .fl_pid = current->tgid,
15844 + .fl_file = filp,
15845 + .fl_flags = FL_FLOCK,
15846 + .fl_type = F_UNLCK,
15847 + .fl_end = OFFSET_MAX,
15848 + };
15849 +- filp->f_op->flock(filp, F_SETLKW, &fl);
15850 +- if (fl.fl_ops && fl.fl_ops->fl_release_private)
15851 +- fl.fl_ops->fl_release_private(&fl);
15852 ++ filp->f_op->flock(filp, F_SETLKW, &flock);
15853 ++ if (flock.fl_ops && flock.fl_ops->fl_release_private)
15854 ++ flock.fl_ops->fl_release_private(&flock);
15855 + }
15856 +
15857 + lock_kernel();
15858 +diff -urNp linux-2.6.27.10/fs/namei.c linux-2.6.27.10/fs/namei.c
15859 +--- linux-2.6.27.10/fs/namei.c 2008-11-07 12:55:34.000000000 -0500
15860 ++++ linux-2.6.27.10/fs/namei.c 2008-11-18 04:47:57.000000000 -0500
15861 +@@ -31,6 +31,8 @@
15862 + #include <linux/file.h>
15863 + #include <linux/fcntl.h>
15864 + #include <linux/device_cgroup.h>
15865 ++#include <linux/grsecurity.h>
15866 ++
15867 + #include <asm/uaccess.h>
15868 +
15869 + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
15870 +@@ -646,7 +648,7 @@ static __always_inline int __do_follow_l
15871 + cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
15872 + error = PTR_ERR(cookie);
15873 + if (!IS_ERR(cookie)) {
15874 +- char *s = nd_get_link(nd);
15875 ++ const char *s = nd_get_link(nd);
15876 + error = 0;
15877 + if (s)
15878 + error = __vfs_follow_link(nd, s);
15879 +@@ -677,6 +679,13 @@ static inline int do_follow_link(struct
15880 + err = security_inode_follow_link(path->dentry, nd);
15881 + if (err)
15882 + goto loop;
15883 ++
15884 ++ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
15885 ++ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
15886 ++ err = -EACCES;
15887 ++ goto loop;
15888 ++ }
15889 ++
15890 + current->link_count++;
15891 + current->total_link_count++;
15892 + nd->depth++;
15893 +@@ -1025,11 +1034,18 @@ return_reval:
15894 + break;
15895 + }
15896 + return_base:
15897 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
15898 ++ path_put(&nd->path);
15899 ++ return -ENOENT;
15900 ++ }
15901 + return 0;
15902 + out_dput:
15903 + path_put_conditional(&next, nd);
15904 + break;
15905 + }
15906 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
15907 ++ err = -ENOENT;
15908 ++
15909 + path_put(&nd->path);
15910 + return_err:
15911 + return err;
15912 +@@ -1613,9 +1629,17 @@ static int __open_namei_create(struct na
15913 + int error;
15914 + struct dentry *dir = nd->path.dentry;
15915 +
15916 ++ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
15917 ++ error = -EACCES;
15918 ++ goto out_unlock_dput;
15919 ++ }
15920 ++
15921 + if (!IS_POSIXACL(dir->d_inode))
15922 + mode &= ~current->fs->umask;
15923 + error = vfs_create(dir->d_inode, path->dentry, mode, nd);
15924 ++ if (!error)
15925 ++ gr_handle_create(path->dentry, nd->path.mnt);
15926 ++out_unlock_dput:
15927 + mutex_unlock(&dir->d_inode->i_mutex);
15928 + dput(nd->path.dentry);
15929 + nd->path.dentry = path->dentry;
15930 +@@ -1696,6 +1720,17 @@ struct file *do_filp_open(int dfd, const
15931 + &nd, flag);
15932 + if (error)
15933 + return ERR_PTR(error);
15934 ++
15935 ++ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
15936 ++ error = -EPERM;
15937 ++ goto exit;
15938 ++ }
15939 ++
15940 ++ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
15941 ++ error = -EACCES;
15942 ++ goto exit;
15943 ++ }
15944 ++
15945 + goto ok;
15946 + }
15947 +
15948 +@@ -1759,6 +1794,20 @@ do_last:
15949 + /*
15950 + * It already exists.
15951 + */
15952 ++
15953 ++ if (gr_handle_rawio(path.dentry->d_inode)) {
15954 ++ error = -EPERM;
15955 ++ goto exit_mutex_unlock;
15956 ++ }
15957 ++ if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) {
15958 ++ error = -EACCES;
15959 ++ goto exit_mutex_unlock;
15960 ++ }
15961 ++ if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) {
15962 ++ error = -EACCES;
15963 ++ goto exit_mutex_unlock;
15964 ++ }
15965 ++
15966 + mutex_unlock(&dir->d_inode->i_mutex);
15967 + audit_inode(pathname, path.dentry);
15968 +
15969 +@@ -1843,6 +1892,13 @@ do_link:
15970 + error = security_inode_follow_link(path.dentry, &nd);
15971 + if (error)
15972 + goto exit_dput;
15973 ++
15974 ++ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
15975 ++ path.dentry, nd.path.mnt)) {
15976 ++ error = -EACCES;
15977 ++ goto exit_dput;
15978 ++ }
15979 ++
15980 + error = __do_follow_link(&path, &nd);
15981 + if (error) {
15982 + /* Does someone understand code flow here? Or it is only
15983 +@@ -2015,9 +2071,21 @@ asmlinkage long sys_mknodat(int dfd, con
15984 + error = may_mknod(mode);
15985 + if (error)
15986 + goto out_dput;
15987 ++
15988 ++ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
15989 ++ error = -EPERM;
15990 ++ goto out_dput;
15991 ++ }
15992 ++
15993 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
15994 ++ error = -EACCES;
15995 ++ goto out_dput;
15996 ++ }
15997 ++
15998 + error = mnt_want_write(nd.path.mnt);
15999 + if (error)
16000 + goto out_dput;
16001 ++
16002 + switch (mode & S_IFMT) {
16003 + case 0: case S_IFREG:
16004 + error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
16005 +@@ -2031,6 +2099,9 @@ asmlinkage long sys_mknodat(int dfd, con
16006 + break;
16007 + }
16008 + mnt_drop_write(nd.path.mnt);
16009 ++
16010 ++ if (!error)
16011 ++ gr_handle_create(dentry, nd.path.mnt);
16012 + out_dput:
16013 + dput(dentry);
16014 + out_unlock:
16015 +@@ -2084,6 +2155,11 @@ asmlinkage long sys_mkdirat(int dfd, con
16016 + if (IS_ERR(dentry))
16017 + goto out_unlock;
16018 +
16019 ++ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
16020 ++ error = -EACCES;
16021 ++ goto out_dput;
16022 ++ }
16023 ++
16024 + if (!IS_POSIXACL(nd.path.dentry->d_inode))
16025 + mode &= ~current->fs->umask;
16026 + error = mnt_want_write(nd.path.mnt);
16027 +@@ -2091,6 +2167,10 @@ asmlinkage long sys_mkdirat(int dfd, con
16028 + goto out_dput;
16029 + error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
16030 + mnt_drop_write(nd.path.mnt);
16031 ++
16032 ++ if (!error)
16033 ++ gr_handle_create(dentry, nd.path.mnt);
16034 ++
16035 + out_dput:
16036 + dput(dentry);
16037 + out_unlock:
16038 +@@ -2172,6 +2252,8 @@ static long do_rmdir(int dfd, const char
16039 + char * name;
16040 + struct dentry *dentry;
16041 + struct nameidata nd;
16042 ++ ino_t saved_ino = 0;
16043 ++ dev_t saved_dev = 0;
16044 +
16045 + error = user_path_parent(dfd, pathname, &nd, &name);
16046 + if (error)
16047 +@@ -2193,11 +2275,26 @@ static long do_rmdir(int dfd, const char
16048 + error = PTR_ERR(dentry);
16049 + if (IS_ERR(dentry))
16050 + goto exit2;
16051 ++
16052 ++ if (dentry->d_inode != NULL) {
16053 ++ if (dentry->d_inode->i_nlink <= 1) {
16054 ++ saved_ino = dentry->d_inode->i_ino;
16055 ++ saved_dev = dentry->d_inode->i_sb->s_dev;
16056 ++ }
16057 ++
16058 ++ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
16059 ++ error = -EACCES;
16060 ++ goto exit3;
16061 ++ }
16062 ++ }
16063 ++
16064 + error = mnt_want_write(nd.path.mnt);
16065 + if (error)
16066 + goto exit3;
16067 + error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
16068 + mnt_drop_write(nd.path.mnt);
16069 ++ if (!error && (saved_dev || saved_ino))
16070 ++ gr_handle_delete(saved_ino, saved_dev);
16071 + exit3:
16072 + dput(dentry);
16073 + exit2:
16074 +@@ -2257,6 +2354,8 @@ static long do_unlinkat(int dfd, const c
16075 + struct dentry *dentry;
16076 + struct nameidata nd;
16077 + struct inode *inode = NULL;
16078 ++ ino_t saved_ino = 0;
16079 ++ dev_t saved_dev = 0;
16080 +
16081 + error = user_path_parent(dfd, pathname, &nd, &name);
16082 + if (error)
16083 +@@ -2273,12 +2372,25 @@ static long do_unlinkat(int dfd, const c
16084 + if (nd.last.name[nd.last.len])
16085 + goto slashes;
16086 + inode = dentry->d_inode;
16087 +- if (inode)
16088 ++ if (inode) {
16089 ++ if (inode->i_nlink <= 1) {
16090 ++ saved_ino = inode->i_ino;
16091 ++ saved_dev = inode->i_sb->s_dev;
16092 ++ }
16093 ++
16094 + atomic_inc(&inode->i_count);
16095 ++
16096 ++ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
16097 ++ error = -EACCES;
16098 ++ goto exit2;
16099 ++ }
16100 ++ }
16101 + error = mnt_want_write(nd.path.mnt);
16102 + if (error)
16103 + goto exit2;
16104 + error = vfs_unlink(nd.path.dentry->d_inode, dentry);
16105 ++ if (!error && (saved_ino || saved_dev))
16106 ++ gr_handle_delete(saved_ino, saved_dev);
16107 + mnt_drop_write(nd.path.mnt);
16108 + exit2:
16109 + dput(dentry);
16110 +@@ -2356,10 +2468,17 @@ asmlinkage long sys_symlinkat(const char
16111 + if (IS_ERR(dentry))
16112 + goto out_unlock;
16113 +
16114 ++ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
16115 ++ error = -EACCES;
16116 ++ goto out_dput;
16117 ++ }
16118 ++
16119 + error = mnt_want_write(nd.path.mnt);
16120 + if (error)
16121 + goto out_dput;
16122 + error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
16123 ++ if (!error)
16124 ++ gr_handle_create(dentry, nd.path.mnt);
16125 + mnt_drop_write(nd.path.mnt);
16126 + out_dput:
16127 + dput(dentry);
16128 +@@ -2453,10 +2572,26 @@ asmlinkage long sys_linkat(int olddfd, c
16129 + error = PTR_ERR(new_dentry);
16130 + if (IS_ERR(new_dentry))
16131 + goto out_unlock;
16132 ++
16133 ++ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
16134 ++ old_path.dentry->d_inode,
16135 ++ old_path.dentry->d_inode->i_mode, to)) {
16136 ++ error = -EACCES;
16137 ++ goto out_dput;
16138 ++ }
16139 ++
16140 ++ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
16141 ++ old_path.dentry, old_path.mnt, to)) {
16142 ++ error = -EACCES;
16143 ++ goto out_dput;
16144 ++ }
16145 ++
16146 + error = mnt_want_write(nd.path.mnt);
16147 + if (error)
16148 + goto out_dput;
16149 + error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
16150 ++ if (!error)
16151 ++ gr_handle_create(new_dentry, nd.path.mnt);
16152 + mnt_drop_write(nd.path.mnt);
16153 + out_dput:
16154 + dput(new_dentry);
16155 +@@ -2612,8 +2747,10 @@ int vfs_rename(struct inode *old_dir, st
16156 + error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
16157 + else
16158 + error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
16159 ++
16160 + if (!error) {
16161 + const char *new_name = old_dentry->d_name.name;
16162 ++
16163 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
16164 + new_dentry->d_inode, old_dentry);
16165 + }
16166 +@@ -2685,11 +2822,21 @@ asmlinkage long sys_renameat(int olddfd,
16167 + if (new_dentry == trap)
16168 + goto exit5;
16169 +
16170 ++ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
16171 ++ old_dentry, old_dir->d_inode, oldnd.path.mnt,
16172 ++ to);
16173 ++ if (error)
16174 ++ goto exit5;
16175 ++
16176 + error = mnt_want_write(oldnd.path.mnt);
16177 + if (error)
16178 + goto exit5;
16179 + error = vfs_rename(old_dir->d_inode, old_dentry,
16180 + new_dir->d_inode, new_dentry);
16181 ++ if (!error)
16182 ++ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
16183 ++ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
16184 ++
16185 + mnt_drop_write(oldnd.path.mnt);
16186 + exit5:
16187 + dput(new_dentry);
16188 +diff -urNp linux-2.6.27.10/fs/namespace.c linux-2.6.27.10/fs/namespace.c
16189 +--- linux-2.6.27.10/fs/namespace.c 2008-11-18 11:38:40.000000000 -0500
16190 ++++ linux-2.6.27.10/fs/namespace.c 2008-11-18 11:40:53.000000000 -0500
16191 +@@ -27,6 +27,7 @@
16192 + #include <linux/ramfs.h>
16193 + #include <linux/log2.h>
16194 + #include <linux/idr.h>
16195 ++#include <linux/grsecurity.h>
16196 + #include <asm/uaccess.h>
16197 + #include <asm/unistd.h>
16198 + #include "pnode.h"
16199 +@@ -1094,6 +1095,8 @@ static int do_umount(struct vfsmount *mn
16200 + lock_kernel();
16201 + retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
16202 + unlock_kernel();
16203 ++
16204 ++ gr_log_remount(mnt->mnt_devname, retval);
16205 + }
16206 + up_write(&sb->s_umount);
16207 + return retval;
16208 +@@ -1117,6 +1120,9 @@ static int do_umount(struct vfsmount *mn
16209 + security_sb_umount_busy(mnt);
16210 + up_write(&namespace_sem);
16211 + release_mounts(&umount_list);
16212 ++
16213 ++ gr_log_unmount(mnt->mnt_devname, retval);
16214 ++
16215 + return retval;
16216 + }
16217 +
16218 +@@ -1954,6 +1960,11 @@ long do_mount(char *dev_name, char *dir_
16219 + if (retval)
16220 + goto dput_out;
16221 +
16222 ++ if (gr_handle_chroot_mount(nd.path.dentry, nd.path.mnt, dev_name)) {
16223 ++ retval = -EPERM;
16224 ++ goto dput_out;
16225 ++ }
16226 ++
16227 + if (flags & MS_REMOUNT)
16228 + retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
16229 + data_page);
16230 +@@ -1968,6 +1979,9 @@ long do_mount(char *dev_name, char *dir_
16231 + dev_name, data_page);
16232 + dput_out:
16233 + path_put(&nd.path);
16234 ++
16235 ++ gr_log_mount(dev_name, dir_name, retval);
16236 ++
16237 + return retval;
16238 + }
16239 +
16240 +@@ -2080,6 +2094,9 @@ asmlinkage long sys_mount(char __user *
16241 + if (retval < 0)
16242 + goto out3;
16243 +
16244 ++ if (gr_handle_chroot_pivot())
16245 ++ return -EPERM;
16246 ++
16247 + lock_kernel();
16248 + retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
16249 + flags, (void *)data_page);
16250 +diff -urNp linux-2.6.27.10/fs/nfs/nfs4proc.c linux-2.6.27.10/fs/nfs/nfs4proc.c
16251 +--- linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-07 12:55:34.000000000 -0500
16252 ++++ linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-18 03:38:45.000000000 -0500
16253 +@@ -653,7 +653,7 @@ static int _nfs4_do_open_reclaim(struct
16254 + static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
16255 + {
16256 + struct nfs_server *server = NFS_SERVER(state->inode);
16257 +- struct nfs4_exception exception = { };
16258 ++ struct nfs4_exception exception = {0, 0};
16259 + int err;
16260 + do {
16261 + err = _nfs4_do_open_reclaim(ctx, state);
16262 +@@ -695,7 +695,7 @@ static int _nfs4_open_delegation_recall(
16263 +
16264 + int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
16265 + {
16266 +- struct nfs4_exception exception = { };
16267 ++ struct nfs4_exception exception = {0, 0};
16268 + struct nfs_server *server = NFS_SERVER(state->inode);
16269 + int err;
16270 + do {
16271 +@@ -988,7 +988,7 @@ static int _nfs4_open_expired(struct nfs
16272 + static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
16273 + {
16274 + struct nfs_server *server = NFS_SERVER(state->inode);
16275 +- struct nfs4_exception exception = { };
16276 ++ struct nfs4_exception exception = {0, 0};
16277 + int err;
16278 +
16279 + do {
16280 +@@ -1090,7 +1090,7 @@ out_err:
16281 +
16282 + static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int flags, struct iattr *sattr, struct rpc_cred *cred)
16283 + {
16284 +- struct nfs4_exception exception = { };
16285 ++ struct nfs4_exception exception = {0, 0};
16286 + struct nfs4_state *res;
16287 + int status;
16288 +
16289 +@@ -1181,7 +1181,7 @@ static int nfs4_do_setattr(struct inode
16290 + struct nfs4_state *state)
16291 + {
16292 + struct nfs_server *server = NFS_SERVER(inode);
16293 +- struct nfs4_exception exception = { };
16294 ++ struct nfs4_exception exception = {0, 0};
16295 + int err;
16296 + do {
16297 + err = nfs4_handle_exception(server,
16298 +@@ -1494,7 +1494,7 @@ static int _nfs4_server_capabilities(str
16299 +
16300 + int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
16301 + {
16302 +- struct nfs4_exception exception = { };
16303 ++ struct nfs4_exception exception = {0, 0};
16304 + int err;
16305 + do {
16306 + err = nfs4_handle_exception(server,
16307 +@@ -1527,7 +1527,7 @@ static int _nfs4_lookup_root(struct nfs_
16308 + static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
16309 + struct nfs_fsinfo *info)
16310 + {
16311 +- struct nfs4_exception exception = { };
16312 ++ struct nfs4_exception exception = {0, 0};
16313 + int err;
16314 + do {
16315 + err = nfs4_handle_exception(server,
16316 +@@ -1616,7 +1616,7 @@ static int _nfs4_proc_getattr(struct nfs
16317 +
16318 + static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16319 + {
16320 +- struct nfs4_exception exception = { };
16321 ++ struct nfs4_exception exception = {0, 0};
16322 + int err;
16323 + do {
16324 + err = nfs4_handle_exception(server,
16325 +@@ -1702,7 +1702,7 @@ static int nfs4_proc_lookupfh(struct nfs
16326 + struct qstr *name, struct nfs_fh *fhandle,
16327 + struct nfs_fattr *fattr)
16328 + {
16329 +- struct nfs4_exception exception = { };
16330 ++ struct nfs4_exception exception = {0, 0};
16331 + int err;
16332 + do {
16333 + err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
16334 +@@ -1731,7 +1731,7 @@ static int _nfs4_proc_lookup(struct inod
16335 +
16336 + static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16337 + {
16338 +- struct nfs4_exception exception = { };
16339 ++ struct nfs4_exception exception = {0, 0};
16340 + int err;
16341 + do {
16342 + err = nfs4_handle_exception(NFS_SERVER(dir),
16343 +@@ -1795,7 +1795,7 @@ static int _nfs4_proc_access(struct inod
16344 +
16345 + static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
16346 + {
16347 +- struct nfs4_exception exception = { };
16348 ++ struct nfs4_exception exception = {0, 0};
16349 + int err;
16350 + do {
16351 + err = nfs4_handle_exception(NFS_SERVER(inode),
16352 +@@ -1850,7 +1850,7 @@ static int _nfs4_proc_readlink(struct in
16353 + static int nfs4_proc_readlink(struct inode *inode, struct page *page,
16354 + unsigned int pgbase, unsigned int pglen)
16355 + {
16356 +- struct nfs4_exception exception = { };
16357 ++ struct nfs4_exception exception = {0, 0};
16358 + int err;
16359 + do {
16360 + err = nfs4_handle_exception(NFS_SERVER(inode),
16361 +@@ -1947,7 +1947,7 @@ static int _nfs4_proc_remove(struct inod
16362 +
16363 + static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
16364 + {
16365 +- struct nfs4_exception exception = { };
16366 ++ struct nfs4_exception exception = {0, 0};
16367 + int err;
16368 + do {
16369 + err = nfs4_handle_exception(NFS_SERVER(dir),
16370 +@@ -2019,7 +2019,7 @@ static int _nfs4_proc_rename(struct inod
16371 + static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
16372 + struct inode *new_dir, struct qstr *new_name)
16373 + {
16374 +- struct nfs4_exception exception = { };
16375 ++ struct nfs4_exception exception = {0, 0};
16376 + int err;
16377 + do {
16378 + err = nfs4_handle_exception(NFS_SERVER(old_dir),
16379 +@@ -2066,7 +2066,7 @@ static int _nfs4_proc_link(struct inode
16380 +
16381 + static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
16382 + {
16383 +- struct nfs4_exception exception = { };
16384 ++ struct nfs4_exception exception = {0, 0};
16385 + int err;
16386 + do {
16387 + err = nfs4_handle_exception(NFS_SERVER(inode),
16388 +@@ -2157,7 +2157,7 @@ out:
16389 + static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
16390 + struct page *page, unsigned int len, struct iattr *sattr)
16391 + {
16392 +- struct nfs4_exception exception = { };
16393 ++ struct nfs4_exception exception = {0, 0};
16394 + int err;
16395 + do {
16396 + err = nfs4_handle_exception(NFS_SERVER(dir),
16397 +@@ -2188,7 +2188,7 @@ out:
16398 + static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
16399 + struct iattr *sattr)
16400 + {
16401 +- struct nfs4_exception exception = { };
16402 ++ struct nfs4_exception exception = {0, 0};
16403 + int err;
16404 + do {
16405 + err = nfs4_handle_exception(NFS_SERVER(dir),
16406 +@@ -2237,7 +2237,7 @@ static int _nfs4_proc_readdir(struct den
16407 + static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
16408 + u64 cookie, struct page *page, unsigned int count, int plus)
16409 + {
16410 +- struct nfs4_exception exception = { };
16411 ++ struct nfs4_exception exception = {0, 0};
16412 + int err;
16413 + do {
16414 + err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
16415 +@@ -2285,7 +2285,7 @@ out:
16416 + static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
16417 + struct iattr *sattr, dev_t rdev)
16418 + {
16419 +- struct nfs4_exception exception = { };
16420 ++ struct nfs4_exception exception = {0, 0};
16421 + int err;
16422 + do {
16423 + err = nfs4_handle_exception(NFS_SERVER(dir),
16424 +@@ -2314,7 +2314,7 @@ static int _nfs4_proc_statfs(struct nfs_
16425 +
16426 + static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
16427 + {
16428 +- struct nfs4_exception exception = { };
16429 ++ struct nfs4_exception exception = {0, 0};
16430 + int err;
16431 + do {
16432 + err = nfs4_handle_exception(server,
16433 +@@ -2342,7 +2342,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
16434 +
16435 + static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
16436 + {
16437 +- struct nfs4_exception exception = { };
16438 ++ struct nfs4_exception exception = {0, 0};
16439 + int err;
16440 +
16441 + do {
16442 +@@ -2385,7 +2385,7 @@ static int _nfs4_proc_pathconf(struct nf
16443 + static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
16444 + struct nfs_pathconf *pathconf)
16445 + {
16446 +- struct nfs4_exception exception = { };
16447 ++ struct nfs4_exception exception = {0, 0};
16448 + int err;
16449 +
16450 + do {
16451 +@@ -2672,7 +2672,7 @@ out_free:
16452 +
16453 + static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
16454 + {
16455 +- struct nfs4_exception exception = { };
16456 ++ struct nfs4_exception exception = {0, 0};
16457 + ssize_t ret;
16458 + do {
16459 + ret = __nfs4_get_acl_uncached(inode, buf, buflen);
16460 +@@ -2729,7 +2729,7 @@ static int __nfs4_proc_set_acl(struct in
16461 +
16462 + static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
16463 + {
16464 +- struct nfs4_exception exception = { };
16465 ++ struct nfs4_exception exception = {0, 0};
16466 + int err;
16467 + do {
16468 + err = nfs4_handle_exception(NFS_SERVER(inode),
16469 +@@ -3020,7 +3020,7 @@ out:
16470 + int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
16471 + {
16472 + struct nfs_server *server = NFS_SERVER(inode);
16473 +- struct nfs4_exception exception = { };
16474 ++ struct nfs4_exception exception = {0, 0};
16475 + int err;
16476 + do {
16477 + err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
16478 +@@ -3095,7 +3095,7 @@ out:
16479 +
16480 + static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16481 + {
16482 +- struct nfs4_exception exception = { };
16483 ++ struct nfs4_exception exception = {0, 0};
16484 + int err;
16485 +
16486 + do {
16487 +@@ -3445,7 +3445,7 @@ static int _nfs4_do_setlk(struct nfs4_st
16488 + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
16489 + {
16490 + struct nfs_server *server = NFS_SERVER(state->inode);
16491 +- struct nfs4_exception exception = { };
16492 ++ struct nfs4_exception exception = {0, 0};
16493 + int err;
16494 +
16495 + do {
16496 +@@ -3463,7 +3463,7 @@ static int nfs4_lock_reclaim(struct nfs4
16497 + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
16498 + {
16499 + struct nfs_server *server = NFS_SERVER(state->inode);
16500 +- struct nfs4_exception exception = { };
16501 ++ struct nfs4_exception exception = {0, 0};
16502 + int err;
16503 +
16504 + err = nfs4_set_lock_state(state, request);
16505 +@@ -3524,7 +3524,7 @@ out:
16506 +
16507 + static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16508 + {
16509 +- struct nfs4_exception exception = { };
16510 ++ struct nfs4_exception exception = {0, 0};
16511 + int err;
16512 +
16513 + do {
16514 +@@ -3574,7 +3574,7 @@ nfs4_proc_lock(struct file *filp, int cm
16515 + int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
16516 + {
16517 + struct nfs_server *server = NFS_SERVER(state->inode);
16518 +- struct nfs4_exception exception = { };
16519 ++ struct nfs4_exception exception = {0, 0};
16520 + int err;
16521 +
16522 + err = nfs4_set_lock_state(state, fl);
16523 +diff -urNp linux-2.6.27.10/fs/nfsd/export.c linux-2.6.27.10/fs/nfsd/export.c
16524 +--- linux-2.6.27.10/fs/nfsd/export.c 2008-11-07 12:55:34.000000000 -0500
16525 ++++ linux-2.6.27.10/fs/nfsd/export.c 2008-11-18 03:38:45.000000000 -0500
16526 +@@ -473,7 +473,7 @@ static int secinfo_parse(char **mesg, ch
16527 + * probably discover the problem when someone fails to
16528 + * authenticate.
16529 + */
16530 +- if (f->pseudoflavor < 0)
16531 ++ if ((s32)f->pseudoflavor < 0)
16532 + return -EINVAL;
16533 + err = get_int(mesg, &f->flags);
16534 + if (err)
16535 +diff -urNp linux-2.6.27.10/fs/nls/nls_base.c linux-2.6.27.10/fs/nls/nls_base.c
16536 +--- linux-2.6.27.10/fs/nls/nls_base.c 2008-11-07 12:55:34.000000000 -0500
16537 ++++ linux-2.6.27.10/fs/nls/nls_base.c 2008-11-18 03:38:45.000000000 -0500
16538 +@@ -42,7 +42,7 @@ static const struct utf8_table utf8_tabl
16539 + {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
16540 + {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
16541 + {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
16542 +- {0, /* end of table */}
16543 ++ {0, 0, 0, 0, 0, /* end of table */}
16544 + };
16545 +
16546 + int
16547 +diff -urNp linux-2.6.27.10/fs/ntfs/file.c linux-2.6.27.10/fs/ntfs/file.c
16548 +--- linux-2.6.27.10/fs/ntfs/file.c 2008-11-07 12:55:34.000000000 -0500
16549 ++++ linux-2.6.27.10/fs/ntfs/file.c 2008-11-18 03:38:45.000000000 -0500
16550 +@@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_
16551 + #endif /* NTFS_RW */
16552 + };
16553 +
16554 +-const struct file_operations ntfs_empty_file_ops = {};
16555 ++const struct file_operations ntfs_empty_file_ops;
16556 +
16557 +-const struct inode_operations ntfs_empty_inode_ops = {};
16558 ++const struct inode_operations ntfs_empty_inode_ops;
16559 +diff -urNp linux-2.6.27.10/fs/open.c linux-2.6.27.10/fs/open.c
16560 +--- linux-2.6.27.10/fs/open.c 2008-11-07 12:55:34.000000000 -0500
16561 ++++ linux-2.6.27.10/fs/open.c 2008-11-18 03:38:45.000000000 -0500
16562 +@@ -29,6 +29,7 @@
16563 + #include <linux/rcupdate.h>
16564 + #include <linux/audit.h>
16565 + #include <linux/falloc.h>
16566 ++#include <linux/grsecurity.h>
16567 +
16568 + int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
16569 + {
16570 +@@ -207,6 +208,9 @@ int do_truncate(struct dentry *dentry, l
16571 + if (length < 0)
16572 + return -EINVAL;
16573 +
16574 ++ if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt))
16575 ++ return -EACCES;
16576 ++
16577 + newattrs.ia_size = length;
16578 + newattrs.ia_valid = ATTR_SIZE | time_attrs;
16579 + if (filp) {
16580 +@@ -491,6 +495,9 @@ asmlinkage long sys_faccessat(int dfd, c
16581 + if (__mnt_is_readonly(path.mnt))
16582 + res = -EROFS;
16583 +
16584 ++ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
16585 ++ res = -EACCES;
16586 ++
16587 + out_path_release:
16588 + path_put(&path);
16589 + out:
16590 +@@ -521,6 +528,8 @@ asmlinkage long sys_chdir(const char __u
16591 + if (error)
16592 + goto dput_and_out;
16593 +
16594 ++ gr_log_chdir(path.dentry, path.mnt);
16595 ++
16596 + set_fs_pwd(current->fs, &path);
16597 +
16598 + dput_and_out:
16599 +@@ -547,6 +556,13 @@ asmlinkage long sys_fchdir(unsigned int
16600 + goto out_putf;
16601 +
16602 + error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
16603 ++
16604 ++ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
16605 ++ error = -EPERM;
16606 ++
16607 ++ if (!error)
16608 ++ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
16609 ++
16610 + if (!error)
16611 + set_fs_pwd(current->fs, &file->f_path);
16612 + out_putf:
16613 +@@ -572,7 +588,14 @@ asmlinkage long sys_chroot(const char __
16614 + if (!capable(CAP_SYS_CHROOT))
16615 + goto dput_and_out;
16616 +
16617 ++ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
16618 ++ goto dput_and_out;
16619 ++
16620 + set_fs_root(current->fs, &path);
16621 ++
16622 ++ gr_handle_chroot_caps(current);
16623 ++ gr_handle_chroot_chdir(&path);
16624 ++
16625 + error = 0;
16626 + dput_and_out:
16627 + path_put(&path);
16628 +@@ -600,13 +623,28 @@ asmlinkage long sys_fchmod(unsigned int
16629 + err = mnt_want_write(file->f_path.mnt);
16630 + if (err)
16631 + goto out_putf;
16632 ++
16633 ++ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
16634 ++ err = -EACCES;
16635 ++ goto out_drop_write;
16636 ++ }
16637 ++
16638 + mutex_lock(&inode->i_mutex);
16639 + if (mode == (mode_t) -1)
16640 + mode = inode->i_mode;
16641 ++
16642 ++ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
16643 ++ err = -EPERM;
16644 ++ mutex_unlock(&inode->i_mutex);
16645 ++ goto out_drop_write;
16646 ++ }
16647 ++
16648 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16649 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16650 + err = notify_change(dentry, &newattrs);
16651 + mutex_unlock(&inode->i_mutex);
16652 ++
16653 ++out_drop_write:
16654 + mnt_drop_write(file->f_path.mnt);
16655 + out_putf:
16656 + fput(file);
16657 +@@ -630,13 +668,28 @@ asmlinkage long sys_fchmodat(int dfd, co
16658 + error = mnt_want_write(path.mnt);
16659 + if (error)
16660 + goto dput_and_out;
16661 ++
16662 ++ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
16663 ++ error = -EACCES;
16664 ++ goto out_drop_write;
16665 ++ }
16666 ++
16667 + mutex_lock(&inode->i_mutex);
16668 + if (mode == (mode_t) -1)
16669 + mode = inode->i_mode;
16670 ++
16671 ++ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
16672 ++ error = -EACCES;
16673 ++ mutex_unlock(&inode->i_mutex);
16674 ++ goto out_drop_write;
16675 ++ }
16676 ++
16677 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16678 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16679 + error = notify_change(path.dentry, &newattrs);
16680 + mutex_unlock(&inode->i_mutex);
16681 ++
16682 ++out_drop_write:
16683 + mnt_drop_write(path.mnt);
16684 + dput_and_out:
16685 + path_put(&path);
16686 +@@ -649,12 +702,15 @@ asmlinkage long sys_chmod(const char __u
16687 + return sys_fchmodat(AT_FDCWD, filename, mode);
16688 + }
16689 +
16690 +-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
16691 ++static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
16692 + {
16693 + struct inode *inode = dentry->d_inode;
16694 + int error;
16695 + struct iattr newattrs;
16696 +
16697 ++ if (!gr_acl_handle_chown(dentry, mnt))
16698 ++ return -EACCES;
16699 ++
16700 + newattrs.ia_valid = ATTR_CTIME;
16701 + if (user != (uid_t) -1) {
16702 + newattrs.ia_valid |= ATTR_UID;
16703 +@@ -685,7 +741,7 @@ asmlinkage long sys_chown(const char __u
16704 + error = mnt_want_write(path.mnt);
16705 + if (error)
16706 + goto out_release;
16707 +- error = chown_common(path.dentry, user, group);
16708 ++ error = chown_common(path.dentry, user, group, path.mnt);
16709 + mnt_drop_write(path.mnt);
16710 + out_release:
16711 + path_put(&path);
16712 +@@ -710,7 +766,7 @@ asmlinkage long sys_fchownat(int dfd, co
16713 + error = mnt_want_write(path.mnt);
16714 + if (error)
16715 + goto out_release;
16716 +- error = chown_common(path.dentry, user, group);
16717 ++ error = chown_common(path.dentry, user, group, path.mnt);
16718 + mnt_drop_write(path.mnt);
16719 + out_release:
16720 + path_put(&path);
16721 +@@ -729,7 +785,7 @@ asmlinkage long sys_lchown(const char __
16722 + error = mnt_want_write(path.mnt);
16723 + if (error)
16724 + goto out_release;
16725 +- error = chown_common(path.dentry, user, group);
16726 ++ error = chown_common(path.dentry, user, group, path.mnt);
16727 + mnt_drop_write(path.mnt);
16728 + out_release:
16729 + path_put(&path);
16730 +@@ -753,7 +809,7 @@ asmlinkage long sys_fchown(unsigned int
16731 + goto out_fput;
16732 + dentry = file->f_path.dentry;
16733 + audit_inode(NULL, dentry);
16734 +- error = chown_common(dentry, user, group);
16735 ++ error = chown_common(dentry, user, group, file->f_path.mnt);
16736 + mnt_drop_write(file->f_path.mnt);
16737 + out_fput:
16738 + fput(file);
16739 +diff -urNp linux-2.6.27.10/fs/pipe.c linux-2.6.27.10/fs/pipe.c
16740 +--- linux-2.6.27.10/fs/pipe.c 2008-11-07 12:55:34.000000000 -0500
16741 ++++ linux-2.6.27.10/fs/pipe.c 2008-11-18 03:38:45.000000000 -0500
16742 +@@ -851,7 +851,7 @@ void free_pipe_info(struct inode *inode)
16743 + inode->i_pipe = NULL;
16744 + }
16745 +
16746 +-static struct vfsmount *pipe_mnt __read_mostly;
16747 ++struct vfsmount *pipe_mnt __read_mostly;
16748 + static int pipefs_delete_dentry(struct dentry *dentry)
16749 + {
16750 + /*
16751 +diff -urNp linux-2.6.27.10/fs/proc/array.c linux-2.6.27.10/fs/proc/array.c
16752 +--- linux-2.6.27.10/fs/proc/array.c 2008-11-07 12:55:34.000000000 -0500
16753 ++++ linux-2.6.27.10/fs/proc/array.c 2008-11-18 03:38:45.000000000 -0500
16754 +@@ -315,6 +315,21 @@ static inline void task_context_switch_c
16755 + p->nivcsw);
16756 + }
16757 +
16758 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16759 ++static inline void task_pax(struct seq_file *m, struct task_struct *p)
16760 ++{
16761 ++ if (p->mm)
16762 ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
16763 ++ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
16764 ++ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
16765 ++ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
16766 ++ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
16767 ++ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
16768 ++ else
16769 ++ seq_printf(m, "PaX:\t-----\n");
16770 ++}
16771 ++#endif
16772 ++
16773 + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
16774 + struct pid *pid, struct task_struct *task)
16775 + {
16776 +@@ -334,9 +349,20 @@ int proc_pid_status(struct seq_file *m,
16777 + task_show_regs(m, task);
16778 + #endif
16779 + task_context_switch_counts(m, task);
16780 ++
16781 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16782 ++ task_pax(m, task);
16783 ++#endif
16784 ++
16785 + return 0;
16786 + }
16787 +
16788 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16789 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
16790 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
16791 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
16792 ++#endif
16793 ++
16794 + static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
16795 + struct pid *pid, struct task_struct *task, int whole)
16796 + {
16797 +@@ -429,6 +455,19 @@ static int do_task_stat(struct seq_file
16798 + gtime = task_gtime(task);
16799 + }
16800 +
16801 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16802 ++ if (PAX_RAND_FLAGS(mm)) {
16803 ++ eip = 0;
16804 ++ esp = 0;
16805 ++ wchan = 0;
16806 ++ }
16807 ++#endif
16808 ++#ifdef CONFIG_GRKERNSEC_HIDESYM
16809 ++ wchan = 0;
16810 ++ eip =0;
16811 ++ esp =0;
16812 ++#endif
16813 ++
16814 + /* scale priority and nice values from timeslices to -20..20 */
16815 + /* to make it look like a "normal" Unix priority/nice value */
16816 + priority = task_prio(task);
16817 +@@ -469,9 +508,15 @@ static int do_task_stat(struct seq_file
16818 + vsize,
16819 + mm ? get_mm_rss(mm) : 0,
16820 + rsslim,
16821 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16822 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
16823 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
16824 ++ PAX_RAND_FLAGS(mm) ? 0 : (mm ? mm->start_stack : 0),
16825 ++#else
16826 + mm ? mm->start_code : 0,
16827 + mm ? mm->end_code : 0,
16828 + mm ? mm->start_stack : 0,
16829 ++#endif
16830 + esp,
16831 + eip,
16832 + /* The signal information here is obsolete.
16833 +@@ -524,3 +569,10 @@ int proc_pid_statm(struct seq_file *m, s
16834 +
16835 + return 0;
16836 + }
16837 ++
16838 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
16839 ++int proc_pid_ipaddr(struct task_struct *task, char *buffer)
16840 ++{
16841 ++ return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
16842 ++}
16843 ++#endif
16844 +diff -urNp linux-2.6.27.10/fs/proc/base.c linux-2.6.27.10/fs/proc/base.c
16845 +--- linux-2.6.27.10/fs/proc/base.c 2008-11-07 12:55:34.000000000 -0500
16846 ++++ linux-2.6.27.10/fs/proc/base.c 2008-11-18 03:38:45.000000000 -0500
16847 +@@ -79,6 +79,8 @@
16848 + #include <linux/oom.h>
16849 + #include <linux/elf.h>
16850 + #include <linux/pid_namespace.h>
16851 ++#include <linux/grsecurity.h>
16852 ++
16853 + #include "internal.h"
16854 +
16855 + /* NOTE:
16856 +@@ -148,7 +150,7 @@ static unsigned int pid_entry_count_dirs
16857 + return count;
16858 + }
16859 +
16860 +-int maps_protect;
16861 ++int maps_protect = 1;
16862 + EXPORT_SYMBOL(maps_protect);
16863 +
16864 + static struct fs_struct *get_fs_struct(struct task_struct *task)
16865 +@@ -229,6 +231,9 @@ static int check_mem_permission(struct t
16866 + if (task == current)
16867 + return 0;
16868 +
16869 ++ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
16870 ++ return -EPERM;
16871 ++
16872 + /*
16873 + * If current is actively ptrace'ing, and would also be
16874 + * permitted to freshly attach with ptrace now, permit it.
16875 +@@ -312,9 +317,9 @@ static int proc_pid_auxv(struct task_str
16876 + struct mm_struct *mm = get_task_mm(task);
16877 + if (mm) {
16878 + unsigned int nwords = 0;
16879 +- do
16880 ++ do {
16881 + nwords += 2;
16882 +- while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16883 ++ } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16884 + res = nwords * sizeof(mm->saved_auxv[0]);
16885 + if (res > PAGE_SIZE)
16886 + res = PAGE_SIZE;
16887 +@@ -1437,7 +1442,11 @@ static struct inode *proc_pid_make_inode
16888 + inode->i_gid = 0;
16889 + if (task_dumpable(task)) {
16890 + inode->i_uid = task->euid;
16891 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16892 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16893 ++#else
16894 + inode->i_gid = task->egid;
16895 ++#endif
16896 + }
16897 + security_task_to_inode(task, inode);
16898 +
16899 +@@ -1453,17 +1462,45 @@ static int pid_getattr(struct vfsmount *
16900 + {
16901 + struct inode *inode = dentry->d_inode;
16902 + struct task_struct *task;
16903 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16904 ++ struct task_struct *tmp = current;
16905 ++#endif
16906 ++
16907 + generic_fillattr(inode, stat);
16908 +
16909 + rcu_read_lock();
16910 + stat->uid = 0;
16911 + stat->gid = 0;
16912 + task = pid_task(proc_pid(inode), PIDTYPE_PID);
16913 +- if (task) {
16914 ++
16915 ++ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
16916 ++ rcu_read_unlock();
16917 ++ return -ENOENT;
16918 ++ }
16919 ++
16920 ++
16921 ++ if (task
16922 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16923 ++ && (!tmp->uid || (tmp->uid == task->uid)
16924 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16925 ++ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
16926 ++#endif
16927 ++ )
16928 ++#endif
16929 ++ ) {
16930 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16931 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16932 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16933 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16934 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16935 ++#endif
16936 + task_dumpable(task)) {
16937 + stat->uid = task->euid;
16938 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16939 ++ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
16940 ++#else
16941 + stat->gid = task->egid;
16942 ++#endif
16943 + }
16944 + }
16945 + rcu_read_unlock();
16946 +@@ -1491,11 +1528,21 @@ static int pid_revalidate(struct dentry
16947 + {
16948 + struct inode *inode = dentry->d_inode;
16949 + struct task_struct *task = get_proc_task(inode);
16950 ++
16951 + if (task) {
16952 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16953 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16954 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16955 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16956 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16957 ++#endif
16958 + task_dumpable(task)) {
16959 + inode->i_uid = task->euid;
16960 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16961 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16962 ++#else
16963 + inode->i_gid = task->egid;
16964 ++#endif
16965 + } else {
16966 + inode->i_uid = 0;
16967 + inode->i_gid = 0;
16968 +@@ -1863,12 +1910,22 @@ static const struct file_operations proc
16969 + static int proc_fd_permission(struct inode *inode, int mask)
16970 + {
16971 + int rv;
16972 ++ struct task_struct *task;
16973 +
16974 + rv = generic_permission(inode, mask, NULL);
16975 +- if (rv == 0)
16976 +- return 0;
16977 ++
16978 + if (task_pid(current) == proc_pid(inode))
16979 + rv = 0;
16980 ++
16981 ++ task = get_proc_task(inode);
16982 ++ if (task == NULL)
16983 ++ return rv;
16984 ++
16985 ++ if (gr_acl_handle_procpidmem(task))
16986 ++ rv = -EACCES;
16987 ++
16988 ++ put_task_struct(task);
16989 ++
16990 + return rv;
16991 + }
16992 +
16993 +@@ -1979,6 +2036,9 @@ static struct dentry *proc_pident_lookup
16994 + if (!task)
16995 + goto out_no_task;
16996 +
16997 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16998 ++ goto out;
16999 ++
17000 + /*
17001 + * Yes, it does not scale. And it should not. Don't add
17002 + * new entries into /proc/<tgid>/ without very good reasons.
17003 +@@ -2023,6 +2083,9 @@ static int proc_pident_readdir(struct fi
17004 + if (!task)
17005 + goto out_no_task;
17006 +
17007 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
17008 ++ goto out;
17009 ++
17010 + ret = 0;
17011 + i = filp->f_pos;
17012 + switch (i) {
17013 +@@ -2385,6 +2448,9 @@ static struct dentry *proc_base_lookup(s
17014 + if (p > last)
17015 + goto out;
17016 +
17017 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
17018 ++ goto out;
17019 ++
17020 + error = proc_base_instantiate(dir, dentry, task, p);
17021 +
17022 + out:
17023 +@@ -2518,6 +2584,9 @@ static const struct pid_entry tgid_base_
17024 + #ifdef CONFIG_TASK_IO_ACCOUNTING
17025 + INF("io", S_IRUGO, tgid_io_accounting),
17026 + #endif
17027 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
17028 ++ INF("ipaddr", S_IRUSR, pid_ipaddr),
17029 ++#endif
17030 + };
17031 +
17032 + static int proc_tgid_base_readdir(struct file * filp,
17033 +@@ -2647,7 +2716,14 @@ static struct dentry *proc_pid_instantia
17034 + if (!inode)
17035 + goto out;
17036 +
17037 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17038 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
17039 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17040 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
17041 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
17042 ++#else
17043 + inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
17044 ++#endif
17045 + inode->i_op = &proc_tgid_base_inode_operations;
17046 + inode->i_fop = &proc_tgid_base_operations;
17047 + inode->i_flags|=S_IMMUTABLE;
17048 +@@ -2689,7 +2765,11 @@ struct dentry *proc_pid_lookup(struct in
17049 + if (!task)
17050 + goto out;
17051 +
17052 ++ if (gr_check_hidden_task(task))
17053 ++ goto out_put_task;
17054 ++
17055 + result = proc_pid_instantiate(dir, dentry, task, NULL);
17056 ++out_put_task:
17057 + put_task_struct(task);
17058 + out:
17059 + return result;
17060 +@@ -2754,6 +2834,9 @@ int proc_pid_readdir(struct file * filp,
17061 + {
17062 + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
17063 + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
17064 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17065 ++ struct task_struct *tmp = current;
17066 ++#endif
17067 + struct tgid_iter iter;
17068 + struct pid_namespace *ns;
17069 +
17070 +@@ -2772,6 +2855,17 @@ int proc_pid_readdir(struct file * filp,
17071 + for (iter = next_tgid(ns, iter);
17072 + iter.task;
17073 + iter.tgid += 1, iter = next_tgid(ns, iter)) {
17074 ++ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
17075 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17076 ++ || (tmp->uid && (iter.task->uid != tmp->uid)
17077 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
17078 ++ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
17079 ++#endif
17080 ++ )
17081 ++#endif
17082 ++ )
17083 ++ continue;
17084 ++
17085 + filp->f_pos = iter.tgid + TGID_OFFSET;
17086 + if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
17087 + put_task_struct(iter.task);
17088 +diff -urNp linux-2.6.27.10/fs/proc/inode.c linux-2.6.27.10/fs/proc/inode.c
17089 +--- linux-2.6.27.10/fs/proc/inode.c 2008-11-07 12:55:34.000000000 -0500
17090 ++++ linux-2.6.27.10/fs/proc/inode.c 2008-11-18 03:38:45.000000000 -0500
17091 +@@ -467,7 +467,11 @@ struct inode *proc_get_inode(struct supe
17092 + if (de->mode) {
17093 + inode->i_mode = de->mode;
17094 + inode->i_uid = de->uid;
17095 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
17096 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
17097 ++#else
17098 + inode->i_gid = de->gid;
17099 ++#endif
17100 + }
17101 + if (de->size)
17102 + inode->i_size = de->size;
17103 +diff -urNp linux-2.6.27.10/fs/proc/internal.h linux-2.6.27.10/fs/proc/internal.h
17104 +--- linux-2.6.27.10/fs/proc/internal.h 2008-11-07 12:55:34.000000000 -0500
17105 ++++ linux-2.6.27.10/fs/proc/internal.h 2008-11-18 03:38:45.000000000 -0500
17106 +@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_fi
17107 + struct pid *pid, struct task_struct *task);
17108 + extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
17109 + struct pid *pid, struct task_struct *task);
17110 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
17111 ++extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
17112 ++#endif
17113 + extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
17114 +
17115 + extern const struct file_operations proc_maps_operations;
17116 +diff -urNp linux-2.6.27.10/fs/proc/Kconfig linux-2.6.27.10/fs/proc/Kconfig
17117 +--- linux-2.6.27.10/fs/proc/Kconfig 2008-11-07 12:55:34.000000000 -0500
17118 ++++ linux-2.6.27.10/fs/proc/Kconfig 2008-11-18 03:38:45.000000000 -0500
17119 +@@ -30,12 +30,12 @@ config PROC_FS
17120 +
17121 + config PROC_KCORE
17122 + bool "/proc/kcore support" if !ARM
17123 +- depends on PROC_FS && MMU
17124 ++ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
17125 +
17126 + config PROC_VMCORE
17127 + bool "/proc/vmcore support (EXPERIMENTAL)"
17128 +- depends on PROC_FS && CRASH_DUMP
17129 +- default y
17130 ++ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
17131 ++ default n
17132 + help
17133 + Exports the dump image of crashed kernel in ELF format.
17134 +
17135 +diff -urNp linux-2.6.27.10/fs/proc/proc_misc.c linux-2.6.27.10/fs/proc/proc_misc.c
17136 +--- linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-07 12:55:34.000000000 -0500
17137 ++++ linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-18 03:38:45.000000000 -0500
17138 +@@ -860,6 +860,8 @@ struct proc_dir_entry *proc_root_kcore;
17139 +
17140 + void __init proc_misc_init(void)
17141 + {
17142 ++ int gr_mode = 0;
17143 ++
17144 + static struct {
17145 + char *name;
17146 + int (*read_proc)(char*,char**,off_t,int,int*,void*);
17147 +@@ -875,13 +877,24 @@ void __init proc_misc_init(void)
17148 + {"stram", stram_read_proc},
17149 + #endif
17150 + {"filesystems", filesystems_read_proc},
17151 ++#ifndef CONFIG_GRKERNSEC_PROC_ADD
17152 + {"cmdline", cmdline_read_proc},
17153 ++#endif
17154 + {"execdomains", execdomains_read_proc},
17155 + {NULL,}
17156 + };
17157 + for (p = simple_ones; p->name; p++)
17158 + create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
17159 +
17160 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17161 ++ gr_mode = S_IRUSR;
17162 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17163 ++ gr_mode = S_IRUSR | S_IRGRP;
17164 ++#endif
17165 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17166 ++ create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
17167 ++#endif
17168 ++
17169 + proc_symlink("mounts", NULL, "self/mounts");
17170 +
17171 + /* And now for trickier ones */
17172 +@@ -889,14 +902,18 @@ void __init proc_misc_init(void)
17173 + proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
17174 + #endif
17175 + proc_create("locks", 0, NULL, &proc_locks_operations);
17176 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17177 ++ proc_create("devices", gr_mode, NULL, &proc_devinfo_operations);
17178 ++#else
17179 + proc_create("devices", 0, NULL, &proc_devinfo_operations);
17180 ++#endif
17181 + proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
17182 + #ifdef CONFIG_BLOCK
17183 + proc_create("partitions", 0, NULL, &proc_partitions_operations);
17184 + #endif
17185 + proc_create("stat", 0, NULL, &proc_stat_operations);
17186 + proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
17187 +-#ifdef CONFIG_SLABINFO
17188 ++#if defined(CONFIG_SLABINFO) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17189 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
17190 + #ifdef CONFIG_DEBUG_SLAB_LEAK
17191 + proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
17192 +@@ -918,7 +935,7 @@ void __init proc_misc_init(void)
17193 + #ifdef CONFIG_SCHEDSTATS
17194 + proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
17195 + #endif
17196 +-#ifdef CONFIG_PROC_KCORE
17197 ++#if defined(CONFIG_PROC_KCORE) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17198 + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
17199 + if (proc_root_kcore)
17200 + proc_root_kcore->size =
17201 +diff -urNp linux-2.6.27.10/fs/proc/proc_net.c linux-2.6.27.10/fs/proc/proc_net.c
17202 +--- linux-2.6.27.10/fs/proc/proc_net.c 2008-11-07 12:55:34.000000000 -0500
17203 ++++ linux-2.6.27.10/fs/proc/proc_net.c 2008-11-18 03:38:45.000000000 -0500
17204 +@@ -106,6 +106,14 @@ static struct net *get_proc_task_net(str
17205 + struct nsproxy *ns;
17206 + struct net *net = NULL;
17207 +
17208 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17209 ++ if (current->fsuid)
17210 ++ return net;
17211 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17212 ++ if (current->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
17213 ++ return net;
17214 ++#endif
17215 ++
17216 + rcu_read_lock();
17217 + task = pid_task(proc_pid(dir), PIDTYPE_PID);
17218 + if (task != NULL) {
17219 +diff -urNp linux-2.6.27.10/fs/proc/proc_sysctl.c linux-2.6.27.10/fs/proc/proc_sysctl.c
17220 +--- linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:38:40.000000000 -0500
17221 ++++ linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:40:53.000000000 -0500
17222 +@@ -7,6 +7,8 @@
17223 + #include <linux/security.h>
17224 + #include "internal.h"
17225 +
17226 ++extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
17227 ++
17228 + static struct dentry_operations proc_sys_dentry_operations;
17229 + static const struct file_operations proc_sys_file_operations;
17230 + static const struct inode_operations proc_sys_inode_operations;
17231 +@@ -110,6 +112,9 @@ static struct dentry *proc_sys_lookup(st
17232 + if (!p)
17233 + goto out;
17234 +
17235 ++ if (gr_handle_sysctl(p, MAY_EXEC))
17236 ++ goto out;
17237 ++
17238 + err = ERR_PTR(-ENOMEM);
17239 + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
17240 + if (h)
17241 +@@ -229,6 +234,9 @@ static int scan(struct ctl_table_header
17242 + if (*pos < file->f_pos)
17243 + continue;
17244 +
17245 ++ if (gr_handle_sysctl(table, 0))
17246 ++ continue;
17247 ++
17248 + res = proc_sys_fill_cache(file, dirent, filldir, head, table);
17249 + if (res)
17250 + return res;
17251 +@@ -339,6 +347,9 @@ static int proc_sys_getattr(struct vfsmo
17252 + if (IS_ERR(head))
17253 + return PTR_ERR(head);
17254 +
17255 ++ if (table && gr_handle_sysctl(table, MAY_EXEC))
17256 ++ return -ENOENT;
17257 ++
17258 + generic_fillattr(inode, stat);
17259 + if (table)
17260 + stat->mode = (stat->mode & S_IFMT) | table->mode;
17261 +diff -urNp linux-2.6.27.10/fs/proc/root.c linux-2.6.27.10/fs/proc/root.c
17262 +--- linux-2.6.27.10/fs/proc/root.c 2008-11-07 12:55:34.000000000 -0500
17263 ++++ linux-2.6.27.10/fs/proc/root.c 2008-11-18 03:38:45.000000000 -0500
17264 +@@ -135,7 +135,15 @@ void __init proc_root_init(void)
17265 + #ifdef CONFIG_PROC_DEVICETREE
17266 + proc_device_tree_init();
17267 + #endif
17268 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17269 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17270 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
17271 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17272 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
17273 ++#endif
17274 ++#else
17275 + proc_mkdir("bus", NULL);
17276 ++#endif
17277 + proc_sys_init();
17278 + }
17279 +
17280 +diff -urNp linux-2.6.27.10/fs/proc/task_mmu.c linux-2.6.27.10/fs/proc/task_mmu.c
17281 +--- linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:16:51.000000000 -0500
17282 ++++ linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:13:46.000000000 -0500
17283 +@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
17284 + "VmStk:\t%8lu kB\n"
17285 + "VmExe:\t%8lu kB\n"
17286 + "VmLib:\t%8lu kB\n"
17287 +- "VmPTE:\t%8lu kB\n",
17288 +- hiwater_vm << (PAGE_SHIFT-10),
17289 ++ "VmPTE:\t%8lu kB\n"
17290 ++
17291 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17292 ++ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
17293 ++#endif
17294 ++
17295 ++ ,hiwater_vm << (PAGE_SHIFT-10),
17296 + (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
17297 + mm->locked_vm << (PAGE_SHIFT-10),
17298 + hiwater_rss << (PAGE_SHIFT-10),
17299 + total_rss << (PAGE_SHIFT-10),
17300 + data << (PAGE_SHIFT-10),
17301 + mm->stack_vm << (PAGE_SHIFT-10), text, lib,
17302 +- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
17303 ++ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
17304 ++
17305 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17306 ++ , mm->context.user_cs_base, mm->context.user_cs_limit
17307 ++#endif
17308 ++
17309 ++ );
17310 + }
17311 +
17312 + unsigned long task_vsize(struct mm_struct *mm)
17313 +@@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in
17314 + return ret;
17315 + }
17316 +
17317 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17318 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
17319 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
17320 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
17321 ++#endif
17322 ++
17323 + static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
17324 + {
17325 + struct mm_struct *mm = vma->vm_mm;
17326 +@@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file
17327 + }
17328 +
17329 + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
17330 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17331 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
17332 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
17333 ++#else
17334 + vma->vm_start,
17335 + vma->vm_end,
17336 ++#endif
17337 + flags & VM_READ ? 'r' : '-',
17338 + flags & VM_WRITE ? 'w' : '-',
17339 + flags & VM_EXEC ? 'x' : '-',
17340 + flags & VM_MAYSHARE ? 's' : 'p',
17341 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17342 ++ PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17343 ++#else
17344 + ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17345 ++#endif
17346 + MAJOR(dev), MINOR(dev), ino, &len);
17347 +
17348 + /*
17349 +@@ -234,11 +260,11 @@ static void show_map_vma(struct seq_file
17350 + const char *name = arch_vma_name(vma);
17351 + if (!name) {
17352 + if (mm) {
17353 +- if (vma->vm_start <= mm->start_brk &&
17354 +- vma->vm_end >= mm->brk) {
17355 ++ if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
17356 + name = "[heap]";
17357 +- } else if (vma->vm_start <= mm->start_stack &&
17358 +- vma->vm_end >= mm->start_stack) {
17359 ++ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
17360 ++ (vma->vm_start <= mm->start_stack &&
17361 ++ vma->vm_end >= mm->start_stack)) {
17362 + name = "[stack]";
17363 + }
17364 + } else {
17365 +@@ -387,9 +413,16 @@ static int show_smap(struct seq_file *m,
17366 + return -EACCES;
17367 +
17368 + memset(&mss, 0, sizeof mss);
17369 +- mss.vma = vma;
17370 +- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17371 +- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17372 ++
17373 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17374 ++ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
17375 ++#endif
17376 ++ mss.vma = vma;
17377 ++ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17378 ++ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17379 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17380 ++ }
17381 ++#endif
17382 +
17383 + show_map_vma(m, vma);
17384 +
17385 +@@ -403,7 +436,11 @@ static int show_smap(struct seq_file *m,
17386 + "Private_Dirty: %8lu kB\n"
17387 + "Referenced: %8lu kB\n"
17388 + "Swap: %8lu kB\n",
17389 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17390 ++ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
17391 ++#else
17392 + (vma->vm_end - vma->vm_start) >> 10,
17393 ++#endif
17394 + mss.resident >> 10,
17395 + (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
17396 + mss.shared_clean >> 10,
17397 +@@ -757,6 +794,11 @@ static int show_numa_map_checked(struct
17398 + struct proc_maps_private *priv = m->private;
17399 + struct task_struct *task = priv->task;
17400 +
17401 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17402 ++ if (!ptrace_may_access(task, PTRACE_MODE_READ))
17403 ++ return -EACCES;
17404 ++#endif
17405 ++
17406 + if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
17407 + return -EACCES;
17408 +
17409 +diff -urNp linux-2.6.27.10/fs/readdir.c linux-2.6.27.10/fs/readdir.c
17410 +--- linux-2.6.27.10/fs/readdir.c 2008-11-07 12:55:34.000000000 -0500
17411 ++++ linux-2.6.27.10/fs/readdir.c 2008-11-18 03:38:45.000000000 -0500
17412 +@@ -16,6 +16,8 @@
17413 + #include <linux/security.h>
17414 + #include <linux/syscalls.h>
17415 + #include <linux/unistd.h>
17416 ++#include <linux/namei.h>
17417 ++#include <linux/grsecurity.h>
17418 +
17419 + #include <asm/uaccess.h>
17420 +
17421 +@@ -67,6 +69,7 @@ struct old_linux_dirent {
17422 +
17423 + struct readdir_callback {
17424 + struct old_linux_dirent __user * dirent;
17425 ++ struct file * file;
17426 + int result;
17427 + };
17428 +
17429 +@@ -84,6 +87,10 @@ static int fillonedir(void * __buf, cons
17430 + buf->result = -EOVERFLOW;
17431 + return -EOVERFLOW;
17432 + }
17433 ++
17434 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17435 ++ return 0;
17436 ++
17437 + buf->result++;
17438 + dirent = buf->dirent;
17439 + if (!access_ok(VERIFY_WRITE, dirent,
17440 +@@ -115,6 +122,7 @@ asmlinkage long old_readdir(unsigned int
17441 +
17442 + buf.result = 0;
17443 + buf.dirent = dirent;
17444 ++ buf.file = file;
17445 +
17446 + error = vfs_readdir(file, fillonedir, &buf);
17447 + if (error >= 0)
17448 +@@ -141,6 +149,7 @@ struct linux_dirent {
17449 + struct getdents_callback {
17450 + struct linux_dirent __user * current_dir;
17451 + struct linux_dirent __user * previous;
17452 ++ struct file * file;
17453 + int count;
17454 + int error;
17455 + };
17456 +@@ -161,6 +170,10 @@ static int filldir(void * __buf, const c
17457 + buf->error = -EOVERFLOW;
17458 + return -EOVERFLOW;
17459 + }
17460 ++
17461 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17462 ++ return 0;
17463 ++
17464 + dirent = buf->previous;
17465 + if (dirent) {
17466 + if (__put_user(offset, &dirent->d_off))
17467 +@@ -207,6 +220,7 @@ asmlinkage long sys_getdents(unsigned in
17468 + buf.previous = NULL;
17469 + buf.count = count;
17470 + buf.error = 0;
17471 ++ buf.file = file;
17472 +
17473 + error = vfs_readdir(file, filldir, &buf);
17474 + if (error < 0)
17475 +@@ -229,6 +243,7 @@ out:
17476 + struct getdents_callback64 {
17477 + struct linux_dirent64 __user * current_dir;
17478 + struct linux_dirent64 __user * previous;
17479 ++ struct file *file;
17480 + int count;
17481 + int error;
17482 + };
17483 +@@ -243,6 +258,10 @@ static int filldir64(void * __buf, const
17484 + buf->error = -EINVAL; /* only used if we fail.. */
17485 + if (reclen > buf->count)
17486 + return -EINVAL;
17487 ++
17488 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17489 ++ return 0;
17490 ++
17491 + dirent = buf->previous;
17492 + if (dirent) {
17493 + if (__put_user(offset, &dirent->d_off))
17494 +@@ -289,6 +308,7 @@ asmlinkage long sys_getdents64(unsigned
17495 +
17496 + buf.current_dir = dirent;
17497 + buf.previous = NULL;
17498 ++ buf.file = file;
17499 + buf.count = count;
17500 + buf.error = 0;
17501 +
17502 +diff -urNp linux-2.6.27.10/fs/select.c linux-2.6.27.10/fs/select.c
17503 +--- linux-2.6.27.10/fs/select.c 2008-11-07 12:55:34.000000000 -0500
17504 ++++ linux-2.6.27.10/fs/select.c 2008-11-18 03:38:45.000000000 -0500
17505 +@@ -24,6 +24,7 @@
17506 + #include <linux/fdtable.h>
17507 + #include <linux/fs.h>
17508 + #include <linux/rcupdate.h>
17509 ++#include <linux/grsecurity.h>
17510 +
17511 + #include <asm/uaccess.h>
17512 +
17513 +@@ -658,6 +659,7 @@ int do_sys_poll(struct pollfd __user *uf
17514 + struct poll_list *walk = head;
17515 + unsigned long todo = nfds;
17516 +
17517 ++ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
17518 + if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
17519 + return -EINVAL;
17520 +
17521 +diff -urNp linux-2.6.27.10/fs/smbfs/symlink.c linux-2.6.27.10/fs/smbfs/symlink.c
17522 +--- linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17523 ++++ linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17524 +@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
17525 +
17526 + static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
17527 + {
17528 +- char *s = nd_get_link(nd);
17529 ++ const char *s = nd_get_link(nd);
17530 + if (!IS_ERR(s))
17531 + __putname(s);
17532 + }
17533 +diff -urNp linux-2.6.27.10/fs/sysfs/symlink.c linux-2.6.27.10/fs/sysfs/symlink.c
17534 +--- linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17535 ++++ linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17536 +@@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de
17537 +
17538 + static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
17539 + {
17540 +- char *page = nd_get_link(nd);
17541 ++ const char *page = nd_get_link(nd);
17542 + if (!IS_ERR(page))
17543 + free_page((unsigned long)page);
17544 + }
17545 +diff -urNp linux-2.6.27.10/fs/udf/balloc.c linux-2.6.27.10/fs/udf/balloc.c
17546 +--- linux-2.6.27.10/fs/udf/balloc.c 2008-11-07 12:55:34.000000000 -0500
17547 ++++ linux-2.6.27.10/fs/udf/balloc.c 2008-11-18 03:38:45.000000000 -0500
17548 +@@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc
17549 + unsigned long overflow;
17550 +
17551 + mutex_lock(&sbi->s_alloc_mutex);
17552 +- if (bloc.logicalBlockNum < 0 ||
17553 +- (bloc.logicalBlockNum + count) >
17554 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17555 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17556 + udf_debug("%d < %d || %d + %d > %d\n",
17557 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17558 + sbi->s_partmaps[bloc.partitionReferenceNum].
17559 +@@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st
17560 +
17561 + mutex_lock(&sbi->s_alloc_mutex);
17562 + part_len = sbi->s_partmaps[partition].s_partition_len;
17563 +- if (first_block < 0 || first_block >= part_len)
17564 ++ if (first_block >= part_len)
17565 + goto out;
17566 +
17567 + if (first_block + block_count > part_len)
17568 +@@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s
17569 + mutex_lock(&sbi->s_alloc_mutex);
17570 +
17571 + repeat:
17572 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17573 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17574 + goal = 0;
17575 +
17576 + nr_groups = bitmap->s_nr_groups;
17577 +@@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct
17578 + struct udf_inode_info *iinfo;
17579 +
17580 + mutex_lock(&sbi->s_alloc_mutex);
17581 +- if (bloc.logicalBlockNum < 0 ||
17582 +- (bloc.logicalBlockNum + count) >
17583 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17584 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17585 + udf_debug("%d < %d || %d + %d > %d\n",
17586 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17587 + sbi->s_partmaps[bloc.partitionReferenceNum].
17588 +@@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str
17589 + int8_t etype = -1;
17590 + struct udf_inode_info *iinfo;
17591 +
17592 +- if (first_block < 0 ||
17593 +- first_block >= sbi->s_partmaps[partition].s_partition_len)
17594 ++ if (first_block >= sbi->s_partmaps[partition].s_partition_len)
17595 + return 0;
17596 +
17597 + iinfo = UDF_I(table);
17598 +@@ -750,7 +745,7 @@ static int udf_table_new_block(struct su
17599 + return newblock;
17600 +
17601 + mutex_lock(&sbi->s_alloc_mutex);
17602 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17603 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17604 + goal = 0;
17605 +
17606 + /* We search for the closest matching block to goal. If we find
17607 +diff -urNp linux-2.6.27.10/fs/ufs/inode.c linux-2.6.27.10/fs/ufs/inode.c
17608 +--- linux-2.6.27.10/fs/ufs/inode.c 2008-11-07 12:55:34.000000000 -0500
17609 ++++ linux-2.6.27.10/fs/ufs/inode.c 2008-11-18 03:38:45.000000000 -0500
17610 +@@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod
17611 +
17612 +
17613 + UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
17614 +- if (i_block < 0) {
17615 +- ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
17616 +- } else if (i_block < direct_blocks) {
17617 ++ if (i_block < direct_blocks) {
17618 + offsets[n++] = i_block;
17619 + } else if ((i_block -= direct_blocks) < indirect_blocks) {
17620 + offsets[n++] = UFS_IND_BLOCK;
17621 +@@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod
17622 + lock_kernel();
17623 +
17624 + UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
17625 +- if (fragment < 0)
17626 +- goto abort_negative;
17627 + if (fragment >
17628 + ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
17629 + << uspi->s_fpbshift))
17630 +@@ -504,10 +500,6 @@ abort:
17631 + unlock_kernel();
17632 + return err;
17633 +
17634 +-abort_negative:
17635 +- ufs_warning(sb, "ufs_get_block", "block < 0");
17636 +- goto abort;
17637 +-
17638 + abort_too_big:
17639 + ufs_warning(sb, "ufs_get_block", "block > big");
17640 + goto abort;
17641 +diff -urNp linux-2.6.27.10/fs/utimes.c linux-2.6.27.10/fs/utimes.c
17642 +--- linux-2.6.27.10/fs/utimes.c 2008-11-07 12:55:34.000000000 -0500
17643 ++++ linux-2.6.27.10/fs/utimes.c 2008-11-18 03:38:45.000000000 -0500
17644 +@@ -8,6 +8,7 @@
17645 + #include <linux/stat.h>
17646 + #include <linux/utime.h>
17647 + #include <linux/syscalls.h>
17648 ++#include <linux/grsecurity.h>
17649 + #include <asm/uaccess.h>
17650 + #include <asm/unistd.h>
17651 +
17652 +@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
17653 + goto mnt_drop_write_and_out;
17654 + }
17655 + }
17656 ++
17657 ++ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
17658 ++ error = -EACCES;
17659 ++ goto mnt_drop_write_and_out;
17660 ++ }
17661 ++
17662 + mutex_lock(&inode->i_mutex);
17663 + error = notify_change(path->dentry, &newattrs);
17664 + mutex_unlock(&inode->i_mutex);
17665 +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
17666 +--- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-07 12:55:34.000000000 -0500
17667 ++++ linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-18 03:38:45.000000000 -0500
17668 +@@ -500,7 +500,7 @@ xfs_vn_put_link(
17669 + struct nameidata *nd,
17670 + void *p)
17671 + {
17672 +- char *s = nd_get_link(nd);
17673 ++ const char *s = nd_get_link(nd);
17674 +
17675 + if (!IS_ERR(s))
17676 + kfree(s);
17677 +diff -urNp linux-2.6.27.10/fs/xfs/xfs_bmap.c linux-2.6.27.10/fs/xfs/xfs_bmap.c
17678 +--- linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-07 12:55:34.000000000 -0500
17679 ++++ linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-18 03:38:45.000000000 -0500
17680 +@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
17681 + int nmap,
17682 + int ret_nmap);
17683 + #else
17684 +-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
17685 ++#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
17686 + #endif /* DEBUG */
17687 +
17688 + #if defined(XFS_RW_TRACE)
17689 +diff -urNp linux-2.6.27.10/grsecurity/gracl_alloc.c linux-2.6.27.10/grsecurity/gracl_alloc.c
17690 +--- linux-2.6.27.10/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
17691 ++++ linux-2.6.27.10/grsecurity/gracl_alloc.c 2008-11-18 03:38:45.000000000 -0500
17692 +@@ -0,0 +1,91 @@
17693 ++#include <linux/kernel.h>
17694 ++#include <linux/mm.h>
17695 ++#include <linux/slab.h>
17696 ++#include <linux/vmalloc.h>
17697 ++#include <linux/gracl.h>
17698 ++#include <linux/grsecurity.h>
17699 ++
17700 ++static unsigned long alloc_stack_next = 1;
17701 ++static unsigned long alloc_stack_size = 1;
17702 ++static void **alloc_stack;
17703 ++
17704 ++static __inline__ int
17705 ++alloc_pop(void)
17706 ++{
17707 ++ if (alloc_stack_next == 1)
17708 ++ return 0;
17709 ++
17710 ++ kfree(alloc_stack[alloc_stack_next - 2]);
17711 ++
17712 ++ alloc_stack_next--;
17713 ++
17714 ++ return 1;
17715 ++}
17716 ++
17717 ++static __inline__ void
17718 ++alloc_push(void *buf)
17719 ++{
17720 ++ if (alloc_stack_next >= alloc_stack_size)
17721 ++ BUG();
17722 ++
17723 ++ alloc_stack[alloc_stack_next - 1] = buf;
17724 ++
17725 ++ alloc_stack_next++;
17726 ++
17727 ++ return;
17728 ++}
17729 ++
17730 ++void *
17731 ++acl_alloc(unsigned long len)
17732 ++{
17733 ++ void *ret;
17734 ++
17735 ++ if (len > PAGE_SIZE)
17736 ++ BUG();
17737 ++
17738 ++ ret = kmalloc(len, GFP_KERNEL);
17739 ++
17740 ++ if (ret)
17741 ++ alloc_push(ret);
17742 ++
17743 ++ return ret;
17744 ++}
17745 ++
17746 ++void
17747 ++acl_free_all(void)
17748 ++{
17749 ++ if (gr_acl_is_enabled() || !alloc_stack)
17750 ++ return;
17751 ++
17752 ++ while (alloc_pop()) ;
17753 ++
17754 ++ if (alloc_stack) {
17755 ++ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
17756 ++ kfree(alloc_stack);
17757 ++ else
17758 ++ vfree(alloc_stack);
17759 ++ }
17760 ++
17761 ++ alloc_stack = NULL;
17762 ++ alloc_stack_size = 1;
17763 ++ alloc_stack_next = 1;
17764 ++
17765 ++ return;
17766 ++}
17767 ++
17768 ++int
17769 ++acl_alloc_stack_init(unsigned long size)
17770 ++{
17771 ++ if ((size * sizeof (void *)) <= PAGE_SIZE)
17772 ++ alloc_stack =
17773 ++ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
17774 ++ else
17775 ++ alloc_stack = (void **) vmalloc(size * sizeof (void *));
17776 ++
17777 ++ alloc_stack_size = size;
17778 ++
17779 ++ if (!alloc_stack)
17780 ++ return 0;
17781 ++ else
17782 ++ return 1;
17783 ++}
17784 +diff -urNp linux-2.6.27.10/grsecurity/gracl.c linux-2.6.27.10/grsecurity/gracl.c
17785 +--- linux-2.6.27.10/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
17786 ++++ linux-2.6.27.10/grsecurity/gracl.c 2008-11-18 03:38:45.000000000 -0500
17787 +@@ -0,0 +1,3722 @@
17788 ++#include <linux/kernel.h>
17789 ++#include <linux/module.h>
17790 ++#include <linux/sched.h>
17791 ++#include <linux/mm.h>
17792 ++#include <linux/file.h>
17793 ++#include <linux/fs.h>
17794 ++#include <linux/namei.h>
17795 ++#include <linux/mount.h>
17796 ++#include <linux/tty.h>
17797 ++#include <linux/proc_fs.h>
17798 ++#include <linux/smp_lock.h>
17799 ++#include <linux/slab.h>
17800 ++#include <linux/vmalloc.h>
17801 ++#include <linux/types.h>
17802 ++#include <linux/sysctl.h>
17803 ++#include <linux/netdevice.h>
17804 ++#include <linux/ptrace.h>
17805 ++#include <linux/gracl.h>
17806 ++#include <linux/gralloc.h>
17807 ++#include <linux/grsecurity.h>
17808 ++#include <linux/grinternal.h>
17809 ++#include <linux/pid_namespace.h>
17810 ++#include <linux/fdtable.h>
17811 ++#include <linux/percpu.h>
17812 ++
17813 ++#include <asm/uaccess.h>
17814 ++#include <asm/errno.h>
17815 ++#include <asm/mman.h>
17816 ++
17817 ++static struct acl_role_db acl_role_set;
17818 ++static struct name_db name_set;
17819 ++static struct inodev_db inodev_set;
17820 ++
17821 ++/* for keeping track of userspace pointers used for subjects, so we
17822 ++ can share references in the kernel as well
17823 ++*/
17824 ++
17825 ++static struct dentry *real_root;
17826 ++static struct vfsmount *real_root_mnt;
17827 ++
17828 ++static struct acl_subj_map_db subj_map_set;
17829 ++
17830 ++static struct acl_role_label *default_role;
17831 ++
17832 ++static u16 acl_sp_role_value;
17833 ++
17834 ++extern char *gr_shared_page[4];
17835 ++static DECLARE_MUTEX(gr_dev_sem);
17836 ++DEFINE_RWLOCK(gr_inode_lock);
17837 ++
17838 ++struct gr_arg *gr_usermode;
17839 ++
17840 ++static unsigned int gr_status = GR_STATUS_INIT;
17841 ++
17842 ++extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
17843 ++extern void gr_clear_learn_entries(void);
17844 ++
17845 ++#ifdef CONFIG_GRKERNSEC_RESLOG
17846 ++extern void gr_log_resource(const struct task_struct *task,
17847 ++ const int res, const unsigned long wanted, const int gt);
17848 ++#endif
17849 ++
17850 ++unsigned char *gr_system_salt;
17851 ++unsigned char *gr_system_sum;
17852 ++
17853 ++static struct sprole_pw **acl_special_roles = NULL;
17854 ++static __u16 num_sprole_pws = 0;
17855 ++
17856 ++static struct acl_role_label *kernel_role = NULL;
17857 ++
17858 ++static unsigned int gr_auth_attempts = 0;
17859 ++static unsigned long gr_auth_expires = 0UL;
17860 ++
17861 ++extern struct vfsmount *sock_mnt;
17862 ++extern struct vfsmount *pipe_mnt;
17863 ++extern struct vfsmount *shm_mnt;
17864 ++static struct acl_object_label *fakefs_obj;
17865 ++
17866 ++extern int gr_init_uidset(void);
17867 ++extern void gr_free_uidset(void);
17868 ++extern void gr_remove_uid(uid_t uid);
17869 ++extern int gr_find_uid(uid_t uid);
17870 ++
17871 ++__inline__ int
17872 ++gr_acl_is_enabled(void)
17873 ++{
17874 ++ return (gr_status & GR_READY);
17875 ++}
17876 ++
17877 ++char gr_roletype_to_char(void)
17878 ++{
17879 ++ switch (current->role->roletype &
17880 ++ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
17881 ++ GR_ROLE_SPECIAL)) {
17882 ++ case GR_ROLE_DEFAULT:
17883 ++ return 'D';
17884 ++ case GR_ROLE_USER:
17885 ++ return 'U';
17886 ++ case GR_ROLE_GROUP:
17887 ++ return 'G';
17888 ++ case GR_ROLE_SPECIAL:
17889 ++ return 'S';
17890 ++ }
17891 ++
17892 ++ return 'X';
17893 ++}
17894 ++
17895 ++__inline__ int
17896 ++gr_acl_tpe_check(void)
17897 ++{
17898 ++ if (unlikely(!(gr_status & GR_READY)))
17899 ++ return 0;
17900 ++ if (current->role->roletype & GR_ROLE_TPE)
17901 ++ return 1;
17902 ++ else
17903 ++ return 0;
17904 ++}
17905 ++
17906 ++int
17907 ++gr_handle_rawio(const struct inode *inode)
17908 ++{
17909 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
17910 ++ if (inode && S_ISBLK(inode->i_mode) &&
17911 ++ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
17912 ++ !capable(CAP_SYS_RAWIO))
17913 ++ return 1;
17914 ++#endif
17915 ++ return 0;
17916 ++}
17917 ++
17918 ++static int
17919 ++gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
17920 ++{
17921 ++ int i;
17922 ++ unsigned long *l1;
17923 ++ unsigned long *l2;
17924 ++ unsigned char *c1;
17925 ++ unsigned char *c2;
17926 ++ int num_longs;
17927 ++
17928 ++ if (likely(lena != lenb))
17929 ++ return 0;
17930 ++
17931 ++ l1 = (unsigned long *)a;
17932 ++ l2 = (unsigned long *)b;
17933 ++
17934 ++ num_longs = lena / sizeof(unsigned long);
17935 ++
17936 ++ for (i = num_longs; i--; l1++, l2++) {
17937 ++ if (unlikely(*l1 != *l2))
17938 ++ return 0;
17939 ++ }
17940 ++
17941 ++ c1 = (unsigned char *) l1;
17942 ++ c2 = (unsigned char *) l2;
17943 ++
17944 ++ i = lena - (num_longs * sizeof(unsigned long));
17945 ++
17946 ++ for (; i--; c1++, c2++) {
17947 ++ if (unlikely(*c1 != *c2))
17948 ++ return 0;
17949 ++ }
17950 ++
17951 ++ return 1;
17952 ++}
17953 ++
17954 ++static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
17955 ++ struct dentry *root, struct vfsmount *rootmnt,
17956 ++ char *buffer, int buflen)
17957 ++{
17958 ++ char * end = buffer+buflen;
17959 ++ char * retval;
17960 ++ int namelen;
17961 ++
17962 ++ *--end = '\0';
17963 ++ buflen--;
17964 ++
17965 ++ if (buflen < 1)
17966 ++ goto Elong;
17967 ++ /* Get '/' right */
17968 ++ retval = end-1;
17969 ++ *retval = '/';
17970 ++
17971 ++ for (;;) {
17972 ++ struct dentry * parent;
17973 ++
17974 ++ if (dentry == root && vfsmnt == rootmnt)
17975 ++ break;
17976 ++ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
17977 ++ /* Global root? */
17978 ++ spin_lock(&vfsmount_lock);
17979 ++ if (vfsmnt->mnt_parent == vfsmnt) {
17980 ++ spin_unlock(&vfsmount_lock);
17981 ++ goto global_root;
17982 ++ }
17983 ++ dentry = vfsmnt->mnt_mountpoint;
17984 ++ vfsmnt = vfsmnt->mnt_parent;
17985 ++ spin_unlock(&vfsmount_lock);
17986 ++ continue;
17987 ++ }
17988 ++ parent = dentry->d_parent;
17989 ++ prefetch(parent);
17990 ++ namelen = dentry->d_name.len;
17991 ++ buflen -= namelen + 1;
17992 ++ if (buflen < 0)
17993 ++ goto Elong;
17994 ++ end -= namelen;
17995 ++ memcpy(end, dentry->d_name.name, namelen);
17996 ++ *--end = '/';
17997 ++ retval = end;
17998 ++ dentry = parent;
17999 ++ }
18000 ++
18001 ++ return retval;
18002 ++
18003 ++global_root:
18004 ++ namelen = dentry->d_name.len;
18005 ++ buflen -= namelen;
18006 ++ if (buflen < 0)
18007 ++ goto Elong;
18008 ++ retval -= namelen-1; /* hit the slash */
18009 ++ memcpy(retval, dentry->d_name.name, namelen);
18010 ++ return retval;
18011 ++Elong:
18012 ++ return ERR_PTR(-ENAMETOOLONG);
18013 ++}
18014 ++
18015 ++static char *
18016 ++gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
18017 ++ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
18018 ++{
18019 ++ char *retval;
18020 ++
18021 ++ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
18022 ++ if (unlikely(IS_ERR(retval)))
18023 ++ retval = strcpy(buf, "<path too long>");
18024 ++ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
18025 ++ retval[1] = '\0';
18026 ++
18027 ++ return retval;
18028 ++}
18029 ++
18030 ++static char *
18031 ++__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
18032 ++ char *buf, int buflen)
18033 ++{
18034 ++ char *res;
18035 ++
18036 ++ /* we can use real_root, real_root_mnt, because this is only called
18037 ++ by the RBAC system */
18038 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
18039 ++
18040 ++ return res;
18041 ++}
18042 ++
18043 ++static char *
18044 ++d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
18045 ++ char *buf, int buflen)
18046 ++{
18047 ++ char *res;
18048 ++ struct dentry *root;
18049 ++ struct vfsmount *rootmnt;
18050 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
18051 ++
18052 ++ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
18053 ++ read_lock(&reaper->fs->lock);
18054 ++ root = dget(reaper->fs->root.dentry);
18055 ++ rootmnt = mntget(reaper->fs->root.mnt);
18056 ++ read_unlock(&reaper->fs->lock);
18057 ++
18058 ++ spin_lock(&dcache_lock);
18059 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
18060 ++ spin_unlock(&dcache_lock);
18061 ++
18062 ++ dput(root);
18063 ++ mntput(rootmnt);
18064 ++ return res;
18065 ++}
18066 ++
18067 ++static char *
18068 ++gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
18069 ++{
18070 ++ char *ret;
18071 ++ spin_lock(&dcache_lock);
18072 ++ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
18073 ++ PAGE_SIZE);
18074 ++ spin_unlock(&dcache_lock);
18075 ++ return ret;
18076 ++}
18077 ++
18078 ++char *
18079 ++gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
18080 ++{
18081 ++ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
18082 ++ PAGE_SIZE);
18083 ++}
18084 ++
18085 ++char *
18086 ++gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
18087 ++{
18088 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
18089 ++ PAGE_SIZE);
18090 ++}
18091 ++
18092 ++char *
18093 ++gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
18094 ++{
18095 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
18096 ++ PAGE_SIZE);
18097 ++}
18098 ++
18099 ++char *
18100 ++gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
18101 ++{
18102 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
18103 ++ PAGE_SIZE);
18104 ++}
18105 ++
18106 ++char *
18107 ++gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
18108 ++{
18109 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
18110 ++ PAGE_SIZE);
18111 ++}
18112 ++
18113 ++__inline__ __u32
18114 ++to_gr_audit(const __u32 reqmode)
18115 ++{
18116 ++ /* masks off auditable permission flags, then shifts them to create
18117 ++ auditing flags, and adds the special case of append auditing if
18118 ++ we're requesting write */
18119 ++ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
18120 ++}
18121 ++
18122 ++struct acl_subject_label *
18123 ++lookup_subject_map(const struct acl_subject_label *userp)
18124 ++{
18125 ++ unsigned int index = shash(userp, subj_map_set.s_size);
18126 ++ struct subject_map *match;
18127 ++
18128 ++ match = subj_map_set.s_hash[index];
18129 ++
18130 ++ while (match && match->user != userp)
18131 ++ match = match->next;
18132 ++
18133 ++ if (match != NULL)
18134 ++ return match->kernel;
18135 ++ else
18136 ++ return NULL;
18137 ++}
18138 ++
18139 ++static void
18140 ++insert_subj_map_entry(struct subject_map *subjmap)
18141 ++{
18142 ++ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
18143 ++ struct subject_map **curr;
18144 ++
18145 ++ subjmap->prev = NULL;
18146 ++
18147 ++ curr = &subj_map_set.s_hash[index];
18148 ++ if (*curr != NULL)
18149 ++ (*curr)->prev = subjmap;
18150 ++
18151 ++ subjmap->next = *curr;
18152 ++ *curr = subjmap;
18153 ++
18154 ++ return;
18155 ++}
18156 ++
18157 ++static struct acl_role_label *
18158 ++lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
18159 ++ const gid_t gid)
18160 ++{
18161 ++ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
18162 ++ struct acl_role_label *match;
18163 ++ struct role_allowed_ip *ipp;
18164 ++ unsigned int x;
18165 ++
18166 ++ match = acl_role_set.r_hash[index];
18167 ++
18168 ++ while (match) {
18169 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
18170 ++ for (x = 0; x < match->domain_child_num; x++) {
18171 ++ if (match->domain_children[x] == uid)
18172 ++ goto found;
18173 ++ }
18174 ++ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
18175 ++ break;
18176 ++ match = match->next;
18177 ++ }
18178 ++found:
18179 ++ if (match == NULL) {
18180 ++ try_group:
18181 ++ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
18182 ++ match = acl_role_set.r_hash[index];
18183 ++
18184 ++ while (match) {
18185 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
18186 ++ for (x = 0; x < match->domain_child_num; x++) {
18187 ++ if (match->domain_children[x] == gid)
18188 ++ goto found2;
18189 ++ }
18190 ++ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
18191 ++ break;
18192 ++ match = match->next;
18193 ++ }
18194 ++found2:
18195 ++ if (match == NULL)
18196 ++ match = default_role;
18197 ++ if (match->allowed_ips == NULL)
18198 ++ return match;
18199 ++ else {
18200 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18201 ++ if (likely
18202 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18203 ++ (ntohl(ipp->addr) & ipp->netmask)))
18204 ++ return match;
18205 ++ }
18206 ++ match = default_role;
18207 ++ }
18208 ++ } else if (match->allowed_ips == NULL) {
18209 ++ return match;
18210 ++ } else {
18211 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18212 ++ if (likely
18213 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18214 ++ (ntohl(ipp->addr) & ipp->netmask)))
18215 ++ return match;
18216 ++ }
18217 ++ goto try_group;
18218 ++ }
18219 ++
18220 ++ return match;
18221 ++}
18222 ++
18223 ++struct acl_subject_label *
18224 ++lookup_acl_subj_label(const ino_t ino, const dev_t dev,
18225 ++ const struct acl_role_label *role)
18226 ++{
18227 ++ unsigned int index = fhash(ino, dev, role->subj_hash_size);
18228 ++ struct acl_subject_label *match;
18229 ++
18230 ++ match = role->subj_hash[index];
18231 ++
18232 ++ while (match && (match->inode != ino || match->device != dev ||
18233 ++ (match->mode & GR_DELETED))) {
18234 ++ match = match->next;
18235 ++ }
18236 ++
18237 ++ if (match && !(match->mode & GR_DELETED))
18238 ++ return match;
18239 ++ else
18240 ++ return NULL;
18241 ++}
18242 ++
18243 ++static struct acl_object_label *
18244 ++lookup_acl_obj_label(const ino_t ino, const dev_t dev,
18245 ++ const struct acl_subject_label *subj)
18246 ++{
18247 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18248 ++ struct acl_object_label *match;
18249 ++
18250 ++ match = subj->obj_hash[index];
18251 ++
18252 ++ while (match && (match->inode != ino || match->device != dev ||
18253 ++ (match->mode & GR_DELETED))) {
18254 ++ match = match->next;
18255 ++ }
18256 ++
18257 ++ if (match && !(match->mode & GR_DELETED))
18258 ++ return match;
18259 ++ else
18260 ++ return NULL;
18261 ++}
18262 ++
18263 ++static struct acl_object_label *
18264 ++lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
18265 ++ const struct acl_subject_label *subj)
18266 ++{
18267 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18268 ++ struct acl_object_label *match;
18269 ++
18270 ++ match = subj->obj_hash[index];
18271 ++
18272 ++ while (match && (match->inode != ino || match->device != dev ||
18273 ++ !(match->mode & GR_DELETED))) {
18274 ++ match = match->next;
18275 ++ }
18276 ++
18277 ++ if (match && (match->mode & GR_DELETED))
18278 ++ return match;
18279 ++
18280 ++ match = subj->obj_hash[index];
18281 ++
18282 ++ while (match && (match->inode != ino || match->device != dev ||
18283 ++ (match->mode & GR_DELETED))) {
18284 ++ match = match->next;
18285 ++ }
18286 ++
18287 ++ if (match && !(match->mode & GR_DELETED))
18288 ++ return match;
18289 ++ else
18290 ++ return NULL;
18291 ++}
18292 ++
18293 ++static struct name_entry *
18294 ++lookup_name_entry(const char *name)
18295 ++{
18296 ++ unsigned int len = strlen(name);
18297 ++ unsigned int key = full_name_hash(name, len);
18298 ++ unsigned int index = key % name_set.n_size;
18299 ++ struct name_entry *match;
18300 ++
18301 ++ match = name_set.n_hash[index];
18302 ++
18303 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
18304 ++ match = match->next;
18305 ++
18306 ++ return match;
18307 ++}
18308 ++
18309 ++static struct name_entry *
18310 ++lookup_name_entry_create(const char *name)
18311 ++{
18312 ++ unsigned int len = strlen(name);
18313 ++ unsigned int key = full_name_hash(name, len);
18314 ++ unsigned int index = key % name_set.n_size;
18315 ++ struct name_entry *match;
18316 ++
18317 ++ match = name_set.n_hash[index];
18318 ++
18319 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18320 ++ !match->deleted))
18321 ++ match = match->next;
18322 ++
18323 ++ if (match && match->deleted)
18324 ++ return match;
18325 ++
18326 ++ match = name_set.n_hash[index];
18327 ++
18328 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18329 ++ match->deleted))
18330 ++ match = match->next;
18331 ++
18332 ++ if (match && !match->deleted)
18333 ++ return match;
18334 ++ else
18335 ++ return NULL;
18336 ++}
18337 ++
18338 ++static struct inodev_entry *
18339 ++lookup_inodev_entry(const ino_t ino, const dev_t dev)
18340 ++{
18341 ++ unsigned int index = fhash(ino, dev, inodev_set.i_size);
18342 ++ struct inodev_entry *match;
18343 ++
18344 ++ match = inodev_set.i_hash[index];
18345 ++
18346 ++ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
18347 ++ match = match->next;
18348 ++
18349 ++ return match;
18350 ++}
18351 ++
18352 ++static void
18353 ++insert_inodev_entry(struct inodev_entry *entry)
18354 ++{
18355 ++ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
18356 ++ inodev_set.i_size);
18357 ++ struct inodev_entry **curr;
18358 ++
18359 ++ entry->prev = NULL;
18360 ++
18361 ++ curr = &inodev_set.i_hash[index];
18362 ++ if (*curr != NULL)
18363 ++ (*curr)->prev = entry;
18364 ++
18365 ++ entry->next = *curr;
18366 ++ *curr = entry;
18367 ++
18368 ++ return;
18369 ++}
18370 ++
18371 ++static void
18372 ++__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
18373 ++{
18374 ++ unsigned int index =
18375 ++ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
18376 ++ struct acl_role_label **curr;
18377 ++
18378 ++ role->prev = NULL;
18379 ++
18380 ++ curr = &acl_role_set.r_hash[index];
18381 ++ if (*curr != NULL)
18382 ++ (*curr)->prev = role;
18383 ++
18384 ++ role->next = *curr;
18385 ++ *curr = role;
18386 ++
18387 ++ return;
18388 ++}
18389 ++
18390 ++static void
18391 ++insert_acl_role_label(struct acl_role_label *role)
18392 ++{
18393 ++ int i;
18394 ++
18395 ++ if (role->roletype & GR_ROLE_DOMAIN) {
18396 ++ for (i = 0; i < role->domain_child_num; i++)
18397 ++ __insert_acl_role_label(role, role->domain_children[i]);
18398 ++ } else
18399 ++ __insert_acl_role_label(role, role->uidgid);
18400 ++}
18401 ++
18402 ++static int
18403 ++insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
18404 ++{
18405 ++ struct name_entry **curr, *nentry;
18406 ++ struct inodev_entry *ientry;
18407 ++ unsigned int len = strlen(name);
18408 ++ unsigned int key = full_name_hash(name, len);
18409 ++ unsigned int index = key % name_set.n_size;
18410 ++
18411 ++ curr = &name_set.n_hash[index];
18412 ++
18413 ++ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
18414 ++ curr = &((*curr)->next);
18415 ++
18416 ++ if (*curr != NULL)
18417 ++ return 1;
18418 ++
18419 ++ nentry = acl_alloc(sizeof (struct name_entry));
18420 ++ if (nentry == NULL)
18421 ++ return 0;
18422 ++ ientry = acl_alloc(sizeof (struct inodev_entry));
18423 ++ if (ientry == NULL)
18424 ++ return 0;
18425 ++ ientry->nentry = nentry;
18426 ++
18427 ++ nentry->key = key;
18428 ++ nentry->name = name;
18429 ++ nentry->inode = inode;
18430 ++ nentry->device = device;
18431 ++ nentry->len = len;
18432 ++ nentry->deleted = deleted;
18433 ++
18434 ++ nentry->prev = NULL;
18435 ++ curr = &name_set.n_hash[index];
18436 ++ if (*curr != NULL)
18437 ++ (*curr)->prev = nentry;
18438 ++ nentry->next = *curr;
18439 ++ *curr = nentry;
18440 ++
18441 ++ /* insert us into the table searchable by inode/dev */
18442 ++ insert_inodev_entry(ientry);
18443 ++
18444 ++ return 1;
18445 ++}
18446 ++
18447 ++static void
18448 ++insert_acl_obj_label(struct acl_object_label *obj,
18449 ++ struct acl_subject_label *subj)
18450 ++{
18451 ++ unsigned int index =
18452 ++ fhash(obj->inode, obj->device, subj->obj_hash_size);
18453 ++ struct acl_object_label **curr;
18454 ++
18455 ++
18456 ++ obj->prev = NULL;
18457 ++
18458 ++ curr = &subj->obj_hash[index];
18459 ++ if (*curr != NULL)
18460 ++ (*curr)->prev = obj;
18461 ++
18462 ++ obj->next = *curr;
18463 ++ *curr = obj;
18464 ++
18465 ++ return;
18466 ++}
18467 ++
18468 ++static void
18469 ++insert_acl_subj_label(struct acl_subject_label *obj,
18470 ++ struct acl_role_label *role)
18471 ++{
18472 ++ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
18473 ++ struct acl_subject_label **curr;
18474 ++
18475 ++ obj->prev = NULL;
18476 ++
18477 ++ curr = &role->subj_hash[index];
18478 ++ if (*curr != NULL)
18479 ++ (*curr)->prev = obj;
18480 ++
18481 ++ obj->next = *curr;
18482 ++ *curr = obj;
18483 ++
18484 ++ return;
18485 ++}
18486 ++
18487 ++/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
18488 ++
18489 ++static void *
18490 ++create_table(__u32 * len, int elementsize)
18491 ++{
18492 ++ unsigned int table_sizes[] = {
18493 ++ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
18494 ++ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
18495 ++ 4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
18496 ++ 268435399, 536870909, 1073741789, 2147483647
18497 ++ };
18498 ++ void *newtable = NULL;
18499 ++ unsigned int pwr = 0;
18500 ++
18501 ++ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
18502 ++ table_sizes[pwr] <= *len)
18503 ++ pwr++;
18504 ++
18505 ++ if (table_sizes[pwr] <= *len)
18506 ++ return newtable;
18507 ++
18508 ++ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
18509 ++ newtable =
18510 ++ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
18511 ++ else
18512 ++ newtable = vmalloc(table_sizes[pwr] * elementsize);
18513 ++
18514 ++ *len = table_sizes[pwr];
18515 ++
18516 ++ return newtable;
18517 ++}
18518 ++
18519 ++static int
18520 ++init_variables(const struct gr_arg *arg)
18521 ++{
18522 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
18523 ++ unsigned int stacksize;
18524 ++
18525 ++ subj_map_set.s_size = arg->role_db.num_subjects;
18526 ++ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
18527 ++ name_set.n_size = arg->role_db.num_objects;
18528 ++ inodev_set.i_size = arg->role_db.num_objects;
18529 ++
18530 ++ if (!subj_map_set.s_size || !acl_role_set.r_size ||
18531 ++ !name_set.n_size || !inodev_set.i_size)
18532 ++ return 1;
18533 ++
18534 ++ if (!gr_init_uidset())
18535 ++ return 1;
18536 ++
18537 ++ /* set up the stack that holds allocation info */
18538 ++
18539 ++ stacksize = arg->role_db.num_pointers + 5;
18540 ++
18541 ++ if (!acl_alloc_stack_init(stacksize))
18542 ++ return 1;
18543 ++
18544 ++ /* grab reference for the real root dentry and vfsmount */
18545 ++ read_lock(&reaper->fs->lock);
18546 ++ real_root_mnt = mntget(reaper->fs->root.mnt);
18547 ++ real_root = dget(reaper->fs->root.dentry);
18548 ++ read_unlock(&reaper->fs->lock);
18549 ++
18550 ++ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
18551 ++ if (fakefs_obj == NULL)
18552 ++ return 1;
18553 ++ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
18554 ++
18555 ++ subj_map_set.s_hash =
18556 ++ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
18557 ++ acl_role_set.r_hash =
18558 ++ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
18559 ++ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
18560 ++ inodev_set.i_hash =
18561 ++ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
18562 ++
18563 ++ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
18564 ++ !name_set.n_hash || !inodev_set.i_hash)
18565 ++ return 1;
18566 ++
18567 ++ memset(subj_map_set.s_hash, 0,
18568 ++ sizeof(struct subject_map *) * subj_map_set.s_size);
18569 ++ memset(acl_role_set.r_hash, 0,
18570 ++ sizeof (struct acl_role_label *) * acl_role_set.r_size);
18571 ++ memset(name_set.n_hash, 0,
18572 ++ sizeof (struct name_entry *) * name_set.n_size);
18573 ++ memset(inodev_set.i_hash, 0,
18574 ++ sizeof (struct inodev_entry *) * inodev_set.i_size);
18575 ++
18576 ++ return 0;
18577 ++}
18578 ++
18579 ++/* free information not needed after startup
18580 ++ currently contains user->kernel pointer mappings for subjects
18581 ++*/
18582 ++
18583 ++static void
18584 ++free_init_variables(void)
18585 ++{
18586 ++ __u32 i;
18587 ++
18588 ++ if (subj_map_set.s_hash) {
18589 ++ for (i = 0; i < subj_map_set.s_size; i++) {
18590 ++ if (subj_map_set.s_hash[i]) {
18591 ++ kfree(subj_map_set.s_hash[i]);
18592 ++ subj_map_set.s_hash[i] = NULL;
18593 ++ }
18594 ++ }
18595 ++
18596 ++ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
18597 ++ PAGE_SIZE)
18598 ++ kfree(subj_map_set.s_hash);
18599 ++ else
18600 ++ vfree(subj_map_set.s_hash);
18601 ++ }
18602 ++
18603 ++ return;
18604 ++}
18605 ++
18606 ++static void
18607 ++free_variables(void)
18608 ++{
18609 ++ struct acl_subject_label *s;
18610 ++ struct acl_role_label *r;
18611 ++ struct task_struct *task, *task2;
18612 ++ unsigned int i, x;
18613 ++
18614 ++ gr_clear_learn_entries();
18615 ++
18616 ++ read_lock(&tasklist_lock);
18617 ++ do_each_thread(task2, task) {
18618 ++ task->acl_sp_role = 0;
18619 ++ task->acl_role_id = 0;
18620 ++ task->acl = NULL;
18621 ++ task->role = NULL;
18622 ++ } while_each_thread(task2, task);
18623 ++ read_unlock(&tasklist_lock);
18624 ++
18625 ++ /* release the reference to the real root dentry and vfsmount */
18626 ++ if (real_root)
18627 ++ dput(real_root);
18628 ++ real_root = NULL;
18629 ++ if (real_root_mnt)
18630 ++ mntput(real_root_mnt);
18631 ++ real_root_mnt = NULL;
18632 ++
18633 ++ /* free all object hash tables */
18634 ++
18635 ++ FOR_EACH_ROLE_START(r, i)
18636 ++ if (r->subj_hash == NULL)
18637 ++ break;
18638 ++ FOR_EACH_SUBJECT_START(r, s, x)
18639 ++ if (s->obj_hash == NULL)
18640 ++ break;
18641 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18642 ++ kfree(s->obj_hash);
18643 ++ else
18644 ++ vfree(s->obj_hash);
18645 ++ FOR_EACH_SUBJECT_END(s, x)
18646 ++ FOR_EACH_NESTED_SUBJECT_START(r, s)
18647 ++ if (s->obj_hash == NULL)
18648 ++ break;
18649 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18650 ++ kfree(s->obj_hash);
18651 ++ else
18652 ++ vfree(s->obj_hash);
18653 ++ FOR_EACH_NESTED_SUBJECT_END(s)
18654 ++ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
18655 ++ kfree(r->subj_hash);
18656 ++ else
18657 ++ vfree(r->subj_hash);
18658 ++ r->subj_hash = NULL;
18659 ++ FOR_EACH_ROLE_END(r,i)
18660 ++
18661 ++ acl_free_all();
18662 ++
18663 ++ if (acl_role_set.r_hash) {
18664 ++ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
18665 ++ PAGE_SIZE)
18666 ++ kfree(acl_role_set.r_hash);
18667 ++ else
18668 ++ vfree(acl_role_set.r_hash);
18669 ++ }
18670 ++ if (name_set.n_hash) {
18671 ++ if ((name_set.n_size * sizeof (struct name_entry *)) <=
18672 ++ PAGE_SIZE)
18673 ++ kfree(name_set.n_hash);
18674 ++ else
18675 ++ vfree(name_set.n_hash);
18676 ++ }
18677 ++
18678 ++ if (inodev_set.i_hash) {
18679 ++ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
18680 ++ PAGE_SIZE)
18681 ++ kfree(inodev_set.i_hash);
18682 ++ else
18683 ++ vfree(inodev_set.i_hash);
18684 ++ }
18685 ++
18686 ++ gr_free_uidset();
18687 ++
18688 ++ memset(&name_set, 0, sizeof (struct name_db));
18689 ++ memset(&inodev_set, 0, sizeof (struct inodev_db));
18690 ++ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
18691 ++ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
18692 ++
18693 ++ default_role = NULL;
18694 ++
18695 ++ return;
18696 ++}
18697 ++
18698 ++static __u32
18699 ++count_user_objs(struct acl_object_label *userp)
18700 ++{
18701 ++ struct acl_object_label o_tmp;
18702 ++ __u32 num = 0;
18703 ++
18704 ++ while (userp) {
18705 ++ if (copy_from_user(&o_tmp, userp,
18706 ++ sizeof (struct acl_object_label)))
18707 ++ break;
18708 ++
18709 ++ userp = o_tmp.prev;
18710 ++ num++;
18711 ++ }
18712 ++
18713 ++ return num;
18714 ++}
18715 ++
18716 ++static struct acl_subject_label *
18717 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
18718 ++
18719 ++static int
18720 ++copy_user_glob(struct acl_object_label *obj)
18721 ++{
18722 ++ struct acl_object_label *g_tmp, **guser;
18723 ++ unsigned int len;
18724 ++ char *tmp;
18725 ++
18726 ++ if (obj->globbed == NULL)
18727 ++ return 0;
18728 ++
18729 ++ guser = &obj->globbed;
18730 ++ while (*guser) {
18731 ++ g_tmp = (struct acl_object_label *)
18732 ++ acl_alloc(sizeof (struct acl_object_label));
18733 ++ if (g_tmp == NULL)
18734 ++ return -ENOMEM;
18735 ++
18736 ++ if (copy_from_user(g_tmp, *guser,
18737 ++ sizeof (struct acl_object_label)))
18738 ++ return -EFAULT;
18739 ++
18740 ++ len = strnlen_user(g_tmp->filename, PATH_MAX);
18741 ++
18742 ++ if (!len || len >= PATH_MAX)
18743 ++ return -EINVAL;
18744 ++
18745 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18746 ++ return -ENOMEM;
18747 ++
18748 ++ if (copy_from_user(tmp, g_tmp->filename, len))
18749 ++ return -EFAULT;
18750 ++
18751 ++ g_tmp->filename = tmp;
18752 ++
18753 ++ *guser = g_tmp;
18754 ++ guser = &(g_tmp->next);
18755 ++ }
18756 ++
18757 ++ return 0;
18758 ++}
18759 ++
18760 ++static int
18761 ++copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
18762 ++ struct acl_role_label *role)
18763 ++{
18764 ++ struct acl_object_label *o_tmp;
18765 ++ unsigned int len;
18766 ++ int ret;
18767 ++ char *tmp;
18768 ++
18769 ++ while (userp) {
18770 ++ if ((o_tmp = (struct acl_object_label *)
18771 ++ acl_alloc(sizeof (struct acl_object_label))) == NULL)
18772 ++ return -ENOMEM;
18773 ++
18774 ++ if (copy_from_user(o_tmp, userp,
18775 ++ sizeof (struct acl_object_label)))
18776 ++ return -EFAULT;
18777 ++
18778 ++ userp = o_tmp->prev;
18779 ++
18780 ++ len = strnlen_user(o_tmp->filename, PATH_MAX);
18781 ++
18782 ++ if (!len || len >= PATH_MAX)
18783 ++ return -EINVAL;
18784 ++
18785 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18786 ++ return -ENOMEM;
18787 ++
18788 ++ if (copy_from_user(tmp, o_tmp->filename, len))
18789 ++ return -EFAULT;
18790 ++
18791 ++ o_tmp->filename = tmp;
18792 ++
18793 ++ insert_acl_obj_label(o_tmp, subj);
18794 ++ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
18795 ++ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
18796 ++ return -ENOMEM;
18797 ++
18798 ++ ret = copy_user_glob(o_tmp);
18799 ++ if (ret)
18800 ++ return ret;
18801 ++
18802 ++ if (o_tmp->nested) {
18803 ++ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
18804 ++ if (IS_ERR(o_tmp->nested))
18805 ++ return PTR_ERR(o_tmp->nested);
18806 ++
18807 ++ /* insert into nested subject list */
18808 ++ o_tmp->nested->next = role->hash->first;
18809 ++ role->hash->first = o_tmp->nested;
18810 ++ }
18811 ++ }
18812 ++
18813 ++ return 0;
18814 ++}
18815 ++
18816 ++static __u32
18817 ++count_user_subjs(struct acl_subject_label *userp)
18818 ++{
18819 ++ struct acl_subject_label s_tmp;
18820 ++ __u32 num = 0;
18821 ++
18822 ++ while (userp) {
18823 ++ if (copy_from_user(&s_tmp, userp,
18824 ++ sizeof (struct acl_subject_label)))
18825 ++ break;
18826 ++
18827 ++ userp = s_tmp.prev;
18828 ++ /* do not count nested subjects against this count, since
18829 ++ they are not included in the hash table, but are
18830 ++ attached to objects. We have already counted
18831 ++ the subjects in userspace for the allocation
18832 ++ stack
18833 ++ */
18834 ++ if (!(s_tmp.mode & GR_NESTED))
18835 ++ num++;
18836 ++ }
18837 ++
18838 ++ return num;
18839 ++}
18840 ++
18841 ++static int
18842 ++copy_user_allowedips(struct acl_role_label *rolep)
18843 ++{
18844 ++ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
18845 ++
18846 ++ ruserip = rolep->allowed_ips;
18847 ++
18848 ++ while (ruserip) {
18849 ++ rlast = rtmp;
18850 ++
18851 ++ if ((rtmp = (struct role_allowed_ip *)
18852 ++ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
18853 ++ return -ENOMEM;
18854 ++
18855 ++ if (copy_from_user(rtmp, ruserip,
18856 ++ sizeof (struct role_allowed_ip)))
18857 ++ return -EFAULT;
18858 ++
18859 ++ ruserip = rtmp->prev;
18860 ++
18861 ++ if (!rlast) {
18862 ++ rtmp->prev = NULL;
18863 ++ rolep->allowed_ips = rtmp;
18864 ++ } else {
18865 ++ rlast->next = rtmp;
18866 ++ rtmp->prev = rlast;
18867 ++ }
18868 ++
18869 ++ if (!ruserip)
18870 ++ rtmp->next = NULL;
18871 ++ }
18872 ++
18873 ++ return 0;
18874 ++}
18875 ++
18876 ++static int
18877 ++copy_user_transitions(struct acl_role_label *rolep)
18878 ++{
18879 ++ struct role_transition *rusertp, *rtmp = NULL, *rlast;
18880 ++
18881 ++ unsigned int len;
18882 ++ char *tmp;
18883 ++
18884 ++ rusertp = rolep->transitions;
18885 ++
18886 ++ while (rusertp) {
18887 ++ rlast = rtmp;
18888 ++
18889 ++ if ((rtmp = (struct role_transition *)
18890 ++ acl_alloc(sizeof (struct role_transition))) == NULL)
18891 ++ return -ENOMEM;
18892 ++
18893 ++ if (copy_from_user(rtmp, rusertp,
18894 ++ sizeof (struct role_transition)))
18895 ++ return -EFAULT;
18896 ++
18897 ++ rusertp = rtmp->prev;
18898 ++
18899 ++ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
18900 ++
18901 ++ if (!len || len >= GR_SPROLE_LEN)
18902 ++ return -EINVAL;
18903 ++
18904 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18905 ++ return -ENOMEM;
18906 ++
18907 ++ if (copy_from_user(tmp, rtmp->rolename, len))
18908 ++ return -EFAULT;
18909 ++
18910 ++ rtmp->rolename = tmp;
18911 ++
18912 ++ if (!rlast) {
18913 ++ rtmp->prev = NULL;
18914 ++ rolep->transitions = rtmp;
18915 ++ } else {
18916 ++ rlast->next = rtmp;
18917 ++ rtmp->prev = rlast;
18918 ++ }
18919 ++
18920 ++ if (!rusertp)
18921 ++ rtmp->next = NULL;
18922 ++ }
18923 ++
18924 ++ return 0;
18925 ++}
18926 ++
18927 ++static struct acl_subject_label *
18928 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
18929 ++{
18930 ++ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
18931 ++ unsigned int len;
18932 ++ char *tmp;
18933 ++ __u32 num_objs;
18934 ++ struct acl_ip_label **i_tmp, *i_utmp2;
18935 ++ struct gr_hash_struct ghash;
18936 ++ struct subject_map *subjmap;
18937 ++ unsigned int i_num;
18938 ++ int err;
18939 ++
18940 ++ s_tmp = lookup_subject_map(userp);
18941 ++
18942 ++ /* we've already copied this subject into the kernel, just return
18943 ++ the reference to it, and don't copy it over again
18944 ++ */
18945 ++ if (s_tmp)
18946 ++ return(s_tmp);
18947 ++
18948 ++ if ((s_tmp = (struct acl_subject_label *)
18949 ++ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
18950 ++ return ERR_PTR(-ENOMEM);
18951 ++
18952 ++ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
18953 ++ if (subjmap == NULL)
18954 ++ return ERR_PTR(-ENOMEM);
18955 ++
18956 ++ subjmap->user = userp;
18957 ++ subjmap->kernel = s_tmp;
18958 ++ insert_subj_map_entry(subjmap);
18959 ++
18960 ++ if (copy_from_user(s_tmp, userp,
18961 ++ sizeof (struct acl_subject_label)))
18962 ++ return ERR_PTR(-EFAULT);
18963 ++
18964 ++ len = strnlen_user(s_tmp->filename, PATH_MAX);
18965 ++
18966 ++ if (!len || len >= PATH_MAX)
18967 ++ return ERR_PTR(-EINVAL);
18968 ++
18969 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18970 ++ return ERR_PTR(-ENOMEM);
18971 ++
18972 ++ if (copy_from_user(tmp, s_tmp->filename, len))
18973 ++ return ERR_PTR(-EFAULT);
18974 ++
18975 ++ s_tmp->filename = tmp;
18976 ++
18977 ++ if (!strcmp(s_tmp->filename, "/"))
18978 ++ role->root_label = s_tmp;
18979 ++
18980 ++ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
18981 ++ return ERR_PTR(-EFAULT);
18982 ++
18983 ++ /* copy user and group transition tables */
18984 ++
18985 ++ if (s_tmp->user_trans_num) {
18986 ++ uid_t *uidlist;
18987 ++
18988 ++ uidlist = (uid_t *)acl_alloc(s_tmp->user_trans_num * sizeof(uid_t));
18989 ++ if (uidlist == NULL)
18990 ++ return ERR_PTR(-ENOMEM);
18991 ++ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
18992 ++ return ERR_PTR(-EFAULT);
18993 ++
18994 ++ s_tmp->user_transitions = uidlist;
18995 ++ }
18996 ++
18997 ++ if (s_tmp->group_trans_num) {
18998 ++ gid_t *gidlist;
18999 ++
19000 ++ gidlist = (gid_t *)acl_alloc(s_tmp->group_trans_num * sizeof(gid_t));
19001 ++ if (gidlist == NULL)
19002 ++ return ERR_PTR(-ENOMEM);
19003 ++ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
19004 ++ return ERR_PTR(-EFAULT);
19005 ++
19006 ++ s_tmp->group_transitions = gidlist;
19007 ++ }
19008 ++
19009 ++ /* set up object hash table */
19010 ++ num_objs = count_user_objs(ghash.first);
19011 ++
19012 ++ s_tmp->obj_hash_size = num_objs;
19013 ++ s_tmp->obj_hash =
19014 ++ (struct acl_object_label **)
19015 ++ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
19016 ++
19017 ++ if (!s_tmp->obj_hash)
19018 ++ return ERR_PTR(-ENOMEM);
19019 ++
19020 ++ memset(s_tmp->obj_hash, 0,
19021 ++ s_tmp->obj_hash_size *
19022 ++ sizeof (struct acl_object_label *));
19023 ++
19024 ++ /* add in objects */
19025 ++ err = copy_user_objs(ghash.first, s_tmp, role);
19026 ++
19027 ++ if (err)
19028 ++ return ERR_PTR(err);
19029 ++
19030 ++ /* set pointer for parent subject */
19031 ++ if (s_tmp->parent_subject) {
19032 ++ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
19033 ++
19034 ++ if (IS_ERR(s_tmp2))
19035 ++ return s_tmp2;
19036 ++
19037 ++ s_tmp->parent_subject = s_tmp2;
19038 ++ }
19039 ++
19040 ++ /* add in ip acls */
19041 ++
19042 ++ if (!s_tmp->ip_num) {
19043 ++ s_tmp->ips = NULL;
19044 ++ goto insert;
19045 ++ }
19046 ++
19047 ++ i_tmp =
19048 ++ (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
19049 ++ sizeof (struct
19050 ++ acl_ip_label *));
19051 ++
19052 ++ if (!i_tmp)
19053 ++ return ERR_PTR(-ENOMEM);
19054 ++
19055 ++ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
19056 ++ *(i_tmp + i_num) =
19057 ++ (struct acl_ip_label *)
19058 ++ acl_alloc(sizeof (struct acl_ip_label));
19059 ++ if (!*(i_tmp + i_num))
19060 ++ return ERR_PTR(-ENOMEM);
19061 ++
19062 ++ if (copy_from_user
19063 ++ (&i_utmp2, s_tmp->ips + i_num,
19064 ++ sizeof (struct acl_ip_label *)))
19065 ++ return ERR_PTR(-EFAULT);
19066 ++
19067 ++ if (copy_from_user
19068 ++ (*(i_tmp + i_num), i_utmp2,
19069 ++ sizeof (struct acl_ip_label)))
19070 ++ return ERR_PTR(-EFAULT);
19071 ++
19072 ++ if ((*(i_tmp + i_num))->iface == NULL)
19073 ++ continue;
19074 ++
19075 ++ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
19076 ++ if (!len || len >= IFNAMSIZ)
19077 ++ return ERR_PTR(-EINVAL);
19078 ++ tmp = acl_alloc(len);
19079 ++ if (tmp == NULL)
19080 ++ return ERR_PTR(-ENOMEM);
19081 ++ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
19082 ++ return ERR_PTR(-EFAULT);
19083 ++ (*(i_tmp + i_num))->iface = tmp;
19084 ++ }
19085 ++
19086 ++ s_tmp->ips = i_tmp;
19087 ++
19088 ++insert:
19089 ++ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
19090 ++ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
19091 ++ return ERR_PTR(-ENOMEM);
19092 ++
19093 ++ return s_tmp;
19094 ++}
19095 ++
19096 ++static int
19097 ++copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
19098 ++{
19099 ++ struct acl_subject_label s_pre;
19100 ++ struct acl_subject_label * ret;
19101 ++ int err;
19102 ++
19103 ++ while (userp) {
19104 ++ if (copy_from_user(&s_pre, userp,
19105 ++ sizeof (struct acl_subject_label)))
19106 ++ return -EFAULT;
19107 ++
19108 ++ /* do not add nested subjects here, add
19109 ++ while parsing objects
19110 ++ */
19111 ++
19112 ++ if (s_pre.mode & GR_NESTED) {
19113 ++ userp = s_pre.prev;
19114 ++ continue;
19115 ++ }
19116 ++
19117 ++ ret = do_copy_user_subj(userp, role);
19118 ++
19119 ++ err = PTR_ERR(ret);
19120 ++ if (IS_ERR(ret))
19121 ++ return err;
19122 ++
19123 ++ insert_acl_subj_label(ret, role);
19124 ++
19125 ++ userp = s_pre.prev;
19126 ++ }
19127 ++
19128 ++ return 0;
19129 ++}
19130 ++
19131 ++static int
19132 ++copy_user_acl(struct gr_arg *arg)
19133 ++{
19134 ++ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
19135 ++ struct sprole_pw *sptmp;
19136 ++ struct gr_hash_struct *ghash;
19137 ++ uid_t *domainlist;
19138 ++ unsigned int r_num;
19139 ++ unsigned int len;
19140 ++ char *tmp;
19141 ++ int err = 0;
19142 ++ __u16 i;
19143 ++ __u32 num_subjs;
19144 ++
19145 ++ /* we need a default and kernel role */
19146 ++ if (arg->role_db.num_roles < 2)
19147 ++ return -EINVAL;
19148 ++
19149 ++ /* copy special role authentication info from userspace */
19150 ++
19151 ++ num_sprole_pws = arg->num_sprole_pws;
19152 ++ acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
19153 ++
19154 ++ if (!acl_special_roles) {
19155 ++ err = -ENOMEM;
19156 ++ goto cleanup;
19157 ++ }
19158 ++
19159 ++ for (i = 0; i < num_sprole_pws; i++) {
19160 ++ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
19161 ++ if (!sptmp) {
19162 ++ err = -ENOMEM;
19163 ++ goto cleanup;
19164 ++ }
19165 ++ if (copy_from_user(sptmp, arg->sprole_pws + i,
19166 ++ sizeof (struct sprole_pw))) {
19167 ++ err = -EFAULT;
19168 ++ goto cleanup;
19169 ++ }
19170 ++
19171 ++ len =
19172 ++ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
19173 ++
19174 ++ if (!len || len >= GR_SPROLE_LEN) {
19175 ++ err = -EINVAL;
19176 ++ goto cleanup;
19177 ++ }
19178 ++
19179 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19180 ++ err = -ENOMEM;
19181 ++ goto cleanup;
19182 ++ }
19183 ++
19184 ++ if (copy_from_user(tmp, sptmp->rolename, len)) {
19185 ++ err = -EFAULT;
19186 ++ goto cleanup;
19187 ++ }
19188 ++
19189 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
19190 ++ printk(KERN_ALERT "Copying special role %s\n", tmp);
19191 ++#endif
19192 ++ sptmp->rolename = tmp;
19193 ++ acl_special_roles[i] = sptmp;
19194 ++ }
19195 ++
19196 ++ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
19197 ++
19198 ++ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
19199 ++ r_tmp = acl_alloc(sizeof (struct acl_role_label));
19200 ++
19201 ++ if (!r_tmp) {
19202 ++ err = -ENOMEM;
19203 ++ goto cleanup;
19204 ++ }
19205 ++
19206 ++ if (copy_from_user(&r_utmp2, r_utmp + r_num,
19207 ++ sizeof (struct acl_role_label *))) {
19208 ++ err = -EFAULT;
19209 ++ goto cleanup;
19210 ++ }
19211 ++
19212 ++ if (copy_from_user(r_tmp, r_utmp2,
19213 ++ sizeof (struct acl_role_label))) {
19214 ++ err = -EFAULT;
19215 ++ goto cleanup;
19216 ++ }
19217 ++
19218 ++ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
19219 ++
19220 ++ if (!len || len >= PATH_MAX) {
19221 ++ err = -EINVAL;
19222 ++ goto cleanup;
19223 ++ }
19224 ++
19225 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19226 ++ err = -ENOMEM;
19227 ++ goto cleanup;
19228 ++ }
19229 ++ if (copy_from_user(tmp, r_tmp->rolename, len)) {
19230 ++ err = -EFAULT;
19231 ++ goto cleanup;
19232 ++ }
19233 ++ r_tmp->rolename = tmp;
19234 ++
19235 ++ if (!strcmp(r_tmp->rolename, "default")
19236 ++ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
19237 ++ default_role = r_tmp;
19238 ++ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
19239 ++ kernel_role = r_tmp;
19240 ++ }
19241 ++
19242 ++ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
19243 ++ err = -ENOMEM;
19244 ++ goto cleanup;
19245 ++ }
19246 ++ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
19247 ++ err = -EFAULT;
19248 ++ goto cleanup;
19249 ++ }
19250 ++
19251 ++ r_tmp->hash = ghash;
19252 ++
19253 ++ num_subjs = count_user_subjs(r_tmp->hash->first);
19254 ++
19255 ++ r_tmp->subj_hash_size = num_subjs;
19256 ++ r_tmp->subj_hash =
19257 ++ (struct acl_subject_label **)
19258 ++ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
19259 ++
19260 ++ if (!r_tmp->subj_hash) {
19261 ++ err = -ENOMEM;
19262 ++ goto cleanup;
19263 ++ }
19264 ++
19265 ++ err = copy_user_allowedips(r_tmp);
19266 ++ if (err)
19267 ++ goto cleanup;
19268 ++
19269 ++ /* copy domain info */
19270 ++ if (r_tmp->domain_children != NULL) {
19271 ++ domainlist = acl_alloc(r_tmp->domain_child_num * sizeof(uid_t));
19272 ++ if (domainlist == NULL) {
19273 ++ err = -ENOMEM;
19274 ++ goto cleanup;
19275 ++ }
19276 ++ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
19277 ++ err = -EFAULT;
19278 ++ goto cleanup;
19279 ++ }
19280 ++ r_tmp->domain_children = domainlist;
19281 ++ }
19282 ++
19283 ++ err = copy_user_transitions(r_tmp);
19284 ++ if (err)
19285 ++ goto cleanup;
19286 ++
19287 ++ memset(r_tmp->subj_hash, 0,
19288 ++ r_tmp->subj_hash_size *
19289 ++ sizeof (struct acl_subject_label *));
19290 ++
19291 ++ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
19292 ++
19293 ++ if (err)
19294 ++ goto cleanup;
19295 ++
19296 ++ /* set nested subject list to null */
19297 ++ r_tmp->hash->first = NULL;
19298 ++
19299 ++ insert_acl_role_label(r_tmp);
19300 ++ }
19301 ++
19302 ++ goto return_err;
19303 ++ cleanup:
19304 ++ free_variables();
19305 ++ return_err:
19306 ++ return err;
19307 ++
19308 ++}
19309 ++
19310 ++static int
19311 ++gracl_init(struct gr_arg *args)
19312 ++{
19313 ++ int error = 0;
19314 ++
19315 ++ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
19316 ++ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
19317 ++
19318 ++ if (init_variables(args)) {
19319 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
19320 ++ error = -ENOMEM;
19321 ++ free_variables();
19322 ++ goto out;
19323 ++ }
19324 ++
19325 ++ error = copy_user_acl(args);
19326 ++ free_init_variables();
19327 ++ if (error) {
19328 ++ free_variables();
19329 ++ goto out;
19330 ++ }
19331 ++
19332 ++ if ((error = gr_set_acls(0))) {
19333 ++ free_variables();
19334 ++ goto out;
19335 ++ }
19336 ++
19337 ++ gr_status |= GR_READY;
19338 ++ out:
19339 ++ return error;
19340 ++}
19341 ++
19342 ++/* derived from glibc fnmatch() 0: match, 1: no match*/
19343 ++
19344 ++static int
19345 ++glob_match(const char *p, const char *n)
19346 ++{
19347 ++ char c;
19348 ++
19349 ++ while ((c = *p++) != '\0') {
19350 ++ switch (c) {
19351 ++ case '?':
19352 ++ if (*n == '\0')
19353 ++ return 1;
19354 ++ else if (*n == '/')
19355 ++ return 1;
19356 ++ break;
19357 ++ case '\\':
19358 ++ if (*n != c)
19359 ++ return 1;
19360 ++ break;
19361 ++ case '*':
19362 ++ for (c = *p++; c == '?' || c == '*'; c = *p++) {
19363 ++ if (*n == '/')
19364 ++ return 1;
19365 ++ else if (c == '?') {
19366 ++ if (*n == '\0')
19367 ++ return 1;
19368 ++ else
19369 ++ ++n;
19370 ++ }
19371 ++ }
19372 ++ if (c == '\0') {
19373 ++ return 0;
19374 ++ } else {
19375 ++ const char *endp;
19376 ++
19377 ++ if ((endp = strchr(n, '/')) == NULL)
19378 ++ endp = n + strlen(n);
19379 ++
19380 ++ if (c == '[') {
19381 ++ for (--p; n < endp; ++n)
19382 ++ if (!glob_match(p, n))
19383 ++ return 0;
19384 ++ } else if (c == '/') {
19385 ++ while (*n != '\0' && *n != '/')
19386 ++ ++n;
19387 ++ if (*n == '/' && !glob_match(p, n + 1))
19388 ++ return 0;
19389 ++ } else {
19390 ++ for (--p; n < endp; ++n)
19391 ++ if (*n == c && !glob_match(p, n))
19392 ++ return 0;
19393 ++ }
19394 ++
19395 ++ return 1;
19396 ++ }
19397 ++ case '[':
19398 ++ {
19399 ++ int not;
19400 ++ char cold;
19401 ++
19402 ++ if (*n == '\0' || *n == '/')
19403 ++ return 1;
19404 ++
19405 ++ not = (*p == '!' || *p == '^');
19406 ++ if (not)
19407 ++ ++p;
19408 ++
19409 ++ c = *p++;
19410 ++ for (;;) {
19411 ++ unsigned char fn = (unsigned char)*n;
19412 ++
19413 ++ if (c == '\0')
19414 ++ return 1;
19415 ++ else {
19416 ++ if (c == fn)
19417 ++ goto matched;
19418 ++ cold = c;
19419 ++ c = *p++;
19420 ++
19421 ++ if (c == '-' && *p != ']') {
19422 ++ unsigned char cend = *p++;
19423 ++
19424 ++ if (cend == '\0')
19425 ++ return 1;
19426 ++
19427 ++ if (cold <= fn && fn <= cend)
19428 ++ goto matched;
19429 ++
19430 ++ c = *p++;
19431 ++ }
19432 ++ }
19433 ++
19434 ++ if (c == ']')
19435 ++ break;
19436 ++ }
19437 ++ if (!not)
19438 ++ return 1;
19439 ++ break;
19440 ++ matched:
19441 ++ while (c != ']') {
19442 ++ if (c == '\0')
19443 ++ return 1;
19444 ++
19445 ++ c = *p++;
19446 ++ }
19447 ++ if (not)
19448 ++ return 1;
19449 ++ }
19450 ++ break;
19451 ++ default:
19452 ++ if (c != *n)
19453 ++ return 1;
19454 ++ }
19455 ++
19456 ++ ++n;
19457 ++ }
19458 ++
19459 ++ if (*n == '\0')
19460 ++ return 0;
19461 ++
19462 ++ if (*n == '/')
19463 ++ return 0;
19464 ++
19465 ++ return 1;
19466 ++}
19467 ++
19468 ++static struct acl_object_label *
19469 ++chk_glob_label(struct acl_object_label *globbed,
19470 ++ struct dentry *dentry, struct vfsmount *mnt, char **path)
19471 ++{
19472 ++ struct acl_object_label *tmp;
19473 ++
19474 ++ if (*path == NULL)
19475 ++ *path = gr_to_filename_nolock(dentry, mnt);
19476 ++
19477 ++ tmp = globbed;
19478 ++
19479 ++ while (tmp) {
19480 ++ if (!glob_match(tmp->filename, *path))
19481 ++ return tmp;
19482 ++ tmp = tmp->next;
19483 ++ }
19484 ++
19485 ++ return NULL;
19486 ++}
19487 ++
19488 ++static struct acl_object_label *
19489 ++__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19490 ++ const ino_t curr_ino, const dev_t curr_dev,
19491 ++ const struct acl_subject_label *subj, char **path)
19492 ++{
19493 ++ struct acl_subject_label *tmpsubj;
19494 ++ struct acl_object_label *retval;
19495 ++ struct acl_object_label *retval2;
19496 ++
19497 ++ tmpsubj = (struct acl_subject_label *) subj;
19498 ++ read_lock(&gr_inode_lock);
19499 ++ do {
19500 ++ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
19501 ++ if (retval) {
19502 ++ if (retval->globbed) {
19503 ++ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
19504 ++ (struct vfsmount *)orig_mnt, path);
19505 ++ if (retval2)
19506 ++ retval = retval2;
19507 ++ }
19508 ++ break;
19509 ++ }
19510 ++ } while ((tmpsubj = tmpsubj->parent_subject));
19511 ++ read_unlock(&gr_inode_lock);
19512 ++
19513 ++ return retval;
19514 ++}
19515 ++
19516 ++static __inline__ struct acl_object_label *
19517 ++full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19518 ++ const struct dentry *curr_dentry,
19519 ++ const struct acl_subject_label *subj, char **path)
19520 ++{
19521 ++ return __full_lookup(orig_dentry, orig_mnt,
19522 ++ curr_dentry->d_inode->i_ino,
19523 ++ curr_dentry->d_inode->i_sb->s_dev, subj, path);
19524 ++}
19525 ++
19526 ++static struct acl_object_label *
19527 ++__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19528 ++ const struct acl_subject_label *subj, char *path)
19529 ++{
19530 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19531 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19532 ++ struct acl_object_label *retval;
19533 ++
19534 ++ spin_lock(&dcache_lock);
19535 ++
19536 ++ if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
19537 ++ /* ignore Eric Biederman */
19538 ++ IS_PRIVATE(l_dentry->d_inode))) {
19539 ++ retval = fakefs_obj;
19540 ++ goto out;
19541 ++ }
19542 ++
19543 ++ for (;;) {
19544 ++ if (dentry == real_root && mnt == real_root_mnt)
19545 ++ break;
19546 ++
19547 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19548 ++ if (mnt->mnt_parent == mnt)
19549 ++ break;
19550 ++
19551 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19552 ++ if (retval != NULL)
19553 ++ goto out;
19554 ++
19555 ++ dentry = mnt->mnt_mountpoint;
19556 ++ mnt = mnt->mnt_parent;
19557 ++ continue;
19558 ++ }
19559 ++
19560 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19561 ++ if (retval != NULL)
19562 ++ goto out;
19563 ++
19564 ++ dentry = dentry->d_parent;
19565 ++ }
19566 ++
19567 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19568 ++
19569 ++ if (retval == NULL)
19570 ++ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path);
19571 ++out:
19572 ++ spin_unlock(&dcache_lock);
19573 ++ return retval;
19574 ++}
19575 ++
19576 ++static __inline__ struct acl_object_label *
19577 ++chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19578 ++ const struct acl_subject_label *subj)
19579 ++{
19580 ++ char *path = NULL;
19581 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19582 ++}
19583 ++
19584 ++static __inline__ struct acl_object_label *
19585 ++chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19586 ++ const struct acl_subject_label *subj, char *path)
19587 ++{
19588 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19589 ++}
19590 ++
19591 ++static struct acl_subject_label *
19592 ++chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19593 ++ const struct acl_role_label *role)
19594 ++{
19595 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19596 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19597 ++ struct acl_subject_label *retval;
19598 ++
19599 ++ spin_lock(&dcache_lock);
19600 ++
19601 ++ for (;;) {
19602 ++ if (dentry == real_root && mnt == real_root_mnt)
19603 ++ break;
19604 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19605 ++ if (mnt->mnt_parent == mnt)
19606 ++ break;
19607 ++
19608 ++ read_lock(&gr_inode_lock);
19609 ++ retval =
19610 ++ lookup_acl_subj_label(dentry->d_inode->i_ino,
19611 ++ dentry->d_inode->i_sb->s_dev, role);
19612 ++ read_unlock(&gr_inode_lock);
19613 ++ if (retval != NULL)
19614 ++ goto out;
19615 ++
19616 ++ dentry = mnt->mnt_mountpoint;
19617 ++ mnt = mnt->mnt_parent;
19618 ++ continue;
19619 ++ }
19620 ++
19621 ++ read_lock(&gr_inode_lock);
19622 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19623 ++ dentry->d_inode->i_sb->s_dev, role);
19624 ++ read_unlock(&gr_inode_lock);
19625 ++ if (retval != NULL)
19626 ++ goto out;
19627 ++
19628 ++ dentry = dentry->d_parent;
19629 ++ }
19630 ++
19631 ++ read_lock(&gr_inode_lock);
19632 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19633 ++ dentry->d_inode->i_sb->s_dev, role);
19634 ++ read_unlock(&gr_inode_lock);
19635 ++
19636 ++ if (unlikely(retval == NULL)) {
19637 ++ read_lock(&gr_inode_lock);
19638 ++ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
19639 ++ real_root->d_inode->i_sb->s_dev, role);
19640 ++ read_unlock(&gr_inode_lock);
19641 ++ }
19642 ++out:
19643 ++ spin_unlock(&dcache_lock);
19644 ++
19645 ++ return retval;
19646 ++}
19647 ++
19648 ++static void
19649 ++gr_log_learn(const struct task_struct *task, const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
19650 ++{
19651 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19652 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19653 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19654 ++ 1, 1, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19655 ++
19656 ++ return;
19657 ++}
19658 ++
19659 ++static void
19660 ++gr_log_learn_sysctl(const struct task_struct *task, const char *path, const __u32 mode)
19661 ++{
19662 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19663 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19664 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19665 ++ 1, 1, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19666 ++
19667 ++ return;
19668 ++}
19669 ++
19670 ++static void
19671 ++gr_log_learn_id_change(const struct task_struct *task, const char type, const unsigned int real,
19672 ++ const unsigned int effective, const unsigned int fs)
19673 ++{
19674 ++ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
19675 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19676 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19677 ++ type, real, effective, fs, NIPQUAD(task->signal->curr_ip));
19678 ++
19679 ++ return;
19680 ++}
19681 ++
19682 ++__u32
19683 ++gr_check_link(const struct dentry * new_dentry,
19684 ++ const struct dentry * parent_dentry,
19685 ++ const struct vfsmount * parent_mnt,
19686 ++ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
19687 ++{
19688 ++ struct acl_object_label *obj;
19689 ++ __u32 oldmode, newmode;
19690 ++ __u32 needmode;
19691 ++
19692 ++ if (unlikely(!(gr_status & GR_READY)))
19693 ++ return (GR_CREATE | GR_LINK);
19694 ++
19695 ++ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
19696 ++ oldmode = obj->mode;
19697 ++
19698 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19699 ++ oldmode |= (GR_CREATE | GR_LINK);
19700 ++
19701 ++ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
19702 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19703 ++ needmode |= GR_SETID | GR_AUDIT_SETID;
19704 ++
19705 ++ newmode =
19706 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
19707 ++ oldmode | needmode);
19708 ++
19709 ++ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
19710 ++ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
19711 ++ GR_INHERIT | GR_AUDIT_INHERIT);
19712 ++
19713 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
19714 ++ goto bad;
19715 ++
19716 ++ if ((oldmode & needmode) != needmode)
19717 ++ goto bad;
19718 ++
19719 ++ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
19720 ++ if ((newmode & needmode) != needmode)
19721 ++ goto bad;
19722 ++
19723 ++ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
19724 ++ return newmode;
19725 ++bad:
19726 ++ needmode = oldmode;
19727 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19728 ++ needmode |= GR_SETID;
19729 ++
19730 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19731 ++ gr_log_learn(current, old_dentry, old_mnt, needmode);
19732 ++ return (GR_CREATE | GR_LINK);
19733 ++ } else if (newmode & GR_SUPPRESS)
19734 ++ return GR_SUPPRESS;
19735 ++ else
19736 ++ return 0;
19737 ++}
19738 ++
19739 ++__u32
19740 ++gr_search_file(const struct dentry * dentry, const __u32 mode,
19741 ++ const struct vfsmount * mnt)
19742 ++{
19743 ++ __u32 retval = mode;
19744 ++ struct acl_subject_label *curracl;
19745 ++ struct acl_object_label *currobj;
19746 ++
19747 ++ if (unlikely(!(gr_status & GR_READY)))
19748 ++ return (mode & ~GR_AUDITS);
19749 ++
19750 ++ curracl = current->acl;
19751 ++
19752 ++ currobj = chk_obj_label(dentry, mnt, curracl);
19753 ++ retval = currobj->mode & mode;
19754 ++
19755 ++ if (unlikely
19756 ++ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
19757 ++ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
19758 ++ __u32 new_mode = mode;
19759 ++
19760 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19761 ++
19762 ++ retval = new_mode;
19763 ++
19764 ++ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
19765 ++ new_mode |= GR_INHERIT;
19766 ++
19767 ++ if (!(mode & GR_NOLEARN))
19768 ++ gr_log_learn(current, dentry, mnt, new_mode);
19769 ++ }
19770 ++
19771 ++ return retval;
19772 ++}
19773 ++
19774 ++__u32
19775 ++gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
19776 ++ const struct vfsmount * mnt, const __u32 mode)
19777 ++{
19778 ++ struct name_entry *match;
19779 ++ struct acl_object_label *matchpo;
19780 ++ struct acl_subject_label *curracl;
19781 ++ char *path;
19782 ++ __u32 retval;
19783 ++
19784 ++ if (unlikely(!(gr_status & GR_READY)))
19785 ++ return (mode & ~GR_AUDITS);
19786 ++
19787 ++ preempt_disable();
19788 ++ path = gr_to_filename_rbac(new_dentry, mnt);
19789 ++ match = lookup_name_entry_create(path);
19790 ++
19791 ++ if (!match)
19792 ++ goto check_parent;
19793 ++
19794 ++ curracl = current->acl;
19795 ++
19796 ++ read_lock(&gr_inode_lock);
19797 ++ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
19798 ++ read_unlock(&gr_inode_lock);
19799 ++
19800 ++ if (matchpo) {
19801 ++ if ((matchpo->mode & mode) !=
19802 ++ (mode & ~(GR_AUDITS | GR_SUPPRESS))
19803 ++ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19804 ++ __u32 new_mode = mode;
19805 ++
19806 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19807 ++
19808 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19809 ++
19810 ++ preempt_enable();
19811 ++ return new_mode;
19812 ++ }
19813 ++ preempt_enable();
19814 ++ return (matchpo->mode & mode);
19815 ++ }
19816 ++
19817 ++ check_parent:
19818 ++ curracl = current->acl;
19819 ++
19820 ++ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
19821 ++ retval = matchpo->mode & mode;
19822 ++
19823 ++ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
19824 ++ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
19825 ++ __u32 new_mode = mode;
19826 ++
19827 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19828 ++
19829 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19830 ++ preempt_enable();
19831 ++ return new_mode;
19832 ++ }
19833 ++
19834 ++ preempt_enable();
19835 ++ return retval;
19836 ++}
19837 ++
19838 ++int
19839 ++gr_check_hidden_task(const struct task_struct *task)
19840 ++{
19841 ++ if (unlikely(!(gr_status & GR_READY)))
19842 ++ return 0;
19843 ++
19844 ++ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
19845 ++ return 1;
19846 ++
19847 ++ return 0;
19848 ++}
19849 ++
19850 ++int
19851 ++gr_check_protected_task(const struct task_struct *task)
19852 ++{
19853 ++ if (unlikely(!(gr_status & GR_READY) || !task))
19854 ++ return 0;
19855 ++
19856 ++ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
19857 ++ task->acl != current->acl)
19858 ++ return 1;
19859 ++
19860 ++ return 0;
19861 ++}
19862 ++
19863 ++void
19864 ++gr_copy_label(struct task_struct *tsk)
19865 ++{
19866 ++ tsk->signal->used_accept = 0;
19867 ++ tsk->acl_sp_role = 0;
19868 ++ tsk->acl_role_id = current->acl_role_id;
19869 ++ tsk->acl = current->acl;
19870 ++ tsk->role = current->role;
19871 ++ tsk->signal->curr_ip = current->signal->curr_ip;
19872 ++ if (current->exec_file)
19873 ++ get_file(current->exec_file);
19874 ++ tsk->exec_file = current->exec_file;
19875 ++ tsk->is_writable = current->is_writable;
19876 ++ if (unlikely(current->signal->used_accept))
19877 ++ current->signal->curr_ip = 0;
19878 ++
19879 ++ return;
19880 ++}
19881 ++
19882 ++static void
19883 ++gr_set_proc_res(struct task_struct *task)
19884 ++{
19885 ++ struct acl_subject_label *proc;
19886 ++ unsigned short i;
19887 ++
19888 ++ proc = task->acl;
19889 ++
19890 ++ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
19891 ++ return;
19892 ++
19893 ++ for (i = 0; i < (GR_NLIMITS - 1); i++) {
19894 ++ if (!(proc->resmask & (1 << i)))
19895 ++ continue;
19896 ++
19897 ++ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
19898 ++ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
19899 ++ }
19900 ++
19901 ++ return;
19902 ++}
19903 ++
19904 ++int
19905 ++gr_check_user_change(int real, int effective, int fs)
19906 ++{
19907 ++ unsigned int i;
19908 ++ __u16 num;
19909 ++ uid_t *uidlist;
19910 ++ int curuid;
19911 ++ int realok = 0;
19912 ++ int effectiveok = 0;
19913 ++ int fsok = 0;
19914 ++
19915 ++ if (unlikely(!(gr_status & GR_READY)))
19916 ++ return 0;
19917 ++
19918 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19919 ++ gr_log_learn_id_change(current, 'u', real, effective, fs);
19920 ++
19921 ++ num = current->acl->user_trans_num;
19922 ++ uidlist = current->acl->user_transitions;
19923 ++
19924 ++ if (uidlist == NULL)
19925 ++ return 0;
19926 ++
19927 ++ if (real == -1)
19928 ++ realok = 1;
19929 ++ if (effective == -1)
19930 ++ effectiveok = 1;
19931 ++ if (fs == -1)
19932 ++ fsok = 1;
19933 ++
19934 ++ if (current->acl->user_trans_type & GR_ID_ALLOW) {
19935 ++ for (i = 0; i < num; i++) {
19936 ++ curuid = (int)uidlist[i];
19937 ++ if (real == curuid)
19938 ++ realok = 1;
19939 ++ if (effective == curuid)
19940 ++ effectiveok = 1;
19941 ++ if (fs == curuid)
19942 ++ fsok = 1;
19943 ++ }
19944 ++ } else if (current->acl->user_trans_type & GR_ID_DENY) {
19945 ++ for (i = 0; i < num; i++) {
19946 ++ curuid = (int)uidlist[i];
19947 ++ if (real == curuid)
19948 ++ break;
19949 ++ if (effective == curuid)
19950 ++ break;
19951 ++ if (fs == curuid)
19952 ++ break;
19953 ++ }
19954 ++ /* not in deny list */
19955 ++ if (i == num) {
19956 ++ realok = 1;
19957 ++ effectiveok = 1;
19958 ++ fsok = 1;
19959 ++ }
19960 ++ }
19961 ++
19962 ++ if (realok && effectiveok && fsok)
19963 ++ return 0;
19964 ++ else {
19965 ++ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
19966 ++ return 1;
19967 ++ }
19968 ++}
19969 ++
19970 ++int
19971 ++gr_check_group_change(int real, int effective, int fs)
19972 ++{
19973 ++ unsigned int i;
19974 ++ __u16 num;
19975 ++ gid_t *gidlist;
19976 ++ int curgid;
19977 ++ int realok = 0;
19978 ++ int effectiveok = 0;
19979 ++ int fsok = 0;
19980 ++
19981 ++ if (unlikely(!(gr_status & GR_READY)))
19982 ++ return 0;
19983 ++
19984 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19985 ++ gr_log_learn_id_change(current, 'g', real, effective, fs);
19986 ++
19987 ++ num = current->acl->group_trans_num;
19988 ++ gidlist = current->acl->group_transitions;
19989 ++
19990 ++ if (gidlist == NULL)
19991 ++ return 0;
19992 ++
19993 ++ if (real == -1)
19994 ++ realok = 1;
19995 ++ if (effective == -1)
19996 ++ effectiveok = 1;
19997 ++ if (fs == -1)
19998 ++ fsok = 1;
19999 ++
20000 ++ if (current->acl->group_trans_type & GR_ID_ALLOW) {
20001 ++ for (i = 0; i < num; i++) {
20002 ++ curgid = (int)gidlist[i];
20003 ++ if (real == curgid)
20004 ++ realok = 1;
20005 ++ if (effective == curgid)
20006 ++ effectiveok = 1;
20007 ++ if (fs == curgid)
20008 ++ fsok = 1;
20009 ++ }
20010 ++ } else if (current->acl->group_trans_type & GR_ID_DENY) {
20011 ++ for (i = 0; i < num; i++) {
20012 ++ curgid = (int)gidlist[i];
20013 ++ if (real == curgid)
20014 ++ break;
20015 ++ if (effective == curgid)
20016 ++ break;
20017 ++ if (fs == curgid)
20018 ++ break;
20019 ++ }
20020 ++ /* not in deny list */
20021 ++ if (i == num) {
20022 ++ realok = 1;
20023 ++ effectiveok = 1;
20024 ++ fsok = 1;
20025 ++ }
20026 ++ }
20027 ++
20028 ++ if (realok && effectiveok && fsok)
20029 ++ return 0;
20030 ++ else {
20031 ++ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
20032 ++ return 1;
20033 ++ }
20034 ++}
20035 ++
20036 ++void
20037 ++gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
20038 ++{
20039 ++ struct acl_role_label *role = task->role;
20040 ++ struct acl_subject_label *subj = NULL;
20041 ++ struct acl_object_label *obj;
20042 ++ struct file *filp;
20043 ++
20044 ++ if (unlikely(!(gr_status & GR_READY)))
20045 ++ return;
20046 ++
20047 ++ filp = task->exec_file;
20048 ++
20049 ++ /* kernel process, we'll give them the kernel role */
20050 ++ if (unlikely(!filp)) {
20051 ++ task->role = kernel_role;
20052 ++ task->acl = kernel_role->root_label;
20053 ++ return;
20054 ++ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
20055 ++ role = lookup_acl_role_label(task, uid, gid);
20056 ++
20057 ++ /* perform subject lookup in possibly new role
20058 ++ we can use this result below in the case where role == task->role
20059 ++ */
20060 ++ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
20061 ++
20062 ++ /* if we changed uid/gid, but result in the same role
20063 ++ and are using inheritance, don't lose the inherited subject
20064 ++ if current subject is other than what normal lookup
20065 ++ would result in, we arrived via inheritance, don't
20066 ++ lose subject
20067 ++ */
20068 ++ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
20069 ++ (subj == task->acl)))
20070 ++ task->acl = subj;
20071 ++
20072 ++ task->role = role;
20073 ++
20074 ++ task->is_writable = 0;
20075 ++
20076 ++ /* ignore additional mmap checks for processes that are writable
20077 ++ by the default ACL */
20078 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20079 ++ if (unlikely(obj->mode & GR_WRITE))
20080 ++ task->is_writable = 1;
20081 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
20082 ++ if (unlikely(obj->mode & GR_WRITE))
20083 ++ task->is_writable = 1;
20084 ++
20085 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20086 ++ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20087 ++#endif
20088 ++
20089 ++ gr_set_proc_res(task);
20090 ++
20091 ++ return;
20092 ++}
20093 ++
20094 ++int
20095 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
20096 ++{
20097 ++ struct task_struct *task = current;
20098 ++ struct acl_subject_label *newacl;
20099 ++ struct acl_object_label *obj;
20100 ++ __u32 retmode;
20101 ++
20102 ++ if (unlikely(!(gr_status & GR_READY)))
20103 ++ return 0;
20104 ++
20105 ++ newacl = chk_subj_label(dentry, mnt, task->role);
20106 ++
20107 ++ task_lock(task);
20108 ++ if (((task->ptrace & PT_PTRACED) && !(task->acl->mode &
20109 ++ GR_POVERRIDE) && (task->acl != newacl) &&
20110 ++ !(task->role->roletype & GR_ROLE_GOD) &&
20111 ++ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
20112 ++ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) ||
20113 ++ (atomic_read(&task->fs->count) > 1 ||
20114 ++ atomic_read(&task->files->count) > 1 ||
20115 ++ atomic_read(&task->sighand->count) > 1)) {
20116 ++ task_unlock(task);
20117 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
20118 ++ return -EACCES;
20119 ++ }
20120 ++ task_unlock(task);
20121 ++
20122 ++ obj = chk_obj_label(dentry, mnt, task->acl);
20123 ++ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
20124 ++
20125 ++ if (!(task->acl->mode & GR_INHERITLEARN) &&
20126 ++ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
20127 ++ if (obj->nested)
20128 ++ task->acl = obj->nested;
20129 ++ else
20130 ++ task->acl = newacl;
20131 ++ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
20132 ++ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
20133 ++
20134 ++ task->is_writable = 0;
20135 ++
20136 ++ /* ignore additional mmap checks for processes that are writable
20137 ++ by the default ACL */
20138 ++ obj = chk_obj_label(dentry, mnt, default_role->root_label);
20139 ++ if (unlikely(obj->mode & GR_WRITE))
20140 ++ task->is_writable = 1;
20141 ++ obj = chk_obj_label(dentry, mnt, task->role->root_label);
20142 ++ if (unlikely(obj->mode & GR_WRITE))
20143 ++ task->is_writable = 1;
20144 ++
20145 ++ gr_set_proc_res(task);
20146 ++
20147 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20148 ++ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20149 ++#endif
20150 ++ return 0;
20151 ++}
20152 ++
20153 ++/* always called with valid inodev ptr */
20154 ++static void
20155 ++do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
20156 ++{
20157 ++ struct acl_object_label *matchpo;
20158 ++ struct acl_subject_label *matchps;
20159 ++ struct acl_subject_label *subj;
20160 ++ struct acl_role_label *role;
20161 ++ unsigned int i, x;
20162 ++
20163 ++ FOR_EACH_ROLE_START(role, i)
20164 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20165 ++ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
20166 ++ matchpo->mode |= GR_DELETED;
20167 ++ FOR_EACH_SUBJECT_END(subj,x)
20168 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20169 ++ if (subj->inode == ino && subj->device == dev)
20170 ++ subj->mode |= GR_DELETED;
20171 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20172 ++ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
20173 ++ matchps->mode |= GR_DELETED;
20174 ++ FOR_EACH_ROLE_END(role,i)
20175 ++
20176 ++ inodev->nentry->deleted = 1;
20177 ++
20178 ++ return;
20179 ++}
20180 ++
20181 ++void
20182 ++gr_handle_delete(const ino_t ino, const dev_t dev)
20183 ++{
20184 ++ struct inodev_entry *inodev;
20185 ++
20186 ++ if (unlikely(!(gr_status & GR_READY)))
20187 ++ return;
20188 ++
20189 ++ write_lock(&gr_inode_lock);
20190 ++ inodev = lookup_inodev_entry(ino, dev);
20191 ++ if (inodev != NULL)
20192 ++ do_handle_delete(inodev, ino, dev);
20193 ++ write_unlock(&gr_inode_lock);
20194 ++
20195 ++ return;
20196 ++}
20197 ++
20198 ++static void
20199 ++update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
20200 ++ const ino_t newinode, const dev_t newdevice,
20201 ++ struct acl_subject_label *subj)
20202 ++{
20203 ++ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
20204 ++ struct acl_object_label *match;
20205 ++
20206 ++ match = subj->obj_hash[index];
20207 ++
20208 ++ while (match && (match->inode != oldinode ||
20209 ++ match->device != olddevice ||
20210 ++ !(match->mode & GR_DELETED)))
20211 ++ match = match->next;
20212 ++
20213 ++ if (match && (match->inode == oldinode)
20214 ++ && (match->device == olddevice)
20215 ++ && (match->mode & GR_DELETED)) {
20216 ++ if (match->prev == NULL) {
20217 ++ subj->obj_hash[index] = match->next;
20218 ++ if (match->next != NULL)
20219 ++ match->next->prev = NULL;
20220 ++ } else {
20221 ++ match->prev->next = match->next;
20222 ++ if (match->next != NULL)
20223 ++ match->next->prev = match->prev;
20224 ++ }
20225 ++ match->prev = NULL;
20226 ++ match->next = NULL;
20227 ++ match->inode = newinode;
20228 ++ match->device = newdevice;
20229 ++ match->mode &= ~GR_DELETED;
20230 ++
20231 ++ insert_acl_obj_label(match, subj);
20232 ++ }
20233 ++
20234 ++ return;
20235 ++}
20236 ++
20237 ++static void
20238 ++update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
20239 ++ const ino_t newinode, const dev_t newdevice,
20240 ++ struct acl_role_label *role)
20241 ++{
20242 ++ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
20243 ++ struct acl_subject_label *match;
20244 ++
20245 ++ match = role->subj_hash[index];
20246 ++
20247 ++ while (match && (match->inode != oldinode ||
20248 ++ match->device != olddevice ||
20249 ++ !(match->mode & GR_DELETED)))
20250 ++ match = match->next;
20251 ++
20252 ++ if (match && (match->inode == oldinode)
20253 ++ && (match->device == olddevice)
20254 ++ && (match->mode & GR_DELETED)) {
20255 ++ if (match->prev == NULL) {
20256 ++ role->subj_hash[index] = match->next;
20257 ++ if (match->next != NULL)
20258 ++ match->next->prev = NULL;
20259 ++ } else {
20260 ++ match->prev->next = match->next;
20261 ++ if (match->next != NULL)
20262 ++ match->next->prev = match->prev;
20263 ++ }
20264 ++ match->prev = NULL;
20265 ++ match->next = NULL;
20266 ++ match->inode = newinode;
20267 ++ match->device = newdevice;
20268 ++ match->mode &= ~GR_DELETED;
20269 ++
20270 ++ insert_acl_subj_label(match, role);
20271 ++ }
20272 ++
20273 ++ return;
20274 ++}
20275 ++
20276 ++static void
20277 ++update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
20278 ++ const ino_t newinode, const dev_t newdevice)
20279 ++{
20280 ++ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
20281 ++ struct inodev_entry *match;
20282 ++
20283 ++ match = inodev_set.i_hash[index];
20284 ++
20285 ++ while (match && (match->nentry->inode != oldinode ||
20286 ++ match->nentry->device != olddevice || !match->nentry->deleted))
20287 ++ match = match->next;
20288 ++
20289 ++ if (match && (match->nentry->inode == oldinode)
20290 ++ && (match->nentry->device == olddevice) &&
20291 ++ match->nentry->deleted) {
20292 ++ if (match->prev == NULL) {
20293 ++ inodev_set.i_hash[index] = match->next;
20294 ++ if (match->next != NULL)
20295 ++ match->next->prev = NULL;
20296 ++ } else {
20297 ++ match->prev->next = match->next;
20298 ++ if (match->next != NULL)
20299 ++ match->next->prev = match->prev;
20300 ++ }
20301 ++ match->prev = NULL;
20302 ++ match->next = NULL;
20303 ++ match->nentry->inode = newinode;
20304 ++ match->nentry->device = newdevice;
20305 ++ match->nentry->deleted = 0;
20306 ++
20307 ++ insert_inodev_entry(match);
20308 ++ }
20309 ++
20310 ++ return;
20311 ++}
20312 ++
20313 ++static void
20314 ++do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
20315 ++ const struct vfsmount *mnt)
20316 ++{
20317 ++ struct acl_subject_label *subj;
20318 ++ struct acl_role_label *role;
20319 ++ unsigned int i, x;
20320 ++
20321 ++ FOR_EACH_ROLE_START(role, i)
20322 ++ update_acl_subj_label(matchn->inode, matchn->device,
20323 ++ dentry->d_inode->i_ino,
20324 ++ dentry->d_inode->i_sb->s_dev, role);
20325 ++
20326 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20327 ++ if ((subj->inode == dentry->d_inode->i_ino) &&
20328 ++ (subj->device == dentry->d_inode->i_sb->s_dev)) {
20329 ++ subj->inode = dentry->d_inode->i_ino;
20330 ++ subj->device = dentry->d_inode->i_sb->s_dev;
20331 ++ }
20332 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20333 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20334 ++ update_acl_obj_label(matchn->inode, matchn->device,
20335 ++ dentry->d_inode->i_ino,
20336 ++ dentry->d_inode->i_sb->s_dev, subj);
20337 ++ FOR_EACH_SUBJECT_END(subj,x)
20338 ++ FOR_EACH_ROLE_END(role,i)
20339 ++
20340 ++ update_inodev_entry(matchn->inode, matchn->device,
20341 ++ dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
20342 ++
20343 ++ return;
20344 ++}
20345 ++
20346 ++void
20347 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
20348 ++{
20349 ++ struct name_entry *matchn;
20350 ++
20351 ++ if (unlikely(!(gr_status & GR_READY)))
20352 ++ return;
20353 ++
20354 ++ preempt_disable();
20355 ++ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
20356 ++
20357 ++ if (unlikely((unsigned long)matchn)) {
20358 ++ write_lock(&gr_inode_lock);
20359 ++ do_handle_create(matchn, dentry, mnt);
20360 ++ write_unlock(&gr_inode_lock);
20361 ++ }
20362 ++ preempt_enable();
20363 ++
20364 ++ return;
20365 ++}
20366 ++
20367 ++void
20368 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
20369 ++ struct dentry *old_dentry,
20370 ++ struct dentry *new_dentry,
20371 ++ struct vfsmount *mnt, const __u8 replace)
20372 ++{
20373 ++ struct name_entry *matchn;
20374 ++ struct inodev_entry *inodev;
20375 ++
20376 ++ /* vfs_rename swaps the name and parent link for old_dentry and
20377 ++ new_dentry
20378 ++ at this point, old_dentry has the new name, parent link, and inode
20379 ++ for the renamed file
20380 ++ if a file is being replaced by a rename, new_dentry has the inode
20381 ++ and name for the replaced file
20382 ++ */
20383 ++
20384 ++ if (unlikely(!(gr_status & GR_READY)))
20385 ++ return;
20386 ++
20387 ++ preempt_disable();
20388 ++ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
20389 ++
20390 ++ /* we wouldn't have to check d_inode if it weren't for
20391 ++ NFS silly-renaming
20392 ++ */
20393 ++
20394 ++ write_lock(&gr_inode_lock);
20395 ++ if (unlikely(replace && new_dentry->d_inode)) {
20396 ++ inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
20397 ++ new_dentry->d_inode->i_sb->s_dev);
20398 ++ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
20399 ++ do_handle_delete(inodev, new_dentry->d_inode->i_ino,
20400 ++ new_dentry->d_inode->i_sb->s_dev);
20401 ++ }
20402 ++
20403 ++ inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
20404 ++ old_dentry->d_inode->i_sb->s_dev);
20405 ++ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
20406 ++ do_handle_delete(inodev, old_dentry->d_inode->i_ino,
20407 ++ old_dentry->d_inode->i_sb->s_dev);
20408 ++
20409 ++ if (unlikely((unsigned long)matchn))
20410 ++ do_handle_create(matchn, old_dentry, mnt);
20411 ++
20412 ++ write_unlock(&gr_inode_lock);
20413 ++ preempt_enable();
20414 ++
20415 ++ return;
20416 ++}
20417 ++
20418 ++static int
20419 ++lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
20420 ++ unsigned char **sum)
20421 ++{
20422 ++ struct acl_role_label *r;
20423 ++ struct role_allowed_ip *ipp;
20424 ++ struct role_transition *trans;
20425 ++ unsigned int i;
20426 ++ int found = 0;
20427 ++
20428 ++ /* check transition table */
20429 ++
20430 ++ for (trans = current->role->transitions; trans; trans = trans->next) {
20431 ++ if (!strcmp(rolename, trans->rolename)) {
20432 ++ found = 1;
20433 ++ break;
20434 ++ }
20435 ++ }
20436 ++
20437 ++ if (!found)
20438 ++ return 0;
20439 ++
20440 ++ /* handle special roles that do not require authentication
20441 ++ and check ip */
20442 ++
20443 ++ FOR_EACH_ROLE_START(r, i)
20444 ++ if (!strcmp(rolename, r->rolename) &&
20445 ++ (r->roletype & GR_ROLE_SPECIAL)) {
20446 ++ found = 0;
20447 ++ if (r->allowed_ips != NULL) {
20448 ++ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
20449 ++ if ((ntohl(current->signal->curr_ip) & ipp->netmask) ==
20450 ++ (ntohl(ipp->addr) & ipp->netmask))
20451 ++ found = 1;
20452 ++ }
20453 ++ } else
20454 ++ found = 2;
20455 ++ if (!found)
20456 ++ return 0;
20457 ++
20458 ++ if (((mode == SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
20459 ++ ((mode == SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
20460 ++ *salt = NULL;
20461 ++ *sum = NULL;
20462 ++ return 1;
20463 ++ }
20464 ++ }
20465 ++ FOR_EACH_ROLE_END(r,i)
20466 ++
20467 ++ for (i = 0; i < num_sprole_pws; i++) {
20468 ++ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
20469 ++ *salt = acl_special_roles[i]->salt;
20470 ++ *sum = acl_special_roles[i]->sum;
20471 ++ return 1;
20472 ++ }
20473 ++ }
20474 ++
20475 ++ return 0;
20476 ++}
20477 ++
20478 ++static void
20479 ++assign_special_role(char *rolename)
20480 ++{
20481 ++ struct acl_object_label *obj;
20482 ++ struct acl_role_label *r;
20483 ++ struct acl_role_label *assigned = NULL;
20484 ++ struct task_struct *tsk;
20485 ++ struct file *filp;
20486 ++ unsigned int i;
20487 ++
20488 ++ FOR_EACH_ROLE_START(r, i)
20489 ++ if (!strcmp(rolename, r->rolename) &&
20490 ++ (r->roletype & GR_ROLE_SPECIAL))
20491 ++ assigned = r;
20492 ++ FOR_EACH_ROLE_END(r,i)
20493 ++
20494 ++ if (!assigned)
20495 ++ return;
20496 ++
20497 ++ read_lock(&tasklist_lock);
20498 ++ read_lock(&grsec_exec_file_lock);
20499 ++
20500 ++ tsk = current->parent;
20501 ++ if (tsk == NULL)
20502 ++ goto out_unlock;
20503 ++
20504 ++ filp = tsk->exec_file;
20505 ++ if (filp == NULL)
20506 ++ goto out_unlock;
20507 ++
20508 ++ tsk->is_writable = 0;
20509 ++
20510 ++ tsk->acl_sp_role = 1;
20511 ++ tsk->acl_role_id = ++acl_sp_role_value;
20512 ++ tsk->role = assigned;
20513 ++ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
20514 ++
20515 ++ /* ignore additional mmap checks for processes that are writable
20516 ++ by the default ACL */
20517 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20518 ++ if (unlikely(obj->mode & GR_WRITE))
20519 ++ tsk->is_writable = 1;
20520 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
20521 ++ if (unlikely(obj->mode & GR_WRITE))
20522 ++ tsk->is_writable = 1;
20523 ++
20524 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20525 ++ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
20526 ++#endif
20527 ++
20528 ++out_unlock:
20529 ++ read_unlock(&grsec_exec_file_lock);
20530 ++ read_unlock(&tasklist_lock);
20531 ++ return;
20532 ++}
20533 ++
20534 ++int gr_check_secure_terminal(struct task_struct *task)
20535 ++{
20536 ++ struct task_struct *p, *p2, *p3;
20537 ++ struct files_struct *files;
20538 ++ struct fdtable *fdt;
20539 ++ struct file *our_file = NULL, *file;
20540 ++ int i;
20541 ++
20542 ++ if (task->signal->tty == NULL)
20543 ++ return 1;
20544 ++
20545 ++ files = get_files_struct(task);
20546 ++ if (files != NULL) {
20547 ++ rcu_read_lock();
20548 ++ fdt = files_fdtable(files);
20549 ++ for (i=0; i < fdt->max_fds; i++) {
20550 ++ file = fcheck_files(files, i);
20551 ++ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
20552 ++ get_file(file);
20553 ++ our_file = file;
20554 ++ }
20555 ++ }
20556 ++ rcu_read_unlock();
20557 ++ put_files_struct(files);
20558 ++ }
20559 ++
20560 ++ if (our_file == NULL)
20561 ++ return 1;
20562 ++
20563 ++ read_lock(&tasklist_lock);
20564 ++ do_each_thread(p2, p) {
20565 ++ files = get_files_struct(p);
20566 ++ if (files == NULL ||
20567 ++ (p->signal && p->signal->tty == task->signal->tty)) {
20568 ++ if (files != NULL)
20569 ++ put_files_struct(files);
20570 ++ continue;
20571 ++ }
20572 ++ rcu_read_lock();
20573 ++ fdt = files_fdtable(files);
20574 ++ for (i=0; i < fdt->max_fds; i++) {
20575 ++ file = fcheck_files(files, i);
20576 ++ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
20577 ++ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
20578 ++ p3 = task;
20579 ++ while (p3->pid > 0) {
20580 ++ if (p3 == p)
20581 ++ break;
20582 ++ p3 = p3->parent;
20583 ++ }
20584 ++ if (p3 == p)
20585 ++ break;
20586 ++ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
20587 ++ gr_handle_alertkill(p);
20588 ++ rcu_read_unlock();
20589 ++ put_files_struct(files);
20590 ++ read_unlock(&tasklist_lock);
20591 ++ fput(our_file);
20592 ++ return 0;
20593 ++ }
20594 ++ }
20595 ++ rcu_read_unlock();
20596 ++ put_files_struct(files);
20597 ++ } while_each_thread(p2, p);
20598 ++ read_unlock(&tasklist_lock);
20599 ++
20600 ++ fput(our_file);
20601 ++ return 1;
20602 ++}
20603 ++
20604 ++ssize_t
20605 ++write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
20606 ++{
20607 ++ struct gr_arg_wrapper uwrap;
20608 ++ unsigned char *sprole_salt;
20609 ++ unsigned char *sprole_sum;
20610 ++ int error = sizeof (struct gr_arg_wrapper);
20611 ++ int error2 = 0;
20612 ++
20613 ++ down(&gr_dev_sem);
20614 ++
20615 ++ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
20616 ++ error = -EPERM;
20617 ++ goto out;
20618 ++ }
20619 ++
20620 ++ if (count != sizeof (struct gr_arg_wrapper)) {
20621 ++ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
20622 ++ error = -EINVAL;
20623 ++ goto out;
20624 ++ }
20625 ++
20626 ++
20627 ++ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
20628 ++ gr_auth_expires = 0;
20629 ++ gr_auth_attempts = 0;
20630 ++ }
20631 ++
20632 ++ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
20633 ++ error = -EFAULT;
20634 ++ goto out;
20635 ++ }
20636 ++
20637 ++ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
20638 ++ error = -EINVAL;
20639 ++ goto out;
20640 ++ }
20641 ++
20642 ++ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
20643 ++ error = -EFAULT;
20644 ++ goto out;
20645 ++ }
20646 ++
20647 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != SPROLEPAM &&
20648 ++ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20649 ++ time_after(gr_auth_expires, get_seconds())) {
20650 ++ error = -EBUSY;
20651 ++ goto out;
20652 ++ }
20653 ++
20654 ++ /* if non-root trying to do anything other than use a special role,
20655 ++ do not attempt authentication, do not count towards authentication
20656 ++ locking
20657 ++ */
20658 ++
20659 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != STATUS &&
20660 ++ gr_usermode->mode != UNSPROLE && gr_usermode->mode != SPROLEPAM &&
20661 ++ current->uid) {
20662 ++ error = -EPERM;
20663 ++ goto out;
20664 ++ }
20665 ++
20666 ++ /* ensure pw and special role name are null terminated */
20667 ++
20668 ++ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
20669 ++ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
20670 ++
20671 ++ /* Okay.
20672 ++ * We have our enough of the argument structure..(we have yet
20673 ++ * to copy_from_user the tables themselves) . Copy the tables
20674 ++ * only if we need them, i.e. for loading operations. */
20675 ++
20676 ++ switch (gr_usermode->mode) {
20677 ++ case STATUS:
20678 ++ if (gr_status & GR_READY) {
20679 ++ error = 1;
20680 ++ if (!gr_check_secure_terminal(current))
20681 ++ error = 3;
20682 ++ } else
20683 ++ error = 2;
20684 ++ goto out;
20685 ++ case SHUTDOWN:
20686 ++ if ((gr_status & GR_READY)
20687 ++ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20688 ++ gr_status &= ~GR_READY;
20689 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
20690 ++ free_variables();
20691 ++ memset(gr_usermode, 0, sizeof (struct gr_arg));
20692 ++ memset(gr_system_salt, 0, GR_SALT_LEN);
20693 ++ memset(gr_system_sum, 0, GR_SHA_LEN);
20694 ++ } else if (gr_status & GR_READY) {
20695 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
20696 ++ error = -EPERM;
20697 ++ } else {
20698 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
20699 ++ error = -EAGAIN;
20700 ++ }
20701 ++ break;
20702 ++ case ENABLE:
20703 ++ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
20704 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
20705 ++ else {
20706 ++ if (gr_status & GR_READY)
20707 ++ error = -EAGAIN;
20708 ++ else
20709 ++ error = error2;
20710 ++ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
20711 ++ }
20712 ++ break;
20713 ++ case RELOAD:
20714 ++ if (!(gr_status & GR_READY)) {
20715 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
20716 ++ error = -EAGAIN;
20717 ++ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20718 ++ lock_kernel();
20719 ++ gr_status &= ~GR_READY;
20720 ++ free_variables();
20721 ++ if (!(error2 = gracl_init(gr_usermode))) {
20722 ++ unlock_kernel();
20723 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
20724 ++ } else {
20725 ++ unlock_kernel();
20726 ++ error = error2;
20727 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20728 ++ }
20729 ++ } else {
20730 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20731 ++ error = -EPERM;
20732 ++ }
20733 ++ break;
20734 ++ case SEGVMOD:
20735 ++ if (unlikely(!(gr_status & GR_READY))) {
20736 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
20737 ++ error = -EAGAIN;
20738 ++ break;
20739 ++ }
20740 ++
20741 ++ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20742 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
20743 ++ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
20744 ++ struct acl_subject_label *segvacl;
20745 ++ segvacl =
20746 ++ lookup_acl_subj_label(gr_usermode->segv_inode,
20747 ++ gr_usermode->segv_device,
20748 ++ current->role);
20749 ++ if (segvacl) {
20750 ++ segvacl->crashes = 0;
20751 ++ segvacl->expires = 0;
20752 ++ }
20753 ++ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
20754 ++ gr_remove_uid(gr_usermode->segv_uid);
20755 ++ }
20756 ++ } else {
20757 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
20758 ++ error = -EPERM;
20759 ++ }
20760 ++ break;
20761 ++ case SPROLE:
20762 ++ case SPROLEPAM:
20763 ++ if (unlikely(!(gr_status & GR_READY))) {
20764 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
20765 ++ error = -EAGAIN;
20766 ++ break;
20767 ++ }
20768 ++
20769 ++ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
20770 ++ current->role->expires = 0;
20771 ++ current->role->auth_attempts = 0;
20772 ++ }
20773 ++
20774 ++ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20775 ++ time_after(current->role->expires, get_seconds())) {
20776 ++ error = -EBUSY;
20777 ++ goto out;
20778 ++ }
20779 ++
20780 ++ if (lookup_special_role_auth
20781 ++ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
20782 ++ && ((!sprole_salt && !sprole_sum)
20783 ++ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
20784 ++ char *p = "";
20785 ++ assign_special_role(gr_usermode->sp_role);
20786 ++ read_lock(&tasklist_lock);
20787 ++ if (current->parent)
20788 ++ p = current->parent->role->rolename;
20789 ++ read_unlock(&tasklist_lock);
20790 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
20791 ++ p, acl_sp_role_value);
20792 ++ } else {
20793 ++ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
20794 ++ error = -EPERM;
20795 ++ if(!(current->role->auth_attempts++))
20796 ++ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20797 ++
20798 ++ goto out;
20799 ++ }
20800 ++ break;
20801 ++ case UNSPROLE:
20802 ++ if (unlikely(!(gr_status & GR_READY))) {
20803 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
20804 ++ error = -EAGAIN;
20805 ++ break;
20806 ++ }
20807 ++
20808 ++ if (current->role->roletype & GR_ROLE_SPECIAL) {
20809 ++ char *p = "";
20810 ++ int i = 0;
20811 ++
20812 ++ read_lock(&tasklist_lock);
20813 ++ if (current->parent) {
20814 ++ p = current->parent->role->rolename;
20815 ++ i = current->parent->acl_role_id;
20816 ++ }
20817 ++ read_unlock(&tasklist_lock);
20818 ++
20819 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
20820 ++ gr_set_acls(1);
20821 ++ } else {
20822 ++ gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename);
20823 ++ error = -EPERM;
20824 ++ goto out;
20825 ++ }
20826 ++ break;
20827 ++ default:
20828 ++ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
20829 ++ error = -EINVAL;
20830 ++ break;
20831 ++ }
20832 ++
20833 ++ if (error != -EPERM)
20834 ++ goto out;
20835 ++
20836 ++ if(!(gr_auth_attempts++))
20837 ++ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20838 ++
20839 ++ out:
20840 ++ up(&gr_dev_sem);
20841 ++ return error;
20842 ++}
20843 ++
20844 ++int
20845 ++gr_set_acls(const int type)
20846 ++{
20847 ++ struct acl_object_label *obj;
20848 ++ struct task_struct *task, *task2;
20849 ++ struct file *filp;
20850 ++ struct acl_role_label *role = current->role;
20851 ++ __u16 acl_role_id = current->acl_role_id;
20852 ++
20853 ++ read_lock(&tasklist_lock);
20854 ++ read_lock(&grsec_exec_file_lock);
20855 ++ do_each_thread(task2, task) {
20856 ++ /* check to see if we're called from the exit handler,
20857 ++ if so, only replace ACLs that have inherited the admin
20858 ++ ACL */
20859 ++
20860 ++ if (type && (task->role != role ||
20861 ++ task->acl_role_id != acl_role_id))
20862 ++ continue;
20863 ++
20864 ++ task->acl_role_id = 0;
20865 ++ task->acl_sp_role = 0;
20866 ++
20867 ++ if ((filp = task->exec_file)) {
20868 ++ task->role = lookup_acl_role_label(task, task->uid, task->gid);
20869 ++
20870 ++ task->acl =
20871 ++ chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
20872 ++ task->role);
20873 ++ if (task->acl) {
20874 ++ struct acl_subject_label *curr;
20875 ++ curr = task->acl;
20876 ++
20877 ++ task->is_writable = 0;
20878 ++ /* ignore additional mmap checks for processes that are writable
20879 ++ by the default ACL */
20880 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20881 ++ if (unlikely(obj->mode & GR_WRITE))
20882 ++ task->is_writable = 1;
20883 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
20884 ++ if (unlikely(obj->mode & GR_WRITE))
20885 ++ task->is_writable = 1;
20886 ++
20887 ++ gr_set_proc_res(task);
20888 ++
20889 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20890 ++ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20891 ++#endif
20892 ++ } else {
20893 ++ read_unlock(&grsec_exec_file_lock);
20894 ++ read_unlock(&tasklist_lock);
20895 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
20896 ++ return 1;
20897 ++ }
20898 ++ } else {
20899 ++ // it's a kernel process
20900 ++ task->role = kernel_role;
20901 ++ task->acl = kernel_role->root_label;
20902 ++#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
20903 ++ task->acl->mode &= ~GR_PROCFIND;
20904 ++#endif
20905 ++ }
20906 ++ } while_each_thread(task2, task);
20907 ++ read_unlock(&grsec_exec_file_lock);
20908 ++ read_unlock(&tasklist_lock);
20909 ++ return 0;
20910 ++}
20911 ++
20912 ++void
20913 ++gr_learn_resource(const struct task_struct *task,
20914 ++ const int res, const unsigned long wanted, const int gt)
20915 ++{
20916 ++ struct acl_subject_label *acl;
20917 ++
20918 ++ if (unlikely((gr_status & GR_READY) &&
20919 ++ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
20920 ++ goto skip_reslog;
20921 ++
20922 ++#ifdef CONFIG_GRKERNSEC_RESLOG
20923 ++ gr_log_resource(task, res, wanted, gt);
20924 ++#endif
20925 ++ skip_reslog:
20926 ++
20927 ++ if (unlikely(!(gr_status & GR_READY) || !wanted))
20928 ++ return;
20929 ++
20930 ++ acl = task->acl;
20931 ++
20932 ++ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
20933 ++ !(acl->resmask & (1 << (unsigned short) res))))
20934 ++ return;
20935 ++
20936 ++ if (wanted >= acl->res[res].rlim_cur) {
20937 ++ unsigned long res_add;
20938 ++
20939 ++ res_add = wanted;
20940 ++ switch (res) {
20941 ++ case RLIMIT_CPU:
20942 ++ res_add += GR_RLIM_CPU_BUMP;
20943 ++ break;
20944 ++ case RLIMIT_FSIZE:
20945 ++ res_add += GR_RLIM_FSIZE_BUMP;
20946 ++ break;
20947 ++ case RLIMIT_DATA:
20948 ++ res_add += GR_RLIM_DATA_BUMP;
20949 ++ break;
20950 ++ case RLIMIT_STACK:
20951 ++ res_add += GR_RLIM_STACK_BUMP;
20952 ++ break;
20953 ++ case RLIMIT_CORE:
20954 ++ res_add += GR_RLIM_CORE_BUMP;
20955 ++ break;
20956 ++ case RLIMIT_RSS:
20957 ++ res_add += GR_RLIM_RSS_BUMP;
20958 ++ break;
20959 ++ case RLIMIT_NPROC:
20960 ++ res_add += GR_RLIM_NPROC_BUMP;
20961 ++ break;
20962 ++ case RLIMIT_NOFILE:
20963 ++ res_add += GR_RLIM_NOFILE_BUMP;
20964 ++ break;
20965 ++ case RLIMIT_MEMLOCK:
20966 ++ res_add += GR_RLIM_MEMLOCK_BUMP;
20967 ++ break;
20968 ++ case RLIMIT_AS:
20969 ++ res_add += GR_RLIM_AS_BUMP;
20970 ++ break;
20971 ++ case RLIMIT_LOCKS:
20972 ++ res_add += GR_RLIM_LOCKS_BUMP;
20973 ++ break;
20974 ++ }
20975 ++
20976 ++ acl->res[res].rlim_cur = res_add;
20977 ++
20978 ++ if (wanted > acl->res[res].rlim_max)
20979 ++ acl->res[res].rlim_max = res_add;
20980 ++
20981 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
20982 ++ task->role->roletype, acl->filename,
20983 ++ acl->res[res].rlim_cur, acl->res[res].rlim_max,
20984 ++ "", (unsigned long) res);
20985 ++ }
20986 ++
20987 ++ return;
20988 ++}
20989 ++
20990 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
20991 ++void
20992 ++pax_set_initial_flags(struct linux_binprm *bprm)
20993 ++{
20994 ++ struct task_struct *task = current;
20995 ++ struct acl_subject_label *proc;
20996 ++ unsigned long flags;
20997 ++
20998 ++ if (unlikely(!(gr_status & GR_READY)))
20999 ++ return;
21000 ++
21001 ++ flags = pax_get_flags(task);
21002 ++
21003 ++ proc = task->acl;
21004 ++
21005 ++ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
21006 ++ flags &= ~MF_PAX_PAGEEXEC;
21007 ++ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
21008 ++ flags &= ~MF_PAX_SEGMEXEC;
21009 ++ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
21010 ++ flags &= ~MF_PAX_RANDMMAP;
21011 ++ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
21012 ++ flags &= ~MF_PAX_EMUTRAMP;
21013 ++ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
21014 ++ flags &= ~MF_PAX_MPROTECT;
21015 ++
21016 ++ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
21017 ++ flags |= MF_PAX_PAGEEXEC;
21018 ++ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
21019 ++ flags |= MF_PAX_SEGMEXEC;
21020 ++ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
21021 ++ flags |= MF_PAX_RANDMMAP;
21022 ++ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
21023 ++ flags |= MF_PAX_EMUTRAMP;
21024 ++ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
21025 ++ flags |= MF_PAX_MPROTECT;
21026 ++
21027 ++ pax_set_flags(task, flags);
21028 ++
21029 ++ return;
21030 ++}
21031 ++#endif
21032 ++
21033 ++#ifdef CONFIG_SYSCTL
21034 ++/* Eric Biederman likes breaking userland ABI and every inode-based security
21035 ++ system to save 35kb of memory */
21036 ++
21037 ++/* we modify the passed in filename, but adjust it back before returning */
21038 ++static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
21039 ++{
21040 ++ struct name_entry *nmatch;
21041 ++ char *p, *lastp = NULL;
21042 ++ struct acl_object_label *obj = NULL, *tmp;
21043 ++ struct acl_subject_label *tmpsubj;
21044 ++ char c = '\0';
21045 ++
21046 ++ read_lock(&gr_inode_lock);
21047 ++
21048 ++ p = name + len - 1;
21049 ++ do {
21050 ++ nmatch = lookup_name_entry(name);
21051 ++ if (lastp != NULL)
21052 ++ *lastp = c;
21053 ++
21054 ++ if (nmatch == NULL)
21055 ++ goto next_component;
21056 ++ tmpsubj = current->acl;
21057 ++ do {
21058 ++ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
21059 ++ if (obj != NULL) {
21060 ++ tmp = obj->globbed;
21061 ++ while (tmp) {
21062 ++ if (!glob_match(tmp->filename, name)) {
21063 ++ obj = tmp;
21064 ++ goto found_obj;
21065 ++ }
21066 ++ tmp = tmp->next;
21067 ++ }
21068 ++ goto found_obj;
21069 ++ }
21070 ++ } while ((tmpsubj = tmpsubj->parent_subject));
21071 ++next_component:
21072 ++ /* end case */
21073 ++ if (p == name)
21074 ++ break;
21075 ++
21076 ++ while (*p != '/')
21077 ++ p--;
21078 ++ if (p == name)
21079 ++ lastp = p + 1;
21080 ++ else {
21081 ++ lastp = p;
21082 ++ p--;
21083 ++ }
21084 ++ c = *lastp;
21085 ++ *lastp = '\0';
21086 ++ } while (1);
21087 ++found_obj:
21088 ++ read_unlock(&gr_inode_lock);
21089 ++ /* obj returned will always be non-null */
21090 ++ return obj;
21091 ++}
21092 ++
21093 ++/* returns 0 when allowing, non-zero on error
21094 ++ op of 0 is used for readdir, so we don't log the names of hidden files
21095 ++*/
21096 ++__u32
21097 ++gr_handle_sysctl(const struct ctl_table *table, const int op)
21098 ++{
21099 ++ ctl_table *tmp;
21100 ++ const char *proc_sys = "/proc/sys";
21101 ++ char *path;
21102 ++ struct acl_object_label *obj;
21103 ++ unsigned short len = 0, pos = 0, depth = 0, i;
21104 ++ __u32 err = 0;
21105 ++ __u32 mode = 0;
21106 ++
21107 ++ if (unlikely(!(gr_status & GR_READY)))
21108 ++ return 0;
21109 ++
21110 ++ /* for now, ignore operations on non-sysctl entries if it's not a
21111 ++ readdir*/
21112 ++ if (table->child != NULL && op != 0)
21113 ++ return 0;
21114 ++
21115 ++ mode |= GR_FIND;
21116 ++ /* it's only a read if it's an entry, read on dirs is for readdir */
21117 ++ if (op & MAY_READ)
21118 ++ mode |= GR_READ;
21119 ++ if (op & MAY_WRITE)
21120 ++ mode |= GR_WRITE;
21121 ++
21122 ++ preempt_disable();
21123 ++
21124 ++ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
21125 ++
21126 ++ /* it's only a read/write if it's an actual entry, not a dir
21127 ++ (which are opened for readdir)
21128 ++ */
21129 ++
21130 ++ /* convert the requested sysctl entry into a pathname */
21131 ++
21132 ++ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21133 ++ len += strlen(tmp->procname);
21134 ++ len++;
21135 ++ depth++;
21136 ++ }
21137 ++
21138 ++ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
21139 ++ /* deny */
21140 ++ goto out;
21141 ++ }
21142 ++
21143 ++ memset(path, 0, PAGE_SIZE);
21144 ++
21145 ++ memcpy(path, proc_sys, strlen(proc_sys));
21146 ++
21147 ++ pos += strlen(proc_sys);
21148 ++
21149 ++ for (; depth > 0; depth--) {
21150 ++ path[pos] = '/';
21151 ++ pos++;
21152 ++ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21153 ++ if (depth == i) {
21154 ++ memcpy(path + pos, tmp->procname,
21155 ++ strlen(tmp->procname));
21156 ++ pos += strlen(tmp->procname);
21157 ++ }
21158 ++ i++;
21159 ++ }
21160 ++ }
21161 ++
21162 ++ obj = gr_lookup_by_name(path, pos);
21163 ++ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
21164 ++
21165 ++ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
21166 ++ ((err & mode) != mode))) {
21167 ++ __u32 new_mode = mode;
21168 ++
21169 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21170 ++
21171 ++ err = 0;
21172 ++ gr_log_learn_sysctl(current, path, new_mode);
21173 ++ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
21174 ++ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
21175 ++ err = -ENOENT;
21176 ++ } else if (!(err & GR_FIND)) {
21177 ++ err = -ENOENT;
21178 ++ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
21179 ++ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
21180 ++ path, (mode & GR_READ) ? " reading" : "",
21181 ++ (mode & GR_WRITE) ? " writing" : "");
21182 ++ err = -EACCES;
21183 ++ } else if ((err & mode) != mode) {
21184 ++ err = -EACCES;
21185 ++ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
21186 ++ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
21187 ++ path, (mode & GR_READ) ? " reading" : "",
21188 ++ (mode & GR_WRITE) ? " writing" : "");
21189 ++ err = 0;
21190 ++ } else
21191 ++ err = 0;
21192 ++
21193 ++ out:
21194 ++ preempt_enable();
21195 ++
21196 ++ return err;
21197 ++}
21198 ++#endif
21199 ++
21200 ++int
21201 ++gr_handle_proc_ptrace(struct task_struct *task)
21202 ++{
21203 ++ struct file *filp;
21204 ++ struct task_struct *tmp = task;
21205 ++ struct task_struct *curtemp = current;
21206 ++ __u32 retmode;
21207 ++
21208 ++ if (unlikely(!(gr_status & GR_READY)))
21209 ++ return 0;
21210 ++
21211 ++ read_lock(&tasklist_lock);
21212 ++ read_lock(&grsec_exec_file_lock);
21213 ++ filp = task->exec_file;
21214 ++
21215 ++ while (tmp->pid > 0) {
21216 ++ if (tmp == curtemp)
21217 ++ break;
21218 ++ tmp = tmp->parent;
21219 ++ }
21220 ++
21221 ++ if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) {
21222 ++ read_unlock(&grsec_exec_file_lock);
21223 ++ read_unlock(&tasklist_lock);
21224 ++ return 1;
21225 ++ }
21226 ++
21227 ++ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
21228 ++ read_unlock(&grsec_exec_file_lock);
21229 ++ read_unlock(&tasklist_lock);
21230 ++
21231 ++ if (retmode & GR_NOPTRACE)
21232 ++ return 1;
21233 ++
21234 ++ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
21235 ++ && (current->acl != task->acl || (current->acl != current->role->root_label
21236 ++ && current->pid != task->pid)))
21237 ++ return 1;
21238 ++
21239 ++ return 0;
21240 ++}
21241 ++
21242 ++int
21243 ++gr_handle_ptrace(struct task_struct *task, const long request)
21244 ++{
21245 ++ struct task_struct *tmp = task;
21246 ++ struct task_struct *curtemp = current;
21247 ++ __u32 retmode;
21248 ++
21249 ++ if (unlikely(!(gr_status & GR_READY)))
21250 ++ return 0;
21251 ++
21252 ++ read_lock(&tasklist_lock);
21253 ++ while (tmp->pid > 0) {
21254 ++ if (tmp == curtemp)
21255 ++ break;
21256 ++ tmp = tmp->parent;
21257 ++ }
21258 ++
21259 ++ if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) {
21260 ++ read_unlock(&tasklist_lock);
21261 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21262 ++ return 1;
21263 ++ }
21264 ++ read_unlock(&tasklist_lock);
21265 ++
21266 ++ read_lock(&grsec_exec_file_lock);
21267 ++ if (unlikely(!task->exec_file)) {
21268 ++ read_unlock(&grsec_exec_file_lock);
21269 ++ return 0;
21270 ++ }
21271 ++
21272 ++ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
21273 ++ read_unlock(&grsec_exec_file_lock);
21274 ++
21275 ++ if (retmode & GR_NOPTRACE) {
21276 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21277 ++ return 1;
21278 ++ }
21279 ++
21280 ++ if (retmode & GR_PTRACERD) {
21281 ++ switch (request) {
21282 ++ case PTRACE_POKETEXT:
21283 ++ case PTRACE_POKEDATA:
21284 ++ case PTRACE_POKEUSR:
21285 ++#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
21286 ++ case PTRACE_SETREGS:
21287 ++ case PTRACE_SETFPREGS:
21288 ++#endif
21289 ++#ifdef CONFIG_X86
21290 ++ case PTRACE_SETFPXREGS:
21291 ++#endif
21292 ++#ifdef CONFIG_ALTIVEC
21293 ++ case PTRACE_SETVRREGS:
21294 ++#endif
21295 ++ return 1;
21296 ++ default:
21297 ++ return 0;
21298 ++ }
21299 ++ } else if (!(current->acl->mode & GR_POVERRIDE) &&
21300 ++ !(current->role->roletype & GR_ROLE_GOD) &&
21301 ++ (current->acl != task->acl)) {
21302 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21303 ++ return 1;
21304 ++ }
21305 ++
21306 ++ return 0;
21307 ++}
21308 ++
21309 ++static int is_writable_mmap(const struct file *filp)
21310 ++{
21311 ++ struct task_struct *task = current;
21312 ++ struct acl_object_label *obj, *obj2;
21313 ++
21314 ++ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
21315 ++ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) {
21316 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
21317 ++ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
21318 ++ task->role->root_label);
21319 ++ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
21320 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
21321 ++ return 1;
21322 ++ }
21323 ++ }
21324 ++ return 0;
21325 ++}
21326 ++
21327 ++int
21328 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
21329 ++{
21330 ++ __u32 mode;
21331 ++
21332 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21333 ++ return 1;
21334 ++
21335 ++ if (is_writable_mmap(file))
21336 ++ return 0;
21337 ++
21338 ++ mode =
21339 ++ gr_search_file(file->f_path.dentry,
21340 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21341 ++ file->f_path.mnt);
21342 ++
21343 ++ if (!gr_tpe_allow(file))
21344 ++ return 0;
21345 ++
21346 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21347 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21348 ++ return 0;
21349 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21350 ++ return 0;
21351 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21352 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21353 ++ return 1;
21354 ++ }
21355 ++
21356 ++ return 1;
21357 ++}
21358 ++
21359 ++int
21360 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
21361 ++{
21362 ++ __u32 mode;
21363 ++
21364 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21365 ++ return 1;
21366 ++
21367 ++ if (is_writable_mmap(file))
21368 ++ return 0;
21369 ++
21370 ++ mode =
21371 ++ gr_search_file(file->f_path.dentry,
21372 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21373 ++ file->f_path.mnt);
21374 ++
21375 ++ if (!gr_tpe_allow(file))
21376 ++ return 0;
21377 ++
21378 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21379 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21380 ++ return 0;
21381 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21382 ++ return 0;
21383 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21384 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21385 ++ return 1;
21386 ++ }
21387 ++
21388 ++ return 1;
21389 ++}
21390 ++
21391 ++void
21392 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
21393 ++{
21394 ++ unsigned long runtime;
21395 ++ unsigned long cputime;
21396 ++ unsigned int wday, cday;
21397 ++ __u8 whr, chr;
21398 ++ __u8 wmin, cmin;
21399 ++ __u8 wsec, csec;
21400 ++ struct timespec timeval;
21401 ++
21402 ++ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
21403 ++ !(task->acl->mode & GR_PROCACCT)))
21404 ++ return;
21405 ++
21406 ++ do_posix_clock_monotonic_gettime(&timeval);
21407 ++ runtime = timeval.tv_sec - task->start_time.tv_sec;
21408 ++ wday = runtime / (3600 * 24);
21409 ++ runtime -= wday * (3600 * 24);
21410 ++ whr = runtime / 3600;
21411 ++ runtime -= whr * 3600;
21412 ++ wmin = runtime / 60;
21413 ++ runtime -= wmin * 60;
21414 ++ wsec = runtime;
21415 ++
21416 ++ cputime = (task->utime + task->stime) / HZ;
21417 ++ cday = cputime / (3600 * 24);
21418 ++ cputime -= cday * (3600 * 24);
21419 ++ chr = cputime / 3600;
21420 ++ cputime -= chr * 3600;
21421 ++ cmin = cputime / 60;
21422 ++ cputime -= cmin * 60;
21423 ++ csec = cputime;
21424 ++
21425 ++ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
21426 ++
21427 ++ return;
21428 ++}
21429 ++
21430 ++void gr_set_kernel_label(struct task_struct *task)
21431 ++{
21432 ++ if (gr_status & GR_READY) {
21433 ++ task->role = kernel_role;
21434 ++ task->acl = kernel_role->root_label;
21435 ++ }
21436 ++ return;
21437 ++}
21438 ++
21439 ++int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
21440 ++{
21441 ++ struct task_struct *task = current;
21442 ++ struct dentry *dentry = file->f_path.dentry;
21443 ++ struct vfsmount *mnt = file->f_path.mnt;
21444 ++ struct acl_object_label *obj, *tmp;
21445 ++ struct acl_subject_label *subj;
21446 ++ unsigned int bufsize;
21447 ++ int is_not_root;
21448 ++ char *path;
21449 ++
21450 ++ if (unlikely(!(gr_status & GR_READY)))
21451 ++ return 1;
21452 ++
21453 ++ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21454 ++ return 1;
21455 ++
21456 ++ /* ignore Eric Biederman */
21457 ++ if (IS_PRIVATE(dentry->d_inode))
21458 ++ return 1;
21459 ++
21460 ++ subj = task->acl;
21461 ++ do {
21462 ++ obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
21463 ++ if (obj != NULL)
21464 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21465 ++ } while ((subj = subj->parent_subject));
21466 ++
21467 ++ obj = chk_obj_label(dentry, mnt, task->acl);
21468 ++ if (obj->globbed == NULL)
21469 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21470 ++
21471 ++ is_not_root = ((obj->filename[0] == '/') &&
21472 ++ (obj->filename[1] == '\0')) ? 0 : 1;
21473 ++ bufsize = PAGE_SIZE - namelen - is_not_root;
21474 ++
21475 ++ /* check bufsize > PAGE_SIZE || bufsize == 0 */
21476 ++ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
21477 ++ return 1;
21478 ++
21479 ++ preempt_disable();
21480 ++ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
21481 ++ bufsize);
21482 ++
21483 ++ bufsize = strlen(path);
21484 ++
21485 ++ /* if base is "/", don't append an additional slash */
21486 ++ if (is_not_root)
21487 ++ *(path + bufsize) = '/';
21488 ++ memcpy(path + bufsize + is_not_root, name, namelen);
21489 ++ *(path + bufsize + namelen + is_not_root) = '\0';
21490 ++
21491 ++ tmp = obj->globbed;
21492 ++ while (tmp) {
21493 ++ if (!glob_match(tmp->filename, path)) {
21494 ++ preempt_enable();
21495 ++ return (tmp->mode & GR_FIND) ? 1 : 0;
21496 ++ }
21497 ++ tmp = tmp->next;
21498 ++ }
21499 ++ preempt_enable();
21500 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21501 ++}
21502 ++
21503 ++EXPORT_SYMBOL(gr_learn_resource);
21504 ++EXPORT_SYMBOL(gr_set_kernel_label);
21505 ++#ifdef CONFIG_SECURITY
21506 ++EXPORT_SYMBOL(gr_check_user_change);
21507 ++EXPORT_SYMBOL(gr_check_group_change);
21508 ++#endif
21509 ++
21510 +diff -urNp linux-2.6.27.10/grsecurity/gracl_cap.c linux-2.6.27.10/grsecurity/gracl_cap.c
21511 +--- linux-2.6.27.10/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
21512 ++++ linux-2.6.27.10/grsecurity/gracl_cap.c 2008-11-18 03:38:45.000000000 -0500
21513 +@@ -0,0 +1,129 @@
21514 ++#include <linux/kernel.h>
21515 ++#include <linux/module.h>
21516 ++#include <linux/sched.h>
21517 ++#include <linux/gracl.h>
21518 ++#include <linux/grsecurity.h>
21519 ++#include <linux/grinternal.h>
21520 ++
21521 ++static const char *captab_log[] = {
21522 ++ "CAP_CHOWN",
21523 ++ "CAP_DAC_OVERRIDE",
21524 ++ "CAP_DAC_READ_SEARCH",
21525 ++ "CAP_FOWNER",
21526 ++ "CAP_FSETID",
21527 ++ "CAP_KILL",
21528 ++ "CAP_SETGID",
21529 ++ "CAP_SETUID",
21530 ++ "CAP_SETPCAP",
21531 ++ "CAP_LINUX_IMMUTABLE",
21532 ++ "CAP_NET_BIND_SERVICE",
21533 ++ "CAP_NET_BROADCAST",
21534 ++ "CAP_NET_ADMIN",
21535 ++ "CAP_NET_RAW",
21536 ++ "CAP_IPC_LOCK",
21537 ++ "CAP_IPC_OWNER",
21538 ++ "CAP_SYS_MODULE",
21539 ++ "CAP_SYS_RAWIO",
21540 ++ "CAP_SYS_CHROOT",
21541 ++ "CAP_SYS_PTRACE",
21542 ++ "CAP_SYS_PACCT",
21543 ++ "CAP_SYS_ADMIN",
21544 ++ "CAP_SYS_BOOT",
21545 ++ "CAP_SYS_NICE",
21546 ++ "CAP_SYS_RESOURCE",
21547 ++ "CAP_SYS_TIME",
21548 ++ "CAP_SYS_TTY_CONFIG",
21549 ++ "CAP_MKNOD",
21550 ++ "CAP_LEASE",
21551 ++ "CAP_AUDIT_WRITE",
21552 ++ "CAP_AUDIT_CONTROL",
21553 ++ "CAP_SETFCAP",
21554 ++ "CAP_MAC_OVERRIDE",
21555 ++ "CAP_MAC_ADMIN"
21556 ++};
21557 ++
21558 ++EXPORT_SYMBOL(gr_task_is_capable);
21559 ++EXPORT_SYMBOL(gr_is_capable_nolog);
21560 ++
21561 ++int
21562 ++gr_task_is_capable(struct task_struct *task, const int cap)
21563 ++{
21564 ++ struct acl_subject_label *curracl;
21565 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21566 ++
21567 ++ if (!gr_acl_is_enabled())
21568 ++ return 1;
21569 ++
21570 ++ curracl = task->acl;
21571 ++
21572 ++ cap_drop = curracl->cap_lower;
21573 ++ cap_mask = curracl->cap_mask;
21574 ++
21575 ++ while ((curracl = curracl->parent_subject)) {
21576 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21577 ++ current level subject, and is lowered in the current level subject, then add
21578 ++ it to the set of dropped capabilities
21579 ++ otherwise, add the current level subject's mask to the current computed mask
21580 ++ */
21581 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21582 ++ cap_raise(cap_mask, cap);
21583 ++ if (cap_raised(curracl->cap_lower, cap))
21584 ++ cap_raise(cap_drop, cap);
21585 ++ }
21586 ++ }
21587 ++
21588 ++ if (!cap_raised(cap_drop, cap))
21589 ++ return 1;
21590 ++
21591 ++ curracl = task->acl;
21592 ++
21593 ++ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
21594 ++ && cap_raised(task->cap_effective, cap)) {
21595 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
21596 ++ task->role->roletype, task->uid,
21597 ++ task->gid, task->exec_file ?
21598 ++ gr_to_filename(task->exec_file->f_path.dentry,
21599 ++ task->exec_file->f_path.mnt) : curracl->filename,
21600 ++ curracl->filename, 0UL,
21601 ++ 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip));
21602 ++ return 1;
21603 ++ }
21604 ++
21605 ++ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(task->cap_effective, cap))
21606 ++ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
21607 ++ return 0;
21608 ++}
21609 ++
21610 ++int
21611 ++gr_is_capable_nolog(const int cap)
21612 ++{
21613 ++ struct acl_subject_label *curracl;
21614 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21615 ++
21616 ++ if (!gr_acl_is_enabled())
21617 ++ return 1;
21618 ++
21619 ++ curracl = current->acl;
21620 ++
21621 ++ cap_drop = curracl->cap_lower;
21622 ++ cap_mask = curracl->cap_mask;
21623 ++
21624 ++ while ((curracl = curracl->parent_subject)) {
21625 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21626 ++ current level subject, and is lowered in the current level subject, then add
21627 ++ it to the set of dropped capabilities
21628 ++ otherwise, add the current level subject's mask to the current computed mask
21629 ++ */
21630 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21631 ++ cap_raise(cap_mask, cap);
21632 ++ if (cap_raised(curracl->cap_lower, cap))
21633 ++ cap_raise(cap_drop, cap);
21634 ++ }
21635 ++ }
21636 ++
21637 ++ if (!cap_raised(cap_drop, cap))
21638 ++ return 1;
21639 ++
21640 ++ return 0;
21641 ++}
21642 ++
21643 +diff -urNp linux-2.6.27.10/grsecurity/gracl_fs.c linux-2.6.27.10/grsecurity/gracl_fs.c
21644 +--- linux-2.6.27.10/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
21645 ++++ linux-2.6.27.10/grsecurity/gracl_fs.c 2008-11-18 03:38:45.000000000 -0500
21646 +@@ -0,0 +1,423 @@
21647 ++#include <linux/kernel.h>
21648 ++#include <linux/sched.h>
21649 ++#include <linux/types.h>
21650 ++#include <linux/fs.h>
21651 ++#include <linux/file.h>
21652 ++#include <linux/stat.h>
21653 ++#include <linux/grsecurity.h>
21654 ++#include <linux/grinternal.h>
21655 ++#include <linux/gracl.h>
21656 ++
21657 ++__u32
21658 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
21659 ++ const struct vfsmount * mnt)
21660 ++{
21661 ++ __u32 mode;
21662 ++
21663 ++ if (unlikely(!dentry->d_inode))
21664 ++ return GR_FIND;
21665 ++
21666 ++ mode =
21667 ++ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
21668 ++
21669 ++ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
21670 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21671 ++ return mode;
21672 ++ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
21673 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21674 ++ return 0;
21675 ++ } else if (unlikely(!(mode & GR_FIND)))
21676 ++ return 0;
21677 ++
21678 ++ return GR_FIND;
21679 ++}
21680 ++
21681 ++__u32
21682 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
21683 ++ const int fmode)
21684 ++{
21685 ++ __u32 reqmode = GR_FIND;
21686 ++ __u32 mode;
21687 ++
21688 ++ if (unlikely(!dentry->d_inode))
21689 ++ return reqmode;
21690 ++
21691 ++ if (unlikely(fmode & O_APPEND))
21692 ++ reqmode |= GR_APPEND;
21693 ++ else if (unlikely(fmode & FMODE_WRITE))
21694 ++ reqmode |= GR_WRITE;
21695 ++ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21696 ++ reqmode |= GR_READ;
21697 ++
21698 ++ mode =
21699 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21700 ++ mnt);
21701 ++
21702 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21703 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21704 ++ reqmode & GR_READ ? " reading" : "",
21705 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21706 ++ GR_APPEND ? " appending" : "");
21707 ++ return reqmode;
21708 ++ } else
21709 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21710 ++ {
21711 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21712 ++ reqmode & GR_READ ? " reading" : "",
21713 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21714 ++ GR_APPEND ? " appending" : "");
21715 ++ return 0;
21716 ++ } else if (unlikely((mode & reqmode) != reqmode))
21717 ++ return 0;
21718 ++
21719 ++ return reqmode;
21720 ++}
21721 ++
21722 ++__u32
21723 ++gr_acl_handle_creat(const struct dentry * dentry,
21724 ++ const struct dentry * p_dentry,
21725 ++ const struct vfsmount * p_mnt, const int fmode,
21726 ++ const int imode)
21727 ++{
21728 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21729 ++ __u32 mode;
21730 ++
21731 ++ if (unlikely(fmode & O_APPEND))
21732 ++ reqmode |= GR_APPEND;
21733 ++ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21734 ++ reqmode |= GR_READ;
21735 ++ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
21736 ++ reqmode |= GR_SETID;
21737 ++
21738 ++ mode =
21739 ++ gr_check_create(dentry, p_dentry, p_mnt,
21740 ++ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21741 ++
21742 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21743 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21744 ++ reqmode & GR_READ ? " reading" : "",
21745 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21746 ++ GR_APPEND ? " appending" : "");
21747 ++ return reqmode;
21748 ++ } else
21749 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21750 ++ {
21751 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21752 ++ reqmode & GR_READ ? " reading" : "",
21753 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21754 ++ GR_APPEND ? " appending" : "");
21755 ++ return 0;
21756 ++ } else if (unlikely((mode & reqmode) != reqmode))
21757 ++ return 0;
21758 ++
21759 ++ return reqmode;
21760 ++}
21761 ++
21762 ++__u32
21763 ++gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
21764 ++ const int fmode)
21765 ++{
21766 ++ __u32 mode, reqmode = GR_FIND;
21767 ++
21768 ++ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
21769 ++ reqmode |= GR_EXEC;
21770 ++ if (fmode & S_IWOTH)
21771 ++ reqmode |= GR_WRITE;
21772 ++ if (fmode & S_IROTH)
21773 ++ reqmode |= GR_READ;
21774 ++
21775 ++ mode =
21776 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21777 ++ mnt);
21778 ++
21779 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21780 ++ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21781 ++ reqmode & GR_READ ? " reading" : "",
21782 ++ reqmode & GR_WRITE ? " writing" : "",
21783 ++ reqmode & GR_EXEC ? " executing" : "");
21784 ++ return reqmode;
21785 ++ } else
21786 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21787 ++ {
21788 ++ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21789 ++ reqmode & GR_READ ? " reading" : "",
21790 ++ reqmode & GR_WRITE ? " writing" : "",
21791 ++ reqmode & GR_EXEC ? " executing" : "");
21792 ++ return 0;
21793 ++ } else if (unlikely((mode & reqmode) != reqmode))
21794 ++ return 0;
21795 ++
21796 ++ return reqmode;
21797 ++}
21798 ++
21799 ++static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
21800 ++{
21801 ++ __u32 mode;
21802 ++
21803 ++ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
21804 ++
21805 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21806 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
21807 ++ return mode;
21808 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21809 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
21810 ++ return 0;
21811 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21812 ++ return 0;
21813 ++
21814 ++ return (reqmode);
21815 ++}
21816 ++
21817 ++__u32
21818 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
21819 ++{
21820 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
21821 ++}
21822 ++
21823 ++__u32
21824 ++gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
21825 ++{
21826 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
21827 ++}
21828 ++
21829 ++__u32
21830 ++gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
21831 ++{
21832 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
21833 ++}
21834 ++
21835 ++__u32
21836 ++gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
21837 ++{
21838 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
21839 ++}
21840 ++
21841 ++__u32
21842 ++gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
21843 ++ mode_t mode)
21844 ++{
21845 ++ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
21846 ++ return 1;
21847 ++
21848 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21849 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21850 ++ GR_FCHMOD_ACL_MSG);
21851 ++ } else {
21852 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
21853 ++ }
21854 ++}
21855 ++
21856 ++__u32
21857 ++gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
21858 ++ mode_t mode)
21859 ++{
21860 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21861 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21862 ++ GR_CHMOD_ACL_MSG);
21863 ++ } else {
21864 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
21865 ++ }
21866 ++}
21867 ++
21868 ++__u32
21869 ++gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
21870 ++{
21871 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
21872 ++}
21873 ++
21874 ++__u32
21875 ++gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
21876 ++{
21877 ++ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
21878 ++}
21879 ++
21880 ++__u32
21881 ++gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
21882 ++{
21883 ++ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
21884 ++ GR_UNIXCONNECT_ACL_MSG);
21885 ++}
21886 ++
21887 ++/* hardlinks require at minimum create permission,
21888 ++ any additional privilege required is based on the
21889 ++ privilege of the file being linked to
21890 ++*/
21891 ++__u32
21892 ++gr_acl_handle_link(const struct dentry * new_dentry,
21893 ++ const struct dentry * parent_dentry,
21894 ++ const struct vfsmount * parent_mnt,
21895 ++ const struct dentry * old_dentry,
21896 ++ const struct vfsmount * old_mnt, const char *to)
21897 ++{
21898 ++ __u32 mode;
21899 ++ __u32 needmode = GR_CREATE | GR_LINK;
21900 ++ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
21901 ++
21902 ++ mode =
21903 ++ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
21904 ++ old_mnt);
21905 ++
21906 ++ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
21907 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21908 ++ return mode;
21909 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21910 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21911 ++ return 0;
21912 ++ } else if (unlikely((mode & needmode) != needmode))
21913 ++ return 0;
21914 ++
21915 ++ return 1;
21916 ++}
21917 ++
21918 ++__u32
21919 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
21920 ++ const struct dentry * parent_dentry,
21921 ++ const struct vfsmount * parent_mnt, const char *from)
21922 ++{
21923 ++ __u32 needmode = GR_WRITE | GR_CREATE;
21924 ++ __u32 mode;
21925 ++
21926 ++ mode =
21927 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
21928 ++ GR_CREATE | GR_AUDIT_CREATE |
21929 ++ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
21930 ++
21931 ++ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
21932 ++ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21933 ++ return mode;
21934 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21935 ++ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21936 ++ return 0;
21937 ++ } else if (unlikely((mode & needmode) != needmode))
21938 ++ return 0;
21939 ++
21940 ++ return (GR_WRITE | GR_CREATE);
21941 ++}
21942 ++
21943 ++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)
21944 ++{
21945 ++ __u32 mode;
21946 ++
21947 ++ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21948 ++
21949 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21950 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
21951 ++ return mode;
21952 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21953 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
21954 ++ return 0;
21955 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21956 ++ return 0;
21957 ++
21958 ++ return (reqmode);
21959 ++}
21960 ++
21961 ++__u32
21962 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
21963 ++ const struct dentry * parent_dentry,
21964 ++ const struct vfsmount * parent_mnt,
21965 ++ const int mode)
21966 ++{
21967 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21968 ++ if (unlikely(mode & (S_ISUID | S_ISGID)))
21969 ++ reqmode |= GR_SETID;
21970 ++
21971 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21972 ++ reqmode, GR_MKNOD_ACL_MSG);
21973 ++}
21974 ++
21975 ++__u32
21976 ++gr_acl_handle_mkdir(const struct dentry *new_dentry,
21977 ++ const struct dentry *parent_dentry,
21978 ++ const struct vfsmount *parent_mnt)
21979 ++{
21980 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21981 ++ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
21982 ++}
21983 ++
21984 ++#define RENAME_CHECK_SUCCESS(old, new) \
21985 ++ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
21986 ++ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
21987 ++
21988 ++int
21989 ++gr_acl_handle_rename(struct dentry *new_dentry,
21990 ++ struct dentry *parent_dentry,
21991 ++ const struct vfsmount *parent_mnt,
21992 ++ struct dentry *old_dentry,
21993 ++ struct inode *old_parent_inode,
21994 ++ struct vfsmount *old_mnt, const char *newname)
21995 ++{
21996 ++ __u32 comp1, comp2;
21997 ++ int error = 0;
21998 ++
21999 ++ if (unlikely(!gr_acl_is_enabled()))
22000 ++ return 0;
22001 ++
22002 ++ if (!new_dentry->d_inode) {
22003 ++ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
22004 ++ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
22005 ++ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
22006 ++ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
22007 ++ GR_DELETE | GR_AUDIT_DELETE |
22008 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
22009 ++ GR_SUPPRESS, old_mnt);
22010 ++ } else {
22011 ++ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
22012 ++ GR_CREATE | GR_DELETE |
22013 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
22014 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
22015 ++ GR_SUPPRESS, parent_mnt);
22016 ++ comp2 =
22017 ++ gr_search_file(old_dentry,
22018 ++ GR_READ | GR_WRITE | GR_AUDIT_READ |
22019 ++ GR_DELETE | GR_AUDIT_DELETE |
22020 ++ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
22021 ++ }
22022 ++
22023 ++ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
22024 ++ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
22025 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
22026 ++ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
22027 ++ && !(comp2 & GR_SUPPRESS)) {
22028 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
22029 ++ error = -EACCES;
22030 ++ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
22031 ++ error = -EACCES;
22032 ++
22033 ++ return error;
22034 ++}
22035 ++
22036 ++void
22037 ++gr_acl_handle_exit(void)
22038 ++{
22039 ++ u16 id;
22040 ++ char *rolename;
22041 ++ struct file *exec_file;
22042 ++
22043 ++ if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
22044 ++ id = current->acl_role_id;
22045 ++ rolename = current->role->rolename;
22046 ++ gr_set_acls(1);
22047 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
22048 ++ }
22049 ++
22050 ++ write_lock(&grsec_exec_file_lock);
22051 ++ exec_file = current->exec_file;
22052 ++ current->exec_file = NULL;
22053 ++ write_unlock(&grsec_exec_file_lock);
22054 ++
22055 ++ if (exec_file)
22056 ++ fput(exec_file);
22057 ++}
22058 ++
22059 ++int
22060 ++gr_acl_handle_procpidmem(const struct task_struct *task)
22061 ++{
22062 ++ if (unlikely(!gr_acl_is_enabled()))
22063 ++ return 0;
22064 ++
22065 ++ if (task != current && task->acl->mode & GR_PROTPROCFD)
22066 ++ return -EACCES;
22067 ++
22068 ++ return 0;
22069 ++}
22070 +diff -urNp linux-2.6.27.10/grsecurity/gracl_ip.c linux-2.6.27.10/grsecurity/gracl_ip.c
22071 +--- linux-2.6.27.10/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
22072 ++++ linux-2.6.27.10/grsecurity/gracl_ip.c 2008-11-18 03:38:45.000000000 -0500
22073 +@@ -0,0 +1,313 @@
22074 ++#include <linux/kernel.h>
22075 ++#include <asm/uaccess.h>
22076 ++#include <asm/errno.h>
22077 ++#include <net/sock.h>
22078 ++#include <linux/file.h>
22079 ++#include <linux/fs.h>
22080 ++#include <linux/net.h>
22081 ++#include <linux/in.h>
22082 ++#include <linux/skbuff.h>
22083 ++#include <linux/ip.h>
22084 ++#include <linux/udp.h>
22085 ++#include <linux/smp_lock.h>
22086 ++#include <linux/types.h>
22087 ++#include <linux/sched.h>
22088 ++#include <linux/netdevice.h>
22089 ++#include <linux/inetdevice.h>
22090 ++#include <linux/gracl.h>
22091 ++#include <linux/grsecurity.h>
22092 ++#include <linux/grinternal.h>
22093 ++
22094 ++#define GR_BIND 0x01
22095 ++#define GR_CONNECT 0x02
22096 ++#define GR_INVERT 0x04
22097 ++
22098 ++static const char * gr_protocols[256] = {
22099 ++ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
22100 ++ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
22101 ++ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
22102 ++ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
22103 ++ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
22104 ++ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
22105 ++ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
22106 ++ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
22107 ++ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
22108 ++ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
22109 ++ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
22110 ++ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
22111 ++ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
22112 ++ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
22113 ++ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
22114 ++ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
22115 ++ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
22116 ++ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
22117 ++ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
22118 ++ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
22119 ++ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
22120 ++ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
22121 ++ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
22122 ++ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
22123 ++ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
22124 ++ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
22125 ++ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
22126 ++ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
22127 ++ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
22128 ++ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
22129 ++ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
22130 ++ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
22131 ++ };
22132 ++
22133 ++static const char * gr_socktypes[11] = {
22134 ++ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
22135 ++ "unknown:7", "unknown:8", "unknown:9", "packet"
22136 ++ };
22137 ++
22138 ++const char *
22139 ++gr_proto_to_name(unsigned char proto)
22140 ++{
22141 ++ return gr_protocols[proto];
22142 ++}
22143 ++
22144 ++const char *
22145 ++gr_socktype_to_name(unsigned char type)
22146 ++{
22147 ++ return gr_socktypes[type];
22148 ++}
22149 ++
22150 ++int
22151 ++gr_search_socket(const int domain, const int type, const int protocol)
22152 ++{
22153 ++ struct acl_subject_label *curr;
22154 ++
22155 ++ if (unlikely(!gr_acl_is_enabled()))
22156 ++ goto exit;
22157 ++
22158 ++ if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
22159 ++ || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
22160 ++ goto exit; // let the kernel handle it
22161 ++
22162 ++ curr = current->acl;
22163 ++
22164 ++ if (!curr->ips)
22165 ++ goto exit;
22166 ++
22167 ++ if ((curr->ip_type & (1 << type)) &&
22168 ++ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
22169 ++ goto exit;
22170 ++
22171 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22172 ++ /* we don't place acls on raw sockets , and sometimes
22173 ++ dgram/ip sockets are opened for ioctl and not
22174 ++ bind/connect, so we'll fake a bind learn log */
22175 ++ if (type == SOCK_RAW || type == SOCK_PACKET) {
22176 ++ __u32 fakeip = 0;
22177 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22178 ++ current->role->roletype, current->uid,
22179 ++ current->gid, current->exec_file ?
22180 ++ gr_to_filename(current->exec_file->f_path.dentry,
22181 ++ current->exec_file->f_path.mnt) :
22182 ++ curr->filename, curr->filename,
22183 ++ NIPQUAD(fakeip), 0, type,
22184 ++ protocol, GR_CONNECT,
22185 ++NIPQUAD(current->signal->curr_ip));
22186 ++ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
22187 ++ __u32 fakeip = 0;
22188 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22189 ++ current->role->roletype, current->uid,
22190 ++ current->gid, current->exec_file ?
22191 ++ gr_to_filename(current->exec_file->f_path.dentry,
22192 ++ current->exec_file->f_path.mnt) :
22193 ++ curr->filename, curr->filename,
22194 ++ NIPQUAD(fakeip), 0, type,
22195 ++ protocol, GR_BIND, NIPQUAD(current->signal->curr_ip));
22196 ++ }
22197 ++ /* we'll log when they use connect or bind */
22198 ++ goto exit;
22199 ++ }
22200 ++
22201 ++ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet",
22202 ++ gr_socktype_to_name(type), gr_proto_to_name(protocol));
22203 ++
22204 ++ return 0;
22205 ++ exit:
22206 ++ return 1;
22207 ++}
22208 ++
22209 ++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)
22210 ++{
22211 ++ if ((ip->mode & mode) &&
22212 ++ (ip_port >= ip->low) &&
22213 ++ (ip_port <= ip->high) &&
22214 ++ ((ntohl(ip_addr) & our_netmask) ==
22215 ++ (ntohl(our_addr) & our_netmask))
22216 ++ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
22217 ++ && (ip->type & (1 << type))) {
22218 ++ if (ip->mode & GR_INVERT)
22219 ++ return 2; // specifically denied
22220 ++ else
22221 ++ return 1; // allowed
22222 ++ }
22223 ++
22224 ++ return 0; // not specifically allowed, may continue parsing
22225 ++}
22226 ++
22227 ++static int
22228 ++gr_search_connectbind(const int mode, const struct sock *sk,
22229 ++ const struct sockaddr_in *addr, const int type)
22230 ++{
22231 ++ char iface[IFNAMSIZ] = {0};
22232 ++ struct acl_subject_label *curr;
22233 ++ struct acl_ip_label *ip;
22234 ++ struct net_device *dev;
22235 ++ struct in_device *idev;
22236 ++ unsigned long i;
22237 ++ int ret;
22238 ++ __u32 ip_addr = 0;
22239 ++ __u32 our_addr;
22240 ++ __u32 our_netmask;
22241 ++ char *p;
22242 ++ __u16 ip_port = 0;
22243 ++
22244 ++ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
22245 ++ return 1;
22246 ++
22247 ++ curr = current->acl;
22248 ++
22249 ++ if (!curr->ips)
22250 ++ return 1;
22251 ++
22252 ++ ip_addr = addr->sin_addr.s_addr;
22253 ++ ip_port = ntohs(addr->sin_port);
22254 ++
22255 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22256 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22257 ++ current->role->roletype, current->uid,
22258 ++ current->gid, current->exec_file ?
22259 ++ gr_to_filename(current->exec_file->f_path.dentry,
22260 ++ current->exec_file->f_path.mnt) :
22261 ++ curr->filename, curr->filename,
22262 ++ NIPQUAD(ip_addr), ip_port, type,
22263 ++ sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip));
22264 ++ return 1;
22265 ++ }
22266 ++
22267 ++ for (i = 0; i < curr->ip_num; i++) {
22268 ++ ip = *(curr->ips + i);
22269 ++ if (ip->iface != NULL) {
22270 ++ strncpy(iface, ip->iface, IFNAMSIZ - 1);
22271 ++ p = strchr(iface, ':');
22272 ++ if (p != NULL)
22273 ++ *p = '\0';
22274 ++ dev = dev_get_by_name(sock_net(sk), iface);
22275 ++ if (dev == NULL)
22276 ++ continue;
22277 ++ idev = in_dev_get(dev);
22278 ++ if (idev == NULL) {
22279 ++ dev_put(dev);
22280 ++ continue;
22281 ++ }
22282 ++ rcu_read_lock();
22283 ++ for_ifa(idev) {
22284 ++ if (!strcmp(ip->iface, ifa->ifa_label)) {
22285 ++ our_addr = ifa->ifa_address;
22286 ++ our_netmask = 0xffffffff;
22287 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22288 ++ if (ret == 1) {
22289 ++ rcu_read_unlock();
22290 ++ in_dev_put(idev);
22291 ++ dev_put(dev);
22292 ++ return 1;
22293 ++ } else if (ret == 2) {
22294 ++ rcu_read_unlock();
22295 ++ in_dev_put(idev);
22296 ++ dev_put(dev);
22297 ++ goto denied;
22298 ++ }
22299 ++ }
22300 ++ } endfor_ifa(idev);
22301 ++ rcu_read_unlock();
22302 ++ in_dev_put(idev);
22303 ++ dev_put(dev);
22304 ++ } else {
22305 ++ our_addr = ip->addr;
22306 ++ our_netmask = ip->netmask;
22307 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22308 ++ if (ret == 1)
22309 ++ return 1;
22310 ++ else if (ret == 2)
22311 ++ goto denied;
22312 ++ }
22313 ++ }
22314 ++
22315 ++denied:
22316 ++ if (mode == GR_BIND)
22317 ++ 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));
22318 ++ else if (mode == GR_CONNECT)
22319 ++ 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));
22320 ++
22321 ++ return 0;
22322 ++}
22323 ++
22324 ++int
22325 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
22326 ++{
22327 ++ return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
22328 ++}
22329 ++
22330 ++int
22331 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
22332 ++{
22333 ++ return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
22334 ++}
22335 ++
22336 ++int gr_search_listen(const struct socket *sock)
22337 ++{
22338 ++ struct sock *sk = sock->sk;
22339 ++ struct sockaddr_in addr;
22340 ++
22341 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22342 ++ addr.sin_port = inet_sk(sk)->sport;
22343 ++
22344 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22345 ++}
22346 ++
22347 ++int gr_search_accept(const struct socket *sock)
22348 ++{
22349 ++ struct sock *sk = sock->sk;
22350 ++ struct sockaddr_in addr;
22351 ++
22352 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22353 ++ addr.sin_port = inet_sk(sk)->sport;
22354 ++
22355 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22356 ++}
22357 ++
22358 ++int
22359 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
22360 ++{
22361 ++ if (addr)
22362 ++ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
22363 ++ else {
22364 ++ struct sockaddr_in sin;
22365 ++ const struct inet_sock *inet = inet_sk(sk);
22366 ++
22367 ++ sin.sin_addr.s_addr = inet->daddr;
22368 ++ sin.sin_port = inet->dport;
22369 ++
22370 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22371 ++ }
22372 ++}
22373 ++
22374 ++int
22375 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
22376 ++{
22377 ++ struct sockaddr_in sin;
22378 ++
22379 ++ if (unlikely(skb->len < sizeof (struct udphdr)))
22380 ++ return 1; // skip this packet
22381 ++
22382 ++ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
22383 ++ sin.sin_port = udp_hdr(skb)->source;
22384 ++
22385 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22386 ++}
22387 +diff -urNp linux-2.6.27.10/grsecurity/gracl_learn.c linux-2.6.27.10/grsecurity/gracl_learn.c
22388 +--- linux-2.6.27.10/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
22389 ++++ linux-2.6.27.10/grsecurity/gracl_learn.c 2008-11-18 03:38:45.000000000 -0500
22390 +@@ -0,0 +1,211 @@
22391 ++#include <linux/kernel.h>
22392 ++#include <linux/mm.h>
22393 ++#include <linux/sched.h>
22394 ++#include <linux/poll.h>
22395 ++#include <linux/smp_lock.h>
22396 ++#include <linux/string.h>
22397 ++#include <linux/file.h>
22398 ++#include <linux/types.h>
22399 ++#include <linux/vmalloc.h>
22400 ++#include <linux/grinternal.h>
22401 ++
22402 ++extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
22403 ++ size_t count, loff_t *ppos);
22404 ++extern int gr_acl_is_enabled(void);
22405 ++
22406 ++static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
22407 ++static int gr_learn_attached;
22408 ++
22409 ++/* use a 512k buffer */
22410 ++#define LEARN_BUFFER_SIZE (512 * 1024)
22411 ++
22412 ++static DEFINE_SPINLOCK(gr_learn_lock);
22413 ++static DECLARE_MUTEX(gr_learn_user_sem);
22414 ++
22415 ++/* we need to maintain two buffers, so that the kernel context of grlearn
22416 ++ uses a semaphore around the userspace copying, and the other kernel contexts
22417 ++ use a spinlock when copying into the buffer, since they cannot sleep
22418 ++*/
22419 ++static char *learn_buffer;
22420 ++static char *learn_buffer_user;
22421 ++static int learn_buffer_len;
22422 ++static int learn_buffer_user_len;
22423 ++
22424 ++static ssize_t
22425 ++read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
22426 ++{
22427 ++ DECLARE_WAITQUEUE(wait, current);
22428 ++ ssize_t retval = 0;
22429 ++
22430 ++ add_wait_queue(&learn_wait, &wait);
22431 ++ set_current_state(TASK_INTERRUPTIBLE);
22432 ++ do {
22433 ++ down(&gr_learn_user_sem);
22434 ++ spin_lock(&gr_learn_lock);
22435 ++ if (learn_buffer_len)
22436 ++ break;
22437 ++ spin_unlock(&gr_learn_lock);
22438 ++ up(&gr_learn_user_sem);
22439 ++ if (file->f_flags & O_NONBLOCK) {
22440 ++ retval = -EAGAIN;
22441 ++ goto out;
22442 ++ }
22443 ++ if (signal_pending(current)) {
22444 ++ retval = -ERESTARTSYS;
22445 ++ goto out;
22446 ++ }
22447 ++
22448 ++ schedule();
22449 ++ } while (1);
22450 ++
22451 ++ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
22452 ++ learn_buffer_user_len = learn_buffer_len;
22453 ++ retval = learn_buffer_len;
22454 ++ learn_buffer_len = 0;
22455 ++
22456 ++ spin_unlock(&gr_learn_lock);
22457 ++
22458 ++ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
22459 ++ retval = -EFAULT;
22460 ++
22461 ++ up(&gr_learn_user_sem);
22462 ++out:
22463 ++ set_current_state(TASK_RUNNING);
22464 ++ remove_wait_queue(&learn_wait, &wait);
22465 ++ return retval;
22466 ++}
22467 ++
22468 ++static unsigned int
22469 ++poll_learn(struct file * file, poll_table * wait)
22470 ++{
22471 ++ poll_wait(file, &learn_wait, wait);
22472 ++
22473 ++ if (learn_buffer_len)
22474 ++ return (POLLIN | POLLRDNORM);
22475 ++
22476 ++ return 0;
22477 ++}
22478 ++
22479 ++void
22480 ++gr_clear_learn_entries(void)
22481 ++{
22482 ++ char *tmp;
22483 ++
22484 ++ down(&gr_learn_user_sem);
22485 ++ if (learn_buffer != NULL) {
22486 ++ spin_lock(&gr_learn_lock);
22487 ++ tmp = learn_buffer;
22488 ++ learn_buffer = NULL;
22489 ++ spin_unlock(&gr_learn_lock);
22490 ++ vfree(learn_buffer);
22491 ++ }
22492 ++ if (learn_buffer_user != NULL) {
22493 ++ vfree(learn_buffer_user);
22494 ++ learn_buffer_user = NULL;
22495 ++ }
22496 ++ learn_buffer_len = 0;
22497 ++ up(&gr_learn_user_sem);
22498 ++
22499 ++ return;
22500 ++}
22501 ++
22502 ++void
22503 ++gr_add_learn_entry(const char *fmt, ...)
22504 ++{
22505 ++ va_list args;
22506 ++ unsigned int len;
22507 ++
22508 ++ if (!gr_learn_attached)
22509 ++ return;
22510 ++
22511 ++ spin_lock(&gr_learn_lock);
22512 ++
22513 ++ /* leave a gap at the end so we know when it's "full" but don't have to
22514 ++ compute the exact length of the string we're trying to append
22515 ++ */
22516 ++ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
22517 ++ spin_unlock(&gr_learn_lock);
22518 ++ wake_up_interruptible(&learn_wait);
22519 ++ return;
22520 ++ }
22521 ++ if (learn_buffer == NULL) {
22522 ++ spin_unlock(&gr_learn_lock);
22523 ++ return;
22524 ++ }
22525 ++
22526 ++ va_start(args, fmt);
22527 ++ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
22528 ++ va_end(args);
22529 ++
22530 ++ learn_buffer_len += len + 1;
22531 ++
22532 ++ spin_unlock(&gr_learn_lock);
22533 ++ wake_up_interruptible(&learn_wait);
22534 ++
22535 ++ return;
22536 ++}
22537 ++
22538 ++static int
22539 ++open_learn(struct inode *inode, struct file *file)
22540 ++{
22541 ++ if (file->f_mode & FMODE_READ && gr_learn_attached)
22542 ++ return -EBUSY;
22543 ++ if (file->f_mode & FMODE_READ) {
22544 ++ int retval = 0;
22545 ++ down(&gr_learn_user_sem);
22546 ++ if (learn_buffer == NULL)
22547 ++ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
22548 ++ if (learn_buffer_user == NULL)
22549 ++ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
22550 ++ if (learn_buffer == NULL) {
22551 ++ retval = -ENOMEM;
22552 ++ goto out_error;
22553 ++ }
22554 ++ if (learn_buffer_user == NULL) {
22555 ++ retval = -ENOMEM;
22556 ++ goto out_error;
22557 ++ }
22558 ++ learn_buffer_len = 0;
22559 ++ learn_buffer_user_len = 0;
22560 ++ gr_learn_attached = 1;
22561 ++out_error:
22562 ++ up(&gr_learn_user_sem);
22563 ++ return retval;
22564 ++ }
22565 ++ return 0;
22566 ++}
22567 ++
22568 ++static int
22569 ++close_learn(struct inode *inode, struct file *file)
22570 ++{
22571 ++ char *tmp;
22572 ++
22573 ++ if (file->f_mode & FMODE_READ) {
22574 ++ down(&gr_learn_user_sem);
22575 ++ if (learn_buffer != NULL) {
22576 ++ spin_lock(&gr_learn_lock);
22577 ++ tmp = learn_buffer;
22578 ++ learn_buffer = NULL;
22579 ++ spin_unlock(&gr_learn_lock);
22580 ++ vfree(tmp);
22581 ++ }
22582 ++ if (learn_buffer_user != NULL) {
22583 ++ vfree(learn_buffer_user);
22584 ++ learn_buffer_user = NULL;
22585 ++ }
22586 ++ learn_buffer_len = 0;
22587 ++ learn_buffer_user_len = 0;
22588 ++ gr_learn_attached = 0;
22589 ++ up(&gr_learn_user_sem);
22590 ++ }
22591 ++
22592 ++ return 0;
22593 ++}
22594 ++
22595 ++struct file_operations grsec_fops = {
22596 ++ .read = read_learn,
22597 ++ .write = write_grsec_handler,
22598 ++ .open = open_learn,
22599 ++ .release = close_learn,
22600 ++ .poll = poll_learn,
22601 ++};
22602 +diff -urNp linux-2.6.27.10/grsecurity/gracl_res.c linux-2.6.27.10/grsecurity/gracl_res.c
22603 +--- linux-2.6.27.10/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
22604 ++++ linux-2.6.27.10/grsecurity/gracl_res.c 2008-11-18 03:38:45.000000000 -0500
22605 +@@ -0,0 +1,45 @@
22606 ++#include <linux/kernel.h>
22607 ++#include <linux/sched.h>
22608 ++#include <linux/gracl.h>
22609 ++#include <linux/grinternal.h>
22610 ++
22611 ++static const char *restab_log[] = {
22612 ++ [RLIMIT_CPU] = "RLIMIT_CPU",
22613 ++ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
22614 ++ [RLIMIT_DATA] = "RLIMIT_DATA",
22615 ++ [RLIMIT_STACK] = "RLIMIT_STACK",
22616 ++ [RLIMIT_CORE] = "RLIMIT_CORE",
22617 ++ [RLIMIT_RSS] = "RLIMIT_RSS",
22618 ++ [RLIMIT_NPROC] = "RLIMIT_NPROC",
22619 ++ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
22620 ++ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
22621 ++ [RLIMIT_AS] = "RLIMIT_AS",
22622 ++ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
22623 ++ [RLIMIT_LOCKS + 1] = "RLIMIT_CRASH"
22624 ++};
22625 ++
22626 ++void
22627 ++gr_log_resource(const struct task_struct *task,
22628 ++ const int res, const unsigned long wanted, const int gt)
22629 ++{
22630 ++ if (res == RLIMIT_NPROC &&
22631 ++ (cap_raised(task->cap_effective, CAP_SYS_ADMIN) ||
22632 ++ cap_raised(task->cap_effective, CAP_SYS_RESOURCE)))
22633 ++ return;
22634 ++ else if (res == RLIMIT_MEMLOCK &&
22635 ++ cap_raised(task->cap_effective, CAP_IPC_LOCK))
22636 ++ return;
22637 ++
22638 ++ if (!gr_acl_is_enabled() && !grsec_resource_logging)
22639 ++ return;
22640 ++
22641 ++ preempt_disable();
22642 ++
22643 ++ if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) ||
22644 ++ (!gt && wanted >= task->signal->rlim[res].rlim_cur)) &&
22645 ++ task->signal->rlim[res].rlim_cur != RLIM_INFINITY))
22646 ++ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur);
22647 ++ preempt_enable_no_resched();
22648 ++
22649 ++ return;
22650 ++}
22651 +diff -urNp linux-2.6.27.10/grsecurity/gracl_segv.c linux-2.6.27.10/grsecurity/gracl_segv.c
22652 +--- linux-2.6.27.10/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
22653 ++++ linux-2.6.27.10/grsecurity/gracl_segv.c 2008-11-18 03:38:45.000000000 -0500
22654 +@@ -0,0 +1,304 @@
22655 ++#include <linux/kernel.h>
22656 ++#include <linux/mm.h>
22657 ++#include <asm/uaccess.h>
22658 ++#include <asm/errno.h>
22659 ++#include <asm/mman.h>
22660 ++#include <net/sock.h>
22661 ++#include <linux/file.h>
22662 ++#include <linux/fs.h>
22663 ++#include <linux/net.h>
22664 ++#include <linux/in.h>
22665 ++#include <linux/smp_lock.h>
22666 ++#include <linux/slab.h>
22667 ++#include <linux/types.h>
22668 ++#include <linux/sched.h>
22669 ++#include <linux/timer.h>
22670 ++#include <linux/gracl.h>
22671 ++#include <linux/grsecurity.h>
22672 ++#include <linux/grinternal.h>
22673 ++
22674 ++static struct crash_uid *uid_set;
22675 ++static unsigned short uid_used;
22676 ++static DEFINE_SPINLOCK(gr_uid_lock);
22677 ++extern rwlock_t gr_inode_lock;
22678 ++extern struct acl_subject_label *
22679 ++ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
22680 ++ struct acl_role_label *role);
22681 ++extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
22682 ++
22683 ++int
22684 ++gr_init_uidset(void)
22685 ++{
22686 ++ uid_set =
22687 ++ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
22688 ++ uid_used = 0;
22689 ++
22690 ++ return uid_set ? 1 : 0;
22691 ++}
22692 ++
22693 ++void
22694 ++gr_free_uidset(void)
22695 ++{
22696 ++ if (uid_set)
22697 ++ kfree(uid_set);
22698 ++
22699 ++ return;
22700 ++}
22701 ++
22702 ++int
22703 ++gr_find_uid(const uid_t uid)
22704 ++{
22705 ++ struct crash_uid *tmp = uid_set;
22706 ++ uid_t buid;
22707 ++ int low = 0, high = uid_used - 1, mid;
22708 ++
22709 ++ while (high >= low) {
22710 ++ mid = (low + high) >> 1;
22711 ++ buid = tmp[mid].uid;
22712 ++ if (buid == uid)
22713 ++ return mid;
22714 ++ if (buid > uid)
22715 ++ high = mid - 1;
22716 ++ if (buid < uid)
22717 ++ low = mid + 1;
22718 ++ }
22719 ++
22720 ++ return -1;
22721 ++}
22722 ++
22723 ++static __inline__ void
22724 ++gr_insertsort(void)
22725 ++{
22726 ++ unsigned short i, j;
22727 ++ struct crash_uid index;
22728 ++
22729 ++ for (i = 1; i < uid_used; i++) {
22730 ++ index = uid_set[i];
22731 ++ j = i;
22732 ++ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
22733 ++ uid_set[j] = uid_set[j - 1];
22734 ++ j--;
22735 ++ }
22736 ++ uid_set[j] = index;
22737 ++ }
22738 ++
22739 ++ return;
22740 ++}
22741 ++
22742 ++static __inline__ void
22743 ++gr_insert_uid(const uid_t uid, const unsigned long expires)
22744 ++{
22745 ++ int loc;
22746 ++
22747 ++ if (uid_used == GR_UIDTABLE_MAX)
22748 ++ return;
22749 ++
22750 ++ loc = gr_find_uid(uid);
22751 ++
22752 ++ if (loc >= 0) {
22753 ++ uid_set[loc].expires = expires;
22754 ++ return;
22755 ++ }
22756 ++
22757 ++ uid_set[uid_used].uid = uid;
22758 ++ uid_set[uid_used].expires = expires;
22759 ++ uid_used++;
22760 ++
22761 ++ gr_insertsort();
22762 ++
22763 ++ return;
22764 ++}
22765 ++
22766 ++void
22767 ++gr_remove_uid(const unsigned short loc)
22768 ++{
22769 ++ unsigned short i;
22770 ++
22771 ++ for (i = loc + 1; i < uid_used; i++)
22772 ++ uid_set[i - 1] = uid_set[i];
22773 ++
22774 ++ uid_used--;
22775 ++
22776 ++ return;
22777 ++}
22778 ++
22779 ++int
22780 ++gr_check_crash_uid(const uid_t uid)
22781 ++{
22782 ++ int loc;
22783 ++ int ret = 0;
22784 ++
22785 ++ if (unlikely(!gr_acl_is_enabled()))
22786 ++ return 0;
22787 ++
22788 ++ spin_lock(&gr_uid_lock);
22789 ++ loc = gr_find_uid(uid);
22790 ++
22791 ++ if (loc < 0)
22792 ++ goto out_unlock;
22793 ++
22794 ++ if (time_before_eq(uid_set[loc].expires, get_seconds()))
22795 ++ gr_remove_uid(loc);
22796 ++ else
22797 ++ ret = 1;
22798 ++
22799 ++out_unlock:
22800 ++ spin_unlock(&gr_uid_lock);
22801 ++ return ret;
22802 ++}
22803 ++
22804 ++static __inline__ int
22805 ++proc_is_setxid(const struct task_struct *task)
22806 ++{
22807 ++ if (task->uid != task->euid || task->uid != task->suid ||
22808 ++ task->uid != task->fsuid)
22809 ++ return 1;
22810 ++ if (task->gid != task->egid || task->gid != task->sgid ||
22811 ++ task->gid != task->fsgid)
22812 ++ return 1;
22813 ++
22814 ++ return 0;
22815 ++}
22816 ++static __inline__ int
22817 ++gr_fake_force_sig(int sig, struct task_struct *t)
22818 ++{
22819 ++ unsigned long int flags;
22820 ++ int ret, blocked, ignored;
22821 ++ struct k_sigaction *action;
22822 ++
22823 ++ spin_lock_irqsave(&t->sighand->siglock, flags);
22824 ++ action = &t->sighand->action[sig-1];
22825 ++ ignored = action->sa.sa_handler == SIG_IGN;
22826 ++ blocked = sigismember(&t->blocked, sig);
22827 ++ if (blocked || ignored) {
22828 ++ action->sa.sa_handler = SIG_DFL;
22829 ++ if (blocked) {
22830 ++ sigdelset(&t->blocked, sig);
22831 ++ recalc_sigpending_and_wake(t);
22832 ++ }
22833 ++ }
22834 ++ if (action->sa.sa_handler == SIG_DFL)
22835 ++ t->signal->flags &= ~SIGNAL_UNKILLABLE;
22836 ++ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
22837 ++
22838 ++ spin_unlock_irqrestore(&t->sighand->siglock, flags);
22839 ++
22840 ++ return ret;
22841 ++}
22842 ++
22843 ++void
22844 ++gr_handle_crash(struct task_struct *task, const int sig)
22845 ++{
22846 ++ struct acl_subject_label *curr;
22847 ++ struct acl_subject_label *curr2;
22848 ++ struct task_struct *tsk, *tsk2;
22849 ++
22850 ++ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
22851 ++ return;
22852 ++
22853 ++ if (unlikely(!gr_acl_is_enabled()))
22854 ++ return;
22855 ++
22856 ++ curr = task->acl;
22857 ++
22858 ++ if (!(curr->resmask & (1 << GR_CRASH_RES)))
22859 ++ return;
22860 ++
22861 ++ if (time_before_eq(curr->expires, get_seconds())) {
22862 ++ curr->expires = 0;
22863 ++ curr->crashes = 0;
22864 ++ }
22865 ++
22866 ++ curr->crashes++;
22867 ++
22868 ++ if (!curr->expires)
22869 ++ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
22870 ++
22871 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22872 ++ time_after(curr->expires, get_seconds())) {
22873 ++ if (task->uid && proc_is_setxid(task)) {
22874 ++ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22875 ++ spin_lock(&gr_uid_lock);
22876 ++ gr_insert_uid(task->uid, curr->expires);
22877 ++ spin_unlock(&gr_uid_lock);
22878 ++ curr->expires = 0;
22879 ++ curr->crashes = 0;
22880 ++ read_lock(&tasklist_lock);
22881 ++ do_each_thread(tsk2, tsk) {
22882 ++ if (tsk != task && tsk->uid == task->uid)
22883 ++ gr_fake_force_sig(SIGKILL, tsk);
22884 ++ } while_each_thread(tsk2, tsk);
22885 ++ read_unlock(&tasklist_lock);
22886 ++ } else {
22887 ++ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22888 ++ read_lock(&tasklist_lock);
22889 ++ do_each_thread(tsk2, tsk) {
22890 ++ if (likely(tsk != task)) {
22891 ++ curr2 = tsk->acl;
22892 ++
22893 ++ if (curr2->device == curr->device &&
22894 ++ curr2->inode == curr->inode)
22895 ++ gr_fake_force_sig(SIGKILL, tsk);
22896 ++ }
22897 ++ } while_each_thread(tsk2, tsk);
22898 ++ read_unlock(&tasklist_lock);
22899 ++ }
22900 ++ }
22901 ++
22902 ++ return;
22903 ++}
22904 ++
22905 ++int
22906 ++gr_check_crash_exec(const struct file *filp)
22907 ++{
22908 ++ struct acl_subject_label *curr;
22909 ++
22910 ++ if (unlikely(!gr_acl_is_enabled()))
22911 ++ return 0;
22912 ++
22913 ++ read_lock(&gr_inode_lock);
22914 ++ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
22915 ++ filp->f_path.dentry->d_inode->i_sb->s_dev,
22916 ++ current->role);
22917 ++ read_unlock(&gr_inode_lock);
22918 ++
22919 ++ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
22920 ++ (!curr->crashes && !curr->expires))
22921 ++ return 0;
22922 ++
22923 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22924 ++ time_after(curr->expires, get_seconds()))
22925 ++ return 1;
22926 ++ else if (time_before_eq(curr->expires, get_seconds())) {
22927 ++ curr->crashes = 0;
22928 ++ curr->expires = 0;
22929 ++ }
22930 ++
22931 ++ return 0;
22932 ++}
22933 ++
22934 ++void
22935 ++gr_handle_alertkill(struct task_struct *task)
22936 ++{
22937 ++ struct acl_subject_label *curracl;
22938 ++ __u32 curr_ip;
22939 ++ struct task_struct *p, *p2;
22940 ++
22941 ++ if (unlikely(!gr_acl_is_enabled()))
22942 ++ return;
22943 ++
22944 ++ curracl = task->acl;
22945 ++ curr_ip = task->signal->curr_ip;
22946 ++
22947 ++ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
22948 ++ read_lock(&tasklist_lock);
22949 ++ do_each_thread(p2, p) {
22950 ++ if (p->signal->curr_ip == curr_ip)
22951 ++ gr_fake_force_sig(SIGKILL, p);
22952 ++ } while_each_thread(p2, p);
22953 ++ read_unlock(&tasklist_lock);
22954 ++ } else if (curracl->mode & GR_KILLPROC)
22955 ++ gr_fake_force_sig(SIGKILL, task);
22956 ++
22957 ++ return;
22958 ++}
22959 +diff -urNp linux-2.6.27.10/grsecurity/gracl_shm.c linux-2.6.27.10/grsecurity/gracl_shm.c
22960 +--- linux-2.6.27.10/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
22961 ++++ linux-2.6.27.10/grsecurity/gracl_shm.c 2008-11-18 03:38:45.000000000 -0500
22962 +@@ -0,0 +1,33 @@
22963 ++#include <linux/kernel.h>
22964 ++#include <linux/mm.h>
22965 ++#include <linux/sched.h>
22966 ++#include <linux/file.h>
22967 ++#include <linux/ipc.h>
22968 ++#include <linux/gracl.h>
22969 ++#include <linux/grsecurity.h>
22970 ++#include <linux/grinternal.h>
22971 ++
22972 ++int
22973 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
22974 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
22975 ++{
22976 ++ struct task_struct *task;
22977 ++
22978 ++ if (!gr_acl_is_enabled())
22979 ++ return 1;
22980 ++
22981 ++ task = find_task_by_vpid(shm_cprid);
22982 ++
22983 ++ if (unlikely(!task))
22984 ++ task = find_task_by_vpid(shm_lapid);
22985 ++
22986 ++ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
22987 ++ (task->pid == shm_lapid)) &&
22988 ++ (task->acl->mode & GR_PROTSHM) &&
22989 ++ (task->acl != current->acl))) {
22990 ++ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
22991 ++ return 0;
22992 ++ }
22993 ++
22994 ++ return 1;
22995 ++}
22996 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chdir.c linux-2.6.27.10/grsecurity/grsec_chdir.c
22997 +--- linux-2.6.27.10/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
22998 ++++ linux-2.6.27.10/grsecurity/grsec_chdir.c 2008-11-18 03:38:45.000000000 -0500
22999 +@@ -0,0 +1,19 @@
23000 ++#include <linux/kernel.h>
23001 ++#include <linux/sched.h>
23002 ++#include <linux/fs.h>
23003 ++#include <linux/file.h>
23004 ++#include <linux/grsecurity.h>
23005 ++#include <linux/grinternal.h>
23006 ++
23007 ++void
23008 ++gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
23009 ++{
23010 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
23011 ++ if ((grsec_enable_chdir && grsec_enable_group &&
23012 ++ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
23013 ++ !grsec_enable_group)) {
23014 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
23015 ++ }
23016 ++#endif
23017 ++ return;
23018 ++}
23019 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chroot.c linux-2.6.27.10/grsecurity/grsec_chroot.c
23020 +--- linux-2.6.27.10/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
23021 ++++ linux-2.6.27.10/grsecurity/grsec_chroot.c 2008-11-18 03:38:45.000000000 -0500
23022 +@@ -0,0 +1,336 @@
23023 ++#include <linux/kernel.h>
23024 ++#include <linux/module.h>
23025 ++#include <linux/sched.h>
23026 ++#include <linux/file.h>
23027 ++#include <linux/fs.h>
23028 ++#include <linux/mount.h>
23029 ++#include <linux/types.h>
23030 ++#include <linux/pid_namespace.h>
23031 ++#include <linux/grsecurity.h>
23032 ++#include <linux/grinternal.h>
23033 ++
23034 ++int
23035 ++gr_handle_chroot_unix(const pid_t pid)
23036 ++{
23037 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
23038 ++ struct pid *spid = NULL;
23039 ++
23040 ++ if (unlikely(!grsec_enable_chroot_unix))
23041 ++ return 1;
23042 ++
23043 ++ if (likely(!proc_is_chrooted(current)))
23044 ++ return 1;
23045 ++
23046 ++ read_lock(&tasklist_lock);
23047 ++
23048 ++ spid = find_vpid(pid);
23049 ++ if (spid) {
23050 ++ struct task_struct *p;
23051 ++ p = pid_task(spid, PIDTYPE_PID);
23052 ++ task_lock(p);
23053 ++ if (unlikely(!have_same_root(current, p))) {
23054 ++ task_unlock(p);
23055 ++ read_unlock(&tasklist_lock);
23056 ++ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
23057 ++ return 0;
23058 ++ }
23059 ++ task_unlock(p);
23060 ++ }
23061 ++ read_unlock(&tasklist_lock);
23062 ++#endif
23063 ++ return 1;
23064 ++}
23065 ++
23066 ++int
23067 ++gr_handle_chroot_nice(void)
23068 ++{
23069 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
23070 ++ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
23071 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
23072 ++ return -EPERM;
23073 ++ }
23074 ++#endif
23075 ++ return 0;
23076 ++}
23077 ++
23078 ++int
23079 ++gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
23080 ++{
23081 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
23082 ++ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
23083 ++ && proc_is_chrooted(current)) {
23084 ++ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
23085 ++ return -EACCES;
23086 ++ }
23087 ++#endif
23088 ++ return 0;
23089 ++}
23090 ++
23091 ++int
23092 ++gr_handle_chroot_rawio(const struct inode *inode)
23093 ++{
23094 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23095 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
23096 ++ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
23097 ++ return 1;
23098 ++#endif
23099 ++ return 0;
23100 ++}
23101 ++
23102 ++int
23103 ++gr_pid_is_chrooted(struct task_struct *p)
23104 ++{
23105 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
23106 ++ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
23107 ++ return 0;
23108 ++
23109 ++ task_lock(p);
23110 ++ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
23111 ++ !have_same_root(current, p)) {
23112 ++ task_unlock(p);
23113 ++ return 1;
23114 ++ }
23115 ++ task_unlock(p);
23116 ++#endif
23117 ++ return 0;
23118 ++}
23119 ++
23120 ++EXPORT_SYMBOL(gr_pid_is_chrooted);
23121 ++
23122 ++#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
23123 ++int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
23124 ++{
23125 ++ struct dentry *dentry = (struct dentry *)u_dentry;
23126 ++ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
23127 ++ struct dentry *realroot;
23128 ++ struct vfsmount *realrootmnt;
23129 ++ struct dentry *currentroot;
23130 ++ struct vfsmount *currentmnt;
23131 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
23132 ++ int ret = 1;
23133 ++
23134 ++ read_lock(&reaper->fs->lock);
23135 ++ realrootmnt = mntget(reaper->fs->root.mnt);
23136 ++ realroot = dget(reaper->fs->root.dentry);
23137 ++ read_unlock(&reaper->fs->lock);
23138 ++
23139 ++ read_lock(&current->fs->lock);
23140 ++ currentmnt = mntget(current->fs->root.mnt);
23141 ++ currentroot = dget(current->fs->root.dentry);
23142 ++ read_unlock(&current->fs->lock);
23143 ++
23144 ++ spin_lock(&dcache_lock);
23145 ++ for (;;) {
23146 ++ if (unlikely((dentry == realroot && mnt == realrootmnt)
23147 ++ || (dentry == currentroot && mnt == currentmnt)))
23148 ++ break;
23149 ++ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
23150 ++ if (mnt->mnt_parent == mnt)
23151 ++ break;
23152 ++ dentry = mnt->mnt_mountpoint;
23153 ++ mnt = mnt->mnt_parent;
23154 ++ continue;
23155 ++ }
23156 ++ dentry = dentry->d_parent;
23157 ++ }
23158 ++ spin_unlock(&dcache_lock);
23159 ++
23160 ++ dput(currentroot);
23161 ++ mntput(currentmnt);
23162 ++
23163 ++ /* access is outside of chroot */
23164 ++ if (dentry == realroot && mnt == realrootmnt)
23165 ++ ret = 0;
23166 ++
23167 ++ dput(realroot);
23168 ++ mntput(realrootmnt);
23169 ++ return ret;
23170 ++}
23171 ++#endif
23172 ++
23173 ++int
23174 ++gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
23175 ++{
23176 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
23177 ++ if (!grsec_enable_chroot_fchdir)
23178 ++ return 1;
23179 ++
23180 ++ if (!proc_is_chrooted(current))
23181 ++ return 1;
23182 ++ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
23183 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
23184 ++ return 0;
23185 ++ }
23186 ++#endif
23187 ++ return 1;
23188 ++}
23189 ++
23190 ++int
23191 ++gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23192 ++ const time_t shm_createtime)
23193 ++{
23194 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
23195 ++ struct pid *pid = NULL;
23196 ++ time_t starttime;
23197 ++
23198 ++ if (unlikely(!grsec_enable_chroot_shmat))
23199 ++ return 1;
23200 ++
23201 ++ if (likely(!proc_is_chrooted(current)))
23202 ++ return 1;
23203 ++
23204 ++ read_lock(&tasklist_lock);
23205 ++
23206 ++ pid = find_vpid(shm_cprid);
23207 ++ if (pid) {
23208 ++ struct task_struct *p;
23209 ++ p = pid_task(pid, PIDTYPE_PID);
23210 ++ task_lock(p);
23211 ++ starttime = p->start_time.tv_sec;
23212 ++ if (unlikely(!have_same_root(current, p) &&
23213 ++ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
23214 ++ task_unlock(p);
23215 ++ read_unlock(&tasklist_lock);
23216 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23217 ++ return 0;
23218 ++ }
23219 ++ task_unlock(p);
23220 ++ } else {
23221 ++ pid = find_vpid(shm_lapid);
23222 ++ if (pid) {
23223 ++ struct task_struct *p;
23224 ++ p = pid_task(pid, PIDTYPE_PID);
23225 ++ task_lock(p);
23226 ++ if (unlikely(!have_same_root(current, p))) {
23227 ++ task_unlock(p);
23228 ++ read_unlock(&tasklist_lock);
23229 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23230 ++ return 0;
23231 ++ }
23232 ++ task_unlock(p);
23233 ++ }
23234 ++ }
23235 ++
23236 ++ read_unlock(&tasklist_lock);
23237 ++#endif
23238 ++ return 1;
23239 ++}
23240 ++
23241 ++void
23242 ++gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
23243 ++{
23244 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
23245 ++ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
23246 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
23247 ++#endif
23248 ++ return;
23249 ++}
23250 ++
23251 ++int
23252 ++gr_handle_chroot_mknod(const struct dentry *dentry,
23253 ++ const struct vfsmount *mnt, const int mode)
23254 ++{
23255 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
23256 ++ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
23257 ++ proc_is_chrooted(current)) {
23258 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
23259 ++ return -EPERM;
23260 ++ }
23261 ++#endif
23262 ++ return 0;
23263 ++}
23264 ++
23265 ++int
23266 ++gr_handle_chroot_mount(const struct dentry *dentry,
23267 ++ const struct vfsmount *mnt, const char *dev_name)
23268 ++{
23269 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
23270 ++ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
23271 ++ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
23272 ++ return -EPERM;
23273 ++ }
23274 ++#endif
23275 ++ return 0;
23276 ++}
23277 ++
23278 ++int
23279 ++gr_handle_chroot_pivot(void)
23280 ++{
23281 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
23282 ++ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
23283 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
23284 ++ return -EPERM;
23285 ++ }
23286 ++#endif
23287 ++ return 0;
23288 ++}
23289 ++
23290 ++int
23291 ++gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
23292 ++{
23293 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
23294 ++ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
23295 ++ !gr_is_outside_chroot(dentry, mnt)) {
23296 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
23297 ++ return -EPERM;
23298 ++ }
23299 ++#endif
23300 ++ return 0;
23301 ++}
23302 ++
23303 ++void
23304 ++gr_handle_chroot_caps(struct task_struct *task)
23305 ++{
23306 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23307 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
23308 ++ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
23309 ++ task->cap_permitted =
23310 ++ cap_drop(task->cap_permitted, chroot_caps);
23311 ++ task->cap_inheritable =
23312 ++ cap_drop(task->cap_inheritable, chroot_caps);
23313 ++ task->cap_effective =
23314 ++ cap_drop(task->cap_effective, chroot_caps);
23315 ++ }
23316 ++#endif
23317 ++ return;
23318 ++}
23319 ++
23320 ++int
23321 ++gr_handle_chroot_sysctl(const int op)
23322 ++{
23323 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
23324 ++ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
23325 ++ && (op & MAY_WRITE))
23326 ++ return -EACCES;
23327 ++#endif
23328 ++ return 0;
23329 ++}
23330 ++
23331 ++void
23332 ++gr_handle_chroot_chdir(struct path *path)
23333 ++{
23334 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
23335 ++ if (grsec_enable_chroot_chdir)
23336 ++ set_fs_pwd(current->fs, path);
23337 ++#endif
23338 ++ return;
23339 ++}
23340 ++
23341 ++int
23342 ++gr_handle_chroot_chmod(const struct dentry *dentry,
23343 ++ const struct vfsmount *mnt, const int mode)
23344 ++{
23345 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
23346 ++ if (grsec_enable_chroot_chmod &&
23347 ++ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
23348 ++ proc_is_chrooted(current)) {
23349 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
23350 ++ return -EPERM;
23351 ++ }
23352 ++#endif
23353 ++ return 0;
23354 ++}
23355 ++
23356 ++#ifdef CONFIG_SECURITY
23357 ++EXPORT_SYMBOL(gr_handle_chroot_caps);
23358 ++#endif
23359 +diff -urNp linux-2.6.27.10/grsecurity/grsec_disabled.c linux-2.6.27.10/grsecurity/grsec_disabled.c
23360 +--- linux-2.6.27.10/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
23361 ++++ linux-2.6.27.10/grsecurity/grsec_disabled.c 2008-11-18 03:38:45.000000000 -0500
23362 +@@ -0,0 +1,418 @@
23363 ++#include <linux/kernel.h>
23364 ++#include <linux/module.h>
23365 ++#include <linux/sched.h>
23366 ++#include <linux/file.h>
23367 ++#include <linux/fs.h>
23368 ++#include <linux/kdev_t.h>
23369 ++#include <linux/net.h>
23370 ++#include <linux/in.h>
23371 ++#include <linux/ip.h>
23372 ++#include <linux/skbuff.h>
23373 ++#include <linux/sysctl.h>
23374 ++
23375 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
23376 ++void
23377 ++pax_set_initial_flags(struct linux_binprm *bprm)
23378 ++{
23379 ++ return;
23380 ++}
23381 ++#endif
23382 ++
23383 ++#ifdef CONFIG_SYSCTL
23384 ++__u32
23385 ++gr_handle_sysctl(const struct ctl_table * table, const int op)
23386 ++{
23387 ++ return 0;
23388 ++}
23389 ++#endif
23390 ++
23391 ++int
23392 ++gr_acl_is_enabled(void)
23393 ++{
23394 ++ return 0;
23395 ++}
23396 ++
23397 ++int
23398 ++gr_handle_rawio(const struct inode *inode)
23399 ++{
23400 ++ return 0;
23401 ++}
23402 ++
23403 ++void
23404 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
23405 ++{
23406 ++ return;
23407 ++}
23408 ++
23409 ++int
23410 ++gr_handle_ptrace(struct task_struct *task, const long request)
23411 ++{
23412 ++ return 0;
23413 ++}
23414 ++
23415 ++int
23416 ++gr_handle_proc_ptrace(struct task_struct *task)
23417 ++{
23418 ++ return 0;
23419 ++}
23420 ++
23421 ++void
23422 ++gr_learn_resource(const struct task_struct *task,
23423 ++ const int res, const unsigned long wanted, const int gt)
23424 ++{
23425 ++ return;
23426 ++}
23427 ++
23428 ++int
23429 ++gr_set_acls(const int type)
23430 ++{
23431 ++ return 0;
23432 ++}
23433 ++
23434 ++int
23435 ++gr_check_hidden_task(const struct task_struct *tsk)
23436 ++{
23437 ++ return 0;
23438 ++}
23439 ++
23440 ++int
23441 ++gr_check_protected_task(const struct task_struct *task)
23442 ++{
23443 ++ return 0;
23444 ++}
23445 ++
23446 ++void
23447 ++gr_copy_label(struct task_struct *tsk)
23448 ++{
23449 ++ return;
23450 ++}
23451 ++
23452 ++void
23453 ++gr_set_pax_flags(struct task_struct *task)
23454 ++{
23455 ++ return;
23456 ++}
23457 ++
23458 ++int
23459 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
23460 ++{
23461 ++ return 0;
23462 ++}
23463 ++
23464 ++void
23465 ++gr_handle_delete(const ino_t ino, const dev_t dev)
23466 ++{
23467 ++ return;
23468 ++}
23469 ++
23470 ++void
23471 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
23472 ++{
23473 ++ return;
23474 ++}
23475 ++
23476 ++void
23477 ++gr_handle_crash(struct task_struct *task, const int sig)
23478 ++{
23479 ++ return;
23480 ++}
23481 ++
23482 ++int
23483 ++gr_check_crash_exec(const struct file *filp)
23484 ++{
23485 ++ return 0;
23486 ++}
23487 ++
23488 ++int
23489 ++gr_check_crash_uid(const uid_t uid)
23490 ++{
23491 ++ return 0;
23492 ++}
23493 ++
23494 ++void
23495 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
23496 ++ struct dentry *old_dentry,
23497 ++ struct dentry *new_dentry,
23498 ++ struct vfsmount *mnt, const __u8 replace)
23499 ++{
23500 ++ return;
23501 ++}
23502 ++
23503 ++int
23504 ++gr_search_socket(const int family, const int type, const int protocol)
23505 ++{
23506 ++ return 1;
23507 ++}
23508 ++
23509 ++int
23510 ++gr_search_connectbind(const int mode, const struct socket *sock,
23511 ++ const struct sockaddr_in *addr)
23512 ++{
23513 ++ return 1;
23514 ++}
23515 ++
23516 ++int
23517 ++gr_task_is_capable(struct task_struct *task, const int cap)
23518 ++{
23519 ++ return 1;
23520 ++}
23521 ++
23522 ++int
23523 ++gr_is_capable_nolog(const int cap)
23524 ++{
23525 ++ return 1;
23526 ++}
23527 ++
23528 ++void
23529 ++gr_handle_alertkill(struct task_struct *task)
23530 ++{
23531 ++ return;
23532 ++}
23533 ++
23534 ++__u32
23535 ++gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
23536 ++{
23537 ++ return 1;
23538 ++}
23539 ++
23540 ++__u32
23541 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
23542 ++ const struct vfsmount * mnt)
23543 ++{
23544 ++ return 1;
23545 ++}
23546 ++
23547 ++__u32
23548 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
23549 ++ const int fmode)
23550 ++{
23551 ++ return 1;
23552 ++}
23553 ++
23554 ++__u32
23555 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
23556 ++{
23557 ++ return 1;
23558 ++}
23559 ++
23560 ++__u32
23561 ++gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
23562 ++{
23563 ++ return 1;
23564 ++}
23565 ++
23566 ++int
23567 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
23568 ++ unsigned int *vm_flags)
23569 ++{
23570 ++ return 1;
23571 ++}
23572 ++
23573 ++__u32
23574 ++gr_acl_handle_truncate(const struct dentry * dentry,
23575 ++ const struct vfsmount * mnt)
23576 ++{
23577 ++ return 1;
23578 ++}
23579 ++
23580 ++__u32
23581 ++gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
23582 ++{
23583 ++ return 1;
23584 ++}
23585 ++
23586 ++__u32
23587 ++gr_acl_handle_access(const struct dentry * dentry,
23588 ++ const struct vfsmount * mnt, const int fmode)
23589 ++{
23590 ++ return 1;
23591 ++}
23592 ++
23593 ++__u32
23594 ++gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
23595 ++ mode_t mode)
23596 ++{
23597 ++ return 1;
23598 ++}
23599 ++
23600 ++__u32
23601 ++gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
23602 ++ mode_t mode)
23603 ++{
23604 ++ return 1;
23605 ++}
23606 ++
23607 ++__u32
23608 ++gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
23609 ++{
23610 ++ return 1;
23611 ++}
23612 ++
23613 ++void
23614 ++grsecurity_init(void)
23615 ++{
23616 ++ return;
23617 ++}
23618 ++
23619 ++__u32
23620 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
23621 ++ const struct dentry * parent_dentry,
23622 ++ const struct vfsmount * parent_mnt,
23623 ++ const int mode)
23624 ++{
23625 ++ return 1;
23626 ++}
23627 ++
23628 ++__u32
23629 ++gr_acl_handle_mkdir(const struct dentry * new_dentry,
23630 ++ const struct dentry * parent_dentry,
23631 ++ const struct vfsmount * parent_mnt)
23632 ++{
23633 ++ return 1;
23634 ++}
23635 ++
23636 ++__u32
23637 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
23638 ++ const struct dentry * parent_dentry,
23639 ++ const struct vfsmount * parent_mnt, const char *from)
23640 ++{
23641 ++ return 1;
23642 ++}
23643 ++
23644 ++__u32
23645 ++gr_acl_handle_link(const struct dentry * new_dentry,
23646 ++ const struct dentry * parent_dentry,
23647 ++ const struct vfsmount * parent_mnt,
23648 ++ const struct dentry * old_dentry,
23649 ++ const struct vfsmount * old_mnt, const char *to)
23650 ++{
23651 ++ return 1;
23652 ++}
23653 ++
23654 ++int
23655 ++gr_acl_handle_rename(const struct dentry *new_dentry,
23656 ++ const struct dentry *parent_dentry,
23657 ++ const struct vfsmount *parent_mnt,
23658 ++ const struct dentry *old_dentry,
23659 ++ const struct inode *old_parent_inode,
23660 ++ const struct vfsmount *old_mnt, const char *newname)
23661 ++{
23662 ++ return 0;
23663 ++}
23664 ++
23665 ++int
23666 ++gr_acl_handle_filldir(const struct file *file, const char *name,
23667 ++ const int namelen, const ino_t ino)
23668 ++{
23669 ++ return 1;
23670 ++}
23671 ++
23672 ++int
23673 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23674 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
23675 ++{
23676 ++ return 1;
23677 ++}
23678 ++
23679 ++int
23680 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
23681 ++{
23682 ++ return 1;
23683 ++}
23684 ++
23685 ++int
23686 ++gr_search_accept(const struct socket *sock)
23687 ++{
23688 ++ return 1;
23689 ++}
23690 ++
23691 ++int
23692 ++gr_search_listen(const struct socket *sock)
23693 ++{
23694 ++ return 1;
23695 ++}
23696 ++
23697 ++int
23698 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
23699 ++{
23700 ++ return 1;
23701 ++}
23702 ++
23703 ++__u32
23704 ++gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
23705 ++{
23706 ++ return 1;
23707 ++}
23708 ++
23709 ++__u32
23710 ++gr_acl_handle_creat(const struct dentry * dentry,
23711 ++ const struct dentry * p_dentry,
23712 ++ const struct vfsmount * p_mnt, const int fmode,
23713 ++ const int imode)
23714 ++{
23715 ++ return 1;
23716 ++}
23717 ++
23718 ++void
23719 ++gr_acl_handle_exit(void)
23720 ++{
23721 ++ return;
23722 ++}
23723 ++
23724 ++int
23725 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
23726 ++{
23727 ++ return 1;
23728 ++}
23729 ++
23730 ++void
23731 ++gr_set_role_label(const uid_t uid, const gid_t gid)
23732 ++{
23733 ++ return;
23734 ++}
23735 ++
23736 ++int
23737 ++gr_acl_handle_procpidmem(const struct task_struct *task)
23738 ++{
23739 ++ return 0;
23740 ++}
23741 ++
23742 ++int
23743 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
23744 ++{
23745 ++ return 1;
23746 ++}
23747 ++
23748 ++int
23749 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
23750 ++{
23751 ++ return 1;
23752 ++}
23753 ++
23754 ++void
23755 ++gr_set_kernel_label(struct task_struct *task)
23756 ++{
23757 ++ return;
23758 ++}
23759 ++
23760 ++int
23761 ++gr_check_user_change(int real, int effective, int fs)
23762 ++{
23763 ++ return 0;
23764 ++}
23765 ++
23766 ++int
23767 ++gr_check_group_change(int real, int effective, int fs)
23768 ++{
23769 ++ return 0;
23770 ++}
23771 ++
23772 ++
23773 ++EXPORT_SYMBOL(gr_task_is_capable);
23774 ++EXPORT_SYMBOL(gr_is_capable_nolog);
23775 ++EXPORT_SYMBOL(gr_learn_resource);
23776 ++EXPORT_SYMBOL(gr_set_kernel_label);
23777 ++#ifdef CONFIG_SECURITY
23778 ++EXPORT_SYMBOL(gr_check_user_change);
23779 ++EXPORT_SYMBOL(gr_check_group_change);
23780 ++#endif
23781 +diff -urNp linux-2.6.27.10/grsecurity/grsec_exec.c linux-2.6.27.10/grsecurity/grsec_exec.c
23782 +--- linux-2.6.27.10/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
23783 ++++ linux-2.6.27.10/grsecurity/grsec_exec.c 2008-11-18 03:38:45.000000000 -0500
23784 +@@ -0,0 +1,88 @@
23785 ++#include <linux/kernel.h>
23786 ++#include <linux/sched.h>
23787 ++#include <linux/file.h>
23788 ++#include <linux/binfmts.h>
23789 ++#include <linux/smp_lock.h>
23790 ++#include <linux/fs.h>
23791 ++#include <linux/types.h>
23792 ++#include <linux/grdefs.h>
23793 ++#include <linux/grinternal.h>
23794 ++#include <linux/capability.h>
23795 ++
23796 ++#include <asm/uaccess.h>
23797 ++
23798 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23799 ++static char gr_exec_arg_buf[132];
23800 ++static DECLARE_MUTEX(gr_exec_arg_sem);
23801 ++#endif
23802 ++
23803 ++int
23804 ++gr_handle_nproc(void)
23805 ++{
23806 ++#ifdef CONFIG_GRKERNSEC_EXECVE
23807 ++ if (grsec_enable_execve && current->user &&
23808 ++ (atomic_read(&current->user->processes) >
23809 ++ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
23810 ++ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
23811 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
23812 ++ return -EAGAIN;
23813 ++ }
23814 ++#endif
23815 ++ return 0;
23816 ++}
23817 ++
23818 ++void
23819 ++gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv)
23820 ++{
23821 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23822 ++ char *grarg = gr_exec_arg_buf;
23823 ++ unsigned int i, x, execlen = 0;
23824 ++ char c;
23825 ++
23826 ++ if (!((grsec_enable_execlog && grsec_enable_group &&
23827 ++ in_group_p(grsec_audit_gid))
23828 ++ || (grsec_enable_execlog && !grsec_enable_group)))
23829 ++ return;
23830 ++
23831 ++ down(&gr_exec_arg_sem);
23832 ++ memset(grarg, 0, sizeof(gr_exec_arg_buf));
23833 ++
23834 ++ if (unlikely(argv == NULL))
23835 ++ goto log;
23836 ++
23837 ++ for (i = 0; i < bprm->argc && execlen < 128; i++) {
23838 ++ const char __user *p;
23839 ++ unsigned int len;
23840 ++
23841 ++ if (copy_from_user(&p, argv + i, sizeof(p)))
23842 ++ goto log;
23843 ++ if (!p)
23844 ++ goto log;
23845 ++ len = strnlen_user(p, 128 - execlen);
23846 ++ if (len > 128 - execlen)
23847 ++ len = 128 - execlen;
23848 ++ else if (len > 0)
23849 ++ len--;
23850 ++ if (copy_from_user(grarg + execlen, p, len))
23851 ++ goto log;
23852 ++
23853 ++ /* rewrite unprintable characters */
23854 ++ for (x = 0; x < len; x++) {
23855 ++ c = *(grarg + execlen + x);
23856 ++ if (c < 32 || c > 126)
23857 ++ *(grarg + execlen + x) = ' ';
23858 ++ }
23859 ++
23860 ++ execlen += len;
23861 ++ *(grarg + execlen) = ' ';
23862 ++ *(grarg + execlen + 1) = '\0';
23863 ++ execlen++;
23864 ++ }
23865 ++
23866 ++ log:
23867 ++ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
23868 ++ bprm->file->f_path.mnt, grarg);
23869 ++ up(&gr_exec_arg_sem);
23870 ++#endif
23871 ++ return;
23872 ++}
23873 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fifo.c linux-2.6.27.10/grsecurity/grsec_fifo.c
23874 +--- linux-2.6.27.10/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
23875 ++++ linux-2.6.27.10/grsecurity/grsec_fifo.c 2008-11-18 03:38:45.000000000 -0500
23876 +@@ -0,0 +1,22 @@
23877 ++#include <linux/kernel.h>
23878 ++#include <linux/sched.h>
23879 ++#include <linux/fs.h>
23880 ++#include <linux/file.h>
23881 ++#include <linux/grinternal.h>
23882 ++
23883 ++int
23884 ++gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
23885 ++ const struct dentry *dir, const int flag, const int acc_mode)
23886 ++{
23887 ++#ifdef CONFIG_GRKERNSEC_FIFO
23888 ++ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
23889 ++ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
23890 ++ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
23891 ++ (current->fsuid != dentry->d_inode->i_uid)) {
23892 ++ if (!generic_permission(dentry->d_inode, acc_mode, NULL))
23893 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
23894 ++ return -EACCES;
23895 ++ }
23896 ++#endif
23897 ++ return 0;
23898 ++}
23899 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fork.c linux-2.6.27.10/grsecurity/grsec_fork.c
23900 +--- linux-2.6.27.10/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
23901 ++++ linux-2.6.27.10/grsecurity/grsec_fork.c 2008-11-18 03:38:45.000000000 -0500
23902 +@@ -0,0 +1,15 @@
23903 ++#include <linux/kernel.h>
23904 ++#include <linux/sched.h>
23905 ++#include <linux/grsecurity.h>
23906 ++#include <linux/grinternal.h>
23907 ++#include <linux/errno.h>
23908 ++
23909 ++void
23910 ++gr_log_forkfail(const int retval)
23911 ++{
23912 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
23913 ++ if (grsec_enable_forkfail && retval != -ERESTARTNOINTR)
23914 ++ gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval);
23915 ++#endif
23916 ++ return;
23917 ++}
23918 +diff -urNp linux-2.6.27.10/grsecurity/grsec_init.c linux-2.6.27.10/grsecurity/grsec_init.c
23919 +--- linux-2.6.27.10/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
23920 ++++ linux-2.6.27.10/grsecurity/grsec_init.c 2008-11-18 03:38:45.000000000 -0500
23921 +@@ -0,0 +1,230 @@
23922 ++#include <linux/kernel.h>
23923 ++#include <linux/sched.h>
23924 ++#include <linux/mm.h>
23925 ++#include <linux/smp_lock.h>
23926 ++#include <linux/gracl.h>
23927 ++#include <linux/slab.h>
23928 ++#include <linux/vmalloc.h>
23929 ++#include <linux/percpu.h>
23930 ++
23931 ++int grsec_enable_link;
23932 ++int grsec_enable_dmesg;
23933 ++int grsec_enable_fifo;
23934 ++int grsec_enable_execve;
23935 ++int grsec_enable_execlog;
23936 ++int grsec_enable_signal;
23937 ++int grsec_enable_forkfail;
23938 ++int grsec_enable_time;
23939 ++int grsec_enable_audit_textrel;
23940 ++int grsec_enable_group;
23941 ++int grsec_audit_gid;
23942 ++int grsec_enable_chdir;
23943 ++int grsec_enable_audit_ipc;
23944 ++int grsec_enable_mount;
23945 ++int grsec_enable_chroot_findtask;
23946 ++int grsec_enable_chroot_mount;
23947 ++int grsec_enable_chroot_shmat;
23948 ++int grsec_enable_chroot_fchdir;
23949 ++int grsec_enable_chroot_double;
23950 ++int grsec_enable_chroot_pivot;
23951 ++int grsec_enable_chroot_chdir;
23952 ++int grsec_enable_chroot_chmod;
23953 ++int grsec_enable_chroot_mknod;
23954 ++int grsec_enable_chroot_nice;
23955 ++int grsec_enable_chroot_execlog;
23956 ++int grsec_enable_chroot_caps;
23957 ++int grsec_enable_chroot_sysctl;
23958 ++int grsec_enable_chroot_unix;
23959 ++int grsec_enable_tpe;
23960 ++int grsec_tpe_gid;
23961 ++int grsec_enable_tpe_all;
23962 ++int grsec_enable_socket_all;
23963 ++int grsec_socket_all_gid;
23964 ++int grsec_enable_socket_client;
23965 ++int grsec_socket_client_gid;
23966 ++int grsec_enable_socket_server;
23967 ++int grsec_socket_server_gid;
23968 ++int grsec_resource_logging;
23969 ++int grsec_lock;
23970 ++
23971 ++DEFINE_SPINLOCK(grsec_alert_lock);
23972 ++unsigned long grsec_alert_wtime = 0;
23973 ++unsigned long grsec_alert_fyet = 0;
23974 ++
23975 ++DEFINE_SPINLOCK(grsec_audit_lock);
23976 ++
23977 ++DEFINE_RWLOCK(grsec_exec_file_lock);
23978 ++
23979 ++char *gr_shared_page[4];
23980 ++
23981 ++char *gr_alert_log_fmt;
23982 ++char *gr_audit_log_fmt;
23983 ++char *gr_alert_log_buf;
23984 ++char *gr_audit_log_buf;
23985 ++
23986 ++extern struct gr_arg *gr_usermode;
23987 ++extern unsigned char *gr_system_salt;
23988 ++extern unsigned char *gr_system_sum;
23989 ++
23990 ++void
23991 ++grsecurity_init(void)
23992 ++{
23993 ++ int j;
23994 ++ /* create the per-cpu shared pages */
23995 ++
23996 ++#ifdef CONFIG_X86
23997 ++ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
23998 ++#endif
23999 ++
24000 ++ for (j = 0; j < 4; j++) {
24001 ++ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE);
24002 ++ if (gr_shared_page[j] == NULL) {
24003 ++ panic("Unable to allocate grsecurity shared page");
24004 ++ return;
24005 ++ }
24006 ++ }
24007 ++
24008 ++ /* allocate log buffers */
24009 ++ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
24010 ++ if (!gr_alert_log_fmt) {
24011 ++ panic("Unable to allocate grsecurity alert log format buffer");
24012 ++ return;
24013 ++ }
24014 ++ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
24015 ++ if (!gr_audit_log_fmt) {
24016 ++ panic("Unable to allocate grsecurity audit log format buffer");
24017 ++ return;
24018 ++ }
24019 ++ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
24020 ++ if (!gr_alert_log_buf) {
24021 ++ panic("Unable to allocate grsecurity alert log buffer");
24022 ++ return;
24023 ++ }
24024 ++ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
24025 ++ if (!gr_audit_log_buf) {
24026 ++ panic("Unable to allocate grsecurity audit log buffer");
24027 ++ return;
24028 ++ }
24029 ++
24030 ++ /* allocate memory for authentication structure */
24031 ++ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
24032 ++ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
24033 ++ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
24034 ++
24035 ++ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
24036 ++ panic("Unable to allocate grsecurity authentication structure");
24037 ++ return;
24038 ++ }
24039 ++
24040 ++#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
24041 ++#ifndef CONFIG_GRKERNSEC_SYSCTL
24042 ++ grsec_lock = 1;
24043 ++#endif
24044 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
24045 ++ grsec_enable_audit_textrel = 1;
24046 ++#endif
24047 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
24048 ++ grsec_enable_group = 1;
24049 ++ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
24050 ++#endif
24051 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
24052 ++ grsec_enable_chdir = 1;
24053 ++#endif
24054 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24055 ++ grsec_enable_audit_ipc = 1;
24056 ++#endif
24057 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24058 ++ grsec_enable_mount = 1;
24059 ++#endif
24060 ++#ifdef CONFIG_GRKERNSEC_LINK
24061 ++ grsec_enable_link = 1;
24062 ++#endif
24063 ++#ifdef CONFIG_GRKERNSEC_DMESG
24064 ++ grsec_enable_dmesg = 1;
24065 ++#endif
24066 ++#ifdef CONFIG_GRKERNSEC_FIFO
24067 ++ grsec_enable_fifo = 1;
24068 ++#endif
24069 ++#ifdef CONFIG_GRKERNSEC_EXECVE
24070 ++ grsec_enable_execve = 1;
24071 ++#endif
24072 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
24073 ++ grsec_enable_execlog = 1;
24074 ++#endif
24075 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
24076 ++ grsec_enable_signal = 1;
24077 ++#endif
24078 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
24079 ++ grsec_enable_forkfail = 1;
24080 ++#endif
24081 ++#ifdef CONFIG_GRKERNSEC_TIME
24082 ++ grsec_enable_time = 1;
24083 ++#endif
24084 ++#ifdef CONFIG_GRKERNSEC_RESLOG
24085 ++ grsec_resource_logging = 1;
24086 ++#endif
24087 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
24088 ++ grsec_enable_chroot_findtask = 1;
24089 ++#endif
24090 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
24091 ++ grsec_enable_chroot_unix = 1;
24092 ++#endif
24093 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
24094 ++ grsec_enable_chroot_mount = 1;
24095 ++#endif
24096 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
24097 ++ grsec_enable_chroot_fchdir = 1;
24098 ++#endif
24099 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
24100 ++ grsec_enable_chroot_shmat = 1;
24101 ++#endif
24102 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
24103 ++ grsec_enable_chroot_double = 1;
24104 ++#endif
24105 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
24106 ++ grsec_enable_chroot_pivot = 1;
24107 ++#endif
24108 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
24109 ++ grsec_enable_chroot_chdir = 1;
24110 ++#endif
24111 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
24112 ++ grsec_enable_chroot_chmod = 1;
24113 ++#endif
24114 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
24115 ++ grsec_enable_chroot_mknod = 1;
24116 ++#endif
24117 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
24118 ++ grsec_enable_chroot_nice = 1;
24119 ++#endif
24120 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
24121 ++ grsec_enable_chroot_execlog = 1;
24122 ++#endif
24123 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
24124 ++ grsec_enable_chroot_caps = 1;
24125 ++#endif
24126 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
24127 ++ grsec_enable_chroot_sysctl = 1;
24128 ++#endif
24129 ++#ifdef CONFIG_GRKERNSEC_TPE
24130 ++ grsec_enable_tpe = 1;
24131 ++ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
24132 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
24133 ++ grsec_enable_tpe_all = 1;
24134 ++#endif
24135 ++#endif
24136 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24137 ++ grsec_enable_socket_all = 1;
24138 ++ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
24139 ++#endif
24140 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24141 ++ grsec_enable_socket_client = 1;
24142 ++ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
24143 ++#endif
24144 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24145 ++ grsec_enable_socket_server = 1;
24146 ++ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
24147 ++#endif
24148 ++#endif
24149 ++
24150 ++ return;
24151 ++}
24152 +diff -urNp linux-2.6.27.10/grsecurity/grsec_ipc.c linux-2.6.27.10/grsecurity/grsec_ipc.c
24153 +--- linux-2.6.27.10/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500
24154 ++++ linux-2.6.27.10/grsecurity/grsec_ipc.c 2008-11-18 03:38:45.000000000 -0500
24155 +@@ -0,0 +1,81 @@
24156 ++#include <linux/kernel.h>
24157 ++#include <linux/sched.h>
24158 ++#include <linux/types.h>
24159 ++#include <linux/ipc.h>
24160 ++#include <linux/grsecurity.h>
24161 ++#include <linux/grinternal.h>
24162 ++
24163 ++void
24164 ++gr_log_msgget(const int ret, const int msgflg)
24165 ++{
24166 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24167 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24168 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24169 ++ !grsec_enable_group)) && (ret >= 0)
24170 ++ && (msgflg & IPC_CREAT))
24171 ++ gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG);
24172 ++#endif
24173 ++ return;
24174 ++}
24175 ++
24176 ++void
24177 ++gr_log_msgrm(const uid_t uid, const uid_t cuid)
24178 ++{
24179 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24180 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24181 ++ grsec_enable_audit_ipc) ||
24182 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24183 ++ gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid);
24184 ++#endif
24185 ++ return;
24186 ++}
24187 ++
24188 ++void
24189 ++gr_log_semget(const int err, const int semflg)
24190 ++{
24191 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24192 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24193 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24194 ++ !grsec_enable_group)) && (err >= 0)
24195 ++ && (semflg & IPC_CREAT))
24196 ++ gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG);
24197 ++#endif
24198 ++ return;
24199 ++}
24200 ++
24201 ++void
24202 ++gr_log_semrm(const uid_t uid, const uid_t cuid)
24203 ++{
24204 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24205 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24206 ++ grsec_enable_audit_ipc) ||
24207 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24208 ++ gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid);
24209 ++#endif
24210 ++ return;
24211 ++}
24212 ++
24213 ++void
24214 ++gr_log_shmget(const int err, const int shmflg, const size_t size)
24215 ++{
24216 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24217 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24218 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24219 ++ !grsec_enable_group)) && (err >= 0)
24220 ++ && (shmflg & IPC_CREAT))
24221 ++ gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size);
24222 ++#endif
24223 ++ return;
24224 ++}
24225 ++
24226 ++void
24227 ++gr_log_shmrm(const uid_t uid, const uid_t cuid)
24228 ++{
24229 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24230 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24231 ++ grsec_enable_audit_ipc) ||
24232 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24233 ++ gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid);
24234 ++#endif
24235 ++ return;
24236 ++}
24237 +diff -urNp linux-2.6.27.10/grsecurity/grsec_link.c linux-2.6.27.10/grsecurity/grsec_link.c
24238 +--- linux-2.6.27.10/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
24239 ++++ linux-2.6.27.10/grsecurity/grsec_link.c 2008-11-18 03:38:45.000000000 -0500
24240 +@@ -0,0 +1,39 @@
24241 ++#include <linux/kernel.h>
24242 ++#include <linux/sched.h>
24243 ++#include <linux/fs.h>
24244 ++#include <linux/file.h>
24245 ++#include <linux/grinternal.h>
24246 ++
24247 ++int
24248 ++gr_handle_follow_link(const struct inode *parent,
24249 ++ const struct inode *inode,
24250 ++ const struct dentry *dentry, const struct vfsmount *mnt)
24251 ++{
24252 ++#ifdef CONFIG_GRKERNSEC_LINK
24253 ++ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
24254 ++ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
24255 ++ (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
24256 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
24257 ++ return -EACCES;
24258 ++ }
24259 ++#endif
24260 ++ return 0;
24261 ++}
24262 ++
24263 ++int
24264 ++gr_handle_hardlink(const struct dentry *dentry,
24265 ++ const struct vfsmount *mnt,
24266 ++ struct inode *inode, const int mode, const char *to)
24267 ++{
24268 ++#ifdef CONFIG_GRKERNSEC_LINK
24269 ++ if (grsec_enable_link && current->fsuid != inode->i_uid &&
24270 ++ (!S_ISREG(mode) || (mode & S_ISUID) ||
24271 ++ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
24272 ++ (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
24273 ++ !capable(CAP_FOWNER) && current->uid) {
24274 ++ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
24275 ++ return -EPERM;
24276 ++ }
24277 ++#endif
24278 ++ return 0;
24279 ++}
24280 +diff -urNp linux-2.6.27.10/grsecurity/grsec_log.c linux-2.6.27.10/grsecurity/grsec_log.c
24281 +--- linux-2.6.27.10/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
24282 ++++ linux-2.6.27.10/grsecurity/grsec_log.c 2008-11-18 03:38:45.000000000 -0500
24283 +@@ -0,0 +1,269 @@
24284 ++#include <linux/kernel.h>
24285 ++#include <linux/sched.h>
24286 ++#include <linux/file.h>
24287 ++#include <linux/tty.h>
24288 ++#include <linux/fs.h>
24289 ++#include <linux/grinternal.h>
24290 ++
24291 ++#define BEGIN_LOCKS(x) \
24292 ++ read_lock(&tasklist_lock); \
24293 ++ read_lock(&grsec_exec_file_lock); \
24294 ++ if (x != GR_DO_AUDIT) \
24295 ++ spin_lock(&grsec_alert_lock); \
24296 ++ else \
24297 ++ spin_lock(&grsec_audit_lock)
24298 ++
24299 ++#define END_LOCKS(x) \
24300 ++ if (x != GR_DO_AUDIT) \
24301 ++ spin_unlock(&grsec_alert_lock); \
24302 ++ else \
24303 ++ spin_unlock(&grsec_audit_lock); \
24304 ++ read_unlock(&grsec_exec_file_lock); \
24305 ++ read_unlock(&tasklist_lock); \
24306 ++ if (x == GR_DONT_AUDIT) \
24307 ++ gr_handle_alertkill(current)
24308 ++
24309 ++enum {
24310 ++ FLOODING,
24311 ++ NO_FLOODING
24312 ++};
24313 ++
24314 ++extern char *gr_alert_log_fmt;
24315 ++extern char *gr_audit_log_fmt;
24316 ++extern char *gr_alert_log_buf;
24317 ++extern char *gr_audit_log_buf;
24318 ++
24319 ++static int gr_log_start(int audit)
24320 ++{
24321 ++ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
24322 ++ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
24323 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24324 ++
24325 ++ if (audit == GR_DO_AUDIT)
24326 ++ goto set_fmt;
24327 ++
24328 ++ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
24329 ++ grsec_alert_wtime = jiffies;
24330 ++ grsec_alert_fyet = 0;
24331 ++ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
24332 ++ grsec_alert_fyet++;
24333 ++ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
24334 ++ grsec_alert_wtime = jiffies;
24335 ++ grsec_alert_fyet++;
24336 ++ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
24337 ++ return FLOODING;
24338 ++ } else return FLOODING;
24339 ++
24340 ++set_fmt:
24341 ++ memset(buf, 0, PAGE_SIZE);
24342 ++ if (current->signal->curr_ip && gr_acl_is_enabled()) {
24343 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
24344 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24345 ++ } else if (current->signal->curr_ip) {
24346 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
24347 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
24348 ++ } else if (gr_acl_is_enabled()) {
24349 ++ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
24350 ++ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24351 ++ } else {
24352 ++ sprintf(fmt, "%s%s", loglevel, "grsec: ");
24353 ++ strcpy(buf, fmt);
24354 ++ }
24355 ++
24356 ++ return NO_FLOODING;
24357 ++}
24358 ++
24359 ++static void gr_log_middle(int audit, const char *msg, va_list ap)
24360 ++{
24361 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24362 ++ unsigned int len = strlen(buf);
24363 ++
24364 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24365 ++
24366 ++ return;
24367 ++}
24368 ++
24369 ++static void gr_log_middle_varargs(int audit, const char *msg, ...)
24370 ++{
24371 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24372 ++ unsigned int len = strlen(buf);
24373 ++ va_list ap;
24374 ++
24375 ++ va_start(ap, msg);
24376 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24377 ++ va_end(ap);
24378 ++
24379 ++ return;
24380 ++}
24381 ++
24382 ++static void gr_log_end(int audit)
24383 ++{
24384 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24385 ++ unsigned int len = strlen(buf);
24386 ++
24387 ++ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current));
24388 ++ printk("%s\n", buf);
24389 ++
24390 ++ return;
24391 ++}
24392 ++
24393 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
24394 ++{
24395 ++ int logtype;
24396 ++ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
24397 ++ char *str1, *str2, *str3;
24398 ++ int num1, num2;
24399 ++ unsigned long ulong1, ulong2;
24400 ++ struct dentry *dentry;
24401 ++ struct vfsmount *mnt;
24402 ++ struct file *file;
24403 ++ struct task_struct *task;
24404 ++ va_list ap;
24405 ++
24406 ++ BEGIN_LOCKS(audit);
24407 ++ logtype = gr_log_start(audit);
24408 ++ if (logtype == FLOODING) {
24409 ++ END_LOCKS(audit);
24410 ++ return;
24411 ++ }
24412 ++ va_start(ap, argtypes);
24413 ++ switch (argtypes) {
24414 ++ case GR_TTYSNIFF:
24415 ++ task = va_arg(ap, struct task_struct *);
24416 ++ 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);
24417 ++ break;
24418 ++ case GR_SYSCTL_HIDDEN:
24419 ++ str1 = va_arg(ap, char *);
24420 ++ gr_log_middle_varargs(audit, msg, result, str1);
24421 ++ break;
24422 ++ case GR_RBAC:
24423 ++ dentry = va_arg(ap, struct dentry *);
24424 ++ mnt = va_arg(ap, struct vfsmount *);
24425 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
24426 ++ break;
24427 ++ case GR_RBAC_STR:
24428 ++ dentry = va_arg(ap, struct dentry *);
24429 ++ mnt = va_arg(ap, struct vfsmount *);
24430 ++ str1 = va_arg(ap, char *);
24431 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
24432 ++ break;
24433 ++ case GR_STR_RBAC:
24434 ++ str1 = va_arg(ap, char *);
24435 ++ dentry = va_arg(ap, struct dentry *);
24436 ++ mnt = va_arg(ap, struct vfsmount *);
24437 ++ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
24438 ++ break;
24439 ++ case GR_RBAC_MODE2:
24440 ++ dentry = va_arg(ap, struct dentry *);
24441 ++ mnt = va_arg(ap, struct vfsmount *);
24442 ++ str1 = va_arg(ap, char *);
24443 ++ str2 = va_arg(ap, char *);
24444 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
24445 ++ break;
24446 ++ case GR_RBAC_MODE3:
24447 ++ dentry = va_arg(ap, struct dentry *);
24448 ++ mnt = va_arg(ap, struct vfsmount *);
24449 ++ str1 = va_arg(ap, char *);
24450 ++ str2 = va_arg(ap, char *);
24451 ++ str3 = va_arg(ap, char *);
24452 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
24453 ++ break;
24454 ++ case GR_FILENAME:
24455 ++ dentry = va_arg(ap, struct dentry *);
24456 ++ mnt = va_arg(ap, struct vfsmount *);
24457 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
24458 ++ break;
24459 ++ case GR_STR_FILENAME:
24460 ++ str1 = va_arg(ap, char *);
24461 ++ dentry = va_arg(ap, struct dentry *);
24462 ++ mnt = va_arg(ap, struct vfsmount *);
24463 ++ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
24464 ++ break;
24465 ++ case GR_FILENAME_STR:
24466 ++ dentry = va_arg(ap, struct dentry *);
24467 ++ mnt = va_arg(ap, struct vfsmount *);
24468 ++ str1 = va_arg(ap, char *);
24469 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
24470 ++ break;
24471 ++ case GR_FILENAME_TWO_INT:
24472 ++ dentry = va_arg(ap, struct dentry *);
24473 ++ mnt = va_arg(ap, struct vfsmount *);
24474 ++ num1 = va_arg(ap, int);
24475 ++ num2 = va_arg(ap, int);
24476 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
24477 ++ break;
24478 ++ case GR_FILENAME_TWO_INT_STR:
24479 ++ dentry = va_arg(ap, struct dentry *);
24480 ++ mnt = va_arg(ap, struct vfsmount *);
24481 ++ num1 = va_arg(ap, int);
24482 ++ num2 = va_arg(ap, int);
24483 ++ str1 = va_arg(ap, char *);
24484 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
24485 ++ break;
24486 ++ case GR_TEXTREL:
24487 ++ file = va_arg(ap, struct file *);
24488 ++ ulong1 = va_arg(ap, unsigned long);
24489 ++ ulong2 = va_arg(ap, unsigned long);
24490 ++ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
24491 ++ break;
24492 ++ case GR_PTRACE:
24493 ++ task = va_arg(ap, struct task_struct *);
24494 ++ 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);
24495 ++ break;
24496 ++ case GR_RESOURCE:
24497 ++ task = va_arg(ap, struct task_struct *);
24498 ++ ulong1 = va_arg(ap, unsigned long);
24499 ++ str1 = va_arg(ap, char *);
24500 ++ ulong2 = va_arg(ap, unsigned long);
24501 ++ 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);
24502 ++ break;
24503 ++ case GR_CAP:
24504 ++ task = va_arg(ap, struct task_struct *);
24505 ++ str1 = va_arg(ap, char *);
24506 ++ 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);
24507 ++ break;
24508 ++ case GR_SIG:
24509 ++ task = va_arg(ap, struct task_struct *);
24510 ++ num1 = va_arg(ap, int);
24511 ++ 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);
24512 ++ break;
24513 ++ case GR_CRASH1:
24514 ++ task = va_arg(ap, struct task_struct *);
24515 ++ ulong1 = va_arg(ap, unsigned long);
24516 ++ 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);
24517 ++ break;
24518 ++ case GR_CRASH2:
24519 ++ task = va_arg(ap, struct task_struct *);
24520 ++ ulong1 = va_arg(ap, unsigned long);
24521 ++ 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);
24522 ++ break;
24523 ++ case GR_PSACCT:
24524 ++ {
24525 ++ unsigned int wday, cday;
24526 ++ __u8 whr, chr;
24527 ++ __u8 wmin, cmin;
24528 ++ __u8 wsec, csec;
24529 ++ char cur_tty[64] = { 0 };
24530 ++ char parent_tty[64] = { 0 };
24531 ++
24532 ++ task = va_arg(ap, struct task_struct *);
24533 ++ wday = va_arg(ap, unsigned int);
24534 ++ cday = va_arg(ap, unsigned int);
24535 ++ whr = va_arg(ap, int);
24536 ++ chr = va_arg(ap, int);
24537 ++ wmin = va_arg(ap, int);
24538 ++ cmin = va_arg(ap, int);
24539 ++ wsec = va_arg(ap, int);
24540 ++ csec = va_arg(ap, int);
24541 ++ ulong1 = va_arg(ap, unsigned long);
24542 ++
24543 ++ 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);
24544 ++ }
24545 ++ break;
24546 ++ default:
24547 ++ gr_log_middle(audit, msg, ap);
24548 ++ }
24549 ++ va_end(ap);
24550 ++ gr_log_end(audit);
24551 ++ END_LOCKS(audit);
24552 ++}
24553 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mem.c linux-2.6.27.10/grsecurity/grsec_mem.c
24554 +--- linux-2.6.27.10/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
24555 ++++ linux-2.6.27.10/grsecurity/grsec_mem.c 2008-11-18 03:38:45.000000000 -0500
24556 +@@ -0,0 +1,71 @@
24557 ++#include <linux/kernel.h>
24558 ++#include <linux/sched.h>
24559 ++#include <linux/mm.h>
24560 ++#include <linux/mman.h>
24561 ++#include <linux/grinternal.h>
24562 ++
24563 ++void
24564 ++gr_handle_ioperm(void)
24565 ++{
24566 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
24567 ++ return;
24568 ++}
24569 ++
24570 ++void
24571 ++gr_handle_iopl(void)
24572 ++{
24573 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
24574 ++ return;
24575 ++}
24576 ++
24577 ++void
24578 ++gr_handle_mem_write(void)
24579 ++{
24580 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
24581 ++ return;
24582 ++}
24583 ++
24584 ++void
24585 ++gr_handle_kmem_write(void)
24586 ++{
24587 ++ gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
24588 ++ return;
24589 ++}
24590 ++
24591 ++void
24592 ++gr_handle_open_port(void)
24593 ++{
24594 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
24595 ++ return;
24596 ++}
24597 ++
24598 ++int
24599 ++gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
24600 ++{
24601 ++ unsigned long start, end;
24602 ++
24603 ++ start = offset;
24604 ++ end = start + vma->vm_end - vma->vm_start;
24605 ++
24606 ++ if (start > end) {
24607 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24608 ++ return -EPERM;
24609 ++ }
24610 ++
24611 ++ /* allowed ranges : ISA I/O BIOS */
24612 ++ if ((start >= __pa(high_memory))
24613 ++#ifdef CONFIG_X86
24614 ++ || (start >= 0x000a0000 && end <= 0x00100000)
24615 ++ || (start >= 0x00000000 && end <= 0x00001000)
24616 ++#endif
24617 ++ )
24618 ++ return 0;
24619 ++
24620 ++ if (vma->vm_flags & VM_WRITE) {
24621 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24622 ++ return -EPERM;
24623 ++ } else
24624 ++ vma->vm_flags &= ~VM_MAYWRITE;
24625 ++
24626 ++ return 0;
24627 ++}
24628 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mount.c linux-2.6.27.10/grsecurity/grsec_mount.c
24629 +--- linux-2.6.27.10/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
24630 ++++ linux-2.6.27.10/grsecurity/grsec_mount.c 2008-11-18 03:38:45.000000000 -0500
24631 +@@ -0,0 +1,34 @@
24632 ++#include <linux/kernel.h>
24633 ++#include <linux/sched.h>
24634 ++#include <linux/grsecurity.h>
24635 ++#include <linux/grinternal.h>
24636 ++
24637 ++void
24638 ++gr_log_remount(const char *devname, const int retval)
24639 ++{
24640 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24641 ++ if (grsec_enable_mount && (retval >= 0))
24642 ++ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
24643 ++#endif
24644 ++ return;
24645 ++}
24646 ++
24647 ++void
24648 ++gr_log_unmount(const char *devname, const int retval)
24649 ++{
24650 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24651 ++ if (grsec_enable_mount && (retval >= 0))
24652 ++ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
24653 ++#endif
24654 ++ return;
24655 ++}
24656 ++
24657 ++void
24658 ++gr_log_mount(const char *from, const char *to, const int retval)
24659 ++{
24660 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24661 ++ if (grsec_enable_mount && (retval >= 0))
24662 ++ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
24663 ++#endif
24664 ++ return;
24665 ++}
24666 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sig.c linux-2.6.27.10/grsecurity/grsec_sig.c
24667 +--- linux-2.6.27.10/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
24668 ++++ linux-2.6.27.10/grsecurity/grsec_sig.c 2008-11-18 03:38:45.000000000 -0500
24669 +@@ -0,0 +1,58 @@
24670 ++#include <linux/kernel.h>
24671 ++#include <linux/sched.h>
24672 ++#include <linux/delay.h>
24673 ++#include <linux/grsecurity.h>
24674 ++#include <linux/grinternal.h>
24675 ++
24676 ++void
24677 ++gr_log_signal(const int sig, const struct task_struct *t)
24678 ++{
24679 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
24680 ++ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
24681 ++ (sig == SIGABRT) || (sig == SIGBUS))) {
24682 ++ if (t->pid == current->pid) {
24683 ++ gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig);
24684 ++ } else {
24685 ++ gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
24686 ++ }
24687 ++ }
24688 ++#endif
24689 ++ return;
24690 ++}
24691 ++
24692 ++int
24693 ++gr_handle_signal(const struct task_struct *p, const int sig)
24694 ++{
24695 ++#ifdef CONFIG_GRKERNSEC
24696 ++ if (current->pid > 1 && gr_check_protected_task(p)) {
24697 ++ gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
24698 ++ return -EPERM;
24699 ++ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
24700 ++ return -EPERM;
24701 ++ }
24702 ++#endif
24703 ++ return 0;
24704 ++}
24705 ++
24706 ++void gr_handle_brute_attach(struct task_struct *p)
24707 ++{
24708 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24709 ++ read_lock(&tasklist_lock);
24710 ++ read_lock(&grsec_exec_file_lock);
24711 ++ if (p->parent && p->parent->exec_file == p->exec_file)
24712 ++ p->parent->brute = 1;
24713 ++ read_unlock(&grsec_exec_file_lock);
24714 ++ read_unlock(&tasklist_lock);
24715 ++#endif
24716 ++ return;
24717 ++}
24718 ++
24719 ++void gr_handle_brute_check(void)
24720 ++{
24721 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24722 ++ if (current->brute)
24723 ++ msleep(30 * 1000);
24724 ++#endif
24725 ++ return;
24726 ++}
24727 ++
24728 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sock.c linux-2.6.27.10/grsecurity/grsec_sock.c
24729 +--- linux-2.6.27.10/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
24730 ++++ linux-2.6.27.10/grsecurity/grsec_sock.c 2008-11-18 11:35:13.000000000 -0500
24731 +@@ -0,0 +1,274 @@
24732 ++#include <linux/kernel.h>
24733 ++#include <linux/module.h>
24734 ++#include <linux/sched.h>
24735 ++#include <linux/file.h>
24736 ++#include <linux/net.h>
24737 ++#include <linux/in.h>
24738 ++#include <linux/ip.h>
24739 ++#include <net/sock.h>
24740 ++#include <net/inet_sock.h>
24741 ++#include <linux/grsecurity.h>
24742 ++#include <linux/grinternal.h>
24743 ++#include <linux/gracl.h>
24744 ++
24745 ++#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
24746 ++extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
24747 ++EXPORT_SYMBOL(udp_v4_lookup);
24748 ++#endif
24749 ++
24750 ++kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
24751 ++EXPORT_SYMBOL(gr_cap_rtnetlink);
24752 ++
24753 ++extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
24754 ++extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
24755 ++
24756 ++EXPORT_SYMBOL(gr_search_udp_recvmsg);
24757 ++EXPORT_SYMBOL(gr_search_udp_sendmsg);
24758 ++
24759 ++#ifdef CONFIG_UNIX_MODULE
24760 ++EXPORT_SYMBOL(gr_acl_handle_unix);
24761 ++EXPORT_SYMBOL(gr_acl_handle_mknod);
24762 ++EXPORT_SYMBOL(gr_handle_chroot_unix);
24763 ++EXPORT_SYMBOL(gr_handle_create);
24764 ++#endif
24765 ++
24766 ++#ifdef CONFIG_GRKERNSEC
24767 ++#define gr_conn_table_size 32749
24768 ++struct conn_table_entry {
24769 ++ struct conn_table_entry *next;
24770 ++ struct signal_struct *sig;
24771 ++};
24772 ++
24773 ++struct conn_table_entry *gr_conn_table[gr_conn_table_size];
24774 ++DEFINE_SPINLOCK(gr_conn_table_lock);
24775 ++
24776 ++extern const char * gr_socktype_to_name(unsigned char type);
24777 ++extern const char * gr_proto_to_name(unsigned char proto);
24778 ++
24779 ++static __inline__ int
24780 ++conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
24781 ++{
24782 ++ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
24783 ++}
24784 ++
24785 ++static __inline__ int
24786 ++conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
24787 ++ __u16 sport, __u16 dport)
24788 ++{
24789 ++ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
24790 ++ sig->gr_sport == sport && sig->gr_dport == dport))
24791 ++ return 1;
24792 ++ else
24793 ++ return 0;
24794 ++}
24795 ++
24796 ++static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
24797 ++{
24798 ++ struct conn_table_entry **match;
24799 ++ unsigned int index;
24800 ++
24801 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24802 ++ sig->gr_sport, sig->gr_dport,
24803 ++ gr_conn_table_size);
24804 ++
24805 ++ newent->sig = sig;
24806 ++
24807 ++ match = &gr_conn_table[index];
24808 ++ newent->next = *match;
24809 ++ *match = newent;
24810 ++
24811 ++ return;
24812 ++}
24813 ++
24814 ++static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
24815 ++{
24816 ++ struct conn_table_entry *match, *last = NULL;
24817 ++ unsigned int index;
24818 ++
24819 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24820 ++ sig->gr_sport, sig->gr_dport,
24821 ++ gr_conn_table_size);
24822 ++
24823 ++ match = gr_conn_table[index];
24824 ++ while (match && !conn_match(match->sig,
24825 ++ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
24826 ++ sig->gr_dport)) {
24827 ++ last = match;
24828 ++ match = match->next;
24829 ++ }
24830 ++
24831 ++ if (match) {
24832 ++ if (last)
24833 ++ last->next = match->next;
24834 ++ else
24835 ++ gr_conn_table[index] = NULL;
24836 ++ kfree(match);
24837 ++ }
24838 ++
24839 ++ return;
24840 ++}
24841 ++
24842 ++static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
24843 ++ __u16 sport, __u16 dport)
24844 ++{
24845 ++ struct conn_table_entry *match;
24846 ++ unsigned int index;
24847 ++
24848 ++ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
24849 ++
24850 ++ match = gr_conn_table[index];
24851 ++ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
24852 ++ match = match->next;
24853 ++
24854 ++ if (match)
24855 ++ return match->sig;
24856 ++ else
24857 ++ return NULL;
24858 ++}
24859 ++
24860 ++#endif
24861 ++
24862 ++void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
24863 ++{
24864 ++#ifdef CONFIG_GRKERNSEC
24865 ++ struct signal_struct *sig = task->signal;
24866 ++ struct conn_table_entry *newent;
24867 ++
24868 ++ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
24869 ++ if (newent == NULL)
24870 ++ return;
24871 ++ /* no bh lock needed since we are called with bh disabled */
24872 ++ spin_lock(&gr_conn_table_lock);
24873 ++ gr_del_task_from_ip_table_nolock(sig);
24874 ++ sig->gr_saddr = inet->rcv_saddr;
24875 ++ sig->gr_daddr = inet->daddr;
24876 ++ sig->gr_sport = inet->sport;
24877 ++ sig->gr_dport = inet->dport;
24878 ++ gr_add_to_task_ip_table_nolock(sig, newent);
24879 ++ spin_unlock(&gr_conn_table_lock);
24880 ++#endif
24881 ++ return;
24882 ++}
24883 ++
24884 ++void gr_del_task_from_ip_table(struct task_struct *task)
24885 ++{
24886 ++#ifdef CONFIG_GRKERNSEC
24887 ++ spin_lock_bh(&gr_conn_table_lock);
24888 ++ gr_del_task_from_ip_table_nolock(task->signal);
24889 ++ spin_unlock_bh(&gr_conn_table_lock);
24890 ++#endif
24891 ++ return;
24892 ++}
24893 ++
24894 ++void
24895 ++gr_attach_curr_ip(const struct sock *sk)
24896 ++{
24897 ++#ifdef CONFIG_GRKERNSEC
24898 ++ struct signal_struct *p, *set;
24899 ++ const struct inet_sock *inet = inet_sk(sk);
24900 ++
24901 ++ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
24902 ++ return;
24903 ++
24904 ++ set = current->signal;
24905 ++
24906 ++ spin_lock_bh(&gr_conn_table_lock);
24907 ++ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
24908 ++ inet->dport, inet->sport);
24909 ++ if (unlikely(p != NULL)) {
24910 ++ set->curr_ip = p->curr_ip;
24911 ++ set->used_accept = 1;
24912 ++ gr_del_task_from_ip_table_nolock(p);
24913 ++ spin_unlock_bh(&gr_conn_table_lock);
24914 ++ return;
24915 ++ }
24916 ++ spin_unlock_bh(&gr_conn_table_lock);
24917 ++
24918 ++ set->curr_ip = inet->daddr;
24919 ++ set->used_accept = 1;
24920 ++#endif
24921 ++ return;
24922 ++}
24923 ++
24924 ++int
24925 ++gr_handle_sock_all(const int family, const int type, const int protocol)
24926 ++{
24927 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24928 ++ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
24929 ++ (family != AF_UNIX) && (family != AF_LOCAL)) {
24930 ++ gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol));
24931 ++ return -EACCES;
24932 ++ }
24933 ++#endif
24934 ++ return 0;
24935 ++}
24936 ++
24937 ++int
24938 ++gr_handle_sock_server(const struct sockaddr *sck)
24939 ++{
24940 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24941 ++ if (grsec_enable_socket_server &&
24942 ++ in_group_p(grsec_socket_server_gid) &&
24943 ++ sck && (sck->sa_family != AF_UNIX) &&
24944 ++ (sck->sa_family != AF_LOCAL)) {
24945 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24946 ++ return -EACCES;
24947 ++ }
24948 ++#endif
24949 ++ return 0;
24950 ++}
24951 ++
24952 ++int
24953 ++gr_handle_sock_server_other(const struct sock *sck)
24954 ++{
24955 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24956 ++ if (grsec_enable_socket_server &&
24957 ++ in_group_p(grsec_socket_server_gid) &&
24958 ++ sck && (sck->sk_family != AF_UNIX) &&
24959 ++ (sck->sk_family != AF_LOCAL)) {
24960 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24961 ++ return -EACCES;
24962 ++ }
24963 ++#endif
24964 ++ return 0;
24965 ++}
24966 ++
24967 ++int
24968 ++gr_handle_sock_client(const struct sockaddr *sck)
24969 ++{
24970 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24971 ++ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
24972 ++ sck && (sck->sa_family != AF_UNIX) &&
24973 ++ (sck->sa_family != AF_LOCAL)) {
24974 ++ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
24975 ++ return -EACCES;
24976 ++ }
24977 ++#endif
24978 ++ return 0;
24979 ++}
24980 ++
24981 ++kernel_cap_t
24982 ++gr_cap_rtnetlink(struct sock *sock)
24983 ++{
24984 ++#ifdef CONFIG_GRKERNSEC
24985 ++ if (!gr_acl_is_enabled())
24986 ++ return current->cap_effective;
24987 ++ else if (sock->sk_protocol == NETLINK_ISCSI &&
24988 ++ cap_raised(current->cap_effective, CAP_SYS_ADMIN) &&
24989 ++ gr_task_is_capable(current, CAP_SYS_ADMIN))
24990 ++ return current->cap_effective;
24991 ++ else if (sock->sk_protocol == NETLINK_AUDIT &&
24992 ++ cap_raised(current->cap_effective, CAP_AUDIT_WRITE) &&
24993 ++ gr_task_is_capable(current, CAP_AUDIT_WRITE) &&
24994 ++ cap_raised(current->cap_effective, CAP_AUDIT_CONTROL) &&
24995 ++ gr_task_is_capable(current, CAP_AUDIT_CONTROL))
24996 ++ return current->cap_effective;
24997 ++ else if (cap_raised(current->cap_effective, CAP_NET_ADMIN) &&
24998 ++ gr_task_is_capable(current, CAP_NET_ADMIN))
24999 ++ return current->cap_effective;
25000 ++ else
25001 ++ return __cap_empty_set;
25002 ++#else
25003 ++ return current->cap_effective;
25004 ++#endif
25005 ++}
25006 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sysctl.c linux-2.6.27.10/grsecurity/grsec_sysctl.c
25007 +--- linux-2.6.27.10/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
25008 ++++ linux-2.6.27.10/grsecurity/grsec_sysctl.c 2008-11-18 03:38:45.000000000 -0500
25009 +@@ -0,0 +1,435 @@
25010 ++#include <linux/kernel.h>
25011 ++#include <linux/sched.h>
25012 ++#include <linux/sysctl.h>
25013 ++#include <linux/grsecurity.h>
25014 ++#include <linux/grinternal.h>
25015 ++
25016 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25017 ++int grsec_modstop;
25018 ++#endif
25019 ++
25020 ++int
25021 ++gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
25022 ++{
25023 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
25024 ++ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
25025 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
25026 ++ return -EACCES;
25027 ++ }
25028 ++#endif
25029 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25030 ++ if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") &&
25031 ++ grsec_modstop && (op & MAY_WRITE)) {
25032 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
25033 ++ return -EACCES;
25034 ++ }
25035 ++#endif
25036 ++ return 0;
25037 ++}
25038 ++
25039 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
25040 ++ctl_table grsecurity_table[] = {
25041 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
25042 ++#ifdef CONFIG_GRKERNSEC_LINK
25043 ++ {
25044 ++ .ctl_name = CTL_UNNUMBERED,
25045 ++ .procname = "linking_restrictions",
25046 ++ .data = &grsec_enable_link,
25047 ++ .maxlen = sizeof(int),
25048 ++ .mode = 0600,
25049 ++ .proc_handler = &proc_dointvec,
25050 ++ },
25051 ++#endif
25052 ++#ifdef CONFIG_GRKERNSEC_FIFO
25053 ++ {
25054 ++ .ctl_name = CTL_UNNUMBERED,
25055 ++ .procname = "fifo_restrictions",
25056 ++ .data = &grsec_enable_fifo,
25057 ++ .maxlen = sizeof(int),
25058 ++ .mode = 0600,
25059 ++ .proc_handler = &proc_dointvec,
25060 ++ },
25061 ++#endif
25062 ++#ifdef CONFIG_GRKERNSEC_EXECVE
25063 ++ {
25064 ++ .ctl_name = CTL_UNNUMBERED,
25065 ++ .procname = "execve_limiting",
25066 ++ .data = &grsec_enable_execve,
25067 ++ .maxlen = sizeof(int),
25068 ++ .mode = 0600,
25069 ++ .proc_handler = &proc_dointvec,
25070 ++ },
25071 ++#endif
25072 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
25073 ++ {
25074 ++ .ctl_name = CTL_UNNUMBERED,
25075 ++ .procname = "exec_logging",
25076 ++ .data = &grsec_enable_execlog,
25077 ++ .maxlen = sizeof(int),
25078 ++ .mode = 0600,
25079 ++ .proc_handler = &proc_dointvec,
25080 ++ },
25081 ++#endif
25082 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
25083 ++ {
25084 ++ .ctl_name = CTL_UNNUMBERED,
25085 ++ .procname = "signal_logging",
25086 ++ .data = &grsec_enable_signal,
25087 ++ .maxlen = sizeof(int),
25088 ++ .mode = 0600,
25089 ++ .proc_handler = &proc_dointvec,
25090 ++ },
25091 ++#endif
25092 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
25093 ++ {
25094 ++ .ctl_name = CTL_UNNUMBERED,
25095 ++ .procname = "forkfail_logging",
25096 ++ .data = &grsec_enable_forkfail,
25097 ++ .maxlen = sizeof(int),
25098 ++ .mode = 0600,
25099 ++ .proc_handler = &proc_dointvec,
25100 ++ },
25101 ++#endif
25102 ++#ifdef CONFIG_GRKERNSEC_TIME
25103 ++ {
25104 ++ .ctl_name = CTL_UNNUMBERED,
25105 ++ .procname = "timechange_logging",
25106 ++ .data = &grsec_enable_time,
25107 ++ .maxlen = sizeof(int),
25108 ++ .mode = 0600,
25109 ++ .proc_handler = &proc_dointvec,
25110 ++ },
25111 ++#endif
25112 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
25113 ++ {
25114 ++ .ctl_name = CTL_UNNUMBERED,
25115 ++ .procname = "chroot_deny_shmat",
25116 ++ .data = &grsec_enable_chroot_shmat,
25117 ++ .maxlen = sizeof(int),
25118 ++ .mode = 0600,
25119 ++ .proc_handler = &proc_dointvec,
25120 ++ },
25121 ++#endif
25122 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
25123 ++ {
25124 ++ .ctl_name = CTL_UNNUMBERED,
25125 ++ .procname = "chroot_deny_unix",
25126 ++ .data = &grsec_enable_chroot_unix,
25127 ++ .maxlen = sizeof(int),
25128 ++ .mode = 0600,
25129 ++ .proc_handler = &proc_dointvec,
25130 ++ },
25131 ++#endif
25132 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
25133 ++ {
25134 ++ .ctl_name = CTL_UNNUMBERED,
25135 ++ .procname = "chroot_deny_mount",
25136 ++ .data = &grsec_enable_chroot_mount,
25137 ++ .maxlen = sizeof(int),
25138 ++ .mode = 0600,
25139 ++ .proc_handler = &proc_dointvec,
25140 ++ },
25141 ++#endif
25142 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
25143 ++ {
25144 ++ .ctl_name = CTL_UNNUMBERED,
25145 ++ .procname = "chroot_deny_fchdir",
25146 ++ .data = &grsec_enable_chroot_fchdir,
25147 ++ .maxlen = sizeof(int),
25148 ++ .mode = 0600,
25149 ++ .proc_handler = &proc_dointvec,
25150 ++ },
25151 ++#endif
25152 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
25153 ++ {
25154 ++ .ctl_name = CTL_UNNUMBERED,
25155 ++ .procname = "chroot_deny_chroot",
25156 ++ .data = &grsec_enable_chroot_double,
25157 ++ .maxlen = sizeof(int),
25158 ++ .mode = 0600,
25159 ++ .proc_handler = &proc_dointvec,
25160 ++ },
25161 ++#endif
25162 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
25163 ++ {
25164 ++ .ctl_name = CTL_UNNUMBERED,
25165 ++ .procname = "chroot_deny_pivot",
25166 ++ .data = &grsec_enable_chroot_pivot,
25167 ++ .maxlen = sizeof(int),
25168 ++ .mode = 0600,
25169 ++ .proc_handler = &proc_dointvec,
25170 ++ },
25171 ++#endif
25172 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
25173 ++ {
25174 ++ .ctl_name = CTL_UNNUMBERED,
25175 ++ .procname = "chroot_enforce_chdir",
25176 ++ .data = &grsec_enable_chroot_chdir,
25177 ++ .maxlen = sizeof(int),
25178 ++ .mode = 0600,
25179 ++ .proc_handler = &proc_dointvec,
25180 ++ },
25181 ++#endif
25182 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
25183 ++ {
25184 ++ .ctl_name = CTL_UNNUMBERED,
25185 ++ .procname = "chroot_deny_chmod",
25186 ++ .data = &grsec_enable_chroot_chmod,
25187 ++ .maxlen = sizeof(int),
25188 ++ .mode = 0600,
25189 ++ .proc_handler = &proc_dointvec,
25190 ++ },
25191 ++#endif
25192 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
25193 ++ {
25194 ++ .ctl_name = CTL_UNNUMBERED,
25195 ++ .procname = "chroot_deny_mknod",
25196 ++ .data = &grsec_enable_chroot_mknod,
25197 ++ .maxlen = sizeof(int),
25198 ++ .mode = 0600,
25199 ++ .proc_handler = &proc_dointvec,
25200 ++ },
25201 ++#endif
25202 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
25203 ++ {
25204 ++ .ctl_name = CTL_UNNUMBERED,
25205 ++ .procname = "chroot_restrict_nice",
25206 ++ .data = &grsec_enable_chroot_nice,
25207 ++ .maxlen = sizeof(int),
25208 ++ .mode = 0600,
25209 ++ .proc_handler = &proc_dointvec,
25210 ++ },
25211 ++#endif
25212 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
25213 ++ {
25214 ++ .ctl_name = CTL_UNNUMBERED,
25215 ++ .procname = "chroot_execlog",
25216 ++ .data = &grsec_enable_chroot_execlog,
25217 ++ .maxlen = sizeof(int),
25218 ++ .mode = 0600,
25219 ++ .proc_handler = &proc_dointvec,
25220 ++ },
25221 ++#endif
25222 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
25223 ++ {
25224 ++ .ctl_name = CTL_UNNUMBERED,
25225 ++ .procname = "chroot_caps",
25226 ++ .data = &grsec_enable_chroot_caps,
25227 ++ .maxlen = sizeof(int),
25228 ++ .mode = 0600,
25229 ++ .proc_handler = &proc_dointvec,
25230 ++ },
25231 ++#endif
25232 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
25233 ++ {
25234 ++ .ctl_name = CTL_UNNUMBERED,
25235 ++ .procname = "chroot_deny_sysctl",
25236 ++ .data = &grsec_enable_chroot_sysctl,
25237 ++ .maxlen = sizeof(int),
25238 ++ .mode = 0600,
25239 ++ .proc_handler = &proc_dointvec,
25240 ++ },
25241 ++#endif
25242 ++#ifdef CONFIG_GRKERNSEC_TPE
25243 ++ {
25244 ++ .ctl_name = CTL_UNNUMBERED,
25245 ++ .procname = "tpe",
25246 ++ .data = &grsec_enable_tpe,
25247 ++ .maxlen = sizeof(int),
25248 ++ .mode = 0600,
25249 ++ .proc_handler = &proc_dointvec,
25250 ++ },
25251 ++ {
25252 ++ .ctl_name = CTL_UNNUMBERED,
25253 ++ .procname = "tpe_gid",
25254 ++ .data = &grsec_tpe_gid,
25255 ++ .maxlen = sizeof(int),
25256 ++ .mode = 0600,
25257 ++ .proc_handler = &proc_dointvec,
25258 ++ },
25259 ++#endif
25260 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25261 ++ {
25262 ++ .ctl_name = CTL_UNNUMBERED,
25263 ++ .procname = "tpe_restrict_all",
25264 ++ .data = &grsec_enable_tpe_all,
25265 ++ .maxlen = sizeof(int),
25266 ++ .mode = 0600,
25267 ++ .proc_handler = &proc_dointvec,
25268 ++ },
25269 ++#endif
25270 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
25271 ++ {
25272 ++ .ctl_name = CTL_UNNUMBERED,
25273 ++ .procname = "socket_all",
25274 ++ .data = &grsec_enable_socket_all,
25275 ++ .maxlen = sizeof(int),
25276 ++ .mode = 0600,
25277 ++ .proc_handler = &proc_dointvec,
25278 ++ },
25279 ++ {
25280 ++ .ctl_name = CTL_UNNUMBERED,
25281 ++ .procname = "socket_all_gid",
25282 ++ .data = &grsec_socket_all_gid,
25283 ++ .maxlen = sizeof(int),
25284 ++ .mode = 0600,
25285 ++ .proc_handler = &proc_dointvec,
25286 ++ },
25287 ++#endif
25288 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
25289 ++ {
25290 ++ .ctl_name = CTL_UNNUMBERED,
25291 ++ .procname = "socket_client",
25292 ++ .data = &grsec_enable_socket_client,
25293 ++ .maxlen = sizeof(int),
25294 ++ .mode = 0600,
25295 ++ .proc_handler = &proc_dointvec,
25296 ++ },
25297 ++ {
25298 ++ .ctl_name = CTL_UNNUMBERED,
25299 ++ .procname = "socket_client_gid",
25300 ++ .data = &grsec_socket_client_gid,
25301 ++ .maxlen = sizeof(int),
25302 ++ .mode = 0600,
25303 ++ .proc_handler = &proc_dointvec,
25304 ++ },
25305 ++#endif
25306 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
25307 ++ {
25308 ++ .ctl_name = CTL_UNNUMBERED,
25309 ++ .procname = "socket_server",
25310 ++ .data = &grsec_enable_socket_server,
25311 ++ .maxlen = sizeof(int),
25312 ++ .mode = 0600,
25313 ++ .proc_handler = &proc_dointvec,
25314 ++ },
25315 ++ {
25316 ++ .ctl_name = CTL_UNNUMBERED,
25317 ++ .procname = "socket_server_gid",
25318 ++ .data = &grsec_socket_server_gid,
25319 ++ .maxlen = sizeof(int),
25320 ++ .mode = 0600,
25321 ++ .proc_handler = &proc_dointvec,
25322 ++ },
25323 ++#endif
25324 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
25325 ++ {
25326 ++ .ctl_name = CTL_UNNUMBERED,
25327 ++ .procname = "audit_group",
25328 ++ .data = &grsec_enable_group,
25329 ++ .maxlen = sizeof(int),
25330 ++ .mode = 0600,
25331 ++ .proc_handler = &proc_dointvec,
25332 ++ },
25333 ++ {
25334 ++ .ctl_name = CTL_UNNUMBERED,
25335 ++ .procname = "audit_gid",
25336 ++ .data = &grsec_audit_gid,
25337 ++ .maxlen = sizeof(int),
25338 ++ .mode = 0600,
25339 ++ .proc_handler = &proc_dointvec,
25340 ++ },
25341 ++#endif
25342 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
25343 ++ {
25344 ++ .ctl_name = CTL_UNNUMBERED,
25345 ++ .procname = "audit_chdir",
25346 ++ .data = &grsec_enable_chdir,
25347 ++ .maxlen = sizeof(int),
25348 ++ .mode = 0600,
25349 ++ .proc_handler = &proc_dointvec,
25350 ++ },
25351 ++#endif
25352 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
25353 ++ {
25354 ++ .ctl_name = CTL_UNNUMBERED,
25355 ++ .procname = "audit_mount",
25356 ++ .data = &grsec_enable_mount,
25357 ++ .maxlen = sizeof(int),
25358 ++ .mode = 0600,
25359 ++ .proc_handler = &proc_dointvec,
25360 ++ },
25361 ++#endif
25362 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25363 ++ {
25364 ++ .ctl_name = CTL_UNNUMBERED,
25365 ++ .procname = "audit_ipc",
25366 ++ .data = &grsec_enable_audit_ipc,
25367 ++ .maxlen = sizeof(int),
25368 ++ .mode = 0600,
25369 ++ .proc_handler = &proc_dointvec,
25370 ++ },
25371 ++#endif
25372 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25373 ++ {
25374 ++ .ctl_name = CTL_UNNUMBERED,
25375 ++ .procname = "audit_textrel",
25376 ++ .data = &grsec_enable_audit_textrel,
25377 ++ .maxlen = sizeof(int),
25378 ++ .mode = 0600,
25379 ++ .proc_handler = &proc_dointvec,
25380 ++ },
25381 ++#endif
25382 ++#ifdef CONFIG_GRKERNSEC_DMESG
25383 ++ {
25384 ++ .ctl_name = CTL_UNNUMBERED,
25385 ++ .procname = "dmesg",
25386 ++ .data = &grsec_enable_dmesg,
25387 ++ .maxlen = sizeof(int),
25388 ++ .mode = 0600,
25389 ++ .proc_handler = &proc_dointvec,
25390 ++ },
25391 ++#endif
25392 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
25393 ++ {
25394 ++ .ctl_name = CTL_UNNUMBERED,
25395 ++ .procname = "chroot_findtask",
25396 ++ .data = &grsec_enable_chroot_findtask,
25397 ++ .maxlen = sizeof(int),
25398 ++ .mode = 0600,
25399 ++ .proc_handler = &proc_dointvec,
25400 ++ },
25401 ++#endif
25402 ++#ifdef CONFIG_GRKERNSEC_RESLOG
25403 ++ {
25404 ++ .ctl_name = CTL_UNNUMBERED,
25405 ++ .procname = "resource_logging",
25406 ++ .data = &grsec_resource_logging,
25407 ++ .maxlen = sizeof(int),
25408 ++ .mode = 0600,
25409 ++ .proc_handler = &proc_dointvec,
25410 ++ },
25411 ++#endif
25412 ++ {
25413 ++ .ctl_name = CTL_UNNUMBERED,
25414 ++ .procname = "grsec_lock",
25415 ++ .data = &grsec_lock,
25416 ++ .maxlen = sizeof(int),
25417 ++ .mode = 0600,
25418 ++ .proc_handler = &proc_dointvec,
25419 ++ },
25420 ++#endif
25421 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25422 ++ {
25423 ++ .ctl_name = CTL_UNNUMBERED,
25424 ++ .procname = "disable_modules",
25425 ++ .data = &grsec_modstop,
25426 ++ .maxlen = sizeof(int),
25427 ++ .mode = 0600,
25428 ++ .proc_handler = &proc_dointvec,
25429 ++ },
25430 ++#endif
25431 ++ { .ctl_name = 0 }
25432 ++};
25433 ++#endif
25434 ++
25435 ++int gr_check_modstop(void)
25436 ++{
25437 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25438 ++ if (grsec_modstop == 1) {
25439 ++ gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG);
25440 ++ return 1;
25441 ++ }
25442 ++#endif
25443 ++ return 0;
25444 ++}
25445 +diff -urNp linux-2.6.27.10/grsecurity/grsec_textrel.c linux-2.6.27.10/grsecurity/grsec_textrel.c
25446 +--- linux-2.6.27.10/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500
25447 ++++ linux-2.6.27.10/grsecurity/grsec_textrel.c 2008-11-18 03:38:45.000000000 -0500
25448 +@@ -0,0 +1,16 @@
25449 ++#include <linux/kernel.h>
25450 ++#include <linux/sched.h>
25451 ++#include <linux/mm.h>
25452 ++#include <linux/file.h>
25453 ++#include <linux/grinternal.h>
25454 ++#include <linux/grsecurity.h>
25455 ++
25456 ++void
25457 ++gr_log_textrel(struct vm_area_struct * vma)
25458 ++{
25459 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25460 ++ if (grsec_enable_audit_textrel)
25461 ++ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
25462 ++#endif
25463 ++ return;
25464 ++}
25465 +diff -urNp linux-2.6.27.10/grsecurity/grsec_time.c linux-2.6.27.10/grsecurity/grsec_time.c
25466 +--- linux-2.6.27.10/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
25467 ++++ linux-2.6.27.10/grsecurity/grsec_time.c 2008-11-18 03:38:45.000000000 -0500
25468 +@@ -0,0 +1,13 @@
25469 ++#include <linux/kernel.h>
25470 ++#include <linux/sched.h>
25471 ++#include <linux/grinternal.h>
25472 ++
25473 ++void
25474 ++gr_log_timechange(void)
25475 ++{
25476 ++#ifdef CONFIG_GRKERNSEC_TIME
25477 ++ if (grsec_enable_time)
25478 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
25479 ++#endif
25480 ++ return;
25481 ++}
25482 +diff -urNp linux-2.6.27.10/grsecurity/grsec_tpe.c linux-2.6.27.10/grsecurity/grsec_tpe.c
25483 +--- linux-2.6.27.10/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
25484 ++++ linux-2.6.27.10/grsecurity/grsec_tpe.c 2008-11-18 03:38:45.000000000 -0500
25485 +@@ -0,0 +1,37 @@
25486 ++#include <linux/kernel.h>
25487 ++#include <linux/sched.h>
25488 ++#include <linux/file.h>
25489 ++#include <linux/fs.h>
25490 ++#include <linux/grinternal.h>
25491 ++
25492 ++extern int gr_acl_tpe_check(void);
25493 ++
25494 ++int
25495 ++gr_tpe_allow(const struct file *file)
25496 ++{
25497 ++#ifdef CONFIG_GRKERNSEC
25498 ++ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
25499 ++
25500 ++ if (current->uid && ((grsec_enable_tpe &&
25501 ++#ifdef CONFIG_GRKERNSEC_TPE_INVERT
25502 ++ !in_group_p(grsec_tpe_gid)
25503 ++#else
25504 ++ in_group_p(grsec_tpe_gid)
25505 ++#endif
25506 ++ ) || gr_acl_tpe_check()) &&
25507 ++ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
25508 ++ (inode->i_mode & S_IWOTH))))) {
25509 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25510 ++ return 0;
25511 ++ }
25512 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25513 ++ if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
25514 ++ ((inode->i_uid && (inode->i_uid != current->uid)) ||
25515 ++ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
25516 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25517 ++ return 0;
25518 ++ }
25519 ++#endif
25520 ++#endif
25521 ++ return 1;
25522 ++}
25523 +diff -urNp linux-2.6.27.10/grsecurity/grsum.c linux-2.6.27.10/grsecurity/grsum.c
25524 +--- linux-2.6.27.10/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
25525 ++++ linux-2.6.27.10/grsecurity/grsum.c 2008-11-18 03:38:45.000000000 -0500
25526 +@@ -0,0 +1,59 @@
25527 ++#include <linux/err.h>
25528 ++#include <linux/kernel.h>
25529 ++#include <linux/sched.h>
25530 ++#include <linux/mm.h>
25531 ++#include <linux/scatterlist.h>
25532 ++#include <linux/crypto.h>
25533 ++#include <linux/gracl.h>
25534 ++
25535 ++
25536 ++#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
25537 ++#error "crypto and sha256 must be built into the kernel"
25538 ++#endif
25539 ++
25540 ++int
25541 ++chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
25542 ++{
25543 ++ char *p;
25544 ++ struct crypto_hash *tfm;
25545 ++ struct hash_desc desc;
25546 ++ struct scatterlist sg;
25547 ++ unsigned char temp_sum[GR_SHA_LEN];
25548 ++ volatile int retval = 0;
25549 ++ volatile int dummy = 0;
25550 ++ unsigned int i;
25551 ++
25552 ++ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
25553 ++ if (IS_ERR(tfm)) {
25554 ++ /* should never happen, since sha256 should be built in */
25555 ++ return 1;
25556 ++ }
25557 ++
25558 ++ desc.tfm = tfm;
25559 ++ desc.flags = 0;
25560 ++
25561 ++ crypto_hash_init(&desc);
25562 ++
25563 ++ p = salt;
25564 ++ sg_set_buf(&sg, p, GR_SALT_LEN);
25565 ++ crypto_hash_update(&desc, &sg, sg.length);
25566 ++
25567 ++ p = entry->pw;
25568 ++ sg_set_buf(&sg, p, strlen(p));
25569 ++
25570 ++ crypto_hash_update(&desc, &sg, sg.length);
25571 ++
25572 ++ crypto_hash_final(&desc, temp_sum);
25573 ++
25574 ++ memset(entry->pw, 0, GR_PW_LEN);
25575 ++
25576 ++ for (i = 0; i < GR_SHA_LEN; i++)
25577 ++ if (sum[i] != temp_sum[i])
25578 ++ retval = 1;
25579 ++ else
25580 ++ dummy = 1; // waste a cycle
25581 ++
25582 ++ crypto_free_hash(tfm);
25583 ++
25584 ++ return retval;
25585 ++}
25586 +diff -urNp linux-2.6.27.10/grsecurity/Kconfig linux-2.6.27.10/grsecurity/Kconfig
25587 +--- linux-2.6.27.10/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
25588 ++++ linux-2.6.27.10/grsecurity/Kconfig 2008-11-18 11:18:57.000000000 -0500
25589 +@@ -0,0 +1,863 @@
25590 ++#
25591 ++# grecurity configuration
25592 ++#
25593 ++
25594 ++menu "Grsecurity"
25595 ++
25596 ++config GRKERNSEC
25597 ++ bool "Grsecurity"
25598 ++ select CRYPTO
25599 ++ select CRYPTO_SHA256
25600 ++ select SECURITY
25601 ++ select SECURITY_CAPABILITIES
25602 ++ help
25603 ++ If you say Y here, you will be able to configure many features
25604 ++ that will enhance the security of your system. It is highly
25605 ++ recommended that you say Y here and read through the help
25606 ++ for each option so that you fully understand the features and
25607 ++ can evaluate their usefulness for your machine.
25608 ++
25609 ++choice
25610 ++ prompt "Security Level"
25611 ++ depends on GRKERNSEC
25612 ++ default GRKERNSEC_CUSTOM
25613 ++
25614 ++config GRKERNSEC_LOW
25615 ++ bool "Low"
25616 ++ select GRKERNSEC_LINK
25617 ++ select GRKERNSEC_FIFO
25618 ++ select GRKERNSEC_EXECVE
25619 ++ select GRKERNSEC_RANDNET
25620 ++ select GRKERNSEC_DMESG
25621 ++ select GRKERNSEC_CHROOT_CHDIR
25622 ++ select GRKERNSEC_MODSTOP if (MODULES)
25623 ++
25624 ++ help
25625 ++ If you choose this option, several of the grsecurity options will
25626 ++ be enabled that will give you greater protection against a number
25627 ++ of attacks, while assuring that none of your software will have any
25628 ++ conflicts with the additional security measures. If you run a lot
25629 ++ of unusual software, or you are having problems with the higher
25630 ++ security levels, you should say Y here. With this option, the
25631 ++ following features are enabled:
25632 ++
25633 ++ - Linking restrictions
25634 ++ - FIFO restrictions
25635 ++ - Enforcing RLIMIT_NPROC on execve
25636 ++ - Restricted dmesg
25637 ++ - Enforced chdir("/") on chroot
25638 ++ - Runtime module disabling
25639 ++
25640 ++config GRKERNSEC_MEDIUM
25641 ++ bool "Medium"
25642 ++ select PAX
25643 ++ select PAX_EI_PAX
25644 ++ select PAX_PT_PAX_FLAGS
25645 ++ select PAX_HAVE_ACL_FLAGS
25646 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25647 ++ select GRKERNSEC_CHROOT_SYSCTL
25648 ++ select GRKERNSEC_LINK
25649 ++ select GRKERNSEC_FIFO
25650 ++ select GRKERNSEC_EXECVE
25651 ++ select GRKERNSEC_DMESG
25652 ++ select GRKERNSEC_RANDNET
25653 ++ select GRKERNSEC_FORKFAIL
25654 ++ select GRKERNSEC_TIME
25655 ++ select GRKERNSEC_SIGNAL
25656 ++ select GRKERNSEC_CHROOT
25657 ++ select GRKERNSEC_CHROOT_UNIX
25658 ++ select GRKERNSEC_CHROOT_MOUNT
25659 ++ select GRKERNSEC_CHROOT_PIVOT
25660 ++ select GRKERNSEC_CHROOT_DOUBLE
25661 ++ select GRKERNSEC_CHROOT_CHDIR
25662 ++ select GRKERNSEC_CHROOT_MKNOD
25663 ++ select GRKERNSEC_PROC
25664 ++ select GRKERNSEC_PROC_USERGROUP
25665 ++ select GRKERNSEC_MODSTOP if (MODULES)
25666 ++ select PAX_RANDUSTACK
25667 ++ select PAX_ASLR
25668 ++ select PAX_RANDMMAP
25669 ++ select PAX_REFCOUNT if (X86)
25670 ++
25671 ++ help
25672 ++ If you say Y here, several features in addition to those included
25673 ++ in the low additional security level will be enabled. These
25674 ++ features provide even more security to your system, though in rare
25675 ++ cases they may be incompatible with very old or poorly written
25676 ++ software. If you enable this option, make sure that your auth
25677 ++ service (identd) is running as gid 1001. With this option,
25678 ++ the following features (in addition to those provided in the
25679 ++ low additional security level) will be enabled:
25680 ++
25681 ++ - Failed fork logging
25682 ++ - Time change logging
25683 ++ - Signal logging
25684 ++ - Deny mounts in chroot
25685 ++ - Deny double chrooting
25686 ++ - Deny sysctl writes in chroot
25687 ++ - Deny mknod in chroot
25688 ++ - Deny access to abstract AF_UNIX sockets out of chroot
25689 ++ - Deny pivot_root in chroot
25690 ++ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
25691 ++ - /proc restrictions with special GID set to 10 (usually wheel)
25692 ++ - Address Space Layout Randomization (ASLR)
25693 ++
25694 ++config GRKERNSEC_HIGH
25695 ++ bool "High"
25696 ++ select GRKERNSEC_LINK
25697 ++ select GRKERNSEC_FIFO
25698 ++ select GRKERNSEC_EXECVE
25699 ++ select GRKERNSEC_DMESG
25700 ++ select GRKERNSEC_FORKFAIL
25701 ++ select GRKERNSEC_TIME
25702 ++ select GRKERNSEC_SIGNAL
25703 ++ select GRKERNSEC_CHROOT_SHMAT
25704 ++ select GRKERNSEC_CHROOT_UNIX
25705 ++ select GRKERNSEC_CHROOT_MOUNT
25706 ++ select GRKERNSEC_CHROOT_FCHDIR
25707 ++ select GRKERNSEC_CHROOT_PIVOT
25708 ++ select GRKERNSEC_CHROOT_DOUBLE
25709 ++ select GRKERNSEC_CHROOT_CHDIR
25710 ++ select GRKERNSEC_CHROOT_MKNOD
25711 ++ select GRKERNSEC_CHROOT_CAPS
25712 ++ select GRKERNSEC_CHROOT_SYSCTL
25713 ++ select GRKERNSEC_CHROOT_FINDTASK
25714 ++ select GRKERNSEC_PROC
25715 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25716 ++ select GRKERNSEC_HIDESYM
25717 ++ select GRKERNSEC_BRUTE
25718 ++ select GRKERNSEC_PROC_USERGROUP
25719 ++ select GRKERNSEC_KMEM
25720 ++ select GRKERNSEC_RESLOG
25721 ++ select GRKERNSEC_RANDNET
25722 ++ select GRKERNSEC_PROC_ADD
25723 ++ select GRKERNSEC_CHROOT_CHMOD
25724 ++ select GRKERNSEC_CHROOT_NICE
25725 ++ select GRKERNSEC_AUDIT_MOUNT
25726 ++ select GRKERNSEC_MODSTOP if (MODULES)
25727 ++ select PAX
25728 ++ select PAX_RANDUSTACK
25729 ++ select PAX_ASLR
25730 ++ select PAX_RANDMMAP
25731 ++ select PAX_NOEXEC
25732 ++ select PAX_MPROTECT
25733 ++ select PAX_EI_PAX
25734 ++ select PAX_PT_PAX_FLAGS
25735 ++ select PAX_HAVE_ACL_FLAGS
25736 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
25737 ++ select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO)
25738 ++ select PAX_RANDKSTACK if (X86_TSC && !X86_64)
25739 ++ select PAX_SEGMEXEC if (X86 && !X86_64)
25740 ++ select PAX_PAGEEXEC if (!X86)
25741 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
25742 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
25743 ++ select PAX_SYSCALL if (PPC32)
25744 ++ select PAX_EMUTRAMP if (PARISC)
25745 ++ select PAX_EMUSIGRT if (PARISC)
25746 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
25747 ++ select PAX_REFCOUNT if (X86)
25748 ++ help
25749 ++ If you say Y here, many of the features of grsecurity will be
25750 ++ enabled, which will protect you against many kinds of attacks
25751 ++ against your system. The heightened security comes at a cost
25752 ++ of an increased chance of incompatibilities with rare software
25753 ++ on your machine. Since this security level enables PaX, you should
25754 ++ view <http://pax.grsecurity.net> and read about the PaX
25755 ++ project. While you are there, download chpax and run it on
25756 ++ binaries that cause problems with PaX. Also remember that
25757 ++ since the /proc restrictions are enabled, you must run your
25758 ++ identd as gid 1001. This security level enables the following
25759 ++ features in addition to those listed in the low and medium
25760 ++ security levels:
25761 ++
25762 ++ - Additional /proc restrictions
25763 ++ - Chmod restrictions in chroot
25764 ++ - No signals, ptrace, or viewing of processes outside of chroot
25765 ++ - Capability restrictions in chroot
25766 ++ - Deny fchdir out of chroot
25767 ++ - Priority restrictions in chroot
25768 ++ - Segmentation-based implementation of PaX
25769 ++ - Mprotect restrictions
25770 ++ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
25771 ++ - Kernel stack randomization
25772 ++ - Mount/unmount/remount logging
25773 ++ - Kernel symbol hiding
25774 ++ - Prevention of memory exhaustion-based exploits
25775 ++config GRKERNSEC_CUSTOM
25776 ++ bool "Custom"
25777 ++ help
25778 ++ If you say Y here, you will be able to configure every grsecurity
25779 ++ option, which allows you to enable many more features that aren't
25780 ++ covered in the basic security levels. These additional features
25781 ++ include TPE, socket restrictions, and the sysctl system for
25782 ++ grsecurity. It is advised that you read through the help for
25783 ++ each option to determine its usefulness in your situation.
25784 ++
25785 ++endchoice
25786 ++
25787 ++menu "Address Space Protection"
25788 ++depends on GRKERNSEC
25789 ++
25790 ++config GRKERNSEC_KMEM
25791 ++ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
25792 ++ help
25793 ++ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
25794 ++ be written to via mmap or otherwise to modify the running kernel.
25795 ++ /dev/port will also not be allowed to be opened. If you have module
25796 ++ support disabled, enabling this will close up four ways that are
25797 ++ currently used to insert malicious code into the running kernel.
25798 ++ Even with all these features enabled, we still highly recommend that
25799 ++ you use the RBAC system, as it is still possible for an attacker to
25800 ++ modify the running kernel through privileged I/O granted by ioperm/iopl.
25801 ++ If you are not using XFree86, you may be able to stop this additional
25802 ++ case by enabling the 'Disable privileged I/O' option. Though nothing
25803 ++ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
25804 ++ but only to video memory, which is the only writing we allow in this
25805 ++ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
25806 ++ not be allowed to mprotect it with PROT_WRITE later.
25807 ++ It is highly recommended that you say Y here if you meet all the
25808 ++ conditions above.
25809 ++
25810 ++config GRKERNSEC_IO
25811 ++ bool "Disable privileged I/O"
25812 ++ depends on X86
25813 ++ select RTC
25814 ++ help
25815 ++ If you say Y here, all ioperm and iopl calls will return an error.
25816 ++ Ioperm and iopl can be used to modify the running kernel.
25817 ++ Unfortunately, some programs need this access to operate properly,
25818 ++ the most notable of which are XFree86 and hwclock. hwclock can be
25819 ++ remedied by having RTC support in the kernel, so CONFIG_RTC is
25820 ++ enabled if this option is enabled, to ensure that hwclock operates
25821 ++ correctly. XFree86 still will not operate correctly with this option
25822 ++ enabled, so DO NOT CHOOSE Y IF YOU USE XFree86. If you use XFree86
25823 ++ and you still want to protect your kernel against modification,
25824 ++ use the RBAC system.
25825 ++
25826 ++config GRKERNSEC_PROC_MEMMAP
25827 ++ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
25828 ++ depends on PAX_NOEXEC || PAX_ASLR
25829 ++ help
25830 ++ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
25831 ++ give no information about the addresses of its mappings if
25832 ++ PaX features that rely on random addresses are enabled on the task.
25833 ++ If you use PaX it is greatly recommended that you say Y here as it
25834 ++ closes up a hole that makes the full ASLR useless for suid
25835 ++ binaries.
25836 ++
25837 ++config GRKERNSEC_BRUTE
25838 ++ bool "Deter exploit bruteforcing"
25839 ++ help
25840 ++ If you say Y here, attempts to bruteforce exploits against forking
25841 ++ daemons such as apache or sshd will be deterred. When a child of a
25842 ++ forking daemon is killed by PaX or crashes due to an illegal
25843 ++ instruction, the parent process will be delayed 30 seconds upon every
25844 ++ subsequent fork until the administrator is able to assess the
25845 ++ situation and restart the daemon. It is recommended that you also
25846 ++ enable signal logging in the auditing section so that logs are
25847 ++ generated when a process performs an illegal instruction.
25848 ++
25849 ++config GRKERNSEC_MODSTOP
25850 ++ bool "Runtime module disabling"
25851 ++ depends on MODULES
25852 ++ help
25853 ++ If you say Y here, you will be able to disable the ability to (un)load
25854 ++ modules at runtime. This feature is useful if you need the ability
25855 ++ to load kernel modules at boot time, but do not want to allow an
25856 ++ attacker to load a rootkit kernel module into the system, or to remove
25857 ++ a loaded kernel module important to system functioning. You should
25858 ++ enable the /dev/mem protection feature as well, since rootkits can be
25859 ++ inserted into the kernel via other methods than kernel modules. Since
25860 ++ an untrusted module could still be loaded by modifying init scripts and
25861 ++ rebooting the system, it is also recommended that you enable the RBAC
25862 ++ system. If you enable this option, a sysctl option with name
25863 ++ "disable_modules" will be created. Setting this option to "1" disables
25864 ++ module loading. After this option is set, no further writes to it are
25865 ++ allowed until the system is rebooted.
25866 ++
25867 ++config GRKERNSEC_HIDESYM
25868 ++ bool "Hide kernel symbols"
25869 ++ help
25870 ++ If you say Y here, getting information on loaded modules, and
25871 ++ displaying all kernel symbols through a syscall will be restricted
25872 ++ to users with CAP_SYS_MODULE. This option is only effective
25873 ++ provided the following conditions are met:
25874 ++ 1) The kernel using grsecurity is not precompiled by some distribution
25875 ++ 2) You are using the RBAC system and hiding other files such as your
25876 ++ kernel image and System.map
25877 ++ 3) You have the additional /proc restrictions enabled, which removes
25878 ++ /proc/kcore
25879 ++ If the above conditions are met, this option will aid to provide a
25880 ++ useful protection against local and remote kernel exploitation of
25881 ++ overflows and arbitrary read/write vulnerabilities.
25882 ++
25883 ++endmenu
25884 ++menu "Role Based Access Control Options"
25885 ++depends on GRKERNSEC
25886 ++
25887 ++config GRKERNSEC_ACL_HIDEKERN
25888 ++ bool "Hide kernel processes"
25889 ++ help
25890 ++ If you say Y here, all kernel threads will be hidden to all
25891 ++ processes but those whose subject has the "view hidden processes"
25892 ++ flag.
25893 ++
25894 ++config GRKERNSEC_ACL_MAXTRIES
25895 ++ int "Maximum tries before password lockout"
25896 ++ default 3
25897 ++ help
25898 ++ This option enforces the maximum number of times a user can attempt
25899 ++ to authorize themselves with the grsecurity RBAC system before being
25900 ++ denied the ability to attempt authorization again for a specified time.
25901 ++ The lower the number, the harder it will be to brute-force a password.
25902 ++
25903 ++config GRKERNSEC_ACL_TIMEOUT
25904 ++ int "Time to wait after max password tries, in seconds"
25905 ++ default 30
25906 ++ help
25907 ++ This option specifies the time the user must wait after attempting to
25908 ++ authorize to the RBAC system with the maximum number of invalid
25909 ++ passwords. The higher the number, the harder it will be to brute-force
25910 ++ a password.
25911 ++
25912 ++endmenu
25913 ++menu "Filesystem Protections"
25914 ++depends on GRKERNSEC
25915 ++
25916 ++config GRKERNSEC_PROC
25917 ++ bool "Proc restrictions"
25918 ++ help
25919 ++ If you say Y here, the permissions of the /proc filesystem
25920 ++ will be altered to enhance system security and privacy. You MUST
25921 ++ choose either a user only restriction or a user and group restriction.
25922 ++ Depending upon the option you choose, you can either restrict users to
25923 ++ see only the processes they themselves run, or choose a group that can
25924 ++ view all processes and files normally restricted to root if you choose
25925 ++ the "restrict to user only" option. NOTE: If you're running identd as
25926 ++ a non-root user, you will have to run it as the group you specify here.
25927 ++
25928 ++config GRKERNSEC_PROC_USER
25929 ++ bool "Restrict /proc to user only"
25930 ++ depends on GRKERNSEC_PROC
25931 ++ help
25932 ++ If you say Y here, non-root users will only be able to view their own
25933 ++ processes, and restricts them from viewing network-related information,
25934 ++ and viewing kernel symbol and module information.
25935 ++
25936 ++config GRKERNSEC_PROC_USERGROUP
25937 ++ bool "Allow special group"
25938 ++ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
25939 ++ help
25940 ++ If you say Y here, you will be able to select a group that will be
25941 ++ able to view all processes, network-related information, and
25942 ++ kernel and symbol information. This option is useful if you want
25943 ++ to run identd as a non-root user.
25944 ++
25945 ++config GRKERNSEC_PROC_GID
25946 ++ int "GID for special group"
25947 ++ depends on GRKERNSEC_PROC_USERGROUP
25948 ++ default 1001
25949 ++
25950 ++config GRKERNSEC_PROC_ADD
25951 ++ bool "Additional restrictions"
25952 ++ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
25953 ++ help
25954 ++ If you say Y here, additional restrictions will be placed on
25955 ++ /proc that keep normal users from viewing device information and
25956 ++ slabinfo information that could be useful for exploits.
25957 ++
25958 ++config GRKERNSEC_LINK
25959 ++ bool "Linking restrictions"
25960 ++ help
25961 ++ If you say Y here, /tmp race exploits will be prevented, since users
25962 ++ will no longer be able to follow symlinks owned by other users in
25963 ++ world-writable +t directories (i.e. /tmp), unless the owner of the
25964 ++ symlink is the owner of the directory. users will also not be
25965 ++ able to hardlink to files they do not own. If the sysctl option is
25966 ++ enabled, a sysctl option with name "linking_restrictions" is created.
25967 ++
25968 ++config GRKERNSEC_FIFO
25969 ++ bool "FIFO restrictions"
25970 ++ help
25971 ++ If you say Y here, users will not be able to write to FIFOs they don't
25972 ++ own in world-writable +t directories (i.e. /tmp), unless the owner of
25973 ++ the FIFO is the same owner of the directory it's held in. If the sysctl
25974 ++ option is enabled, a sysctl option with name "fifo_restrictions" is
25975 ++ created.
25976 ++
25977 ++config GRKERNSEC_CHROOT
25978 ++ bool "Chroot jail restrictions"
25979 ++ help
25980 ++ If you say Y here, you will be able to choose several options that will
25981 ++ make breaking out of a chrooted jail much more difficult. If you
25982 ++ encounter no software incompatibilities with the following options, it
25983 ++ is recommended that you enable each one.
25984 ++
25985 ++config GRKERNSEC_CHROOT_MOUNT
25986 ++ bool "Deny mounts"
25987 ++ depends on GRKERNSEC_CHROOT
25988 ++ help
25989 ++ If you say Y here, processes inside a chroot will not be able to
25990 ++ mount or remount filesystems. If the sysctl option is enabled, a
25991 ++ sysctl option with name "chroot_deny_mount" is created.
25992 ++
25993 ++config GRKERNSEC_CHROOT_DOUBLE
25994 ++ bool "Deny double-chroots"
25995 ++ depends on GRKERNSEC_CHROOT
25996 ++ help
25997 ++ If you say Y here, processes inside a chroot will not be able to chroot
25998 ++ again outside the chroot. This is a widely used method of breaking
25999 ++ out of a chroot jail and should not be allowed. If the sysctl
26000 ++ option is enabled, a sysctl option with name
26001 ++ "chroot_deny_chroot" is created.
26002 ++
26003 ++config GRKERNSEC_CHROOT_PIVOT
26004 ++ bool "Deny pivot_root in chroot"
26005 ++ depends on GRKERNSEC_CHROOT
26006 ++ help
26007 ++ If you say Y here, processes inside a chroot will not be able to use
26008 ++ a function called pivot_root() that was introduced in Linux 2.3.41. It
26009 ++ works similar to chroot in that it changes the root filesystem. This
26010 ++ function could be misused in a chrooted process to attempt to break out
26011 ++ of the chroot, and therefore should not be allowed. If the sysctl
26012 ++ option is enabled, a sysctl option with name "chroot_deny_pivot" is
26013 ++ created.
26014 ++
26015 ++config GRKERNSEC_CHROOT_CHDIR
26016 ++ bool "Enforce chdir(\"/\") on all chroots"
26017 ++ depends on GRKERNSEC_CHROOT
26018 ++ help
26019 ++ If you say Y here, the current working directory of all newly-chrooted
26020 ++ applications will be set to the the root directory of the chroot.
26021 ++ The man page on chroot(2) states:
26022 ++ Note that this call does not change the current working
26023 ++ directory, so that `.' can be outside the tree rooted at
26024 ++ `/'. In particular, the super-user can escape from a
26025 ++ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
26026 ++
26027 ++ It is recommended that you say Y here, since it's not known to break
26028 ++ any software. If the sysctl option is enabled, a sysctl option with
26029 ++ name "chroot_enforce_chdir" is created.
26030 ++
26031 ++config GRKERNSEC_CHROOT_CHMOD
26032 ++ bool "Deny (f)chmod +s"
26033 ++ depends on GRKERNSEC_CHROOT
26034 ++ help
26035 ++ If you say Y here, processes inside a chroot will not be able to chmod
26036 ++ or fchmod files to make them have suid or sgid bits. This protects
26037 ++ against another published method of breaking a chroot. If the sysctl
26038 ++ option is enabled, a sysctl option with name "chroot_deny_chmod" is
26039 ++ created.
26040 ++
26041 ++config GRKERNSEC_CHROOT_FCHDIR
26042 ++ bool "Deny fchdir out of chroot"
26043 ++ depends on GRKERNSEC_CHROOT
26044 ++ help
26045 ++ If you say Y here, a well-known method of breaking chroots by fchdir'ing
26046 ++ to a file descriptor of the chrooting process that points to a directory
26047 ++ outside the filesystem will be stopped. If the sysctl option
26048 ++ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
26049 ++
26050 ++config GRKERNSEC_CHROOT_MKNOD
26051 ++ bool "Deny mknod"
26052 ++ depends on GRKERNSEC_CHROOT
26053 ++ help
26054 ++ If you say Y here, processes inside a chroot will not be allowed to
26055 ++ mknod. The problem with using mknod inside a chroot is that it
26056 ++ would allow an attacker to create a device entry that is the same
26057 ++ as one on the physical root of your system, which could range from
26058 ++ anything from the console device to a device for your harddrive (which
26059 ++ they could then use to wipe the drive or steal data). It is recommended
26060 ++ that you say Y here, unless you run into software incompatibilities.
26061 ++ If the sysctl option is enabled, a sysctl option with name
26062 ++ "chroot_deny_mknod" is created.
26063 ++
26064 ++config GRKERNSEC_CHROOT_SHMAT
26065 ++ bool "Deny shmat() out of chroot"
26066 ++ depends on GRKERNSEC_CHROOT
26067 ++ help
26068 ++ If you say Y here, processes inside a chroot will not be able to attach
26069 ++ to shared memory segments that were created outside of the chroot jail.
26070 ++ It is recommended that you say Y here. If the sysctl option is enabled,
26071 ++ a sysctl option with name "chroot_deny_shmat" is created.
26072 ++
26073 ++config GRKERNSEC_CHROOT_UNIX
26074 ++ bool "Deny access to abstract AF_UNIX sockets out of chroot"
26075 ++ depends on GRKERNSEC_CHROOT
26076 ++ help
26077 ++ If you say Y here, processes inside a chroot will not be able to
26078 ++ connect to abstract (meaning not belonging to a filesystem) Unix
26079 ++ domain sockets that were bound outside of a chroot. It is recommended
26080 ++ that you say Y here. If the sysctl option is enabled, a sysctl option
26081 ++ with name "chroot_deny_unix" is created.
26082 ++
26083 ++config GRKERNSEC_CHROOT_FINDTASK
26084 ++ bool "Protect outside processes"
26085 ++ depends on GRKERNSEC_CHROOT
26086 ++ help
26087 ++ If you say Y here, processes inside a chroot will not be able to
26088 ++ kill, send signals with fcntl, ptrace, capget, getpgid, getsid,
26089 ++ or view any process outside of the chroot. If the sysctl
26090 ++ option is enabled, a sysctl option with name "chroot_findtask" is
26091 ++ created.
26092 ++
26093 ++config GRKERNSEC_CHROOT_NICE
26094 ++ bool "Restrict priority changes"
26095 ++ depends on GRKERNSEC_CHROOT
26096 ++ help
26097 ++ If you say Y here, processes inside a chroot will not be able to raise
26098 ++ the priority of processes in the chroot, or alter the priority of
26099 ++ processes outside the chroot. This provides more security than simply
26100 ++ removing CAP_SYS_NICE from the process' capability set. If the
26101 ++ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
26102 ++ is created.
26103 ++
26104 ++config GRKERNSEC_CHROOT_SYSCTL
26105 ++ bool "Deny sysctl writes"
26106 ++ depends on GRKERNSEC_CHROOT
26107 ++ help
26108 ++ If you say Y here, an attacker in a chroot will not be able to
26109 ++ write to sysctl entries, either by sysctl(2) or through a /proc
26110 ++ interface. It is strongly recommended that you say Y here. If the
26111 ++ sysctl option is enabled, a sysctl option with name
26112 ++ "chroot_deny_sysctl" is created.
26113 ++
26114 ++config GRKERNSEC_CHROOT_CAPS
26115 ++ bool "Capability restrictions"
26116 ++ depends on GRKERNSEC_CHROOT
26117 ++ help
26118 ++ If you say Y here, the capabilities on all root processes within a
26119 ++ chroot jail will be lowered to stop module insertion, raw i/o,
26120 ++ system and net admin tasks, rebooting the system, modifying immutable
26121 ++ files, modifying IPC owned by another, and changing the system time.
26122 ++ This is left an option because it can break some apps. Disable this
26123 ++ if your chrooted apps are having problems performing those kinds of
26124 ++ tasks. If the sysctl option is enabled, a sysctl option with
26125 ++ name "chroot_caps" is created.
26126 ++
26127 ++endmenu
26128 ++menu "Kernel Auditing"
26129 ++depends on GRKERNSEC
26130 ++
26131 ++config GRKERNSEC_AUDIT_GROUP
26132 ++ bool "Single group for auditing"
26133 ++ help
26134 ++ If you say Y here, the exec, chdir, (un)mount, and ipc logging features
26135 ++ will only operate on a group you specify. This option is recommended
26136 ++ if you only want to watch certain users instead of having a large
26137 ++ amount of logs from the entire system. If the sysctl option is enabled,
26138 ++ a sysctl option with name "audit_group" is created.
26139 ++
26140 ++config GRKERNSEC_AUDIT_GID
26141 ++ int "GID for auditing"
26142 ++ depends on GRKERNSEC_AUDIT_GROUP
26143 ++ default 1007
26144 ++
26145 ++config GRKERNSEC_EXECLOG
26146 ++ bool "Exec logging"
26147 ++ help
26148 ++ If you say Y here, all execve() calls will be logged (since the
26149 ++ other exec*() calls are frontends to execve(), all execution
26150 ++ will be logged). Useful for shell-servers that like to keep track
26151 ++ of their users. If the sysctl option is enabled, a sysctl option with
26152 ++ name "exec_logging" is created.
26153 ++ WARNING: This option when enabled will produce a LOT of logs, especially
26154 ++ on an active system.
26155 ++
26156 ++config GRKERNSEC_RESLOG
26157 ++ bool "Resource logging"
26158 ++ help
26159 ++ If you say Y here, all attempts to overstep resource limits will
26160 ++ be logged with the resource name, the requested size, and the current
26161 ++ limit. It is highly recommended that you say Y here. If the sysctl
26162 ++ option is enabled, a sysctl option with name "resource_logging" is
26163 ++ created. If the RBAC system is enabled, the sysctl value is ignored.
26164 ++
26165 ++config GRKERNSEC_CHROOT_EXECLOG
26166 ++ bool "Log execs within chroot"
26167 ++ help
26168 ++ If you say Y here, all executions inside a chroot jail will be logged
26169 ++ to syslog. This can cause a large amount of logs if certain
26170 ++ applications (eg. djb's daemontools) are installed on the system, and
26171 ++ is therefore left as an option. If the sysctl option is enabled, a
26172 ++ sysctl option with name "chroot_execlog" is created.
26173 ++
26174 ++config GRKERNSEC_AUDIT_CHDIR
26175 ++ bool "Chdir logging"
26176 ++ help
26177 ++ If you say Y here, all chdir() calls will be logged. If the sysctl
26178 ++ option is enabled, a sysctl option with name "audit_chdir" is created.
26179 ++
26180 ++config GRKERNSEC_AUDIT_MOUNT
26181 ++ bool "(Un)Mount logging"
26182 ++ help
26183 ++ If you say Y here, all mounts and unmounts will be logged. If the
26184 ++ sysctl option is enabled, a sysctl option with name "audit_mount" is
26185 ++ created.
26186 ++
26187 ++config GRKERNSEC_AUDIT_IPC
26188 ++ bool "IPC logging"
26189 ++ help
26190 ++ If you say Y here, creation and removal of message queues, semaphores,
26191 ++ and shared memory will be logged. If the sysctl option is enabled, a
26192 ++ sysctl option with name "audit_ipc" is created.
26193 ++
26194 ++config GRKERNSEC_SIGNAL
26195 ++ bool "Signal logging"
26196 ++ help
26197 ++ If you say Y here, certain important signals will be logged, such as
26198 ++ SIGSEGV, which will as a result inform you of when a error in a program
26199 ++ occurred, which in some cases could mean a possible exploit attempt.
26200 ++ If the sysctl option is enabled, a sysctl option with name
26201 ++ "signal_logging" is created.
26202 ++
26203 ++config GRKERNSEC_FORKFAIL
26204 ++ bool "Fork failure logging"
26205 ++ help
26206 ++ If you say Y here, all failed fork() attempts will be logged.
26207 ++ This could suggest a fork bomb, or someone attempting to overstep
26208 ++ their process limit. If the sysctl option is enabled, a sysctl option
26209 ++ with name "forkfail_logging" is created.
26210 ++
26211 ++config GRKERNSEC_TIME
26212 ++ bool "Time change logging"
26213 ++ help
26214 ++ If you say Y here, any changes of the system clock will be logged.
26215 ++ If the sysctl option is enabled, a sysctl option with name
26216 ++ "timechange_logging" is created.
26217 ++
26218 ++config GRKERNSEC_PROC_IPADDR
26219 ++ bool "/proc/<pid>/ipaddr support"
26220 ++ help
26221 ++ If you say Y here, a new entry will be added to each /proc/<pid>
26222 ++ directory that contains the IP address of the person using the task.
26223 ++ The IP is carried across local TCP and AF_UNIX stream sockets.
26224 ++ This information can be useful for IDS/IPSes to perform remote response
26225 ++ to a local attack. The entry is readable by only the owner of the
26226 ++ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
26227 ++ the RBAC system), and thus does not create privacy concerns.
26228 ++
26229 ++config GRKERNSEC_AUDIT_TEXTREL
26230 ++ bool 'ELF text relocations logging (READ HELP)'
26231 ++ depends on PAX_MPROTECT
26232 ++ help
26233 ++ If you say Y here, text relocations will be logged with the filename
26234 ++ of the offending library or binary. The purpose of the feature is
26235 ++ to help Linux distribution developers get rid of libraries and
26236 ++ binaries that need text relocations which hinder the future progress
26237 ++ of PaX. Only Linux distribution developers should say Y here, and
26238 ++ never on a production machine, as this option creates an information
26239 ++ leak that could aid an attacker in defeating the randomization of
26240 ++ a single memory region. If the sysctl option is enabled, a sysctl
26241 ++ option with name "audit_textrel" is created.
26242 ++
26243 ++endmenu
26244 ++
26245 ++menu "Executable Protections"
26246 ++depends on GRKERNSEC
26247 ++
26248 ++config GRKERNSEC_EXECVE
26249 ++ bool "Enforce RLIMIT_NPROC on execs"
26250 ++ help
26251 ++ If you say Y here, users with a resource limit on processes will
26252 ++ have the value checked during execve() calls. The current system
26253 ++ only checks the system limit during fork() calls. If the sysctl option
26254 ++ is enabled, a sysctl option with name "execve_limiting" is created.
26255 ++
26256 ++config GRKERNSEC_DMESG
26257 ++ bool "Dmesg(8) restriction"
26258 ++ help
26259 ++ If you say Y here, non-root users will not be able to use dmesg(8)
26260 ++ to view up to the last 4kb of messages in the kernel's log buffer.
26261 ++ If the sysctl option is enabled, a sysctl option with name "dmesg" is
26262 ++ created.
26263 ++
26264 ++config GRKERNSEC_TPE
26265 ++ bool "Trusted Path Execution (TPE)"
26266 ++ help
26267 ++ If you say Y here, you will be able to choose a gid to add to the
26268 ++ supplementary groups of users you want to mark as "untrusted."
26269 ++ These users will not be able to execute any files that are not in
26270 ++ root-owned directories writable only by root. If the sysctl option
26271 ++ is enabled, a sysctl option with name "tpe" is created.
26272 ++
26273 ++config GRKERNSEC_TPE_ALL
26274 ++ bool "Partially restrict non-root users"
26275 ++ depends on GRKERNSEC_TPE
26276 ++ help
26277 ++ If you say Y here, All non-root users other than the ones in the
26278 ++ group specified in the main TPE option will only be allowed to
26279 ++ execute files in directories they own that are not group or
26280 ++ world-writable, or in directories owned by root and writable only by
26281 ++ root. If the sysctl option is enabled, a sysctl option with name
26282 ++ "tpe_restrict_all" is created.
26283 ++
26284 ++config GRKERNSEC_TPE_INVERT
26285 ++ bool "Invert GID option"
26286 ++ depends on GRKERNSEC_TPE
26287 ++ help
26288 ++ If you say Y here, the group you specify in the TPE configuration will
26289 ++ decide what group TPE restrictions will be *disabled* for. This
26290 ++ option is useful if you want TPE restrictions to be applied to most
26291 ++ users on the system.
26292 ++
26293 ++config GRKERNSEC_TPE_GID
26294 ++ int "GID for untrusted users"
26295 ++ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
26296 ++ default 1005
26297 ++ help
26298 ++ If you have selected the "Invert GID option" above, setting this
26299 ++ GID determines what group TPE restrictions will be *disabled* for.
26300 ++ If you have not selected the "Invert GID option" above, setting this
26301 ++ GID determines what group TPE restrictions will be *enabled* for.
26302 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26303 ++ is created.
26304 ++
26305 ++config GRKERNSEC_TPE_GID
26306 ++ int "GID for trusted users"
26307 ++ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
26308 ++ default 1005
26309 ++ help
26310 ++ If you have selected the "Invert GID option" above, setting this
26311 ++ GID determines what group TPE restrictions will be *disabled* for.
26312 ++ If you have not selected the "Invert GID option" above, setting this
26313 ++ GID determines what group TPE restrictions will be *enabled* for.
26314 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26315 ++ is created.
26316 ++
26317 ++endmenu
26318 ++menu "Network Protections"
26319 ++depends on GRKERNSEC
26320 ++
26321 ++config GRKERNSEC_RANDNET
26322 ++ bool "Larger entropy pools"
26323 ++ help
26324 ++ If you say Y here, the entropy pools used for many features of Linux
26325 ++ and grsecurity will be doubled in size. Since several grsecurity
26326 ++ features use additional randomness, it is recommended that you say Y
26327 ++ here. Saying Y here has a similar effect as modifying
26328 ++ /proc/sys/kernel/random/poolsize.
26329 ++
26330 ++config GRKERNSEC_SOCKET
26331 ++ bool "Socket restrictions"
26332 ++ help
26333 ++ If you say Y here, you will be able to choose from several options.
26334 ++ If you assign a GID on your system and add it to the supplementary
26335 ++ groups of users you want to restrict socket access to, this patch
26336 ++ will perform up to three things, based on the option(s) you choose.
26337 ++
26338 ++config GRKERNSEC_SOCKET_ALL
26339 ++ bool "Deny any sockets to group"
26340 ++ depends on GRKERNSEC_SOCKET
26341 ++ help
26342 ++ If you say Y here, you will be able to choose a GID of whose users will
26343 ++ be unable to connect to other hosts from your machine or run server
26344 ++ applications from your machine. If the sysctl option is enabled, a
26345 ++ sysctl option with name "socket_all" is created.
26346 ++
26347 ++config GRKERNSEC_SOCKET_ALL_GID
26348 ++ int "GID to deny all sockets for"
26349 ++ depends on GRKERNSEC_SOCKET_ALL
26350 ++ default 1004
26351 ++ help
26352 ++ Here you can choose the GID to disable socket access for. Remember to
26353 ++ add the users you want socket access disabled for to the GID
26354 ++ specified here. If the sysctl option is enabled, a sysctl option
26355 ++ with name "socket_all_gid" is created.
26356 ++
26357 ++config GRKERNSEC_SOCKET_CLIENT
26358 ++ bool "Deny client sockets to group"
26359 ++ depends on GRKERNSEC_SOCKET
26360 ++ help
26361 ++ If you say Y here, you will be able to choose a GID of whose users will
26362 ++ be unable to connect to other hosts from your machine, but will be
26363 ++ able to run servers. If this option is enabled, all users in the group
26364 ++ you specify will have to use passive mode when initiating ftp transfers
26365 ++ from the shell on your machine. If the sysctl option is enabled, a
26366 ++ sysctl option with name "socket_client" is created.
26367 ++
26368 ++config GRKERNSEC_SOCKET_CLIENT_GID
26369 ++ int "GID to deny client sockets for"
26370 ++ depends on GRKERNSEC_SOCKET_CLIENT
26371 ++ default 1003
26372 ++ help
26373 ++ Here you can choose the GID to disable client socket access for.
26374 ++ Remember to add the users you want client socket access disabled for to
26375 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26376 ++ option with name "socket_client_gid" is created.
26377 ++
26378 ++config GRKERNSEC_SOCKET_SERVER
26379 ++ bool "Deny server sockets to group"
26380 ++ depends on GRKERNSEC_SOCKET
26381 ++ help
26382 ++ If you say Y here, you will be able to choose a GID of whose users will
26383 ++ be unable to run server applications from your machine. If the sysctl
26384 ++ option is enabled, a sysctl option with name "socket_server" is created.
26385 ++
26386 ++config GRKERNSEC_SOCKET_SERVER_GID
26387 ++ int "GID to deny server sockets for"
26388 ++ depends on GRKERNSEC_SOCKET_SERVER
26389 ++ default 1002
26390 ++ help
26391 ++ Here you can choose the GID to disable server socket access for.
26392 ++ Remember to add the users you want server socket access disabled for to
26393 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26394 ++ option with name "socket_server_gid" is created.
26395 ++
26396 ++endmenu
26397 ++menu "Sysctl support"
26398 ++depends on GRKERNSEC && SYSCTL
26399 ++
26400 ++config GRKERNSEC_SYSCTL
26401 ++ bool "Sysctl support"
26402 ++ help
26403 ++ If you say Y here, you will be able to change the options that
26404 ++ grsecurity runs with at bootup, without having to recompile your
26405 ++ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
26406 ++ to enable (1) or disable (0) various features. All the sysctl entries
26407 ++ are mutable until the "grsec_lock" entry is set to a non-zero value.
26408 ++ All features enabled in the kernel configuration are disabled at boot
26409 ++ if you do not say Y to the "Turn on features by default" option.
26410 ++ All options should be set at startup, and the grsec_lock entry should
26411 ++ be set to a non-zero value after all the options are set.
26412 ++ *THIS IS EXTREMELY IMPORTANT*
26413 ++
26414 ++config GRKERNSEC_SYSCTL_ON
26415 ++ bool "Turn on features by default"
26416 ++ depends on GRKERNSEC_SYSCTL
26417 ++ help
26418 ++ If you say Y here, instead of having all features enabled in the
26419 ++ kernel configuration disabled at boot time, the features will be
26420 ++ enabled at boot time. It is recommended you say Y here unless
26421 ++ there is some reason you would want all sysctl-tunable features to
26422 ++ be disabled by default. As mentioned elsewhere, it is important
26423 ++ to enable the grsec_lock entry once you have finished modifying
26424 ++ the sysctl entries.
26425 ++
26426 ++endmenu
26427 ++menu "Logging Options"
26428 ++depends on GRKERNSEC
26429 ++
26430 ++config GRKERNSEC_FLOODTIME
26431 ++ int "Seconds in between log messages (minimum)"
26432 ++ default 10
26433 ++ help
26434 ++ This option allows you to enforce the number of seconds between
26435 ++ grsecurity log messages. The default should be suitable for most
26436 ++ people, however, if you choose to change it, choose a value small enough
26437 ++ to allow informative logs to be produced, but large enough to
26438 ++ prevent flooding.
26439 ++
26440 ++config GRKERNSEC_FLOODBURST
26441 ++ int "Number of messages in a burst (maximum)"
26442 ++ default 4
26443 ++ help
26444 ++ This option allows you to choose the maximum number of messages allowed
26445 ++ within the flood time interval you chose in a separate option. The
26446 ++ default should be suitable for most people, however if you find that
26447 ++ many of your logs are being interpreted as flooding, you may want to
26448 ++ raise this value.
26449 ++
26450 ++endmenu
26451 ++
26452 ++endmenu
26453 +diff -urNp linux-2.6.27.10/grsecurity/Makefile linux-2.6.27.10/grsecurity/Makefile
26454 +--- linux-2.6.27.10/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
26455 ++++ linux-2.6.27.10/grsecurity/Makefile 2008-11-18 03:38:45.000000000 -0500
26456 +@@ -0,0 +1,20 @@
26457 ++# grsecurity's ACL system was originally written in 2001 by Michael Dalton
26458 ++# during 2001-2005 it has been completely redesigned by Brad Spengler
26459 ++# into an RBAC system
26460 ++#
26461 ++# All code in this directory and various hooks inserted throughout the kernel
26462 ++# are copyright Brad Spengler, and released under the GPL v2 or higher
26463 ++
26464 ++obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
26465 ++ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
26466 ++ grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o
26467 ++
26468 ++obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
26469 ++ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
26470 ++ gracl_learn.o grsec_log.o
26471 ++obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
26472 ++
26473 ++ifndef CONFIG_GRKERNSEC
26474 ++obj-y += grsec_disabled.o
26475 ++endif
26476 ++
26477 +diff -urNp linux-2.6.27.10/include/asm-cris/kmap_types.h linux-2.6.27.10/include/asm-cris/kmap_types.h
26478 +--- linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26479 ++++ linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26480 +@@ -19,6 +19,7 @@ enum km_type {
26481 + KM_IRQ1,
26482 + KM_SOFTIRQ0,
26483 + KM_SOFTIRQ1,
26484 ++ KM_CLEARPAGE,
26485 + KM_TYPE_NR
26486 + };
26487 +
26488 +diff -urNp linux-2.6.27.10/include/asm-frv/kmap_types.h linux-2.6.27.10/include/asm-frv/kmap_types.h
26489 +--- linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26490 ++++ linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26491 +@@ -23,6 +23,7 @@ enum km_type {
26492 + KM_IRQ1,
26493 + KM_SOFTIRQ0,
26494 + KM_SOFTIRQ1,
26495 ++ KM_CLEARPAGE,
26496 + KM_TYPE_NR
26497 + };
26498 +
26499 +diff -urNp linux-2.6.27.10/include/asm-generic/futex.h linux-2.6.27.10/include/asm-generic/futex.h
26500 +--- linux-2.6.27.10/include/asm-generic/futex.h 2008-11-07 12:55:34.000000000 -0500
26501 ++++ linux-2.6.27.10/include/asm-generic/futex.h 2008-11-18 03:38:45.000000000 -0500
26502 +@@ -6,7 +6,7 @@
26503 + #include <asm/errno.h>
26504 +
26505 + static inline int
26506 +-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
26507 ++futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
26508 + {
26509 + int op = (encoded_op >> 28) & 7;
26510 + int cmp = (encoded_op >> 24) & 15;
26511 +@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
26512 + }
26513 +
26514 + static inline int
26515 +-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
26516 ++futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
26517 + {
26518 + return -ENOSYS;
26519 + }
26520 +diff -urNp linux-2.6.27.10/include/asm-generic/vmlinux.lds.h linux-2.6.27.10/include/asm-generic/vmlinux.lds.h
26521 +--- linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-07 12:55:34.000000000 -0500
26522 ++++ linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-18 03:38:45.000000000 -0500
26523 +@@ -59,6 +59,7 @@
26524 + .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
26525 + VMLINUX_SYMBOL(__start_rodata) = .; \
26526 + *(.rodata) *(.rodata.*) \
26527 ++ *(.data.read_only) \
26528 + *(__vermagic) /* Kernel version magic */ \
26529 + *(__markers_strings) /* Markers: strings */ \
26530 + } \
26531 +diff -urNp linux-2.6.27.10/include/asm-m32r/kmap_types.h linux-2.6.27.10/include/asm-m32r/kmap_types.h
26532 +--- linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26533 ++++ linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26534 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
26535 + D(10) KM_IRQ1,
26536 + D(11) KM_SOFTIRQ0,
26537 + D(12) KM_SOFTIRQ1,
26538 +-D(13) KM_TYPE_NR
26539 ++D(13) KM_CLEARPAGE,
26540 ++D(14) KM_TYPE_NR
26541 + };
26542 +
26543 + #undef D
26544 +diff -urNp linux-2.6.27.10/include/asm-m68k/kmap_types.h linux-2.6.27.10/include/asm-m68k/kmap_types.h
26545 +--- linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26546 ++++ linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26547 +@@ -15,6 +15,7 @@ enum km_type {
26548 + KM_IRQ1,
26549 + KM_SOFTIRQ0,
26550 + KM_SOFTIRQ1,
26551 ++ KM_CLEARPAGE,
26552 + KM_TYPE_NR
26553 + };
26554 +
26555 +diff -urNp linux-2.6.27.10/include/asm-mips/elf.h linux-2.6.27.10/include/asm-mips/elf.h
26556 +--- linux-2.6.27.10/include/asm-mips/elf.h 2008-11-07 12:55:34.000000000 -0500
26557 ++++ linux-2.6.27.10/include/asm-mips/elf.h 2008-11-18 03:38:45.000000000 -0500
26558 +@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
26559 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
26560 + #endif
26561 +
26562 ++#ifdef CONFIG_PAX_ASLR
26563 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
26564 ++
26565 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26566 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26567 ++#endif
26568 ++
26569 + #endif /* _ASM_ELF_H */
26570 +diff -urNp linux-2.6.27.10/include/asm-mips/kmap_types.h linux-2.6.27.10/include/asm-mips/kmap_types.h
26571 +--- linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26572 ++++ linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26573 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26574 + D(10) KM_IRQ1,
26575 + D(11) KM_SOFTIRQ0,
26576 + D(12) KM_SOFTIRQ1,
26577 +-D(13) KM_TYPE_NR
26578 ++D(13) KM_CLEARPAGE,
26579 ++D(14) KM_TYPE_NR
26580 + };
26581 +
26582 + #undef D
26583 +diff -urNp linux-2.6.27.10/include/asm-mips/page.h linux-2.6.27.10/include/asm-mips/page.h
26584 +--- linux-2.6.27.10/include/asm-mips/page.h 2008-11-07 12:55:34.000000000 -0500
26585 ++++ linux-2.6.27.10/include/asm-mips/page.h 2008-11-18 03:38:45.000000000 -0500
26586 +@@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa
26587 + #ifdef CONFIG_CPU_MIPS32
26588 + typedef struct { unsigned long pte_low, pte_high; } pte_t;
26589 + #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
26590 +- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
26591 ++ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
26592 + #else
26593 + typedef struct { unsigned long long pte; } pte_t;
26594 + #define pte_val(x) ((x).pte)
26595 +diff -urNp linux-2.6.27.10/include/asm-mips/system.h linux-2.6.27.10/include/asm-mips/system.h
26596 +--- linux-2.6.27.10/include/asm-mips/system.h 2008-11-07 12:55:34.000000000 -0500
26597 ++++ linux-2.6.27.10/include/asm-mips/system.h 2008-11-18 03:38:45.000000000 -0500
26598 +@@ -215,6 +215,6 @@ extern void per_cpu_trap_init(void);
26599 + */
26600 + #define __ARCH_WANT_UNLOCKED_CTXSW
26601 +
26602 +-extern unsigned long arch_align_stack(unsigned long sp);
26603 ++#define arch_align_stack(x) ((x) & ALMASK)
26604 +
26605 + #endif /* _ASM_SYSTEM_H */
26606 +diff -urNp linux-2.6.27.10/include/asm-mn10300/kmap_types.h linux-2.6.27.10/include/asm-mn10300/kmap_types.h
26607 +--- linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26608 ++++ linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
26609 +@@ -25,6 +25,7 @@ enum km_type {
26610 + KM_IRQ1,
26611 + KM_SOFTIRQ0,
26612 + KM_SOFTIRQ1,
26613 ++ KM_CLEARPAGE,
26614 + KM_TYPE_NR
26615 + };
26616 +
26617 +diff -urNp linux-2.6.27.10/include/asm-parisc/elf.h linux-2.6.27.10/include/asm-parisc/elf.h
26618 +--- linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-07 12:55:34.000000000 -0500
26619 ++++ linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-18 03:38:45.000000000 -0500
26620 +@@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration..
26621 +
26622 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
26623 +
26624 ++#ifdef CONFIG_PAX_ASLR
26625 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
26626 ++
26627 ++#define PAX_DELTA_MMAP_LEN 16
26628 ++#define PAX_DELTA_STACK_LEN 16
26629 ++#endif
26630 ++
26631 + /* This yields a mask that user programs can use to figure out what
26632 + instruction set this CPU supports. This could be done in user space,
26633 + but it's not easy, and we've already done it here. */
26634 +diff -urNp linux-2.6.27.10/include/asm-parisc/kmap_types.h linux-2.6.27.10/include/asm-parisc/kmap_types.h
26635 +--- linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26636 ++++ linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26637 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26638 + D(10) KM_IRQ1,
26639 + D(11) KM_SOFTIRQ0,
26640 + D(12) KM_SOFTIRQ1,
26641 +-D(13) KM_TYPE_NR
26642 ++D(13) KM_CLEARPAGE,
26643 ++D(14) KM_TYPE_NR
26644 + };
26645 +
26646 + #undef D
26647 +diff -urNp linux-2.6.27.10/include/asm-parisc/pgtable.h linux-2.6.27.10/include/asm-parisc/pgtable.h
26648 +--- linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-07 12:55:34.000000000 -0500
26649 ++++ linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-18 03:38:45.000000000 -0500
26650 +@@ -202,6 +202,17 @@
26651 + #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
26652 + #define PAGE_COPY PAGE_EXECREAD
26653 + #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
26654 ++
26655 ++#ifdef CONFIG_PAX_PAGEEXEC
26656 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
26657 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26658 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26659 ++#else
26660 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
26661 ++# define PAGE_COPY_NOEXEC PAGE_COPY
26662 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
26663 ++#endif
26664 ++
26665 + #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
26666 + #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
26667 + #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
26668 +diff -urNp linux-2.6.27.10/include/asm-um/kmap_types.h linux-2.6.27.10/include/asm-um/kmap_types.h
26669 +--- linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26670 ++++ linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26671 +@@ -23,6 +23,7 @@ enum km_type {
26672 + KM_IRQ1,
26673 + KM_SOFTIRQ0,
26674 + KM_SOFTIRQ1,
26675 ++ KM_CLEARPAGE,
26676 + KM_TYPE_NR
26677 + };
26678 +
26679 +diff -urNp linux-2.6.27.10/include/asm-um/page.h linux-2.6.27.10/include/asm-um/page.h
26680 +--- linux-2.6.27.10/include/asm-um/page.h 2008-11-07 12:55:34.000000000 -0500
26681 ++++ linux-2.6.27.10/include/asm-um/page.h 2008-11-18 03:38:45.000000000 -0500
26682 +@@ -14,6 +14,9 @@
26683 + #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
26684 + #define PAGE_MASK (~(PAGE_SIZE-1))
26685 +
26686 ++#define ktla_ktva(addr) (addr)
26687 ++#define ktva_ktla(addr) (addr)
26688 ++
26689 + #ifndef __ASSEMBLY__
26690 +
26691 + struct page;
26692 +diff -urNp linux-2.6.27.10/include/asm-x86/alternative.h linux-2.6.27.10/include/asm-x86/alternative.h
26693 +--- linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-07 12:55:34.000000000 -0500
26694 ++++ linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-18 03:38:45.000000000 -0500
26695 +@@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab
26696 + " .byte 662b-661b\n" /* sourcelen */ \
26697 + " .byte 664f-663f\n" /* replacementlen */ \
26698 + ".previous\n" \
26699 +- ".section .altinstr_replacement,\"ax\"\n" \
26700 ++ ".section .altinstr_replacement,\"a\"\n" \
26701 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26702 + ".previous" :: "i" (feature) : "memory")
26703 +
26704 +@@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab
26705 + " .byte 662b-661b\n" /* sourcelen */ \
26706 + " .byte 664f-663f\n" /* replacementlen */ \
26707 + ".previous\n" \
26708 +- ".section .altinstr_replacement,\"ax\"\n" \
26709 ++ ".section .altinstr_replacement,\"a\"\n" \
26710 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26711 + ".previous" :: "i" (feature), ##input)
26712 +
26713 +@@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab
26714 + " .byte 662b-661b\n" /* sourcelen */ \
26715 + " .byte 664f-663f\n" /* replacementlen */ \
26716 + ".previous\n" \
26717 +- ".section .altinstr_replacement,\"ax\"\n" \
26718 ++ ".section .altinstr_replacement,\"a\"\n" \
26719 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26720 + ".previous" : output : [feat] "i" (feature), ##input)
26721 +
26722 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_32.h linux-2.6.27.10/include/asm-x86/atomic_32.h
26723 +--- linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-07 12:55:34.000000000 -0500
26724 ++++ linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-18 03:38:45.000000000 -0500
26725 +@@ -47,7 +47,15 @@ typedef struct {
26726 + */
26727 + static inline void atomic_add(int i, atomic_t *v)
26728 + {
26729 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26730 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26731 ++
26732 ++#ifdef CONFIG_PAX_REFCOUNT
26733 ++ "jno 0f\n"
26734 ++ LOCK_PREFIX "subl %1,%0\n"
26735 ++ "into\n0:\n"
26736 ++ _ASM_EXTABLE(0b, 0b)
26737 ++#endif
26738 ++
26739 + : "+m" (v->counter)
26740 + : "ir" (i));
26741 + }
26742 +@@ -61,7 +69,15 @@ static inline void atomic_add(int i, ato
26743 + */
26744 + static inline void atomic_sub(int i, atomic_t *v)
26745 + {
26746 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26747 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26748 ++
26749 ++#ifdef CONFIG_PAX_REFCOUNT
26750 ++ "jno 0f\n"
26751 ++ LOCK_PREFIX "addl %1,%0\n"
26752 ++ "into\n0:\n"
26753 ++ _ASM_EXTABLE(0b, 0b)
26754 ++#endif
26755 ++
26756 + : "+m" (v->counter)
26757 + : "ir" (i));
26758 + }
26759 +@@ -79,7 +95,16 @@ static inline int atomic_sub_and_test(in
26760 + {
26761 + unsigned char c;
26762 +
26763 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26764 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26765 ++
26766 ++#ifdef CONFIG_PAX_REFCOUNT
26767 ++ "jno 0f\n"
26768 ++ LOCK_PREFIX "addl %2,%0\n"
26769 ++ "into\n0:\n"
26770 ++ _ASM_EXTABLE(0b, 0b)
26771 ++#endif
26772 ++
26773 ++ "sete %1\n"
26774 + : "+m" (v->counter), "=qm" (c)
26775 + : "ir" (i) : "memory");
26776 + return c;
26777 +@@ -93,7 +118,18 @@ static inline int atomic_sub_and_test(in
26778 + */
26779 + static inline void atomic_inc(atomic_t *v)
26780 + {
26781 +- asm volatile(LOCK_PREFIX "incl %0"
26782 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26783 ++
26784 ++#ifdef CONFIG_PAX_REFCOUNT
26785 ++ "into\n0:\n"
26786 ++ ".pushsection .fixup,\"ax\"\n"
26787 ++ "1:\n"
26788 ++ LOCK_PREFIX "decl %0\n"
26789 ++ "jmp 0b\n"
26790 ++ ".popsection\n"
26791 ++ _ASM_EXTABLE(0b, 1b)
26792 ++#endif
26793 ++
26794 + : "+m" (v->counter));
26795 + }
26796 +
26797 +@@ -105,7 +141,18 @@ static inline void atomic_inc(atomic_t *
26798 + */
26799 + static inline void atomic_dec(atomic_t *v)
26800 + {
26801 +- asm volatile(LOCK_PREFIX "decl %0"
26802 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26803 ++
26804 ++#ifdef CONFIG_PAX_REFCOUNT
26805 ++ "into\n0:\n"
26806 ++ ".pushsection .fixup,\"ax\"\n"
26807 ++ "1: \n"
26808 ++ LOCK_PREFIX "incl %0\n"
26809 ++ "jmp 0b\n"
26810 ++ ".popsection\n"
26811 ++ _ASM_EXTABLE(0b, 1b)
26812 ++#endif
26813 ++
26814 + : "+m" (v->counter));
26815 + }
26816 +
26817 +@@ -121,7 +168,19 @@ static inline int atomic_dec_and_test(at
26818 + {
26819 + unsigned char c;
26820 +
26821 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26822 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26823 ++
26824 ++#ifdef CONFIG_PAX_REFCOUNT
26825 ++ "into\n0:\n"
26826 ++ ".pushsection .fixup,\"ax\"\n"
26827 ++ "1: \n"
26828 ++ LOCK_PREFIX "incl %0\n"
26829 ++ "jmp 0b\n"
26830 ++ ".popsection\n"
26831 ++ _ASM_EXTABLE(0b, 1b)
26832 ++#endif
26833 ++
26834 ++ "sete %1\n"
26835 + : "+m" (v->counter), "=qm" (c)
26836 + : : "memory");
26837 + return c != 0;
26838 +@@ -139,7 +198,19 @@ static inline int atomic_inc_and_test(at
26839 + {
26840 + unsigned char c;
26841 +
26842 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
26843 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26844 ++
26845 ++#ifdef CONFIG_PAX_REFCOUNT
26846 ++ "into\n0:\n"
26847 ++ ".pushsection .fixup,\"ax\"\n"
26848 ++ "1: \n"
26849 ++ LOCK_PREFIX "decl %0\n"
26850 ++ "jmp 0b\n"
26851 ++ ".popsection\n"
26852 ++ _ASM_EXTABLE(0b, 1b)
26853 ++#endif
26854 ++
26855 ++ "sete %1\n"
26856 + : "+m" (v->counter), "=qm" (c)
26857 + : : "memory");
26858 + return c != 0;
26859 +@@ -158,7 +229,16 @@ static inline int atomic_add_negative(in
26860 + {
26861 + unsigned char c;
26862 +
26863 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
26864 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
26865 ++
26866 ++#ifdef CONFIG_PAX_REFCOUNT
26867 ++ "jno 0f\n"
26868 ++ LOCK_PREFIX "subl %2,%0\n"
26869 ++ "into\n0:\n"
26870 ++ _ASM_EXTABLE(0b, 0b)
26871 ++#endif
26872 ++
26873 ++ "sets %1\n"
26874 + : "+m" (v->counter), "=qm" (c)
26875 + : "ir" (i) : "memory");
26876 + return c;
26877 +@@ -181,7 +261,15 @@ static inline int atomic_add_return(int
26878 + #endif
26879 + /* Modern 486+ processor */
26880 + __i = i;
26881 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
26882 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
26883 ++
26884 ++#ifdef CONFIG_PAX_REFCOUNT
26885 ++ "jno 0f\n"
26886 ++ "movl %0, %1\n"
26887 ++ "into\n0:\n"
26888 ++ _ASM_EXTABLE(0b, 0b)
26889 ++#endif
26890 ++
26891 + : "+r" (i), "+m" (v->counter)
26892 + : : "memory");
26893 + return i + __i;
26894 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_64.h linux-2.6.27.10/include/asm-x86/atomic_64.h
26895 +--- linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-07 12:55:34.000000000 -0500
26896 ++++ linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-18 03:38:45.000000000 -0500
26897 +@@ -48,7 +48,15 @@ typedef struct {
26898 + */
26899 + static inline void atomic_add(int i, atomic_t *v)
26900 + {
26901 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26902 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26903 ++
26904 ++#ifdef CONFIG_PAX_REFCOUNT
26905 ++ "jno 0f\n"
26906 ++ LOCK_PREFIX "subl %1,%0\n"
26907 ++ "int $4\n0:\n"
26908 ++ _ASM_EXTABLE(0b, 0b)
26909 ++#endif
26910 ++
26911 + : "=m" (v->counter)
26912 + : "ir" (i), "m" (v->counter));
26913 + }
26914 +@@ -62,7 +70,15 @@ static inline void atomic_add(int i, ato
26915 + */
26916 + static inline void atomic_sub(int i, atomic_t *v)
26917 + {
26918 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26919 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26920 ++
26921 ++#ifdef CONFIG_PAX_REFCOUNT
26922 ++ "jno 0f\n"
26923 ++ LOCK_PREFIX "addl %1,%0\n"
26924 ++ "int $4\n0:\n"
26925 ++ _ASM_EXTABLE(0b, 0b)
26926 ++#endif
26927 ++
26928 + : "=m" (v->counter)
26929 + : "ir" (i), "m" (v->counter));
26930 + }
26931 +@@ -80,7 +96,16 @@ static inline int atomic_sub_and_test(in
26932 + {
26933 + unsigned char c;
26934 +
26935 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26936 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26937 ++
26938 ++#ifdef CONFIG_PAX_REFCOUNT
26939 ++ "jno 0f\n"
26940 ++ LOCK_PREFIX "addl %2,%0\n"
26941 ++ "int $4\n0:\n"
26942 ++ _ASM_EXTABLE(0b, 0b)
26943 ++#endif
26944 ++
26945 ++ "sete %1\n"
26946 + : "=m" (v->counter), "=qm" (c)
26947 + : "ir" (i), "m" (v->counter) : "memory");
26948 + return c;
26949 +@@ -94,7 +119,19 @@ static inline int atomic_sub_and_test(in
26950 + */
26951 + static inline void atomic_inc(atomic_t *v)
26952 + {
26953 +- asm volatile(LOCK_PREFIX "incl %0"
26954 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26955 ++
26956 ++#ifdef CONFIG_PAX_REFCOUNT
26957 ++ "jno 0f\n"
26958 ++ "int $4\n0:\n"
26959 ++ ".pushsection .fixup,\"ax\"\n"
26960 ++ "1:\n"
26961 ++ LOCK_PREFIX "decl %0\n"
26962 ++ "jmp 0b\n"
26963 ++ ".popsection\n"
26964 ++ _ASM_EXTABLE(0b, 1b)
26965 ++#endif
26966 ++
26967 + : "=m" (v->counter)
26968 + : "m" (v->counter));
26969 + }
26970 +@@ -107,7 +144,19 @@ static inline void atomic_inc(atomic_t *
26971 + */
26972 + static inline void atomic_dec(atomic_t *v)
26973 + {
26974 +- asm volatile(LOCK_PREFIX "decl %0"
26975 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26976 ++
26977 ++#ifdef CONFIG_PAX_REFCOUNT
26978 ++ "jno 0f\n"
26979 ++ "int $4\n0:\n"
26980 ++ ".pushsection .fixup,\"ax\"\n"
26981 ++ "1: \n"
26982 ++ LOCK_PREFIX "incl %0\n"
26983 ++ "jmp 0b\n"
26984 ++ ".popsection\n"
26985 ++ _ASM_EXTABLE(0b, 1b)
26986 ++#endif
26987 ++
26988 + : "=m" (v->counter)
26989 + : "m" (v->counter));
26990 + }
26991 +@@ -124,7 +173,20 @@ static inline int atomic_dec_and_test(at
26992 + {
26993 + unsigned char c;
26994 +
26995 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26996 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26997 ++
26998 ++#ifdef CONFIG_PAX_REFCOUNT
26999 ++ "jno 0f\n"
27000 ++ "int $4\n0:\n"
27001 ++ ".pushsection .fixup,\"ax\"\n"
27002 ++ "1: \n"
27003 ++ LOCK_PREFIX "incl %0\n"
27004 ++ "jmp 0b\n"
27005 ++ ".popsection\n"
27006 ++ _ASM_EXTABLE(0b, 1b)
27007 ++#endif
27008 ++
27009 ++ "sete %1\n"
27010 + : "=m" (v->counter), "=qm" (c)
27011 + : "m" (v->counter) : "memory");
27012 + return c != 0;
27013 +@@ -142,7 +204,20 @@ static inline int atomic_inc_and_test(at
27014 + {
27015 + unsigned char c;
27016 +
27017 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
27018 ++ asm volatile(LOCK_PREFIX "incl %0\n"
27019 ++
27020 ++#ifdef CONFIG_PAX_REFCOUNT
27021 ++ "jno 0f\n"
27022 ++ "int $4\n0:\n"
27023 ++ ".pushsection .fixup,\"ax\"\n"
27024 ++ "1: \n"
27025 ++ LOCK_PREFIX "decl %0\n"
27026 ++ "jmp 0b\n"
27027 ++ ".popsection\n"
27028 ++ _ASM_EXTABLE(0b, 1b)
27029 ++#endif
27030 ++
27031 ++ "sete %1\n"
27032 + : "=m" (v->counter), "=qm" (c)
27033 + : "m" (v->counter) : "memory");
27034 + return c != 0;
27035 +@@ -161,7 +236,16 @@ static inline int atomic_add_negative(in
27036 + {
27037 + unsigned char c;
27038 +
27039 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
27040 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
27041 ++
27042 ++#ifdef CONFIG_PAX_REFCOUNT
27043 ++ "jno 0f\n"
27044 ++ LOCK_PREFIX "subl %2,%0\n"
27045 ++ "int $4\n0:\n"
27046 ++ _ASM_EXTABLE(0b, 0b)
27047 ++#endif
27048 ++
27049 ++ "sets %1\n"
27050 + : "=m" (v->counter), "=qm" (c)
27051 + : "ir" (i), "m" (v->counter) : "memory");
27052 + return c;
27053 +@@ -177,7 +261,15 @@ static inline int atomic_add_negative(in
27054 + static inline int atomic_add_return(int i, atomic_t *v)
27055 + {
27056 + int __i = i;
27057 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
27058 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
27059 ++
27060 ++#ifdef CONFIG_PAX_REFCOUNT
27061 ++ "jno 0f\n"
27062 ++ "movl %0, %1\n"
27063 ++ "int $4\n0:\n"
27064 ++ _ASM_EXTABLE(0b, 0b)
27065 ++#endif
27066 ++
27067 + : "+r" (i), "+m" (v->counter)
27068 + : : "memory");
27069 + return i + __i;
27070 +@@ -226,7 +318,15 @@ typedef struct {
27071 + */
27072 + static inline void atomic64_add(long i, atomic64_t *v)
27073 + {
27074 +- asm volatile(LOCK_PREFIX "addq %1,%0"
27075 ++ asm volatile(LOCK_PREFIX "addq %1,%0\n"
27076 ++
27077 ++#ifdef CONFIG_PAX_REFCOUNT
27078 ++ "jno 0f\n"
27079 ++ LOCK_PREFIX "subq %1,%0\n"
27080 ++ "int $4\n0:\n"
27081 ++ _ASM_EXTABLE(0b, 0b)
27082 ++#endif
27083 ++
27084 + : "=m" (v->counter)
27085 + : "er" (i), "m" (v->counter));
27086 + }
27087 +@@ -240,7 +340,15 @@ static inline void atomic64_add(long i,
27088 + */
27089 + static inline void atomic64_sub(long i, atomic64_t *v)
27090 + {
27091 +- asm volatile(LOCK_PREFIX "subq %1,%0"
27092 ++ asm volatile(LOCK_PREFIX "subq %1,%0\n"
27093 ++
27094 ++#ifdef CONFIG_PAX_REFCOUNT
27095 ++ "jno 0f\n"
27096 ++ LOCK_PREFIX "addq %1,%0\n"
27097 ++ "int $4\n0:\n"
27098 ++ _ASM_EXTABLE(0b, 0b)
27099 ++#endif
27100 ++
27101 + : "=m" (v->counter)
27102 + : "er" (i), "m" (v->counter));
27103 + }
27104 +@@ -258,7 +366,16 @@ static inline int atomic64_sub_and_test(
27105 + {
27106 + unsigned char c;
27107 +
27108 +- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
27109 ++ asm volatile(LOCK_PREFIX "subq %2,%0\n"
27110 ++
27111 ++#ifdef CONFIG_PAX_REFCOUNT
27112 ++ "jno 0f\n"
27113 ++ LOCK_PREFIX "addq %2,%0\n"
27114 ++ "int $4\n0:\n"
27115 ++ _ASM_EXTABLE(0b, 0b)
27116 ++#endif
27117 ++
27118 ++ "sete %1\n"
27119 + : "=m" (v->counter), "=qm" (c)
27120 + : "er" (i), "m" (v->counter) : "memory");
27121 + return c;
27122 +@@ -272,7 +389,19 @@ static inline int atomic64_sub_and_test(
27123 + */
27124 + static inline void atomic64_inc(atomic64_t *v)
27125 + {
27126 +- asm volatile(LOCK_PREFIX "incq %0"
27127 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27128 ++
27129 ++#ifdef CONFIG_PAX_REFCOUNT
27130 ++ "jno 0f\n"
27131 ++ "int $4\n0:\n"
27132 ++ ".pushsection .fixup,\"ax\"\n"
27133 ++ "1:\n"
27134 ++ LOCK_PREFIX "decq %0\n"
27135 ++ "jmp 0b\n"
27136 ++ ".popsection\n"
27137 ++ _ASM_EXTABLE(0b, 1b)
27138 ++#endif
27139 ++
27140 + : "=m" (v->counter)
27141 + : "m" (v->counter));
27142 + }
27143 +@@ -285,7 +414,19 @@ static inline void atomic64_inc(atomic64
27144 + */
27145 + static inline void atomic64_dec(atomic64_t *v)
27146 + {
27147 +- asm volatile(LOCK_PREFIX "decq %0"
27148 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27149 ++
27150 ++#ifdef CONFIG_PAX_REFCOUNT
27151 ++ "jno 0f\n"
27152 ++ "int $4\n0:\n"
27153 ++ ".pushsection .fixup,\"ax\"\n"
27154 ++ "1: \n"
27155 ++ LOCK_PREFIX "incq %0\n"
27156 ++ "jmp 0b\n"
27157 ++ ".popsection\n"
27158 ++ _ASM_EXTABLE(0b, 1b)
27159 ++#endif
27160 ++
27161 + : "=m" (v->counter)
27162 + : "m" (v->counter));
27163 + }
27164 +@@ -302,7 +443,20 @@ static inline int atomic64_dec_and_test(
27165 + {
27166 + unsigned char c;
27167 +
27168 +- asm volatile(LOCK_PREFIX "decq %0; sete %1"
27169 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27170 ++
27171 ++#ifdef CONFIG_PAX_REFCOUNT
27172 ++ "jno 0f\n"
27173 ++ "int $4\n0:\n"
27174 ++ ".pushsection .fixup,\"ax\"\n"
27175 ++ "1: \n"
27176 ++ LOCK_PREFIX "incq %0\n"
27177 ++ "jmp 0b\n"
27178 ++ ".popsection\n"
27179 ++ _ASM_EXTABLE(0b, 1b)
27180 ++#endif
27181 ++
27182 ++ "sete %1\n"
27183 + : "=m" (v->counter), "=qm" (c)
27184 + : "m" (v->counter) : "memory");
27185 + return c != 0;
27186 +@@ -320,7 +474,20 @@ static inline int atomic64_inc_and_test(
27187 + {
27188 + unsigned char c;
27189 +
27190 +- asm volatile(LOCK_PREFIX "incq %0; sete %1"
27191 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27192 ++
27193 ++#ifdef CONFIG_PAX_REFCOUNT
27194 ++ "jno 0f\n"
27195 ++ "int $4\n0:\n"
27196 ++ ".pushsection .fixup,\"ax\"\n"
27197 ++ "1: \n"
27198 ++ LOCK_PREFIX "decq %0\n"
27199 ++ "jmp 0b\n"
27200 ++ ".popsection\n"
27201 ++ _ASM_EXTABLE(0b, 1b)
27202 ++#endif
27203 ++
27204 ++ "sete %1\n"
27205 + : "=m" (v->counter), "=qm" (c)
27206 + : "m" (v->counter) : "memory");
27207 + return c != 0;
27208 +@@ -339,7 +506,16 @@ static inline int atomic64_add_negative(
27209 + {
27210 + unsigned char c;
27211 +
27212 +- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
27213 ++ asm volatile(LOCK_PREFIX "addq %2,%0\n"
27214 ++
27215 ++#ifdef CONFIG_PAX_REFCOUNT
27216 ++ "jno 0f\n"
27217 ++ LOCK_PREFIX "subq %2,%0\n"
27218 ++ "int $4\n0:\n"
27219 ++ _ASM_EXTABLE(0b, 0b)
27220 ++#endif
27221 ++
27222 ++ "sets %1\n"
27223 + : "=m" (v->counter), "=qm" (c)
27224 + : "er" (i), "m" (v->counter) : "memory");
27225 + return c;
27226 +@@ -355,7 +531,15 @@ static inline int atomic64_add_negative(
27227 + static inline long atomic64_add_return(long i, atomic64_t *v)
27228 + {
27229 + long __i = i;
27230 +- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
27231 ++ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
27232 ++
27233 ++#ifdef CONFIG_PAX_REFCOUNT
27234 ++ "jno 0f\n"
27235 ++ "movq %0, %1\n"
27236 ++ "int $4\n0:\n"
27237 ++ _ASM_EXTABLE(0b, 0b)
27238 ++#endif
27239 ++
27240 + : "+r" (i), "+m" (v->counter)
27241 + : : "memory");
27242 + return i + __i;
27243 +diff -urNp linux-2.6.27.10/include/asm-x86/boot.h linux-2.6.27.10/include/asm-x86/boot.h
27244 +--- linux-2.6.27.10/include/asm-x86/boot.h 2008-11-07 12:55:34.000000000 -0500
27245 ++++ linux-2.6.27.10/include/asm-x86/boot.h 2008-11-18 03:38:45.000000000 -0500
27246 +@@ -13,10 +13,15 @@
27247 + #define ASK_VGA 0xfffd /* ask for it at bootup */
27248 +
27249 + /* Physical address where kernel should be loaded. */
27250 +-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27251 ++#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27252 + + (CONFIG_PHYSICAL_ALIGN - 1)) \
27253 + & ~(CONFIG_PHYSICAL_ALIGN - 1))
27254 +
27255 ++#ifndef __ASSEMBLY__
27256 ++extern unsigned char __LOAD_PHYSICAL_ADDR[];
27257 ++#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
27258 ++#endif
27259 ++
27260 + #ifdef CONFIG_X86_64
27261 + #define BOOT_HEAP_SIZE 0x7000
27262 + #define BOOT_STACK_SIZE 0x4000
27263 +diff -urNp linux-2.6.27.10/include/asm-x86/cache.h linux-2.6.27.10/include/asm-x86/cache.h
27264 +--- linux-2.6.27.10/include/asm-x86/cache.h 2008-11-07 12:55:34.000000000 -0500
27265 ++++ linux-2.6.27.10/include/asm-x86/cache.h 2008-11-18 03:38:45.000000000 -0500
27266 +@@ -6,6 +6,7 @@
27267 + #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
27268 +
27269 + #define __read_mostly __attribute__((__section__(".data.read_mostly")))
27270 ++#define __read_only __attribute__((__section__(".data.read_only")))
27271 +
27272 + #ifdef CONFIG_X86_VSMP
27273 + /* vSMP Internode cacheline shift */
27274 +diff -urNp linux-2.6.27.10/include/asm-x86/checksum_32.h linux-2.6.27.10/include/asm-x86/checksum_32.h
27275 +--- linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-07 12:55:34.000000000 -0500
27276 ++++ linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-18 03:38:45.000000000 -0500
27277 +@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
27278 + int len, __wsum sum,
27279 + int *src_err_ptr, int *dst_err_ptr);
27280 +
27281 ++asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
27282 ++ int len, __wsum sum,
27283 ++ int *src_err_ptr, int *dst_err_ptr);
27284 ++
27285 ++asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
27286 ++ int len, __wsum sum,
27287 ++ int *src_err_ptr, int *dst_err_ptr);
27288 ++
27289 + /*
27290 + * Note: when you get a NULL pointer exception here this means someone
27291 + * passed in an incorrect kernel address to one of these functions.
27292 +@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
27293 + int *err_ptr)
27294 + {
27295 + might_sleep();
27296 +- return csum_partial_copy_generic((__force void *)src, dst,
27297 ++ return csum_partial_copy_generic_from_user((__force void *)src, dst,
27298 + len, sum, err_ptr, NULL);
27299 + }
27300 +
27301 +@@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us
27302 + {
27303 + might_sleep();
27304 + if (access_ok(VERIFY_WRITE, dst, len))
27305 +- return csum_partial_copy_generic(src, (__force void *)dst,
27306 ++ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
27307 + len, sum, NULL, err_ptr);
27308 +
27309 + if (len)
27310 +diff -urNp linux-2.6.27.10/include/asm-x86/desc.h linux-2.6.27.10/include/asm-x86/desc.h
27311 +--- linux-2.6.27.10/include/asm-x86/desc.h 2008-11-07 12:55:34.000000000 -0500
27312 ++++ linux-2.6.27.10/include/asm-x86/desc.h 2008-11-18 03:38:45.000000000 -0500
27313 +@@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_
27314 + desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
27315 + desc->type = (info->read_exec_only ^ 1) << 1;
27316 + desc->type |= info->contents << 2;
27317 ++ desc->type |= info->seg_not_present ^ 1;
27318 + desc->s = 1;
27319 + desc->dpl = 0x3;
27320 + desc->p = info->seg_not_present ^ 1;
27321 +@@ -27,16 +28,12 @@ static inline void fill_ldt(struct desc_
27322 + }
27323 +
27324 + extern struct desc_ptr idt_descr;
27325 +-extern gate_desc idt_table[];
27326 +-
27327 +-struct gdt_page {
27328 +- struct desc_struct gdt[GDT_ENTRIES];
27329 +-} __attribute__((aligned(PAGE_SIZE)));
27330 +-DECLARE_PER_CPU(struct gdt_page, gdt_page);
27331 ++extern gate_desc idt_table[256];
27332 +
27333 ++extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
27334 + static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
27335 + {
27336 +- return per_cpu(gdt_page, cpu).gdt;
27337 ++ return cpu_gdt_table[cpu];
27338 + }
27339 +
27340 + #ifdef CONFIG_X86_64
27341 +@@ -65,7 +62,6 @@ static inline void pack_gate(gate_desc *
27342 + gate->b = (base & 0xffff0000) |
27343 + (((0x80 | type | (dpl << 5)) & 0xff) << 8);
27344 + }
27345 +-
27346 + #endif
27347 +
27348 + static inline int desc_empty(const void *ptr)
27349 +@@ -102,19 +98,48 @@ static inline int desc_empty(const void
27350 + static inline void native_write_idt_entry(gate_desc *idt, int entry,
27351 + const gate_desc *gate)
27352 + {
27353 ++
27354 ++#ifdef CONFIG_PAX_KERNEXEC
27355 ++ unsigned long cr0;
27356 ++
27357 ++ pax_open_kernel(cr0);
27358 ++#endif
27359 ++
27360 + memcpy(&idt[entry], gate, sizeof(*gate));
27361 ++
27362 ++#ifdef CONFIG_PAX_KERNEXEC
27363 ++ pax_close_kernel(cr0);
27364 ++#endif
27365 ++
27366 + }
27367 +
27368 + static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
27369 + const void *desc)
27370 + {
27371 ++
27372 ++#ifdef CONFIG_PAX_KERNEXEC
27373 ++ unsigned long cr0;
27374 ++
27375 ++ pax_open_kernel(cr0);
27376 ++#endif
27377 ++
27378 + memcpy(&ldt[entry], desc, 8);
27379 ++
27380 ++#ifdef CONFIG_PAX_KERNEXEC
27381 ++ pax_close_kernel(cr0);
27382 ++#endif
27383 ++
27384 + }
27385 +
27386 + static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
27387 + const void *desc, int type)
27388 + {
27389 + unsigned int size;
27390 ++
27391 ++#ifdef CONFIG_PAX_KERNEXEC
27392 ++ unsigned long cr0;
27393 ++#endif
27394 ++
27395 + switch (type) {
27396 + case DESC_TSS:
27397 + size = sizeof(tss_desc);
27398 +@@ -126,7 +151,17 @@ static inline void native_write_gdt_entr
27399 + size = sizeof(struct desc_struct);
27400 + break;
27401 + }
27402 ++
27403 ++#ifdef CONFIG_PAX_KERNEXEC
27404 ++ pax_open_kernel(cr0);
27405 ++#endif
27406 ++
27407 + memcpy(&gdt[entry], desc, size);
27408 ++
27409 ++#ifdef CONFIG_PAX_KERNEXEC
27410 ++ pax_close_kernel(cr0);
27411 ++#endif
27412 ++
27413 + }
27414 +
27415 + static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
27416 +@@ -198,7 +233,19 @@ static inline void native_set_ldt(const
27417 +
27418 + static inline void native_load_tr_desc(void)
27419 + {
27420 ++
27421 ++#ifdef CONFIG_PAX_KERNEXEC
27422 ++ unsigned long cr0;
27423 ++
27424 ++ pax_open_kernel(cr0);
27425 ++#endif
27426 ++
27427 + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
27428 ++
27429 ++#ifdef CONFIG_PAX_KERNEXEC
27430 ++ pax_close_kernel(cr0);
27431 ++#endif
27432 ++
27433 + }
27434 +
27435 + static inline void native_load_gdt(const struct desc_ptr *dtr)
27436 +@@ -233,8 +280,19 @@ static inline void native_load_tls(struc
27437 + unsigned int i;
27438 + struct desc_struct *gdt = get_cpu_gdt_table(cpu);
27439 +
27440 ++#ifdef CONFIG_PAX_KERNEXEC
27441 ++ unsigned long cr0;
27442 ++
27443 ++ pax_open_kernel(cr0);
27444 ++#endif
27445 ++
27446 + for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
27447 + gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
27448 ++
27449 ++#ifdef CONFIG_PAX_KERNEXEC
27450 ++ pax_close_kernel(cr0);
27451 ++#endif
27452 ++
27453 + }
27454 +
27455 + #define _LDT_empty(info) \
27456 +@@ -372,6 +430,18 @@ static inline void set_system_gate_ist(i
27457 + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
27458 + }
27459 +
27460 ++#ifdef CONFIG_X86_32
27461 ++static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
27462 ++{
27463 ++ struct desc_struct d;
27464 ++
27465 ++ if (likely(limit))
27466 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
27467 ++ pack_descriptor(&d, base, limit, 0xFB, 0xC);
27468 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
27469 ++}
27470 ++#endif
27471 ++
27472 + #else
27473 + /*
27474 + * GET_DESC_BASE reads the descriptor base of the specified segment.
27475 +diff -urNp linux-2.6.27.10/include/asm-x86/e820.h linux-2.6.27.10/include/asm-x86/e820.h
27476 +--- linux-2.6.27.10/include/asm-x86/e820.h 2008-11-07 12:55:34.000000000 -0500
27477 ++++ linux-2.6.27.10/include/asm-x86/e820.h 2008-11-18 03:38:45.000000000 -0500
27478 +@@ -131,7 +131,7 @@ extern char *memory_setup(void);
27479 + #define ISA_END_ADDRESS 0x100000
27480 + #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
27481 +
27482 +-#define BIOS_BEGIN 0x000a0000
27483 ++#define BIOS_BEGIN 0x000c0000
27484 + #define BIOS_END 0x00100000
27485 +
27486 + #ifdef __KERNEL__
27487 +diff -urNp linux-2.6.27.10/include/asm-x86/elf.h linux-2.6.27.10/include/asm-x86/elf.h
27488 +--- linux-2.6.27.10/include/asm-x86/elf.h 2008-11-07 12:55:34.000000000 -0500
27489 ++++ linux-2.6.27.10/include/asm-x86/elf.h 2008-11-18 03:38:45.000000000 -0500
27490 +@@ -251,7 +251,25 @@ extern int force_personality32;
27491 + the loader. We need to make sure that it is out of the way of the program
27492 + that it will "exec", and that there is sufficient room for the brk. */
27493 +
27494 ++#ifdef CONFIG_PAX_SEGMEXEC
27495 ++#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
27496 ++#else
27497 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
27498 ++#endif
27499 ++
27500 ++#ifdef CONFIG_PAX_ASLR
27501 ++#ifdef CONFIG_X86_32
27502 ++#define PAX_ELF_ET_DYN_BASE 0x10000000UL
27503 ++
27504 ++#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27505 ++#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27506 ++#else
27507 ++#define PAX_ELF_ET_DYN_BASE 0x400000UL
27508 ++
27509 ++#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27510 ++#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27511 ++#endif
27512 ++#endif
27513 +
27514 + /* This yields a mask that user programs can use to figure out what
27515 + instruction set this CPU supports. This could be done in user space,
27516 +@@ -303,8 +321,7 @@ do { \
27517 + #define ARCH_DLINFO \
27518 + do { \
27519 + if (vdso_enabled) \
27520 +- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
27521 +- (unsigned long)current->mm->context.vdso); \
27522 ++ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
27523 + } while (0)
27524 +
27525 + #define AT_SYSINFO 32
27526 +@@ -315,7 +332,7 @@ do { \
27527 +
27528 + #endif /* !CONFIG_X86_32 */
27529 +
27530 +-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
27531 ++#define VDSO_CURRENT_BASE (current->mm->context.vdso)
27532 +
27533 + #define VDSO_ENTRY \
27534 + ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
27535 +@@ -329,7 +346,4 @@ extern int arch_setup_additional_pages(s
27536 + extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
27537 + #define compat_arch_setup_additional_pages syscall32_setup_pages
27538 +
27539 +-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
27540 +-#define arch_randomize_brk arch_randomize_brk
27541 +-
27542 + #endif
27543 +diff -urNp linux-2.6.27.10/include/asm-x86/futex.h linux-2.6.27.10/include/asm-x86/futex.h
27544 +--- linux-2.6.27.10/include/asm-x86/futex.h 2008-11-07 12:55:34.000000000 -0500
27545 ++++ linux-2.6.27.10/include/asm-x86/futex.h 2008-11-18 03:38:45.000000000 -0500
27546 +@@ -11,6 +11,40 @@
27547 + #include <asm/processor.h>
27548 + #include <asm/system.h>
27549 +
27550 ++#ifdef CONFIG_X86_32
27551 ++#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27552 ++ asm volatile( \
27553 ++ "movw\t%w6, %%ds\n" \
27554 ++ "1:\t" insn "\n" \
27555 ++ "2:\tpushl\t%%ss\n" \
27556 ++ "\tpopl\t%%ds\n" \
27557 ++ "\t.section .fixup,\"ax\"\n" \
27558 ++ "3:\tmov\t%3, %1\n" \
27559 ++ "\tjmp\t2b\n" \
27560 ++ "\t.previous\n" \
27561 ++ _ASM_EXTABLE(1b, 3b) \
27562 ++ : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
27563 ++ : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS))
27564 ++
27565 ++#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
27566 ++ asm volatile("movw\t%w7, %%es\n" \
27567 ++ "1:\tmovl\t%%es:%2, %0\n" \
27568 ++ "\tmovl\t%0, %3\n" \
27569 ++ "\t" insn "\n" \
27570 ++ "2:\tlock; cmpxchgl %3, %%es:%2\n" \
27571 ++ "\tjnz\t1b\n" \
27572 ++ "3:\tpushl\t%%ss\n" \
27573 ++ "\tpopl\t%%es\n" \
27574 ++ "\t.section .fixup,\"ax\"\n" \
27575 ++ "4:\tmov\t%5, %1\n" \
27576 ++ "\tjmp\t3b\n" \
27577 ++ "\t.previous\n" \
27578 ++ _ASM_EXTABLE(1b, 4b) \
27579 ++ _ASM_EXTABLE(2b, 4b) \
27580 ++ : "=&a" (oldval), "=&r" (ret), \
27581 ++ "+m" (*uaddr), "=&r" (tem) \
27582 ++ : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS))
27583 ++#else
27584 + #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27585 + asm volatile("1:\t" insn "\n" \
27586 + "2:\t.section .fixup,\"ax\"\n" \
27587 +@@ -36,8 +70,9 @@
27588 + : "=&a" (oldval), "=&r" (ret), \
27589 + "+m" (*uaddr), "=&r" (tem) \
27590 + : "r" (oparg), "i" (-EFAULT), "1" (0))
27591 ++#endif
27592 +
27593 +-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
27594 ++static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
27595 + {
27596 + int op = (encoded_op >> 28) & 7;
27597 + int cmp = (encoded_op >> 24) & 15;
27598 +@@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser
27599 +
27600 + switch (op) {
27601 + case FUTEX_OP_SET:
27602 ++#ifdef CONFIG_X86_32
27603 ++ __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg);
27604 ++#else
27605 + __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
27606 ++#endif
27607 + break;
27608 + case FUTEX_OP_ADD:
27609 ++#ifdef CONFIG_X86_32
27610 ++ __futex_atomic_op1("lock ; xaddl %0, %%ds:%2", ret, oldval,
27611 ++ uaddr, oparg);
27612 ++#else
27613 + __futex_atomic_op1("lock; xaddl %0, %2", ret, oldval,
27614 + uaddr, oparg);
27615 ++#endif
27616 + break;
27617 + case FUTEX_OP_OR:
27618 + __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg);
27619 +@@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser
27620 + return ret;
27621 + }
27622 +
27623 +-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
27624 ++static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
27625 + int newval)
27626 + {
27627 +
27628 +@@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i
27629 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
27630 + return -EFAULT;
27631 +
27632 +- asm volatile("1:\tlock; cmpxchgl %3, %1\n"
27633 ++ asm volatile(
27634 ++#ifdef CONFIG_X86_32
27635 ++ "\tmovw %w5, %%ds\n"
27636 ++ "1:\tlock; cmpxchgl %3, %1\n"
27637 ++ "2:\tpushl %%ss\n"
27638 ++ "\tpopl %%ds\n"
27639 ++ "\t.section .fixup, \"ax\"\n"
27640 ++#else
27641 ++ "1:\tlock; cmpxchgl %3, %1\n"
27642 + "2:\t.section .fixup, \"ax\"\n"
27643 ++#endif
27644 + "3:\tmov %2, %0\n"
27645 + "\tjmp 2b\n"
27646 + "\t.previous\n"
27647 + _ASM_EXTABLE(1b, 3b)
27648 + : "=a" (oldval), "+m" (*uaddr)
27649 ++#ifdef CONFIG_X86_32
27650 ++ : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS)
27651 ++#else
27652 + : "i" (-EFAULT), "r" (newval), "0" (oldval)
27653 ++#endif
27654 + : "memory"
27655 + );
27656 +
27657 +diff -urNp linux-2.6.27.10/include/asm-x86/i387.h linux-2.6.27.10/include/asm-x86/i387.h
27658 +--- linux-2.6.27.10/include/asm-x86/i387.h 2008-11-07 12:55:34.000000000 -0500
27659 ++++ linux-2.6.27.10/include/asm-x86/i387.h 2008-11-18 03:38:45.000000000 -0500
27660 +@@ -159,13 +159,8 @@ static inline void restore_fpu(struct ta
27661 + }
27662 +
27663 + /* We need a safe address that is cheap to find and that is already
27664 +- in L1 during context switch. The best choices are unfortunately
27665 +- different for UP and SMP */
27666 +-#ifdef CONFIG_SMP
27667 +-#define safe_address (__per_cpu_offset[0])
27668 +-#else
27669 +-#define safe_address (kstat_cpu(0).cpustat.user)
27670 +-#endif
27671 ++ in L1 during context switch. */
27672 ++#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
27673 +
27674 + /*
27675 + * These must be called with preempt disabled
27676 +diff -urNp linux-2.6.27.10/include/asm-x86/io_64.h linux-2.6.27.10/include/asm-x86/io_64.h
27677 +--- linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-07 12:55:34.000000000 -0500
27678 ++++ linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-18 03:38:45.000000000 -0500
27679 +@@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne
27680 + }
27681 + #endif
27682 +
27683 ++#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
27684 ++static inline int valid_phys_addr_range (unsigned long addr, size_t count)
27685 ++{
27686 ++ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27687 ++}
27688 ++
27689 ++static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count)
27690 ++{
27691 ++ return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27692 ++}
27693 ++
27694 + /*
27695 + * Change "struct page" to physical address.
27696 + */
27697 +diff -urNp linux-2.6.27.10/include/asm-x86/irqflags.h linux-2.6.27.10/include/asm-x86/irqflags.h
27698 +--- linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-07 12:55:34.000000000 -0500
27699 ++++ linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-18 03:38:45.000000000 -0500
27700 +@@ -141,6 +141,8 @@ static inline unsigned long __raw_local_
27701 + #define INTERRUPT_RETURN iret
27702 + #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
27703 + #define GET_CR0_INTO_EAX movl %cr0, %eax
27704 ++#define GET_CR0_INTO_EDX movl %cr0, %edx
27705 ++#define SET_CR0_FROM_EDX movl %edx, %cr0
27706 + #endif
27707 +
27708 +
27709 +diff -urNp linux-2.6.27.10/include/asm-x86/kmap_types.h linux-2.6.27.10/include/asm-x86/kmap_types.h
27710 +--- linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
27711 ++++ linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
27712 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
27713 + D(10) KM_IRQ1,
27714 + D(11) KM_SOFTIRQ0,
27715 + D(12) KM_SOFTIRQ1,
27716 +-D(13) KM_TYPE_NR
27717 ++D(13) KM_CLEARPAGE,
27718 ++D(14) KM_TYPE_NR
27719 + };
27720 +
27721 + #undef D
27722 +diff -urNp linux-2.6.27.10/include/asm-x86/linkage.h linux-2.6.27.10/include/asm-x86/linkage.h
27723 +--- linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-07 12:55:34.000000000 -0500
27724 ++++ linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-18 03:38:45.000000000 -0500
27725 +@@ -7,6 +7,11 @@
27726 + #ifdef CONFIG_X86_64
27727 + #define __ALIGN .p2align 4,,15
27728 + #define __ALIGN_STR ".p2align 4,,15"
27729 ++#else
27730 ++#ifdef CONFIG_X86_ALIGNMENT_16
27731 ++#define __ALIGN .align 16,0x90
27732 ++#define __ALIGN_STR ".align 16,0x90"
27733 ++#endif
27734 + #endif
27735 +
27736 + #ifdef CONFIG_X86_32
27737 +@@ -52,10 +57,5 @@
27738 +
27739 + #endif
27740 +
27741 +-#ifdef CONFIG_X86_ALIGNMENT_16
27742 +-#define __ALIGN .align 16,0x90
27743 +-#define __ALIGN_STR ".align 16,0x90"
27744 +-#endif
27745 +-
27746 + #endif
27747 +
27748 +diff -urNp linux-2.6.27.10/include/asm-x86/local.h linux-2.6.27.10/include/asm-x86/local.h
27749 +--- linux-2.6.27.10/include/asm-x86/local.h 2008-11-07 12:55:34.000000000 -0500
27750 ++++ linux-2.6.27.10/include/asm-x86/local.h 2008-11-18 03:38:45.000000000 -0500
27751 +@@ -18,26 +18,90 @@ typedef struct {
27752 +
27753 + static inline void local_inc(local_t *l)
27754 + {
27755 +- asm volatile(_ASM_INC "%0"
27756 ++ asm volatile(_ASM_INC "%0\n"
27757 ++
27758 ++#ifdef CONFIG_PAX_REFCOUNT
27759 ++#ifdef CONFIG_X86_32
27760 ++ "into\n0:\n"
27761 ++#else
27762 ++ "jno 0f\n"
27763 ++ "int $4\n0:\n"
27764 ++#endif
27765 ++ ".pushsection .fixup,\"ax\"\n"
27766 ++ "1:\n"
27767 ++ _ASM_DEC "%0\n"
27768 ++ "jmp 0b\n"
27769 ++ ".popsection\n"
27770 ++ _ASM_EXTABLE(0b, 1b)
27771 ++#endif
27772 ++
27773 + : "+m" (l->a.counter));
27774 + }
27775 +
27776 + static inline void local_dec(local_t *l)
27777 + {
27778 +- asm volatile(_ASM_DEC "%0"
27779 ++ asm volatile(_ASM_DEC "%0\n"
27780 ++
27781 ++#ifdef CONFIG_PAX_REFCOUNT
27782 ++#ifdef CONFIG_X86_32
27783 ++ "into\n0:\n"
27784 ++#else
27785 ++ "jno 0f\n"
27786 ++ "int $4\n0:\n"
27787 ++#endif
27788 ++ ".pushsection .fixup,\"ax\"\n"
27789 ++ "1:\n"
27790 ++ _ASM_INC "%0\n"
27791 ++ "jmp 0b\n"
27792 ++ ".popsection\n"
27793 ++ _ASM_EXTABLE(0b, 1b)
27794 ++#endif
27795 ++
27796 + : "+m" (l->a.counter));
27797 + }
27798 +
27799 + static inline void local_add(long i, local_t *l)
27800 + {
27801 +- asm volatile(_ASM_ADD "%1,%0"
27802 ++ asm volatile(_ASM_ADD "%1,%0\n"
27803 ++
27804 ++#ifdef CONFIG_PAX_REFCOUNT
27805 ++#ifdef CONFIG_X86_32
27806 ++ "into\n0:\n"
27807 ++#else
27808 ++ "jno 0f\n"
27809 ++ "int $4\n0:\n"
27810 ++#endif
27811 ++ ".pushsection .fixup,\"ax\"\n"
27812 ++ "1:\n"
27813 ++ _ASM_SUB "%1,%0\n"
27814 ++ "jmp 0b\n"
27815 ++ ".popsection\n"
27816 ++ _ASM_EXTABLE(0b, 1b)
27817 ++#endif
27818 ++
27819 + : "+m" (l->a.counter)
27820 + : "ir" (i));
27821 + }
27822 +
27823 + static inline void local_sub(long i, local_t *l)
27824 + {
27825 +- asm volatile(_ASM_SUB "%1,%0"
27826 ++ asm volatile(_ASM_SUB "%1,%0\n"
27827 ++
27828 ++#ifdef CONFIG_PAX_REFCOUNT
27829 ++#ifdef CONFIG_X86_32
27830 ++ "into\n0:\n"
27831 ++#else
27832 ++ "jno 0f\n"
27833 ++ "int $4\n0:\n"
27834 ++#endif
27835 ++ ".pushsection .fixup,\"ax\"\n"
27836 ++ "1:\n"
27837 ++ _ASM_ADD "%1,%0\n"
27838 ++ "jmp 0b\n"
27839 ++ ".popsection\n"
27840 ++ _ASM_EXTABLE(0b, 1b)
27841 ++#endif
27842 ++
27843 + : "+m" (l->a.counter)
27844 + : "ir" (i));
27845 + }
27846 +@@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon
27847 + {
27848 + unsigned char c;
27849 +
27850 +- asm volatile(_ASM_SUB "%2,%0; sete %1"
27851 ++ asm volatile(_ASM_SUB "%2,%0\n"
27852 ++
27853 ++#ifdef CONFIG_PAX_REFCOUNT
27854 ++#ifdef CONFIG_X86_32
27855 ++ "into\n0:\n"
27856 ++#else
27857 ++ "jno 0f\n"
27858 ++ "int $4\n0:\n"
27859 ++#endif
27860 ++ ".pushsection .fixup,\"ax\"\n"
27861 ++ "1:\n"
27862 ++ _ASM_ADD "%2,%0\n"
27863 ++ "jmp 0b\n"
27864 ++ ".popsection\n"
27865 ++ _ASM_EXTABLE(0b, 1b)
27866 ++#endif
27867 ++
27868 ++ "sete %1\n"
27869 + : "+m" (l->a.counter), "=qm" (c)
27870 + : "ir" (i) : "memory");
27871 + return c;
27872 +@@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc
27873 + {
27874 + unsigned char c;
27875 +
27876 +- asm volatile(_ASM_DEC "%0; sete %1"
27877 ++ asm volatile(_ASM_DEC "%0\n"
27878 ++
27879 ++#ifdef CONFIG_PAX_REFCOUNT
27880 ++#ifdef CONFIG_X86_32
27881 ++ "into\n0:\n"
27882 ++#else
27883 ++ "jno 0f\n"
27884 ++ "int $4\n0:\n"
27885 ++#endif
27886 ++ ".pushsection .fixup,\"ax\"\n"
27887 ++ "1:\n"
27888 ++ _ASM_INC "%0\n"
27889 ++ "jmp 0b\n"
27890 ++ ".popsection\n"
27891 ++ _ASM_EXTABLE(0b, 1b)
27892 ++#endif
27893 ++
27894 ++ "sete %1\n"
27895 + : "+m" (l->a.counter), "=qm" (c)
27896 + : : "memory");
27897 + return c != 0;
27898 +@@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc
27899 + {
27900 + unsigned char c;
27901 +
27902 +- asm volatile(_ASM_INC "%0; sete %1"
27903 ++ asm volatile(_ASM_INC "%0\n"
27904 ++
27905 ++#ifdef CONFIG_PAX_REFCOUNT
27906 ++#ifdef CONFIG_X86_32
27907 ++ "into\n0:\n"
27908 ++#else
27909 ++ "jno 0f\n"
27910 ++ "int $4\n0:\n"
27911 ++#endif
27912 ++ ".pushsection .fixup,\"ax\"\n"
27913 ++ "1:\n"
27914 ++ _ASM_DEC "%0\n"
27915 ++ "jmp 0b\n"
27916 ++ ".popsection\n"
27917 ++ _ASM_EXTABLE(0b, 1b)
27918 ++#endif
27919 ++
27920 ++ "sete %1\n"
27921 + : "+m" (l->a.counter), "=qm" (c)
27922 + : : "memory");
27923 + return c != 0;
27924 +@@ -110,7 +225,24 @@ static inline int local_add_negative(lon
27925 + {
27926 + unsigned char c;
27927 +
27928 +- asm volatile(_ASM_ADD "%2,%0; sets %1"
27929 ++ asm volatile(_ASM_ADD "%2,%0\n"
27930 ++
27931 ++#ifdef CONFIG_PAX_REFCOUNT
27932 ++#ifdef CONFIG_X86_32
27933 ++ "into\n0:\n"
27934 ++#else
27935 ++ "jno 0f\n"
27936 ++ "int $4\n0:\n"
27937 ++#endif
27938 ++ ".pushsection .fixup,\"ax\"\n"
27939 ++ "1:\n"
27940 ++ _ASM_SUB "%2,%0\n"
27941 ++ "jmp 0b\n"
27942 ++ ".popsection\n"
27943 ++ _ASM_EXTABLE(0b, 1b)
27944 ++#endif
27945 ++
27946 ++ "sets %1\n"
27947 + : "+m" (l->a.counter), "=qm" (c)
27948 + : "ir" (i) : "memory");
27949 + return c;
27950 +@@ -133,7 +265,23 @@ static inline long local_add_return(long
27951 + #endif
27952 + /* Modern 486+ processor */
27953 + __i = i;
27954 +- asm volatile(_ASM_XADD "%0, %1;"
27955 ++ asm volatile(_ASM_XADD "%0, %1\n"
27956 ++
27957 ++#ifdef CONFIG_PAX_REFCOUNT
27958 ++#ifdef CONFIG_X86_32
27959 ++ "into\n0:\n"
27960 ++#else
27961 ++ "jno 0f\n"
27962 ++ "int $4\n0:\n"
27963 ++#endif
27964 ++ ".pushsection .fixup,\"ax\"\n"
27965 ++ "1:\n"
27966 ++ _ASM_MOV_UL "%0,%1\n"
27967 ++ "jmp 0b\n"
27968 ++ ".popsection\n"
27969 ++ _ASM_EXTABLE(0b, 1b)
27970 ++#endif
27971 ++
27972 + : "+r" (i), "+m" (l->a.counter)
27973 + : : "memory");
27974 + return i + __i;
27975 +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
27976 +--- linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-07 12:55:34.000000000 -0500
27977 ++++ linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-18 03:38:45.000000000 -0500
27978 +@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
27979 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27980 + "pushl %%edi\n\t"
27981 + "pushl %%ebp\n\t"
27982 +- "lcall *%%cs:apm_bios_entry\n\t"
27983 ++ "lcall *%%ss:apm_bios_entry\n\t"
27984 + "setc %%al\n\t"
27985 + "popl %%ebp\n\t"
27986 + "popl %%edi\n\t"
27987 +@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
27988 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27989 + "pushl %%edi\n\t"
27990 + "pushl %%ebp\n\t"
27991 +- "lcall *%%cs:apm_bios_entry\n\t"
27992 ++ "lcall *%%ss:apm_bios_entry\n\t"
27993 + "setc %%bl\n\t"
27994 + "popl %%ebp\n\t"
27995 + "popl %%edi\n\t"
27996 +diff -urNp linux-2.6.27.10/include/asm-x86/mman.h linux-2.6.27.10/include/asm-x86/mman.h
27997 +--- linux-2.6.27.10/include/asm-x86/mman.h 2008-11-07 12:55:34.000000000 -0500
27998 ++++ linux-2.6.27.10/include/asm-x86/mman.h 2008-11-18 03:38:45.000000000 -0500
27999 +@@ -17,4 +17,14 @@
28000 + #define MCL_CURRENT 1 /* lock all current mappings */
28001 + #define MCL_FUTURE 2 /* lock all future mappings */
28002 +
28003 ++#ifdef __KERNEL__
28004 ++#ifndef __ASSEMBLY__
28005 ++#ifdef CONFIG_X86_32
28006 ++#define arch_mmap_check i386_mmap_check
28007 ++int i386_mmap_check(unsigned long addr, unsigned long len,
28008 ++ unsigned long flags);
28009 ++#endif
28010 ++#endif
28011 ++#endif
28012 ++
28013 + #endif /* _ASM_X86_MMAN_H */
28014 +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
28015 +--- linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-07 12:55:34.000000000 -0500
28016 ++++ linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-18 03:38:45.000000000 -0500
28017 +@@ -33,6 +33,22 @@ static inline void switch_mm(struct mm_s
28018 + */
28019 + if (unlikely(prev->context.ldt != next->context.ldt))
28020 + load_LDT_nolock(&next->context);
28021 ++
28022 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
28023 ++ if (!nx_enabled) {
28024 ++ smp_mb__before_clear_bit();
28025 ++ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
28026 ++ smp_mb__after_clear_bit();
28027 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
28028 ++ }
28029 ++#endif
28030 ++
28031 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28032 ++ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
28033 ++ prev->context.user_cs_limit != next->context.user_cs_limit))
28034 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
28035 ++#endif
28036 ++
28037 + }
28038 + #ifdef CONFIG_SMP
28039 + else {
28040 +@@ -45,6 +61,19 @@ static inline void switch_mm(struct mm_s
28041 + */
28042 + load_cr3(next->pgd);
28043 + load_LDT_nolock(&next->context);
28044 ++
28045 ++#ifdef CONFIG_PAX_PAGEEXEC
28046 ++ if (!nx_enabled)
28047 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
28048 ++#endif
28049 ++
28050 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28051 ++#ifdef CONFIG_PAX_PAGEEXEC
28052 ++ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
28053 ++#endif
28054 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
28055 ++#endif
28056 ++
28057 + }
28058 + }
28059 + #endif
28060 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu.h linux-2.6.27.10/include/asm-x86/mmu.h
28061 +--- linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-07 12:55:34.000000000 -0500
28062 ++++ linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-18 03:38:45.000000000 -0500
28063 +@@ -11,13 +11,26 @@
28064 + * cpu_vm_mask is used to optimize ldt flushing.
28065 + */
28066 + typedef struct {
28067 +- void *ldt;
28068 ++ struct desc_struct *ldt;
28069 + #ifdef CONFIG_X86_64
28070 + rwlock_t ldtlock;
28071 + #endif
28072 + int size;
28073 + struct mutex lock;
28074 +- void *vdso;
28075 ++ unsigned long vdso;
28076 ++
28077 ++#ifdef CONFIG_X86_32
28078 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28079 ++ unsigned long user_cs_base;
28080 ++ unsigned long user_cs_limit;
28081 ++
28082 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
28083 ++ cpumask_t cpu_user_cs_mask;
28084 ++#endif
28085 ++
28086 ++#endif
28087 ++#endif
28088 ++
28089 + } mm_context_t;
28090 +
28091 + #ifdef CONFIG_SMP
28092 +diff -urNp linux-2.6.27.10/include/asm-x86/module.h linux-2.6.27.10/include/asm-x86/module.h
28093 +--- linux-2.6.27.10/include/asm-x86/module.h 2008-11-07 12:55:34.000000000 -0500
28094 ++++ linux-2.6.27.10/include/asm-x86/module.h 2008-11-18 03:38:45.000000000 -0500
28095 +@@ -76,7 +76,12 @@ struct mod_arch_specific {};
28096 + # else
28097 + # define MODULE_STACKSIZE ""
28098 + # endif
28099 +-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
28100 ++# ifdef CONFIG_GRKERNSEC
28101 ++# define MODULE_GRSEC "GRSECURITY "
28102 ++# else
28103 ++# define MODULE_GRSEC ""
28104 ++# endif
28105 ++# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC
28106 + #endif
28107 +
28108 + #endif /* _ASM_MODULE_H */
28109 +diff -urNp linux-2.6.27.10/include/asm-x86/page_32.h linux-2.6.27.10/include/asm-x86/page_32.h
28110 +--- linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-07 12:55:34.000000000 -0500
28111 ++++ linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-18 03:38:45.000000000 -0500
28112 +@@ -13,6 +13,23 @@
28113 + */
28114 + #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
28115 +
28116 ++#ifdef CONFIG_PAX_KERNEXEC
28117 ++#ifndef __ASSEMBLY__
28118 ++extern unsigned char MODULES_VADDR[];
28119 ++extern unsigned char MODULES_END[];
28120 ++extern unsigned char KERNEL_TEXT_OFFSET[];
28121 ++#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET)
28122 ++#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET)
28123 ++#endif
28124 ++#else
28125 ++#define ktla_ktva(addr) (addr)
28126 ++#define ktva_ktla(addr) (addr)
28127 ++#endif
28128 ++
28129 ++#ifdef CONFIG_PAX_PAGEEXEC
28130 ++#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1
28131 ++#endif
28132 ++
28133 + #ifdef CONFIG_4KSTACKS
28134 + #define THREAD_ORDER 0
28135 + #else
28136 +diff -urNp linux-2.6.27.10/include/asm-x86/page_64.h linux-2.6.27.10/include/asm-x86/page_64.h
28137 +--- linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-07 12:55:34.000000000 -0500
28138 ++++ linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-18 03:38:45.000000000 -0500
28139 +@@ -49,6 +49,9 @@
28140 + #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
28141 + #define __START_KERNEL_map _AC(0xffffffff80000000, UL)
28142 +
28143 ++#define ktla_ktva(addr) (addr)
28144 ++#define ktva_ktla(addr) (addr)
28145 ++
28146 + /* See Documentation/x86_64/mm.txt for a description of the memory map. */
28147 + #define __PHYSICAL_MASK_SHIFT 46
28148 + #define __VIRTUAL_MASK_SHIFT 48
28149 +@@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign
28150 + #define pfn_valid(pfn) ((pfn) < max_pfn)
28151 + #endif
28152 +
28153 ++#define nx_enabled (1)
28154 +
28155 + #endif /* _X86_64_PAGE_H */
28156 +diff -urNp linux-2.6.27.10/include/asm-x86/paravirt.h linux-2.6.27.10/include/asm-x86/paravirt.h
28157 +--- linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-07 12:55:34.000000000 -0500
28158 ++++ linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-18 03:38:45.000000000 -0500
28159 +@@ -1557,7 +1557,7 @@ static inline unsigned long __raw_local_
28160 + #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
28161 + #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
28162 + #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
28163 +-#define PARA_INDIRECT(addr) *%cs:addr
28164 ++#define PARA_INDIRECT(addr) *%ss:addr
28165 + #endif
28166 +
28167 + #define INTERRUPT_RETURN \
28168 +diff -urNp linux-2.6.27.10/include/asm-x86/pda.h linux-2.6.27.10/include/asm-x86/pda.h
28169 +--- linux-2.6.27.10/include/asm-x86/pda.h 2008-11-07 12:55:34.000000000 -0500
28170 ++++ linux-2.6.27.10/include/asm-x86/pda.h 2008-11-18 03:38:45.000000000 -0500
28171 +@@ -16,11 +16,9 @@ struct x8664_pda {
28172 + unsigned long oldrsp; /* 24 user rsp for system call */
28173 + int irqcount; /* 32 Irq nesting counter. Starts -1 */
28174 + unsigned int cpunumber; /* 36 Logical CPU number */
28175 +-#ifdef CONFIG_CC_STACKPROTECTOR
28176 + unsigned long stack_canary; /* 40 stack canary value */
28177 + /* gcc-ABI: this canary MUST be at
28178 + offset 40!!! */
28179 +-#endif
28180 + char *irqstackptr;
28181 + short nodenumber; /* number of current node (32k max) */
28182 + short in_bootmem; /* pda lives in bootmem */
28183 +diff -urNp linux-2.6.27.10/include/asm-x86/percpu.h linux-2.6.27.10/include/asm-x86/percpu.h
28184 +--- linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-07 12:55:34.000000000 -0500
28185 ++++ linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-18 03:38:45.000000000 -0500
28186 +@@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda);
28187 +
28188 + #define __my_cpu_offset x86_read_percpu(this_cpu_off)
28189 +
28190 ++#include <asm-generic/sections.h>
28191 ++#include <linux/threads.h>
28192 ++#define __per_cpu_offset __per_cpu_offset
28193 ++extern unsigned long __per_cpu_offset[NR_CPUS];
28194 ++#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start)
28195 ++
28196 + /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
28197 + #define __percpu_seg "%%fs:"
28198 +
28199 +diff -urNp linux-2.6.27.10/include/asm-x86/pgalloc.h linux-2.6.27.10/include/asm-x86/pgalloc.h
28200 +--- linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-07 12:55:34.000000000 -0500
28201 ++++ linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-18 03:38:45.000000000 -0500
28202 +@@ -51,7 +51,7 @@ static inline void pmd_populate_kernel(s
28203 + pmd_t *pmd, pte_t *pte)
28204 + {
28205 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
28206 +- set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
28207 ++ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
28208 + }
28209 +
28210 + static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
28211 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-2level.h linux-2.6.27.10/include/asm-x86/pgtable-2level.h
28212 +--- linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-07 12:55:34.000000000 -0500
28213 ++++ linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-18 03:38:45.000000000 -0500
28214 +@@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t
28215 +
28216 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28217 + {
28218 ++
28219 ++#ifdef CONFIG_PAX_KERNEXEC
28220 ++ unsigned long cr0;
28221 ++
28222 ++ pax_open_kernel(cr0);
28223 ++#endif
28224 ++
28225 + *pmdp = pmd;
28226 ++
28227 ++#ifdef CONFIG_PAX_KERNEXEC
28228 ++ pax_close_kernel(cr0);
28229 ++#endif
28230 ++
28231 + }
28232 +
28233 + static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
28234 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_32.h linux-2.6.27.10/include/asm-x86/pgtable_32.h
28235 +--- linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
28236 ++++ linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-18 03:38:45.000000000 -0500
28237 +@@ -25,8 +25,6 @@
28238 + struct mm_struct;
28239 + struct vm_area_struct;
28240 +
28241 +-extern pgd_t swapper_pg_dir[1024];
28242 +-
28243 + static inline void pgtable_cache_init(void) { }
28244 + static inline void check_pgt_cache(void) { }
28245 + void paging_init(void);
28246 +@@ -45,6 +43,11 @@ void paging_init(void);
28247 + # include <asm/pgtable-2level-defs.h>
28248 + #endif
28249 +
28250 ++extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
28251 ++#ifdef CONFIG_X86_PAE
28252 ++extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
28253 ++#endif
28254 ++
28255 + #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
28256 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
28257 +
28258 +@@ -81,7 +84,7 @@ void paging_init(void);
28259 + #undef TEST_ACCESS_OK
28260 +
28261 + /* The boot page tables (all created as a single array) */
28262 +-extern unsigned long pg0[];
28263 ++extern pte_t pg0[];
28264 +
28265 + #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
28266 +
28267 +@@ -173,6 +176,9 @@ do { \
28268 +
28269 + #endif /* !__ASSEMBLY__ */
28270 +
28271 ++#define HAVE_ARCH_UNMAPPED_AREA
28272 ++#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
28273 ++
28274 + /*
28275 + * kern_addr_valid() is (1) for FLATMEM and (0) for
28276 + * SPARSEMEM and DISCONTIGMEM
28277 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-3level.h linux-2.6.27.10/include/asm-x86/pgtable-3level.h
28278 +--- linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-07 12:55:34.000000000 -0500
28279 ++++ linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-18 03:38:45.000000000 -0500
28280 +@@ -70,12 +70,36 @@ static inline void native_set_pte_atomic
28281 +
28282 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28283 + {
28284 ++
28285 ++#ifdef CONFIG_PAX_KERNEXEC
28286 ++ unsigned long cr0;
28287 ++
28288 ++ pax_open_kernel(cr0);
28289 ++#endif
28290 ++
28291 + set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
28292 ++
28293 ++#ifdef CONFIG_PAX_KERNEXEC
28294 ++ pax_close_kernel(cr0);
28295 ++#endif
28296 ++
28297 + }
28298 +
28299 + static inline void native_set_pud(pud_t *pudp, pud_t pud)
28300 + {
28301 ++
28302 ++#ifdef CONFIG_PAX_KERNEXEC
28303 ++ unsigned long cr0;
28304 ++
28305 ++ pax_open_kernel(cr0);
28306 ++#endif
28307 ++
28308 + set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
28309 ++
28310 ++#ifdef CONFIG_PAX_KERNEXEC
28311 ++ pax_close_kernel(cr0);
28312 ++#endif
28313 ++
28314 + }
28315 +
28316 + /*
28317 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_64.h linux-2.6.27.10/include/asm-x86/pgtable_64.h
28318 +--- linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-07 12:55:34.000000000 -0500
28319 ++++ linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-18 03:38:45.000000000 -0500
28320 +@@ -15,9 +15,12 @@
28321 +
28322 + extern pud_t level3_kernel_pgt[512];
28323 + extern pud_t level3_ident_pgt[512];
28324 ++extern pud_t level3_vmalloc_pgt[512];
28325 ++extern pud_t level3_vmemmap_pgt[512];
28326 + extern pmd_t level2_kernel_pgt[512];
28327 + extern pmd_t level2_fixmap_pgt[512];
28328 + extern pmd_t level2_ident_pgt[512];
28329 ++extern pte_t level1_fixmap_pgt[512];
28330 + extern pgd_t init_level4_pgt[];
28331 +
28332 + #define swapper_pg_dir init_level4_pgt
28333 +@@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_
28334 +
28335 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28336 + {
28337 ++
28338 ++#ifdef CONFIG_PAX_KERNEXEC
28339 ++ unsigned long cr0;
28340 ++
28341 ++ pax_open_kernel(cr0);
28342 ++#endif
28343 ++
28344 + *pmdp = pmd;
28345 ++
28346 ++#ifdef CONFIG_PAX_KERNEXEC
28347 ++ pax_close_kernel(cr0);
28348 ++#endif
28349 ++
28350 + }
28351 +
28352 + static inline void native_pmd_clear(pmd_t *pmd)
28353 +@@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_
28354 +
28355 + static inline int pgd_bad(pgd_t pgd)
28356 + {
28357 +- return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28358 ++ return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28359 + }
28360 +
28361 + static inline int pud_bad(pud_t pud)
28362 + {
28363 +- return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28364 ++ return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28365 + }
28366 +
28367 + static inline int pmd_bad(pmd_t pmd)
28368 + {
28369 +- return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28370 ++ return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28371 + }
28372 +
28373 + #define pte_none(x) (!pte_val((x)))
28374 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable.h linux-2.6.27.10/include/asm-x86/pgtable.h
28375 +--- linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-07 12:55:34.000000000 -0500
28376 ++++ linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-18 03:38:45.000000000 -0500
28377 +@@ -41,7 +41,7 @@
28378 + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28379 + #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
28380 + #else
28381 +-#define _PAGE_NX (_AT(pteval_t, 0))
28382 ++#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
28383 + #endif
28384 +
28385 + /* If _PAGE_PRESENT is clear, we use these: */
28386 +@@ -81,6 +81,9 @@
28387 + #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
28388 + _PAGE_ACCESSED)
28389 +
28390 ++#define PAGE_READONLY_NOEXEC PAGE_READONLY
28391 ++#define PAGE_SHARED_NOEXEC PAGE_SHARED
28392 ++
28393 + #define __PAGE_KERNEL_EXEC \
28394 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
28395 + #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
28396 +@@ -92,7 +95,7 @@
28397 + #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
28398 + #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
28399 + #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
28400 +-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
28401 ++#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
28402 + #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
28403 + #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
28404 + #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
28405 +@@ -142,10 +145,17 @@ extern unsigned long empty_zero_page[PAG
28406 + extern spinlock_t pgd_lock;
28407 + extern struct list_head pgd_list;
28408 +
28409 ++extern pteval_t __supported_pte_mask;
28410 ++
28411 + /*
28412 + * The following only work if pte_present() is true.
28413 + * Undefined behaviour if not..
28414 + */
28415 ++static inline int pte_user(pte_t pte)
28416 ++{
28417 ++ return pte_val(pte) & _PAGE_USER;
28418 ++}
28419 ++
28420 + static inline int pte_dirty(pte_t pte)
28421 + {
28422 + return pte_flags(pte) & _PAGE_DIRTY;
28423 +@@ -207,9 +217,29 @@ static inline pte_t pte_wrprotect(pte_t
28424 + return __pte(pte_val(pte) & ~_PAGE_RW);
28425 + }
28426 +
28427 ++static inline pte_t pte_mkread(pte_t pte)
28428 ++{
28429 ++ return __pte(pte_val(pte) | _PAGE_USER);
28430 ++}
28431 ++
28432 + static inline pte_t pte_mkexec(pte_t pte)
28433 + {
28434 +- return __pte(pte_val(pte) & ~_PAGE_NX);
28435 ++#ifdef CONFIG_X86_PAE
28436 ++ if (__supported_pte_mask & _PAGE_NX)
28437 ++ return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
28438 ++ else
28439 ++#endif
28440 ++ return __pte(pte_val(pte) | _PAGE_USER);
28441 ++}
28442 ++
28443 ++static inline pte_t pte_exprotect(pte_t pte)
28444 ++{
28445 ++#ifdef CONFIG_X86_PAE
28446 ++ if (__supported_pte_mask & _PAGE_NX)
28447 ++ return __pte(pte_val(pte) | _PAGE_NX);
28448 ++ else
28449 ++#endif
28450 ++ return __pte(pte_val(pte) & ~_PAGE_USER);
28451 + }
28452 +
28453 + static inline pte_t pte_mkdirty(pte_t pte)
28454 +@@ -252,8 +282,6 @@ static inline pte_t pte_mkspecial(pte_t
28455 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
28456 + }
28457 +
28458 +-extern pteval_t __supported_pte_mask;
28459 +-
28460 + static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
28461 + {
28462 + return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
28463 +@@ -514,7 +542,19 @@ static inline void ptep_set_wrprotect(st
28464 + */
28465 + static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
28466 + {
28467 +- memcpy(dst, src, count * sizeof(pgd_t));
28468 ++
28469 ++#ifdef CONFIG_PAX_KERNEXEC
28470 ++ unsigned long cr0;
28471 ++
28472 ++ pax_open_kernel(cr0);
28473 ++#endif
28474 ++
28475 ++ memcpy(dst, src, count * sizeof(pgd_t));
28476 ++
28477 ++#ifdef CONFIG_PAX_KERNEXEC
28478 ++ pax_close_kernel(cr0);
28479 ++#endif
28480 ++
28481 + }
28482 +
28483 +
28484 +diff -urNp linux-2.6.27.10/include/asm-x86/processor.h linux-2.6.27.10/include/asm-x86/processor.h
28485 +--- linux-2.6.27.10/include/asm-x86/processor.h 2008-11-07 12:55:34.000000000 -0500
28486 ++++ linux-2.6.27.10/include/asm-x86/processor.h 2008-11-18 03:38:45.000000000 -0500
28487 +@@ -269,7 +269,7 @@ struct tss_struct {
28488 +
28489 + } ____cacheline_aligned;
28490 +
28491 +-DECLARE_PER_CPU(struct tss_struct, init_tss);
28492 ++extern struct tss_struct init_tss[NR_CPUS];
28493 +
28494 + /*
28495 + * Save the original ist values for checking stack pointers during debugging
28496 +@@ -832,11 +832,20 @@ static inline void spin_lock_prefetch(co
28497 + * User space process size: 3GB (default).
28498 + */
28499 + #define TASK_SIZE PAGE_OFFSET
28500 ++
28501 ++#ifdef CONFIG_PAX_SEGMEXEC
28502 ++#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
28503 ++#endif
28504 ++
28505 ++#ifdef CONFIG_PAX_SEGMEXEC
28506 ++#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
28507 ++#else
28508 + #define STACK_TOP TASK_SIZE
28509 +-#define STACK_TOP_MAX STACK_TOP
28510 ++#endif
28511 ++#define STACK_TOP_MAX TASK_SIZE
28512 +
28513 + #define INIT_THREAD { \
28514 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28515 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28516 + .vm86_info = NULL, \
28517 + .sysenter_cs = __KERNEL_CS, \
28518 + .io_bitmap_ptr = NULL, \
28519 +@@ -851,7 +860,7 @@ static inline void spin_lock_prefetch(co
28520 + */
28521 + #define INIT_TSS { \
28522 + .x86_tss = { \
28523 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28524 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28525 + .ss0 = __KERNEL_DS, \
28526 + .ss1 = __KERNEL_CS, \
28527 + .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
28528 +@@ -862,11 +871,7 @@ static inline void spin_lock_prefetch(co
28529 + extern unsigned long thread_saved_pc(struct task_struct *tsk);
28530 +
28531 + #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
28532 +-#define KSTK_TOP(info) \
28533 +-({ \
28534 +- unsigned long *__ptr = (unsigned long *)(info); \
28535 +- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
28536 +-})
28537 ++#define KSTK_TOP(info) ((info)->task.thread.sp0)
28538 +
28539 + /*
28540 + * The below -8 is to reserve 8 bytes on top of the ring0 stack.
28541 +@@ -881,7 +886,7 @@ extern unsigned long thread_saved_pc(str
28542 + #define task_pt_regs(task) \
28543 + ({ \
28544 + struct pt_regs *__regs__; \
28545 +- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
28546 ++ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
28547 + __regs__ - 1; \
28548 + })
28549 +
28550 +@@ -897,7 +902,7 @@ extern unsigned long thread_saved_pc(str
28551 + * space during mmap's.
28552 + */
28553 + #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
28554 +- 0xc0000000 : 0xFFFFe000)
28555 ++ 0xc0000000 : 0xFFFFf000)
28556 +
28557 + #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
28558 + IA32_PAGE_OFFSET : TASK_SIZE64)
28559 +@@ -934,6 +939,10 @@ extern void start_thread(struct pt_regs
28560 + */
28561 + #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
28562 +
28563 ++#ifdef CONFIG_PAX_SEGMEXEC
28564 ++#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
28565 ++#endif
28566 ++
28567 + #define KSTK_EIP(task) (task_pt_regs(task)->ip)
28568 +
28569 + /* Get/set a process' ability to use the timestamp counter instruction */
28570 +diff -urNp linux-2.6.27.10/include/asm-x86/ptrace.h linux-2.6.27.10/include/asm-x86/ptrace.h
28571 +--- linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-07 12:55:34.000000000 -0500
28572 ++++ linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-18 03:38:45.000000000 -0500
28573 +@@ -131,6 +131,7 @@ struct pt_regs {
28574 +
28575 + /* the DS BTS struct is used for ptrace as well */
28576 + #include <asm/ds.h>
28577 ++#include <asm/segment.h>
28578 +
28579 + struct task_struct;
28580 +
28581 +@@ -154,28 +155,29 @@ static inline unsigned long regs_return_
28582 + }
28583 +
28584 + /*
28585 +- * user_mode_vm(regs) determines whether a register set came from user mode.
28586 ++ * user_mode(regs) determines whether a register set came from user mode.
28587 + * This is true if V8086 mode was enabled OR if the register set was from
28588 + * protected mode with RPL-3 CS value. This tricky test checks that with
28589 + * one comparison. Many places in the kernel can bypass this full check
28590 +- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
28591 ++ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
28592 ++ * be used.
28593 + */
28594 +-static inline int user_mode(struct pt_regs *regs)
28595 ++static inline int user_mode_novm(struct pt_regs *regs)
28596 + {
28597 + #ifdef CONFIG_X86_32
28598 + return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
28599 + #else
28600 +- return !!(regs->cs & 3);
28601 ++ return !!(regs->cs & SEGMENT_RPL_MASK);
28602 + #endif
28603 + }
28604 +
28605 +-static inline int user_mode_vm(struct pt_regs *regs)
28606 ++static inline int user_mode(struct pt_regs *regs)
28607 + {
28608 + #ifdef CONFIG_X86_32
28609 + return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
28610 + USER_RPL;
28611 + #else
28612 +- return user_mode(regs);
28613 ++ return user_mode_novm(regs);
28614 + #endif
28615 + }
28616 +
28617 +diff -urNp linux-2.6.27.10/include/asm-x86/reboot.h linux-2.6.27.10/include/asm-x86/reboot.h
28618 +--- linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-07 12:55:34.000000000 -0500
28619 ++++ linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-18 03:38:45.000000000 -0500
28620 +@@ -16,6 +16,6 @@ extern struct machine_ops machine_ops;
28621 +
28622 + void native_machine_crash_shutdown(struct pt_regs *regs);
28623 + void native_machine_shutdown(void);
28624 +-void machine_real_restart(const unsigned char *code, int length);
28625 ++void machine_real_restart(const unsigned char *code, unsigned int length);
28626 +
28627 + #endif /* _ASM_REBOOT_H */
28628 +diff -urNp linux-2.6.27.10/include/asm-x86/rwsem.h linux-2.6.27.10/include/asm-x86/rwsem.h
28629 +--- linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-07 12:55:34.000000000 -0500
28630 ++++ linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-18 03:38:45.000000000 -0500
28631 +@@ -106,10 +106,26 @@ static inline void __down_read(struct rw
28632 + {
28633 + asm volatile("# beginning down_read\n\t"
28634 + LOCK_PREFIX " incl (%%eax)\n\t"
28635 ++
28636 ++#ifdef CONFIG_PAX_REFCOUNT
28637 ++#ifdef CONFIG_X86_32
28638 ++ "into\n0:\n"
28639 ++#else
28640 ++ "jno 0f\n"
28641 ++ "int $4\n0:\n"
28642 ++#endif
28643 ++ ".pushsection .fixup,\"ax\"\n"
28644 ++ "1:\n"
28645 ++ LOCK_PREFIX "decl (%%eax)\n"
28646 ++ "jmp 0b\n"
28647 ++ ".popsection\n"
28648 ++ _ASM_EXTABLE(0b, 1b)
28649 ++#endif
28650 ++
28651 + /* adds 0x00000001, returns the old value */
28652 +- " jns 1f\n"
28653 ++ " jns 2f\n"
28654 + " call call_rwsem_down_read_failed\n"
28655 +- "1:\n\t"
28656 ++ "2:\n\t"
28657 + "# ending down_read\n\t"
28658 + : "+m" (sem->count)
28659 + : "a" (sem)
28660 +@@ -124,13 +140,29 @@ static inline int __down_read_trylock(st
28661 + __s32 result, tmp;
28662 + asm volatile("# beginning __down_read_trylock\n\t"
28663 + " movl %0,%1\n\t"
28664 +- "1:\n\t"
28665 ++ "2:\n\t"
28666 + " movl %1,%2\n\t"
28667 + " addl %3,%2\n\t"
28668 +- " jle 2f\n\t"
28669 ++
28670 ++#ifdef CONFIG_PAX_REFCOUNT
28671 ++#ifdef CONFIG_X86_32
28672 ++ "into\n0:\n"
28673 ++#else
28674 ++ "jno 0f\n"
28675 ++ "int $4\n0:\n"
28676 ++#endif
28677 ++ ".pushsection .fixup,\"ax\"\n"
28678 ++ "1:\n"
28679 ++ "subl %3,%2\n"
28680 ++ "jmp 0b\n"
28681 ++ ".popsection\n"
28682 ++ _ASM_EXTABLE(0b, 1b)
28683 ++#endif
28684 ++
28685 ++ " jle 3f\n\t"
28686 + LOCK_PREFIX " cmpxchgl %2,%0\n\t"
28687 +- " jnz 1b\n\t"
28688 +- "2:\n\t"
28689 ++ " jnz 2b\n\t"
28690 ++ "3:\n\t"
28691 + "# ending __down_read_trylock\n\t"
28692 + : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
28693 + : "i" (RWSEM_ACTIVE_READ_BIAS)
28694 +@@ -148,12 +180,28 @@ static inline void __down_write_nested(s
28695 + tmp = RWSEM_ACTIVE_WRITE_BIAS;
28696 + asm volatile("# beginning down_write\n\t"
28697 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28698 ++
28699 ++#ifdef CONFIG_PAX_REFCOUNT
28700 ++#ifdef CONFIG_X86_32
28701 ++ "into\n0:\n"
28702 ++#else
28703 ++ "jno 0f\n"
28704 ++ "int $4\n0:\n"
28705 ++#endif
28706 ++ ".pushsection .fixup,\"ax\"\n"
28707 ++ "1:\n"
28708 ++ "movl %%edx,(%%eax)\n"
28709 ++ "jmp 0b\n"
28710 ++ ".popsection\n"
28711 ++ _ASM_EXTABLE(0b, 1b)
28712 ++#endif
28713 ++
28714 + /* subtract 0x0000ffff, returns the old value */
28715 + " testl %%edx,%%edx\n\t"
28716 + /* was the count 0 before? */
28717 +- " jz 1f\n"
28718 ++ " jz 2f\n"
28719 + " call call_rwsem_down_write_failed\n"
28720 +- "1:\n"
28721 ++ "2:\n"
28722 + "# ending down_write"
28723 + : "+m" (sem->count), "=d" (tmp)
28724 + : "a" (sem), "1" (tmp)
28725 +@@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s
28726 + __s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
28727 + asm volatile("# beginning __up_read\n\t"
28728 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28729 ++
28730 ++#ifdef CONFIG_PAX_REFCOUNT
28731 ++#ifdef CONFIG_X86_32
28732 ++ "into\n0:\n"
28733 ++#else
28734 ++ "jno 0f\n"
28735 ++ "int $4\n0:\n"
28736 ++#endif
28737 ++ ".pushsection .fixup,\"ax\"\n"
28738 ++ "1:\n"
28739 ++ "movl %%edx,(%%eax)\n"
28740 ++ "jmp 0b\n"
28741 ++ ".popsection\n"
28742 ++ _ASM_EXTABLE(0b, 1b)
28743 ++#endif
28744 ++
28745 + /* subtracts 1, returns the old value */
28746 +- " jns 1f\n\t"
28747 ++ " jns 2f\n\t"
28748 + " call call_rwsem_wake\n"
28749 +- "1:\n"
28750 ++ "2:\n"
28751 + "# ending __up_read\n"
28752 + : "+m" (sem->count), "=d" (tmp)
28753 + : "a" (sem), "1" (tmp)
28754 +@@ -204,11 +268,27 @@ static inline void __up_write(struct rw_
28755 + asm volatile("# beginning __up_write\n\t"
28756 + " movl %2,%%edx\n\t"
28757 + LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t"
28758 ++
28759 ++#ifdef CONFIG_PAX_REFCOUNT
28760 ++#ifdef CONFIG_X86_32
28761 ++ "into\n0:\n"
28762 ++#else
28763 ++ "jno 0f\n"
28764 ++ "int $4\n0:\n"
28765 ++#endif
28766 ++ ".pushsection .fixup,\"ax\"\n"
28767 ++ "1:\n"
28768 ++ "movl %%edx,(%%eax)\n"
28769 ++ "jmp 0b\n"
28770 ++ ".popsection\n"
28771 ++ _ASM_EXTABLE(0b, 1b)
28772 ++#endif
28773 ++
28774 + /* tries to transition
28775 + 0xffff0001 -> 0x00000000 */
28776 +- " jz 1f\n"
28777 ++ " jz 2f\n"
28778 + " call call_rwsem_wake\n"
28779 +- "1:\n\t"
28780 ++ "2:\n\t"
28781 + "# ending __up_write\n"
28782 + : "+m" (sem->count)
28783 + : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
28784 +@@ -222,10 +302,26 @@ static inline void __downgrade_write(str
28785 + {
28786 + asm volatile("# beginning __downgrade_write\n\t"
28787 + LOCK_PREFIX " addl %2,(%%eax)\n\t"
28788 ++
28789 ++#ifdef CONFIG_PAX_REFCOUNT
28790 ++#ifdef CONFIG_X86_32
28791 ++ "into\n0:\n"
28792 ++#else
28793 ++ "jno 0f\n"
28794 ++ "int $4\n0:\n"
28795 ++#endif
28796 ++ ".pushsection .fixup,\"ax\"\n"
28797 ++ "1:\n"
28798 ++ LOCK_PREFIX "subl %2,(%%eax)\n"
28799 ++ "jmp 0b\n"
28800 ++ ".popsection\n"
28801 ++ _ASM_EXTABLE(0b, 1b)
28802 ++#endif
28803 ++
28804 + /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
28805 +- " jns 1f\n\t"
28806 ++ " jns 2f\n\t"
28807 + " call call_rwsem_downgrade_wake\n"
28808 +- "1:\n\t"
28809 ++ "2:\n\t"
28810 + "# ending __downgrade_write\n"
28811 + : "+m" (sem->count)
28812 + : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
28813 +@@ -237,7 +333,23 @@ static inline void __downgrade_write(str
28814 + */
28815 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
28816 + {
28817 +- asm volatile(LOCK_PREFIX "addl %1,%0"
28818 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
28819 ++
28820 ++#ifdef CONFIG_PAX_REFCOUNT
28821 ++#ifdef CONFIG_X86_32
28822 ++ "into\n0:\n"
28823 ++#else
28824 ++ "jno 0f\n"
28825 ++ "int $4\n0:\n"
28826 ++#endif
28827 ++ ".pushsection .fixup,\"ax\"\n"
28828 ++ "1:\n"
28829 ++ LOCK_PREFIX "subl %1,%0\n"
28830 ++ "jmp 0b\n"
28831 ++ ".popsection\n"
28832 ++ _ASM_EXTABLE(0b, 1b)
28833 ++#endif
28834 ++
28835 + : "+m" (sem->count)
28836 + : "ir" (delta));
28837 + }
28838 +@@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in
28839 + {
28840 + int tmp = delta;
28841 +
28842 +- asm volatile(LOCK_PREFIX "xadd %0,%1"
28843 ++ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
28844 ++
28845 ++#ifdef CONFIG_PAX_REFCOUNT
28846 ++#ifdef CONFIG_X86_32
28847 ++ "into\n0:\n"
28848 ++#else
28849 ++ "jno 0f\n"
28850 ++ "int $4\n0:\n"
28851 ++#endif
28852 ++ ".pushsection .fixup,\"ax\"\n"
28853 ++ "1:\n"
28854 ++ "movl %0,%1\n"
28855 ++ "jmp 0b\n"
28856 ++ ".popsection\n"
28857 ++ _ASM_EXTABLE(0b, 1b)
28858 ++#endif
28859 ++
28860 + : "+r" (tmp), "+m" (sem->count)
28861 + : : "memory");
28862 +
28863 +diff -urNp linux-2.6.27.10/include/asm-x86/segment.h linux-2.6.27.10/include/asm-x86/segment.h
28864 +--- linux-2.6.27.10/include/asm-x86/segment.h 2008-11-07 12:55:34.000000000 -0500
28865 ++++ linux-2.6.27.10/include/asm-x86/segment.h 2008-11-18 03:38:45.000000000 -0500
28866 +@@ -88,13 +88,19 @@
28867 + #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
28868 + #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
28869 +
28870 +-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28871 ++#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28872 + #ifdef CONFIG_SMP
28873 + #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
28874 + #else
28875 + #define __KERNEL_PERCPU 0
28876 + #endif
28877 +
28878 ++#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16)
28879 ++#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
28880 ++
28881 ++#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17)
28882 ++#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
28883 ++
28884 + #define GDT_ENTRY_DOUBLEFAULT_TSS 31
28885 +
28886 + /*
28887 +@@ -135,10 +141,10 @@
28888 + #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
28889 +
28890 + /* Matches __KERNEL_CS and __USER_CS (they must be 2 entries apart) */
28891 +-#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xec) == GDT_ENTRY_KERNEL_CS * 8)
28892 ++#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xFFFCU) == __KERNEL_CS || ((x) & 0xFFFCU) == __USER_CS)
28893 +
28894 + /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
28895 +-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
28896 ++#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
28897 +
28898 +
28899 + #else
28900 +diff -urNp linux-2.6.27.10/include/asm-x86/spinlock.h linux-2.6.27.10/include/asm-x86/spinlock.h
28901 +--- linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-07 12:55:34.000000000 -0500
28902 ++++ linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-18 03:38:45.000000000 -0500
28903 +@@ -315,18 +315,50 @@ static inline int __raw_write_can_lock(r
28904 + static inline void __raw_read_lock(raw_rwlock_t *rw)
28905 + {
28906 + asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
28907 +- "jns 1f\n"
28908 +- "call __read_lock_failed\n\t"
28909 ++
28910 ++#ifdef CONFIG_PAX_REFCOUNT
28911 ++#ifdef CONFIG_X86_32
28912 ++ "into\n0:\n"
28913 ++#else
28914 ++ "jno 0f\n"
28915 ++ "int $4\n0:\n"
28916 ++#endif
28917 ++ ".pushsection .fixup,\"ax\"\n"
28918 + "1:\n"
28919 ++ LOCK_PREFIX " addl $1,(%0)\n"
28920 ++ "jmp 0b\n"
28921 ++ ".popsection\n"
28922 ++ _ASM_EXTABLE(0b, 1b)
28923 ++#endif
28924 ++
28925 ++ "jns 2f\n"
28926 ++ "call __read_lock_failed\n\t"
28927 ++ "2:\n"
28928 + ::LOCK_PTR_REG (rw) : "memory");
28929 + }
28930 +
28931 + static inline void __raw_write_lock(raw_rwlock_t *rw)
28932 + {
28933 + asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
28934 +- "jz 1f\n"
28935 +- "call __write_lock_failed\n\t"
28936 ++
28937 ++#ifdef CONFIG_PAX_REFCOUNT
28938 ++#ifdef CONFIG_X86_32
28939 ++ "into\n0:\n"
28940 ++#else
28941 ++ "jno 0f\n"
28942 ++ "int $4\n0:\n"
28943 ++#endif
28944 ++ ".pushsection .fixup,\"ax\"\n"
28945 + "1:\n"
28946 ++ LOCK_PREFIX " addl %1,(%0)\n"
28947 ++ "jmp 0b\n"
28948 ++ ".popsection\n"
28949 ++ _ASM_EXTABLE(0b, 1b)
28950 ++#endif
28951 ++
28952 ++ "jz 2f\n"
28953 ++ "call __write_lock_failed\n\t"
28954 ++ "2:\n"
28955 + ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory");
28956 + }
28957 +
28958 +@@ -353,12 +385,45 @@ static inline int __raw_write_trylock(ra
28959 +
28960 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
28961 + {
28962 +- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
28963 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28964 ++
28965 ++#ifdef CONFIG_PAX_REFCOUNT
28966 ++#ifdef CONFIG_X86_32
28967 ++ "into\n0:\n"
28968 ++#else
28969 ++ "jno 0f\n"
28970 ++ "int $4\n0:\n"
28971 ++#endif
28972 ++ ".pushsection .fixup,\"ax\"\n"
28973 ++ "1:\n"
28974 ++ LOCK_PREFIX "decl %0\n"
28975 ++ "jmp 0b\n"
28976 ++ ".popsection\n"
28977 ++ _ASM_EXTABLE(0b, 1b)
28978 ++#endif
28979 ++
28980 ++ :"+m" (rw->lock) : : "memory");
28981 + }
28982 +
28983 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
28984 + {
28985 +- asm volatile(LOCK_PREFIX "addl %1, %0"
28986 ++ asm volatile(LOCK_PREFIX "addl %1, %0\n"
28987 ++
28988 ++#ifdef CONFIG_PAX_REFCOUNT
28989 ++#ifdef CONFIG_X86_32
28990 ++ "into\n0:\n"
28991 ++#else
28992 ++ "jno 0f\n"
28993 ++ "int $4\n0:\n"
28994 ++#endif
28995 ++ ".pushsection .fixup,\"ax\"\n"
28996 ++ "1:\n"
28997 ++ LOCK_PREFIX "subl %1,%0\n"
28998 ++ "jmp 0b\n"
28999 ++ ".popsection\n"
29000 ++ _ASM_EXTABLE(0b, 1b)
29001 ++#endif
29002 ++
29003 + : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
29004 + }
29005 +
29006 +diff -urNp linux-2.6.27.10/include/asm-x86/system.h linux-2.6.27.10/include/asm-x86/system.h
29007 +--- linux-2.6.27.10/include/asm-x86/system.h 2008-11-07 12:55:34.000000000 -0500
29008 ++++ linux-2.6.27.10/include/asm-x86/system.h 2008-11-18 03:38:45.000000000 -0500
29009 +@@ -92,6 +92,8 @@ do { \
29010 + ".globl thread_return\n" \
29011 + "thread_return:\n\t" \
29012 + "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
29013 ++ "movq %P[task_canary](%%rsi),%%r8\n\t" \
29014 ++ "movq %%r8,%%gs:%P[pda_canary]\n\t" \
29015 + "movq %P[thread_info](%%rsi),%%r8\n\t" \
29016 + LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
29017 + "movq %%rax,%%rdi\n\t" \
29018 +@@ -103,7 +105,9 @@ do { \
29019 + [ti_flags] "i" (offsetof(struct thread_info, flags)), \
29020 + [tif_fork] "i" (TIF_FORK), \
29021 + [thread_info] "i" (offsetof(struct task_struct, stack)), \
29022 +- [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
29023 ++ [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \
29024 ++ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
29025 ++ [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
29026 + : "memory", "cc" __EXTRA_CLOBBER)
29027 + #endif
29028 +
29029 +@@ -166,7 +170,7 @@ static inline unsigned long get_limit(un
29030 + {
29031 + unsigned long __limit;
29032 + asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
29033 +- return __limit + 1;
29034 ++ return __limit;
29035 + }
29036 +
29037 + static inline void native_clts(void)
29038 +@@ -292,6 +296,21 @@ static inline void native_wbinvd(void)
29039 +
29040 + #define stts() write_cr0(read_cr0() | X86_CR0_TS)
29041 +
29042 ++#define pax_open_kernel(cr0) \
29043 ++do { \
29044 ++ typecheck(unsigned long, cr0); \
29045 ++ preempt_disable(); \
29046 ++ cr0 = read_cr0(); \
29047 ++ write_cr0(cr0 & ~X86_CR0_WP); \
29048 ++} while (0)
29049 ++
29050 ++#define pax_close_kernel(cr0) \
29051 ++do { \
29052 ++ typecheck(unsigned long, cr0); \
29053 ++ write_cr0(cr0); \
29054 ++ preempt_enable_no_resched(); \
29055 ++} while (0)
29056 ++
29057 + #endif /* __KERNEL__ */
29058 +
29059 + static inline void clflush(volatile void *__p)
29060 +@@ -306,7 +325,7 @@ void enable_hlt(void);
29061 +
29062 + void cpu_idle_wait(void);
29063 +
29064 +-extern unsigned long arch_align_stack(unsigned long sp);
29065 ++#define arch_align_stack(x) ((x) & ~0xfUL)
29066 + extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
29067 +
29068 + void default_idle(void);
29069 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess_64.h linux-2.6.27.10/include/asm-x86/uaccess_64.h
29070 +--- linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-07 12:55:34.000000000 -0500
29071 ++++ linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-18 03:38:45.000000000 -0500
29072 +@@ -10,6 +10,8 @@
29073 + #include <linux/lockdep.h>
29074 + #include <asm/page.h>
29075 +
29076 ++#define set_fs(x) (current_thread_info()->addr_limit = (x))
29077 ++
29078 + /*
29079 + * Copy To/From Userspace
29080 + */
29081 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess.h linux-2.6.27.10/include/asm-x86/uaccess.h
29082 +--- linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-07 12:55:34.000000000 -0500
29083 ++++ linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-18 03:38:45.000000000 -0500
29084 +@@ -10,6 +10,7 @@
29085 + #include <linux/string.h>
29086 + #include <asm/asm.h>
29087 + #include <asm/page.h>
29088 ++#include <asm/segment.h>
29089 +
29090 + #define VERIFY_READ 0
29091 + #define VERIFY_WRITE 1
29092 +@@ -29,7 +30,12 @@
29093 +
29094 + #define get_ds() (KERNEL_DS)
29095 + #define get_fs() (current_thread_info()->addr_limit)
29096 ++#ifdef CONFIG_X86_32
29097 ++void __set_fs(mm_segment_t x, int cpu);
29098 ++void set_fs(mm_segment_t x);
29099 ++#else
29100 + #define set_fs(x) (current_thread_info()->addr_limit = (x))
29101 ++#endif
29102 +
29103 + #define segment_eq(a, b) ((a).seg == (b).seg)
29104 +
29105 +@@ -97,6 +103,7 @@ struct exception_table_entry {
29106 + };
29107 +
29108 + extern int fixup_exception(struct pt_regs *regs);
29109 ++#define ARCH_HAS_SORT_EXTABLE
29110 +
29111 + /*
29112 + * These are the main single-value transfer routines. They automatically
29113 +@@ -186,9 +193,12 @@ extern int __get_user_bad(void);
29114 +
29115 + #ifdef CONFIG_X86_32
29116 + #define __put_user_u64(x, addr, err) \
29117 +- asm volatile("1: movl %%eax,0(%2)\n" \
29118 +- "2: movl %%edx,4(%2)\n" \
29119 ++ asm volatile(" movw %w5,%%ds\n" \
29120 ++ "1: movl %%eax,%%ds:0(%2)\n" \
29121 ++ "2: movl %%edx,%%ds:4(%2)\n" \
29122 + "3:\n" \
29123 ++ " pushl %%ss\n" \
29124 ++ " popl %%ds\n" \
29125 + ".section .fixup,\"ax\"\n" \
29126 + "4: movl %3,%0\n" \
29127 + " jmp 3b\n" \
29128 +@@ -196,7 +206,8 @@ extern int __get_user_bad(void);
29129 + _ASM_EXTABLE(1b, 4b) \
29130 + _ASM_EXTABLE(2b, 4b) \
29131 + : "=r" (err) \
29132 +- : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
29133 ++ : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \
29134 ++ "r"(__USER_DS))
29135 +
29136 + #define __put_user_x8(x, ptr, __ret_pu) \
29137 + asm volatile("call __put_user_8" : "=a" (__ret_pu) \
29138 +@@ -336,6 +347,22 @@ do { \
29139 + } \
29140 + } while (0)
29141 +
29142 ++#ifdef CONFIG_X86_32
29143 ++#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29144 ++ asm volatile(" movw %w5,%%ds\n" \
29145 ++ "1: mov"itype" %%ds:%2,%"rtype"1\n" \
29146 ++ "2:\n" \
29147 ++ " pushl %%ss\n" \
29148 ++ " popl %%ds\n" \
29149 ++ ".section .fixup,\"ax\"\n" \
29150 ++ "3: movl %3,%0\n" \
29151 ++ " xor"itype" %"rtype"1,%"rtype"1\n" \
29152 ++ " jmp 2b\n" \
29153 ++ ".previous\n" \
29154 ++ _ASM_EXTABLE(1b, 3b) \
29155 ++ : "=r" (err), ltype (x) \
29156 ++ : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS))
29157 ++#else
29158 + #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29159 + asm volatile("1: mov"itype" %2,%"rtype"1\n" \
29160 + "2:\n" \
29161 +@@ -347,6 +374,7 @@ do { \
29162 + _ASM_EXTABLE(1b, 3b) \
29163 + : "=r" (err), ltype(x) \
29164 + : "m" (__m(addr)), "i" (errret), "0" (err))
29165 ++#endif
29166 +
29167 + #define __put_user_nocheck(x, ptr, size) \
29168 + ({ \
29169 +@@ -373,6 +401,22 @@ struct __large_struct { unsigned long bu
29170 + * we do not write to any memory gcc knows about, so there are no
29171 + * aliasing issues.
29172 + */
29173 ++#ifdef CONFIG_X86_32
29174 ++#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29175 ++ asm volatile(" movw %w5,%%ds\n" \
29176 ++ "1: mov"itype" %"rtype"1,%%ds:%2\n" \
29177 ++ "2:\n" \
29178 ++ " pushl %%ss\n" \
29179 ++ " popl %%ds\n" \
29180 ++ ".section .fixup,\"ax\"\n" \
29181 ++ "3: movl %3,%0\n" \
29182 ++ " jmp 2b\n" \
29183 ++ ".previous\n" \
29184 ++ _ASM_EXTABLE(1b, 3b) \
29185 ++ : "=r"(err) \
29186 ++ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\
29187 ++ "r"(__USER_DS))
29188 ++#else
29189 + #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29190 + asm volatile("1: mov"itype" %"rtype"1,%2\n" \
29191 + "2:\n" \
29192 +@@ -383,6 +427,7 @@ struct __large_struct { unsigned long bu
29193 + _ASM_EXTABLE(1b, 3b) \
29194 + : "=r"(err) \
29195 + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
29196 ++#endif
29197 + /**
29198 + * __get_user: - Get a simple variable from user space, with less checking.
29199 + * @x: Variable to store result.
29200 +@@ -447,6 +492,7 @@ extern struct movsl_mask {
29201 + # include "uaccess_32.h"
29202 + #else
29203 + # define ARCH_HAS_SEARCH_EXTABLE
29204 ++# define ARCH_HAS_SORT_EXTABLE
29205 + # include "uaccess_64.h"
29206 + #endif
29207 +
29208 +diff -urNp linux-2.6.27.10/include/asm-xtensa/kmap_types.h linux-2.6.27.10/include/asm-xtensa/kmap_types.h
29209 +--- linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
29210 ++++ linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
29211 +@@ -25,6 +25,7 @@ enum km_type {
29212 + KM_IRQ1,
29213 + KM_SOFTIRQ0,
29214 + KM_SOFTIRQ1,
29215 ++ KM_CLEARPAGE,
29216 + KM_TYPE_NR
29217 + };
29218 +
29219 +diff -urNp linux-2.6.27.10/include/drm/drm_pciids.h linux-2.6.27.10/include/drm/drm_pciids.h
29220 +--- linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-07 12:55:34.000000000 -0500
29221 ++++ linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-18 03:38:45.000000000 -0500
29222 +@@ -237,7 +237,7 @@
29223 + {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
29224 + {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29225 + {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29226 +- {0, 0, 0}
29227 ++ {0, 0, 0, 0, 0, 0}
29228 +
29229 + #define r128_PCI_IDS \
29230 + {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29231 +@@ -277,14 +277,14 @@
29232 + {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29233 + {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29234 + {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29235 +- {0, 0, 0}
29236 ++ {0, 0, 0, 0, 0, 0}
29237 +
29238 + #define mga_PCI_IDS \
29239 + {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29240 + {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29241 + {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
29242 + {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
29243 +- {0, 0, 0}
29244 ++ {0, 0, 0, 0, 0, 0}
29245 +
29246 + #define mach64_PCI_IDS \
29247 + {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29248 +@@ -307,7 +307,7 @@
29249 + {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29250 + {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29251 + {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29252 +- {0, 0, 0}
29253 ++ {0, 0, 0, 0, 0, 0}
29254 +
29255 + #define sisdrv_PCI_IDS \
29256 + {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29257 +@@ -318,7 +318,7 @@
29258 + {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29259 + {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29260 + {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29261 +- {0, 0, 0}
29262 ++ {0, 0, 0, 0, 0, 0}
29263 +
29264 + #define tdfx_PCI_IDS \
29265 + {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29266 +@@ -327,7 +327,7 @@
29267 + {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29268 + {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29269 + {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29270 +- {0, 0, 0}
29271 ++ {0, 0, 0, 0, 0, 0}
29272 +
29273 + #define viadrv_PCI_IDS \
29274 + {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29275 +@@ -339,25 +339,25 @@
29276 + {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29277 + {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
29278 + {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
29279 +- {0, 0, 0}
29280 ++ {0, 0, 0, 0, 0, 0}
29281 +
29282 + #define i810_PCI_IDS \
29283 + {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29284 + {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29285 + {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29286 + {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29287 +- {0, 0, 0}
29288 ++ {0, 0, 0, 0, 0, 0}
29289 +
29290 + #define i830_PCI_IDS \
29291 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29292 + {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29293 + {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29294 + {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29295 +- {0, 0, 0}
29296 ++ {0, 0, 0, 0, 0, 0}
29297 +
29298 + #define gamma_PCI_IDS \
29299 + {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29300 +- {0, 0, 0}
29301 ++ {0, 0, 0, 0, 0, 0}
29302 +
29303 + #define savage_PCI_IDS \
29304 + {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
29305 +@@ -383,10 +383,10 @@
29306 + {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
29307 + {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29308 + {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29309 +- {0, 0, 0}
29310 ++ {0, 0, 0, 0, 0, 0}
29311 +
29312 + #define ffb_PCI_IDS \
29313 +- {0, 0, 0}
29314 ++ {0, 0, 0, 0, 0, 0}
29315 +
29316 + #define i915_PCI_IDS \
29317 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29318 +@@ -412,4 +412,4 @@
29319 + {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29320 + {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29321 + {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29322 +- {0, 0, 0}
29323 ++ {0, 0, 0, 0, 0, 0}
29324 +diff -urNp linux-2.6.27.10/include/linux/a.out.h linux-2.6.27.10/include/linux/a.out.h
29325 +--- linux-2.6.27.10/include/linux/a.out.h 2008-11-07 12:55:34.000000000 -0500
29326 ++++ linux-2.6.27.10/include/linux/a.out.h 2008-11-18 03:38:45.000000000 -0500
29327 +@@ -39,6 +39,14 @@ enum machine_type {
29328 + M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
29329 + };
29330 +
29331 ++/* Constants for the N_FLAGS field */
29332 ++#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29333 ++#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
29334 ++#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
29335 ++#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
29336 ++/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29337 ++#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29338 ++
29339 + #if !defined (N_MAGIC)
29340 + #define N_MAGIC(exec) ((exec).a_info & 0xffff)
29341 + #endif
29342 +diff -urNp linux-2.6.27.10/include/linux/binfmts.h linux-2.6.27.10/include/linux/binfmts.h
29343 +--- linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:16:52.000000000 -0500
29344 ++++ linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:13:46.000000000 -0500
29345 +@@ -71,6 +71,7 @@ struct linux_binfmt {
29346 + int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
29347 + int (*load_shlib)(struct file *);
29348 + int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
29349 ++ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
29350 + unsigned long min_coredump; /* minimal dump size */
29351 + int hasvdso;
29352 + };
29353 +diff -urNp linux-2.6.27.10/include/linux/cache.h linux-2.6.27.10/include/linux/cache.h
29354 +--- linux-2.6.27.10/include/linux/cache.h 2008-11-07 12:55:34.000000000 -0500
29355 ++++ linux-2.6.27.10/include/linux/cache.h 2008-11-18 03:38:45.000000000 -0500
29356 +@@ -16,6 +16,10 @@
29357 + #define __read_mostly
29358 + #endif
29359 +
29360 ++#ifndef __read_only
29361 ++#define __read_only __read_mostly
29362 ++#endif
29363 ++
29364 + #ifndef ____cacheline_aligned
29365 + #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
29366 + #endif
29367 +diff -urNp linux-2.6.27.10/include/linux/capability.h linux-2.6.27.10/include/linux/capability.h
29368 +--- linux-2.6.27.10/include/linux/capability.h 2008-11-07 12:55:34.000000000 -0500
29369 ++++ linux-2.6.27.10/include/linux/capability.h 2008-11-18 03:38:45.000000000 -0500
29370 +@@ -516,6 +516,7 @@ kernel_cap_t cap_set_effective(const ker
29371 + #define has_capability(t, cap) (security_capable((t), (cap)) == 0)
29372 +
29373 + extern int capable(int cap);
29374 ++int capable_nolog(int cap);
29375 +
29376 + #endif /* __KERNEL__ */
29377 +
29378 +diff -urNp linux-2.6.27.10/include/linux/cpumask.h linux-2.6.27.10/include/linux/cpumask.h
29379 +--- linux-2.6.27.10/include/linux/cpumask.h 2008-11-07 12:55:34.000000000 -0500
29380 ++++ linux-2.6.27.10/include/linux/cpumask.h 2008-11-18 03:38:45.000000000 -0500
29381 +@@ -139,7 +139,6 @@
29382 + #include <linux/bitmap.h>
29383 +
29384 + typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
29385 +-extern cpumask_t _unused_cpumask_arg_;
29386 +
29387 + #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
29388 + static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
29389 +diff -urNp linux-2.6.27.10/include/linux/elf.h linux-2.6.27.10/include/linux/elf.h
29390 +--- linux-2.6.27.10/include/linux/elf.h 2008-11-07 12:55:34.000000000 -0500
29391 ++++ linux-2.6.27.10/include/linux/elf.h 2008-12-21 00:44:29.000000000 -0500
29392 +@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
29393 + #define PT_GNU_EH_FRAME 0x6474e550
29394 +
29395 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
29396 ++#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
29397 ++
29398 ++#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
29399 ++
29400 ++/* Constants for the e_flags field */
29401 ++#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29402 ++#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
29403 ++#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
29404 ++#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
29405 ++/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29406 ++#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29407 +
29408 + /* These constants define the different elf file types */
29409 + #define ET_NONE 0
29410 +@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
29411 + #define DT_DEBUG 21
29412 + #define DT_TEXTREL 22
29413 + #define DT_JMPREL 23
29414 ++#define DT_FLAGS 30
29415 ++ #define DF_TEXTREL 0x00000004
29416 + #define DT_ENCODING 32
29417 + #define OLD_DT_LOOS 0x60000000
29418 + #define DT_LOOS 0x6000000d
29419 +@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
29420 + #define PF_W 0x2
29421 + #define PF_X 0x1
29422 +
29423 ++#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
29424 ++#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
29425 ++#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
29426 ++#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
29427 ++#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
29428 ++#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
29429 ++/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
29430 ++/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
29431 ++#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
29432 ++#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
29433 ++#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
29434 ++#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
29435 ++
29436 + typedef struct elf32_phdr{
29437 + Elf32_Word p_type;
29438 + Elf32_Off p_offset;
29439 +@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
29440 + #define EI_OSABI 7
29441 + #define EI_PAD 8
29442 +
29443 ++#define EI_PAX 14
29444 ++
29445 + #define ELFMAG0 0x7f /* EI_MAG */
29446 + #define ELFMAG1 'E'
29447 + #define ELFMAG2 'L'
29448 +@@ -383,6 +411,7 @@ extern Elf32_Dyn _DYNAMIC [];
29449 + #define elf_phdr elf32_phdr
29450 + #define elf_note elf32_note
29451 + #define elf_addr_t Elf32_Off
29452 ++#define elf_dyn Elf32_Dyn
29453 +
29454 + #else
29455 +
29456 +@@ -391,6 +420,7 @@ extern Elf64_Dyn _DYNAMIC [];
29457 + #define elf_phdr elf64_phdr
29458 + #define elf_note elf64_note
29459 + #define elf_addr_t Elf64_Off
29460 ++#define elf_dyn Elf64_Dyn
29461 +
29462 + #endif
29463 +
29464 +diff -urNp linux-2.6.27.10/include/linux/gracl.h linux-2.6.27.10/include/linux/gracl.h
29465 +--- linux-2.6.27.10/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
29466 ++++ linux-2.6.27.10/include/linux/gracl.h 2008-11-18 03:38:45.000000000 -0500
29467 +@@ -0,0 +1,318 @@
29468 ++#ifndef GR_ACL_H
29469 ++#define GR_ACL_H
29470 ++
29471 ++#include <linux/grdefs.h>
29472 ++#include <linux/resource.h>
29473 ++#include <linux/capability.h>
29474 ++#include <linux/dcache.h>
29475 ++#include <asm/resource.h>
29476 ++
29477 ++/* Major status information */
29478 ++
29479 ++#define GR_VERSION "grsecurity 2.1.12"
29480 ++#define GRSECURITY_VERSION 0x2112
29481 ++
29482 ++enum {
29483 ++
29484 ++ SHUTDOWN = 0,
29485 ++ ENABLE = 1,
29486 ++ SPROLE = 2,
29487 ++ RELOAD = 3,
29488 ++ SEGVMOD = 4,
29489 ++ STATUS = 5,
29490 ++ UNSPROLE = 6,
29491 ++ PASSSET = 7,
29492 ++ SPROLEPAM = 8
29493 ++};
29494 ++
29495 ++/* Password setup definitions
29496 ++ * kernel/grhash.c */
29497 ++enum {
29498 ++ GR_PW_LEN = 128,
29499 ++ GR_SALT_LEN = 16,
29500 ++ GR_SHA_LEN = 32,
29501 ++};
29502 ++
29503 ++enum {
29504 ++ GR_SPROLE_LEN = 64,
29505 ++};
29506 ++
29507 ++#define GR_NLIMITS (RLIMIT_LOCKS + 2)
29508 ++
29509 ++/* Begin Data Structures */
29510 ++
29511 ++struct sprole_pw {
29512 ++ unsigned char *rolename;
29513 ++ unsigned char salt[GR_SALT_LEN];
29514 ++ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
29515 ++};
29516 ++
29517 ++struct name_entry {
29518 ++ __u32 key;
29519 ++ ino_t inode;
29520 ++ dev_t device;
29521 ++ char *name;
29522 ++ __u16 len;
29523 ++ __u8 deleted;
29524 ++ struct name_entry *prev;
29525 ++ struct name_entry *next;
29526 ++};
29527 ++
29528 ++struct inodev_entry {
29529 ++ struct name_entry *nentry;
29530 ++ struct inodev_entry *prev;
29531 ++ struct inodev_entry *next;
29532 ++};
29533 ++
29534 ++struct acl_role_db {
29535 ++ struct acl_role_label **r_hash;
29536 ++ __u32 r_size;
29537 ++};
29538 ++
29539 ++struct inodev_db {
29540 ++ struct inodev_entry **i_hash;
29541 ++ __u32 i_size;
29542 ++};
29543 ++
29544 ++struct name_db {
29545 ++ struct name_entry **n_hash;
29546 ++ __u32 n_size;
29547 ++};
29548 ++
29549 ++struct crash_uid {
29550 ++ uid_t uid;
29551 ++ unsigned long expires;
29552 ++};
29553 ++
29554 ++struct gr_hash_struct {
29555 ++ void **table;
29556 ++ void **nametable;
29557 ++ void *first;
29558 ++ __u32 table_size;
29559 ++ __u32 used_size;
29560 ++ int type;
29561 ++};
29562 ++
29563 ++/* Userspace Grsecurity ACL data structures */
29564 ++
29565 ++struct acl_subject_label {
29566 ++ char *filename;
29567 ++ ino_t inode;
29568 ++ dev_t device;
29569 ++ __u32 mode;
29570 ++ kernel_cap_t cap_mask;
29571 ++ kernel_cap_t cap_lower;
29572 ++
29573 ++ struct rlimit res[GR_NLIMITS];
29574 ++ __u16 resmask;
29575 ++
29576 ++ __u8 user_trans_type;
29577 ++ __u8 group_trans_type;
29578 ++ uid_t *user_transitions;
29579 ++ gid_t *group_transitions;
29580 ++ __u16 user_trans_num;
29581 ++ __u16 group_trans_num;
29582 ++
29583 ++ __u32 ip_proto[8];
29584 ++ __u32 ip_type;
29585 ++ struct acl_ip_label **ips;
29586 ++ __u32 ip_num;
29587 ++
29588 ++ __u32 crashes;
29589 ++ unsigned long expires;
29590 ++
29591 ++ struct acl_subject_label *parent_subject;
29592 ++ struct gr_hash_struct *hash;
29593 ++ struct acl_subject_label *prev;
29594 ++ struct acl_subject_label *next;
29595 ++
29596 ++ struct acl_object_label **obj_hash;
29597 ++ __u32 obj_hash_size;
29598 ++ __u16 pax_flags;
29599 ++};
29600 ++
29601 ++struct role_allowed_ip {
29602 ++ __u32 addr;
29603 ++ __u32 netmask;
29604 ++
29605 ++ struct role_allowed_ip *prev;
29606 ++ struct role_allowed_ip *next;
29607 ++};
29608 ++
29609 ++struct role_transition {
29610 ++ char *rolename;
29611 ++
29612 ++ struct role_transition *prev;
29613 ++ struct role_transition *next;
29614 ++};
29615 ++
29616 ++struct acl_role_label {
29617 ++ char *rolename;
29618 ++ uid_t uidgid;
29619 ++ __u16 roletype;
29620 ++
29621 ++ __u16 auth_attempts;
29622 ++ unsigned long expires;
29623 ++
29624 ++ struct acl_subject_label *root_label;
29625 ++ struct gr_hash_struct *hash;
29626 ++
29627 ++ struct acl_role_label *prev;
29628 ++ struct acl_role_label *next;
29629 ++
29630 ++ struct role_transition *transitions;
29631 ++ struct role_allowed_ip *allowed_ips;
29632 ++ uid_t *domain_children;
29633 ++ __u16 domain_child_num;
29634 ++
29635 ++ struct acl_subject_label **subj_hash;
29636 ++ __u32 subj_hash_size;
29637 ++};
29638 ++
29639 ++struct user_acl_role_db {
29640 ++ struct acl_role_label **r_table;
29641 ++ __u32 num_pointers; /* Number of allocations to track */
29642 ++ __u32 num_roles; /* Number of roles */
29643 ++ __u32 num_domain_children; /* Number of domain children */
29644 ++ __u32 num_subjects; /* Number of subjects */
29645 ++ __u32 num_objects; /* Number of objects */
29646 ++};
29647 ++
29648 ++struct acl_object_label {
29649 ++ char *filename;
29650 ++ ino_t inode;
29651 ++ dev_t device;
29652 ++ __u32 mode;
29653 ++
29654 ++ struct acl_subject_label *nested;
29655 ++ struct acl_object_label *globbed;
29656 ++
29657 ++ /* next two structures not used */
29658 ++
29659 ++ struct acl_object_label *prev;
29660 ++ struct acl_object_label *next;
29661 ++};
29662 ++
29663 ++struct acl_ip_label {
29664 ++ char *iface;
29665 ++ __u32 addr;
29666 ++ __u32 netmask;
29667 ++ __u16 low, high;
29668 ++ __u8 mode;
29669 ++ __u32 type;
29670 ++ __u32 proto[8];
29671 ++
29672 ++ /* next two structures not used */
29673 ++
29674 ++ struct acl_ip_label *prev;
29675 ++ struct acl_ip_label *next;
29676 ++};
29677 ++
29678 ++struct gr_arg {
29679 ++ struct user_acl_role_db role_db;
29680 ++ unsigned char pw[GR_PW_LEN];
29681 ++ unsigned char salt[GR_SALT_LEN];
29682 ++ unsigned char sum[GR_SHA_LEN];
29683 ++ unsigned char sp_role[GR_SPROLE_LEN];
29684 ++ struct sprole_pw *sprole_pws;
29685 ++ dev_t segv_device;
29686 ++ ino_t segv_inode;
29687 ++ uid_t segv_uid;
29688 ++ __u16 num_sprole_pws;
29689 ++ __u16 mode;
29690 ++};
29691 ++
29692 ++struct gr_arg_wrapper {
29693 ++ struct gr_arg *arg;
29694 ++ __u32 version;
29695 ++ __u32 size;
29696 ++};
29697 ++
29698 ++struct subject_map {
29699 ++ struct acl_subject_label *user;
29700 ++ struct acl_subject_label *kernel;
29701 ++ struct subject_map *prev;
29702 ++ struct subject_map *next;
29703 ++};
29704 ++
29705 ++struct acl_subj_map_db {
29706 ++ struct subject_map **s_hash;
29707 ++ __u32 s_size;
29708 ++};
29709 ++
29710 ++/* End Data Structures Section */
29711 ++
29712 ++/* Hash functions generated by empirical testing by Brad Spengler
29713 ++ Makes good use of the low bits of the inode. Generally 0-1 times
29714 ++ in loop for successful match. 0-3 for unsuccessful match.
29715 ++ Shift/add algorithm with modulus of table size and an XOR*/
29716 ++
29717 ++static __inline__ unsigned int
29718 ++rhash(const uid_t uid, const __u16 type, const unsigned int sz)
29719 ++{
29720 ++ return (((uid << type) + (uid ^ type)) % sz);
29721 ++}
29722 ++
29723 ++ static __inline__ unsigned int
29724 ++shash(const struct acl_subject_label *userp, const unsigned int sz)
29725 ++{
29726 ++ return ((const unsigned long)userp % sz);
29727 ++}
29728 ++
29729 ++static __inline__ unsigned int
29730 ++fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
29731 ++{
29732 ++ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
29733 ++}
29734 ++
29735 ++static __inline__ unsigned int
29736 ++nhash(const char *name, const __u16 len, const unsigned int sz)
29737 ++{
29738 ++ return full_name_hash(name, len) % sz;
29739 ++}
29740 ++
29741 ++#define FOR_EACH_ROLE_START(role,iter) \
29742 ++ role = NULL; \
29743 ++ iter = 0; \
29744 ++ while (iter < acl_role_set.r_size) { \
29745 ++ if (role == NULL) \
29746 ++ role = acl_role_set.r_hash[iter]; \
29747 ++ if (role == NULL) { \
29748 ++ iter++; \
29749 ++ continue; \
29750 ++ }
29751 ++
29752 ++#define FOR_EACH_ROLE_END(role,iter) \
29753 ++ role = role->next; \
29754 ++ if (role == NULL) \
29755 ++ iter++; \
29756 ++ }
29757 ++
29758 ++#define FOR_EACH_SUBJECT_START(role,subj,iter) \
29759 ++ subj = NULL; \
29760 ++ iter = 0; \
29761 ++ while (iter < role->subj_hash_size) { \
29762 ++ if (subj == NULL) \
29763 ++ subj = role->subj_hash[iter]; \
29764 ++ if (subj == NULL) { \
29765 ++ iter++; \
29766 ++ continue; \
29767 ++ }
29768 ++
29769 ++#define FOR_EACH_SUBJECT_END(subj,iter) \
29770 ++ subj = subj->next; \
29771 ++ if (subj == NULL) \
29772 ++ iter++; \
29773 ++ }
29774 ++
29775 ++
29776 ++#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
29777 ++ subj = role->hash->first; \
29778 ++ while (subj != NULL) {
29779 ++
29780 ++#define FOR_EACH_NESTED_SUBJECT_END(subj) \
29781 ++ subj = subj->next; \
29782 ++ }
29783 ++
29784 ++#endif
29785 ++
29786 +diff -urNp linux-2.6.27.10/include/linux/gralloc.h linux-2.6.27.10/include/linux/gralloc.h
29787 +--- linux-2.6.27.10/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
29788 ++++ linux-2.6.27.10/include/linux/gralloc.h 2008-11-18 03:38:45.000000000 -0500
29789 +@@ -0,0 +1,8 @@
29790 ++#ifndef __GRALLOC_H
29791 ++#define __GRALLOC_H
29792 ++
29793 ++void acl_free_all(void);
29794 ++int acl_alloc_stack_init(unsigned long size);
29795 ++void *acl_alloc(unsigned long len);
29796 ++
29797 ++#endif
29798 +diff -urNp linux-2.6.27.10/include/linux/grdefs.h linux-2.6.27.10/include/linux/grdefs.h
29799 +--- linux-2.6.27.10/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
29800 ++++ linux-2.6.27.10/include/linux/grdefs.h 2008-11-18 03:38:45.000000000 -0500
29801 +@@ -0,0 +1,131 @@
29802 ++#ifndef GRDEFS_H
29803 ++#define GRDEFS_H
29804 ++
29805 ++/* Begin grsecurity status declarations */
29806 ++
29807 ++enum {
29808 ++ GR_READY = 0x01,
29809 ++ GR_STATUS_INIT = 0x00 // disabled state
29810 ++};
29811 ++
29812 ++/* Begin ACL declarations */
29813 ++
29814 ++/* Role flags */
29815 ++
29816 ++enum {
29817 ++ GR_ROLE_USER = 0x0001,
29818 ++ GR_ROLE_GROUP = 0x0002,
29819 ++ GR_ROLE_DEFAULT = 0x0004,
29820 ++ GR_ROLE_SPECIAL = 0x0008,
29821 ++ GR_ROLE_AUTH = 0x0010,
29822 ++ GR_ROLE_NOPW = 0x0020,
29823 ++ GR_ROLE_GOD = 0x0040,
29824 ++ GR_ROLE_LEARN = 0x0080,
29825 ++ GR_ROLE_TPE = 0x0100,
29826 ++ GR_ROLE_DOMAIN = 0x0200,
29827 ++ GR_ROLE_PAM = 0x0400
29828 ++};
29829 ++
29830 ++/* ACL Subject and Object mode flags */
29831 ++enum {
29832 ++ GR_DELETED = 0x80000000
29833 ++};
29834 ++
29835 ++/* ACL Object-only mode flags */
29836 ++enum {
29837 ++ GR_READ = 0x00000001,
29838 ++ GR_APPEND = 0x00000002,
29839 ++ GR_WRITE = 0x00000004,
29840 ++ GR_EXEC = 0x00000008,
29841 ++ GR_FIND = 0x00000010,
29842 ++ GR_INHERIT = 0x00000020,
29843 ++ GR_SETID = 0x00000040,
29844 ++ GR_CREATE = 0x00000080,
29845 ++ GR_DELETE = 0x00000100,
29846 ++ GR_LINK = 0x00000200,
29847 ++ GR_AUDIT_READ = 0x00000400,
29848 ++ GR_AUDIT_APPEND = 0x00000800,
29849 ++ GR_AUDIT_WRITE = 0x00001000,
29850 ++ GR_AUDIT_EXEC = 0x00002000,
29851 ++ GR_AUDIT_FIND = 0x00004000,
29852 ++ GR_AUDIT_INHERIT= 0x00008000,
29853 ++ GR_AUDIT_SETID = 0x00010000,
29854 ++ GR_AUDIT_CREATE = 0x00020000,
29855 ++ GR_AUDIT_DELETE = 0x00040000,
29856 ++ GR_AUDIT_LINK = 0x00080000,
29857 ++ GR_PTRACERD = 0x00100000,
29858 ++ GR_NOPTRACE = 0x00200000,
29859 ++ GR_SUPPRESS = 0x00400000,
29860 ++ GR_NOLEARN = 0x00800000
29861 ++};
29862 ++
29863 ++#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
29864 ++ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
29865 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
29866 ++
29867 ++/* ACL subject-only mode flags */
29868 ++enum {
29869 ++ GR_KILL = 0x00000001,
29870 ++ GR_VIEW = 0x00000002,
29871 ++ GR_PROTECTED = 0x00000004,
29872 ++ GR_LEARN = 0x00000008,
29873 ++ GR_OVERRIDE = 0x00000010,
29874 ++ /* just a placeholder, this mode is only used in userspace */
29875 ++ GR_DUMMY = 0x00000020,
29876 ++ GR_PROTSHM = 0x00000040,
29877 ++ GR_KILLPROC = 0x00000080,
29878 ++ GR_KILLIPPROC = 0x00000100,
29879 ++ /* just a placeholder, this mode is only used in userspace */
29880 ++ GR_NOTROJAN = 0x00000200,
29881 ++ GR_PROTPROCFD = 0x00000400,
29882 ++ GR_PROCACCT = 0x00000800,
29883 ++ GR_RELAXPTRACE = 0x00001000,
29884 ++ GR_NESTED = 0x00002000,
29885 ++ GR_INHERITLEARN = 0x00004000,
29886 ++ GR_PROCFIND = 0x00008000,
29887 ++ GR_POVERRIDE = 0x00010000,
29888 ++ GR_KERNELAUTH = 0x00020000,
29889 ++};
29890 ++
29891 ++enum {
29892 ++ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
29893 ++ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
29894 ++ GR_PAX_ENABLE_MPROTECT = 0x0004,
29895 ++ GR_PAX_ENABLE_RANDMMAP = 0x0008,
29896 ++ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
29897 ++ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
29898 ++ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
29899 ++ GR_PAX_DISABLE_MPROTECT = 0x0400,
29900 ++ GR_PAX_DISABLE_RANDMMAP = 0x0800,
29901 ++ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
29902 ++};
29903 ++
29904 ++enum {
29905 ++ GR_ID_USER = 0x01,
29906 ++ GR_ID_GROUP = 0x02,
29907 ++};
29908 ++
29909 ++enum {
29910 ++ GR_ID_ALLOW = 0x01,
29911 ++ GR_ID_DENY = 0x02,
29912 ++};
29913 ++
29914 ++#define GR_CRASH_RES 11
29915 ++#define GR_UIDTABLE_MAX 500
29916 ++
29917 ++/* begin resource learning section */
29918 ++enum {
29919 ++ GR_RLIM_CPU_BUMP = 60,
29920 ++ GR_RLIM_FSIZE_BUMP = 50000,
29921 ++ GR_RLIM_DATA_BUMP = 10000,
29922 ++ GR_RLIM_STACK_BUMP = 1000,
29923 ++ GR_RLIM_CORE_BUMP = 10000,
29924 ++ GR_RLIM_RSS_BUMP = 500000,
29925 ++ GR_RLIM_NPROC_BUMP = 1,
29926 ++ GR_RLIM_NOFILE_BUMP = 5,
29927 ++ GR_RLIM_MEMLOCK_BUMP = 50000,
29928 ++ GR_RLIM_AS_BUMP = 500000,
29929 ++ GR_RLIM_LOCKS_BUMP = 2
29930 ++};
29931 ++
29932 ++#endif
29933 +diff -urNp linux-2.6.27.10/include/linux/grinternal.h linux-2.6.27.10/include/linux/grinternal.h
29934 +--- linux-2.6.27.10/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
29935 ++++ linux-2.6.27.10/include/linux/grinternal.h 2008-11-18 03:38:45.000000000 -0500
29936 +@@ -0,0 +1,210 @@
29937 ++#ifndef __GRINTERNAL_H
29938 ++#define __GRINTERNAL_H
29939 ++
29940 ++#ifdef CONFIG_GRKERNSEC
29941 ++
29942 ++#include <linux/fs.h>
29943 ++#include <linux/gracl.h>
29944 ++#include <linux/grdefs.h>
29945 ++#include <linux/grmsg.h>
29946 ++
29947 ++void gr_add_learn_entry(const char *fmt, ...);
29948 ++__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
29949 ++ const struct vfsmount *mnt);
29950 ++__u32 gr_check_create(const struct dentry *new_dentry,
29951 ++ const struct dentry *parent,
29952 ++ const struct vfsmount *mnt, const __u32 mode);
29953 ++int gr_check_protected_task(const struct task_struct *task);
29954 ++__u32 to_gr_audit(const __u32 reqmode);
29955 ++int gr_set_acls(const int type);
29956 ++
29957 ++int gr_acl_is_enabled(void);
29958 ++char gr_roletype_to_char(void);
29959 ++
29960 ++void gr_handle_alertkill(struct task_struct *task);
29961 ++char *gr_to_filename(const struct dentry *dentry,
29962 ++ const struct vfsmount *mnt);
29963 ++char *gr_to_filename1(const struct dentry *dentry,
29964 ++ const struct vfsmount *mnt);
29965 ++char *gr_to_filename2(const struct dentry *dentry,
29966 ++ const struct vfsmount *mnt);
29967 ++char *gr_to_filename3(const struct dentry *dentry,
29968 ++ const struct vfsmount *mnt);
29969 ++
29970 ++extern int grsec_enable_link;
29971 ++extern int grsec_enable_fifo;
29972 ++extern int grsec_enable_execve;
29973 ++extern int grsec_enable_shm;
29974 ++extern int grsec_enable_execlog;
29975 ++extern int grsec_enable_signal;
29976 ++extern int grsec_enable_forkfail;
29977 ++extern int grsec_enable_time;
29978 ++extern int grsec_enable_chroot_shmat;
29979 ++extern int grsec_enable_chroot_findtask;
29980 ++extern int grsec_enable_chroot_mount;
29981 ++extern int grsec_enable_chroot_double;
29982 ++extern int grsec_enable_chroot_pivot;
29983 ++extern int grsec_enable_chroot_chdir;
29984 ++extern int grsec_enable_chroot_chmod;
29985 ++extern int grsec_enable_chroot_mknod;
29986 ++extern int grsec_enable_chroot_fchdir;
29987 ++extern int grsec_enable_chroot_nice;
29988 ++extern int grsec_enable_chroot_execlog;
29989 ++extern int grsec_enable_chroot_caps;
29990 ++extern int grsec_enable_chroot_sysctl;
29991 ++extern int grsec_enable_chroot_unix;
29992 ++extern int grsec_enable_tpe;
29993 ++extern int grsec_tpe_gid;
29994 ++extern int grsec_enable_tpe_all;
29995 ++extern int grsec_enable_sidcaps;
29996 ++extern int grsec_enable_socket_all;
29997 ++extern int grsec_socket_all_gid;
29998 ++extern int grsec_enable_socket_client;
29999 ++extern int grsec_socket_client_gid;
30000 ++extern int grsec_enable_socket_server;
30001 ++extern int grsec_socket_server_gid;
30002 ++extern int grsec_audit_gid;
30003 ++extern int grsec_enable_group;
30004 ++extern int grsec_enable_audit_ipc;
30005 ++extern int grsec_enable_audit_textrel;
30006 ++extern int grsec_enable_mount;
30007 ++extern int grsec_enable_chdir;
30008 ++extern int grsec_resource_logging;
30009 ++extern int grsec_lock;
30010 ++
30011 ++extern spinlock_t grsec_alert_lock;
30012 ++extern unsigned long grsec_alert_wtime;
30013 ++extern unsigned long grsec_alert_fyet;
30014 ++
30015 ++extern spinlock_t grsec_audit_lock;
30016 ++
30017 ++extern rwlock_t grsec_exec_file_lock;
30018 ++
30019 ++#define gr_task_fullpath(tsk) (tsk->exec_file ? \
30020 ++ gr_to_filename2(tsk->exec_file->f_path.dentry, \
30021 ++ tsk->exec_file->f_vfsmnt) : "/")
30022 ++
30023 ++#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \
30024 ++ gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \
30025 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
30026 ++
30027 ++#define gr_task_fullpath0(tsk) (tsk->exec_file ? \
30028 ++ gr_to_filename(tsk->exec_file->f_path.dentry, \
30029 ++ tsk->exec_file->f_vfsmnt) : "/")
30030 ++
30031 ++#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \
30032 ++ gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \
30033 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
30034 ++
30035 ++#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \
30036 ++ ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \
30037 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \
30038 ++ (tsk_a->fs->root.dentry->d_inode->i_ino != \
30039 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino)))
30040 ++
30041 ++#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \
30042 ++ (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \
30043 ++ tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \
30044 ++ (tsk_a->fs->root.dentry->d_inode->i_ino == \
30045 ++ tsk_b->fs->root.dentry->d_inode->i_ino))
30046 ++
30047 ++#define DEFAULTSECARGS(task) gr_task_fullpath(task), task->comm, \
30048 ++ task->pid, task->uid, \
30049 ++ task->euid, task->gid, task->egid, \
30050 ++ gr_parent_task_fullpath(task), \
30051 ++ task->parent->comm, task->parent->pid, \
30052 ++ task->parent->uid, task->parent->euid, \
30053 ++ task->parent->gid, task->parent->egid
30054 ++
30055 ++#define GR_CHROOT_CAPS {{ \
30056 ++ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
30057 ++ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
30058 ++ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
30059 ++ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
30060 ++ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
30061 ++ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
30062 ++
30063 ++#define security_learn(normal_msg,args...) \
30064 ++({ \
30065 ++ read_lock(&grsec_exec_file_lock); \
30066 ++ gr_add_learn_entry(normal_msg "\n", ## args); \
30067 ++ read_unlock(&grsec_exec_file_lock); \
30068 ++})
30069 ++
30070 ++enum {
30071 ++ GR_DO_AUDIT,
30072 ++ GR_DONT_AUDIT,
30073 ++ GR_DONT_AUDIT_GOOD
30074 ++};
30075 ++
30076 ++enum {
30077 ++ GR_TTYSNIFF,
30078 ++ GR_RBAC,
30079 ++ GR_RBAC_STR,
30080 ++ GR_STR_RBAC,
30081 ++ GR_RBAC_MODE2,
30082 ++ GR_RBAC_MODE3,
30083 ++ GR_FILENAME,
30084 ++ GR_SYSCTL_HIDDEN,
30085 ++ GR_NOARGS,
30086 ++ GR_ONE_INT,
30087 ++ GR_ONE_INT_TWO_STR,
30088 ++ GR_ONE_STR,
30089 ++ GR_STR_INT,
30090 ++ GR_TWO_INT,
30091 ++ GR_THREE_INT,
30092 ++ GR_FIVE_INT_TWO_STR,
30093 ++ GR_TWO_STR,
30094 ++ GR_THREE_STR,
30095 ++ GR_FOUR_STR,
30096 ++ GR_STR_FILENAME,
30097 ++ GR_FILENAME_STR,
30098 ++ GR_FILENAME_TWO_INT,
30099 ++ GR_FILENAME_TWO_INT_STR,
30100 ++ GR_TEXTREL,
30101 ++ GR_PTRACE,
30102 ++ GR_RESOURCE,
30103 ++ GR_CAP,
30104 ++ GR_SIG,
30105 ++ GR_CRASH1,
30106 ++ GR_CRASH2,
30107 ++ GR_PSACCT
30108 ++};
30109 ++
30110 ++#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
30111 ++#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
30112 ++#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
30113 ++#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
30114 ++#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
30115 ++#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
30116 ++#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)
30117 ++#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
30118 ++#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
30119 ++#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
30120 ++#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
30121 ++#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
30122 ++#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
30123 ++#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
30124 ++#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
30125 ++#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)
30126 ++#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
30127 ++#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
30128 ++#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
30129 ++#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
30130 ++#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
30131 ++#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
30132 ++#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)
30133 ++#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
30134 ++#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
30135 ++#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
30136 ++#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
30137 ++#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num)
30138 ++#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
30139 ++#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
30140 ++#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)
30141 ++
30142 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
30143 ++
30144 ++#endif
30145 ++
30146 ++#endif
30147 +diff -urNp linux-2.6.27.10/include/linux/grmsg.h linux-2.6.27.10/include/linux/grmsg.h
30148 +--- linux-2.6.27.10/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
30149 ++++ linux-2.6.27.10/include/linux/grmsg.h 2008-11-18 03:38:45.000000000 -0500
30150 +@@ -0,0 +1,108 @@
30151 ++#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"
30152 ++#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"
30153 ++#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
30154 ++#define GR_STOPMOD_MSG "denied modification of module state by "
30155 ++#define GR_IOPERM_MSG "denied use of ioperm() by "
30156 ++#define GR_IOPL_MSG "denied use of iopl() by "
30157 ++#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
30158 ++#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
30159 ++#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
30160 ++#define GR_KMEM_MSG "denied write of /dev/kmem by "
30161 ++#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
30162 ++#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
30163 ++#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
30164 ++#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
30165 ++#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"
30166 ++#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"
30167 ++#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
30168 ++#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
30169 ++#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
30170 ++#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
30171 ++#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
30172 ++#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
30173 ++#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
30174 ++#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
30175 ++#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
30176 ++#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
30177 ++#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
30178 ++#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
30179 ++#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
30180 ++#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
30181 ++#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
30182 ++#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
30183 ++#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
30184 ++#define GR_NPROC_MSG "denied overstep of process limit by "
30185 ++#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
30186 ++#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
30187 ++#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
30188 ++#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
30189 ++#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
30190 ++#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
30191 ++#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
30192 ++#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
30193 ++#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
30194 ++#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
30195 ++#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
30196 ++#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
30197 ++#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
30198 ++#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
30199 ++#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
30200 ++#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
30201 ++#define GR_INITF_ACL_MSG "init_variables() failed %s by "
30202 ++#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"
30203 ++#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
30204 ++#define GR_SHUTS_ACL_MSG "shutdown auth success for "
30205 ++#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
30206 ++#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
30207 ++#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
30208 ++#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
30209 ++#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
30210 ++#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
30211 ++#define GR_ENABLEF_ACL_MSG "unable to load %s for "
30212 ++#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
30213 ++#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
30214 ++#define GR_RELOADF_ACL_MSG "failed reload of %s for "
30215 ++#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
30216 ++#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
30217 ++#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
30218 ++#define GR_SPROLEF_ACL_MSG "special role %s failure for "
30219 ++#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
30220 ++#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
30221 ++#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for "
30222 ++#define GR_INVMODE_ACL_MSG "invalid mode %d by "
30223 ++#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
30224 ++#define GR_FAILFORK_MSG "failed fork with errno %d by "
30225 ++#define GR_NICE_CHROOT_MSG "denied priority change by "
30226 ++#define GR_UNISIGLOG_MSG "signal %d sent to "
30227 ++#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
30228 ++#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
30229 ++#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
30230 ++#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
30231 ++#define GR_TIME_MSG "time set by "
30232 ++#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
30233 ++#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
30234 ++#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
30235 ++#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
30236 ++#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by "
30237 ++#define GR_BIND_MSG "denied bind() by "
30238 ++#define GR_CONNECT_MSG "denied connect() by "
30239 ++#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30240 ++#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30241 ++#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"
30242 ++#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
30243 ++#define GR_CAP_ACL_MSG "use of %s denied for "
30244 ++#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
30245 ++#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
30246 ++#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
30247 ++#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
30248 ++#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
30249 ++#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
30250 ++#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
30251 ++#define GR_MSGQ_AUDIT_MSG "message queue created by "
30252 ++#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by "
30253 ++#define GR_SEM_AUDIT_MSG "semaphore created by "
30254 ++#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by "
30255 ++#define GR_SHM_AUDIT_MSG "shared memory of size %d created by "
30256 ++#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by "
30257 ++#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
30258 ++#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
30259 +diff -urNp linux-2.6.27.10/include/linux/grsecurity.h linux-2.6.27.10/include/linux/grsecurity.h
30260 +--- linux-2.6.27.10/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
30261 ++++ linux-2.6.27.10/include/linux/grsecurity.h 2008-11-18 03:38:45.000000000 -0500
30262 +@@ -0,0 +1,200 @@
30263 ++#ifndef GR_SECURITY_H
30264 ++#define GR_SECURITY_H
30265 ++#include <linux/fs.h>
30266 ++#include <linux/binfmts.h>
30267 ++#include <linux/gracl.h>
30268 ++
30269 ++/* notify of brain-dead configs */
30270 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
30271 ++#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
30272 ++#endif
30273 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30274 ++#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30275 ++#endif
30276 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30277 ++#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30278 ++#endif
30279 ++#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
30280 ++#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
30281 ++#endif
30282 ++#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
30283 ++#error "CONFIG_PAX enabled, but no PaX options are enabled."
30284 ++#endif
30285 ++
30286 ++void gr_handle_brute_attach(struct task_struct *p);
30287 ++void gr_handle_brute_check(void);
30288 ++
30289 ++char gr_roletype_to_char(void);
30290 ++
30291 ++int gr_check_user_change(int real, int effective, int fs);
30292 ++int gr_check_group_change(int real, int effective, int fs);
30293 ++
30294 ++void gr_del_task_from_ip_table(struct task_struct *p);
30295 ++
30296 ++int gr_pid_is_chrooted(struct task_struct *p);
30297 ++int gr_handle_chroot_nice(void);
30298 ++int gr_handle_chroot_sysctl(const int op);
30299 ++int gr_handle_chroot_setpriority(struct task_struct *p,
30300 ++ const int niceval);
30301 ++int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
30302 ++int gr_handle_chroot_chroot(const struct dentry *dentry,
30303 ++ const struct vfsmount *mnt);
30304 ++void gr_handle_chroot_caps(struct task_struct *task);
30305 ++void gr_handle_chroot_chdir(struct path *path);
30306 ++int gr_handle_chroot_chmod(const struct dentry *dentry,
30307 ++ const struct vfsmount *mnt, const int mode);
30308 ++int gr_handle_chroot_mknod(const struct dentry *dentry,
30309 ++ const struct vfsmount *mnt, const int mode);
30310 ++int gr_handle_chroot_mount(const struct dentry *dentry,
30311 ++ const struct vfsmount *mnt,
30312 ++ const char *dev_name);
30313 ++int gr_handle_chroot_pivot(void);
30314 ++int gr_handle_chroot_unix(const pid_t pid);
30315 ++
30316 ++int gr_handle_rawio(const struct inode *inode);
30317 ++int gr_handle_nproc(void);
30318 ++
30319 ++void gr_handle_ioperm(void);
30320 ++void gr_handle_iopl(void);
30321 ++
30322 ++int gr_tpe_allow(const struct file *file);
30323 ++
30324 ++int gr_random_pid(void);
30325 ++
30326 ++void gr_log_forkfail(const int retval);
30327 ++void gr_log_timechange(void);
30328 ++void gr_log_signal(const int sig, const struct task_struct *t);
30329 ++void gr_log_chdir(const struct dentry *dentry,
30330 ++ const struct vfsmount *mnt);
30331 ++void gr_log_chroot_exec(const struct dentry *dentry,
30332 ++ const struct vfsmount *mnt);
30333 ++void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
30334 ++void gr_log_remount(const char *devname, const int retval);
30335 ++void gr_log_unmount(const char *devname, const int retval);
30336 ++void gr_log_mount(const char *from, const char *to, const int retval);
30337 ++void gr_log_msgget(const int ret, const int msgflg);
30338 ++void gr_log_msgrm(const uid_t uid, const uid_t cuid);
30339 ++void gr_log_semget(const int err, const int semflg);
30340 ++void gr_log_semrm(const uid_t uid, const uid_t cuid);
30341 ++void gr_log_shmget(const int err, const int shmflg, const size_t size);
30342 ++void gr_log_shmrm(const uid_t uid, const uid_t cuid);
30343 ++void gr_log_textrel(struct vm_area_struct *vma);
30344 ++
30345 ++int gr_handle_follow_link(const struct inode *parent,
30346 ++ const struct inode *inode,
30347 ++ const struct dentry *dentry,
30348 ++ const struct vfsmount *mnt);
30349 ++int gr_handle_fifo(const struct dentry *dentry,
30350 ++ const struct vfsmount *mnt,
30351 ++ const struct dentry *dir, const int flag,
30352 ++ const int acc_mode);
30353 ++int gr_handle_hardlink(const struct dentry *dentry,
30354 ++ const struct vfsmount *mnt,
30355 ++ struct inode *inode,
30356 ++ const int mode, const char *to);
30357 ++
30358 ++int gr_task_is_capable(struct task_struct *task, const int cap);
30359 ++int gr_is_capable_nolog(const int cap);
30360 ++void gr_learn_resource(const struct task_struct *task, const int limit,
30361 ++ const unsigned long wanted, const int gt);
30362 ++void gr_copy_label(struct task_struct *tsk);
30363 ++void gr_handle_crash(struct task_struct *task, const int sig);
30364 ++int gr_handle_signal(const struct task_struct *p, const int sig);
30365 ++int gr_check_crash_uid(const uid_t uid);
30366 ++int gr_check_protected_task(const struct task_struct *task);
30367 ++int gr_acl_handle_mmap(const struct file *file,
30368 ++ const unsigned long prot);
30369 ++int gr_acl_handle_mprotect(const struct file *file,
30370 ++ const unsigned long prot);
30371 ++int gr_check_hidden_task(const struct task_struct *tsk);
30372 ++__u32 gr_acl_handle_truncate(const struct dentry *dentry,
30373 ++ const struct vfsmount *mnt);
30374 ++__u32 gr_acl_handle_utime(const struct dentry *dentry,
30375 ++ const struct vfsmount *mnt);
30376 ++__u32 gr_acl_handle_access(const struct dentry *dentry,
30377 ++ const struct vfsmount *mnt, const int fmode);
30378 ++__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
30379 ++ const struct vfsmount *mnt, mode_t mode);
30380 ++__u32 gr_acl_handle_chmod(const struct dentry *dentry,
30381 ++ const struct vfsmount *mnt, mode_t mode);
30382 ++__u32 gr_acl_handle_chown(const struct dentry *dentry,
30383 ++ const struct vfsmount *mnt);
30384 ++int gr_handle_ptrace(struct task_struct *task, const long request);
30385 ++int gr_handle_proc_ptrace(struct task_struct *task);
30386 ++__u32 gr_acl_handle_execve(const struct dentry *dentry,
30387 ++ const struct vfsmount *mnt);
30388 ++int gr_check_crash_exec(const struct file *filp);
30389 ++int gr_acl_is_enabled(void);
30390 ++void gr_set_kernel_label(struct task_struct *task);
30391 ++void gr_set_role_label(struct task_struct *task, const uid_t uid,
30392 ++ const gid_t gid);
30393 ++int gr_set_proc_label(const struct dentry *dentry,
30394 ++ const struct vfsmount *mnt);
30395 ++__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
30396 ++ const struct vfsmount *mnt);
30397 ++__u32 gr_acl_handle_open(const struct dentry *dentry,
30398 ++ const struct vfsmount *mnt, const int fmode);
30399 ++__u32 gr_acl_handle_creat(const struct dentry *dentry,
30400 ++ const struct dentry *p_dentry,
30401 ++ const struct vfsmount *p_mnt, const int fmode,
30402 ++ const int imode);
30403 ++void gr_handle_create(const struct dentry *dentry,
30404 ++ const struct vfsmount *mnt);
30405 ++__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
30406 ++ const struct dentry *parent_dentry,
30407 ++ const struct vfsmount *parent_mnt,
30408 ++ const int mode);
30409 ++__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
30410 ++ const struct dentry *parent_dentry,
30411 ++ const struct vfsmount *parent_mnt);
30412 ++__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
30413 ++ const struct vfsmount *mnt);
30414 ++void gr_handle_delete(const ino_t ino, const dev_t dev);
30415 ++__u32 gr_acl_handle_unlink(const struct dentry *dentry,
30416 ++ const struct vfsmount *mnt);
30417 ++__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
30418 ++ const struct dentry *parent_dentry,
30419 ++ const struct vfsmount *parent_mnt,
30420 ++ const char *from);
30421 ++__u32 gr_acl_handle_link(const struct dentry *new_dentry,
30422 ++ const struct dentry *parent_dentry,
30423 ++ const struct vfsmount *parent_mnt,
30424 ++ const struct dentry *old_dentry,
30425 ++ const struct vfsmount *old_mnt, const char *to);
30426 ++int gr_acl_handle_rename(struct dentry *new_dentry,
30427 ++ struct dentry *parent_dentry,
30428 ++ const struct vfsmount *parent_mnt,
30429 ++ struct dentry *old_dentry,
30430 ++ struct inode *old_parent_inode,
30431 ++ struct vfsmount *old_mnt, const char *newname);
30432 ++void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
30433 ++ struct dentry *old_dentry,
30434 ++ struct dentry *new_dentry,
30435 ++ struct vfsmount *mnt, const __u8 replace);
30436 ++__u32 gr_check_link(const struct dentry *new_dentry,
30437 ++ const struct dentry *parent_dentry,
30438 ++ const struct vfsmount *parent_mnt,
30439 ++ const struct dentry *old_dentry,
30440 ++ const struct vfsmount *old_mnt);
30441 ++int gr_acl_handle_filldir(const struct file *file, const char *name,
30442 ++ const unsigned int namelen, const ino_t ino);
30443 ++
30444 ++__u32 gr_acl_handle_unix(const struct dentry *dentry,
30445 ++ const struct vfsmount *mnt);
30446 ++void gr_acl_handle_exit(void);
30447 ++void gr_acl_handle_psacct(struct task_struct *task, const long code);
30448 ++int gr_acl_handle_procpidmem(const struct task_struct *task);
30449 ++
30450 ++#ifdef CONFIG_GRKERNSEC
30451 ++void gr_handle_mem_write(void);
30452 ++void gr_handle_kmem_write(void);
30453 ++void gr_handle_open_port(void);
30454 ++int gr_handle_mem_mmap(const unsigned long offset,
30455 ++ struct vm_area_struct *vma);
30456 ++
30457 ++extern int grsec_enable_dmesg;
30458 ++extern int grsec_enable_randsrc;
30459 ++extern int grsec_enable_shm;
30460 ++#endif
30461 ++
30462 ++#endif
30463 +diff -urNp linux-2.6.27.10/include/linux/highmem.h linux-2.6.27.10/include/linux/highmem.h
30464 +--- linux-2.6.27.10/include/linux/highmem.h 2008-11-07 12:55:34.000000000 -0500
30465 ++++ linux-2.6.27.10/include/linux/highmem.h 2008-11-18 03:38:45.000000000 -0500
30466 +@@ -122,6 +122,13 @@ static inline void clear_highpage(struct
30467 + kunmap_atomic(kaddr, KM_USER0);
30468 + }
30469 +
30470 ++static inline void sanitize_highpage(struct page *page)
30471 ++{
30472 ++ void *kaddr = kmap_atomic(page, KM_CLEARPAGE);
30473 ++ clear_page(kaddr);
30474 ++ kunmap_atomic(kaddr, KM_CLEARPAGE);
30475 ++}
30476 ++
30477 + static inline void zero_user_segments(struct page *page,
30478 + unsigned start1, unsigned end1,
30479 + unsigned start2, unsigned end2)
30480 +diff -urNp linux-2.6.27.10/include/linux/jbd2.h linux-2.6.27.10/include/linux/jbd2.h
30481 +--- linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:38.000000000 -0500
30482 ++++ linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:46.000000000 -0500
30483 +@@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug;
30484 + } \
30485 + } while (0)
30486 + #else
30487 +-#define jbd_debug(f, a...) /**/
30488 ++#define jbd_debug(f, a...) do {} while (0)
30489 + #endif
30490 +
30491 + static inline void *jbd2_alloc(size_t size, gfp_t flags)
30492 +diff -urNp linux-2.6.27.10/include/linux/jbd.h linux-2.6.27.10/include/linux/jbd.h
30493 +--- linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:16:52.000000000 -0500
30494 ++++ linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:13:46.000000000 -0500
30495 +@@ -66,7 +66,7 @@ extern u8 journal_enable_debug;
30496 + } \
30497 + } while (0)
30498 + #else
30499 +-#define jbd_debug(f, a...) /**/
30500 ++#define jbd_debug(f, a...) do {} while (0)
30501 + #endif
30502 +
30503 + static inline void *jbd_alloc(size_t size, gfp_t flags)
30504 +diff -urNp linux-2.6.27.10/include/linux/libata.h linux-2.6.27.10/include/linux/libata.h
30505 +--- linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:38.000000000 -0500
30506 ++++ linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:46.000000000 -0500
30507 +@@ -64,11 +64,11 @@
30508 + #ifdef ATA_VERBOSE_DEBUG
30509 + #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30510 + #else
30511 +-#define VPRINTK(fmt, args...)
30512 ++#define VPRINTK(fmt, args...) do {} while (0)
30513 + #endif /* ATA_VERBOSE_DEBUG */
30514 + #else
30515 +-#define DPRINTK(fmt, args...)
30516 +-#define VPRINTK(fmt, args...)
30517 ++#define DPRINTK(fmt, args...) do {} while (0)
30518 ++#define VPRINTK(fmt, args...) do {} while (0)
30519 + #endif /* ATA_DEBUG */
30520 +
30521 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30522 +diff -urNp linux-2.6.27.10/include/linux/mm.h linux-2.6.27.10/include/linux/mm.h
30523 +--- linux-2.6.27.10/include/linux/mm.h 2008-11-07 12:55:34.000000000 -0500
30524 ++++ linux-2.6.27.10/include/linux/mm.h 2008-12-21 00:44:29.000000000 -0500
30525 +@@ -38,6 +38,7 @@ extern unsigned long mmap_min_addr;
30526 + #include <asm/page.h>
30527 + #include <asm/pgtable.h>
30528 + #include <asm/processor.h>
30529 ++#include <asm/mman.h>
30530 +
30531 + #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
30532 +
30533 +@@ -114,6 +115,10 @@ extern unsigned int kobjsize(const void
30534 + #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
30535 + #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
30536 +
30537 ++#ifdef CONFIG_PAX_PAGEEXEC
30538 ++#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */
30539 ++#endif
30540 ++
30541 + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
30542 + #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
30543 + #endif
30544 +@@ -874,6 +879,8 @@ struct shrinker {
30545 + extern void register_shrinker(struct shrinker *);
30546 + extern void unregister_shrinker(struct shrinker *);
30547 +
30548 ++pgprot_t vm_get_page_prot(unsigned long vm_flags);
30549 ++
30550 + int vma_wants_writenotify(struct vm_area_struct *vma);
30551 +
30552 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
30553 +@@ -1129,6 +1136,7 @@ out:
30554 + }
30555 +
30556 + extern int do_munmap(struct mm_struct *, unsigned long, size_t);
30557 ++extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
30558 +
30559 + extern unsigned long do_brk(unsigned long, unsigned long);
30560 +
30561 +@@ -1181,6 +1189,10 @@ extern struct vm_area_struct * find_vma(
30562 + extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
30563 + struct vm_area_struct **pprev);
30564 +
30565 ++extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
30566 ++extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
30567 ++extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
30568 ++
30569 + /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
30570 + NULL if none. Assume start_addr < end_addr. */
30571 + static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
30572 +@@ -1197,7 +1209,6 @@ static inline unsigned long vma_pages(st
30573 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
30574 + }
30575 +
30576 +-pgprot_t vm_get_page_prot(unsigned long vm_flags);
30577 + struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
30578 + int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
30579 + unsigned long pfn, unsigned long size, pgprot_t);
30580 +@@ -1286,5 +1297,11 @@ int vmemmap_populate_basepages(struct pa
30581 + int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
30582 + void vmemmap_populate_print_last(void);
30583 +
30584 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
30585 ++extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
30586 ++#else
30587 ++static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
30588 ++#endif
30589 ++
30590 + #endif /* __KERNEL__ */
30591 + #endif /* _LINUX_MM_H */
30592 +diff -urNp linux-2.6.27.10/include/linux/mm_types.h linux-2.6.27.10/include/linux/mm_types.h
30593 +--- linux-2.6.27.10/include/linux/mm_types.h 2008-11-07 12:55:34.000000000 -0500
30594 ++++ linux-2.6.27.10/include/linux/mm_types.h 2008-11-18 03:38:45.000000000 -0500
30595 +@@ -158,6 +158,8 @@ struct vm_area_struct {
30596 + #ifdef CONFIG_NUMA
30597 + struct mempolicy *vm_policy; /* NUMA policy for the VMA */
30598 + #endif
30599 ++
30600 ++ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
30601 + };
30602 +
30603 + struct core_thread {
30604 +@@ -257,6 +259,24 @@ struct mm_struct {
30605 + #ifdef CONFIG_MMU_NOTIFIER
30606 + struct mmu_notifier_mm *mmu_notifier_mm;
30607 + #endif
30608 ++
30609 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30610 ++ unsigned long pax_flags;
30611 ++#endif
30612 ++
30613 ++#ifdef CONFIG_PAX_DLRESOLVE
30614 ++ unsigned long call_dl_resolve;
30615 ++#endif
30616 ++
30617 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
30618 ++ unsigned long call_syscall;
30619 ++#endif
30620 ++
30621 ++#ifdef CONFIG_PAX_ASLR
30622 ++ unsigned long delta_mmap; /* randomized offset */
30623 ++ unsigned long delta_stack; /* randomized offset */
30624 ++#endif
30625 ++
30626 + };
30627 +
30628 + #endif /* _LINUX_MM_TYPES_H */
30629 +diff -urNp linux-2.6.27.10/include/linux/module.h linux-2.6.27.10/include/linux/module.h
30630 +--- linux-2.6.27.10/include/linux/module.h 2008-11-07 12:55:34.000000000 -0500
30631 ++++ linux-2.6.27.10/include/linux/module.h 2008-11-18 03:38:45.000000000 -0500
30632 +@@ -282,16 +282,16 @@ struct module
30633 + int (*init)(void);
30634 +
30635 + /* If this is non-NULL, vfree after init() returns */
30636 +- void *module_init;
30637 ++ void *module_init_rx, *module_init_rw;
30638 +
30639 + /* Here is the actual code + data, vfree'd on unload. */
30640 +- void *module_core;
30641 ++ void *module_core_rx, *module_core_rw;
30642 +
30643 + /* Here are the sizes of the init and core sections */
30644 +- unsigned int init_size, core_size;
30645 ++ unsigned int init_size_rw, core_size_rw;
30646 +
30647 + /* The size of the executable code in each section. */
30648 +- unsigned int init_text_size, core_text_size;
30649 ++ unsigned int init_size_rx, core_size_rx;
30650 +
30651 + /* The handle returned from unwind_add_table. */
30652 + void *unwind_info;
30653 +diff -urNp linux-2.6.27.10/include/linux/moduleloader.h linux-2.6.27.10/include/linux/moduleloader.h
30654 +--- linux-2.6.27.10/include/linux/moduleloader.h 2008-11-07 12:55:34.000000000 -0500
30655 ++++ linux-2.6.27.10/include/linux/moduleloader.h 2008-11-18 03:38:45.000000000 -0500
30656 +@@ -17,9 +17,21 @@ int module_frob_arch_sections(Elf_Ehdr *
30657 + sections. Returns NULL on failure. */
30658 + void *module_alloc(unsigned long size);
30659 +
30660 ++#ifdef CONFIG_PAX_KERNEXEC
30661 ++void *module_alloc_exec(unsigned long size);
30662 ++#else
30663 ++#define module_alloc_exec(x) module_alloc(x)
30664 ++#endif
30665 ++
30666 + /* Free memory returned from module_alloc. */
30667 + void module_free(struct module *mod, void *module_region);
30668 +
30669 ++#ifdef CONFIG_PAX_KERNEXEC
30670 ++void module_free_exec(struct module *mod, void *module_region);
30671 ++#else
30672 ++#define module_free_exec(x, y) module_free(x, y)
30673 ++#endif
30674 ++
30675 + /* Apply the given relocation to the (simplified) ELF. Return -error
30676 + or 0. */
30677 + int apply_relocate(Elf_Shdr *sechdrs,
30678 +diff -urNp linux-2.6.27.10/include/linux/namei.h linux-2.6.27.10/include/linux/namei.h
30679 +--- linux-2.6.27.10/include/linux/namei.h 2008-11-07 12:55:34.000000000 -0500
30680 ++++ linux-2.6.27.10/include/linux/namei.h 2008-11-18 03:38:45.000000000 -0500
30681 +@@ -21,7 +21,7 @@ struct nameidata {
30682 + unsigned int flags;
30683 + int last_type;
30684 + unsigned depth;
30685 +- char *saved_names[MAX_NESTED_LINKS + 1];
30686 ++ const char *saved_names[MAX_NESTED_LINKS + 1];
30687 +
30688 + /* Intent data */
30689 + union {
30690 +@@ -80,12 +80,12 @@ extern int follow_up(struct vfsmount **,
30691 + extern struct dentry *lock_rename(struct dentry *, struct dentry *);
30692 + extern void unlock_rename(struct dentry *, struct dentry *);
30693 +
30694 +-static inline void nd_set_link(struct nameidata *nd, char *path)
30695 ++static inline void nd_set_link(struct nameidata *nd, const char *path)
30696 + {
30697 + nd->saved_names[nd->depth] = path;
30698 + }
30699 +
30700 +-static inline char *nd_get_link(struct nameidata *nd)
30701 ++static inline const char *nd_get_link(struct nameidata *nd)
30702 + {
30703 + return nd->saved_names[nd->depth];
30704 + }
30705 +diff -urNp linux-2.6.27.10/include/linux/nodemask.h linux-2.6.27.10/include/linux/nodemask.h
30706 +--- linux-2.6.27.10/include/linux/nodemask.h 2008-11-07 12:55:34.000000000 -0500
30707 ++++ linux-2.6.27.10/include/linux/nodemask.h 2008-11-18 03:38:45.000000000 -0500
30708 +@@ -442,11 +442,11 @@ static inline int num_node_state(enum no
30709 +
30710 + #define any_online_node(mask) \
30711 + ({ \
30712 +- int node; \
30713 +- for_each_node_mask(node, (mask)) \
30714 +- if (node_online(node)) \
30715 ++ int __node; \
30716 ++ for_each_node_mask(__node, (mask)) \
30717 ++ if (node_online(__node)) \
30718 + break; \
30719 +- node; \
30720 ++ __node; \
30721 + })
30722 +
30723 + #define num_online_nodes() num_node_state(N_ONLINE)
30724 +diff -urNp linux-2.6.27.10/include/linux/percpu.h linux-2.6.27.10/include/linux/percpu.h
30725 +--- linux-2.6.27.10/include/linux/percpu.h 2008-11-07 12:55:34.000000000 -0500
30726 ++++ linux-2.6.27.10/include/linux/percpu.h 2008-11-18 03:38:45.000000000 -0500
30727 +@@ -43,7 +43,7 @@
30728 + #endif
30729 +
30730 + #define PERCPU_ENOUGH_ROOM \
30731 +- (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
30732 ++ ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE))
30733 + #endif /* PERCPU_ENOUGH_ROOM */
30734 +
30735 + /*
30736 +diff -urNp linux-2.6.27.10/include/linux/poison.h linux-2.6.27.10/include/linux/poison.h
30737 +--- linux-2.6.27.10/include/linux/poison.h 2008-11-07 12:55:34.000000000 -0500
30738 ++++ linux-2.6.27.10/include/linux/poison.h 2008-11-18 03:38:45.000000000 -0500
30739 +@@ -7,8 +7,8 @@
30740 + * under normal circumstances, used to verify that nobody uses
30741 + * non-initialized list entries.
30742 + */
30743 +-#define LIST_POISON1 ((void *) 0x00100100)
30744 +-#define LIST_POISON2 ((void *) 0x00200200)
30745 ++#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL)
30746 ++#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL)
30747 +
30748 + /********** include/linux/timer.h **********/
30749 + /*
30750 +diff -urNp linux-2.6.27.10/include/linux/random.h linux-2.6.27.10/include/linux/random.h
30751 +--- linux-2.6.27.10/include/linux/random.h 2008-11-07 12:55:34.000000000 -0500
30752 ++++ linux-2.6.27.10/include/linux/random.h 2008-11-18 03:38:45.000000000 -0500
30753 +@@ -72,6 +72,11 @@ unsigned long randomize_range(unsigned l
30754 + u32 random32(void);
30755 + void srandom32(u32 seed);
30756 +
30757 ++static inline unsigned long pax_get_random_long(void)
30758 ++{
30759 ++ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
30760 ++}
30761 ++
30762 + #endif /* __KERNEL___ */
30763 +
30764 + #endif /* _LINUX_RANDOM_H */
30765 +diff -urNp linux-2.6.27.10/include/linux/sched.h linux-2.6.27.10/include/linux/sched.h
30766 +--- linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:38.000000000 -0500
30767 ++++ linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:46.000000000 -0500
30768 +@@ -96,6 +96,7 @@ struct exec_domain;
30769 + struct futex_pi_state;
30770 + struct robust_list_head;
30771 + struct bio;
30772 ++struct linux_binprm;
30773 +
30774 + /*
30775 + * List of flags we want to share for kernel threads,
30776 +@@ -545,6 +546,15 @@ struct signal_struct {
30777 + unsigned audit_tty;
30778 + struct tty_audit_buf *tty_audit_buf;
30779 + #endif
30780 ++
30781 ++#ifdef CONFIG_GRKERNSEC
30782 ++ u32 curr_ip;
30783 ++ u32 gr_saddr;
30784 ++ u32 gr_daddr;
30785 ++ u16 gr_sport;
30786 ++ u16 gr_dport;
30787 ++ u8 used_accept:1;
30788 ++#endif
30789 + };
30790 +
30791 + /* Context switch must be unlocked if interrupts are to be enabled */
30792 +@@ -1030,7 +1040,7 @@ struct sched_rt_entity {
30793 +
30794 + struct task_struct {
30795 + volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
30796 +- void *stack;
30797 ++ struct thread_info *stack;
30798 + atomic_t usage;
30799 + unsigned int flags; /* per process flags, defined below */
30800 + unsigned int ptrace;
30801 +@@ -1095,10 +1105,9 @@ struct task_struct {
30802 + pid_t pid;
30803 + pid_t tgid;
30804 +
30805 +-#ifdef CONFIG_CC_STACKPROTECTOR
30806 + /* Canary value for the -fstack-protector gcc feature */
30807 + unsigned long stack_canary;
30808 +-#endif
30809 ++
30810 + /*
30811 + * pointers to (original) parent process, youngest child, younger sibling,
30812 + * older sibling, respectively. (p->father can be replaced with
30813 +@@ -1126,8 +1135,8 @@ struct task_struct {
30814 + struct list_head thread_group;
30815 +
30816 + struct completion *vfork_done; /* for vfork() */
30817 +- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
30818 +- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30819 ++ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
30820 ++ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30821 +
30822 + cputime_t utime, stime, utimescaled, stimescaled;
30823 + cputime_t gtime;
30824 +@@ -1307,8 +1316,64 @@ struct task_struct {
30825 + int latency_record_count;
30826 + struct latency_record latency_record[LT_SAVECOUNT];
30827 + #endif
30828 ++
30829 ++#ifdef CONFIG_GRKERNSEC
30830 ++ /* grsecurity */
30831 ++ struct acl_subject_label *acl;
30832 ++ struct acl_role_label *role;
30833 ++ struct file *exec_file;
30834 ++ u16 acl_role_id;
30835 ++ u8 acl_sp_role;
30836 ++ u8 is_writable;
30837 ++ u8 brute;
30838 ++#endif
30839 ++
30840 + };
30841 +
30842 ++#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
30843 ++#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
30844 ++#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
30845 ++#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
30846 ++/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
30847 ++#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
30848 ++
30849 ++#ifdef CONFIG_PAX_SOFTMODE
30850 ++extern unsigned int pax_softmode;
30851 ++#endif
30852 ++
30853 ++extern int pax_check_flags(unsigned long *);
30854 ++
30855 ++/* if tsk != current then task_lock must be held on it */
30856 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30857 ++static inline unsigned long pax_get_flags(struct task_struct *tsk)
30858 ++{
30859 ++ if (likely(tsk->mm))
30860 ++ return tsk->mm->pax_flags;
30861 ++ else
30862 ++ return 0UL;
30863 ++}
30864 ++
30865 ++/* if tsk != current then task_lock must be held on it */
30866 ++static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
30867 ++{
30868 ++ if (likely(tsk->mm)) {
30869 ++ tsk->mm->pax_flags = flags;
30870 ++ return 0;
30871 ++ }
30872 ++ return -EINVAL;
30873 ++}
30874 ++#endif
30875 ++
30876 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
30877 ++extern void pax_set_initial_flags(struct linux_binprm *bprm);
30878 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
30879 ++extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
30880 ++#endif
30881 ++
30882 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
30883 ++void pax_report_insns(void *pc, void *sp);
30884 ++void pax_report_refcount_overflow(struct pt_regs *regs);
30885 ++
30886 + /*
30887 + * Priority of a process goes from 0..MAX_PRIO-1, valid RT
30888 + * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
30889 +@@ -1849,7 +1914,7 @@ extern void __cleanup_sighand(struct sig
30890 + extern void exit_itimers(struct signal_struct *);
30891 + extern void flush_itimer_signals(void);
30892 +
30893 +-extern NORET_TYPE void do_group_exit(int);
30894 ++extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
30895 +
30896 + extern void daemonize(const char *, ...);
30897 + extern int allow_signal(int);
30898 +@@ -1952,8 +2017,8 @@ static inline void unlock_task_sighand(s
30899 +
30900 + #ifndef __HAVE_THREAD_FUNCTIONS
30901 +
30902 +-#define task_thread_info(task) ((struct thread_info *)(task)->stack)
30903 +-#define task_stack_page(task) ((task)->stack)
30904 ++#define task_thread_info(task) ((task)->stack)
30905 ++#define task_stack_page(task) ((void *)(task)->stack)
30906 +
30907 + static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
30908 + {
30909 +diff -urNp linux-2.6.27.10/include/linux/screen_info.h linux-2.6.27.10/include/linux/screen_info.h
30910 +--- linux-2.6.27.10/include/linux/screen_info.h 2008-11-07 12:55:34.000000000 -0500
30911 ++++ linux-2.6.27.10/include/linux/screen_info.h 2008-11-18 03:38:45.000000000 -0500
30912 +@@ -42,7 +42,8 @@ struct screen_info {
30913 + __u16 pages; /* 0x32 */
30914 + __u16 vesa_attributes; /* 0x34 */
30915 + __u32 capabilities; /* 0x36 */
30916 +- __u8 _reserved[6]; /* 0x3a */
30917 ++ __u16 vesapm_size; /* 0x3a */
30918 ++ __u8 _reserved[4]; /* 0x3c */
30919 + } __attribute__((packed));
30920 +
30921 + #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
30922 +diff -urNp linux-2.6.27.10/include/linux/shm.h linux-2.6.27.10/include/linux/shm.h
30923 +--- linux-2.6.27.10/include/linux/shm.h 2008-11-07 12:55:34.000000000 -0500
30924 ++++ linux-2.6.27.10/include/linux/shm.h 2008-11-18 03:38:45.000000000 -0500
30925 +@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
30926 + pid_t shm_cprid;
30927 + pid_t shm_lprid;
30928 + struct user_struct *mlock_user;
30929 ++#ifdef CONFIG_GRKERNSEC
30930 ++ time_t shm_createtime;
30931 ++ pid_t shm_lapid;
30932 ++#endif
30933 + };
30934 +
30935 + /* shm_mode upper byte flags */
30936 +diff -urNp linux-2.6.27.10/include/linux/slab.h linux-2.6.27.10/include/linux/slab.h
30937 +--- linux-2.6.27.10/include/linux/slab.h 2008-11-07 12:55:34.000000000 -0500
30938 ++++ linux-2.6.27.10/include/linux/slab.h 2008-11-18 03:38:45.000000000 -0500
30939 +@@ -45,10 +45,9 @@
30940 + * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
30941 + * Both make kfree a no-op.
30942 + */
30943 +-#define ZERO_SIZE_PTR ((void *)16)
30944 ++#define ZERO_SIZE_PTR ((void *)-1024L)
30945 +
30946 +-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
30947 +- (unsigned long)ZERO_SIZE_PTR)
30948 ++#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR)
30949 +
30950 + /*
30951 + * struct kmem_cache related prototypes
30952 +diff -urNp linux-2.6.27.10/include/linux/sysctl.h linux-2.6.27.10/include/linux/sysctl.h
30953 +--- linux-2.6.27.10/include/linux/sysctl.h 2008-11-07 12:55:34.000000000 -0500
30954 ++++ linux-2.6.27.10/include/linux/sysctl.h 2008-11-18 03:38:45.000000000 -0500
30955 +@@ -165,7 +165,11 @@ enum
30956 + KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
30957 + };
30958 +
30959 +-
30960 ++#ifdef CONFIG_PAX_SOFTMODE
30961 ++enum {
30962 ++ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
30963 ++};
30964 ++#endif
30965 +
30966 + /* CTL_VM names: */
30967 + enum
30968 +diff -urNp linux-2.6.27.10/include/linux/thread_info.h linux-2.6.27.10/include/linux/thread_info.h
30969 +--- linux-2.6.27.10/include/linux/thread_info.h 2008-11-07 12:55:34.000000000 -0500
30970 ++++ linux-2.6.27.10/include/linux/thread_info.h 2008-11-18 03:38:45.000000000 -0500
30971 +@@ -23,7 +23,7 @@ struct restart_block {
30972 + };
30973 + /* For futex_wait */
30974 + struct {
30975 +- u32 *uaddr;
30976 ++ u32 __user *uaddr;
30977 + u32 val;
30978 + u32 flags;
30979 + u32 bitset;
30980 +diff -urNp linux-2.6.27.10/include/linux/uaccess.h linux-2.6.27.10/include/linux/uaccess.h
30981 +--- linux-2.6.27.10/include/linux/uaccess.h 2008-11-07 12:55:34.000000000 -0500
30982 ++++ linux-2.6.27.10/include/linux/uaccess.h 2008-11-18 03:38:45.000000000 -0500
30983 +@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
30984 + long ret; \
30985 + mm_segment_t old_fs = get_fs(); \
30986 + \
30987 +- set_fs(KERNEL_DS); \
30988 + pagefault_disable(); \
30989 ++ set_fs(KERNEL_DS); \
30990 + ret = __get_user(retval, (__force typeof(retval) __user *)(addr)); \
30991 +- pagefault_enable(); \
30992 + set_fs(old_fs); \
30993 ++ pagefault_enable(); \
30994 + ret; \
30995 + })
30996 +
30997 +diff -urNp linux-2.6.27.10/include/linux/vmalloc.h linux-2.6.27.10/include/linux/vmalloc.h
30998 +--- linux-2.6.27.10/include/linux/vmalloc.h 2008-11-07 12:55:34.000000000 -0500
30999 ++++ linux-2.6.27.10/include/linux/vmalloc.h 2008-11-18 03:38:45.000000000 -0500
31000 +@@ -12,6 +12,11 @@ struct vm_area_struct; /* vma defining
31001 + #define VM_MAP 0x00000004 /* vmap()ed pages */
31002 + #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
31003 + #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
31004 ++
31005 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31006 ++#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
31007 ++#endif
31008 ++
31009 + /* bits [20..32] reserved for arch specific ioremap internals */
31010 +
31011 + /*
31012 +diff -urNp linux-2.6.27.10/include/net/sctp/sctp.h linux-2.6.27.10/include/net/sctp/sctp.h
31013 +--- linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-07 12:55:34.000000000 -0500
31014 ++++ linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-18 03:38:45.000000000 -0500
31015 +@@ -309,8 +309,8 @@ extern int sctp_debug_flag;
31016 +
31017 + #else /* SCTP_DEBUG */
31018 +
31019 +-#define SCTP_DEBUG_PRINTK(whatever...)
31020 +-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
31021 ++#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
31022 ++#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
31023 + #define SCTP_ENABLE_DEBUG
31024 + #define SCTP_DISABLE_DEBUG
31025 + #define SCTP_ASSERT(expr, str, func)
31026 +diff -urNp linux-2.6.27.10/include/sound/core.h linux-2.6.27.10/include/sound/core.h
31027 +--- linux-2.6.27.10/include/sound/core.h 2008-11-07 12:55:34.000000000 -0500
31028 ++++ linux-2.6.27.10/include/sound/core.h 2008-11-18 03:38:45.000000000 -0500
31029 +@@ -406,9 +406,9 @@ void snd_verbose_printd(const char *file
31030 +
31031 + #else /* !CONFIG_SND_DEBUG */
31032 +
31033 +-#define snd_printd(fmt, args...) /* nothing */
31034 ++#define snd_printd(fmt, args...) do {} while (0)
31035 + #define snd_assert(expr, args...) (void)(expr)
31036 +-#define snd_BUG() /* nothing */
31037 ++#define snd_BUG() do {} while (0)
31038 +
31039 + #endif /* CONFIG_SND_DEBUG */
31040 +
31041 +@@ -422,7 +422,7 @@ void snd_verbose_printd(const char *file
31042 + */
31043 + #define snd_printdd(format, args...) snd_printk(format, ##args)
31044 + #else
31045 +-#define snd_printdd(format, args...) /* nothing */
31046 ++#define snd_printdd(format, args...) do {} while (0)
31047 + #endif
31048 +
31049 +
31050 +diff -urNp linux-2.6.27.10/include/video/uvesafb.h linux-2.6.27.10/include/video/uvesafb.h
31051 +--- linux-2.6.27.10/include/video/uvesafb.h 2008-11-07 12:55:34.000000000 -0500
31052 ++++ linux-2.6.27.10/include/video/uvesafb.h 2008-11-18 03:38:45.000000000 -0500
31053 +@@ -175,6 +175,7 @@ struct uvesafb_par {
31054 + u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
31055 + u8 pmi_setpal; /* PMI for palette changes */
31056 + u16 *pmi_base; /* protected mode interface location */
31057 ++ u8 *pmi_code; /* protected mode code location */
31058 + void *pmi_start;
31059 + void *pmi_pal;
31060 + u8 *vbe_state_orig; /*
31061 +diff -urNp linux-2.6.27.10/init/do_mounts.c linux-2.6.27.10/init/do_mounts.c
31062 +--- linux-2.6.27.10/init/do_mounts.c 2008-11-07 12:55:34.000000000 -0500
31063 ++++ linux-2.6.27.10/init/do_mounts.c 2008-11-18 03:38:45.000000000 -0500
31064 +@@ -214,11 +214,11 @@ static void __init get_fs_names(char *pa
31065 +
31066 + static int __init do_mount_root(char *name, char *fs, int flags, void *data)
31067 + {
31068 +- int err = sys_mount(name, "/root", fs, flags, data);
31069 ++ int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data);
31070 + if (err)
31071 + return err;
31072 +
31073 +- sys_chdir("/root");
31074 ++ sys_chdir((char __user *)"/root");
31075 + ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
31076 + printk("VFS: Mounted root (%s filesystem)%s.\n",
31077 + current->fs->pwd.mnt->mnt_sb->s_type->name,
31078 +@@ -304,18 +304,18 @@ void __init change_floppy(char *fmt, ...
31079 + va_start(args, fmt);
31080 + vsprintf(buf, fmt, args);
31081 + va_end(args);
31082 +- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
31083 ++ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
31084 + if (fd >= 0) {
31085 + sys_ioctl(fd, FDEJECT, 0);
31086 + sys_close(fd);
31087 + }
31088 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
31089 +- fd = sys_open("/dev/console", O_RDWR, 0);
31090 ++ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
31091 + if (fd >= 0) {
31092 + sys_ioctl(fd, TCGETS, (long)&termios);
31093 + termios.c_lflag &= ~ICANON;
31094 + sys_ioctl(fd, TCSETSF, (long)&termios);
31095 +- sys_read(fd, &c, 1);
31096 ++ sys_read(fd, (char __user *)&c, 1);
31097 + termios.c_lflag |= ICANON;
31098 + sys_ioctl(fd, TCSETSF, (long)&termios);
31099 + sys_close(fd);
31100 +@@ -402,7 +402,7 @@ void __init prepare_namespace(void)
31101 +
31102 + mount_root();
31103 + out:
31104 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31105 +- sys_chroot(".");
31106 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31107 ++ sys_chroot((char __user *)".");
31108 + }
31109 +
31110 +diff -urNp linux-2.6.27.10/init/do_mounts.h linux-2.6.27.10/init/do_mounts.h
31111 +--- linux-2.6.27.10/init/do_mounts.h 2008-11-07 12:55:34.000000000 -0500
31112 ++++ linux-2.6.27.10/init/do_mounts.h 2008-11-18 03:38:45.000000000 -0500
31113 +@@ -14,15 +14,15 @@ extern int root_mountflags;
31114 +
31115 + static inline int create_dev(char *name, dev_t dev)
31116 + {
31117 +- sys_unlink(name);
31118 +- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
31119 ++ sys_unlink((char __user *)name);
31120 ++ return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
31121 + }
31122 +
31123 + #if BITS_PER_LONG == 32
31124 + static inline u32 bstat(char *name)
31125 + {
31126 + struct stat64 stat;
31127 +- if (sys_stat64(name, &stat) != 0)
31128 ++ if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0)
31129 + return 0;
31130 + if (!S_ISBLK(stat.st_mode))
31131 + return 0;
31132 +diff -urNp linux-2.6.27.10/init/do_mounts_initrd.c linux-2.6.27.10/init/do_mounts_initrd.c
31133 +--- linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-07 12:55:34.000000000 -0500
31134 ++++ linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-18 03:38:45.000000000 -0500
31135 +@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
31136 + sys_close(old_fd);sys_close(root_fd);
31137 + sys_close(0);sys_close(1);sys_close(2);
31138 + sys_setsid();
31139 +- (void) sys_open("/dev/console",O_RDWR,0);
31140 ++ (void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
31141 + (void) sys_dup(0);
31142 + (void) sys_dup(0);
31143 + return kernel_execve(shell, argv, envp_init);
31144 +@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
31145 + create_dev("/dev/root.old", Root_RAM0);
31146 + /* mount initrd on rootfs' /root */
31147 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
31148 +- sys_mkdir("/old", 0700);
31149 +- root_fd = sys_open("/", 0, 0);
31150 +- old_fd = sys_open("/old", 0, 0);
31151 ++ sys_mkdir((const char __user *)"/old", 0700);
31152 ++ root_fd = sys_open((const char __user *)"/", 0, 0);
31153 ++ old_fd = sys_open((const char __user *)"/old", 0, 0);
31154 + /* move initrd over / and chdir/chroot in initrd root */
31155 +- sys_chdir("/root");
31156 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31157 +- sys_chroot(".");
31158 ++ sys_chdir((const char __user *)"/root");
31159 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31160 ++ sys_chroot((const char __user *)".");
31161 +
31162 + /*
31163 + * In case that a resume from disk is carried out by linuxrc or one of
31164 +@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
31165 +
31166 + /* move initrd to rootfs' /old */
31167 + sys_fchdir(old_fd);
31168 +- sys_mount("/", ".", NULL, MS_MOVE, NULL);
31169 ++ sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
31170 + /* switch root and cwd back to / of rootfs */
31171 + sys_fchdir(root_fd);
31172 +- sys_chroot(".");
31173 ++ sys_chroot((const char __user *)".");
31174 + sys_close(old_fd);
31175 + sys_close(root_fd);
31176 +
31177 + if (new_decode_dev(real_root_dev) == Root_RAM0) {
31178 +- sys_chdir("/old");
31179 ++ sys_chdir((const char __user *)"/old");
31180 + return;
31181 + }
31182 +
31183 +@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
31184 + mount_root();
31185 +
31186 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
31187 +- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
31188 ++ error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
31189 + if (!error)
31190 + printk("okay\n");
31191 + else {
31192 +- int fd = sys_open("/dev/root.old", O_RDWR, 0);
31193 ++ int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
31194 + if (error == -ENOENT)
31195 + printk("/initrd does not exist. Ignored.\n");
31196 + else
31197 + printk("failed\n");
31198 + printk(KERN_NOTICE "Unmounting old root\n");
31199 +- sys_umount("/old", MNT_DETACH);
31200 ++ sys_umount((char __user *)"/old", MNT_DETACH);
31201 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
31202 + if (fd < 0) {
31203 + error = fd;
31204 +@@ -119,11 +119,11 @@ int __init initrd_load(void)
31205 + * mounted in the normal path.
31206 + */
31207 + if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
31208 +- sys_unlink("/initrd.image");
31209 ++ sys_unlink((const char __user *)"/initrd.image");
31210 + handle_initrd();
31211 + return 1;
31212 + }
31213 + }
31214 +- sys_unlink("/initrd.image");
31215 ++ sys_unlink((const char __user *)"/initrd.image");
31216 + return 0;
31217 + }
31218 +diff -urNp linux-2.6.27.10/init/do_mounts_md.c linux-2.6.27.10/init/do_mounts_md.c
31219 +--- linux-2.6.27.10/init/do_mounts_md.c 2008-11-07 12:55:34.000000000 -0500
31220 ++++ linux-2.6.27.10/init/do_mounts_md.c 2008-11-18 03:38:45.000000000 -0500
31221 +@@ -166,7 +166,7 @@ static void __init md_setup_drive(void)
31222 + partitioned ? "_d" : "", minor,
31223 + md_setup_args[ent].device_names);
31224 +
31225 +- fd = sys_open(name, 0, 0);
31226 ++ fd = sys_open((char __user *)name, 0, 0);
31227 + if (fd < 0) {
31228 + printk(KERN_ERR "md: open failed - cannot start "
31229 + "array %s\n", name);
31230 +@@ -229,7 +229,7 @@ static void __init md_setup_drive(void)
31231 + * array without it
31232 + */
31233 + sys_close(fd);
31234 +- fd = sys_open(name, 0, 0);
31235 ++ fd = sys_open((char __user *)name, 0, 0);
31236 + sys_ioctl(fd, BLKRRPART, 0);
31237 + }
31238 + sys_close(fd);
31239 +@@ -270,7 +270,7 @@ void __init md_run_setup(void)
31240 + if (raid_noautodetect)
31241 + printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
31242 + else {
31243 +- int fd = sys_open("/dev/md0", 0, 0);
31244 ++ int fd = sys_open((char __user *)"/dev/md0", 0, 0);
31245 + if (fd >= 0) {
31246 + sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
31247 + sys_close(fd);
31248 +diff -urNp linux-2.6.27.10/init/initramfs.c linux-2.6.27.10/init/initramfs.c
31249 +--- linux-2.6.27.10/init/initramfs.c 2008-11-07 12:55:34.000000000 -0500
31250 ++++ linux-2.6.27.10/init/initramfs.c 2008-11-18 03:38:45.000000000 -0500
31251 +@@ -230,7 +230,7 @@ static int __init maybe_link(void)
31252 + if (nlink >= 2) {
31253 + char *old = find_link(major, minor, ino, mode, collected);
31254 + if (old)
31255 +- return (sys_link(old, collected) < 0) ? -1 : 1;
31256 ++ return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1;
31257 + }
31258 + return 0;
31259 + }
31260 +@@ -239,11 +239,11 @@ static void __init clean_path(char *path
31261 + {
31262 + struct stat st;
31263 +
31264 +- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
31265 ++ if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
31266 + if (S_ISDIR(st.st_mode))
31267 +- sys_rmdir(path);
31268 ++ sys_rmdir((char __user *)path);
31269 + else
31270 +- sys_unlink(path);
31271 ++ sys_unlink((char __user *)path);
31272 + }
31273 + }
31274 +
31275 +@@ -266,7 +266,7 @@ static int __init do_name(void)
31276 + int openflags = O_WRONLY|O_CREAT;
31277 + if (ml != 1)
31278 + openflags |= O_TRUNC;
31279 +- wfd = sys_open(collected, openflags, mode);
31280 ++ wfd = sys_open((char __user *)collected, openflags, mode);
31281 +
31282 + if (wfd >= 0) {
31283 + sys_fchown(wfd, uid, gid);
31284 +@@ -275,15 +275,15 @@ static int __init do_name(void)
31285 + }
31286 + }
31287 + } else if (S_ISDIR(mode)) {
31288 +- sys_mkdir(collected, mode);
31289 +- sys_chown(collected, uid, gid);
31290 +- sys_chmod(collected, mode);
31291 ++ sys_mkdir((char __user *)collected, mode);
31292 ++ sys_chown((char __user *)collected, uid, gid);
31293 ++ sys_chmod((char __user *)collected, mode);
31294 + } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
31295 + S_ISFIFO(mode) || S_ISSOCK(mode)) {
31296 + if (maybe_link() == 0) {
31297 +- sys_mknod(collected, mode, rdev);
31298 +- sys_chown(collected, uid, gid);
31299 +- sys_chmod(collected, mode);
31300 ++ sys_mknod((char __user *)collected, mode, rdev);
31301 ++ sys_chown((char __user *)collected, uid, gid);
31302 ++ sys_chmod((char __user *)collected, mode);
31303 + }
31304 + }
31305 + return 0;
31306 +@@ -292,13 +292,13 @@ static int __init do_name(void)
31307 + static int __init do_copy(void)
31308 + {
31309 + if (count >= body_len) {
31310 +- sys_write(wfd, victim, body_len);
31311 ++ sys_write(wfd, (char __user *)victim, body_len);
31312 + sys_close(wfd);
31313 + eat(body_len);
31314 + state = SkipIt;
31315 + return 0;
31316 + } else {
31317 +- sys_write(wfd, victim, count);
31318 ++ sys_write(wfd, (char __user *)victim, count);
31319 + body_len -= count;
31320 + eat(count);
31321 + return 1;
31322 +@@ -309,8 +309,8 @@ static int __init do_symlink(void)
31323 + {
31324 + collected[N_ALIGN(name_len) + body_len] = '\0';
31325 + clean_path(collected, 0);
31326 +- sys_symlink(collected + N_ALIGN(name_len), collected);
31327 +- sys_lchown(collected, uid, gid);
31328 ++ sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected);
31329 ++ sys_lchown((char __user *)collected, uid, gid);
31330 + state = SkipIt;
31331 + next_state = Reset;
31332 + return 0;
31333 +diff -urNp linux-2.6.27.10/init/Kconfig linux-2.6.27.10/init/Kconfig
31334 +--- linux-2.6.27.10/init/Kconfig 2008-11-07 12:55:34.000000000 -0500
31335 ++++ linux-2.6.27.10/init/Kconfig 2008-11-18 03:38:45.000000000 -0500
31336 +@@ -561,6 +561,7 @@ config SYSCTL_SYSCALL
31337 + config KALLSYMS
31338 + bool "Load all symbols for debugging/ksymoops" if EMBEDDED
31339 + default y
31340 ++ depends on !GRKERNSEC_HIDESYM
31341 + help
31342 + Say Y here to let the kernel print out symbolic crash information and
31343 + symbolic stack backtraces. This increases the size of the kernel
31344 +@@ -780,8 +781,8 @@ config MARKERS
31345 + source "arch/Kconfig"
31346 +
31347 + config PROC_PAGE_MONITOR
31348 +- default y
31349 +- depends on PROC_FS && MMU
31350 ++ default n
31351 ++ depends on PROC_FS && MMU && !GRKERNSEC
31352 + bool "Enable /proc page monitoring" if EMBEDDED
31353 + help
31354 + Various /proc files exist to monitor process memory utilization:
31355 +@@ -797,9 +798,9 @@ config HAVE_GENERIC_DMA_COHERENT
31356 +
31357 + config SLABINFO
31358 + bool
31359 +- depends on PROC_FS
31360 ++ depends on PROC_FS && !GRKERNSEC_PROC_ADD
31361 + depends on SLAB || SLUB_DEBUG
31362 +- default y
31363 ++ default n
31364 +
31365 + config RT_MUTEXES
31366 + boolean
31367 +diff -urNp linux-2.6.27.10/init/main.c linux-2.6.27.10/init/main.c
31368 +--- linux-2.6.27.10/init/main.c 2008-11-07 12:55:34.000000000 -0500
31369 ++++ linux-2.6.27.10/init/main.c 2008-11-18 03:38:45.000000000 -0500
31370 +@@ -101,6 +101,7 @@ static inline void mark_rodata_ro(void)
31371 + #ifdef CONFIG_TC
31372 + extern void tc_init(void);
31373 + #endif
31374 ++extern void grsecurity_init(void);
31375 +
31376 + enum system_states system_state;
31377 + EXPORT_SYMBOL(system_state);
31378 +@@ -187,6 +188,40 @@ static int __init set_reset_devices(char
31379 +
31380 + __setup("reset_devices", set_reset_devices);
31381 +
31382 ++#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32)
31383 ++static int __init setup_pax_nouderef(char *str)
31384 ++{
31385 ++ unsigned int cpu;
31386 ++
31387 ++#ifdef CONFIG_PAX_KERNEXEC
31388 ++ unsigned long cr0;
31389 ++
31390 ++ pax_open_kernel(cr0);
31391 ++#endif
31392 ++
31393 ++ for (cpu = 0; cpu < NR_CPUS; cpu++)
31394 ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300;
31395 ++
31396 ++#ifdef CONFIG_PAX_KERNEXEC
31397 ++ pax_close_kernel(cr0);
31398 ++#endif
31399 ++
31400 ++ return 1;
31401 ++}
31402 ++__setup("pax_nouderef", setup_pax_nouderef);
31403 ++#endif
31404 ++
31405 ++#ifdef CONFIG_PAX_SOFTMODE
31406 ++unsigned int pax_softmode;
31407 ++
31408 ++static int __init setup_pax_softmode(char *str)
31409 ++{
31410 ++ get_option(&str, &pax_softmode);
31411 ++ return 1;
31412 ++}
31413 ++__setup("pax_softmode=", setup_pax_softmode);
31414 ++#endif
31415 ++
31416 + static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
31417 + char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
31418 + static const char *panic_later, *panic_param;
31419 +@@ -385,7 +420,7 @@ static void __init setup_nr_cpu_ids(void
31420 + }
31421 +
31422 + #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
31423 +-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
31424 ++unsigned long __per_cpu_offset[NR_CPUS] __read_only;
31425 +
31426 + EXPORT_SYMBOL(__per_cpu_offset);
31427 +
31428 +@@ -704,6 +739,7 @@ int do_one_initcall(initcall_t fn)
31429 + {
31430 + int count = preempt_count();
31431 + ktime_t t0, t1, delta;
31432 ++ const char *msg1 = "", *msg2 = "";
31433 + char msgbuf[64];
31434 + int result;
31435 +
31436 +@@ -729,15 +765,15 @@ int do_one_initcall(initcall_t fn)
31437 + sprintf(msgbuf, "error code %d ", result);
31438 +
31439 + if (preempt_count() != count) {
31440 +- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
31441 ++ msg1 = " preemption imbalance";
31442 + preempt_count() = count;
31443 + }
31444 + if (irqs_disabled()) {
31445 +- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
31446 ++ msg2 = " disabled interrupts";
31447 + local_irq_enable();
31448 + }
31449 +- if (msgbuf[0]) {
31450 +- printk("initcall %pF returned with %s\n", fn, msgbuf);
31451 ++ if (msgbuf[0] || *msg1 || *msg2) {
31452 ++ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
31453 + }
31454 +
31455 + return result;
31456 +@@ -876,6 +912,8 @@ static int __init kernel_init(void * unu
31457 + prepare_namespace();
31458 + }
31459 +
31460 ++ grsecurity_init();
31461 ++
31462 + /*
31463 + * Ok, we have completed the initial bootup, and
31464 + * we're essentially up and running. Get rid of the
31465 +diff -urNp linux-2.6.27.10/init/noinitramfs.c linux-2.6.27.10/init/noinitramfs.c
31466 +--- linux-2.6.27.10/init/noinitramfs.c 2008-11-07 12:55:34.000000000 -0500
31467 ++++ linux-2.6.27.10/init/noinitramfs.c 2008-11-18 03:38:45.000000000 -0500
31468 +@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
31469 + {
31470 + int err;
31471 +
31472 +- err = sys_mkdir("/dev", 0755);
31473 ++ err = sys_mkdir((const char __user *)"/dev", 0755);
31474 + if (err < 0)
31475 + goto out;
31476 +
31477 +@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
31478 + if (err < 0)
31479 + goto out;
31480 +
31481 +- err = sys_mkdir("/root", 0700);
31482 ++ err = sys_mkdir((const char __user *)"/root", 0700);
31483 + if (err < 0)
31484 + goto out;
31485 +
31486 +diff -urNp linux-2.6.27.10/ipc/ipc_sysctl.c linux-2.6.27.10/ipc/ipc_sysctl.c
31487 +--- linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-07 12:55:34.000000000 -0500
31488 ++++ linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-18 03:38:45.000000000 -0500
31489 +@@ -268,7 +268,7 @@ static struct ctl_table ipc_kern_table[]
31490 + .extra1 = &zero,
31491 + .extra2 = &one,
31492 + },
31493 +- {}
31494 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31495 + };
31496 +
31497 + static struct ctl_table ipc_root_table[] = {
31498 +@@ -278,7 +278,7 @@ static struct ctl_table ipc_root_table[]
31499 + .mode = 0555,
31500 + .child = ipc_kern_table,
31501 + },
31502 +- {}
31503 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31504 + };
31505 +
31506 + static int __init ipc_sysctl_init(void)
31507 +diff -urNp linux-2.6.27.10/ipc/msg.c linux-2.6.27.10/ipc/msg.c
31508 +--- linux-2.6.27.10/ipc/msg.c 2008-11-07 12:55:34.000000000 -0500
31509 ++++ linux-2.6.27.10/ipc/msg.c 2008-11-18 03:38:45.000000000 -0500
31510 +@@ -38,6 +38,7 @@
31511 + #include <linux/rwsem.h>
31512 + #include <linux/nsproxy.h>
31513 + #include <linux/ipc_namespace.h>
31514 ++#include <linux/grsecurity.h>
31515 +
31516 + #include <asm/current.h>
31517 + #include <asm/uaccess.h>
31518 +@@ -314,6 +315,7 @@ asmlinkage long sys_msgget(key_t key, in
31519 + struct ipc_namespace *ns;
31520 + struct ipc_ops msg_ops;
31521 + struct ipc_params msg_params;
31522 ++ long err;
31523 +
31524 + ns = current->nsproxy->ipc_ns;
31525 +
31526 +@@ -324,7 +326,11 @@ asmlinkage long sys_msgget(key_t key, in
31527 + msg_params.key = key;
31528 + msg_params.flg = msgflg;
31529 +
31530 +- return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31531 ++ err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31532 ++
31533 ++ gr_log_msgget(err, msgflg);
31534 ++
31535 ++ return err;
31536 + }
31537 +
31538 + static inline unsigned long
31539 +@@ -434,6 +440,7 @@ static int msgctl_down(struct ipc_namesp
31540 +
31541 + switch (cmd) {
31542 + case IPC_RMID:
31543 ++ gr_log_msgrm(ipcp->uid, ipcp->cuid);
31544 + freeque(ns, ipcp);
31545 + goto out_up;
31546 + case IPC_SET:
31547 +diff -urNp linux-2.6.27.10/ipc/sem.c linux-2.6.27.10/ipc/sem.c
31548 +--- linux-2.6.27.10/ipc/sem.c 2008-11-07 12:55:34.000000000 -0500
31549 ++++ linux-2.6.27.10/ipc/sem.c 2008-11-18 03:38:45.000000000 -0500
31550 +@@ -83,6 +83,7 @@
31551 + #include <linux/rwsem.h>
31552 + #include <linux/nsproxy.h>
31553 + #include <linux/ipc_namespace.h>
31554 ++#include <linux/grsecurity.h>
31555 +
31556 + #include <asm/uaccess.h>
31557 + #include "util.h"
31558 +@@ -313,6 +314,7 @@ asmlinkage long sys_semget(key_t key, in
31559 + struct ipc_namespace *ns;
31560 + struct ipc_ops sem_ops;
31561 + struct ipc_params sem_params;
31562 ++ long err;
31563 +
31564 + ns = current->nsproxy->ipc_ns;
31565 +
31566 +@@ -327,7 +329,11 @@ asmlinkage long sys_semget(key_t key, in
31567 + sem_params.flg = semflg;
31568 + sem_params.u.nsems = nsems;
31569 +
31570 +- return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31571 ++ err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31572 ++
31573 ++ gr_log_semget(err, semflg);
31574 ++
31575 ++ return err;
31576 + }
31577 +
31578 + /*
31579 +@@ -870,6 +876,7 @@ static int semctl_down(struct ipc_namesp
31580 +
31581 + switch(cmd){
31582 + case IPC_RMID:
31583 ++ gr_log_semrm(ipcp->uid, ipcp->cuid);
31584 + freeary(ns, ipcp);
31585 + goto out_up;
31586 + case IPC_SET:
31587 +diff -urNp linux-2.6.27.10/ipc/shm.c linux-2.6.27.10/ipc/shm.c
31588 +--- linux-2.6.27.10/ipc/shm.c 2008-11-07 12:55:34.000000000 -0500
31589 ++++ linux-2.6.27.10/ipc/shm.c 2008-11-18 03:38:45.000000000 -0500
31590 +@@ -39,6 +39,7 @@
31591 + #include <linux/nsproxy.h>
31592 + #include <linux/mount.h>
31593 + #include <linux/ipc_namespace.h>
31594 ++#include <linux/grsecurity.h>
31595 +
31596 + #include <asm/uaccess.h>
31597 +
31598 +@@ -69,6 +70,14 @@ static void shm_destroy (struct ipc_name
31599 + static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
31600 + #endif
31601 +
31602 ++#ifdef CONFIG_GRKERNSEC
31603 ++extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31604 ++ const time_t shm_createtime, const uid_t cuid,
31605 ++ const int shmid);
31606 ++extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31607 ++ const time_t shm_createtime);
31608 ++#endif
31609 ++
31610 + void shm_init_ns(struct ipc_namespace *ns)
31611 + {
31612 + ns->shm_ctlmax = SHMMAX;
31613 +@@ -87,6 +96,8 @@ static void do_shm_rmid(struct ipc_names
31614 + struct shmid_kernel *shp;
31615 + shp = container_of(ipcp, struct shmid_kernel, shm_perm);
31616 +
31617 ++ gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
31618 ++
31619 + if (shp->shm_nattch){
31620 + shp->shm_perm.mode |= SHM_DEST;
31621 + /* Do not find it any more */
31622 +@@ -392,6 +403,14 @@ static int newseg(struct ipc_namespace *
31623 + shp->shm_lprid = 0;
31624 + shp->shm_atim = shp->shm_dtim = 0;
31625 + shp->shm_ctim = get_seconds();
31626 ++#ifdef CONFIG_GRKERNSEC
31627 ++ {
31628 ++ struct timespec timeval;
31629 ++ do_posix_clock_monotonic_gettime(&timeval);
31630 ++
31631 ++ shp->shm_createtime = timeval.tv_sec;
31632 ++ }
31633 ++#endif
31634 + shp->shm_segsz = size;
31635 + shp->shm_nattch = 0;
31636 + shp->shm_file = file;
31637 +@@ -445,6 +464,7 @@ asmlinkage long sys_shmget (key_t key, s
31638 + struct ipc_namespace *ns;
31639 + struct ipc_ops shm_ops;
31640 + struct ipc_params shm_params;
31641 ++ long err;
31642 +
31643 + ns = current->nsproxy->ipc_ns;
31644 +
31645 +@@ -456,7 +476,11 @@ asmlinkage long sys_shmget (key_t key, s
31646 + shm_params.flg = shmflg;
31647 + shm_params.u.size = size;
31648 +
31649 +- return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31650 ++ err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31651 ++
31652 ++ gr_log_shmget(err, shmflg, size);
31653 ++
31654 ++ return err;
31655 + }
31656 +
31657 + static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
31658 +@@ -869,9 +893,21 @@ long do_shmat(int shmid, char __user *sh
31659 + if (err)
31660 + goto out_unlock;
31661 +
31662 ++#ifdef CONFIG_GRKERNSEC
31663 ++ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
31664 ++ shp->shm_perm.cuid, shmid) ||
31665 ++ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
31666 ++ err = -EACCES;
31667 ++ goto out_unlock;
31668 ++ }
31669 ++#endif
31670 ++
31671 + path.dentry = dget(shp->shm_file->f_path.dentry);
31672 + path.mnt = shp->shm_file->f_path.mnt;
31673 + shp->shm_nattch++;
31674 ++#ifdef CONFIG_GRKERNSEC
31675 ++ shp->shm_lapid = current->pid;
31676 ++#endif
31677 + size = i_size_read(path.dentry->d_inode);
31678 + shm_unlock(shp);
31679 +
31680 +diff -urNp linux-2.6.27.10/kernel/acct.c linux-2.6.27.10/kernel/acct.c
31681 +--- linux-2.6.27.10/kernel/acct.c 2008-11-07 12:55:34.000000000 -0500
31682 ++++ linux-2.6.27.10/kernel/acct.c 2008-11-18 03:38:45.000000000 -0500
31683 +@@ -573,7 +573,7 @@ static void do_acct_process(struct bsd_a
31684 + */
31685 + flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
31686 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
31687 +- file->f_op->write(file, (char *)&ac,
31688 ++ file->f_op->write(file, (char __user *)&ac,
31689 + sizeof(acct_t), &file->f_pos);
31690 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
31691 + set_fs(fs);
31692 +diff -urNp linux-2.6.27.10/kernel/capability.c linux-2.6.27.10/kernel/capability.c
31693 +--- linux-2.6.27.10/kernel/capability.c 2008-11-07 12:55:34.000000000 -0500
31694 ++++ linux-2.6.27.10/kernel/capability.c 2008-11-18 03:38:45.000000000 -0500
31695 +@@ -13,6 +13,7 @@
31696 + #include <linux/security.h>
31697 + #include <linux/syscalls.h>
31698 + #include <linux/pid_namespace.h>
31699 ++#include <linux/grsecurity.h>
31700 + #include <asm/uaccess.h>
31701 +
31702 + /*
31703 +@@ -498,10 +499,21 @@ asmlinkage long sys_capset(cap_user_head
31704 + */
31705 + int capable(int cap)
31706 + {
31707 +- if (has_capability(current, cap)) {
31708 ++ if (has_capability(current, cap) && gr_task_is_capable(current, cap)) {
31709 + current->flags |= PF_SUPERPRIV;
31710 + return 1;
31711 + }
31712 + return 0;
31713 + }
31714 ++
31715 ++int capable_nolog(int cap)
31716 ++{
31717 ++ if (has_capability(current, cap) && gr_is_capable_nolog(cap)) {
31718 ++ current->flags |= PF_SUPERPRIV;
31719 ++ return 1;
31720 ++ }
31721 ++ return 0;
31722 ++}
31723 ++
31724 + EXPORT_SYMBOL(capable);
31725 ++EXPORT_SYMBOL(capable_nolog);
31726 +diff -urNp linux-2.6.27.10/kernel/configs.c linux-2.6.27.10/kernel/configs.c
31727 +--- linux-2.6.27.10/kernel/configs.c 2008-11-07 12:55:34.000000000 -0500
31728 ++++ linux-2.6.27.10/kernel/configs.c 2008-11-18 03:38:45.000000000 -0500
31729 +@@ -79,8 +79,19 @@ static int __init ikconfig_init(void)
31730 + struct proc_dir_entry *entry;
31731 +
31732 + /* create the current config file */
31733 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
31734 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
31735 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
31736 ++ &ikconfig_file_ops);
31737 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
31738 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
31739 ++ &ikconfig_file_ops);
31740 ++#endif
31741 ++#else
31742 + entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
31743 + &ikconfig_file_ops);
31744 ++#endif
31745 ++
31746 + if (!entry)
31747 + return -ENOMEM;
31748 +
31749 +diff -urNp linux-2.6.27.10/kernel/cpu.c linux-2.6.27.10/kernel/cpu.c
31750 +--- linux-2.6.27.10/kernel/cpu.c 2008-11-07 12:55:34.000000000 -0500
31751 ++++ linux-2.6.27.10/kernel/cpu.c 2008-11-18 03:38:45.000000000 -0500
31752 +@@ -40,7 +40,7 @@ EXPORT_SYMBOL(cpu_possible_map);
31753 + /* Serializes the updates to cpu_online_map, cpu_present_map */
31754 + static DEFINE_MUTEX(cpu_add_remove_lock);
31755 +
31756 +-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
31757 ++static RAW_NOTIFIER_HEAD(cpu_chain);
31758 +
31759 + /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
31760 + * Should always be manipulated under cpu_add_remove_lock
31761 +diff -urNp linux-2.6.27.10/kernel/exit.c linux-2.6.27.10/kernel/exit.c
31762 +--- linux-2.6.27.10/kernel/exit.c 2008-11-07 12:55:34.000000000 -0500
31763 ++++ linux-2.6.27.10/kernel/exit.c 2008-11-29 19:01:27.000000000 -0500
31764 +@@ -40,13 +40,17 @@
31765 + #include <linux/cn_proc.h>
31766 + #include <linux/mutex.h>
31767 + #include <linux/futex.h>
31768 +-#include <linux/compat.h>
31769 + #include <linux/pipe_fs_i.h>
31770 + #include <linux/audit.h> /* for audit_free() */
31771 + #include <linux/resource.h>
31772 + #include <linux/blkdev.h>
31773 + #include <linux/task_io_accounting_ops.h>
31774 + #include <linux/tracehook.h>
31775 ++#include <linux/grsecurity.h>
31776 ++
31777 ++#ifdef CONFIG_GRKERNSEC
31778 ++extern rwlock_t grsec_exec_file_lock;
31779 ++#endif
31780 +
31781 + #include <asm/uaccess.h>
31782 + #include <asm/unistd.h>
31783 +@@ -133,7 +137,6 @@ static void __exit_signal(struct task_st
31784 + * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
31785 + */
31786 + flush_sigqueue(&tsk->pending);
31787 +-
31788 + tsk->signal = NULL;
31789 + tsk->sighand = NULL;
31790 + spin_unlock(&sighand->siglock);
31791 +@@ -158,6 +161,8 @@ void release_task(struct task_struct * p
31792 + struct task_struct *leader;
31793 + int zap_leader;
31794 + repeat:
31795 ++ gr_del_task_from_ip_table(p);
31796 ++
31797 + tracehook_prepare_release_task(p);
31798 + atomic_dec(&p->user->processes);
31799 + proc_flush_task(p);
31800 +@@ -321,11 +326,22 @@ static void reparent_to_kthreadd(void)
31801 + {
31802 + write_lock_irq(&tasklist_lock);
31803 +
31804 ++#ifdef CONFIG_GRKERNSEC
31805 ++ write_lock(&grsec_exec_file_lock);
31806 ++ if (current->exec_file) {
31807 ++ fput(current->exec_file);
31808 ++ current->exec_file = NULL;
31809 ++ }
31810 ++ write_unlock(&grsec_exec_file_lock);
31811 ++#endif
31812 ++
31813 + ptrace_unlink(current);
31814 + /* Reparent to init */
31815 + current->real_parent = current->parent = kthreadd_task;
31816 + list_move_tail(&current->sibling, &current->real_parent->children);
31817 +
31818 ++ gr_set_kernel_label(current);
31819 ++
31820 + /* Set the exit signal to SIGCHLD so we signal init on exit */
31821 + current->exit_signal = SIGCHLD;
31822 +
31823 +@@ -419,6 +435,17 @@ void daemonize(const char *name, ...)
31824 + vsnprintf(current->comm, sizeof(current->comm), name, args);
31825 + va_end(args);
31826 +
31827 ++#ifdef CONFIG_GRKERNSEC
31828 ++ write_lock(&grsec_exec_file_lock);
31829 ++ if (current->exec_file) {
31830 ++ fput(current->exec_file);
31831 ++ current->exec_file = NULL;
31832 ++ }
31833 ++ write_unlock(&grsec_exec_file_lock);
31834 ++#endif
31835 ++
31836 ++ gr_set_kernel_label(current);
31837 ++
31838 + /*
31839 + * If we were started as result of loading a module, close all of the
31840 + * user space pages. We don't need them, and if we didn't close them
31841 +@@ -1054,14 +1081,6 @@ NORET_TYPE void do_exit(long code)
31842 + exit_itimers(tsk->signal);
31843 + }
31844 + acct_collect(code, group_dead);
31845 +-#ifdef CONFIG_FUTEX
31846 +- if (unlikely(tsk->robust_list))
31847 +- exit_robust_list(tsk);
31848 +-#ifdef CONFIG_COMPAT
31849 +- if (unlikely(tsk->compat_robust_list))
31850 +- compat_exit_robust_list(tsk);
31851 +-#endif
31852 +-#endif
31853 + if (group_dead)
31854 + tty_audit_exit();
31855 + if (unlikely(tsk->audit_context))
31856 +@@ -1070,6 +1089,9 @@ NORET_TYPE void do_exit(long code)
31857 + tsk->exit_code = code;
31858 + taskstats_exit(tsk, group_dead);
31859 +
31860 ++ gr_acl_handle_psacct(tsk, code);
31861 ++ gr_acl_handle_exit();
31862 ++
31863 + exit_mm(tsk);
31864 +
31865 + if (group_dead)
31866 +@@ -1272,7 +1294,7 @@ static int wait_task_zombie(struct task_
31867 + if (unlikely(options & WNOWAIT)) {
31868 + uid_t uid = p->uid;
31869 + int exit_code = p->exit_code;
31870 +- int why, status;
31871 ++ int why;
31872 +
31873 + get_task_struct(p);
31874 + read_unlock(&tasklist_lock);
31875 +diff -urNp linux-2.6.27.10/kernel/fork.c linux-2.6.27.10/kernel/fork.c
31876 +--- linux-2.6.27.10/kernel/fork.c 2008-12-21 01:16:52.000000000 -0500
31877 ++++ linux-2.6.27.10/kernel/fork.c 2008-12-21 01:13:46.000000000 -0500
31878 +@@ -40,6 +40,7 @@
31879 + #include <linux/jiffies.h>
31880 + #include <linux/tracehook.h>
31881 + #include <linux/futex.h>
31882 ++#include <linux/compat.h>
31883 + #include <linux/task_io_accounting_ops.h>
31884 + #include <linux/rcupdate.h>
31885 + #include <linux/ptrace.h>
31886 +@@ -58,6 +59,7 @@
31887 + #include <linux/tty.h>
31888 + #include <linux/proc_fs.h>
31889 + #include <linux/blkdev.h>
31890 ++#include <linux/grsecurity.h>
31891 +
31892 + #include <asm/pgtable.h>
31893 + #include <asm/pgalloc.h>
31894 +@@ -234,7 +236,7 @@ static struct task_struct *dup_task_stru
31895 + setup_thread_stack(tsk, orig);
31896 +
31897 + #ifdef CONFIG_CC_STACKPROTECTOR
31898 +- tsk->stack_canary = get_random_int();
31899 ++ tsk->stack_canary = pax_get_random_long();
31900 + #endif
31901 +
31902 + /* One for us, one for whoever does the "release_task()" (usually parent) */
31903 +@@ -271,8 +273,8 @@ static int dup_mmap(struct mm_struct *mm
31904 + mm->locked_vm = 0;
31905 + mm->mmap = NULL;
31906 + mm->mmap_cache = NULL;
31907 +- mm->free_area_cache = oldmm->mmap_base;
31908 +- mm->cached_hole_size = ~0UL;
31909 ++ mm->free_area_cache = oldmm->free_area_cache;
31910 ++ mm->cached_hole_size = oldmm->cached_hole_size;
31911 + mm->map_count = 0;
31912 + cpus_clear(mm->cpu_vm_mask);
31913 + mm->mm_rb = RB_ROOT;
31914 +@@ -309,6 +311,7 @@ static int dup_mmap(struct mm_struct *mm
31915 + tmp->vm_flags &= ~VM_LOCKED;
31916 + tmp->vm_mm = mm;
31917 + tmp->vm_next = NULL;
31918 ++ tmp->vm_mirror = NULL;
31919 + anon_vma_link(tmp);
31920 + file = tmp->vm_file;
31921 + if (file) {
31922 +@@ -356,6 +359,31 @@ static int dup_mmap(struct mm_struct *mm
31923 + if (retval)
31924 + goto out;
31925 + }
31926 ++
31927 ++#ifdef CONFIG_PAX_SEGMEXEC
31928 ++ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
31929 ++ struct vm_area_struct *mpnt_m;
31930 ++
31931 ++ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
31932 ++ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
31933 ++
31934 ++ if (!mpnt->vm_mirror)
31935 ++ continue;
31936 ++
31937 ++ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
31938 ++ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
31939 ++ mpnt->vm_mirror = mpnt_m;
31940 ++ } else {
31941 ++ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
31942 ++ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
31943 ++ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
31944 ++ mpnt->vm_mirror->vm_mirror = mpnt;
31945 ++ }
31946 ++ }
31947 ++ BUG_ON(mpnt_m);
31948 ++ }
31949 ++#endif
31950 ++
31951 + /* a new mm has just been created */
31952 + arch_dup_mmap(oldmm, mm);
31953 + retval = 0;
31954 +@@ -521,6 +549,18 @@ void mm_release(struct task_struct *tsk,
31955 + {
31956 + struct completion *vfork_done = tsk->vfork_done;
31957 +
31958 ++ /* Get rid of any futexes when releasing the mm */
31959 ++#ifdef CONFIG_FUTEX
31960 ++ if (unlikely(tsk->robust_list))
31961 ++ exit_robust_list(tsk);
31962 ++ tsk->robust_list = NULL;
31963 ++#ifdef CONFIG_COMPAT
31964 ++ if (unlikely(tsk->compat_robust_list))
31965 ++ compat_exit_robust_list(tsk);
31966 ++ tsk->compat_robust_list = NULL;
31967 ++#endif
31968 ++#endif
31969 ++
31970 + /* Get rid of any cached register state */
31971 + deactivate_mm(tsk, mm);
31972 +
31973 +@@ -539,7 +579,7 @@ void mm_release(struct task_struct *tsk,
31974 + if (tsk->clear_child_tid
31975 + && !(tsk->flags & PF_SIGNALED)
31976 + && atomic_read(&mm->mm_users) > 1) {
31977 +- u32 __user * tidptr = tsk->clear_child_tid;
31978 ++ pid_t __user * tidptr = tsk->clear_child_tid;
31979 + tsk->clear_child_tid = NULL;
31980 +
31981 + /*
31982 +@@ -547,7 +587,7 @@ void mm_release(struct task_struct *tsk,
31983 + * not set up a proper pointer then tough luck.
31984 + */
31985 + put_user(0, tidptr);
31986 +- sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31987 ++ sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31988 + }
31989 + }
31990 +
31991 +@@ -942,6 +982,9 @@ static struct task_struct *copy_process(
31992 + DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
31993 + #endif
31994 + retval = -EAGAIN;
31995 ++
31996 ++ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes), 0);
31997 ++
31998 + if (atomic_read(&p->user->processes) >=
31999 + p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
32000 + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
32001 +@@ -1108,6 +1151,8 @@ static struct task_struct *copy_process(
32002 + goto bad_fork_free_pid;
32003 + }
32004 +
32005 ++ gr_copy_label(p);
32006 ++
32007 + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
32008 + /*
32009 + * Clear TID on mm_release()?
32010 +@@ -1293,6 +1338,8 @@ bad_fork_cleanup_count:
32011 + bad_fork_free:
32012 + free_task(p);
32013 + fork_out:
32014 ++ gr_log_forkfail(retval);
32015 ++
32016 + return ERR_PTR(retval);
32017 + }
32018 +
32019 +@@ -1369,6 +1416,8 @@ long do_fork(unsigned long clone_flags,
32020 + if (clone_flags & CLONE_PARENT_SETTID)
32021 + put_user(nr, parent_tidptr);
32022 +
32023 ++ gr_handle_brute_check();
32024 ++
32025 + if (clone_flags & CLONE_VFORK) {
32026 + p->vfork_done = &vfork;
32027 + init_completion(&vfork);
32028 +diff -urNp linux-2.6.27.10/kernel/futex.c linux-2.6.27.10/kernel/futex.c
32029 +--- linux-2.6.27.10/kernel/futex.c 2008-11-07 12:55:34.000000000 -0500
32030 ++++ linux-2.6.27.10/kernel/futex.c 2008-11-18 03:38:45.000000000 -0500
32031 +@@ -188,6 +188,11 @@ static int get_futex_key(u32 __user *uad
32032 + struct page *page;
32033 + int err;
32034 +
32035 ++#ifdef CONFIG_PAX_SEGMEXEC
32036 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
32037 ++ return -EFAULT;
32038 ++#endif
32039 ++
32040 + /*
32041 + * The futex address must be "naturally" aligned.
32042 + */
32043 +@@ -214,8 +219,8 @@ static int get_futex_key(u32 __user *uad
32044 + * The futex is hashed differently depending on whether
32045 + * it's in a shared or private mapping. So check vma first.
32046 + */
32047 +- vma = find_extend_vma(mm, address);
32048 +- if (unlikely(!vma))
32049 ++ vma = find_vma(mm, address);
32050 ++ if (unlikely(!vma || address < vma->vm_start))
32051 + return -EFAULT;
32052 +
32053 + /*
32054 +@@ -1345,7 +1350,7 @@ static int futex_wait(u32 __user *uaddr,
32055 + struct restart_block *restart;
32056 + restart = &current_thread_info()->restart_block;
32057 + restart->fn = futex_wait_restart;
32058 +- restart->futex.uaddr = (u32 *)uaddr;
32059 ++ restart->futex.uaddr = uaddr;
32060 + restart->futex.val = val;
32061 + restart->futex.time = abs_time->tv64;
32062 + restart->futex.bitset = bitset;
32063 +@@ -1906,7 +1911,7 @@ retry:
32064 + */
32065 + static inline int fetch_robust_entry(struct robust_list __user **entry,
32066 + struct robust_list __user * __user *head,
32067 +- int *pi)
32068 ++ unsigned int *pi)
32069 + {
32070 + unsigned long uentry;
32071 +
32072 +diff -urNp linux-2.6.27.10/kernel/irq/handle.c linux-2.6.27.10/kernel/irq/handle.c
32073 +--- linux-2.6.27.10/kernel/irq/handle.c 2008-11-07 12:55:34.000000000 -0500
32074 ++++ linux-2.6.27.10/kernel/irq/handle.c 2008-11-18 03:38:45.000000000 -0500
32075 +@@ -55,7 +55,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach
32076 + .depth = 1,
32077 + .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
32078 + #ifdef CONFIG_SMP
32079 +- .affinity = CPU_MASK_ALL
32080 ++ .affinity = CPU_MASK_ALL,
32081 ++ .cpu = 0,
32082 + #endif
32083 + }
32084 + };
32085 +diff -urNp linux-2.6.27.10/kernel/kallsyms.c linux-2.6.27.10/kernel/kallsyms.c
32086 +--- linux-2.6.27.10/kernel/kallsyms.c 2008-11-07 12:55:34.000000000 -0500
32087 ++++ linux-2.6.27.10/kernel/kallsyms.c 2008-11-18 03:38:45.000000000 -0500
32088 +@@ -62,6 +62,19 @@ static inline int is_kernel_text(unsigne
32089 +
32090 + static inline int is_kernel(unsigned long addr)
32091 + {
32092 ++
32093 ++#ifdef CONFIG_PAX_KERNEXEC
32094 ++
32095 ++#ifdef CONFIG_MODULES
32096 ++ if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) &&
32097 ++ ktla_ktva(addr) < (unsigned long)MODULES_END)
32098 ++ return 0;
32099 ++#endif
32100 ++
32101 ++ if (is_kernel_inittext(addr))
32102 ++ return 1;
32103 ++#endif
32104 ++
32105 + if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
32106 + return 1;
32107 + return in_gate_area_no_task(addr);
32108 +@@ -366,7 +379,6 @@ static unsigned long get_ksymbol_core(st
32109 +
32110 + static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
32111 + {
32112 +- iter->name[0] = '\0';
32113 + iter->nameoff = get_symbol_offset(new_pos);
32114 + iter->pos = new_pos;
32115 + }
32116 +@@ -450,7 +462,7 @@ static int kallsyms_open(struct inode *i
32117 + struct kallsym_iter *iter;
32118 + int ret;
32119 +
32120 +- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
32121 ++ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
32122 + if (!iter)
32123 + return -ENOMEM;
32124 + reset_iter(iter, 0);
32125 +@@ -472,7 +484,15 @@ static const struct file_operations kall
32126 +
32127 + static int __init kallsyms_init(void)
32128 + {
32129 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
32130 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32131 ++ proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations);
32132 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32133 ++ proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations);
32134 ++#endif
32135 ++#else
32136 + proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
32137 ++#endif
32138 + return 0;
32139 + }
32140 + __initcall(kallsyms_init);
32141 +diff -urNp linux-2.6.27.10/kernel/kmod.c linux-2.6.27.10/kernel/kmod.c
32142 +--- linux-2.6.27.10/kernel/kmod.c 2008-11-07 12:55:34.000000000 -0500
32143 ++++ linux-2.6.27.10/kernel/kmod.c 2008-11-18 03:38:45.000000000 -0500
32144 +@@ -108,7 +108,7 @@ int request_module(const char *fmt, ...)
32145 + return -ENOMEM;
32146 + }
32147 +
32148 +- ret = call_usermodehelper(modprobe_path, argv, envp, 1);
32149 ++ ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC);
32150 + atomic_dec(&kmod_concurrent);
32151 + return ret;
32152 + }
32153 +diff -urNp linux-2.6.27.10/kernel/kprobes.c linux-2.6.27.10/kernel/kprobes.c
32154 +--- linux-2.6.27.10/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
32155 ++++ linux-2.6.27.10/kernel/kprobes.c 2008-11-18 03:38:45.000000000 -0500
32156 +@@ -182,7 +182,7 @@ kprobe_opcode_t __kprobes *get_insn_slot
32157 + * kernel image and loaded module images reside. This is required
32158 + * so x86_64 can correctly handle the %rip-relative fixups.
32159 + */
32160 +- kip->insns = module_alloc(PAGE_SIZE);
32161 ++ kip->insns = module_alloc_exec(PAGE_SIZE);
32162 + if (!kip->insns) {
32163 + kfree(kip);
32164 + return NULL;
32165 +@@ -214,7 +214,7 @@ static int __kprobes collect_one_slot(st
32166 + hlist_add_head(&kip->hlist,
32167 + &kprobe_insn_pages);
32168 + } else {
32169 +- module_free(NULL, kip->insns);
32170 ++ module_free_exec(NULL, kip->insns);
32171 + kfree(kip);
32172 + }
32173 + return 1;
32174 +diff -urNp linux-2.6.27.10/kernel/lockdep.c linux-2.6.27.10/kernel/lockdep.c
32175 +--- linux-2.6.27.10/kernel/lockdep.c 2008-11-07 12:55:34.000000000 -0500
32176 ++++ linux-2.6.27.10/kernel/lockdep.c 2008-11-18 03:38:45.000000000 -0500
32177 +@@ -627,6 +627,10 @@ static int static_obj(void *obj)
32178 + int i;
32179 + #endif
32180 +
32181 ++#ifdef CONFIG_PAX_KERNEXEC
32182 ++ start = (unsigned long )&_data;
32183 ++#endif
32184 ++
32185 + /*
32186 + * static variable?
32187 + */
32188 +@@ -638,9 +642,12 @@ static int static_obj(void *obj)
32189 + * percpu var?
32190 + */
32191 + for_each_possible_cpu(i) {
32192 ++#ifdef CONFIG_X86_32
32193 ++ start = per_cpu_offset(i);
32194 ++#else
32195 + start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
32196 +- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
32197 +- + per_cpu_offset(i);
32198 ++#endif
32199 ++ end = start + PERCPU_ENOUGH_ROOM;
32200 +
32201 + if ((addr >= start) && (addr < end))
32202 + return 1;
32203 +diff -urNp linux-2.6.27.10/kernel/module.c linux-2.6.27.10/kernel/module.c
32204 +--- linux-2.6.27.10/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
32205 ++++ linux-2.6.27.10/kernel/module.c 2008-12-21 01:17:47.000000000 -0500
32206 +@@ -44,6 +44,11 @@
32207 + #include <linux/unwind.h>
32208 + #include <asm/uaccess.h>
32209 + #include <asm/cacheflush.h>
32210 ++
32211 ++#ifdef CONFIG_PAX_KERNEXEC
32212 ++#include <asm/desc.h>
32213 ++#endif
32214 ++
32215 + #include <linux/license.h>
32216 + #include <asm/sections.h>
32217 +
32218 +@@ -71,7 +76,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
32219 + static BLOCKING_NOTIFIER_HEAD(module_notify_list);
32220 +
32221 + /* Bounds of module allocation, for speeding __module_text_address */
32222 +-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
32223 ++static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
32224 ++static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
32225 ++
32226 ++extern int gr_check_modstop(void);
32227 +
32228 + int register_module_notifier(struct notifier_block * nb)
32229 + {
32230 +@@ -217,7 +225,7 @@ static bool each_symbol(bool (*fn)(const
32231 + return true;
32232 +
32233 + list_for_each_entry(mod, &modules, list) {
32234 +- struct symsearch arr[] = {
32235 ++ struct symsearch modarr[] = {
32236 + { mod->syms, mod->syms + mod->num_syms, mod->crcs,
32237 + NOT_GPL_ONLY, false },
32238 + { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
32239 +@@ -239,7 +247,7 @@ static bool each_symbol(bool (*fn)(const
32240 + #endif
32241 + };
32242 +
32243 +- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
32244 ++ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
32245 + return true;
32246 + }
32247 + return false;
32248 +@@ -375,6 +383,8 @@ static inline unsigned int block_size(in
32249 + return val;
32250 + }
32251 +
32252 ++EXPORT_SYMBOL(__per_cpu_start);
32253 ++
32254 + static void *percpu_modalloc(unsigned long size, unsigned long align,
32255 + const char *name)
32256 + {
32257 +@@ -382,7 +392,7 @@ static void *percpu_modalloc(unsigned lo
32258 + unsigned int i;
32259 + void *ptr;
32260 +
32261 +- if (align > PAGE_SIZE) {
32262 ++ if (align-1 >= PAGE_SIZE) {
32263 + printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
32264 + name, align, PAGE_SIZE);
32265 + align = PAGE_SIZE;
32266 +@@ -464,7 +474,11 @@ static void percpu_modcopy(void *pcpudes
32267 + int cpu;
32268 +
32269 + for_each_possible_cpu(cpu)
32270 ++#ifdef CONFIG_X86_32
32271 ++ memcpy(pcpudest + __per_cpu_offset[cpu], from, size);
32272 ++#else
32273 + memcpy(pcpudest + per_cpu_offset(cpu), from, size);
32274 ++#endif
32275 + }
32276 +
32277 + static int percpu_modinit(void)
32278 +@@ -722,6 +736,9 @@ sys_delete_module(const char __user *nam
32279 + char name[MODULE_NAME_LEN];
32280 + int ret, forced = 0;
32281 +
32282 ++ if (gr_check_modstop())
32283 ++ return -EPERM;
32284 ++
32285 + if (!capable(CAP_SYS_MODULE))
32286 + return -EPERM;
32287 +
32288 +@@ -1430,16 +1447,19 @@ static void free_module(struct module *m
32289 + module_unload_free(mod);
32290 +
32291 + /* This may be NULL, but that's OK */
32292 +- module_free(mod, mod->module_init);
32293 ++ module_free(mod, mod->module_init_rw);
32294 ++ module_free_exec(mod, mod->module_init_rx);
32295 + kfree(mod->args);
32296 + if (mod->percpu)
32297 + percpu_modfree(mod->percpu);
32298 +
32299 + /* Free lock-classes: */
32300 +- lockdep_free_key_range(mod->module_core, mod->core_size);
32301 ++ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
32302 ++ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
32303 +
32304 + /* Finally, free the core (containing the module structure) */
32305 +- module_free(mod, mod->module_core);
32306 ++ module_free_exec(mod, mod->module_core_rx);
32307 ++ module_free(mod, mod->module_core_rw);
32308 + }
32309 +
32310 + void *__symbol_get(const char *symbol)
32311 +@@ -1505,10 +1525,14 @@ static int simplify_symbols(Elf_Shdr *se
32312 + struct module *mod)
32313 + {
32314 + Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
32315 +- unsigned long secbase;
32316 ++ unsigned long secbase, symbol;
32317 + unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32318 + int ret = 0;
32319 +
32320 ++#ifdef CONFIG_PAX_KERNEXEC
32321 ++ unsigned long cr0;
32322 ++#endif
32323 ++
32324 + for (i = 1; i < n; i++) {
32325 + switch (sym[i].st_shndx) {
32326 + case SHN_COMMON:
32327 +@@ -1527,10 +1551,19 @@ static int simplify_symbols(Elf_Shdr *se
32328 + break;
32329 +
32330 + case SHN_UNDEF:
32331 +- sym[i].st_value
32332 +- = resolve_symbol(sechdrs, versindex,
32333 ++ symbol = resolve_symbol(sechdrs, versindex,
32334 + strtab + sym[i].st_name, mod);
32335 +
32336 ++#ifdef CONFIG_PAX_KERNEXEC
32337 ++ pax_open_kernel(cr0);
32338 ++#endif
32339 ++
32340 ++ sym[i].st_value = symbol;
32341 ++
32342 ++#ifdef CONFIG_PAX_KERNEXEC
32343 ++ pax_close_kernel(cr0);
32344 ++#endif
32345 ++
32346 + /* Ok if resolved. */
32347 + if (!IS_ERR_VALUE(sym[i].st_value))
32348 + break;
32349 +@@ -1545,11 +1578,27 @@ static int simplify_symbols(Elf_Shdr *se
32350 +
32351 + default:
32352 + /* Divert to percpu allocation if a percpu var. */
32353 +- if (sym[i].st_shndx == pcpuindex)
32354 ++ if (sym[i].st_shndx == pcpuindex) {
32355 ++
32356 ++#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
32357 ++ secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start;
32358 ++#else
32359 + secbase = (unsigned long)mod->percpu;
32360 +- else
32361 ++#endif
32362 ++
32363 ++ } else
32364 + secbase = sechdrs[sym[i].st_shndx].sh_addr;
32365 ++
32366 ++#ifdef CONFIG_PAX_KERNEXEC
32367 ++ pax_open_kernel(cr0);
32368 ++#endif
32369 ++
32370 + sym[i].st_value += secbase;
32371 ++
32372 ++#ifdef CONFIG_PAX_KERNEXEC
32373 ++ pax_close_kernel(cr0);
32374 ++#endif
32375 ++
32376 + break;
32377 + }
32378 + }
32379 +@@ -1601,11 +1650,12 @@ static void layout_sections(struct modul
32380 + || strncmp(secstrings + s->sh_name,
32381 + ".init", 5) == 0)
32382 + continue;
32383 +- s->sh_entsize = get_offset(&mod->core_size, s);
32384 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32385 ++ s->sh_entsize = get_offset(&mod->core_size_rw, s);
32386 ++ else
32387 ++ s->sh_entsize = get_offset(&mod->core_size_rx, s);
32388 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32389 + }
32390 +- if (m == 0)
32391 +- mod->core_text_size = mod->core_size;
32392 + }
32393 +
32394 + DEBUGP("Init section allocation order:\n");
32395 +@@ -1619,12 +1669,13 @@ static void layout_sections(struct modul
32396 + || strncmp(secstrings + s->sh_name,
32397 + ".init", 5) != 0)
32398 + continue;
32399 +- s->sh_entsize = (get_offset(&mod->init_size, s)
32400 +- | INIT_OFFSET_MASK);
32401 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32402 ++ s->sh_entsize = get_offset(&mod->init_size_rw, s);
32403 ++ else
32404 ++ s->sh_entsize = get_offset(&mod->init_size_rx, s);
32405 ++ s->sh_entsize |= INIT_OFFSET_MASK;
32406 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32407 + }
32408 +- if (m == 0)
32409 +- mod->init_text_size = mod->init_size;
32410 + }
32411 + }
32412 +
32413 +@@ -1764,14 +1815,31 @@ static void add_kallsyms(struct module *
32414 + {
32415 + unsigned int i;
32416 +
32417 ++#ifdef CONFIG_PAX_KERNEXEC
32418 ++ unsigned long cr0;
32419 ++#endif
32420 ++
32421 + mod->symtab = (void *)sechdrs[symindex].sh_addr;
32422 + mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32423 + mod->strtab = (void *)sechdrs[strindex].sh_addr;
32424 +
32425 + /* Set types up while we still have access to sections. */
32426 +- for (i = 0; i < mod->num_symtab; i++)
32427 +- mod->symtab[i].st_info
32428 +- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32429 ++
32430 ++ for (i = 0; i < mod->num_symtab; i++) {
32431 ++ char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32432 ++
32433 ++#ifdef CONFIG_PAX_KERNEXEC
32434 ++ pax_open_kernel(cr0);
32435 ++#endif
32436 ++
32437 ++ mod->symtab[i].st_info = type;
32438 ++
32439 ++#ifdef CONFIG_PAX_KERNEXEC
32440 ++ pax_close_kernel(cr0);
32441 ++#endif
32442 ++
32443 ++ }
32444 ++
32445 + }
32446 + #else
32447 + static inline void add_kallsyms(struct module *mod,
32448 +@@ -1783,16 +1851,30 @@ static inline void add_kallsyms(struct m
32449 + }
32450 + #endif /* CONFIG_KALLSYMS */
32451 +
32452 +-static void *module_alloc_update_bounds(unsigned long size)
32453 ++static void *module_alloc_update_bounds_rw(unsigned long size)
32454 + {
32455 + void *ret = module_alloc(size);
32456 +
32457 + if (ret) {
32458 + /* Update module bounds. */
32459 +- if ((unsigned long)ret < module_addr_min)
32460 +- module_addr_min = (unsigned long)ret;
32461 +- if ((unsigned long)ret + size > module_addr_max)
32462 +- module_addr_max = (unsigned long)ret + size;
32463 ++ if ((unsigned long)ret < module_addr_min_rw)
32464 ++ module_addr_min_rw = (unsigned long)ret;
32465 ++ if ((unsigned long)ret + size > module_addr_max_rw)
32466 ++ module_addr_max_rw = (unsigned long)ret + size;
32467 ++ }
32468 ++ return ret;
32469 ++}
32470 ++
32471 ++static void *module_alloc_update_bounds_rx(unsigned long size)
32472 ++{
32473 ++ void *ret = module_alloc_exec(size);
32474 ++
32475 ++ if (ret) {
32476 ++ /* Update module bounds. */
32477 ++ if ((unsigned long)ret < module_addr_min_rx)
32478 ++ module_addr_min_rx = (unsigned long)ret;
32479 ++ if ((unsigned long)ret + size > module_addr_max_rx)
32480 ++ module_addr_max_rx = (unsigned long)ret + size;
32481 + }
32482 + return ret;
32483 + }
32484 +@@ -1837,6 +1919,10 @@ static noinline struct module *load_modu
32485 + struct exception_table_entry *extable;
32486 + mm_segment_t old_fs;
32487 +
32488 ++#ifdef CONFIG_PAX_KERNEXEC
32489 ++ unsigned long cr0;
32490 ++#endif
32491 ++
32492 + DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
32493 + umod, len, uargs);
32494 + if (len < sizeof(*hdr))
32495 +@@ -1998,22 +2084,57 @@ static noinline struct module *load_modu
32496 + layout_sections(mod, hdr, sechdrs, secstrings);
32497 +
32498 + /* Do the allocs. */
32499 +- ptr = module_alloc_update_bounds(mod->core_size);
32500 ++ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
32501 + if (!ptr) {
32502 + err = -ENOMEM;
32503 + goto free_percpu;
32504 + }
32505 +- memset(ptr, 0, mod->core_size);
32506 +- mod->module_core = ptr;
32507 ++ memset(ptr, 0, mod->core_size_rw);
32508 ++ mod->module_core_rw = ptr;
32509 ++
32510 ++ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
32511 ++ if (!ptr && mod->init_size_rw) {
32512 ++ err = -ENOMEM;
32513 ++ goto free_core_rw;
32514 ++ }
32515 ++ memset(ptr, 0, mod->init_size_rw);
32516 ++ mod->module_init_rw = ptr;
32517 ++
32518 ++ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
32519 ++ if (!ptr) {
32520 ++ err = -ENOMEM;
32521 ++ goto free_init_rw;
32522 ++ }
32523 ++
32524 ++#ifdef CONFIG_PAX_KERNEXEC
32525 ++ pax_open_kernel(cr0);
32526 ++#endif
32527 ++
32528 ++ memset(ptr, 0, mod->core_size_rx);
32529 +
32530 +- ptr = module_alloc_update_bounds(mod->init_size);
32531 +- if (!ptr && mod->init_size) {
32532 ++#ifdef CONFIG_PAX_KERNEXEC
32533 ++ pax_close_kernel(cr0);
32534 ++#endif
32535 ++
32536 ++ mod->module_core_rx = ptr;
32537 ++
32538 ++ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
32539 ++ if (!ptr && mod->init_size_rx) {
32540 + err = -ENOMEM;
32541 +- goto free_core;
32542 ++ goto free_core_rx;
32543 + }
32544 +- memset(ptr, 0, mod->init_size);
32545 +- mod->module_init = ptr;
32546 +
32547 ++#ifdef CONFIG_PAX_KERNEXEC
32548 ++ pax_open_kernel(cr0);
32549 ++#endif
32550 ++
32551 ++ memset(ptr, 0, mod->init_size_rx);
32552 ++
32553 ++#ifdef CONFIG_PAX_KERNEXEC
32554 ++ pax_close_kernel(cr0);
32555 ++#endif
32556 ++
32557 ++ mod->module_init_rx = ptr;
32558 + /* Transfer each section which specifies SHF_ALLOC */
32559 + DEBUGP("final section addresses:\n");
32560 + for (i = 0; i < hdr->e_shnum; i++) {
32561 +@@ -2022,17 +2143,41 @@ static noinline struct module *load_modu
32562 + if (!(sechdrs[i].sh_flags & SHF_ALLOC))
32563 + continue;
32564 +
32565 +- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
32566 +- dest = mod->module_init
32567 +- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32568 +- else
32569 +- dest = mod->module_core + sechdrs[i].sh_entsize;
32570 ++ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
32571 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32572 ++ dest = mod->module_init_rw
32573 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32574 ++ else
32575 ++ dest = mod->module_init_rx
32576 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32577 ++ } else {
32578 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32579 ++ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
32580 ++ else
32581 ++ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
32582 ++ }
32583 +
32584 +- if (sechdrs[i].sh_type != SHT_NOBITS)
32585 +- memcpy(dest, (void *)sechdrs[i].sh_addr,
32586 +- sechdrs[i].sh_size);
32587 ++ if (sechdrs[i].sh_type != SHT_NOBITS) {
32588 ++
32589 ++#ifdef CONFIG_PAX_KERNEXEC
32590 ++ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
32591 ++ pax_open_kernel(cr0);
32592 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32593 ++ pax_close_kernel(cr0);
32594 ++ } else
32595 ++#endif
32596 ++
32597 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32598 ++ }
32599 + /* Update sh_addr to point to copy in image. */
32600 +- sechdrs[i].sh_addr = (unsigned long)dest;
32601 ++
32602 ++#ifdef CONFIG_PAX_KERNEXEC
32603 ++ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
32604 ++ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
32605 ++ else
32606 ++#endif
32607 ++
32608 ++ sechdrs[i].sh_addr = (unsigned long)dest;
32609 + DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
32610 + }
32611 + /* Module has been moved. */
32612 +@@ -2120,8 +2265,8 @@ static noinline struct module *load_modu
32613 +
32614 + /* Now do relocations. */
32615 + for (i = 1; i < hdr->e_shnum; i++) {
32616 +- const char *strtab = (char *)sechdrs[strindex].sh_addr;
32617 + unsigned int info = sechdrs[i].sh_info;
32618 ++ strtab = (char *)sechdrs[strindex].sh_addr;
32619 +
32620 + /* Not a valid relocation section? */
32621 + if (info >= hdr->e_shnum)
32622 +@@ -2180,12 +2325,12 @@ static noinline struct module *load_modu
32623 + * Do it before processing of module parameters, so the module
32624 + * can provide parameter accessor functions of its own.
32625 + */
32626 +- if (mod->module_init)
32627 +- flush_icache_range((unsigned long)mod->module_init,
32628 +- (unsigned long)mod->module_init
32629 +- + mod->init_size);
32630 +- flush_icache_range((unsigned long)mod->module_core,
32631 +- (unsigned long)mod->module_core + mod->core_size);
32632 ++ if (mod->module_init_rx)
32633 ++ flush_icache_range((unsigned long)mod->module_init_rx,
32634 ++ (unsigned long)mod->module_init_rx
32635 ++ + mod->init_size_rx);
32636 ++ flush_icache_range((unsigned long)mod->module_core_rx,
32637 ++ (unsigned long)mod->module_core_rx + mod->core_size_rx);
32638 +
32639 + set_fs(old_fs);
32640 +
32641 +@@ -2238,9 +2383,13 @@ static noinline struct module *load_modu
32642 + kobject_put(&mod->mkobj.kobj);
32643 + free_unload:
32644 + module_unload_free(mod);
32645 +- module_free(mod, mod->module_init);
32646 +- free_core:
32647 +- module_free(mod, mod->module_core);
32648 ++ module_free_exec(mod, mod->module_init_rx);
32649 ++ free_core_rx:
32650 ++ module_free_exec(mod, mod->module_core_rx);
32651 ++ free_init_rw:
32652 ++ module_free(mod, mod->module_init_rw);
32653 ++ free_core_rw:
32654 ++ module_free(mod, mod->module_core_rw);
32655 + free_percpu:
32656 + if (percpu)
32657 + percpu_modfree(percpu);
32658 +@@ -2265,6 +2414,9 @@ sys_init_module(void __user *umod,
32659 + struct module *mod;
32660 + int ret = 0;
32661 +
32662 ++ if (gr_check_modstop())
32663 ++ return -EPERM;
32664 ++
32665 + /* Must have permission */
32666 + if (!capable(CAP_SYS_MODULE))
32667 + return -EPERM;
32668 +@@ -2320,10 +2472,12 @@ sys_init_module(void __user *umod,
32669 + /* Drop initial reference. */
32670 + module_put(mod);
32671 + unwind_remove_table(mod->unwind_info, 1);
32672 +- module_free(mod, mod->module_init);
32673 +- mod->module_init = NULL;
32674 +- mod->init_size = 0;
32675 +- mod->init_text_size = 0;
32676 ++ module_free(mod, mod->module_init_rw);
32677 ++ module_free_exec(mod, mod->module_init_rx);
32678 ++ mod->module_init_rw = NULL;
32679 ++ mod->module_init_rx = NULL;
32680 ++ mod->init_size_rw = 0;
32681 ++ mod->init_size_rx = 0;
32682 + mutex_unlock(&module_mutex);
32683 +
32684 + return 0;
32685 +@@ -2331,6 +2485,13 @@ sys_init_module(void __user *umod,
32686 +
32687 + static inline int within(unsigned long addr, void *start, unsigned long size)
32688 + {
32689 ++
32690 ++#ifdef CONFIG_PAX_KERNEXEC
32691 ++ if (ktla_ktva(addr) >= (unsigned long)start &&
32692 ++ ktla_ktva(addr) < (unsigned long)start + size)
32693 ++ return 1;
32694 ++#endif
32695 ++
32696 + return ((void *)addr >= start && (void *)addr < start + size);
32697 + }
32698 +
32699 +@@ -2354,10 +2515,14 @@ static const char *get_ksymbol(struct mo
32700 + unsigned long nextval;
32701 +
32702 + /* At worse, next value is at end of module */
32703 +- if (within(addr, mod->module_init, mod->init_size))
32704 +- nextval = (unsigned long)mod->module_init+mod->init_text_size;
32705 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx))
32706 ++ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
32707 ++ else if (within(addr, mod->module_init_rw, mod->init_size_rw))
32708 ++ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
32709 ++ else if (within(addr, mod->module_core_rx, mod->core_size_rx))
32710 ++ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
32711 + else
32712 +- nextval = (unsigned long)mod->module_core+mod->core_text_size;
32713 ++ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
32714 +
32715 + /* Scan for closest preceeding symbol, and next symbol. (ELF
32716 + starts real symbols at 1). */
32717 +@@ -2402,8 +2567,10 @@ const char *module_address_lookup(unsign
32718 +
32719 + preempt_disable();
32720 + list_for_each_entry(mod, &modules, list) {
32721 +- if (within(addr, mod->module_init, mod->init_size)
32722 +- || within(addr, mod->module_core, mod->core_size)) {
32723 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32724 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32725 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32726 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32727 + if (modname)
32728 + *modname = mod->name;
32729 + ret = get_ksymbol(mod, addr, size, offset);
32730 +@@ -2425,8 +2592,10 @@ int lookup_module_symbol_name(unsigned l
32731 +
32732 + preempt_disable();
32733 + list_for_each_entry(mod, &modules, list) {
32734 +- if (within(addr, mod->module_init, mod->init_size) ||
32735 +- within(addr, mod->module_core, mod->core_size)) {
32736 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32737 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32738 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32739 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32740 + const char *sym;
32741 +
32742 + sym = get_ksymbol(mod, addr, NULL, NULL);
32743 +@@ -2449,8 +2618,10 @@ int lookup_module_symbol_attrs(unsigned
32744 +
32745 + preempt_disable();
32746 + list_for_each_entry(mod, &modules, list) {
32747 +- if (within(addr, mod->module_init, mod->init_size) ||
32748 +- within(addr, mod->module_core, mod->core_size)) {
32749 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32750 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32751 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32752 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32753 + const char *sym;
32754 +
32755 + sym = get_ksymbol(mod, addr, size, offset);
32756 +@@ -2581,7 +2752,7 @@ static int m_show(struct seq_file *m, vo
32757 + char buf[8];
32758 +
32759 + seq_printf(m, "%s %u",
32760 +- mod->name, mod->init_size + mod->core_size);
32761 ++ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
32762 + print_unload_info(m, mod);
32763 +
32764 + /* Informative for users. */
32765 +@@ -2590,7 +2761,7 @@ static int m_show(struct seq_file *m, vo
32766 + mod->state == MODULE_STATE_COMING ? "Loading":
32767 + "Live");
32768 + /* Used by oprofile and other similar tools. */
32769 +- seq_printf(m, " 0x%p", mod->module_core);
32770 ++ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
32771 +
32772 + /* Taints info */
32773 + if (mod->taints)
32774 +@@ -2646,7 +2817,8 @@ int is_module_address(unsigned long addr
32775 + preempt_disable();
32776 +
32777 + list_for_each_entry(mod, &modules, list) {
32778 +- if (within(addr, mod->module_core, mod->core_size)) {
32779 ++ if (within(addr, mod->module_core_rx, mod->core_size_rx) ||
32780 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32781 + preempt_enable();
32782 + return 1;
32783 + }
32784 +@@ -2663,12 +2835,16 @@ struct module *__module_text_address(uns
32785 + {
32786 + struct module *mod;
32787 +
32788 +- if (addr < module_addr_min || addr > module_addr_max)
32789 ++#ifdef CONFIG_X86_32
32790 ++ addr = ktla_ktva(addr);
32791 ++#endif
32792 ++
32793 ++ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
32794 + return NULL;
32795 +
32796 + list_for_each_entry(mod, &modules, list)
32797 +- if (within(addr, mod->module_init, mod->init_text_size)
32798 +- || within(addr, mod->module_core, mod->core_text_size))
32799 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx)
32800 ++ || within(addr, mod->module_core_rx, mod->core_size_rx))
32801 + return mod;
32802 + return NULL;
32803 + }
32804 +diff -urNp linux-2.6.27.10/kernel/mutex.c linux-2.6.27.10/kernel/mutex.c
32805 +--- linux-2.6.27.10/kernel/mutex.c 2008-11-07 12:55:34.000000000 -0500
32806 ++++ linux-2.6.27.10/kernel/mutex.c 2008-11-18 03:38:45.000000000 -0500
32807 +@@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
32808 + *
32809 + * This function is similar to (but not equivalent to) down().
32810 + */
32811 +-void inline __sched mutex_lock(struct mutex *lock)
32812 ++inline void __sched mutex_lock(struct mutex *lock)
32813 + {
32814 + might_sleep();
32815 + /*
32816 +diff -urNp linux-2.6.27.10/kernel/panic.c linux-2.6.27.10/kernel/panic.c
32817 +--- linux-2.6.27.10/kernel/panic.c 2008-11-07 12:55:34.000000000 -0500
32818 ++++ linux-2.6.27.10/kernel/panic.c 2008-11-18 03:38:45.000000000 -0500
32819 +@@ -349,6 +349,8 @@ EXPORT_SYMBOL(warn_slowpath);
32820 + */
32821 + void __stack_chk_fail(void)
32822 + {
32823 ++ print_symbol("stack corrupted in: %s\n", (unsigned long)__builtin_return_address(0));
32824 ++ dump_stack();
32825 + panic("stack-protector: Kernel stack is corrupted");
32826 + }
32827 + EXPORT_SYMBOL(__stack_chk_fail);
32828 +diff -urNp linux-2.6.27.10/kernel/pid.c linux-2.6.27.10/kernel/pid.c
32829 +--- linux-2.6.27.10/kernel/pid.c 2008-11-07 12:55:34.000000000 -0500
32830 ++++ linux-2.6.27.10/kernel/pid.c 2008-11-18 03:38:45.000000000 -0500
32831 +@@ -36,6 +36,7 @@
32832 + #include <linux/pid_namespace.h>
32833 + #include <linux/init_task.h>
32834 + #include <linux/syscalls.h>
32835 ++#include <linux/grsecurity.h>
32836 +
32837 + #define pid_hashfn(nr, ns) \
32838 + hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
32839 +@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
32840 +
32841 + int pid_max = PID_MAX_DEFAULT;
32842 +
32843 +-#define RESERVED_PIDS 300
32844 ++#define RESERVED_PIDS 500
32845 +
32846 + int pid_max_min = RESERVED_PIDS + 1;
32847 + int pid_max_max = PID_MAX_LIMIT;
32848 +@@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task);
32849 + struct task_struct *find_task_by_pid_type_ns(int type, int nr,
32850 + struct pid_namespace *ns)
32851 + {
32852 +- return pid_task(find_pid_ns(nr, ns), type);
32853 ++ struct task_struct *task;
32854 ++
32855 ++ task = pid_task(find_pid_ns(nr, ns), type);
32856 ++
32857 ++ if (gr_pid_is_chrooted(task))
32858 ++ return NULL;
32859 ++
32860 ++ return task;
32861 + }
32862 +
32863 + EXPORT_SYMBOL(find_task_by_pid_type_ns);
32864 +diff -urNp linux-2.6.27.10/kernel/posix-cpu-timers.c linux-2.6.27.10/kernel/posix-cpu-timers.c
32865 +--- linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-07 12:55:34.000000000 -0500
32866 ++++ linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-18 03:38:45.000000000 -0500
32867 +@@ -6,6 +6,7 @@
32868 + #include <linux/posix-timers.h>
32869 + #include <linux/errno.h>
32870 + #include <linux/math64.h>
32871 ++#include <linux/grsecurity.h>
32872 + #include <asm/uaccess.h>
32873 +
32874 + static int check_clock(const clockid_t which_clock)
32875 +@@ -1176,6 +1177,7 @@ static void check_process_timers(struct
32876 + __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
32877 + return;
32878 + }
32879 ++ gr_learn_resource(tsk, RLIMIT_CPU, psecs, 1);
32880 + if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
32881 + /*
32882 + * At the soft limit, send a SIGXCPU every second.
32883 +@@ -1370,17 +1372,17 @@ void run_posix_cpu_timers(struct task_st
32884 + * timer call will interfere.
32885 + */
32886 + list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
32887 +- int firing;
32888 ++ int __firing;
32889 + spin_lock(&timer->it_lock);
32890 + list_del_init(&timer->it.cpu.entry);
32891 +- firing = timer->it.cpu.firing;
32892 ++ __firing = timer->it.cpu.firing;
32893 + timer->it.cpu.firing = 0;
32894 + /*
32895 + * The firing flag is -1 if we collided with a reset
32896 + * of the timer, which already reported this
32897 + * almost-firing as an overrun. So don't generate an event.
32898 + */
32899 +- if (likely(firing >= 0)) {
32900 ++ if (likely(__firing >= 0)) {
32901 + cpu_timer_fire(timer);
32902 + }
32903 + spin_unlock(&timer->it_lock);
32904 +diff -urNp linux-2.6.27.10/kernel/power/poweroff.c linux-2.6.27.10/kernel/power/poweroff.c
32905 +--- linux-2.6.27.10/kernel/power/poweroff.c 2008-11-07 12:55:34.000000000 -0500
32906 ++++ linux-2.6.27.10/kernel/power/poweroff.c 2008-11-18 03:38:45.000000000 -0500
32907 +@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
32908 + .enable_mask = SYSRQ_ENABLE_BOOT,
32909 + };
32910 +
32911 +-static int pm_sysrq_init(void)
32912 ++static int __init pm_sysrq_init(void)
32913 + {
32914 + register_sysrq_key('o', &sysrq_poweroff_op);
32915 + return 0;
32916 +diff -urNp linux-2.6.27.10/kernel/printk.c linux-2.6.27.10/kernel/printk.c
32917 +--- linux-2.6.27.10/kernel/printk.c 2008-11-07 12:55:34.000000000 -0500
32918 ++++ linux-2.6.27.10/kernel/printk.c 2008-11-18 03:38:45.000000000 -0500
32919 +@@ -32,6 +32,7 @@
32920 + #include <linux/security.h>
32921 + #include <linux/bootmem.h>
32922 + #include <linux/syscalls.h>
32923 ++#include <linux/grsecurity.h>
32924 +
32925 + #include <asm/uaccess.h>
32926 +
32927 +@@ -293,6 +294,11 @@ int do_syslog(int type, char __user *buf
32928 + char c;
32929 + int error = 0;
32930 +
32931 ++#ifdef CONFIG_GRKERNSEC_DMESG
32932 ++ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
32933 ++ return -EPERM;
32934 ++#endif
32935 ++
32936 + error = security_syslog(type);
32937 + if (error)
32938 + return error;
32939 +diff -urNp linux-2.6.27.10/kernel/ptrace.c linux-2.6.27.10/kernel/ptrace.c
32940 +--- linux-2.6.27.10/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
32941 ++++ linux-2.6.27.10/kernel/ptrace.c 2008-11-18 03:38:45.000000000 -0500
32942 +@@ -21,6 +21,7 @@
32943 + #include <linux/audit.h>
32944 + #include <linux/pid_namespace.h>
32945 + #include <linux/syscalls.h>
32946 ++#include <linux/grsecurity.h>
32947 +
32948 + #include <asm/pgtable.h>
32949 + #include <asm/uaccess.h>
32950 +@@ -132,12 +133,12 @@ int __ptrace_may_access(struct task_stru
32951 + (current->uid != task->uid) ||
32952 + (current->gid != task->egid) ||
32953 + (current->gid != task->sgid) ||
32954 +- (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
32955 ++ (current->gid != task->gid)) && !capable_nolog(CAP_SYS_PTRACE))
32956 + return -EPERM;
32957 + smp_rmb();
32958 + if (task->mm)
32959 + dumpable = get_dumpable(task->mm);
32960 +- if (!dumpable && !capable(CAP_SYS_PTRACE))
32961 ++ if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
32962 + return -EPERM;
32963 +
32964 + return security_ptrace_may_access(task, mode);
32965 +@@ -193,7 +194,7 @@ repeat:
32966 +
32967 + /* Go */
32968 + task->ptrace |= PT_PTRACED;
32969 +- if (capable(CAP_SYS_PTRACE))
32970 ++ if (capable_nolog(CAP_SYS_PTRACE))
32971 + task->ptrace |= PT_PTRACE_CAP;
32972 +
32973 + __ptrace_link(task, current);
32974 +@@ -582,6 +583,11 @@ asmlinkage long sys_ptrace(long request,
32975 + if (ret < 0)
32976 + goto out_put_task_struct;
32977 +
32978 ++ if (gr_handle_ptrace(child, request)) {
32979 ++ ret = -EPERM;
32980 ++ goto out_put_task_struct;
32981 ++ }
32982 ++
32983 + ret = arch_ptrace(child, request, addr, data);
32984 + if (ret < 0)
32985 + goto out_put_task_struct;
32986 +diff -urNp linux-2.6.27.10/kernel/relay.c linux-2.6.27.10/kernel/relay.c
32987 +--- linux-2.6.27.10/kernel/relay.c 2008-11-07 12:55:34.000000000 -0500
32988 ++++ linux-2.6.27.10/kernel/relay.c 2008-11-18 03:38:45.000000000 -0500
32989 +@@ -1291,7 +1291,7 @@ static int subbuf_splice_actor(struct fi
32990 + return 0;
32991 +
32992 + ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
32993 +- if (ret < 0 || ret < total_len)
32994 ++ if ((int)ret < 0 || ret < total_len)
32995 + return ret;
32996 +
32997 + if (read_start + ret == nonpad_end)
32998 +diff -urNp linux-2.6.27.10/kernel/resource.c linux-2.6.27.10/kernel/resource.c
32999 +--- linux-2.6.27.10/kernel/resource.c 2008-11-07 12:55:34.000000000 -0500
33000 ++++ linux-2.6.27.10/kernel/resource.c 2008-11-18 03:38:45.000000000 -0500
33001 +@@ -131,8 +131,18 @@ static const struct file_operations proc
33002 +
33003 + static int __init ioresources_init(void)
33004 + {
33005 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
33006 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
33007 ++ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
33008 ++ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
33009 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33010 ++ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
33011 ++ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
33012 ++#endif
33013 ++#else
33014 + proc_create("ioports", 0, NULL, &proc_ioports_operations);
33015 + proc_create("iomem", 0, NULL, &proc_iomem_operations);
33016 ++#endif
33017 + return 0;
33018 + }
33019 + __initcall(ioresources_init);
33020 +diff -urNp linux-2.6.27.10/kernel/sched.c linux-2.6.27.10/kernel/sched.c
33021 +--- linux-2.6.27.10/kernel/sched.c 2008-12-21 01:16:52.000000000 -0500
33022 ++++ linux-2.6.27.10/kernel/sched.c 2008-12-21 01:13:46.000000000 -0500
33023 +@@ -71,6 +71,7 @@
33024 + #include <linux/debugfs.h>
33025 + #include <linux/ctype.h>
33026 + #include <linux/ftrace.h>
33027 ++#include <linux/grsecurity.h>
33028 +
33029 + #include <asm/tlb.h>
33030 + #include <asm/irq_regs.h>
33031 +@@ -4962,7 +4963,8 @@ asmlinkage long sys_nice(int increment)
33032 + if (nice > 19)
33033 + nice = 19;
33034 +
33035 +- if (increment < 0 && !can_nice(current, nice))
33036 ++ if (increment < 0 && (!can_nice(current, nice) ||
33037 ++ gr_handle_chroot_nice()))
33038 + return -EPERM;
33039 +
33040 + retval = security_task_setnice(current, nice);
33041 +@@ -6225,7 +6227,7 @@ static struct ctl_table sd_ctl_dir[] = {
33042 + .procname = "sched_domain",
33043 + .mode = 0555,
33044 + },
33045 +- {0, },
33046 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33047 + };
33048 +
33049 + static struct ctl_table sd_ctl_root[] = {
33050 +@@ -6235,7 +6237,7 @@ static struct ctl_table sd_ctl_root[] =
33051 + .mode = 0555,
33052 + .child = sd_ctl_dir,
33053 + },
33054 +- {0, },
33055 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33056 + };
33057 +
33058 + static struct ctl_table *sd_alloc_ctl_entry(int n)
33059 +diff -urNp linux-2.6.27.10/kernel/signal.c linux-2.6.27.10/kernel/signal.c
33060 +--- linux-2.6.27.10/kernel/signal.c 2008-11-07 12:55:34.000000000 -0500
33061 ++++ linux-2.6.27.10/kernel/signal.c 2008-11-18 03:38:45.000000000 -0500
33062 +@@ -26,6 +26,7 @@
33063 + #include <linux/capability.h>
33064 + #include <linux/freezer.h>
33065 + #include <linux/pid_namespace.h>
33066 ++#include <linux/grsecurity.h>
33067 + #include <linux/nsproxy.h>
33068 +
33069 + #include <asm/param.h>
33070 +@@ -595,6 +596,9 @@ static int check_kill_permission(int sig
33071 + }
33072 + }
33073 +
33074 ++ if (gr_handle_signal(t, sig))
33075 ++ return -EPERM;
33076 ++
33077 + return security_task_kill(t, info, sig, 0);
33078 + }
33079 +
33080 +@@ -884,8 +888,8 @@ static void print_fatal_signal(struct pt
33081 + for (i = 0; i < 16; i++) {
33082 + unsigned char insn;
33083 +
33084 +- __get_user(insn, (unsigned char *)(regs->ip + i));
33085 +- printk("%02x ", insn);
33086 ++ if (!get_user(insn, (unsigned char __user *)(regs->ip + i)))
33087 ++ printk("%02x ", insn);
33088 + }
33089 + }
33090 + #endif
33091 +@@ -908,7 +912,7 @@ __group_send_sig_info(int sig, struct si
33092 + return send_signal(sig, info, p, 1);
33093 + }
33094 +
33095 +-static int
33096 ++int
33097 + specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
33098 + {
33099 + return send_signal(sig, info, t, 0);
33100 +@@ -946,8 +950,12 @@ force_sig_info(int sig, struct siginfo *
33101 + if (action->sa.sa_handler == SIG_DFL)
33102 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
33103 + ret = specific_send_sig_info(sig, info, t);
33104 ++
33105 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
33106 +
33107 ++ gr_log_signal(sig, t);
33108 ++ gr_handle_crash(t, sig);
33109 ++
33110 + return ret;
33111 + }
33112 +
33113 +@@ -1018,6 +1026,8 @@ int group_send_sig_info(int sig, struct
33114 + ret = __group_send_sig_info(sig, info, p);
33115 + unlock_task_sighand(p, &flags);
33116 + }
33117 ++ if (!ret)
33118 ++ gr_log_signal(sig, p);
33119 + }
33120 +
33121 + return ret;
33122 +diff -urNp linux-2.6.27.10/kernel/softirq.c linux-2.6.27.10/kernel/softirq.c
33123 +--- linux-2.6.27.10/kernel/softirq.c 2008-11-07 12:55:34.000000000 -0500
33124 ++++ linux-2.6.27.10/kernel/softirq.c 2008-11-18 03:38:45.000000000 -0500
33125 +@@ -453,9 +453,9 @@ void tasklet_kill(struct tasklet_struct
33126 + printk("Attempt to kill tasklet from interrupt\n");
33127 +
33128 + while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
33129 +- do
33130 ++ do {
33131 + yield();
33132 +- while (test_bit(TASKLET_STATE_SCHED, &t->state));
33133 ++ } while (test_bit(TASKLET_STATE_SCHED, &t->state));
33134 + }
33135 + tasklet_unlock_wait(t);
33136 + clear_bit(TASKLET_STATE_SCHED, &t->state);
33137 +diff -urNp linux-2.6.27.10/kernel/sys.c linux-2.6.27.10/kernel/sys.c
33138 +--- linux-2.6.27.10/kernel/sys.c 2008-11-07 12:55:34.000000000 -0500
33139 ++++ linux-2.6.27.10/kernel/sys.c 2008-11-18 03:38:45.000000000 -0500
33140 +@@ -33,6 +33,7 @@
33141 + #include <linux/task_io_accounting_ops.h>
33142 + #include <linux/seccomp.h>
33143 + #include <linux/cpu.h>
33144 ++#include <linux/grsecurity.h>
33145 +
33146 + #include <linux/compat.h>
33147 + #include <linux/syscalls.h>
33148 +@@ -125,6 +126,12 @@ static int set_one_prio(struct task_stru
33149 + error = -EACCES;
33150 + goto out;
33151 + }
33152 ++
33153 ++ if (gr_handle_chroot_setpriority(p, niceval)) {
33154 ++ error = -EACCES;
33155 ++ goto out;
33156 ++ }
33157 ++
33158 + no_nice = security_task_setnice(p, niceval);
33159 + if (no_nice) {
33160 + error = no_nice;
33161 +@@ -181,10 +188,10 @@ asmlinkage long sys_setpriority(int whic
33162 + if ((who != current->uid) && !(user = find_user(who)))
33163 + goto out_unlock; /* No processes for this user */
33164 +
33165 +- do_each_thread(g, p)
33166 ++ do_each_thread(g, p) {
33167 + if (p->uid == who)
33168 + error = set_one_prio(p, niceval, error);
33169 +- while_each_thread(g, p);
33170 ++ } while_each_thread(g, p);
33171 + if (who != current->uid)
33172 + free_uid(user); /* For find_user() */
33173 + break;
33174 +@@ -243,13 +250,13 @@ asmlinkage long sys_getpriority(int whic
33175 + if ((who != current->uid) && !(user = find_user(who)))
33176 + goto out_unlock; /* No processes for this user */
33177 +
33178 +- do_each_thread(g, p)
33179 ++ do_each_thread(g, p) {
33180 + if (p->uid == who) {
33181 + niceval = 20 - task_nice(p);
33182 + if (niceval > retval)
33183 + retval = niceval;
33184 + }
33185 +- while_each_thread(g, p);
33186 ++ } while_each_thread(g, p);
33187 + if (who != current->uid)
33188 + free_uid(user); /* for find_user() */
33189 + break;
33190 +@@ -499,6 +506,10 @@ asmlinkage long sys_setregid(gid_t rgid,
33191 + else
33192 + return -EPERM;
33193 + }
33194 ++
33195 ++ if (gr_check_group_change(new_rgid, new_egid, -1))
33196 ++ return -EPERM;
33197 ++
33198 + if (new_egid != old_egid) {
33199 + set_dumpable(current->mm, suid_dumpable);
33200 + smp_wmb();
33201 +@@ -506,6 +517,9 @@ asmlinkage long sys_setregid(gid_t rgid,
33202 + if (rgid != (gid_t) -1 ||
33203 + (egid != (gid_t) -1 && egid != old_rgid))
33204 + current->sgid = new_egid;
33205 ++
33206 ++ gr_set_role_label(current, current->uid, new_rgid);
33207 ++
33208 + current->fsgid = new_egid;
33209 + current->egid = new_egid;
33210 + current->gid = new_rgid;
33211 +@@ -528,11 +542,17 @@ asmlinkage long sys_setgid(gid_t gid)
33212 + if (retval)
33213 + return retval;
33214 +
33215 ++ if (gr_check_group_change(gid, gid, gid))
33216 ++ return -EPERM;
33217 ++
33218 + if (capable(CAP_SETGID)) {
33219 + if (old_egid != gid) {
33220 + set_dumpable(current->mm, suid_dumpable);
33221 + smp_wmb();
33222 + }
33223 ++
33224 ++ gr_set_role_label(current, current->uid, gid);
33225 ++
33226 + current->gid = current->egid = current->sgid = current->fsgid = gid;
33227 + } else if ((gid == current->gid) || (gid == current->sgid)) {
33228 + if (old_egid != gid) {
33229 +@@ -570,6 +590,9 @@ static int set_user(uid_t new_ruid, int
33230 + set_dumpable(current->mm, suid_dumpable);
33231 + smp_wmb();
33232 + }
33233 ++
33234 ++ gr_set_role_label(current, new_ruid, current->gid);
33235 ++
33236 + current->uid = new_ruid;
33237 + return 0;
33238 + }
33239 +@@ -619,6 +642,9 @@ asmlinkage long sys_setreuid(uid_t ruid,
33240 + return -EPERM;
33241 + }
33242 +
33243 ++ if (gr_check_user_change(new_ruid, new_euid, -1))
33244 ++ return -EPERM;
33245 ++
33246 + if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
33247 + return -EAGAIN;
33248 +
33249 +@@ -665,6 +691,12 @@ asmlinkage long sys_setuid(uid_t uid)
33250 + old_suid = current->suid;
33251 + new_suid = old_suid;
33252 +
33253 ++ if (gr_check_crash_uid(uid))
33254 ++ return -EPERM;
33255 ++
33256 ++ if (gr_check_user_change(uid, uid, uid))
33257 ++ return -EPERM;
33258 ++
33259 + if (capable(CAP_SETUID)) {
33260 + if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
33261 + return -EAGAIN;
33262 +@@ -712,6 +744,10 @@ asmlinkage long sys_setresuid(uid_t ruid
33263 + (suid != current->euid) && (suid != current->suid))
33264 + return -EPERM;
33265 + }
33266 ++
33267 ++ if (gr_check_user_change(ruid, euid, -1))
33268 ++ return -EPERM;
33269 ++
33270 + if (ruid != (uid_t) -1) {
33271 + if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
33272 + return -EAGAIN;
33273 +@@ -766,6 +802,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33274 + (sgid != current->egid) && (sgid != current->sgid))
33275 + return -EPERM;
33276 + }
33277 ++
33278 ++ if (gr_check_group_change(rgid, egid, -1))
33279 ++ return -EPERM;
33280 ++
33281 + if (egid != (gid_t) -1) {
33282 + if (egid != current->egid) {
33283 + set_dumpable(current->mm, suid_dumpable);
33284 +@@ -774,8 +814,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33285 + current->egid = egid;
33286 + }
33287 + current->fsgid = current->egid;
33288 +- if (rgid != (gid_t) -1)
33289 ++ if (rgid != (gid_t) -1) {
33290 ++ gr_set_role_label(current, current->uid, rgid);
33291 + current->gid = rgid;
33292 ++ }
33293 + if (sgid != (gid_t) -1)
33294 + current->sgid = sgid;
33295 +
33296 +@@ -810,6 +852,9 @@ asmlinkage long sys_setfsuid(uid_t uid)
33297 + if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
33298 + return old_fsuid;
33299 +
33300 ++ if (gr_check_user_change(-1, -1, uid))
33301 ++ return old_fsuid;
33302 ++
33303 + if (uid == current->uid || uid == current->euid ||
33304 + uid == current->suid || uid == current->fsuid ||
33305 + capable(CAP_SETUID)) {
33306 +@@ -842,6 +887,9 @@ asmlinkage long sys_setfsgid(gid_t gid)
33307 + if (gid == current->gid || gid == current->egid ||
33308 + gid == current->sgid || gid == current->fsgid ||
33309 + capable(CAP_SETGID)) {
33310 ++ if (gr_check_group_change(-1, -1, gid))
33311 ++ return old_fsgid;
33312 ++
33313 + if (gid != old_fsgid) {
33314 + set_dumpable(current->mm, suid_dumpable);
33315 + smp_wmb();
33316 +@@ -923,7 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, p
33317 + write_lock_irq(&tasklist_lock);
33318 +
33319 + err = -ESRCH;
33320 +- p = find_task_by_vpid(pid);
33321 ++ /* grsec: replaced find_task_by_vpid with equivalent call which
33322 ++ lacks the chroot restriction
33323 ++ */
33324 ++ p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID);
33325 + if (!p)
33326 + goto out;
33327 +
33328 +@@ -1655,7 +1706,7 @@ asmlinkage long sys_prctl(int option, un
33329 + error = get_dumpable(current->mm);
33330 + break;
33331 + case PR_SET_DUMPABLE:
33332 +- if (arg2 < 0 || arg2 > 1) {
33333 ++ if (arg2 > 1) {
33334 + error = -EINVAL;
33335 + break;
33336 + }
33337 +diff -urNp linux-2.6.27.10/kernel/sysctl.c linux-2.6.27.10/kernel/sysctl.c
33338 +--- linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:38.000000000 -0500
33339 ++++ linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:46.000000000 -0500
33340 +@@ -61,6 +61,13 @@
33341 + static int deprecated_sysctl_warning(struct __sysctl_args *args);
33342 +
33343 + #if defined(CONFIG_SYSCTL)
33344 ++#include <linux/grsecurity.h>
33345 ++#include <linux/grinternal.h>
33346 ++
33347 ++extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
33348 ++extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
33349 ++ const int op);
33350 ++extern int gr_handle_chroot_sysctl(const int op);
33351 +
33352 + /* External variables not in a header file. */
33353 + extern int C_A_D;
33354 +@@ -155,6 +162,7 @@ static int proc_do_cad_pid(struct ctl_ta
33355 + static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
33356 + void __user *buffer, size_t *lenp, loff_t *ppos);
33357 + #endif
33358 ++extern ctl_table grsecurity_table[];
33359 +
33360 + static struct ctl_table root_table[];
33361 + static struct ctl_table_root sysctl_table_root;
33362 +@@ -187,6 +195,21 @@ extern struct ctl_table epoll_table[];
33363 + int sysctl_legacy_va_layout;
33364 + #endif
33365 +
33366 ++#ifdef CONFIG_PAX_SOFTMODE
33367 ++static ctl_table pax_table[] = {
33368 ++ {
33369 ++ .ctl_name = CTL_UNNUMBERED,
33370 ++ .procname = "softmode",
33371 ++ .data = &pax_softmode,
33372 ++ .maxlen = sizeof(unsigned int),
33373 ++ .mode = 0600,
33374 ++ .proc_handler = &proc_dointvec,
33375 ++ },
33376 ++
33377 ++ { .ctl_name = 0 }
33378 ++};
33379 ++#endif
33380 ++
33381 + extern int prove_locking;
33382 + extern int lock_stat;
33383 +
33384 +@@ -223,6 +246,7 @@ static struct ctl_table root_table[] = {
33385 + .mode = 0555,
33386 + .child = dev_table,
33387 + },
33388 ++
33389 + /*
33390 + * NOTE: do not add new entries to this table unless you have read
33391 + * Documentation/sysctl/ctl_unnumbered.txt
33392 +@@ -850,6 +874,25 @@ static struct ctl_table kern_table[] = {
33393 + .proc_handler = &proc_dointvec,
33394 + },
33395 + #endif
33396 ++
33397 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
33398 ++ {
33399 ++ .ctl_name = CTL_UNNUMBERED,
33400 ++ .procname = "grsecurity",
33401 ++ .mode = 0500,
33402 ++ .child = grsecurity_table,
33403 ++ },
33404 ++#endif
33405 ++
33406 ++#ifdef CONFIG_PAX_SOFTMODE
33407 ++ {
33408 ++ .ctl_name = CTL_UNNUMBERED,
33409 ++ .procname = "pax",
33410 ++ .mode = 0500,
33411 ++ .child = pax_table,
33412 ++ },
33413 ++#endif
33414 ++
33415 + /*
33416 + * NOTE: do not add new entries to this table unless you have read
33417 + * Documentation/sysctl/ctl_unnumbered.txt
33418 +@@ -1179,6 +1222,7 @@ static struct ctl_table vm_table[] = {
33419 + .extra2 = &one,
33420 + },
33421 + #endif
33422 ++
33423 + /*
33424 + * NOTE: do not add new entries to this table unless you have read
33425 + * Documentation/sysctl/ctl_unnumbered.txt
33426 +@@ -1553,6 +1597,8 @@ static int do_sysctl_strategy(struct ctl
33427 + return 0;
33428 + }
33429 +
33430 ++static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
33431 ++
33432 + static int parse_table(int __user *name, int nlen,
33433 + void __user *oldval, size_t __user *oldlenp,
33434 + void __user *newval, size_t newlen,
33435 +@@ -1571,7 +1617,7 @@ repeat:
33436 + if (n == table->ctl_name) {
33437 + int error;
33438 + if (table->child) {
33439 +- if (sysctl_perm(root, table, MAY_EXEC))
33440 ++ if (sysctl_perm_nochk(root, table, MAY_EXEC))
33441 + return -EPERM;
33442 + name++;
33443 + nlen--;
33444 +@@ -1656,6 +1702,33 @@ int sysctl_perm(struct ctl_table_root *r
33445 + int error;
33446 + int mode;
33447 +
33448 ++ if (table->parent != NULL && table->parent->procname != NULL &&
33449 ++ table->procname != NULL &&
33450 ++ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
33451 ++ return -EACCES;
33452 ++ if (gr_handle_chroot_sysctl(op))
33453 ++ return -EACCES;
33454 ++ error = gr_handle_sysctl(table, op);
33455 ++ if (error)
33456 ++ return error;
33457 ++
33458 ++ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33459 ++ if (error)
33460 ++ return error;
33461 ++
33462 ++ if (root->permissions)
33463 ++ mode = root->permissions(root, current->nsproxy, table);
33464 ++ else
33465 ++ mode = table->mode;
33466 ++
33467 ++ return test_perm(mode, op);
33468 ++}
33469 ++
33470 ++int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
33471 ++{
33472 ++ int error;
33473 ++ int mode;
33474 ++
33475 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33476 + if (error)
33477 + return error;
33478 +diff -urNp linux-2.6.27.10/kernel/time/tick-broadcast.c linux-2.6.27.10/kernel/time/tick-broadcast.c
33479 +--- linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-07 12:55:34.000000000 -0500
33480 ++++ linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-18 03:38:45.000000000 -0500
33481 +@@ -114,7 +114,7 @@ int tick_device_uses_broadcast(struct cl
33482 + * then clear the broadcast bit.
33483 + */
33484 + if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
33485 +- int cpu = smp_processor_id();
33486 ++ cpu = smp_processor_id();
33487 +
33488 + cpu_clear(cpu, tick_broadcast_mask);
33489 + tick_broadcast_clear_oneshot(cpu);
33490 +diff -urNp linux-2.6.27.10/kernel/time.c linux-2.6.27.10/kernel/time.c
33491 +--- linux-2.6.27.10/kernel/time.c 2008-11-07 12:55:34.000000000 -0500
33492 ++++ linux-2.6.27.10/kernel/time.c 2008-11-18 03:38:45.000000000 -0500
33493 +@@ -37,6 +37,7 @@
33494 + #include <linux/fs.h>
33495 + #include <linux/slab.h>
33496 + #include <linux/math64.h>
33497 ++#include <linux/grsecurity.h>
33498 +
33499 + #include <asm/uaccess.h>
33500 + #include <asm/unistd.h>
33501 +@@ -92,6 +93,9 @@ asmlinkage long sys_stime(time_t __user
33502 + return err;
33503 +
33504 + do_settimeofday(&tv);
33505 ++
33506 ++ gr_log_timechange();
33507 ++
33508 + return 0;
33509 + }
33510 +
33511 +@@ -200,6 +204,8 @@ asmlinkage long sys_settimeofday(struct
33512 + return -EFAULT;
33513 + }
33514 +
33515 ++ gr_log_timechange();
33516 ++
33517 + return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
33518 + }
33519 +
33520 +@@ -238,7 +244,7 @@ EXPORT_SYMBOL(current_fs_time);
33521 + * Avoid unnecessary multiplications/divisions in the
33522 + * two most common HZ cases:
33523 + */
33524 +-unsigned int inline jiffies_to_msecs(const unsigned long j)
33525 ++inline unsigned int jiffies_to_msecs(const unsigned long j)
33526 + {
33527 + #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
33528 + return (MSEC_PER_SEC / HZ) * j;
33529 +@@ -254,7 +260,7 @@ unsigned int inline jiffies_to_msecs(con
33530 + }
33531 + EXPORT_SYMBOL(jiffies_to_msecs);
33532 +
33533 +-unsigned int inline jiffies_to_usecs(const unsigned long j)
33534 ++inline unsigned int jiffies_to_usecs(const unsigned long j)
33535 + {
33536 + #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
33537 + return (USEC_PER_SEC / HZ) * j;
33538 +diff -urNp linux-2.6.27.10/kernel/utsname_sysctl.c linux-2.6.27.10/kernel/utsname_sysctl.c
33539 +--- linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-07 12:55:34.000000000 -0500
33540 ++++ linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-18 03:38:45.000000000 -0500
33541 +@@ -124,7 +124,7 @@ static struct ctl_table uts_kern_table[]
33542 + .proc_handler = proc_do_uts_string,
33543 + .strategy = sysctl_uts_string,
33544 + },
33545 +- {}
33546 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33547 + };
33548 +
33549 + static struct ctl_table uts_root_table[] = {
33550 +@@ -134,7 +134,7 @@ static struct ctl_table uts_root_table[]
33551 + .mode = 0555,
33552 + .child = uts_kern_table,
33553 + },
33554 +- {}
33555 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33556 + };
33557 +
33558 + static int __init utsname_sysctl_init(void)
33559 +diff -urNp linux-2.6.27.10/lib/radix-tree.c linux-2.6.27.10/lib/radix-tree.c
33560 +--- linux-2.6.27.10/lib/radix-tree.c 2008-11-07 12:55:34.000000000 -0500
33561 ++++ linux-2.6.27.10/lib/radix-tree.c 2008-11-18 03:38:45.000000000 -0500
33562 +@@ -81,7 +81,7 @@ struct radix_tree_preload {
33563 + int nr;
33564 + struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
33565 + };
33566 +-DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
33567 ++DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
33568 +
33569 + static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
33570 + {
33571 +diff -urNp linux-2.6.27.10/localversion-grsec linux-2.6.27.10/localversion-grsec
33572 +--- linux-2.6.27.10/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
33573 ++++ linux-2.6.27.10/localversion-grsec 2008-11-18 03:38:45.000000000 -0500
33574 +@@ -0,0 +1 @@
33575 ++-grsec
33576 +diff -urNp linux-2.6.27.10/Makefile linux-2.6.27.10/Makefile
33577 +--- linux-2.6.27.10/Makefile 2008-12-21 01:18:11.000000000 -0500
33578 ++++ linux-2.6.27.10/Makefile 2008-12-21 01:18:21.000000000 -0500
33579 +@@ -221,7 +221,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
33580 +
33581 + HOSTCC = gcc
33582 + HOSTCXX = g++
33583 +-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
33584 ++HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
33585 + HOSTCXXFLAGS = -O2
33586 +
33587 + # Decide whether to build built-in, modular, or both.
33588 +@@ -619,7 +619,7 @@ export mod_strip_cmd
33589 +
33590 +
33591 + ifeq ($(KBUILD_EXTMOD),)
33592 +-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
33593 ++core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
33594 +
33595 + vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
33596 + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
33597 +diff -urNp linux-2.6.27.10/mm/filemap.c linux-2.6.27.10/mm/filemap.c
33598 +--- linux-2.6.27.10/mm/filemap.c 2008-11-07 12:55:34.000000000 -0500
33599 ++++ linux-2.6.27.10/mm/filemap.c 2008-11-18 03:38:45.000000000 -0500
33600 +@@ -33,6 +33,7 @@
33601 + #include <linux/cpuset.h>
33602 + #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
33603 + #include <linux/memcontrol.h>
33604 ++#include <linux/grsecurity.h>
33605 + #include "internal.h"
33606 +
33607 + /*
33608 +@@ -1588,7 +1589,7 @@ int generic_file_mmap(struct file * file
33609 + struct address_space *mapping = file->f_mapping;
33610 +
33611 + if (!mapping->a_ops->readpage)
33612 +- return -ENOEXEC;
33613 ++ return -ENODEV;
33614 + file_accessed(file);
33615 + vma->vm_ops = &generic_file_vm_ops;
33616 + vma->vm_flags |= VM_CAN_NONLINEAR;
33617 +@@ -1949,6 +1950,7 @@ inline int generic_write_checks(struct f
33618 + *pos = i_size_read(inode);
33619 +
33620 + if (limit != RLIM_INFINITY) {
33621 ++ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
33622 + if (*pos >= limit) {
33623 + send_sig(SIGXFSZ, current, 0);
33624 + return -EFBIG;
33625 +diff -urNp linux-2.6.27.10/mm/fremap.c linux-2.6.27.10/mm/fremap.c
33626 +--- linux-2.6.27.10/mm/fremap.c 2008-11-07 12:55:34.000000000 -0500
33627 ++++ linux-2.6.27.10/mm/fremap.c 2008-11-18 03:38:45.000000000 -0500
33628 +@@ -151,6 +151,13 @@ asmlinkage long sys_remap_file_pages(uns
33629 + retry:
33630 + vma = find_vma(mm, start);
33631 +
33632 ++#ifdef CONFIG_PAX_SEGMEXEC
33633 ++ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) {
33634 ++ up_read(&mm->mmap_sem);
33635 ++ return err;
33636 ++ }
33637 ++#endif
33638 ++
33639 + /*
33640 + * Make sure the vma is shared, that it supports prefaulting,
33641 + * and that the remapped range is valid and fully within
33642 +diff -urNp linux-2.6.27.10/mm/hugetlb.c linux-2.6.27.10/mm/hugetlb.c
33643 +--- linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:38:40.000000000 -0500
33644 ++++ linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:40:53.000000000 -0500
33645 +@@ -1833,6 +1833,26 @@ int unmap_ref_private(struct mm_struct *
33646 + return 1;
33647 + }
33648 +
33649 ++#ifdef CONFIG_PAX_SEGMEXEC
33650 ++static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
33651 ++{
33652 ++ struct mm_struct *mm = vma->vm_mm;
33653 ++ struct vm_area_struct *vma_m;
33654 ++ unsigned long address_m;
33655 ++ pte_t *ptep_m;
33656 ++
33657 ++ vma_m = pax_find_mirror_vma(vma);
33658 ++ if (!vma_m)
33659 ++ return;
33660 ++
33661 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33662 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33663 ++ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
33664 ++ get_page(page_m);
33665 ++ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
33666 ++}
33667 ++#endif
33668 ++
33669 + static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
33670 + unsigned long address, pte_t *ptep, pte_t pte,
33671 + struct page *pagecache_page)
33672 +@@ -1904,6 +1924,11 @@ retry_avoidcopy:
33673 + huge_ptep_clear_flush(vma, address, ptep);
33674 + set_huge_pte_at(mm, address, ptep,
33675 + make_huge_pte(vma, new_page, 1));
33676 ++
33677 ++#ifdef CONFIG_PAX_SEGMEXEC
33678 ++ pax_mirror_huge_pte(vma, address, new_page);
33679 ++#endif
33680 ++
33681 + /* Make the old page be freed below */
33682 + new_page = old_page;
33683 + }
33684 +@@ -2013,6 +2038,10 @@ retry:
33685 + && (vma->vm_flags & VM_SHARED)));
33686 + set_huge_pte_at(mm, address, ptep, new_pte);
33687 +
33688 ++#ifdef CONFIG_PAX_SEGMEXEC
33689 ++ pax_mirror_huge_pte(vma, address, page);
33690 ++#endif
33691 ++
33692 + if (write_access && !(vma->vm_flags & VM_SHARED)) {
33693 + /* Optimization, do the COW without a second fault */
33694 + ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
33695 +@@ -2041,6 +2070,28 @@ int hugetlb_fault(struct mm_struct *mm,
33696 + static DEFINE_MUTEX(hugetlb_instantiation_mutex);
33697 + struct hstate *h = hstate_vma(vma);
33698 +
33699 ++#ifdef CONFIG_PAX_SEGMEXEC
33700 ++ struct vm_area_struct *vma_m;
33701 ++
33702 ++ vma_m = pax_find_mirror_vma(vma);
33703 ++ if (vma_m) {
33704 ++ unsigned long address_m;
33705 ++
33706 ++ if (vma->vm_start > vma_m->vm_start) {
33707 ++ address_m = address;
33708 ++ address -= SEGMEXEC_TASK_SIZE;
33709 ++ vma = vma_m;
33710 ++ h = hstate_vma(vma);
33711 ++ } else
33712 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33713 ++
33714 ++ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
33715 ++ return VM_FAULT_OOM;
33716 ++ address_m &= HPAGE_MASK;
33717 ++ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
33718 ++ }
33719 ++#endif
33720 ++
33721 + ptep = huge_pte_alloc(mm, address, huge_page_size(h));
33722 + if (!ptep)
33723 + return VM_FAULT_OOM;
33724 +diff -urNp linux-2.6.27.10/mm/madvise.c linux-2.6.27.10/mm/madvise.c
33725 +--- linux-2.6.27.10/mm/madvise.c 2008-11-07 12:55:34.000000000 -0500
33726 ++++ linux-2.6.27.10/mm/madvise.c 2008-11-18 03:38:45.000000000 -0500
33727 +@@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a
33728 + pgoff_t pgoff;
33729 + int new_flags = vma->vm_flags;
33730 +
33731 ++#ifdef CONFIG_PAX_SEGMEXEC
33732 ++ struct vm_area_struct *vma_m;
33733 ++#endif
33734 ++
33735 + switch (behavior) {
33736 + case MADV_NORMAL:
33737 + new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
33738 +@@ -92,6 +96,13 @@ success:
33739 + /*
33740 + * vm_flags is protected by the mmap_sem held in write mode.
33741 + */
33742 ++
33743 ++#ifdef CONFIG_PAX_SEGMEXEC
33744 ++ vma_m = pax_find_mirror_vma(vma);
33745 ++ if (vma_m)
33746 ++ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
33747 ++#endif
33748 ++
33749 + vma->vm_flags = new_flags;
33750 +
33751 + out:
33752 +@@ -236,6 +247,17 @@ madvise_vma(struct vm_area_struct *vma,
33753 +
33754 + case MADV_DONTNEED:
33755 + error = madvise_dontneed(vma, prev, start, end);
33756 ++
33757 ++#ifdef CONFIG_PAX_SEGMEXEC
33758 ++ if (!error) {
33759 ++ struct vm_area_struct *vma_m, *prev_m;
33760 ++
33761 ++ vma_m = pax_find_mirror_vma(vma);
33762 ++ if (vma_m)
33763 ++ error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE);
33764 ++ }
33765 ++#endif
33766 ++
33767 + break;
33768 +
33769 + default:
33770 +@@ -308,6 +330,16 @@ asmlinkage long sys_madvise(unsigned lon
33771 + if (end < start)
33772 + goto out;
33773 +
33774 ++#ifdef CONFIG_PAX_SEGMEXEC
33775 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
33776 ++ if (end > SEGMEXEC_TASK_SIZE)
33777 ++ goto out;
33778 ++ } else
33779 ++#endif
33780 ++
33781 ++ if (end > TASK_SIZE)
33782 ++ goto out;
33783 ++
33784 + error = 0;
33785 + if (end == start)
33786 + goto out;
33787 +diff -urNp linux-2.6.27.10/mm/memory.c linux-2.6.27.10/mm/memory.c
33788 +--- linux-2.6.27.10/mm/memory.c 2008-11-07 12:55:34.000000000 -0500
33789 ++++ linux-2.6.27.10/mm/memory.c 2008-11-18 03:38:45.000000000 -0500
33790 +@@ -52,6 +52,7 @@
33791 + #include <linux/writeback.h>
33792 + #include <linux/memcontrol.h>
33793 + #include <linux/mmu_notifier.h>
33794 ++#include <linux/grsecurity.h>
33795 +
33796 + #include <asm/pgalloc.h>
33797 + #include <asm/uaccess.h>
33798 +@@ -1146,11 +1147,11 @@ int get_user_pages(struct task_struct *t
33799 + vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
33800 + i = 0;
33801 +
33802 +- do {
33803 ++ while (len) {
33804 + struct vm_area_struct *vma;
33805 + unsigned int foll_flags;
33806 +
33807 +- vma = find_extend_vma(mm, start);
33808 ++ vma = find_vma(mm, start);
33809 + if (!vma && in_gate_area(tsk, start)) {
33810 + unsigned long pg = start & PAGE_MASK;
33811 + struct vm_area_struct *gate_vma = get_gate_vma(tsk);
33812 +@@ -1190,7 +1191,7 @@ int get_user_pages(struct task_struct *t
33813 + continue;
33814 + }
33815 +
33816 +- if (!vma || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33817 ++ if (!vma || start < vma->vm_start || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33818 + || !(vm_flags & vma->vm_flags))
33819 + return i ? : -EFAULT;
33820 +
33821 +@@ -1263,7 +1264,7 @@ int get_user_pages(struct task_struct *t
33822 + start += PAGE_SIZE;
33823 + len--;
33824 + } while (len && start < vma->vm_end);
33825 +- } while (len);
33826 ++ }
33827 + return i;
33828 + }
33829 + EXPORT_SYMBOL(get_user_pages);
33830 +@@ -1741,6 +1742,186 @@ static inline void cow_user_page(struct
33831 + copy_user_highpage(dst, src, va, vma);
33832 + }
33833 +
33834 ++#ifdef CONFIG_PAX_SEGMEXEC
33835 ++static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
33836 ++{
33837 ++ struct mm_struct *mm = vma->vm_mm;
33838 ++ spinlock_t *ptl;
33839 ++ pte_t *pte, entry;
33840 ++
33841 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
33842 ++ entry = *pte;
33843 ++ if (!pte_present(entry)) {
33844 ++ if (!pte_none(entry)) {
33845 ++ BUG_ON(pte_file(entry));
33846 ++ free_swap_and_cache(pte_to_swp_entry(entry));
33847 ++ pte_clear_not_present_full(mm, address, pte, 0);
33848 ++ }
33849 ++ } else {
33850 ++ struct page *page;
33851 ++
33852 ++ flush_cache_page(vma, address, pte_pfn(entry));
33853 ++ entry = ptep_clear_flush(vma, address, pte);
33854 ++ BUG_ON(pte_dirty(entry));
33855 ++ page = vm_normal_page(vma, address, entry);
33856 ++ if (page) {
33857 ++ update_hiwater_rss(mm);
33858 ++ if (PageAnon(page))
33859 ++ dec_mm_counter(mm, anon_rss);
33860 ++ else
33861 ++ dec_mm_counter(mm, file_rss);
33862 ++ page_remove_rmap(page, vma);
33863 ++ page_cache_release(page);
33864 ++ }
33865 ++ }
33866 ++ pte_unmap_unlock(pte, ptl);
33867 ++}
33868 ++
33869 ++/* PaX: if vma is mirrored, synchronize the mirror's PTE
33870 ++ *
33871 ++ * the ptl of the lower mapped page is held on entry and is not released on exit
33872 ++ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
33873 ++ */
33874 ++static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33875 ++{
33876 ++ struct mm_struct *mm = vma->vm_mm;
33877 ++ unsigned long address_m;
33878 ++ spinlock_t *ptl_m;
33879 ++ struct vm_area_struct *vma_m;
33880 ++ pmd_t *pmd_m;
33881 ++ pte_t *pte_m, entry_m;
33882 ++
33883 ++ BUG_ON(!page_m || !PageAnon(page_m));
33884 ++
33885 ++ vma_m = pax_find_mirror_vma(vma);
33886 ++ if (!vma_m)
33887 ++ return;
33888 ++
33889 ++ BUG_ON(!PageLocked(page_m));
33890 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33891 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33892 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33893 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33894 ++ ptl_m = pte_lockptr(mm, pmd_m);
33895 ++ if (ptl != ptl_m) {
33896 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33897 ++ if (!pte_none(*pte_m))
33898 ++ goto out;
33899 ++ }
33900 ++
33901 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33902 ++ page_cache_get(page_m);
33903 ++ page_add_anon_rmap(page_m, vma_m, address_m);
33904 ++ inc_mm_counter(mm, anon_rss);
33905 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33906 ++ update_mmu_cache(vma_m, address_m, entry_m);
33907 ++out:
33908 ++ if (ptl != ptl_m)
33909 ++ spin_unlock(ptl_m);
33910 ++ pte_unmap_nested(pte_m);
33911 ++ unlock_page(page_m);
33912 ++}
33913 ++
33914 ++void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33915 ++{
33916 ++ struct mm_struct *mm = vma->vm_mm;
33917 ++ unsigned long address_m;
33918 ++ spinlock_t *ptl_m;
33919 ++ struct vm_area_struct *vma_m;
33920 ++ pmd_t *pmd_m;
33921 ++ pte_t *pte_m, entry_m;
33922 ++
33923 ++ BUG_ON(!page_m || PageAnon(page_m));
33924 ++
33925 ++ vma_m = pax_find_mirror_vma(vma);
33926 ++ if (!vma_m)
33927 ++ return;
33928 ++
33929 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33930 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33931 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33932 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33933 ++ ptl_m = pte_lockptr(mm, pmd_m);
33934 ++ if (ptl != ptl_m) {
33935 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33936 ++ if (!pte_none(*pte_m))
33937 ++ goto out;
33938 ++ }
33939 ++
33940 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33941 ++ page_cache_get(page_m);
33942 ++ page_add_file_rmap(page_m);
33943 ++ inc_mm_counter(mm, file_rss);
33944 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33945 ++ update_mmu_cache(vma_m, address_m, entry_m);
33946 ++out:
33947 ++ if (ptl != ptl_m)
33948 ++ spin_unlock(ptl_m);
33949 ++ pte_unmap_nested(pte_m);
33950 ++}
33951 ++
33952 ++static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
33953 ++{
33954 ++ struct mm_struct *mm = vma->vm_mm;
33955 ++ unsigned long address_m;
33956 ++ spinlock_t *ptl_m;
33957 ++ struct vm_area_struct *vma_m;
33958 ++ pmd_t *pmd_m;
33959 ++ pte_t *pte_m, entry_m;
33960 ++
33961 ++ vma_m = pax_find_mirror_vma(vma);
33962 ++ if (!vma_m)
33963 ++ return;
33964 ++
33965 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33966 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33967 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33968 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33969 ++ ptl_m = pte_lockptr(mm, pmd_m);
33970 ++ if (ptl != ptl_m) {
33971 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33972 ++ if (!pte_none(*pte_m))
33973 ++ goto out;
33974 ++ }
33975 ++
33976 ++ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
33977 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33978 ++out:
33979 ++ if (ptl != ptl_m)
33980 ++ spin_unlock(ptl_m);
33981 ++ pte_unmap_nested(pte_m);
33982 ++}
33983 ++
33984 ++static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
33985 ++{
33986 ++ struct page *page_m;
33987 ++ pte_t entry;
33988 ++
33989 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
33990 ++ goto out;
33991 ++
33992 ++ entry = *pte;
33993 ++ page_m = vm_normal_page(vma, address, entry);
33994 ++ if (!page_m)
33995 ++ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
33996 ++ else if (PageAnon(page_m)) {
33997 ++ if (pax_find_mirror_vma(vma)) {
33998 ++ pte_unmap_unlock(pte, ptl);
33999 ++ lock_page(page_m);
34000 ++ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
34001 ++ if (pte_same(entry, *pte))
34002 ++ pax_mirror_anon_pte(vma, address, page_m, ptl);
34003 ++ else
34004 ++ unlock_page(page_m);
34005 ++ }
34006 ++ } else
34007 ++ pax_mirror_file_pte(vma, address, page_m, ptl);
34008 ++
34009 ++out:
34010 ++ pte_unmap_unlock(pte, ptl);
34011 ++}
34012 ++#endif
34013 ++
34014 + /*
34015 + * This routine handles present pages, when users try to write
34016 + * to a shared page. It is done by copying the page to a new address
34017 +@@ -1869,6 +2050,12 @@ gotten:
34018 + */
34019 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
34020 + if (likely(pte_same(*page_table, orig_pte))) {
34021 ++
34022 ++#ifdef CONFIG_PAX_SEGMEXEC
34023 ++ if (pax_find_mirror_vma(vma))
34024 ++ BUG_ON(!trylock_page(new_page));
34025 ++#endif
34026 ++
34027 + if (old_page) {
34028 + if (!PageAnon(old_page)) {
34029 + dec_mm_counter(mm, file_rss);
34030 +@@ -1917,6 +2104,10 @@ gotten:
34031 + page_remove_rmap(old_page, vma);
34032 + }
34033 +
34034 ++#ifdef CONFIG_PAX_SEGMEXEC
34035 ++ pax_mirror_anon_pte(vma, address, new_page, ptl);
34036 ++#endif
34037 ++
34038 + /* Free the old page.. */
34039 + new_page = old_page;
34040 + ret |= VM_FAULT_WRITE;
34041 +@@ -2176,6 +2367,7 @@ int vmtruncate(struct inode * inode, lof
34042 + unsigned long limit;
34043 +
34044 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
34045 ++ gr_learn_resource(current, RLIMIT_FSIZE, offset, 1);
34046 + if (limit != RLIM_INFINITY && offset > limit)
34047 + goto out_sig;
34048 + if (offset > inode->i_sb->s_maxbytes)
34049 +@@ -2326,6 +2518,11 @@ static int do_swap_page(struct mm_struct
34050 + swap_free(entry);
34051 + if (vm_swap_full())
34052 + remove_exclusive_swap_page(page);
34053 ++
34054 ++#ifdef CONFIG_PAX_SEGMEXEC
34055 ++ if (write_access || !pax_find_mirror_vma(vma))
34056 ++#endif
34057 ++
34058 + unlock_page(page);
34059 +
34060 + if (write_access) {
34061 +@@ -2337,6 +2534,11 @@ static int do_swap_page(struct mm_struct
34062 +
34063 + /* No need to invalidate - it was non-present before */
34064 + update_mmu_cache(vma, address, pte);
34065 ++
34066 ++#ifdef CONFIG_PAX_SEGMEXEC
34067 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34068 ++#endif
34069 ++
34070 + unlock:
34071 + pte_unmap_unlock(page_table, ptl);
34072 + out:
34073 +@@ -2381,6 +2583,12 @@ static int do_anonymous_page(struct mm_s
34074 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
34075 + if (!pte_none(*page_table))
34076 + goto release;
34077 ++
34078 ++#ifdef CONFIG_PAX_SEGMEXEC
34079 ++ if (pax_find_mirror_vma(vma))
34080 ++ BUG_ON(!trylock_page(page));
34081 ++#endif
34082 ++
34083 + inc_mm_counter(mm, anon_rss);
34084 + lru_cache_add_active(page);
34085 + page_add_new_anon_rmap(page, vma, address);
34086 +@@ -2388,6 +2596,11 @@ static int do_anonymous_page(struct mm_s
34087 +
34088 + /* No need to invalidate - it was non-present before */
34089 + update_mmu_cache(vma, address, entry);
34090 ++
34091 ++#ifdef CONFIG_PAX_SEGMEXEC
34092 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34093 ++#endif
34094 ++
34095 + unlock:
34096 + pte_unmap_unlock(page_table, ptl);
34097 + return 0;
34098 +@@ -2516,6 +2729,12 @@ static int __do_fault(struct mm_struct *
34099 + */
34100 + /* Only go through if we didn't race with anybody else... */
34101 + if (likely(pte_same(*page_table, orig_pte))) {
34102 ++
34103 ++#ifdef CONFIG_PAX_SEGMEXEC
34104 ++ if (anon && pax_find_mirror_vma(vma))
34105 ++ BUG_ON(!trylock_page(page));
34106 ++#endif
34107 ++
34108 + flush_icache_page(vma, page);
34109 + entry = mk_pte(page, vma->vm_page_prot);
34110 + if (flags & FAULT_FLAG_WRITE)
34111 +@@ -2536,6 +2755,14 @@ static int __do_fault(struct mm_struct *
34112 +
34113 + /* no need to invalidate: a not-present page won't be cached */
34114 + update_mmu_cache(vma, address, entry);
34115 ++
34116 ++#ifdef CONFIG_PAX_SEGMEXEC
34117 ++ if (anon)
34118 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34119 ++ else
34120 ++ pax_mirror_file_pte(vma, address, page, ptl);
34121 ++#endif
34122 ++
34123 + } else {
34124 + mem_cgroup_uncharge_page(page);
34125 + if (anon)
34126 +@@ -2668,6 +2895,12 @@ static inline int handle_pte_fault(struc
34127 + if (write_access)
34128 + flush_tlb_page(vma, address);
34129 + }
34130 ++
34131 ++#ifdef CONFIG_PAX_SEGMEXEC
34132 ++ pax_mirror_pte(vma, address, pte, pmd, ptl);
34133 ++ return 0;
34134 ++#endif
34135 ++
34136 + unlock:
34137 + pte_unmap_unlock(pte, ptl);
34138 + return 0;
34139 +@@ -2684,6 +2917,10 @@ int handle_mm_fault(struct mm_struct *mm
34140 + pmd_t *pmd;
34141 + pte_t *pte;
34142 +
34143 ++#ifdef CONFIG_PAX_SEGMEXEC
34144 ++ struct vm_area_struct *vma_m;
34145 ++#endif
34146 ++
34147 + __set_current_state(TASK_RUNNING);
34148 +
34149 + count_vm_event(PGFAULT);
34150 +@@ -2691,6 +2928,34 @@ int handle_mm_fault(struct mm_struct *mm
34151 + if (unlikely(is_vm_hugetlb_page(vma)))
34152 + return hugetlb_fault(mm, vma, address, write_access);
34153 +
34154 ++#ifdef CONFIG_PAX_SEGMEXEC
34155 ++ vma_m = pax_find_mirror_vma(vma);
34156 ++ if (vma_m) {
34157 ++ unsigned long address_m;
34158 ++ pgd_t *pgd_m;
34159 ++ pud_t *pud_m;
34160 ++ pmd_t *pmd_m;
34161 ++
34162 ++ if (vma->vm_start > vma_m->vm_start) {
34163 ++ address_m = address;
34164 ++ address -= SEGMEXEC_TASK_SIZE;
34165 ++ vma = vma_m;
34166 ++ } else
34167 ++ address_m = address + SEGMEXEC_TASK_SIZE;
34168 ++
34169 ++ pgd_m = pgd_offset(mm, address_m);
34170 ++ pud_m = pud_alloc(mm, pgd_m, address_m);
34171 ++ if (!pud_m)
34172 ++ return VM_FAULT_OOM;
34173 ++ pmd_m = pmd_alloc(mm, pud_m, address_m);
34174 ++ if (!pmd_m)
34175 ++ return VM_FAULT_OOM;
34176 ++ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
34177 ++ return VM_FAULT_OOM;
34178 ++ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
34179 ++ }
34180 ++#endif
34181 ++
34182 + pgd = pgd_offset(mm, address);
34183 + pud = pud_alloc(mm, pgd, address);
34184 + if (!pud)
34185 +@@ -2798,7 +3063,7 @@ static int __init gate_vma_init(void)
34186 + gate_vma.vm_start = FIXADDR_USER_START;
34187 + gate_vma.vm_end = FIXADDR_USER_END;
34188 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34189 +- gate_vma.vm_page_prot = __P101;
34190 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34191 + /*
34192 + * Make sure the vDSO gets into every core dump.
34193 + * Dumping its contents makes post-mortem fully interpretable later
34194 +diff -urNp linux-2.6.27.10/mm/mempolicy.c linux-2.6.27.10/mm/mempolicy.c
34195 +--- linux-2.6.27.10/mm/mempolicy.c 2008-11-07 12:55:34.000000000 -0500
34196 ++++ linux-2.6.27.10/mm/mempolicy.c 2008-11-18 03:38:45.000000000 -0500
34197 +@@ -555,6 +555,10 @@ static int mbind_range(struct vm_area_st
34198 + struct vm_area_struct *next;
34199 + int err;
34200 +
34201 ++#ifdef CONFIG_PAX_SEGMEXEC
34202 ++ struct vm_area_struct *vma_m;
34203 ++#endif
34204 ++
34205 + err = 0;
34206 + for (; vma && vma->vm_start < end; vma = next) {
34207 + next = vma->vm_next;
34208 +@@ -566,6 +570,16 @@ static int mbind_range(struct vm_area_st
34209 + err = policy_vma(vma, new);
34210 + if (err)
34211 + break;
34212 ++
34213 ++#ifdef CONFIG_PAX_SEGMEXEC
34214 ++ vma_m = pax_find_mirror_vma(vma);
34215 ++ if (vma_m) {
34216 ++ err = policy_vma(vma_m, new);
34217 ++ if (err)
34218 ++ break;
34219 ++ }
34220 ++#endif
34221 ++
34222 + }
34223 + return err;
34224 + }
34225 +@@ -951,6 +965,17 @@ static long do_mbind(unsigned long start
34226 +
34227 + if (end < start)
34228 + return -EINVAL;
34229 ++
34230 ++#ifdef CONFIG_PAX_SEGMEXEC
34231 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
34232 ++ if (end > SEGMEXEC_TASK_SIZE)
34233 ++ return -EINVAL;
34234 ++ } else
34235 ++#endif
34236 ++
34237 ++ if (end > TASK_SIZE)
34238 ++ return -EINVAL;
34239 ++
34240 + if (end == start)
34241 + return 0;
34242 +
34243 +diff -urNp linux-2.6.27.10/mm/mlock.c linux-2.6.27.10/mm/mlock.c
34244 +--- linux-2.6.27.10/mm/mlock.c 2008-11-07 12:55:34.000000000 -0500
34245 ++++ linux-2.6.27.10/mm/mlock.c 2008-11-18 03:38:45.000000000 -0500
34246 +@@ -12,6 +12,7 @@
34247 + #include <linux/syscalls.h>
34248 + #include <linux/sched.h>
34249 + #include <linux/module.h>
34250 ++#include <linux/grsecurity.h>
34251 +
34252 + int can_do_mlock(void)
34253 + {
34254 +@@ -93,6 +94,17 @@ static int do_mlock(unsigned long start,
34255 + return -EINVAL;
34256 + if (end == start)
34257 + return 0;
34258 ++
34259 ++#ifdef CONFIG_PAX_SEGMEXEC
34260 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
34261 ++ if (end > SEGMEXEC_TASK_SIZE)
34262 ++ return -EINVAL;
34263 ++ } else
34264 ++#endif
34265 ++
34266 ++ if (end > TASK_SIZE)
34267 ++ return -EINVAL;
34268 ++
34269 + vma = find_vma_prev(current->mm, start, &prev);
34270 + if (!vma || vma->vm_start > start)
34271 + return -ENOMEM;
34272 +@@ -150,6 +162,7 @@ asmlinkage long sys_mlock(unsigned long
34273 + lock_limit >>= PAGE_SHIFT;
34274 +
34275 + /* check against resource limits */
34276 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
34277 + if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
34278 + error = do_mlock(start, len, 1);
34279 + up_write(&current->mm->mmap_sem);
34280 +@@ -171,10 +184,10 @@ asmlinkage long sys_munlock(unsigned lon
34281 + static int do_mlockall(int flags)
34282 + {
34283 + struct vm_area_struct * vma, * prev = NULL;
34284 +- unsigned int def_flags = 0;
34285 ++ unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED;
34286 +
34287 + if (flags & MCL_FUTURE)
34288 +- def_flags = VM_LOCKED;
34289 ++ def_flags |= VM_LOCKED;
34290 + current->mm->def_flags = def_flags;
34291 + if (flags == MCL_FUTURE)
34292 + goto out;
34293 +@@ -182,6 +195,12 @@ static int do_mlockall(int flags)
34294 + for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
34295 + unsigned int newflags;
34296 +
34297 ++#ifdef CONFIG_PAX_SEGMEXEC
34298 ++ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
34299 ++ break;
34300 ++#endif
34301 ++
34302 ++ BUG_ON(vma->vm_end > TASK_SIZE);
34303 + newflags = vma->vm_flags | VM_LOCKED;
34304 + if (!(flags & MCL_CURRENT))
34305 + newflags &= ~VM_LOCKED;
34306 +@@ -211,6 +230,7 @@ asmlinkage long sys_mlockall(int flags)
34307 + lock_limit >>= PAGE_SHIFT;
34308 +
34309 + ret = -ENOMEM;
34310 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1);
34311 + if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
34312 + capable(CAP_IPC_LOCK))
34313 + ret = do_mlockall(flags);
34314 +diff -urNp linux-2.6.27.10/mm/mmap.c linux-2.6.27.10/mm/mmap.c
34315 +--- linux-2.6.27.10/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
34316 ++++ linux-2.6.27.10/mm/mmap.c 2008-12-21 00:44:29.000000000 -0500
34317 +@@ -27,6 +27,7 @@
34318 + #include <linux/mempolicy.h>
34319 + #include <linux/rmap.h>
34320 + #include <linux/mmu_notifier.h>
34321 ++#include <linux/grsecurity.h>
34322 +
34323 + #include <asm/uaccess.h>
34324 + #include <asm/cacheflush.h>
34325 +@@ -43,6 +44,16 @@
34326 + #define arch_rebalance_pgtables(addr, len) (addr)
34327 + #endif
34328 +
34329 ++static inline void verify_mm_writelocked(struct mm_struct *mm)
34330 ++{
34331 ++#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
34332 ++ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
34333 ++ up_read(&mm->mmap_sem);
34334 ++ BUG();
34335 ++ }
34336 ++#endif
34337 ++}
34338 ++
34339 + static void unmap_region(struct mm_struct *mm,
34340 + struct vm_area_struct *vma, struct vm_area_struct *prev,
34341 + unsigned long start, unsigned long end);
34342 +@@ -68,16 +79,25 @@ static void unmap_region(struct mm_struc
34343 + * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
34344 + *
34345 + */
34346 +-pgprot_t protection_map[16] = {
34347 ++pgprot_t protection_map[16] __read_only = {
34348 + __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
34349 + __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
34350 + };
34351 +
34352 + pgprot_t vm_get_page_prot(unsigned long vm_flags)
34353 + {
34354 +- return __pgprot(pgprot_val(protection_map[vm_flags &
34355 ++ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
34356 + (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
34357 + pgprot_val(arch_vm_get_page_prot(vm_flags)));
34358 ++
34359 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34360 ++ if (!nx_enabled &&
34361 ++ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
34362 ++ (vm_flags & (VM_READ | VM_WRITE)))
34363 ++ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
34364 ++#endif
34365 ++
34366 ++ return prot;
34367 + }
34368 + EXPORT_SYMBOL(vm_get_page_prot);
34369 +
34370 +@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
34371 + struct vm_area_struct *next = vma->vm_next;
34372 +
34373 + might_sleep();
34374 ++ BUG_ON(vma->vm_mirror);
34375 + if (vma->vm_ops && vma->vm_ops->close)
34376 + vma->vm_ops->close(vma);
34377 + if (vma->vm_file) {
34378 +@@ -268,6 +289,7 @@ asmlinkage unsigned long sys_brk(unsigne
34379 + * not page aligned -Ram Gupta
34380 + */
34381 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
34382 ++ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
34383 + if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
34384 + (mm->end_data - mm->start_data) > rlim)
34385 + goto out;
34386 +@@ -697,6 +719,12 @@ static int
34387 + can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
34388 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34389 + {
34390 ++
34391 ++#ifdef CONFIG_PAX_SEGMEXEC
34392 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
34393 ++ return 0;
34394 ++#endif
34395 ++
34396 + if (is_mergeable_vma(vma, file, vm_flags) &&
34397 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34398 + if (vma->vm_pgoff == vm_pgoff)
34399 +@@ -716,6 +744,12 @@ static int
34400 + can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
34401 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34402 + {
34403 ++
34404 ++#ifdef CONFIG_PAX_SEGMEXEC
34405 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
34406 ++ return 0;
34407 ++#endif
34408 ++
34409 + if (is_mergeable_vma(vma, file, vm_flags) &&
34410 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34411 + pgoff_t vm_pglen;
34412 +@@ -758,12 +792,19 @@ can_vma_merge_after(struct vm_area_struc
34413 + struct vm_area_struct *vma_merge(struct mm_struct *mm,
34414 + struct vm_area_struct *prev, unsigned long addr,
34415 + unsigned long end, unsigned long vm_flags,
34416 +- struct anon_vma *anon_vma, struct file *file,
34417 ++ struct anon_vma *anon_vma, struct file *file,
34418 + pgoff_t pgoff, struct mempolicy *policy)
34419 + {
34420 + pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
34421 + struct vm_area_struct *area, *next;
34422 +
34423 ++#ifdef CONFIG_PAX_SEGMEXEC
34424 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
34425 ++ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
34426 ++
34427 ++ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
34428 ++#endif
34429 ++
34430 + /*
34431 + * We later require that vma->vm_flags == vm_flags,
34432 + * so this tests vma->vm_flags & VM_SPECIAL, too.
34433 +@@ -779,6 +820,15 @@ struct vm_area_struct *vma_merge(struct
34434 + if (next && next->vm_end == end) /* cases 6, 7, 8 */
34435 + next = next->vm_next;
34436 +
34437 ++#ifdef CONFIG_PAX_SEGMEXEC
34438 ++ if (prev)
34439 ++ prev_m = pax_find_mirror_vma(prev);
34440 ++ if (area)
34441 ++ area_m = pax_find_mirror_vma(area);
34442 ++ if (next)
34443 ++ next_m = pax_find_mirror_vma(next);
34444 ++#endif
34445 ++
34446 + /*
34447 + * Can it merge with the predecessor?
34448 + */
34449 +@@ -798,9 +848,24 @@ struct vm_area_struct *vma_merge(struct
34450 + /* cases 1, 6 */
34451 + vma_adjust(prev, prev->vm_start,
34452 + next->vm_end, prev->vm_pgoff, NULL);
34453 +- } else /* cases 2, 5, 7 */
34454 ++
34455 ++#ifdef CONFIG_PAX_SEGMEXEC
34456 ++ if (prev_m)
34457 ++ vma_adjust(prev_m, prev_m->vm_start,
34458 ++ next_m->vm_end, prev_m->vm_pgoff, NULL);
34459 ++#endif
34460 ++
34461 ++ } else { /* cases 2, 5, 7 */
34462 + vma_adjust(prev, prev->vm_start,
34463 + end, prev->vm_pgoff, NULL);
34464 ++
34465 ++#ifdef CONFIG_PAX_SEGMEXEC
34466 ++ if (prev_m)
34467 ++ vma_adjust(prev_m, prev_m->vm_start,
34468 ++ end_m, prev_m->vm_pgoff, NULL);
34469 ++#endif
34470 ++
34471 ++ }
34472 + return prev;
34473 + }
34474 +
34475 +@@ -811,12 +876,27 @@ struct vm_area_struct *vma_merge(struct
34476 + mpol_equal(policy, vma_policy(next)) &&
34477 + can_vma_merge_before(next, vm_flags,
34478 + anon_vma, file, pgoff+pglen)) {
34479 +- if (prev && addr < prev->vm_end) /* case 4 */
34480 ++ if (prev && addr < prev->vm_end) { /* case 4 */
34481 + vma_adjust(prev, prev->vm_start,
34482 + addr, prev->vm_pgoff, NULL);
34483 +- else /* cases 3, 8 */
34484 ++
34485 ++#ifdef CONFIG_PAX_SEGMEXEC
34486 ++ if (prev_m)
34487 ++ vma_adjust(prev_m, prev_m->vm_start,
34488 ++ addr_m, prev_m->vm_pgoff, NULL);
34489 ++#endif
34490 ++
34491 ++ } else { /* cases 3, 8 */
34492 + vma_adjust(area, addr, next->vm_end,
34493 + next->vm_pgoff - pglen, NULL);
34494 ++
34495 ++#ifdef CONFIG_PAX_SEGMEXEC
34496 ++ if (area_m)
34497 ++ vma_adjust(area_m, addr_m, next_m->vm_end,
34498 ++ next_m->vm_pgoff - pglen, NULL);
34499 ++#endif
34500 ++
34501 ++ }
34502 + return area;
34503 + }
34504 +
34505 +@@ -891,14 +971,11 @@ none:
34506 + void vm_stat_account(struct mm_struct *mm, unsigned long flags,
34507 + struct file *file, long pages)
34508 + {
34509 +- const unsigned long stack_flags
34510 +- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
34511 +-
34512 + if (file) {
34513 + mm->shared_vm += pages;
34514 + if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
34515 + mm->exec_vm += pages;
34516 +- } else if (flags & stack_flags)
34517 ++ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
34518 + mm->stack_vm += pages;
34519 + if (flags & (VM_RESERVED|VM_IO))
34520 + mm->reserved_vm += pages;
34521 +@@ -926,7 +1003,7 @@ unsigned long do_mmap_pgoff(struct file
34522 + * (the exception is when the underlying filesystem is noexec
34523 + * mounted, in which case we dont add PROT_EXEC.)
34524 + */
34525 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
34526 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
34527 + if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
34528 + prot |= PROT_EXEC;
34529 +
34530 +@@ -936,15 +1013,15 @@ unsigned long do_mmap_pgoff(struct file
34531 + if (!(flags & MAP_FIXED))
34532 + addr = round_hint_to_min(addr);
34533 +
34534 +- error = arch_mmap_check(addr, len, flags);
34535 +- if (error)
34536 +- return error;
34537 +-
34538 + /* Careful about overflows.. */
34539 + len = PAGE_ALIGN(len);
34540 + if (!len || len > TASK_SIZE)
34541 + return -ENOMEM;
34542 +
34543 ++ error = arch_mmap_check(addr, len, flags);
34544 ++ if (error)
34545 ++ return error;
34546 ++
34547 + /* offset overflow? */
34548 + if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
34549 + return -EOVERFLOW;
34550 +@@ -956,7 +1033,7 @@ unsigned long do_mmap_pgoff(struct file
34551 + /* Obtain the address to map to. we verify (or select) it and ensure
34552 + * that it represents a valid section of the address space.
34553 + */
34554 +- addr = get_unmapped_area(file, addr, len, pgoff, flags);
34555 ++ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
34556 + if (addr & ~PAGE_MASK)
34557 + return addr;
34558 +
34559 +@@ -967,6 +1044,26 @@ unsigned long do_mmap_pgoff(struct file
34560 + vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
34561 + mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
34562 +
34563 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
34564 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
34565 ++
34566 ++#ifdef CONFIG_PAX_MPROTECT
34567 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
34568 ++ if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC)
34569 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
34570 ++ else
34571 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
34572 ++ }
34573 ++#endif
34574 ++
34575 ++ }
34576 ++#endif
34577 ++
34578 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34579 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
34580 ++ vm_flags &= ~VM_PAGEEXEC;
34581 ++#endif
34582 ++
34583 + if (flags & MAP_LOCKED) {
34584 + if (!can_do_mlock())
34585 + return -EPERM;
34586 +@@ -979,6 +1076,7 @@ unsigned long do_mmap_pgoff(struct file
34587 + locked += mm->locked_vm;
34588 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
34589 + lock_limit >>= PAGE_SHIFT;
34590 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34591 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
34592 + return -EAGAIN;
34593 + }
34594 +@@ -1051,6 +1149,9 @@ unsigned long do_mmap_pgoff(struct file
34595 + if (error)
34596 + return error;
34597 +
34598 ++ if (!gr_acl_handle_mmap(file, prot))
34599 ++ return -EACCES;
34600 ++
34601 + return mmap_region(file, addr, len, flags, vm_flags, pgoff,
34602 + accountable);
34603 + }
34604 +@@ -1064,10 +1165,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
34605 + */
34606 + int vma_wants_writenotify(struct vm_area_struct *vma)
34607 + {
34608 +- unsigned int vm_flags = vma->vm_flags;
34609 ++ unsigned long vm_flags = vma->vm_flags;
34610 +
34611 + /* If it was private or non-writable, the write bit is already clear */
34612 +- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
34613 ++ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
34614 + return 0;
34615 +
34616 + /* The backer wishes to know when pages are first written to? */
34617 +@@ -1101,14 +1202,24 @@ unsigned long mmap_region(struct file *f
34618 + unsigned long charged = 0;
34619 + struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
34620 +
34621 ++#ifdef CONFIG_PAX_SEGMEXEC
34622 ++ struct vm_area_struct *vma_m = NULL;
34623 ++#endif
34624 ++
34625 ++ /*
34626 ++ * mm->mmap_sem is required to protect against another thread
34627 ++ * changing the mappings in case we sleep.
34628 ++ */
34629 ++ verify_mm_writelocked(mm);
34630 ++
34631 + /* Clear old maps */
34632 + error = -ENOMEM;
34633 +-munmap_back:
34634 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34635 + if (vma && vma->vm_start < addr + len) {
34636 + if (do_munmap(mm, addr, len))
34637 + return -ENOMEM;
34638 +- goto munmap_back;
34639 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34640 ++ BUG_ON(vma && vma->vm_start < addr + len);
34641 + }
34642 +
34643 + /* Check against address space limit. */
34644 +@@ -1155,6 +1266,16 @@ munmap_back:
34645 + goto unacct_error;
34646 + }
34647 +
34648 ++#ifdef CONFIG_PAX_SEGMEXEC
34649 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
34650 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
34651 ++ if (!vma_m) {
34652 ++ error = -ENOMEM;
34653 ++ goto free_vma;
34654 ++ }
34655 ++ }
34656 ++#endif
34657 ++
34658 + vma->vm_mm = mm;
34659 + vma->vm_start = addr;
34660 + vma->vm_end = addr + len;
34661 +@@ -1177,6 +1298,19 @@ munmap_back:
34662 + error = file->f_op->mmap(file, vma);
34663 + if (error)
34664 + goto unmap_and_free_vma;
34665 ++
34666 ++#ifdef CONFIG_PAX_SEGMEXEC
34667 ++ if (vma_m && (vm_flags & VM_EXECUTABLE))
34668 ++ added_exe_file_vma(mm);
34669 ++#endif
34670 ++
34671 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34672 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
34673 ++ vma->vm_flags |= VM_PAGEEXEC;
34674 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
34675 ++ }
34676 ++#endif
34677 ++
34678 + if (vm_flags & VM_EXECUTABLE)
34679 + added_exe_file_vma(mm);
34680 + } else if (vm_flags & VM_SHARED) {
34681 +@@ -1209,12 +1343,29 @@ munmap_back:
34682 + vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) {
34683 + mpol_put(vma_policy(vma));
34684 + kmem_cache_free(vm_area_cachep, vma);
34685 ++ vma = NULL;
34686 + fput(file);
34687 ++
34688 ++#ifdef CONFIG_PAX_SEGMEXEC
34689 ++ if (vma_m) {
34690 ++ kmem_cache_free(vm_area_cachep, vma_m);
34691 ++
34692 ++ if (vm_flags & VM_EXECUTABLE)
34693 ++ removed_exe_file_vma(mm);
34694 ++ }
34695 ++#endif
34696 ++
34697 + if (vm_flags & VM_EXECUTABLE)
34698 + removed_exe_file_vma(mm);
34699 + } else {
34700 + vma_link(mm, vma, prev, rb_link, rb_parent);
34701 + file = vma->vm_file;
34702 ++
34703 ++#ifdef CONFIG_PAX_SEGMEXEC
34704 ++ if (vma_m)
34705 ++ pax_mirror_vma(vma_m, vma);
34706 ++#endif
34707 ++
34708 + }
34709 +
34710 + /* Once vma denies write, undo our temporary denial count */
34711 +@@ -1223,6 +1374,7 @@ munmap_back:
34712 + out:
34713 + mm->total_vm += len >> PAGE_SHIFT;
34714 + vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
34715 ++ track_exec_limit(mm, addr, addr + len, vm_flags);
34716 + if (vm_flags & VM_LOCKED) {
34717 + mm->locked_vm += len >> PAGE_SHIFT;
34718 + make_pages_present(addr, addr + len);
34719 +@@ -1241,6 +1393,12 @@ unmap_and_free_vma:
34720 + unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
34721 + charged = 0;
34722 + free_vma:
34723 ++
34724 ++#ifdef CONFIG_PAX_SEGMEXEC
34725 ++ if (vma_m)
34726 ++ kmem_cache_free(vm_area_cachep, vma_m);
34727 ++#endif
34728 ++
34729 + kmem_cache_free(vm_area_cachep, vma);
34730 + unacct_error:
34731 + if (charged)
34732 +@@ -1274,6 +1432,10 @@ arch_get_unmapped_area(struct file *filp
34733 + if (flags & MAP_FIXED)
34734 + return addr;
34735 +
34736 ++#ifdef CONFIG_PAX_RANDMMAP
34737 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34738 ++#endif
34739 ++
34740 + if (addr) {
34741 + addr = PAGE_ALIGN(addr);
34742 + vma = find_vma(mm, addr);
34743 +@@ -1282,10 +1444,10 @@ arch_get_unmapped_area(struct file *filp
34744 + return addr;
34745 + }
34746 + if (len > mm->cached_hole_size) {
34747 +- start_addr = addr = mm->free_area_cache;
34748 ++ start_addr = addr = mm->free_area_cache;
34749 + } else {
34750 +- start_addr = addr = TASK_UNMAPPED_BASE;
34751 +- mm->cached_hole_size = 0;
34752 ++ start_addr = addr = mm->mmap_base;
34753 ++ mm->cached_hole_size = 0;
34754 + }
34755 +
34756 + full_search:
34757 +@@ -1296,9 +1458,8 @@ full_search:
34758 + * Start a new search - just in case we missed
34759 + * some holes.
34760 + */
34761 +- if (start_addr != TASK_UNMAPPED_BASE) {
34762 +- addr = TASK_UNMAPPED_BASE;
34763 +- start_addr = addr;
34764 ++ if (start_addr != mm->mmap_base) {
34765 ++ start_addr = addr = mm->mmap_base;
34766 + mm->cached_hole_size = 0;
34767 + goto full_search;
34768 + }
34769 +@@ -1320,10 +1481,16 @@ full_search:
34770 +
34771 + void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
34772 + {
34773 ++
34774 ++#ifdef CONFIG_PAX_SEGMEXEC
34775 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34776 ++ return;
34777 ++#endif
34778 ++
34779 + /*
34780 + * Is this a new hole at the lowest possible address?
34781 + */
34782 +- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
34783 ++ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
34784 + mm->free_area_cache = addr;
34785 + mm->cached_hole_size = ~0UL;
34786 + }
34787 +@@ -1341,7 +1508,7 @@ arch_get_unmapped_area_topdown(struct fi
34788 + {
34789 + struct vm_area_struct *vma;
34790 + struct mm_struct *mm = current->mm;
34791 +- unsigned long addr = addr0;
34792 ++ unsigned long base = mm->mmap_base, addr = addr0;
34793 +
34794 + /* requested length too big for entire address space */
34795 + if (len > TASK_SIZE)
34796 +@@ -1350,6 +1517,10 @@ arch_get_unmapped_area_topdown(struct fi
34797 + if (flags & MAP_FIXED)
34798 + return addr;
34799 +
34800 ++#ifdef CONFIG_PAX_RANDMMAP
34801 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34802 ++#endif
34803 ++
34804 + /* requesting a specific address */
34805 + if (addr) {
34806 + addr = PAGE_ALIGN(addr);
34807 +@@ -1407,13 +1578,21 @@ bottomup:
34808 + * can happen with large stack limits and large mmap()
34809 + * allocations.
34810 + */
34811 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
34812 ++
34813 ++#ifdef CONFIG_PAX_RANDMMAP
34814 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
34815 ++ mm->mmap_base += mm->delta_mmap;
34816 ++#endif
34817 ++
34818 ++ mm->free_area_cache = mm->mmap_base;
34819 + mm->cached_hole_size = ~0UL;
34820 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
34821 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
34822 + /*
34823 + * Restore the topdown base:
34824 + */
34825 +- mm->free_area_cache = mm->mmap_base;
34826 ++ mm->mmap_base = base;
34827 ++ mm->free_area_cache = base;
34828 + mm->cached_hole_size = ~0UL;
34829 +
34830 + return addr;
34831 +@@ -1422,6 +1601,12 @@ bottomup:
34832 +
34833 + void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
34834 + {
34835 ++
34836 ++#ifdef CONFIG_PAX_SEGMEXEC
34837 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34838 ++ return;
34839 ++#endif
34840 ++
34841 + /*
34842 + * Is this a new hole at the highest possible address?
34843 + */
34844 +@@ -1429,8 +1614,10 @@ void arch_unmap_area_topdown(struct mm_s
34845 + mm->free_area_cache = addr;
34846 +
34847 + /* dont allow allocations above current base */
34848 +- if (mm->free_area_cache > mm->mmap_base)
34849 ++ if (mm->free_area_cache > mm->mmap_base) {
34850 + mm->free_area_cache = mm->mmap_base;
34851 ++ mm->cached_hole_size = ~0UL;
34852 ++ }
34853 + }
34854 +
34855 + unsigned long
34856 +@@ -1530,6 +1717,27 @@ out:
34857 + return prev ? prev->vm_next : vma;
34858 + }
34859 +
34860 ++#ifdef CONFIG_PAX_SEGMEXEC
34861 ++struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
34862 ++{
34863 ++ struct vm_area_struct *vma_m;
34864 ++
34865 ++ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
34866 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
34867 ++ BUG_ON(vma->vm_mirror);
34868 ++ return NULL;
34869 ++ }
34870 ++ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
34871 ++ vma_m = vma->vm_mirror;
34872 ++ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
34873 ++ BUG_ON(vma->vm_file != vma_m->vm_file);
34874 ++ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
34875 ++ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
34876 ++ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
34877 ++ return vma_m;
34878 ++}
34879 ++#endif
34880 ++
34881 + /*
34882 + * Verify that the stack growth is acceptable and
34883 + * update accounting. This is shared with both the
34884 +@@ -1546,6 +1754,7 @@ static int acct_stack_growth(struct vm_a
34885 + return -ENOMEM;
34886 +
34887 + /* Stack limit test */
34888 ++ gr_learn_resource(current, RLIMIT_STACK, size, 1);
34889 + if (size > rlim[RLIMIT_STACK].rlim_cur)
34890 + return -ENOMEM;
34891 +
34892 +@@ -1555,6 +1764,7 @@ static int acct_stack_growth(struct vm_a
34893 + unsigned long limit;
34894 + locked = mm->locked_vm + grow;
34895 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
34896 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34897 + if (locked > limit && !capable(CAP_IPC_LOCK))
34898 + return -ENOMEM;
34899 + }
34900 +@@ -1569,7 +1779,7 @@ static int acct_stack_growth(struct vm_a
34901 + * Overcommit.. This must be the final test, as it will
34902 + * update security statistics.
34903 + */
34904 +- if (security_vm_enough_memory(grow))
34905 ++ if (security_vm_enough_memory_mm(mm, grow))
34906 + return -ENOMEM;
34907 +
34908 + /* Ok, everything looks good - let it rip */
34909 +@@ -1590,35 +1800,40 @@ static inline
34910 + #endif
34911 + int expand_upwards(struct vm_area_struct *vma, unsigned long address)
34912 + {
34913 +- int error;
34914 ++ int error, locknext;
34915 +
34916 + if (!(vma->vm_flags & VM_GROWSUP))
34917 + return -EFAULT;
34918 +
34919 ++ /* Also guard against wrapping around to address 0. */
34920 ++ if (address < PAGE_ALIGN(address+1))
34921 ++ address = PAGE_ALIGN(address+1);
34922 ++ else
34923 ++ return -ENOMEM;
34924 ++
34925 + /*
34926 + * We must make sure the anon_vma is allocated
34927 + * so that the anon_vma locking is not a noop.
34928 + */
34929 + if (unlikely(anon_vma_prepare(vma)))
34930 + return -ENOMEM;
34931 ++ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
34932 ++ if (locknext && unlikely(anon_vma_prepare(vma->vm_next)))
34933 ++ return -ENOMEM;
34934 + anon_vma_lock(vma);
34935 ++ if (locknext)
34936 ++ anon_vma_lock(vma->vm_next);
34937 +
34938 + /*
34939 + * vma->vm_start/vm_end cannot change under us because the caller
34940 + * is required to hold the mmap_sem in read mode. We need the
34941 +- * anon_vma lock to serialize against concurrent expand_stacks.
34942 +- * Also guard against wrapping around to address 0.
34943 ++ * anon_vma locks to serialize against concurrent expand_stacks
34944 ++ * and expand_upwards.
34945 + */
34946 +- if (address < PAGE_ALIGN(address+4))
34947 +- address = PAGE_ALIGN(address+4);
34948 +- else {
34949 +- anon_vma_unlock(vma);
34950 +- return -ENOMEM;
34951 +- }
34952 + error = 0;
34953 +
34954 + /* Somebody else might have raced and expanded it already */
34955 +- if (address > vma->vm_end) {
34956 ++ if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
34957 + unsigned long size, grow;
34958 +
34959 + size = address - vma->vm_start;
34960 +@@ -1628,6 +1843,8 @@ int expand_upwards(struct vm_area_struct
34961 + if (!error)
34962 + vma->vm_end = address;
34963 + }
34964 ++ if (locknext)
34965 ++ anon_vma_unlock(vma->vm_next);
34966 + anon_vma_unlock(vma);
34967 + return error;
34968 + }
34969 +@@ -1639,7 +1856,8 @@ int expand_upwards(struct vm_area_struct
34970 + static inline int expand_downwards(struct vm_area_struct *vma,
34971 + unsigned long address)
34972 + {
34973 +- int error;
34974 ++ int error, lockprev = 0;
34975 ++ struct vm_area_struct *prev = NULL;
34976 +
34977 + /*
34978 + * We must make sure the anon_vma is allocated
34979 +@@ -1653,6 +1871,15 @@ static inline int expand_downwards(struc
34980 + if (error)
34981 + return error;
34982 +
34983 ++#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
34984 ++ find_vma_prev(vma->vm_mm, address, &prev);
34985 ++ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
34986 ++#endif
34987 ++ if (lockprev && unlikely(anon_vma_prepare(prev)))
34988 ++ return -ENOMEM;
34989 ++ if (lockprev)
34990 ++ anon_vma_lock(prev);
34991 ++
34992 + anon_vma_lock(vma);
34993 +
34994 + /*
34995 +@@ -1662,9 +1889,15 @@ static inline int expand_downwards(struc
34996 + */
34997 +
34998 + /* Somebody else might have raced and expanded it already */
34999 +- if (address < vma->vm_start) {
35000 ++ if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
35001 + unsigned long size, grow;
35002 +
35003 ++#ifdef CONFIG_PAX_SEGMEXEC
35004 ++ struct vm_area_struct *vma_m;
35005 ++
35006 ++ vma_m = pax_find_mirror_vma(vma);
35007 ++#endif
35008 ++
35009 + size = vma->vm_end - address;
35010 + grow = (vma->vm_start - address) >> PAGE_SHIFT;
35011 +
35012 +@@ -1672,9 +1905,20 @@ static inline int expand_downwards(struc
35013 + if (!error) {
35014 + vma->vm_start = address;
35015 + vma->vm_pgoff -= grow;
35016 ++ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
35017 ++
35018 ++#ifdef CONFIG_PAX_SEGMEXEC
35019 ++ if (vma_m) {
35020 ++ vma_m->vm_start -= grow << PAGE_SHIFT;
35021 ++ vma_m->vm_pgoff -= grow;
35022 ++ }
35023 ++#endif
35024 ++
35025 + }
35026 + }
35027 + anon_vma_unlock(vma);
35028 ++ if (lockprev)
35029 ++ anon_vma_unlock(prev);
35030 + return error;
35031 + }
35032 +
35033 +@@ -1746,6 +1990,13 @@ static void remove_vma_list(struct mm_st
35034 + do {
35035 + long nrpages = vma_pages(vma);
35036 +
35037 ++#ifdef CONFIG_PAX_SEGMEXEC
35038 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
35039 ++ vma = remove_vma(vma);
35040 ++ continue;
35041 ++ }
35042 ++#endif
35043 ++
35044 + mm->total_vm -= nrpages;
35045 + if (vma->vm_flags & VM_LOCKED)
35046 + mm->locked_vm -= nrpages;
35047 +@@ -1792,6 +2043,16 @@ detach_vmas_to_be_unmapped(struct mm_str
35048 +
35049 + insertion_point = (prev ? &prev->vm_next : &mm->mmap);
35050 + do {
35051 ++
35052 ++#ifdef CONFIG_PAX_SEGMEXEC
35053 ++ if (vma->vm_mirror) {
35054 ++ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
35055 ++ vma->vm_mirror->vm_mirror = NULL;
35056 ++ vma->vm_mirror->vm_flags &= ~VM_EXEC;
35057 ++ vma->vm_mirror = NULL;
35058 ++ }
35059 ++#endif
35060 ++
35061 + rb_erase(&vma->vm_rb, &mm->mm_rb);
35062 + mm->map_count--;
35063 + tail_vma = vma;
35064 +@@ -1811,6 +2072,108 @@ detach_vmas_to_be_unmapped(struct mm_str
35065 + * Split a vma into two pieces at address 'addr', a new vma is allocated
35066 + * either for the first part or the tail.
35067 + */
35068 ++
35069 ++#ifdef CONFIG_PAX_SEGMEXEC
35070 ++int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
35071 ++ unsigned long addr, int new_below)
35072 ++{
35073 ++ struct mempolicy *pol;
35074 ++ struct vm_area_struct *new, *vma_m, *new_m = NULL;
35075 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
35076 ++
35077 ++ if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK))
35078 ++ return -EINVAL;
35079 ++
35080 ++ vma_m = pax_find_mirror_vma(vma);
35081 ++ if (vma_m) {
35082 ++ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
35083 ++ if (mm->map_count >= sysctl_max_map_count-1)
35084 ++ return -ENOMEM;
35085 ++ } else if (mm->map_count >= sysctl_max_map_count)
35086 ++ return -ENOMEM;
35087 ++
35088 ++ new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35089 ++ if (!new)
35090 ++ return -ENOMEM;
35091 ++
35092 ++ if (vma_m) {
35093 ++ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35094 ++ if (!new_m) {
35095 ++ kmem_cache_free(vm_area_cachep, new);
35096 ++ return -ENOMEM;
35097 ++ }
35098 ++ }
35099 ++
35100 ++ /* most fields are the same, copy all, and then fixup */
35101 ++ *new = *vma;
35102 ++
35103 ++ if (new_below)
35104 ++ new->vm_end = addr;
35105 ++ else {
35106 ++ new->vm_start = addr;
35107 ++ new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
35108 ++ }
35109 ++
35110 ++ if (vma_m) {
35111 ++ *new_m = *vma_m;
35112 ++ new_m->vm_mirror = new;
35113 ++ new->vm_mirror = new_m;
35114 ++
35115 ++ if (new_below)
35116 ++ new_m->vm_end = addr_m;
35117 ++ else {
35118 ++ new_m->vm_start = addr_m;
35119 ++ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
35120 ++ }
35121 ++ }
35122 ++
35123 ++ pol = mpol_dup(vma_policy(vma));
35124 ++ if (IS_ERR(pol)) {
35125 ++ if (new_m)
35126 ++ kmem_cache_free(vm_area_cachep, new_m);
35127 ++ kmem_cache_free(vm_area_cachep, new);
35128 ++ return PTR_ERR(pol);
35129 ++ }
35130 ++ vma_set_policy(new, pol);
35131 ++
35132 ++ if (new->vm_file) {
35133 ++ get_file(new->vm_file);
35134 ++ if (vma->vm_flags & VM_EXECUTABLE)
35135 ++ added_exe_file_vma(mm);
35136 ++ }
35137 ++
35138 ++ if (new->vm_ops && new->vm_ops->open)
35139 ++ new->vm_ops->open(new);
35140 ++
35141 ++ if (new_below)
35142 ++ vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff +
35143 ++ ((addr - new->vm_start) >> PAGE_SHIFT), new);
35144 ++ else
35145 ++ vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
35146 ++
35147 ++ if (vma_m) {
35148 ++ mpol_get(pol);
35149 ++ vma_set_policy(new_m, pol);
35150 ++
35151 ++ if (new_m->vm_file) {
35152 ++ get_file(new_m->vm_file);
35153 ++ if (vma_m->vm_flags & VM_EXECUTABLE)
35154 ++ added_exe_file_vma(mm);
35155 ++ }
35156 ++
35157 ++ if (new_m->vm_ops && new_m->vm_ops->open)
35158 ++ new_m->vm_ops->open(new_m);
35159 ++
35160 ++ if (new_below)
35161 ++ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
35162 ++ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
35163 ++ else
35164 ++ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
35165 ++ }
35166 ++
35167 ++ return 0;
35168 ++}
35169 ++#else
35170 + int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
35171 + unsigned long addr, int new_below)
35172 + {
35173 +@@ -1862,17 +2225,37 @@ int split_vma(struct mm_struct * mm, str
35174 +
35175 + return 0;
35176 + }
35177 ++#endif
35178 +
35179 + /* Munmap is split into 2 main parts -- this part which finds
35180 + * what needs doing, and the areas themselves, which do the
35181 + * work. This now handles partial unmappings.
35182 + * Jeremy Fitzhardinge <jeremy@××××.org>
35183 + */
35184 ++#ifdef CONFIG_PAX_SEGMEXEC
35185 + int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35186 + {
35187 ++ int ret = __do_munmap(mm, start, len);
35188 ++ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
35189 ++ return ret;
35190 ++
35191 ++ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
35192 ++}
35193 ++
35194 ++int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35195 ++#else
35196 ++int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35197 ++#endif
35198 ++{
35199 + unsigned long end;
35200 + struct vm_area_struct *vma, *prev, *last;
35201 +
35202 ++ /*
35203 ++ * mm->mmap_sem is required to protect against another thread
35204 ++ * changing the mappings in case we sleep.
35205 ++ */
35206 ++ verify_mm_writelocked(mm);
35207 ++
35208 + if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
35209 + return -EINVAL;
35210 +
35211 +@@ -1922,6 +2305,8 @@ int do_munmap(struct mm_struct *mm, unsi
35212 + /* Fix up all other VM information */
35213 + remove_vma_list(mm, vma);
35214 +
35215 ++ track_exec_limit(mm, start, end, 0UL);
35216 ++
35217 + return 0;
35218 + }
35219 +
35220 +@@ -1934,22 +2319,18 @@ asmlinkage long sys_munmap(unsigned long
35221 +
35222 + profile_munmap(addr);
35223 +
35224 ++#ifdef CONFIG_PAX_SEGMEXEC
35225 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
35226 ++ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
35227 ++ return -EINVAL;
35228 ++#endif
35229 ++
35230 + down_write(&mm->mmap_sem);
35231 + ret = do_munmap(mm, addr, len);
35232 + up_write(&mm->mmap_sem);
35233 + return ret;
35234 + }
35235 +
35236 +-static inline void verify_mm_writelocked(struct mm_struct *mm)
35237 +-{
35238 +-#ifdef CONFIG_DEBUG_VM
35239 +- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
35240 +- WARN_ON(1);
35241 +- up_read(&mm->mmap_sem);
35242 +- }
35243 +-#endif
35244 +-}
35245 +-
35246 + /*
35247 + * this is really a simplified "do_mmap". it only handles
35248 + * anonymous maps. eventually we may be able to do some
35249 +@@ -1963,6 +2344,11 @@ unsigned long do_brk(unsigned long addr,
35250 + struct rb_node ** rb_link, * rb_parent;
35251 + pgoff_t pgoff = addr >> PAGE_SHIFT;
35252 + int error;
35253 ++ unsigned long charged;
35254 ++
35255 ++#ifdef CONFIG_PAX_SEGMEXEC
35256 ++ struct vm_area_struct *vma_m = NULL;
35257 ++#endif
35258 +
35259 + len = PAGE_ALIGN(len);
35260 + if (!len)
35261 +@@ -1980,19 +2366,34 @@ unsigned long do_brk(unsigned long addr,
35262 +
35263 + flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
35264 +
35265 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
35266 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
35267 ++ flags &= ~VM_EXEC;
35268 ++
35269 ++#ifdef CONFIG_PAX_MPROTECT
35270 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
35271 ++ flags &= ~VM_MAYEXEC;
35272 ++#endif
35273 ++
35274 ++ }
35275 ++#endif
35276 ++
35277 + error = arch_mmap_check(addr, len, flags);
35278 + if (error)
35279 + return error;
35280 +
35281 ++ charged = len >> PAGE_SHIFT;
35282 ++
35283 + /*
35284 + * mlock MCL_FUTURE?
35285 + */
35286 + if (mm->def_flags & VM_LOCKED) {
35287 + unsigned long locked, lock_limit;
35288 +- locked = len >> PAGE_SHIFT;
35289 ++ locked = charged;
35290 + locked += mm->locked_vm;
35291 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
35292 + lock_limit >>= PAGE_SHIFT;
35293 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
35294 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
35295 + return -EAGAIN;
35296 + }
35297 +@@ -2006,22 +2407,22 @@ unsigned long do_brk(unsigned long addr,
35298 + /*
35299 + * Clear old maps. this also does some error checking for us
35300 + */
35301 +- munmap_back:
35302 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35303 + if (vma && vma->vm_start < addr + len) {
35304 + if (do_munmap(mm, addr, len))
35305 + return -ENOMEM;
35306 +- goto munmap_back;
35307 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35308 ++ BUG_ON(vma && vma->vm_start < addr + len);
35309 + }
35310 +
35311 + /* Check against address space limits *after* clearing old maps... */
35312 +- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
35313 ++ if (!may_expand_vm(mm, charged))
35314 + return -ENOMEM;
35315 +
35316 + if (mm->map_count > sysctl_max_map_count)
35317 + return -ENOMEM;
35318 +
35319 +- if (security_vm_enough_memory(len >> PAGE_SHIFT))
35320 ++ if (security_vm_enough_memory(charged))
35321 + return -ENOMEM;
35322 +
35323 + /* Can we just expand an old private anonymous mapping? */
35324 +@@ -2034,10 +2435,21 @@ unsigned long do_brk(unsigned long addr,
35325 + */
35326 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35327 + if (!vma) {
35328 +- vm_unacct_memory(len >> PAGE_SHIFT);
35329 ++ vm_unacct_memory(charged);
35330 + return -ENOMEM;
35331 + }
35332 +
35333 ++#ifdef CONFIG_PAX_SEGMEXEC
35334 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) {
35335 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35336 ++ if (!vma_m) {
35337 ++ kmem_cache_free(vm_area_cachep, vma);
35338 ++ vm_unacct_memory(charged);
35339 ++ return -ENOMEM;
35340 ++ }
35341 ++ }
35342 ++#endif
35343 ++
35344 + vma->vm_mm = mm;
35345 + vma->vm_start = addr;
35346 + vma->vm_end = addr + len;
35347 +@@ -2045,12 +2457,19 @@ unsigned long do_brk(unsigned long addr,
35348 + vma->vm_flags = flags;
35349 + vma->vm_page_prot = vm_get_page_prot(flags);
35350 + vma_link(mm, vma, prev, rb_link, rb_parent);
35351 ++
35352 ++#ifdef CONFIG_PAX_SEGMEXEC
35353 ++ if (vma_m)
35354 ++ pax_mirror_vma(vma_m, vma);
35355 ++#endif
35356 ++
35357 + out:
35358 +- mm->total_vm += len >> PAGE_SHIFT;
35359 ++ mm->total_vm += charged;
35360 + if (flags & VM_LOCKED) {
35361 +- mm->locked_vm += len >> PAGE_SHIFT;
35362 ++ mm->locked_vm += charged;
35363 + make_pages_present(addr, addr + len);
35364 + }
35365 ++ track_exec_limit(mm, addr, addr + len, flags);
35366 + return addr;
35367 + }
35368 +
35369 +@@ -2082,8 +2501,10 @@ void exit_mmap(struct mm_struct *mm)
35370 + * Walk the list again, actually closing and freeing it,
35371 + * with preemption enabled, without holding any MM locks.
35372 + */
35373 +- while (vma)
35374 ++ while (vma) {
35375 ++ vma->vm_mirror = NULL;
35376 + vma = remove_vma(vma);
35377 ++ }
35378 +
35379 + BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
35380 + }
35381 +@@ -2097,6 +2518,10 @@ int insert_vm_struct(struct mm_struct *
35382 + struct vm_area_struct * __vma, * prev;
35383 + struct rb_node ** rb_link, * rb_parent;
35384 +
35385 ++#ifdef CONFIG_PAX_SEGMEXEC
35386 ++ struct vm_area_struct *vma_m = NULL;
35387 ++#endif
35388 ++
35389 + /*
35390 + * The vm_pgoff of a purely anonymous vma should be irrelevant
35391 + * until its first write fault, when page's anon_vma and index
35392 +@@ -2119,7 +2544,22 @@ int insert_vm_struct(struct mm_struct *
35393 + if ((vma->vm_flags & VM_ACCOUNT) &&
35394 + security_vm_enough_memory_mm(mm, vma_pages(vma)))
35395 + return -ENOMEM;
35396 ++
35397 ++#ifdef CONFIG_PAX_SEGMEXEC
35398 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
35399 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35400 ++ if (!vma_m)
35401 ++ return -ENOMEM;
35402 ++ }
35403 ++#endif
35404 ++
35405 + vma_link(mm, vma, prev, rb_link, rb_parent);
35406 ++
35407 ++#ifdef CONFIG_PAX_SEGMEXEC
35408 ++ if (vma_m)
35409 ++ pax_mirror_vma(vma_m, vma);
35410 ++#endif
35411 ++
35412 + return 0;
35413 + }
35414 +
35415 +@@ -2137,6 +2577,8 @@ struct vm_area_struct *copy_vma(struct v
35416 + struct rb_node **rb_link, *rb_parent;
35417 + struct mempolicy *pol;
35418 +
35419 ++ BUG_ON(vma->vm_mirror);
35420 ++
35421 + /*
35422 + * If anonymous vma has not yet been faulted, update new pgoff
35423 + * to match new location, to increase its chance of merging.
35424 +@@ -2180,6 +2622,35 @@ struct vm_area_struct *copy_vma(struct v
35425 + return new_vma;
35426 + }
35427 +
35428 ++#ifdef CONFIG_PAX_SEGMEXEC
35429 ++void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
35430 ++{
35431 ++ struct vm_area_struct *prev_m;
35432 ++ struct rb_node **rb_link_m, *rb_parent_m;
35433 ++ struct mempolicy *pol_m;
35434 ++
35435 ++ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
35436 ++ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
35437 ++ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
35438 ++ *vma_m = *vma;
35439 ++ pol_m = vma_policy(vma_m);
35440 ++ mpol_get(pol_m);
35441 ++ vma_set_policy(vma_m, pol_m);
35442 ++ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
35443 ++ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
35444 ++ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
35445 ++ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
35446 ++ if (vma_m->vm_file)
35447 ++ get_file(vma_m->vm_file);
35448 ++ if (vma_m->vm_ops && vma_m->vm_ops->open)
35449 ++ vma_m->vm_ops->open(vma_m);
35450 ++ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
35451 ++ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
35452 ++ vma_m->vm_mirror = vma;
35453 ++ vma->vm_mirror = vma_m;
35454 ++}
35455 ++#endif
35456 ++
35457 + /*
35458 + * Return true if the calling process may expand its vm space by the passed
35459 + * number of pages
35460 +@@ -2190,7 +2661,7 @@ int may_expand_vm(struct mm_struct *mm,
35461 + unsigned long lim;
35462 +
35463 + lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
35464 +-
35465 ++ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
35466 + if (cur + npages > lim)
35467 + return 0;
35468 + return 1;
35469 +@@ -2259,6 +2730,15 @@ int install_special_mapping(struct mm_st
35470 + vma->vm_start = addr;
35471 + vma->vm_end = addr + len;
35472 +
35473 ++#ifdef CONFIG_PAX_MPROTECT
35474 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
35475 ++ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
35476 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
35477 ++ else
35478 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
35479 ++ }
35480 ++#endif
35481 ++
35482 + vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
35483 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
35484 +
35485 +diff -urNp linux-2.6.27.10/mm/mprotect.c linux-2.6.27.10/mm/mprotect.c
35486 +--- linux-2.6.27.10/mm/mprotect.c 2008-11-07 12:55:34.000000000 -0500
35487 ++++ linux-2.6.27.10/mm/mprotect.c 2008-12-21 00:45:45.000000000 -0500
35488 +@@ -22,10 +22,17 @@
35489 + #include <linux/swap.h>
35490 + #include <linux/swapops.h>
35491 + #include <linux/mmu_notifier.h>
35492 ++#include <linux/grsecurity.h>
35493 ++
35494 ++#ifdef CONFIG_PAX_MPROTECT
35495 ++#include <linux/elf.h>
35496 ++#endif
35497 ++
35498 + #include <asm/uaccess.h>
35499 + #include <asm/pgtable.h>
35500 + #include <asm/cacheflush.h>
35501 + #include <asm/tlbflush.h>
35502 ++#include <asm/mmu_context.h>
35503 +
35504 + #ifndef pgprot_modify
35505 + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
35506 +@@ -133,6 +140,48 @@ static void change_protection(struct vm_
35507 + flush_tlb_range(vma, start, end);
35508 + }
35509 +
35510 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35511 ++/* called while holding the mmap semaphor for writing except stack expansion */
35512 ++void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
35513 ++{
35514 ++ unsigned long oldlimit, newlimit = 0UL;
35515 ++
35516 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
35517 ++ return;
35518 ++
35519 ++ spin_lock(&mm->page_table_lock);
35520 ++ oldlimit = mm->context.user_cs_limit;
35521 ++ if ((prot & VM_EXEC) && oldlimit < end)
35522 ++ /* USER_CS limit moved up */
35523 ++ newlimit = end;
35524 ++ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
35525 ++ /* USER_CS limit moved down */
35526 ++ newlimit = start;
35527 ++
35528 ++ if (newlimit) {
35529 ++ mm->context.user_cs_limit = newlimit;
35530 ++
35531 ++#ifdef CONFIG_SMP
35532 ++ wmb();
35533 ++ cpus_clear(mm->context.cpu_user_cs_mask);
35534 ++ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
35535 ++#endif
35536 ++
35537 ++ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
35538 ++ }
35539 ++ spin_unlock(&mm->page_table_lock);
35540 ++ if (newlimit == end) {
35541 ++ struct vm_area_struct *vma = find_vma(mm, oldlimit);
35542 ++
35543 ++ for (; vma && vma->vm_start < end; vma = vma->vm_next)
35544 ++ if (is_vm_hugetlb_page(vma))
35545 ++ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
35546 ++ else
35547 ++ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
35548 ++ }
35549 ++}
35550 ++#endif
35551 ++
35552 + int
35553 + mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
35554 + unsigned long start, unsigned long end, unsigned long newflags)
35555 +@@ -145,6 +194,14 @@ mprotect_fixup(struct vm_area_struct *vm
35556 + int error;
35557 + int dirty_accountable = 0;
35558 +
35559 ++#ifdef CONFIG_PAX_SEGMEXEC
35560 ++ struct vm_area_struct *vma_m = NULL;
35561 ++ unsigned long start_m, end_m;
35562 ++
35563 ++ start_m = start + SEGMEXEC_TASK_SIZE;
35564 ++ end_m = end + SEGMEXEC_TASK_SIZE;
35565 ++#endif
35566 ++
35567 + if (newflags == oldflags) {
35568 + *pprev = vma;
35569 + return 0;
35570 +@@ -165,6 +222,38 @@ mprotect_fixup(struct vm_area_struct *vm
35571 + }
35572 + }
35573 +
35574 ++#ifdef CONFIG_PAX_SEGMEXEC
35575 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
35576 ++ if (start != vma->vm_start) {
35577 ++ error = split_vma(mm, vma, start, 1);
35578 ++ if (error)
35579 ++ goto fail;
35580 ++ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
35581 ++ *pprev = (*pprev)->vm_next;
35582 ++ }
35583 ++
35584 ++ if (end != vma->vm_end) {
35585 ++ error = split_vma(mm, vma, end, 0);
35586 ++ if (error)
35587 ++ goto fail;
35588 ++ }
35589 ++
35590 ++ if (pax_find_mirror_vma(vma)) {
35591 ++ error = __do_munmap(mm, start_m, end_m - start_m);
35592 ++ if (error)
35593 ++ goto fail;
35594 ++ } else {
35595 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35596 ++ if (!vma_m) {
35597 ++ error = -ENOMEM;
35598 ++ goto fail;
35599 ++ }
35600 ++ vma->vm_flags = newflags;
35601 ++ pax_mirror_vma(vma_m, vma);
35602 ++ }
35603 ++ }
35604 ++#endif
35605 ++
35606 + /*
35607 + * First try to merge with previous and/or next vma.
35608 + */
35609 +@@ -196,8 +285,14 @@ success:
35610 + * held in write mode.
35611 + */
35612 + vma->vm_flags = newflags;
35613 ++
35614 ++#ifdef CONFIG_PAX_MPROTECT
35615 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35616 ++ current->binfmt->handle_mprotect(vma, newflags);
35617 ++#endif
35618 ++
35619 + vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
35620 +- vm_get_page_prot(newflags));
35621 ++ vm_get_page_prot(vma->vm_flags));
35622 +
35623 + if (vma_wants_writenotify(vma)) {
35624 + vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
35625 +@@ -238,6 +333,17 @@ sys_mprotect(unsigned long start, size_t
35626 + end = start + len;
35627 + if (end <= start)
35628 + return -ENOMEM;
35629 ++
35630 ++#ifdef CONFIG_PAX_SEGMEXEC
35631 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35632 ++ if (end > SEGMEXEC_TASK_SIZE)
35633 ++ return -EINVAL;
35634 ++ } else
35635 ++#endif
35636 ++
35637 ++ if (end > TASK_SIZE)
35638 ++ return -EINVAL;
35639 ++
35640 + if (!arch_validate_prot(prot))
35641 + return -EINVAL;
35642 +
35643 +@@ -245,7 +351,7 @@ sys_mprotect(unsigned long start, size_t
35644 + /*
35645 + * Does the application expect PROT_READ to imply PROT_EXEC:
35646 + */
35647 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
35648 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
35649 + prot |= PROT_EXEC;
35650 +
35651 + vm_flags = calc_vm_prot_bits(prot);
35652 +@@ -277,6 +383,16 @@ sys_mprotect(unsigned long start, size_t
35653 + if (start > vma->vm_start)
35654 + prev = vma;
35655 +
35656 ++ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
35657 ++ error = -EACCES;
35658 ++ goto out;
35659 ++ }
35660 ++
35661 ++#ifdef CONFIG_PAX_MPROTECT
35662 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35663 ++ current->binfmt->handle_mprotect(vma, vm_flags);
35664 ++#endif
35665 ++
35666 + for (nstart = start ; ; ) {
35667 + unsigned long newflags;
35668 +
35669 +@@ -300,6 +416,9 @@ sys_mprotect(unsigned long start, size_t
35670 + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
35671 + if (error)
35672 + goto out;
35673 ++
35674 ++ track_exec_limit(current->mm, nstart, tmp, vm_flags);
35675 ++
35676 + nstart = tmp;
35677 +
35678 + if (nstart < prev->vm_end)
35679 +diff -urNp linux-2.6.27.10/mm/mremap.c linux-2.6.27.10/mm/mremap.c
35680 +--- linux-2.6.27.10/mm/mremap.c 2008-11-07 12:55:34.000000000 -0500
35681 ++++ linux-2.6.27.10/mm/mremap.c 2008-11-18 03:38:45.000000000 -0500
35682 +@@ -111,6 +111,12 @@ static void move_ptes(struct vm_area_str
35683 + continue;
35684 + pte = ptep_clear_flush(vma, old_addr, old_pte);
35685 + pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
35686 ++
35687 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35688 ++ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
35689 ++ pte = pte_exprotect(pte);
35690 ++#endif
35691 ++
35692 + set_pte_at(mm, new_addr, new_pte, pte);
35693 + }
35694 +
35695 +@@ -260,6 +266,7 @@ unsigned long do_mremap(unsigned long ad
35696 + struct vm_area_struct *vma;
35697 + unsigned long ret = -EINVAL;
35698 + unsigned long charged = 0;
35699 ++ unsigned long pax_task_size = TASK_SIZE;
35700 +
35701 + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
35702 + goto out;
35703 +@@ -278,6 +285,15 @@ unsigned long do_mremap(unsigned long ad
35704 + if (!new_len)
35705 + goto out;
35706 +
35707 ++#ifdef CONFIG_PAX_SEGMEXEC
35708 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
35709 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
35710 ++#endif
35711 ++
35712 ++ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
35713 ++ old_len > pax_task_size || addr > pax_task_size-old_len)
35714 ++ goto out;
35715 ++
35716 + /* new_addr is only valid if MREMAP_FIXED is specified */
35717 + if (flags & MREMAP_FIXED) {
35718 + if (new_addr & ~PAGE_MASK)
35719 +@@ -285,16 +301,13 @@ unsigned long do_mremap(unsigned long ad
35720 + if (!(flags & MREMAP_MAYMOVE))
35721 + goto out;
35722 +
35723 +- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
35724 ++ if (new_addr > pax_task_size - new_len)
35725 + goto out;
35726 +
35727 + /* Check if the location we're moving into overlaps the
35728 + * old location at all, and fail if it does.
35729 + */
35730 +- if ((new_addr <= addr) && (new_addr+new_len) > addr)
35731 +- goto out;
35732 +-
35733 +- if ((addr <= new_addr) && (addr+old_len) > new_addr)
35734 ++ if (addr + old_len > new_addr && new_addr + new_len > addr)
35735 + goto out;
35736 +
35737 + ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
35738 +@@ -332,6 +345,14 @@ unsigned long do_mremap(unsigned long ad
35739 + ret = -EINVAL;
35740 + goto out;
35741 + }
35742 ++
35743 ++#ifdef CONFIG_PAX_SEGMEXEC
35744 ++ if (pax_find_mirror_vma(vma)) {
35745 ++ ret = -EINVAL;
35746 ++ goto out;
35747 ++ }
35748 ++#endif
35749 ++
35750 + /* We can't remap across vm area boundaries */
35751 + if (old_len > vma->vm_end - addr)
35752 + goto out;
35753 +@@ -365,7 +386,7 @@ unsigned long do_mremap(unsigned long ad
35754 + if (old_len == vma->vm_end - addr &&
35755 + !((flags & MREMAP_FIXED) && (addr != new_addr)) &&
35756 + (old_len != new_len || !(flags & MREMAP_MAYMOVE))) {
35757 +- unsigned long max_addr = TASK_SIZE;
35758 ++ unsigned long max_addr = pax_task_size;
35759 + if (vma->vm_next)
35760 + max_addr = vma->vm_next->vm_start;
35761 + /* can we just expand the current mapping? */
35762 +@@ -383,6 +404,7 @@ unsigned long do_mremap(unsigned long ad
35763 + addr + new_len);
35764 + }
35765 + ret = addr;
35766 ++ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
35767 + goto out;
35768 + }
35769 + }
35770 +@@ -393,8 +415,8 @@ unsigned long do_mremap(unsigned long ad
35771 + */
35772 + ret = -ENOMEM;
35773 + if (flags & MREMAP_MAYMOVE) {
35774 ++ unsigned long map_flags = 0;
35775 + if (!(flags & MREMAP_FIXED)) {
35776 +- unsigned long map_flags = 0;
35777 + if (vma->vm_flags & VM_MAYSHARE)
35778 + map_flags |= MAP_SHARED;
35779 +
35780 +@@ -409,7 +431,12 @@ unsigned long do_mremap(unsigned long ad
35781 + if (ret)
35782 + goto out;
35783 + }
35784 ++ map_flags = vma->vm_flags;
35785 + ret = move_vma(vma, addr, old_len, new_len, new_addr);
35786 ++ if (!(ret & ~PAGE_MASK)) {
35787 ++ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
35788 ++ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
35789 ++ }
35790 + }
35791 + out:
35792 + if (ret & ~PAGE_MASK)
35793 +diff -urNp linux-2.6.27.10/mm/nommu.c linux-2.6.27.10/mm/nommu.c
35794 +--- linux-2.6.27.10/mm/nommu.c 2008-11-07 12:55:34.000000000 -0500
35795 ++++ linux-2.6.27.10/mm/nommu.c 2008-11-18 03:38:45.000000000 -0500
35796 +@@ -437,15 +437,6 @@ struct vm_area_struct *find_vma(struct m
35797 + }
35798 + EXPORT_SYMBOL(find_vma);
35799 +
35800 +-/*
35801 +- * find a VMA
35802 +- * - we don't extend stack VMAs under NOMMU conditions
35803 +- */
35804 +-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
35805 +-{
35806 +- return find_vma(mm, addr);
35807 +-}
35808 +-
35809 + int expand_stack(struct vm_area_struct *vma, unsigned long address)
35810 + {
35811 + return -ENOMEM;
35812 +diff -urNp linux-2.6.27.10/mm/page_alloc.c linux-2.6.27.10/mm/page_alloc.c
35813 +--- linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:12.000000000 -0500
35814 ++++ linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:22.000000000 -0500
35815 +@@ -515,9 +515,20 @@ static void free_pages_bulk(struct zone
35816 +
35817 + static void free_one_page(struct zone *zone, struct page *page, int order)
35818 + {
35819 ++
35820 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35821 ++ unsigned long index = 1UL << order;
35822 ++#endif
35823 ++
35824 + spin_lock(&zone->lock);
35825 + zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
35826 + zone->pages_scanned = 0;
35827 ++
35828 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35829 ++ for (; index; --index)
35830 ++ sanitize_highpage(page + index - 1);
35831 ++#endif
35832 ++
35833 + __free_one_page(page, zone, order);
35834 + spin_unlock(&zone->lock);
35835 + }
35836 +@@ -635,8 +646,10 @@ static int prep_new_page(struct page *pa
35837 + arch_alloc_page(page, order);
35838 + kernel_map_pages(page, 1 << order, 1);
35839 +
35840 ++#ifndef CONFIG_PAX_MEMORY_SANITIZE
35841 + if (gfp_flags & __GFP_ZERO)
35842 + prep_zero_page(page, order, gfp_flags);
35843 ++#endif
35844 +
35845 + if (order && (gfp_flags & __GFP_COMP))
35846 + prep_compound_page(page, order);
35847 +@@ -1009,6 +1022,11 @@ static void free_hot_cold_page(struct pa
35848 + list_add(&page->lru, &pcp->list);
35849 + set_page_private(page, get_pageblock_migratetype(page));
35850 + pcp->count++;
35851 ++
35852 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35853 ++ sanitize_highpage(page);
35854 ++#endif
35855 ++
35856 + if (pcp->count >= pcp->high) {
35857 + free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
35858 + pcp->count -= pcp->batch;
35859 +diff -urNp linux-2.6.27.10/mm/rmap.c linux-2.6.27.10/mm/rmap.c
35860 +--- linux-2.6.27.10/mm/rmap.c 2008-11-07 12:55:34.000000000 -0500
35861 ++++ linux-2.6.27.10/mm/rmap.c 2008-11-18 03:38:45.000000000 -0500
35862 +@@ -91,6 +91,10 @@ int anon_vma_prepare(struct vm_area_stru
35863 + struct mm_struct *mm = vma->vm_mm;
35864 + struct anon_vma *allocated;
35865 +
35866 ++#ifdef CONFIG_PAX_SEGMEXEC
35867 ++ struct vm_area_struct *vma_m;
35868 ++#endif
35869 ++
35870 + anon_vma = find_mergeable_anon_vma(vma);
35871 + allocated = NULL;
35872 + if (!anon_vma) {
35873 +@@ -104,6 +108,15 @@ int anon_vma_prepare(struct vm_area_stru
35874 + /* page_table_lock to protect against threads */
35875 + spin_lock(&mm->page_table_lock);
35876 + if (likely(!vma->anon_vma)) {
35877 ++
35878 ++#ifdef CONFIG_PAX_SEGMEXEC
35879 ++ vma_m = pax_find_mirror_vma(vma);
35880 ++ if (vma_m) {
35881 ++ vma_m->anon_vma = anon_vma;
35882 ++ __anon_vma_link(vma_m);
35883 ++ }
35884 ++#endif
35885 ++
35886 + vma->anon_vma = anon_vma;
35887 + list_add_tail(&vma->anon_vma_node, &anon_vma->head);
35888 + allocated = NULL;
35889 +diff -urNp linux-2.6.27.10/mm/shmem.c linux-2.6.27.10/mm/shmem.c
35890 +--- linux-2.6.27.10/mm/shmem.c 2008-11-07 12:55:34.000000000 -0500
35891 ++++ linux-2.6.27.10/mm/shmem.c 2008-11-18 03:38:45.000000000 -0500
35892 +@@ -2483,7 +2483,7 @@ static struct file_system_type tmpfs_fs_
35893 + .get_sb = shmem_get_sb,
35894 + .kill_sb = kill_litter_super,
35895 + };
35896 +-static struct vfsmount *shm_mnt;
35897 ++struct vfsmount *shm_mnt;
35898 +
35899 + static int __init init_tmpfs(void)
35900 + {
35901 +diff -urNp linux-2.6.27.10/mm/slab.c linux-2.6.27.10/mm/slab.c
35902 +--- linux-2.6.27.10/mm/slab.c 2008-11-07 12:55:34.000000000 -0500
35903 ++++ linux-2.6.27.10/mm/slab.c 2008-11-18 03:38:45.000000000 -0500
35904 +@@ -304,7 +304,7 @@ struct kmem_list3 {
35905 + * Need this for bootstrapping a per node allocator.
35906 + */
35907 + #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
35908 +-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
35909 ++struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
35910 + #define CACHE_CACHE 0
35911 + #define SIZE_AC MAX_NUMNODES
35912 + #define SIZE_L3 (2 * MAX_NUMNODES)
35913 +@@ -653,14 +653,14 @@ struct cache_names {
35914 + static struct cache_names __initdata cache_names[] = {
35915 + #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
35916 + #include <linux/kmalloc_sizes.h>
35917 +- {NULL,}
35918 ++ {NULL, NULL}
35919 + #undef CACHE
35920 + };
35921 +
35922 + static struct arraycache_init initarray_cache __initdata =
35923 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35924 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35925 + static struct arraycache_init initarray_generic =
35926 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35927 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35928 +
35929 + /* internal cache of cache description objs */
35930 + static struct kmem_cache cache_cache = {
35931 +@@ -2996,7 +2996,7 @@ retry:
35932 + * there must be at least one object available for
35933 + * allocation.
35934 + */
35935 +- BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num);
35936 ++ BUG_ON(slabp->inuse >= cachep->num);
35937 +
35938 + while (slabp->inuse < cachep->num && batchcount--) {
35939 + STATS_INC_ALLOCED(cachep);
35940 +diff -urNp linux-2.6.27.10/mm/tiny-shmem.c linux-2.6.27.10/mm/tiny-shmem.c
35941 +--- linux-2.6.27.10/mm/tiny-shmem.c 2008-11-07 12:55:34.000000000 -0500
35942 ++++ linux-2.6.27.10/mm/tiny-shmem.c 2008-11-18 03:38:45.000000000 -0500
35943 +@@ -26,7 +26,7 @@ static struct file_system_type tmpfs_fs_
35944 + .kill_sb = kill_litter_super,
35945 + };
35946 +
35947 +-static struct vfsmount *shm_mnt;
35948 ++struct vfsmount *shm_mnt;
35949 +
35950 + static int __init init_tmpfs(void)
35951 + {
35952 +diff -urNp linux-2.6.27.10/mm/util.c linux-2.6.27.10/mm/util.c
35953 +--- linux-2.6.27.10/mm/util.c 2008-11-07 12:55:34.000000000 -0500
35954 ++++ linux-2.6.27.10/mm/util.c 2008-11-18 03:38:45.000000000 -0500
35955 +@@ -167,6 +167,12 @@ EXPORT_SYMBOL(strndup_user);
35956 + void arch_pick_mmap_layout(struct mm_struct *mm)
35957 + {
35958 + mm->mmap_base = TASK_UNMAPPED_BASE;
35959 ++
35960 ++#ifdef CONFIG_PAX_RANDMMAP
35961 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
35962 ++ mm->mmap_base += mm->delta_mmap;
35963 ++#endif
35964 ++
35965 + mm->get_unmapped_area = arch_get_unmapped_area;
35966 + mm->unmap_area = arch_unmap_area;
35967 + }
35968 +diff -urNp linux-2.6.27.10/mm/vmalloc.c linux-2.6.27.10/mm/vmalloc.c
35969 +--- linux-2.6.27.10/mm/vmalloc.c 2008-11-07 12:55:34.000000000 -0500
35970 ++++ linux-2.6.27.10/mm/vmalloc.c 2008-11-18 03:38:45.000000000 -0500
35971 +@@ -98,19 +98,36 @@ static int vmap_pte_range(pmd_t *pmd, un
35972 + unsigned long end, pgprot_t prot, struct page ***pages)
35973 + {
35974 + pte_t *pte;
35975 ++ int ret = -ENOMEM;
35976 ++
35977 ++#ifdef CONFIG_PAX_KERNEXEC
35978 ++ unsigned long cr0;
35979 ++#endif
35980 +
35981 + pte = pte_alloc_kernel(pmd, addr);
35982 + if (!pte)
35983 + return -ENOMEM;
35984 ++
35985 ++#ifdef CONFIG_PAX_KERNEXEC
35986 ++ pax_open_kernel(cr0);
35987 ++#endif
35988 ++
35989 + do {
35990 + struct page *page = **pages;
35991 + WARN_ON(!pte_none(*pte));
35992 + if (!page)
35993 +- return -ENOMEM;
35994 ++ goto out;
35995 + set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
35996 + (*pages)++;
35997 + } while (pte++, addr += PAGE_SIZE, addr != end);
35998 +- return 0;
35999 ++ ret = 0;
36000 ++out:
36001 ++
36002 ++#ifdef CONFIG_PAX_KERNEXEC
36003 ++ pax_close_kernel(cr0);
36004 ++#endif
36005 ++
36006 ++ return ret;
36007 + }
36008 +
36009 + static inline int vmap_pmd_range(pud_t *pud, unsigned long addr,
36010 +@@ -215,6 +232,16 @@ __get_vm_area_node(unsigned long size, u
36011 + unsigned long addr;
36012 +
36013 + BUG_ON(in_interrupt());
36014 ++
36015 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
36016 ++ if (flags & VM_KERNEXEC) {
36017 ++ if (start != VMALLOC_START || end != VMALLOC_END)
36018 ++ return NULL;
36019 ++ start = (unsigned long)MODULES_VADDR;
36020 ++ end = (unsigned long)MODULES_END;
36021 ++ }
36022 ++#endif
36023 ++
36024 + if (flags & VM_IOREMAP) {
36025 + int bit = fls(size);
36026 +
36027 +@@ -248,20 +275,15 @@ __get_vm_area_node(unsigned long size, u
36028 + (unsigned long)tmp->addr, align);
36029 + continue;
36030 + }
36031 +- if ((size + addr) < addr)
36032 +- goto out;
36033 + if (size + addr <= (unsigned long)tmp->addr)
36034 +- goto found;
36035 ++ break;
36036 + addr = ALIGN(tmp->size + (unsigned long)tmp->addr, align);
36037 +- if (addr > end - size)
36038 +- goto out;
36039 + }
36040 + if ((size + addr) < addr)
36041 + goto out;
36042 + if (addr > end - size)
36043 + goto out;
36044 +
36045 +-found:
36046 + area->next = *p;
36047 + *p = area;
36048 +
36049 +@@ -466,6 +488,11 @@ void *vmap(struct page **pages, unsigned
36050 + if (count > num_physpages)
36051 + return NULL;
36052 +
36053 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
36054 ++ if (!(pgprot_val(prot) & _PAGE_NX))
36055 ++ flags |= VM_KERNEXEC;
36056 ++#endif
36057 ++
36058 + area = get_vm_area_caller((count << PAGE_SHIFT), flags,
36059 + __builtin_return_address(0));
36060 + if (!area)
36061 +@@ -560,6 +587,13 @@ static void *__vmalloc_node(unsigned lon
36062 + if (!size || (size >> PAGE_SHIFT) > num_physpages)
36063 + return NULL;
36064 +
36065 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
36066 ++ if (!(pgprot_val(prot) & _PAGE_NX))
36067 ++ area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
36068 ++ node, gfp_mask, caller);
36069 ++ else
36070 ++#endif
36071 ++
36072 + area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
36073 + node, gfp_mask, caller);
36074 +
36075 +@@ -651,7 +685,7 @@ EXPORT_SYMBOL(vmalloc_node);
36076 +
36077 + void *vmalloc_exec(unsigned long size)
36078 + {
36079 +- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
36080 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC);
36081 + }
36082 +
36083 + #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
36084 +diff -urNp linux-2.6.27.10/net/bridge/br_stp_if.c linux-2.6.27.10/net/bridge/br_stp_if.c
36085 +--- linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-07 12:55:34.000000000 -0500
36086 ++++ linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-18 03:38:45.000000000 -0500
36087 +@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
36088 + char *envp[] = { NULL };
36089 +
36090 + if (br->stp_enabled == BR_USER_STP) {
36091 +- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
36092 ++ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
36093 + printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
36094 + br->dev->name, r);
36095 +
36096 +diff -urNp linux-2.6.27.10/net/core/flow.c linux-2.6.27.10/net/core/flow.c
36097 +--- linux-2.6.27.10/net/core/flow.c 2008-11-07 12:55:34.000000000 -0500
36098 ++++ linux-2.6.27.10/net/core/flow.c 2008-11-18 03:38:45.000000000 -0500
36099 +@@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT(
36100 +
36101 + static u32 flow_hash_shift;
36102 + #define flow_hash_size (1 << flow_hash_shift)
36103 +-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
36104 ++static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
36105 +
36106 + #define flow_table(cpu) (per_cpu(flow_tables, cpu))
36107 +
36108 +@@ -52,7 +52,7 @@ struct flow_percpu_info {
36109 + u32 hash_rnd;
36110 + int count;
36111 + };
36112 +-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
36113 ++static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
36114 +
36115 + #define flow_hash_rnd_recalc(cpu) \
36116 + (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
36117 +@@ -69,7 +69,7 @@ struct flow_flush_info {
36118 + atomic_t cpuleft;
36119 + struct completion completion;
36120 + };
36121 +-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
36122 ++static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
36123 +
36124 + #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
36125 +
36126 +diff -urNp linux-2.6.27.10/net/dccp/ccids/ccid3.c linux-2.6.27.10/net/dccp/ccids/ccid3.c
36127 +--- linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-07 12:55:34.000000000 -0500
36128 ++++ linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-18 03:38:45.000000000 -0500
36129 +@@ -43,7 +43,7 @@
36130 + static int ccid3_debug;
36131 + #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
36132 + #else
36133 +-#define ccid3_pr_debug(format, a...)
36134 ++#define ccid3_pr_debug(format, a...) do {} while (0)
36135 + #endif
36136 +
36137 + /*
36138 +diff -urNp linux-2.6.27.10/net/dccp/dccp.h linux-2.6.27.10/net/dccp/dccp.h
36139 +--- linux-2.6.27.10/net/dccp/dccp.h 2008-11-07 12:55:34.000000000 -0500
36140 ++++ linux-2.6.27.10/net/dccp/dccp.h 2008-11-18 03:38:45.000000000 -0500
36141 +@@ -43,8 +43,8 @@ extern int dccp_debug;
36142 + #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a)
36143 + #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
36144 + #else
36145 +-#define dccp_pr_debug(format, a...)
36146 +-#define dccp_pr_debug_cat(format, a...)
36147 ++#define dccp_pr_debug(format, a...) do {} while (0)
36148 ++#define dccp_pr_debug_cat(format, a...) do {} while (0)
36149 + #endif
36150 +
36151 + extern struct inet_hashinfo dccp_hashinfo;
36152 +diff -urNp linux-2.6.27.10/net/ipv4/inet_connection_sock.c linux-2.6.27.10/net/ipv4/inet_connection_sock.c
36153 +--- linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-07 12:55:34.000000000 -0500
36154 ++++ linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-18 03:38:45.000000000 -0500
36155 +@@ -15,6 +15,7 @@
36156 +
36157 + #include <linux/module.h>
36158 + #include <linux/jhash.h>
36159 ++#include <linux/grsecurity.h>
36160 +
36161 + #include <net/inet_connection_sock.h>
36162 + #include <net/inet_hashtables.h>
36163 +diff -urNp linux-2.6.27.10/net/ipv4/inet_hashtables.c linux-2.6.27.10/net/ipv4/inet_hashtables.c
36164 +--- linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-07 12:55:34.000000000 -0500
36165 ++++ linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-18 03:38:45.000000000 -0500
36166 +@@ -18,11 +18,14 @@
36167 + #include <linux/sched.h>
36168 + #include <linux/slab.h>
36169 + #include <linux/wait.h>
36170 ++#include <linux/grsecurity.h>
36171 +
36172 + #include <net/inet_connection_sock.h>
36173 + #include <net/inet_hashtables.h>
36174 + #include <net/ip.h>
36175 +
36176 ++extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
36177 ++
36178 + /*
36179 + * Allocate and initialize a new local port bind bucket.
36180 + * The bindhash mutex for snum's hash chain must be held here.
36181 +@@ -487,6 +490,8 @@ ok:
36182 + }
36183 + spin_unlock(&head->lock);
36184 +
36185 ++ gr_update_task_in_ip_table(current, inet_sk(sk));
36186 ++
36187 + if (tw) {
36188 + inet_twsk_deschedule(tw, death_row);
36189 + inet_twsk_put(tw);
36190 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c
36191 +--- linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 1969-12-31 19:00:00.000000000 -0500
36192 ++++ linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 2008-11-18 03:38:45.000000000 -0500
36193 +@@ -0,0 +1,114 @@
36194 ++/* Kernel module to add stealth support.
36195 ++ *
36196 ++ * Copyright (C) 2002-2006 Brad Spengler <spender@××××××××××.net>
36197 ++ *
36198 ++ */
36199 ++
36200 ++#include <linux/kernel.h>
36201 ++#include <linux/module.h>
36202 ++#include <linux/skbuff.h>
36203 ++#include <linux/net.h>
36204 ++#include <linux/sched.h>
36205 ++#include <linux/inet.h>
36206 ++#include <linux/stddef.h>
36207 ++
36208 ++#include <net/ip.h>
36209 ++#include <net/sock.h>
36210 ++#include <net/tcp.h>
36211 ++#include <net/udp.h>
36212 ++#include <net/route.h>
36213 ++#include <net/inet_common.h>
36214 ++
36215 ++#include <linux/netfilter_ipv4/ip_tables.h>
36216 ++
36217 ++MODULE_LICENSE("GPL");
36218 ++
36219 ++extern struct sock *udp_v4_lookup(struct net *net, u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
36220 ++
36221 ++static bool
36222 ++match(const struct sk_buff *skb,
36223 ++ const struct net_device *in,
36224 ++ const struct net_device *out,
36225 ++ const struct xt_match *match,
36226 ++ const void *matchinfo,
36227 ++ int offset,
36228 ++ unsigned int protoff,
36229 ++ bool *hotdrop)
36230 ++{
36231 ++ struct iphdr *ip = ip_hdr(skb);
36232 ++ struct tcphdr th;
36233 ++ struct udphdr uh;
36234 ++ struct sock *sk = NULL;
36235 ++
36236 ++ if (!ip || offset) return false;
36237 ++
36238 ++ switch(ip->protocol) {
36239 ++ case IPPROTO_TCP:
36240 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &th, sizeof(th)) < 0) {
36241 ++ *hotdrop = true;
36242 ++ return false;
36243 ++ }
36244 ++ if (!(th.syn && !th.ack)) return false;
36245 ++ sk = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, ip->daddr, th.dest, inet_iif(skb));
36246 ++ break;
36247 ++ case IPPROTO_UDP:
36248 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &uh, sizeof(uh)) < 0) {
36249 ++ *hotdrop = true;
36250 ++ return false;
36251 ++ }
36252 ++ sk = udp_v4_lookup(dev_net(skb->dev), ip->saddr, uh.source, ip->daddr, uh.dest, skb->dev->ifindex);
36253 ++ break;
36254 ++ default:
36255 ++ return false;
36256 ++ }
36257 ++
36258 ++ if(!sk) // port is being listened on, match this
36259 ++ return true;
36260 ++ else {
36261 ++ sock_put(sk);
36262 ++ return false;
36263 ++ }
36264 ++}
36265 ++
36266 ++/* Called when user tries to insert an entry of this type. */
36267 ++static bool
36268 ++checkentry(const char *tablename,
36269 ++ const void *nip,
36270 ++ const struct xt_match *match,
36271 ++ void *matchinfo,
36272 ++ unsigned int hook_mask)
36273 ++{
36274 ++ const struct ipt_ip *ip = (const struct ipt_ip *)nip;
36275 ++
36276 ++ if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
36277 ++ ((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
36278 ++ && (hook_mask & (1 << NF_INET_LOCAL_IN)))
36279 ++ return true;
36280 ++
36281 ++ printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
36282 ++
36283 ++ return false;
36284 ++}
36285 ++
36286 ++
36287 ++static struct xt_match stealth_match __read_mostly = {
36288 ++ .name = "stealth",
36289 ++ .family = AF_INET,
36290 ++ .match = match,
36291 ++ .checkentry = checkentry,
36292 ++ .destroy = NULL,
36293 ++ .me = THIS_MODULE
36294 ++};
36295 ++
36296 ++static int __init init(void)
36297 ++{
36298 ++ return xt_register_match(&stealth_match);
36299 ++}
36300 ++
36301 ++static void __exit fini(void)
36302 ++{
36303 ++ xt_unregister_match(&stealth_match);
36304 ++}
36305 ++
36306 ++module_init(init);
36307 ++module_exit(fini);
36308 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Kconfig linux-2.6.27.10/net/ipv4/netfilter/Kconfig
36309 +--- linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-07 12:55:34.000000000 -0500
36310 ++++ linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-18 03:38:45.000000000 -0500
36311 +@@ -111,6 +111,21 @@ config IP_NF_MATCH_ADDRTYPE
36312 + If you want to compile it as a module, say M here and read
36313 + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
36314 +
36315 ++config IP_NF_MATCH_STEALTH
36316 ++ tristate "stealth match support"
36317 ++ depends on IP_NF_IPTABLES
36318 ++ help
36319 ++ Enabling this option will drop all syn packets coming to unserved tcp
36320 ++ ports as well as all packets coming to unserved udp ports. If you
36321 ++ are using your system to route any type of packets (ie. via NAT)
36322 ++ you should put this module at the end of your ruleset, since it will
36323 ++ drop packets that aren't going to ports that are listening on your
36324 ++ machine itself, it doesn't take into account that the packet might be
36325 ++ destined for someone on your internal network if you're using NAT for
36326 ++ instance.
36327 ++
36328 ++ To compile it as a module, choose M here. If unsure, say N.
36329 ++
36330 + # `filter', generic and specific targets
36331 + config IP_NF_FILTER
36332 + tristate "Packet filtering"
36333 +@@ -407,4 +422,3 @@ config IP_NF_ARP_MANGLE
36334 + hardware and network addresses.
36335 +
36336 + endmenu
36337 +-
36338 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Makefile linux-2.6.27.10/net/ipv4/netfilter/Makefile
36339 +--- linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-07 12:55:34.000000000 -0500
36340 ++++ linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-18 03:38:45.000000000 -0500
36341 +@@ -59,6 +59,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
36342 + obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
36343 + obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
36344 + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
36345 ++obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
36346 + obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
36347 + obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
36348 +
36349 +diff -urNp linux-2.6.27.10/net/ipv4/tcp_ipv4.c linux-2.6.27.10/net/ipv4/tcp_ipv4.c
36350 +--- linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-07 12:55:34.000000000 -0500
36351 ++++ linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-18 03:38:45.000000000 -0500
36352 +@@ -59,6 +59,7 @@
36353 + #include <linux/jhash.h>
36354 + #include <linux/init.h>
36355 + #include <linux/times.h>
36356 ++#include <linux/grsecurity.h>
36357 +
36358 + #include <net/net_namespace.h>
36359 + #include <net/icmp.h>
36360 +diff -urNp linux-2.6.27.10/net/ipv4/udp.c linux-2.6.27.10/net/ipv4/udp.c
36361 +--- linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:16:52.000000000 -0500
36362 ++++ linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:13:47.000000000 -0500
36363 +@@ -97,6 +97,7 @@
36364 + #include <linux/skbuff.h>
36365 + #include <linux/proc_fs.h>
36366 + #include <linux/seq_file.h>
36367 ++#include <linux/grsecurity.h>
36368 + #include <net/net_namespace.h>
36369 + #include <net/icmp.h>
36370 + #include <net/route.h>
36371 +@@ -104,6 +105,11 @@
36372 + #include <net/xfrm.h>
36373 + #include "udp_impl.h"
36374 +
36375 ++extern int gr_search_udp_recvmsg(const struct sock *sk,
36376 ++ const struct sk_buff *skb);
36377 ++extern int gr_search_udp_sendmsg(const struct sock *sk,
36378 ++ const struct sockaddr_in *addr);
36379 ++
36380 + /*
36381 + * Snmp MIB for the UDP layer
36382 + */
36383 +@@ -302,6 +308,13 @@ static struct sock *__udp4_lib_lookup(st
36384 + return result;
36385 + }
36386 +
36387 ++struct sock *udp_v4_lookup(struct net *net, __be32 saddr, __be16 sport,
36388 ++ __be32 daddr, __be16 dport, int dif)
36389 ++{
36390 ++ return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash);
36391 ++}
36392 ++
36393 ++
36394 + static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
36395 + __be16 loc_port, __be32 loc_addr,
36396 + __be16 rmt_port, __be32 rmt_addr,
36397 +@@ -592,9 +605,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
36398 + dport = usin->sin_port;
36399 + if (dport == 0)
36400 + return -EINVAL;
36401 ++
36402 ++ if (!gr_search_udp_sendmsg(sk, usin))
36403 ++ return -EPERM;
36404 + } else {
36405 + if (sk->sk_state != TCP_ESTABLISHED)
36406 + return -EDESTADDRREQ;
36407 ++
36408 ++ if (!gr_search_udp_sendmsg(sk, NULL))
36409 ++ return -EPERM;
36410 ++
36411 + daddr = inet->daddr;
36412 + dport = inet->dport;
36413 + /* Open fast path for connected socket.
36414 +@@ -859,6 +879,11 @@ try_again:
36415 + if (!skb)
36416 + goto out;
36417 +
36418 ++ if (!gr_search_udp_recvmsg(sk, skb)) {
36419 ++ err = -EPERM;
36420 ++ goto out_free;
36421 ++ }
36422 ++
36423 + ulen = skb->len - sizeof(struct udphdr);
36424 + copied = len;
36425 + if (copied > ulen)
36426 +diff -urNp linux-2.6.27.10/net/ipv6/exthdrs.c linux-2.6.27.10/net/ipv6/exthdrs.c
36427 +--- linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-07 12:55:34.000000000 -0500
36428 ++++ linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-18 03:38:45.000000000 -0500
36429 +@@ -624,7 +624,7 @@ static struct tlvtype_proc tlvprochopopt
36430 + .type = IPV6_TLV_JUMBO,
36431 + .func = ipv6_hop_jumbo,
36432 + },
36433 +- { -1, }
36434 ++ { -1, NULL }
36435 + };
36436 +
36437 + int ipv6_parse_hopopts(struct sk_buff *skb)
36438 +diff -urNp linux-2.6.27.10/net/ipv6/raw.c linux-2.6.27.10/net/ipv6/raw.c
36439 +--- linux-2.6.27.10/net/ipv6/raw.c 2008-11-07 12:55:34.000000000 -0500
36440 ++++ linux-2.6.27.10/net/ipv6/raw.c 2008-11-18 03:38:45.000000000 -0500
36441 +@@ -600,7 +600,7 @@ out:
36442 + return err;
36443 + }
36444 +
36445 +-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
36446 ++static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
36447 + struct flowi *fl, struct rt6_info *rt,
36448 + unsigned int flags)
36449 + {
36450 +diff -urNp linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c
36451 +--- linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-07 12:55:34.000000000 -0500
36452 ++++ linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-18 03:38:45.000000000 -0500
36453 +@@ -371,7 +371,7 @@ static int ircomm_tty_open(struct tty_st
36454 + IRDA_DEBUG(2, "%s()\n", __func__ );
36455 +
36456 + line = tty->index;
36457 +- if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
36458 ++ if (line >= IRCOMM_TTY_PORTS) {
36459 + return -ENODEV;
36460 + }
36461 +
36462 +diff -urNp linux-2.6.27.10/net/sctp/socket.c linux-2.6.27.10/net/sctp/socket.c
36463 +--- linux-2.6.27.10/net/sctp/socket.c 2008-11-07 12:55:34.000000000 -0500
36464 ++++ linux-2.6.27.10/net/sctp/socket.c 2008-11-18 03:38:45.000000000 -0500
36465 +@@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
36466 + struct sctp_sndrcvinfo *sinfo;
36467 + struct sctp_initmsg *sinit;
36468 + sctp_assoc_t associd = 0;
36469 +- sctp_cmsgs_t cmsgs = { NULL };
36470 ++ sctp_cmsgs_t cmsgs = { NULL, NULL };
36471 + int err;
36472 + sctp_scope_t scope;
36473 + long timeo;
36474 +@@ -5616,7 +5616,6 @@ pp_found:
36475 + */
36476 + int reuse = sk->sk_reuse;
36477 + struct sock *sk2;
36478 +- struct hlist_node *node;
36479 +
36480 + SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
36481 + if (pp->fastreuse && sk->sk_reuse &&
36482 +diff -urNp linux-2.6.27.10/net/socket.c linux-2.6.27.10/net/socket.c
36483 +--- linux-2.6.27.10/net/socket.c 2008-11-07 12:55:34.000000000 -0500
36484 ++++ linux-2.6.27.10/net/socket.c 2008-11-18 03:38:45.000000000 -0500
36485 +@@ -87,6 +87,7 @@
36486 + #include <linux/audit.h>
36487 + #include <linux/wireless.h>
36488 + #include <linux/nsproxy.h>
36489 ++#include <linux/in.h>
36490 +
36491 + #include <asm/uaccess.h>
36492 + #include <asm/unistd.h>
36493 +@@ -97,6 +98,21 @@
36494 + #include <net/sock.h>
36495 + #include <linux/netfilter.h>
36496 +
36497 ++extern void gr_attach_curr_ip(const struct sock *sk);
36498 ++extern int gr_handle_sock_all(const int family, const int type,
36499 ++ const int protocol);
36500 ++extern int gr_handle_sock_server(const struct sockaddr *sck);
36501 ++extern int gr_handle_sock_server_other(const struct socket *sck);
36502 ++extern int gr_handle_sock_client(const struct sockaddr *sck);
36503 ++extern int gr_search_connect(const struct socket * sock,
36504 ++ const struct sockaddr_in * addr);
36505 ++extern int gr_search_bind(const struct socket * sock,
36506 ++ const struct sockaddr_in * addr);
36507 ++extern int gr_search_listen(const struct socket * sock);
36508 ++extern int gr_search_accept(const struct socket * sock);
36509 ++extern int gr_search_socket(const int domain, const int type,
36510 ++ const int protocol);
36511 ++
36512 + static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
36513 + static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
36514 + unsigned long nr_segs, loff_t pos);
36515 +@@ -300,7 +316,7 @@ static int sockfs_get_sb(struct file_sys
36516 + mnt);
36517 + }
36518 +
36519 +-static struct vfsmount *sock_mnt __read_mostly;
36520 ++struct vfsmount *sock_mnt __read_mostly;
36521 +
36522 + static struct file_system_type sock_fs_type = {
36523 + .name = "sockfs",
36524 +@@ -1236,6 +1252,16 @@ asmlinkage long sys_socket(int family, i
36525 + if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
36526 + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
36527 +
36528 ++ if(!gr_search_socket(family, type, protocol)) {
36529 ++ retval = -EACCES;
36530 ++ goto out;
36531 ++ }
36532 ++
36533 ++ if (gr_handle_sock_all(family, type, protocol)) {
36534 ++ retval = -EACCES;
36535 ++ goto out;
36536 ++ }
36537 ++
36538 + retval = sock_create(family, type, protocol, &sock);
36539 + if (retval < 0)
36540 + goto out;
36541 +@@ -1375,6 +1401,12 @@ asmlinkage long sys_bind(int fd, struct
36542 + if (sock) {
36543 + err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
36544 + if (err >= 0) {
36545 ++ if (!gr_search_bind(sock, (struct sockaddr_in *)&address) ||
36546 ++ gr_handle_sock_server((struct sockaddr *)&address)) {
36547 ++ err = -EACCES;
36548 ++ goto error;
36549 ++ }
36550 ++
36551 + err = security_socket_bind(sock,
36552 + (struct sockaddr *)&address,
36553 + addrlen);
36554 +@@ -1383,6 +1415,7 @@ asmlinkage long sys_bind(int fd, struct
36555 + (struct sockaddr *)
36556 + &address, addrlen);
36557 + }
36558 ++error:
36559 + fput_light(sock->file, fput_needed);
36560 + }
36561 + return err;
36562 +@@ -1406,10 +1439,17 @@ asmlinkage long sys_listen(int fd, int b
36563 + if ((unsigned)backlog > somaxconn)
36564 + backlog = somaxconn;
36565 +
36566 ++ if (gr_handle_sock_server_other(sock) ||
36567 ++ !gr_search_listen(sock)) {
36568 ++ err = -EPERM;
36569 ++ goto error;
36570 ++ }
36571 ++
36572 + err = security_socket_listen(sock, backlog);
36573 + if (!err)
36574 + err = sock->ops->listen(sock, backlog);
36575 +
36576 ++error:
36577 + fput_light(sock->file, fput_needed);
36578 + }
36579 + return err;
36580 +@@ -1452,6 +1492,13 @@ long do_accept(int fd, struct sockaddr _
36581 + newsock->type = sock->type;
36582 + newsock->ops = sock->ops;
36583 +
36584 ++ if (gr_handle_sock_server_other(sock) ||
36585 ++ !gr_search_accept(sock)) {
36586 ++ err = -EPERM;
36587 ++ sock_release(newsock);
36588 ++ goto out_put;
36589 ++ }
36590 ++
36591 + /*
36592 + * We don't need try_module_get here, as the listening socket (sock)
36593 + * has the protocol module (sock->ops->owner) held.
36594 +@@ -1495,6 +1542,7 @@ long do_accept(int fd, struct sockaddr _
36595 + err = newfd;
36596 +
36597 + security_socket_post_accept(sock, newsock);
36598 ++ gr_attach_curr_ip(newsock->sk);
36599 +
36600 + out_put:
36601 + fput_light(sock->file, fput_needed);
36602 +@@ -1589,6 +1637,7 @@ asmlinkage long sys_connect(int fd, stru
36603 + int addrlen)
36604 + {
36605 + struct socket *sock;
36606 ++ struct sockaddr *sck;
36607 + struct sockaddr_storage address;
36608 + int err, fput_needed;
36609 +
36610 +@@ -1599,6 +1648,13 @@ asmlinkage long sys_connect(int fd, stru
36611 + if (err < 0)
36612 + goto out_put;
36613 +
36614 ++ sck = (struct sockaddr *)&address;
36615 ++ if (!gr_search_connect(sock, (struct sockaddr_in *)sck) ||
36616 ++ gr_handle_sock_client(sck)) {
36617 ++ err = -EACCES;
36618 ++ goto out_put;
36619 ++ }
36620 ++
36621 + err =
36622 + security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
36623 + if (err)
36624 +@@ -1866,6 +1922,7 @@ asmlinkage long sys_shutdown(int fd, int
36625 + err = sock->ops->shutdown(sock, how);
36626 + fput_light(sock->file, fput_needed);
36627 + }
36628 ++
36629 + return err;
36630 + }
36631 +
36632 +diff -urNp linux-2.6.27.10/net/unix/af_unix.c linux-2.6.27.10/net/unix/af_unix.c
36633 +--- linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:16:52.000000000 -0500
36634 ++++ linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:13:47.000000000 -0500
36635 +@@ -114,6 +114,7 @@
36636 + #include <linux/mount.h>
36637 + #include <net/checksum.h>
36638 + #include <linux/security.h>
36639 ++#include <linux/grsecurity.h>
36640 +
36641 + static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
36642 + static DEFINE_SPINLOCK(unix_table_lock);
36643 +@@ -725,6 +726,12 @@ static struct sock *unix_find_other(stru
36644 + err = -ECONNREFUSED;
36645 + if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode))
36646 + goto put_fail;
36647 ++
36648 ++ if (!gr_acl_handle_unix(nd.path.dentry, nd.path.mnt)) {
36649 ++ err = -EACCES;
36650 ++ goto put_fail;
36651 ++ }
36652 ++
36653 + u = unix_find_socket_byinode(net, nd.path.dentry->d_inode);
36654 + if (!u)
36655 + goto put_fail;
36656 +@@ -745,6 +752,13 @@ static struct sock *unix_find_other(stru
36657 + if (u) {
36658 + struct dentry *dentry;
36659 + dentry = unix_sk(u)->dentry;
36660 ++
36661 ++ if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
36662 ++ err = -EPERM;
36663 ++ sock_put(u);
36664 ++ goto fail;
36665 ++ }
36666 ++
36667 + if (dentry)
36668 + touch_atime(unix_sk(u)->mnt, dentry);
36669 + } else
36670 +@@ -827,10 +841,20 @@ static int unix_bind(struct socket *sock
36671 + err = mnt_want_write(nd.path.mnt);
36672 + if (err)
36673 + goto out_mknod_dput;
36674 ++
36675 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
36676 ++ err = -EACCES;
36677 ++ mnt_drop_write(nd.path.mnt);
36678 ++ goto out_mknod_dput;
36679 ++ }
36680 ++
36681 + err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
36682 + mnt_drop_write(nd.path.mnt);
36683 + if (err)
36684 + goto out_mknod_dput;
36685 ++
36686 ++ gr_handle_create(dentry, nd.path.mnt);
36687 ++
36688 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
36689 + dput(nd.path.dentry);
36690 + nd.path.dentry = dentry;
36691 +@@ -848,6 +872,10 @@ static int unix_bind(struct socket *sock
36692 + goto out_unlock;
36693 + }
36694 +
36695 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
36696 ++ sk->sk_peercred.pid = current->pid;
36697 ++#endif
36698 ++
36699 + list = &unix_socket_table[addr->hash];
36700 + } else {
36701 + list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
36702 +diff -urNp linux-2.6.27.10/scripts/pnmtologo.c linux-2.6.27.10/scripts/pnmtologo.c
36703 +--- linux-2.6.27.10/scripts/pnmtologo.c 2008-11-07 12:55:34.000000000 -0500
36704 ++++ linux-2.6.27.10/scripts/pnmtologo.c 2008-11-18 03:38:45.000000000 -0500
36705 +@@ -237,14 +237,14 @@ static void write_header(void)
36706 + fprintf(out, " * Linux logo %s\n", logoname);
36707 + fputs(" */\n\n", out);
36708 + fputs("#include <linux/linux_logo.h>\n\n", out);
36709 +- fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
36710 ++ fprintf(out, "static unsigned char %s_data[] = {\n",
36711 + logoname);
36712 + }
36713 +
36714 + static void write_footer(void)
36715 + {
36716 + fputs("\n};\n\n", out);
36717 +- fprintf(out, "struct linux_logo %s __initdata = {\n", logoname);
36718 ++ fprintf(out, "struct linux_logo %s = {\n", logoname);
36719 + fprintf(out, " .type\t= %s,\n", logo_types[logo_type]);
36720 + fprintf(out, " .width\t= %d,\n", logo_width);
36721 + fprintf(out, " .height\t= %d,\n", logo_height);
36722 +@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
36723 + fputs("\n};\n\n", out);
36724 +
36725 + /* write logo clut */
36726 +- fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
36727 ++ fprintf(out, "static unsigned char %s_clut[] = {\n",
36728 + logoname);
36729 + write_hex_cnt = 0;
36730 + for (i = 0; i < logo_clutsize; i++) {
36731 +diff -urNp linux-2.6.27.10/security/commoncap.c linux-2.6.27.10/security/commoncap.c
36732 +--- linux-2.6.27.10/security/commoncap.c 2008-11-07 12:55:34.000000000 -0500
36733 ++++ linux-2.6.27.10/security/commoncap.c 2008-11-18 03:38:45.000000000 -0500
36734 +@@ -26,10 +26,13 @@
36735 + #include <linux/sched.h>
36736 + #include <linux/prctl.h>
36737 + #include <linux/securebits.h>
36738 ++#include <linux/grsecurity.h>
36739 ++
36740 ++extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
36741 +
36742 + int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
36743 + {
36744 +- NETLINK_CB(skb).eff_cap = current->cap_effective;
36745 ++ NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
36746 + return 0;
36747 + }
36748 +
36749 +@@ -51,7 +54,15 @@ EXPORT_SYMBOL(cap_netlink_recv);
36750 + int cap_capable (struct task_struct *tsk, int cap)
36751 + {
36752 + /* Derived from include/linux/sched.h:capable. */
36753 +- if (cap_raised(tsk->cap_effective, cap))
36754 ++ if (cap_raised (tsk->cap_effective, cap))
36755 ++ return 0;
36756 ++ return -EPERM;
36757 ++}
36758 ++
36759 ++int cap_capable_nolog (struct task_struct *tsk, int cap)
36760 ++{
36761 ++ /* tsk = current for all callers */
36762 ++ if (cap_raised(tsk->cap_effective, cap) && gr_is_capable_nolog(cap))
36763 + return 0;
36764 + return -EPERM;
36765 + }
36766 +@@ -379,8 +390,11 @@ void cap_bprm_apply_creds (struct linux_
36767 + }
36768 + }
36769 +
36770 +- current->suid = current->euid = current->fsuid = bprm->e_uid;
36771 +- current->sgid = current->egid = current->fsgid = bprm->e_gid;
36772 ++ if (!gr_check_user_change(-1, bprm->e_uid, bprm->e_uid))
36773 ++ current->suid = current->euid = current->fsuid = bprm->e_uid;
36774 ++
36775 ++ if (!gr_check_group_change(-1, bprm->e_gid, bprm->e_gid))
36776 ++ current->sgid = current->egid = current->fsgid = bprm->e_gid;
36777 +
36778 + /* For init, we want to retain the capabilities set
36779 + * in the init_task struct. Thus we skip the usual
36780 +@@ -393,6 +407,8 @@ void cap_bprm_apply_creds (struct linux_
36781 + cap_clear(current->cap_effective);
36782 + }
36783 +
36784 ++ gr_handle_chroot_caps(current);
36785 ++
36786 + /* AUD: Audit candidate if current->cap_effective is set */
36787 +
36788 + current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
36789 +@@ -705,7 +721,7 @@ int cap_vm_enough_memory(struct mm_struc
36790 + {
36791 + int cap_sys_admin = 0;
36792 +
36793 +- if (cap_capable(current, CAP_SYS_ADMIN) == 0)
36794 ++ if (cap_capable_nolog(current, CAP_SYS_ADMIN) == 0)
36795 + cap_sys_admin = 1;
36796 + return __vm_enough_memory(mm, pages, cap_sys_admin);
36797 + }
36798 +diff -urNp linux-2.6.27.10/security/Kconfig linux-2.6.27.10/security/Kconfig
36799 +--- linux-2.6.27.10/security/Kconfig 2008-11-07 12:55:34.000000000 -0500
36800 ++++ linux-2.6.27.10/security/Kconfig 2008-11-18 03:38:45.000000000 -0500
36801 +@@ -4,6 +4,447 @@
36802 +
36803 + menu "Security options"
36804 +
36805 ++source grsecurity/Kconfig
36806 ++
36807 ++menu "PaX"
36808 ++
36809 ++config PAX
36810 ++ bool "Enable various PaX features"
36811 ++ depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
36812 ++ help
36813 ++ This allows you to enable various PaX features. PaX adds
36814 ++ intrusion prevention mechanisms to the kernel that reduce
36815 ++ the risks posed by exploitable memory corruption bugs.
36816 ++
36817 ++menu "PaX Control"
36818 ++ depends on PAX
36819 ++
36820 ++config PAX_SOFTMODE
36821 ++ bool 'Support soft mode'
36822 ++ help
36823 ++ Enabling this option will allow you to run PaX in soft mode, that
36824 ++ is, PaX features will not be enforced by default, only on executables
36825 ++ marked explicitly. You must also enable PT_PAX_FLAGS support as it
36826 ++ is the only way to mark executables for soft mode use.
36827 ++
36828 ++ Soft mode can be activated by using the "pax_softmode=1" kernel command
36829 ++ line option on boot. Furthermore you can control various PaX features
36830 ++ at runtime via the entries in /proc/sys/kernel/pax.
36831 ++
36832 ++config PAX_EI_PAX
36833 ++ bool 'Use legacy ELF header marking'
36834 ++ help
36835 ++ Enabling this option will allow you to control PaX features on
36836 ++ a per executable basis via the 'chpax' utility available at
36837 ++ http://pax.grsecurity.net/. The control flags will be read from
36838 ++ an otherwise reserved part of the ELF header. This marking has
36839 ++ numerous drawbacks (no support for soft-mode, toolchain does not
36840 ++ know about the non-standard use of the ELF header) therefore it
36841 ++ has been deprecated in favour of PT_PAX_FLAGS support.
36842 ++
36843 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36844 ++ program header then you MUST enable this option otherwise they
36845 ++ will not get any protection.
36846 ++
36847 ++ Note that if you enable PT_PAX_FLAGS marking support as well,
36848 ++ the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
36849 ++
36850 ++config PAX_PT_PAX_FLAGS
36851 ++ bool 'Use ELF program header marking'
36852 ++ help
36853 ++ Enabling this option will allow you to control PaX features on
36854 ++ a per executable basis via the 'paxctl' utility available at
36855 ++ http://pax.grsecurity.net/. The control flags will be read from
36856 ++ a PaX specific ELF program header (PT_PAX_FLAGS). This marking
36857 ++ has the benefits of supporting both soft mode and being fully
36858 ++ integrated into the toolchain (the binutils patch is available
36859 ++ from http://pax.grsecurity.net).
36860 ++
36861 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36862 ++ program header then you MUST enable the EI_PAX marking support
36863 ++ otherwise they will not get any protection.
36864 ++
36865 ++ Note that if you enable the legacy EI_PAX marking support as well,
36866 ++ the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
36867 ++
36868 ++choice
36869 ++ prompt 'MAC system integration'
36870 ++ default PAX_HAVE_ACL_FLAGS
36871 ++ help
36872 ++ Mandatory Access Control systems have the option of controlling
36873 ++ PaX flags on a per executable basis, choose the method supported
36874 ++ by your particular system.
36875 ++
36876 ++ - "none": if your MAC system does not interact with PaX,
36877 ++ - "direct": if your MAC system defines pax_set_initial_flags() itself,
36878 ++ - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
36879 ++
36880 ++ NOTE: this option is for developers/integrators only.
36881 ++
36882 ++ config PAX_NO_ACL_FLAGS
36883 ++ bool 'none'
36884 ++
36885 ++ config PAX_HAVE_ACL_FLAGS
36886 ++ bool 'direct'
36887 ++
36888 ++ config PAX_HOOK_ACL_FLAGS
36889 ++ bool 'hook'
36890 ++endchoice
36891 ++
36892 ++endmenu
36893 ++
36894 ++menu "Non-executable pages"
36895 ++ depends on PAX
36896 ++
36897 ++config PAX_NOEXEC
36898 ++ bool "Enforce non-executable pages"
36899 ++ 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)
36900 ++ help
36901 ++ By design some architectures do not allow for protecting memory
36902 ++ pages against execution or even if they do, Linux does not make
36903 ++ use of this feature. In practice this means that if a page is
36904 ++ readable (such as the stack or heap) it is also executable.
36905 ++
36906 ++ There is a well known exploit technique that makes use of this
36907 ++ fact and a common programming mistake where an attacker can
36908 ++ introduce code of his choice somewhere in the attacked program's
36909 ++ memory (typically the stack or the heap) and then execute it.
36910 ++
36911 ++ If the attacked program was running with different (typically
36912 ++ higher) privileges than that of the attacker, then he can elevate
36913 ++ his own privilege level (e.g. get a root shell, write to files for
36914 ++ which he does not have write access to, etc).
36915 ++
36916 ++ Enabling this option will let you choose from various features
36917 ++ that prevent the injection and execution of 'foreign' code in
36918 ++ a program.
36919 ++
36920 ++ This will also break programs that rely on the old behaviour and
36921 ++ expect that dynamically allocated memory via the malloc() family
36922 ++ of functions is executable (which it is not). Notable examples
36923 ++ are the XFree86 4.x server, the java runtime and wine.
36924 ++
36925 ++config PAX_PAGEEXEC
36926 ++ bool "Paging based non-executable pages"
36927 ++ 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)
36928 ++ help
36929 ++ This implementation is based on the paging feature of the CPU.
36930 ++ On i386 without hardware non-executable bit support there is a
36931 ++ variable but usually low performance impact, however on Intel's
36932 ++ P4 core based CPUs it is very high so you should not enable this
36933 ++ for kernels meant to be used on such CPUs.
36934 ++
36935 ++ On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
36936 ++ with hardware non-executable bit support there is no performance
36937 ++ impact, on ppc the impact is negligible.
36938 ++
36939 ++ Note that several architectures require various emulations due to
36940 ++ badly designed userland ABIs, this will cause a performance impact
36941 ++ but will disappear as soon as userland is fixed (e.g., ppc users
36942 ++ can make use of the secure-plt feature found in binutils).
36943 ++
36944 ++config PAX_SEGMEXEC
36945 ++ bool "Segmentation based non-executable pages"
36946 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32
36947 ++ help
36948 ++ This implementation is based on the segmentation feature of the
36949 ++ CPU and has a very small performance impact, however applications
36950 ++ will be limited to a 1.5 GB address space instead of the normal
36951 ++ 3 GB.
36952 ++
36953 ++config PAX_EMUTRAMP
36954 ++ bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86)
36955 ++ default y if PARISC || PPC32
36956 ++ help
36957 ++ There are some programs and libraries that for one reason or
36958 ++ another attempt to execute special small code snippets from
36959 ++ non-executable memory pages. Most notable examples are the
36960 ++ signal handler return code generated by the kernel itself and
36961 ++ the GCC trampolines.
36962 ++
36963 ++ If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
36964 ++ such programs will no longer work under your kernel.
36965 ++
36966 ++ As a remedy you can say Y here and use the 'chpax' or 'paxctl'
36967 ++ utilities to enable trampoline emulation for the affected programs
36968 ++ yet still have the protection provided by the non-executable pages.
36969 ++
36970 ++ On parisc and ppc you MUST enable this option and EMUSIGRT as
36971 ++ well, otherwise your system will not even boot.
36972 ++
36973 ++ Alternatively you can say N here and use the 'chpax' or 'paxctl'
36974 ++ utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
36975 ++ for the affected files.
36976 ++
36977 ++ NOTE: enabling this feature *may* open up a loophole in the
36978 ++ protection provided by non-executable pages that an attacker
36979 ++ could abuse. Therefore the best solution is to not have any
36980 ++ files on your system that would require this option. This can
36981 ++ be achieved by not using libc5 (which relies on the kernel
36982 ++ signal handler return code) and not using or rewriting programs
36983 ++ that make use of the nested function implementation of GCC.
36984 ++ Skilled users can just fix GCC itself so that it implements
36985 ++ nested function calls in a way that does not interfere with PaX.
36986 ++
36987 ++config PAX_EMUSIGRT
36988 ++ bool "Automatically emulate sigreturn trampolines"
36989 ++ depends on PAX_EMUTRAMP && (PARISC || PPC32)
36990 ++ default y
36991 ++ help
36992 ++ Enabling this option will have the kernel automatically detect
36993 ++ and emulate signal return trampolines executing on the stack
36994 ++ that would otherwise lead to task termination.
36995 ++
36996 ++ This solution is intended as a temporary one for users with
36997 ++ legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
36998 ++ Modula-3 runtime, etc) or executables linked to such, basically
36999 ++ everything that does not specify its own SA_RESTORER function in
37000 ++ normal executable memory like glibc 2.1+ does.
37001 ++
37002 ++ On parisc and ppc you MUST enable this option, otherwise your
37003 ++ system will not even boot.
37004 ++
37005 ++ NOTE: this feature cannot be disabled on a per executable basis
37006 ++ and since it *does* open up a loophole in the protection provided
37007 ++ by non-executable pages, the best solution is to not have any
37008 ++ files on your system that would require this option.
37009 ++
37010 ++config PAX_MPROTECT
37011 ++ bool "Restrict mprotect()"
37012 ++ depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64
37013 ++ help
37014 ++ Enabling this option will prevent programs from
37015 ++ - changing the executable status of memory pages that were
37016 ++ not originally created as executable,
37017 ++ - making read-only executable pages writable again,
37018 ++ - creating executable pages from anonymous memory.
37019 ++
37020 ++ You should say Y here to complete the protection provided by
37021 ++ the enforcement of non-executable pages.
37022 ++
37023 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
37024 ++ this feature on a per file basis.
37025 ++
37026 ++config PAX_NOELFRELOCS
37027 ++ bool "Disallow ELF text relocations"
37028 ++ depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86)
37029 ++ help
37030 ++ Non-executable pages and mprotect() restrictions are effective
37031 ++ in preventing the introduction of new executable code into an
37032 ++ attacked task's address space. There remain only two venues
37033 ++ for this kind of attack: if the attacker can execute already
37034 ++ existing code in the attacked task then he can either have it
37035 ++ create and mmap() a file containing his code or have it mmap()
37036 ++ an already existing ELF library that does not have position
37037 ++ independent code in it and use mprotect() on it to make it
37038 ++ writable and copy his code there. While protecting against
37039 ++ the former approach is beyond PaX, the latter can be prevented
37040 ++ by having only PIC ELF libraries on one's system (which do not
37041 ++ need to relocate their code). If you are sure this is your case,
37042 ++ then enable this option otherwise be careful as you may not even
37043 ++ be able to boot or log on your system (for example, some PAM
37044 ++ modules are erroneously compiled as non-PIC by default).
37045 ++
37046 ++ NOTE: if you are using dynamic ELF executables (as suggested
37047 ++ when using ASLR) then you must have made sure that you linked
37048 ++ your files using the PIC version of crt1 (the et_dyn.tar.gz package
37049 ++ referenced there has already been updated to support this).
37050 ++
37051 ++config PAX_ETEXECRELOCS
37052 ++ bool "Allow ELF ET_EXEC text relocations"
37053 ++ depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
37054 ++ default y
37055 ++ help
37056 ++ On some architectures there are incorrectly created applications
37057 ++ that require text relocations and would not work without enabling
37058 ++ this option. If you are an alpha, ia64 or parisc user, you should
37059 ++ enable this option and disable it once you have made sure that
37060 ++ none of your applications need it.
37061 ++
37062 ++config PAX_EMUPLT
37063 ++ bool "Automatically emulate ELF PLT"
37064 ++ depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37065 ++ default y
37066 ++ help
37067 ++ Enabling this option will have the kernel automatically detect
37068 ++ and emulate the Procedure Linkage Table entries in ELF files.
37069 ++ On some architectures such entries are in writable memory, and
37070 ++ become non-executable leading to task termination. Therefore
37071 ++ it is mandatory that you enable this option on alpha, parisc,
37072 ++ ppc (if secure-plt is not used throughout in userland), sparc
37073 ++ and sparc64, otherwise your system would not even boot.
37074 ++
37075 ++ NOTE: this feature *does* open up a loophole in the protection
37076 ++ provided by the non-executable pages, therefore the proper
37077 ++ solution is to modify the toolchain to produce a PLT that does
37078 ++ not need to be writable.
37079 ++
37080 ++config PAX_DLRESOLVE
37081 ++ bool
37082 ++ depends on PAX_EMUPLT && (SPARC32 || SPARC64)
37083 ++ default y
37084 ++
37085 ++config PAX_SYSCALL
37086 ++ bool
37087 ++ depends on PAX_PAGEEXEC && PPC32
37088 ++ default y
37089 ++
37090 ++config PAX_KERNEXEC
37091 ++ bool "Enforce non-executable kernel pages"
37092 ++ depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT
37093 ++ help
37094 ++ This is the kernel land equivalent of PAGEEXEC and MPROTECT,
37095 ++ that is, enabling this option will make it harder to inject
37096 ++ and execute 'foreign' code in kernel memory itself.
37097 ++
37098 ++endmenu
37099 ++
37100 ++menu "Address Space Layout Randomization"
37101 ++ depends on PAX
37102 ++
37103 ++config PAX_ASLR
37104 ++ bool "Address Space Layout Randomization"
37105 ++ depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
37106 ++ help
37107 ++ Many if not most exploit techniques rely on the knowledge of
37108 ++ certain addresses in the attacked program. The following options
37109 ++ will allow the kernel to apply a certain amount of randomization
37110 ++ to specific parts of the program thereby forcing an attacker to
37111 ++ guess them in most cases. Any failed guess will most likely crash
37112 ++ the attacked program which allows the kernel to detect such attempts
37113 ++ and react on them. PaX itself provides no reaction mechanisms,
37114 ++ instead it is strongly encouraged that you make use of Nergal's
37115 ++ segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
37116 ++ (http://www.grsecurity.net/) built-in crash detection features or
37117 ++ develop one yourself.
37118 ++
37119 ++ By saying Y here you can choose to randomize the following areas:
37120 ++ - top of the task's kernel stack
37121 ++ - top of the task's userland stack
37122 ++ - base address for mmap() requests that do not specify one
37123 ++ (this includes all libraries)
37124 ++ - base address of the main executable
37125 ++
37126 ++ It is strongly recommended to say Y here as address space layout
37127 ++ randomization has negligible impact on performance yet it provides
37128 ++ a very effective protection.
37129 ++
37130 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
37131 ++ this feature on a per file basis.
37132 ++
37133 ++config PAX_RANDKSTACK
37134 ++ bool "Randomize kernel stack base"
37135 ++ depends on PAX_ASLR && X86_TSC && X86_32
37136 ++ help
37137 ++ By saying Y here the kernel will randomize every task's kernel
37138 ++ stack on every system call. This will not only force an attacker
37139 ++ to guess it but also prevent him from making use of possible
37140 ++ leaked information about it.
37141 ++
37142 ++ Since the kernel stack is a rather scarce resource, randomization
37143 ++ may cause unexpected stack overflows, therefore you should very
37144 ++ carefully test your system. Note that once enabled in the kernel
37145 ++ configuration, this feature cannot be disabled on a per file basis.
37146 ++
37147 ++config PAX_RANDUSTACK
37148 ++ bool "Randomize user stack base"
37149 ++ depends on PAX_ASLR
37150 ++ help
37151 ++ By saying Y here the kernel will randomize every task's userland
37152 ++ stack. The randomization is done in two steps where the second
37153 ++ one may apply a big amount of shift to the top of the stack and
37154 ++ cause problems for programs that want to use lots of memory (more
37155 ++ than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
37156 ++ For this reason the second step can be controlled by 'chpax' or
37157 ++ 'paxctl' on a per file basis.
37158 ++
37159 ++config PAX_RANDMMAP
37160 ++ bool "Randomize mmap() base"
37161 ++ depends on PAX_ASLR
37162 ++ help
37163 ++ By saying Y here the kernel will use a randomized base address for
37164 ++ mmap() requests that do not specify one themselves. As a result
37165 ++ all dynamically loaded libraries will appear at random addresses
37166 ++ and therefore be harder to exploit by a technique where an attacker
37167 ++ attempts to execute library code for his purposes (e.g. spawn a
37168 ++ shell from an exploited program that is running at an elevated
37169 ++ privilege level).
37170 ++
37171 ++ Furthermore, if a program is relinked as a dynamic ELF file, its
37172 ++ base address will be randomized as well, completing the full
37173 ++ randomization of the address space layout. Attacking such programs
37174 ++ becomes a guess game. You can find an example of doing this at
37175 ++ http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
37176 ++ http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
37177 ++
37178 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
37179 ++ feature on a per file basis.
37180 ++
37181 ++endmenu
37182 ++
37183 ++menu "Miscellaneous hardening features"
37184 ++
37185 ++config PAX_MEMORY_SANITIZE
37186 ++ bool "Sanitize all freed memory"
37187 ++ help
37188 ++ By saying Y here the kernel will erase memory pages as soon as they
37189 ++ are freed. This in turn reduces the lifetime of data stored in the
37190 ++ pages, making it less likely that sensitive information such as
37191 ++ passwords, cryptographic secrets, etc stay in memory for too long.
37192 ++
37193 ++ This is especially useful for programs whose runtime is short, long
37194 ++ lived processes and the kernel itself benefit from this as long as
37195 ++ they operate on whole memory pages and ensure timely freeing of pages
37196 ++ that may hold sensitive information.
37197 ++
37198 ++ The tradeoff is performance impact, on a single CPU system kernel
37199 ++ compilation sees a 3% slowdown, other systems and workloads may vary
37200 ++ and you are advised to test this feature on your expected workload
37201 ++ before deploying it.
37202 ++
37203 ++ Note that this feature does not protect data stored in live pages,
37204 ++ e.g., process memory swapped to disk may stay there for a long time.
37205 ++
37206 ++config PAX_MEMORY_UDEREF
37207 ++ bool "Prevent invalid userland pointer dereference"
37208 ++ depends on X86_32 && !COMPAT_VDSO && !UML_X86
37209 ++ help
37210 ++ By saying Y here the kernel will be prevented from dereferencing
37211 ++ userland pointers in contexts where the kernel expects only kernel
37212 ++ pointers. This is both a useful runtime debugging feature and a
37213 ++ security measure that prevents exploiting a class of kernel bugs.
37214 ++
37215 ++ The tradeoff is that some virtualization solutions may experience
37216 ++ a huge slowdown and therefore you should not enable this feature
37217 ++ for kernels meant to run in such environments. Whether a given VM
37218 ++ solution is affected or not is best determined by simply trying it
37219 ++ out, the performance impact will be obvious right on boot as this
37220 ++ mechanism engages from very early on. A good rule of thumb is that
37221 ++ VMs running on CPUs without hardware virtualization support (i.e.,
37222 ++ the majority of IA-32 CPUs) will likely experience the slowdown.
37223 ++
37224 ++config PAX_REFCOUNT
37225 ++ bool "Prevent various kernel object reference counter overflows"
37226 ++ depends on X86
37227 ++ help
37228 ++ By saying Y here the kernel will detect and prevent overflowing
37229 ++ various (but not all) kinds of object reference counters. Such
37230 ++ overflows can normally occur due to bugs only and are often, if
37231 ++ not always, exploitable.
37232 ++
37233 ++ The tradeoff is that data structures protected by an oveflowed
37234 ++ refcount will never be freed and therefore will leak memory. Note
37235 ++ that this leak also happens even without this protection but in
37236 ++ that case the overflow can eventually trigger the freeing of the
37237 ++ data structure while it is still being used elsewhere, resulting
37238 ++ in the exploitable situation that this feature prevents.
37239 ++
37240 ++ Since this has a negligible performance impact, you should enable
37241 ++ this feature.
37242 ++endmenu
37243 ++
37244 ++endmenu
37245 ++
37246 + config KEYS
37247 + bool "Enable access key retention support"
37248 + help
37249 +diff -urNp linux-2.6.27.10/sound/core/oss/pcm_oss.c linux-2.6.27.10/sound/core/oss/pcm_oss.c
37250 +--- linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-07 12:55:34.000000000 -0500
37251 ++++ linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-18 03:38:45.000000000 -0500
37252 +@@ -2911,8 +2911,8 @@ static void snd_pcm_oss_proc_done(struct
37253 + }
37254 + }
37255 + #else /* !CONFIG_SND_VERBOSE_PROCFS */
37256 +-#define snd_pcm_oss_proc_init(pcm)
37257 +-#define snd_pcm_oss_proc_done(pcm)
37258 ++#define snd_pcm_oss_proc_init(pcm) do {} while (0)
37259 ++#define snd_pcm_oss_proc_done(pcm) do {} while (0)
37260 + #endif /* CONFIG_SND_VERBOSE_PROCFS */
37261 +
37262 + /*
37263 +diff -urNp linux-2.6.27.10/sound/core/seq/seq_lock.h linux-2.6.27.10/sound/core/seq/seq_lock.h
37264 +--- linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-07 12:55:34.000000000 -0500
37265 ++++ linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-18 03:38:45.000000000 -0500
37266 +@@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
37267 + #else /* SMP || CONFIG_SND_DEBUG */
37268 +
37269 + typedef spinlock_t snd_use_lock_t; /* dummy */
37270 +-#define snd_use_lock_init(lockp) /**/
37271 +-#define snd_use_lock_use(lockp) /**/
37272 +-#define snd_use_lock_free(lockp) /**/
37273 +-#define snd_use_lock_sync(lockp) /**/
37274 ++#define snd_use_lock_init(lockp) do {} while (0)
37275 ++#define snd_use_lock_use(lockp) do {} while (0)
37276 ++#define snd_use_lock_free(lockp) do {} while (0)
37277 ++#define snd_use_lock_sync(lockp) do {} while (0)
37278 +
37279 + #endif /* SMP || CONFIG_SND_DEBUG */
37280 +
37281 +diff -urNp linux-2.6.27.10/sound/pci/ac97/ac97_patch.c linux-2.6.27.10/sound/pci/ac97/ac97_patch.c
37282 +--- linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-07 12:55:34.000000000 -0500
37283 ++++ linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-18 03:38:45.000000000 -0500
37284 +@@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a
37285 + { AC97_VIDEO, 0x9f1f },
37286 + { AC97_AUX, 0x9f1f },
37287 + { AC97_PCM, 0x9f1f },
37288 +- { } /* terminator */
37289 ++ { 0, 0 } /* terminator */
37290 + };
37291 +
37292 + static int patch_ad1819(struct snd_ac97 * ac97)
37293 +@@ -3668,7 +3668,7 @@ static struct snd_ac97_res_table lm4550_
37294 + { AC97_AUX, 0x1f1f },
37295 + { AC97_PCM, 0x1f1f },
37296 + { AC97_REC_GAIN, 0x0f0f },
37297 +- { } /* terminator */
37298 ++ { 0, 0 } /* terminator */
37299 + };
37300 +
37301 + static int patch_lm4550(struct snd_ac97 *ac97)
37302 +diff -urNp linux-2.6.27.10/sound/pci/ens1370.c linux-2.6.27.10/sound/pci/ens1370.c
37303 +--- linux-2.6.27.10/sound/pci/ens1370.c 2008-11-07 12:55:34.000000000 -0500
37304 ++++ linux-2.6.27.10/sound/pci/ens1370.c 2008-11-18 03:38:45.000000000 -0500
37305 +@@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci
37306 + { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */
37307 + { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */
37308 + #endif
37309 +- { 0, }
37310 ++ { 0, 0, 0, 0, 0, 0, 0 }
37311 + };
37312 +
37313 + MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
37314 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0.c linux-2.6.27.10/sound/pci/intel8x0.c
37315 +--- linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-07 12:55:34.000000000 -0500
37316 ++++ linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-18 03:38:45.000000000 -0500
37317 +@@ -437,7 +437,7 @@ static struct pci_device_id snd_intel8x0
37318 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37319 + { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
37320 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37321 +- { 0, }
37322 ++ { 0, 0, 0, 0, 0, 0, 0 }
37323 + };
37324 +
37325 + MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
37326 +@@ -2076,7 +2076,7 @@ static struct ac97_quirk ac97_quirks[] _
37327 + .type = AC97_TUNE_HP_ONLY
37328 + },
37329 + #endif
37330 +- { } /* terminator */
37331 ++ { 0, 0, 0, 0, NULL, 0 } /* terminator */
37332 + };
37333 +
37334 + static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
37335 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0m.c linux-2.6.27.10/sound/pci/intel8x0m.c
37336 +--- linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-07 12:55:34.000000000 -0500
37337 ++++ linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-18 03:38:45.000000000 -0500
37338 +@@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0
37339 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37340 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37341 + #endif
37342 +- { 0, }
37343 ++ { 0, 0, 0, 0, 0, 0, 0 }
37344 + };
37345 +
37346 + MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
37347 +@@ -1257,7 +1257,7 @@ static struct shortname_table {
37348 + { 0x5455, "ALi M5455" },
37349 + { 0x746d, "AMD AMD8111" },
37350 + #endif
37351 +- { 0 },
37352 ++ { 0, NULL },
37353 + };
37354 +
37355 + static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
37356 +diff -urNp linux-2.6.27.10/virt/kvm/kvm_main.c linux-2.6.27.10/virt/kvm/kvm_main.c
37357 +--- linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-07 12:55:34.000000000 -0500
37358 ++++ linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-18 03:38:45.000000000 -0500
37359 +@@ -1469,6 +1469,9 @@ static struct miscdevice kvm_dev = {
37360 + KVM_MINOR,
37361 + "kvm",
37362 + &kvm_chardev_ops,
37363 ++ {NULL, NULL},
37364 ++ NULL,
37365 ++ NULL
37366 + };
37367 +
37368 + static void hardware_enable(void *junk)
37369
37370 Added: hardened/2.6/tags/2.6.27-5/4421_grsec-remove-localversion-grsec.patch
37371 ===================================================================
37372 --- hardened/2.6/tags/2.6.27-5/4421_grsec-remove-localversion-grsec.patch (rev 0)
37373 +++ hardened/2.6/tags/2.6.27-5/4421_grsec-remove-localversion-grsec.patch 2009-01-20 21:32:04 UTC (rev 1480)
37374 @@ -0,0 +1,9 @@
37375 +From: Kerin Millar <kerframil@×××××.com>
37376 +
37377 +Remove grsecurity's localversion-grsec file as it is inconsistent with
37378 +Gentoo's kernel practices and naming scheme.
37379 +
37380 +--- a/localversion-grsec 2008-02-24 14:26:59.000000000 +0000
37381 ++++ b/localversion-grsec 1970-01-01 01:00:00.000000000 +0100
37382 +@@ -1 +0,0 @@
37383 +--grsec
37384
37385 Added: hardened/2.6/tags/2.6.27-5/4422_grsec-mute-warnings.patch
37386 ===================================================================
37387 --- hardened/2.6/tags/2.6.27-5/4422_grsec-mute-warnings.patch (rev 0)
37388 +++ hardened/2.6/tags/2.6.27-5/4422_grsec-mute-warnings.patch 2009-01-20 21:32:04 UTC (rev 1480)
37389 @@ -0,0 +1,28 @@
37390 +From: Gordon Malm <gengor@g.o>
37391 +
37392 +Updated patch for kernel series 2.6.24.
37393 +
37394 +The credits/description from the original version of this patch remain accurate
37395 +and are included below.
37396 +
37397 +---
37398 +From: Alexander Gabert <gaberta@××××××××.de>
37399 +
37400 +This patch removes the warnings introduced by grsec patch 2.1.9 and later.
37401 +It removes the -W options added by the patch and restores the original
37402 +warning flags of vanilla kernel versions.
37403 +
37404 +Acked-by: Christian Heim <phreak@g.o>
37405 +---
37406 +
37407 +--- a/Makefile
37408 ++++ b/Makefile
37409 +@@ -214,7 +214,7 @@
37410 +
37411 + HOSTCC = gcc
37412 + HOSTCXX = g++
37413 +-HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
37414 ++HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
37415 + HOSTCXXFLAGS = -O2
37416 +
37417 + # Decide whether to build built-in, modular, or both.
37418
37419 Added: hardened/2.6/tags/2.6.27-5/4425_grsec-pax-without-grsec.patch
37420 ===================================================================
37421 --- hardened/2.6/tags/2.6.27-5/4425_grsec-pax-without-grsec.patch (rev 0)
37422 +++ hardened/2.6/tags/2.6.27-5/4425_grsec-pax-without-grsec.patch 2009-01-20 21:32:04 UTC (rev 1480)
37423 @@ -0,0 +1,47 @@
37424 +From: Gordon Malm <gengor@g.o>
37425 +
37426 +Allow PaX options to be selected without first selecting CONFIG_GRKERNSEC.
37427 +
37428 +This patch has been updated to keep current with newer kernel versions.
37429 +The original version of this patch contained no credits/description.
37430 +
37431 +--- a/arch/x86/mm/fault.c
37432 ++++ b/arch/x86/mm/fault.c
37433 +@@ -433,10 +433,12 @@ static void show_fault_oops(struct pt_re
37434 + if (init_mm.start_code <= address && address < init_mm.end_code)
37435 + #endif
37436 + {
37437 ++#ifdef CONFIG_GRKERNSEC
37438 + if (current->signal->curr_ip)
37439 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37440 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37441 + else
37442 ++#endif
37443 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37444 + current->comm, task_pid_nr(current), current->uid, current->euid);
37445 + }
37446 +--- a/fs/exec.c
37447 ++++ b/fs/exec.c
37448 +@@ -1691,9 +1691,11 @@ void pax_report_fault(struct pt_regs *re
37449 + }
37450 + up_read(&mm->mmap_sem);
37451 + }
37452 ++#ifdef CONFIG_GRKERNSEC
37453 + if (tsk->signal->curr_ip)
37454 + 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);
37455 + else
37456 ++#endif
37457 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
37458 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
37459 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
37460 +--- a/security/Kconfig
37461 ++++ b/security/Kconfig
37462 +@@ -10,7 +10,7 @@ menu "PaX"
37463 +
37464 + config PAX
37465 + bool "Enable various PaX features"
37466 +- depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37467 ++ depends on (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37468 + help
37469 + This allows you to enable various PaX features. PaX adds
37470 + intrusion prevention mechanisms to the kernel that reduce
37471
37472 Added: hardened/2.6/tags/2.6.27-5/4430_grsec-kconfig-default-gids.patch
37473 ===================================================================
37474 --- hardened/2.6/tags/2.6.27-5/4430_grsec-kconfig-default-gids.patch (rev 0)
37475 +++ hardened/2.6/tags/2.6.27-5/4430_grsec-kconfig-default-gids.patch 2009-01-20 21:32:04 UTC (rev 1480)
37476 @@ -0,0 +1,76 @@
37477 +From: Kerin Millar <kerframil@×××××.com>
37478 +
37479 +grsecurity contains a number of options which allow certain protections
37480 +to be applied to or exempted from members of a given group. However, the
37481 +default GIDs specified in the upstream patch are entirely arbitrary and
37482 +there is no telling which (if any) groups the GIDs will correlate with
37483 +on an end-user's system. Because some users don't pay a great deal of
37484 +attention to the finer points of kernel configuration, it is probably
37485 +wise to specify some reasonable defaults so as to stop careless users
37486 +from shooting themselves in the foot.
37487 +
37488 +--- a/grsecurity/Kconfig
37489 ++++ b/grsecurity/Kconfig
37490 +@@ -352,7 +564,7 @@
37491 + config GRKERNSEC_PROC_GID
37492 + int "GID for special group"
37493 + depends on GRKERNSEC_PROC_USERGROUP
37494 +- default 1001
37495 ++ default 10
37496 +
37497 + config GRKERNSEC_PROC_ADD
37498 + bool "Additional restrictions"
37499 +@@ -547,7 +759,7 @@
37500 + config GRKERNSEC_AUDIT_GID
37501 + int "GID for auditing"
37502 + depends on GRKERNSEC_AUDIT_GROUP
37503 +- default 1007
37504 ++ default 100
37505 +
37506 + config GRKERNSEC_EXECLOG
37507 + bool "Exec logging"
37508 +@@ -700,7 +912,7 @@
37509 + config GRKERNSEC_TPE_GID
37510 + int "GID for untrusted users"
37511 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
37512 +- default 1005
37513 ++ default 100
37514 + help
37515 + If you have selected the "Invert GID option" above, setting this
37516 + GID determines what group TPE restrictions will be *disabled* for.
37517 +@@ -712,7 +924,7 @@
37518 + config GRKERNSEC_TPE_GID
37519 + int "GID for trusted users"
37520 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
37521 +- default 1005
37522 ++ default 10
37523 + help
37524 + If you have selected the "Invert GID option" above, setting this
37525 + GID determines what group TPE restrictions will be *disabled* for.
37526 +@@ -754,7 +966,7 @@
37527 + config GRKERNSEC_SOCKET_ALL_GID
37528 + int "GID to deny all sockets for"
37529 + depends on GRKERNSEC_SOCKET_ALL
37530 +- default 1004
37531 ++ default 65534
37532 + help
37533 + Here you can choose the GID to disable socket access for. Remember to
37534 + add the users you want socket access disabled for to the GID
37535 +@@ -775,7 +987,7 @@
37536 + config GRKERNSEC_SOCKET_CLIENT_GID
37537 + int "GID to deny client sockets for"
37538 + depends on GRKERNSEC_SOCKET_CLIENT
37539 +- default 1003
37540 ++ default 65534
37541 + help
37542 + Here you can choose the GID to disable client socket access for.
37543 + Remember to add the users you want client socket access disabled for to
37544 +@@ -793,7 +1005,7 @@
37545 + config GRKERNSEC_SOCKET_SERVER_GID
37546 + int "GID to deny server sockets for"
37547 + depends on GRKERNSEC_SOCKET_SERVER
37548 +- default 1002
37549 ++ default 65534
37550 + help
37551 + Here you can choose the GID to disable server socket access for.
37552 + Remember to add the users you want server socket access disabled for to
37553
37554 Added: hardened/2.6/tags/2.6.27-5/4435_grsec-kconfig-gentoo.patch
37555 ===================================================================
37556 --- hardened/2.6/tags/2.6.27-5/4435_grsec-kconfig-gentoo.patch (rev 0)
37557 +++ hardened/2.6/tags/2.6.27-5/4435_grsec-kconfig-gentoo.patch 2009-01-20 21:32:04 UTC (rev 1480)
37558 @@ -0,0 +1,243 @@
37559 +From: Gordon Malm <gengor@g.o>
37560 +From: Kerin Millar <kerframil@×××××.com>
37561 +
37562 +Add Hardened Gentoo [server/workstation] predefined grsecurity
37563 +levels. They're designed to provide a comparitively high level of
37564 +security while remaining generally suitable for as great a majority
37565 +of the userbase as possible (particularly new users).
37566 +
37567 +Make Hardened Gentoo [workstation] predefined grsecurity level the
37568 +default. The Hardened Gentoo [server] level is more restrictive
37569 +and conflicts with some software and thus would be less suitable.
37570 +
37571 +The original version of this patch was conceived and created by:
37572 +Ned Ludd <solar@g.o>
37573 +
37574 +--- a/grsecurity/Kconfig
37575 ++++ b/grsecurity/Kconfig
37576 +@@ -20,7 +20,7 @@ config GRKERNSEC
37577 + choice
37578 + prompt "Security Level"
37579 + depends on GRKERNSEC
37580 +- default GRKERNSEC_CUSTOM
37581 ++ default GRKERNSEC_HARDENED_WORKSTATION
37582 +
37583 + config GRKERNSEC_LOW
37584 + bool "Low"
37585 +@@ -183,6 +183,216 @@ config GRKERNSEC_HIGH
37586 + - Mount/unmount/remount logging
37587 + - Kernel symbol hiding
37588 + - Prevention of memory exhaustion-based exploits
37589 ++
37590 ++config GRKERNSEC_HARDENED_SERVER
37591 ++ bool "Hardened Gentoo [server]"
37592 ++ select GRKERNSEC_AUDIT_MOUNT
37593 ++ select GRKERNSEC_BRUTE
37594 ++ select GRKERNSEC_CHROOT
37595 ++ select GRKERNSEC_CHROOT_CAPS
37596 ++ select GRKERNSEC_CHROOT_CHDIR
37597 ++ select GRKERNSEC_CHROOT_CHMOD
37598 ++ select GRKERNSEC_CHROOT_DOUBLE
37599 ++ select GRKERNSEC_CHROOT_FCHDIR
37600 ++ select GRKERNSEC_CHROOT_FINDTASK
37601 ++ select GRKERNSEC_CHROOT_MKNOD
37602 ++ select GRKERNSEC_CHROOT_MOUNT
37603 ++ select GRKERNSEC_CHROOT_NICE
37604 ++ select GRKERNSEC_CHROOT_PIVOT
37605 ++ select GRKERNSEC_CHROOT_SHMAT
37606 ++ select GRKERNSEC_CHROOT_SYSCTL
37607 ++ select GRKERNSEC_CHROOT_UNIX
37608 ++ select GRKERNSEC_DMESG
37609 ++ select GRKERNSEC_EXECVE
37610 ++ select GRKERNSEC_FIFO
37611 ++ select GRKERNSEC_FORKFAIL
37612 ++ select GRKERNSEC_HIDESYM
37613 ++ select GRKERNSEC_IO if (X86)
37614 ++ select GRKERNSEC_KMEM
37615 ++ select GRKERNSEC_LINK
37616 ++ select GRKERNSEC_MODSTOP if (MODULES)
37617 ++ select GRKERNSEC_PROC
37618 ++ select GRKERNSEC_PROC_ADD
37619 ++ select GRKERNSEC_PROC_IPADDR
37620 ++ select GRKERNSEC_PROC_MEMMAP
37621 ++ select GRKERNSEC_PROC_USERGROUP
37622 ++ select GRKERNSEC_RANDNET
37623 ++ select GRKERNSEC_RESLOG
37624 ++ select GRKERNSEC_SIGNAL
37625 ++# select GRKERNSEC_SOCKET
37626 ++# select GRKERNSEC_SOCKET_SERVER
37627 ++ select GRKERNSEC_SYSCTL
37628 ++ select GRKERNSEC_SYSCTL_ON
37629 ++ select GRKERNSEC_TIME
37630 ++ select PAX
37631 ++ select PAX_ASLR
37632 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37633 ++ select PAX_EI_PAX
37634 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37635 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37636 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37637 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37638 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
37639 ++ select PAX_MEMORY_SANITIZE
37640 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37641 ++ select PAX_MPROTECT if (!PPC64)
37642 ++ select PAX_HAVE_ACL_FLAGS
37643 ++ select PAX_NOELFRELOCS if (X86)
37644 ++ select PAX_NOEXEC
37645 ++ select PAX_PAGEEXEC
37646 ++ select PAX_PT_PAX_FLAGS
37647 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37648 ++ select PAX_RANDMMAP
37649 ++ select PAX_RANDUSTACK
37650 ++ select PAX_REFCOUNT if (X86)
37651 ++ select PAX_SEGMEXEC if (X86_32)
37652 ++ select PAX_SYSCALL if (PPC32)
37653 ++ help
37654 ++ If you say Y here, a configuration will be used that is endorsed by
37655 ++ the Hardened Gentoo project. Therefore, many of the protections
37656 ++ made available by grsecurity and PaX will be enabled.
37657 ++
37658 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37659 ++ a high level of security while minimizing incompatibilities with the
37660 ++ majority of available software. For further information, please
37661 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37662 ++ well as the Hardened Gentoo Primer at
37663 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37664 ++
37665 ++ This Hardened Gentoo [server] level is identical to the
37666 ++ Hardened Gentoo [workstation] level, but with the GRKERNSEC_IO,
37667 ++ PAX_KERNEXEC and PAX_NOELFRELOCS security features enabled.
37668 ++ Accordingly, this is the preferred security level if the system will
37669 ++ not be utilizing software incompatible with the aforementioned
37670 ++ grsecurity/PaX features.
37671 ++
37672 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37673 ++ PaX features on problematic binaries on an individual basis. Note that
37674 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37675 ++ Translated, this means that if you wish to toggle PaX features on
37676 ++ binaries provided by applications that are distributed only in binary
37677 ++ format (rather than being built locally from sources), you will need to
37678 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37679 ++ headers.
37680 ++
37681 ++ When this level is selected, some options cannot be changed. However,
37682 ++ you may opt to fully customize the options that are selected by
37683 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37684 ++ to inherit the options selected by the "Hardened Gentoo [server]"
37685 ++ security level as a starting point for further configuration. To
37686 ++ accomplish this, select this security level then exit the menuconfig
37687 ++ interface, saving changes when prompted. Then, run make menuconfig
37688 ++ again and select the "Custom" level.
37689 ++
37690 ++ Note that this security level probably should not be used if the
37691 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37692 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37693 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37694 ++ impact on performance.
37695 ++
37696 ++config GRKERNSEC_HARDENED_WORKSTATION
37697 ++ bool "Hardened Gentoo [workstation]"
37698 ++ select GRKERNSEC_AUDIT_MOUNT
37699 ++ select GRKERNSEC_BRUTE
37700 ++ select GRKERNSEC_CHROOT
37701 ++ select GRKERNSEC_CHROOT_CAPS
37702 ++ select GRKERNSEC_CHROOT_CHDIR
37703 ++ select GRKERNSEC_CHROOT_CHMOD
37704 ++ select GRKERNSEC_CHROOT_DOUBLE
37705 ++ select GRKERNSEC_CHROOT_FCHDIR
37706 ++ select GRKERNSEC_CHROOT_FINDTASK
37707 ++ select GRKERNSEC_CHROOT_MKNOD
37708 ++ select GRKERNSEC_CHROOT_MOUNT
37709 ++ select GRKERNSEC_CHROOT_NICE
37710 ++ select GRKERNSEC_CHROOT_PIVOT
37711 ++ select GRKERNSEC_CHROOT_SHMAT
37712 ++ select GRKERNSEC_CHROOT_SYSCTL
37713 ++ select GRKERNSEC_CHROOT_UNIX
37714 ++ select GRKERNSEC_DMESG
37715 ++ select GRKERNSEC_EXECVE
37716 ++ select GRKERNSEC_FIFO
37717 ++ select GRKERNSEC_FORKFAIL
37718 ++ select GRKERNSEC_HIDESYM
37719 ++ select GRKERNSEC_KMEM
37720 ++ select GRKERNSEC_LINK
37721 ++ select GRKERNSEC_MODSTOP if (MODULES)
37722 ++ select GRKERNSEC_PROC
37723 ++ select GRKERNSEC_PROC_ADD
37724 ++ select GRKERNSEC_PROC_IPADDR
37725 ++ select GRKERNSEC_PROC_MEMMAP
37726 ++ select GRKERNSEC_PROC_USERGROUP
37727 ++ select GRKERNSEC_RANDNET
37728 ++ select GRKERNSEC_RESLOG
37729 ++ select GRKERNSEC_SIGNAL
37730 ++# select GRKERNSEC_SOCKET
37731 ++# select GRKERNSEC_SOCKET_SERVER
37732 ++ select GRKERNSEC_SYSCTL
37733 ++ select GRKERNSEC_SYSCTL_ON
37734 ++ select GRKERNSEC_TIME
37735 ++ select PAX
37736 ++ select PAX_ASLR
37737 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37738 ++ select PAX_EI_PAX
37739 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37740 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37741 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37742 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37743 ++ select PAX_MEMORY_SANITIZE
37744 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37745 ++ select PAX_MPROTECT if (!PPC64)
37746 ++ select PAX_HAVE_ACL_FLAGS
37747 ++ select PAX_NOEXEC
37748 ++ select PAX_PAGEEXEC
37749 ++ select PAX_PT_PAX_FLAGS
37750 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37751 ++ select PAX_RANDMMAP
37752 ++ select PAX_RANDUSTACK
37753 ++ select PAX_REFCOUNT if (X86)
37754 ++ select PAX_SEGMEXEC if (X86_32)
37755 ++ select PAX_SYSCALL if (PPC32)
37756 ++ help
37757 ++ If you say Y here, a configuration will be used that is endorsed by
37758 ++ the Hardened Gentoo project. Therefore, many of the protections
37759 ++ made available by grsecurity and PaX will be enabled.
37760 ++
37761 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37762 ++ a high level of security while minimizing incompatibilities with the
37763 ++ majority of available software. For further information, please
37764 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37765 ++ well as the Hardened Gentoo Primer at
37766 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37767 ++
37768 ++ This Hardened Gentoo [workstation] level is designed for machines
37769 ++ which are intended to run software not compatible with the
37770 ++ GRKERNSEC_IO, PAX_KERNEXEC and PAX_NOELFRELOCS features of grsecurity.
37771 ++ Accordingly, this security level is suitable for use with the X server
37772 ++ "Xorg" and/or any system that will act as host OS to the virtualization
37773 ++ softwares vmware-server or virtualbox.
37774 ++
37775 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37776 ++ PaX features on problematic binaries on an individual basis. Note that
37777 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37778 ++ Translated, this means that if you wish to toggle PaX features on
37779 ++ binaries provided by applications that are distributed only in binary
37780 ++ format (rather than being built locally from sources), you will need to
37781 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37782 ++ headers.
37783 ++
37784 ++ When this level is selected, some options cannot be changed. However,
37785 ++ you may opt to fully customize the options that are selected by
37786 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37787 ++ to inherit the options selected by the "Hardened Gentoo [workstation]"
37788 ++ security level as a starting point for further configuration. To
37789 ++ accomplish this, select this security level then exit the menuconfig
37790 ++ interface, saving changes when prompted. Then, run make menuconfig
37791 ++ again and select the "Custom" level.
37792 ++
37793 ++ Note that this security level probably should not be used if the
37794 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37795 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37796 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37797 ++ impact on performance.
37798 ++
37799 + config GRKERNSEC_CUSTOM
37800 + bool "Custom"
37801 + help
37802
37803 Added: hardened/2.6/tags/2.6.27-5/4440_selinux-avc_audit-log-curr_ip.patch
37804 ===================================================================
37805 --- hardened/2.6/tags/2.6.27-5/4440_selinux-avc_audit-log-curr_ip.patch (rev 0)
37806 +++ hardened/2.6/tags/2.6.27-5/4440_selinux-avc_audit-log-curr_ip.patch 2009-01-20 21:32:04 UTC (rev 1480)
37807 @@ -0,0 +1,65 @@
37808 +From: Gordon Malm <gengor@g.o>
37809 +
37810 +This is a reworked version of the original
37811 +*_selinux-avc_audit-log-curr_ip.patch carried in earlier releases of
37812 +hardened-sources.
37813 +
37814 +Dropping the patch, or simply fixing the #ifdef of the original patch
37815 +could break automated logging setups so this route was necessary.
37816 +
37817 +Suggestions for improving the help text are welcome.
37818 +
37819 +The original patch's description is still accurate and included below.
37820 +
37821 +---
37822 +Provides support for a new field ipaddr within the SELinux
37823 +AVC audit log, relying in task_struct->curr_ip (ipv4 only)
37824 +provided by grSecurity patch to be applied before.
37825 +
37826 +Signed-off-by: Lorenzo Hernandez Garcia-Hierro <lorenzo@×××.org>
37827 +---
37828 +
37829 +--- a/grsecurity/Kconfig
37830 ++++ b/grsecurity/Kconfig
37831 +@@ -1044,6 +1044,27 @@ endmenu
37832 + menu "Logging Options"
37833 + depends on GRKERNSEC
37834 +
37835 ++config GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37836 ++ def_bool n
37837 ++ prompt "Add source IP address to SELinux AVC log messages"
37838 ++ depends on GRKERNSEC && SECURITY_SELINUX
37839 ++ help
37840 ++ If you say Y here, a new field "ipaddr=" will be added to many SELinux
37841 ++ AVC log messages. The value of this field in any given message
37842 ++ represents the source IP address of the remote machine/user that created
37843 ++ the offending process.
37844 ++
37845 ++ This information is sourced from task_struct->curr_ip provided by
37846 ++ grsecurity's GRKERNSEC top-level configuration option. One limitation
37847 ++ is that only IPv4 is supported.
37848 ++
37849 ++ In many instances SELinux AVC log messages already log a superior level
37850 ++ of information that also includes source port and destination ip/port.
37851 ++ Additionally, SELinux's AVC log code supports IPv6.
37852 ++
37853 ++ However, grsecurity's task_struct->curr_ip will sometimes (often?)
37854 ++ provide the offender's IP address where stock SELinux logging fails to.
37855 ++
37856 + config GRKERNSEC_FLOODTIME
37857 + int "Seconds in between log messages (minimum)"
37858 + default 10
37859 +--- a/security/selinux/avc.c
37860 ++++ b/security/selinux/avc.c
37861 +@@ -202,6 +202,11 @@ static void avc_dump_query(struct audit_
37862 + char *scontext;
37863 + u32 scontext_len;
37864 +
37865 ++#ifdef CONFIG_GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37866 ++ if (current->signal->curr_ip)
37867 ++ audit_log_format(ab, "ipaddr=%u.%u.%u.%u ", NIPQUAD(current->signal->curr_ip));
37868 ++#endif
37869 ++
37870 + rc = security_sid_to_context(ssid, &scontext, &scontext_len);
37871 + if (rc)
37872 + audit_log_format(ab, "ssid=%d", ssid);
37873
37874 Added: hardened/2.6/tags/2.6.27-5/4445_disable-compat_vdso.patch
37875 ===================================================================
37876 --- hardened/2.6/tags/2.6.27-5/4445_disable-compat_vdso.patch (rev 0)
37877 +++ hardened/2.6/tags/2.6.27-5/4445_disable-compat_vdso.patch 2009-01-20 21:32:04 UTC (rev 1480)
37878 @@ -0,0 +1,74 @@
37879 +From: Gordon Malm <gengor@g.o>
37880 +From: Kerin Millar <kerframil@×××××.com>
37881 +
37882 +COMPAT_VDSO is inappropriate for any modern Hardened Gentoo system. It
37883 +conflicts with various parts of PaX, crashing the system if enabled
37884 +while PaX's NOEXEC or UDEREF features are active. Moreover, it prevents
37885 +a number of important PaX options from appearing in the configuration
37886 +menu, including all PaX NOEXEC implementations. Unfortunately, the
37887 +reason for the disappearance of these PaX configuration options is
37888 +often far from obvious to inexperienced users.
37889 +
37890 +Therefore, we disable the COMPAT_VDSO menu entry entirely. However,
37891 +COMPAT_VDSO operation can still be enabled via bootparam and sysctl
37892 +interfaces. Consequently, we must also disable the ability to select
37893 +COMPAT_VDSO operation at boot or runtime. Here we patch the kernel so
37894 +that selecting COMPAT_VDSO operation at boot/runtime has no effect if
37895 +conflicting PaX options are enabled, leaving VDSO_ENABLED operation
37896 +intact.
37897 +
37898 +Closes bug: http://bugs.gentoo.org/show_bug.cgi?id=210138
37899 +
37900 +--- a/arch/x86/Kconfig
37901 ++++ b/arch/x86/Kconfig
37902 +@@ -1215,16 +1215,7 @@ config HOTPLUG_CPU
37903 +
37904 + config COMPAT_VDSO
37905 + def_bool n
37906 +- prompt "Compat VDSO support"
37907 + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
37908 +- help
37909 +- Map the 32-bit VDSO to the predictable old-style address too.
37910 +- ---help---
37911 +- Say N here if you are running a sufficiently recent glibc
37912 +- version (2.3.3 or later), to remove the high-mapped
37913 +- VDSO mapping and to exclusively use the randomized VDSO.
37914 +-
37915 +- If unsure, say Y.
37916 +
37917 + endmenu
37918 +
37919 +--- a/arch/x86/vdso/vdso32-setup.c
37920 ++++ b/arch/x86/vdso/vdso32-setup.c
37921 +@@ -333,17 +333,21 @@ int arch_setup_additional_pages(struct l
37922 +
37923 + map_compat_vdso(compat);
37924 +
37925 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37926 + if (compat)
37927 + addr = VDSO_HIGH_BASE;
37928 + else {
37929 ++#endif
37930 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
37931 + if (IS_ERR_VALUE(addr)) {
37932 + ret = addr;
37933 + goto up_fail;
37934 + }
37935 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37936 + }
37937 +
37938 + if (compat_uses_vma || !compat) {
37939 ++#endif
37940 + /*
37941 + * MAYWRITE to allow gdb to COW and set breakpoints
37942 + *
37943 +@@ -361,7 +365,9 @@ int arch_setup_additional_pages(struct l
37944 +
37945 + if (ret)
37946 + goto up_fail;
37947 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37948 + }
37949 ++#endif
37950 +
37951 + current->mm->context.vdso = addr;
37952 + current_thread_info()->sysenter_return =
37953
37954 Added: hardened/2.6/tags/2.6.27-5/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
37955 ===================================================================
37956 --- hardened/2.6/tags/2.6.27-5/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch (rev 0)
37957 +++ hardened/2.6/tags/2.6.27-5/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch 2009-01-20 21:32:04 UTC (rev 1480)
37958 @@ -0,0 +1,21 @@
37959 +From: Gordon Malm <gengor@g.o>
37960 +
37961 +Add offender's IP to PAX_REFCOUNT log messages if it is available.
37962 +
37963 +--- a/fs/exec.c
37964 ++++ b/fs/exec.c
37965 +@@ -1710,7 +1710,13 @@ void pax_report_fault(struct pt_regs *re
37966 + #ifdef CONFIG_PAX_REFCOUNT
37967 + void pax_report_refcount_overflow(struct pt_regs *regs)
37968 + {
37969 +- printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37970 ++#ifdef CONFIG_GRKERNSEC
37971 ++ if (current->signal->curr_ip)
37972 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37973 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37974 ++ else
37975 ++#endif
37976 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37977 + current->comm, task_pid_nr(current), current->uid, current->euid);
37978 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
37979 + show_registers(regs);