grsecurity-2.1.14-2.6.30.8-200909262311.patch 1.38 MB
Newer Older
1 2 3
diff -urNp linux-2.6.30.8/arch/alpha/include/asm/atomic.h linux-2.6.30.8/arch/alpha/include/asm/atomic.h
--- linux-2.6.30.8/arch/alpha/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/include/asm/atomic.h	2009-07-30 09:48:09.872868955 -0400
4 5 6 7 8 9 10 11 12 13
@@ -246,6 +246,9 @@ static __inline__ int atomic64_add_unles
 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0)
 
 #define atomic_inc(v) atomic_add(1,(v))
+#define atomic_inc_unchecked(v) atomic_inc(v)
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
 #define atomic64_inc(v) atomic64_add(1,(v))
 
 #define atomic_dec(v) atomic_sub(1,(v))
14 15 16
diff -urNp linux-2.6.30.8/arch/alpha/include/asm/elf.h linux-2.6.30.8/arch/alpha/include/asm/elf.h
--- linux-2.6.30.8/arch/alpha/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/include/asm/elf.h	2009-07-30 09:48:09.873636524 -0400
17 18 19 20 21 22 23 24 25 26 27 28 29 30
@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
 
 #define ELF_ET_DYN_BASE		(TASK_UNMAPPED_BASE + 0x1000000)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
+
+#define PAX_DELTA_MMAP_LEN	(current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
+#define PAX_DELTA_STACK_LEN	(current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
+#endif
+
 /* $0 is set by ld.so to a pointer to a function which might be 
    registered using atexit.  This provides a mean for the dynamic
    linker to call DT_FINI functions for shared libraries that have
31 32 33
diff -urNp linux-2.6.30.8/arch/alpha/include/asm/kmap_types.h linux-2.6.30.8/arch/alpha/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/alpha/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/include/asm/kmap_types.h	2009-07-30 09:48:09.873636524 -0400
34 35 36 37 38 39 40 41 42 43
@@ -24,7 +24,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)  KM_CLEARPAGE,
+D(14)  KM_TYPE_NR
 };
 
 #undef D
44 45 46
diff -urNp linux-2.6.30.8/arch/alpha/include/asm/pgtable.h linux-2.6.30.8/arch/alpha/include/asm/pgtable.h
--- linux-2.6.30.8/arch/alpha/include/asm/pgtable.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/include/asm/pgtable.h	2009-07-30 09:48:09.874706218 -0400
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
@@ -101,6 +101,17 @@ struct vm_area_struct;
 #define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
 #define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
 #define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
+
+#ifdef CONFIG_PAX_PAGEEXEC
+# define PAGE_SHARED_NOEXEC	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
+# define PAGE_COPY_NOEXEC	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
+# define PAGE_READONLY_NOEXEC	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
+#else
+# define PAGE_SHARED_NOEXEC	PAGE_SHARED
+# define PAGE_COPY_NOEXEC	PAGE_COPY
+# define PAGE_READONLY_NOEXEC	PAGE_READONLY
+#endif
+
 #define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
 
 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
65 66 67
diff -urNp linux-2.6.30.8/arch/alpha/kernel/module.c linux-2.6.30.8/arch/alpha/kernel/module.c
--- linux-2.6.30.8/arch/alpha/kernel/module.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/kernel/module.c	2009-07-30 09:48:09.875723461 -0400
68 69 70 71 72 73 74 75 76
@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, 
 
 	/* The small sections were sorted to the end of the segment.
 	   The following should definitely cover them.  */
-	gp = (u64)me->module_core + me->core_size - 0x8000;
+	gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
 	got = sechdrs[me->arch.gotsecindex].sh_addr;
 
 	for (i = 0; i < n; i++) {
77 78 79
diff -urNp linux-2.6.30.8/arch/alpha/kernel/osf_sys.c linux-2.6.30.8/arch/alpha/kernel/osf_sys.c
--- linux-2.6.30.8/arch/alpha/kernel/osf_sys.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/kernel/osf_sys.c	2009-07-30 09:48:09.875723461 -0400
80
@@ -1215,6 +1215,10 @@ arch_get_unmapped_area(struct file *filp
81 82 83 84 85 86 87 88 89 90
 	   merely specific addresses, but regions of memory -- perhaps
 	   this feature should be incorporated into all ports?  */
 
+#ifdef CONFIG_PAX_RANDMMAP
+	if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
+#endif
+
 	if (addr) {
 		addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
 		if (addr != (unsigned long) -ENOMEM)
91
@@ -1222,8 +1226,8 @@ arch_get_unmapped_area(struct file *filp
92 93 94 95 96 97 98 99 100 101
 	}
 
 	/* Next, try allocating at TASK_UNMAPPED_BASE.  */
-	addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
-					 len, limit);
+	addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
+
 	if (addr != (unsigned long) -ENOMEM)
 		return addr;
 
102 103 104
diff -urNp linux-2.6.30.8/arch/alpha/mm/fault.c linux-2.6.30.8/arch/alpha/mm/fault.c
--- linux-2.6.30.8/arch/alpha/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/alpha/mm/fault.c	2009-07-30 09:48:09.876636955 -0400
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
 	__reload_thread(pcb);
 }
 
+#ifdef CONFIG_PAX_PAGEEXEC
+/*
+ * PaX: decide what to do with offenders (regs->pc = fault address)
+ *
+ * returns 1 when task should be killed
+ *         2 when patched PLT trampoline was detected
+ *         3 when unpatched PLT trampoline was detected
+ */
+static int pax_handle_fetch_fault(struct pt_regs *regs)
+{
+
+#ifdef CONFIG_PAX_EMUPLT
+	int err;
+
+	do { /* PaX: patched PLT emulation #1 */
+		unsigned int ldah, ldq, jmp;
+
+		err = get_user(ldah, (unsigned int *)regs->pc);
+		err |= get_user(ldq, (unsigned int *)(regs->pc+4));
+		err |= get_user(jmp, (unsigned int *)(regs->pc+8));
+
+		if (err)
+			break;
+
+		if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
+		    (ldq & 0xFFFF0000U) == 0xA77B0000U &&
+		    jmp == 0x6BFB0000U)
+		{
+			unsigned long r27, addr;
+			unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
+			unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
+
+			addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
+			err = get_user(r27, (unsigned long *)addr);
+			if (err)
+				break;
+
+			regs->r27 = r27;
+			regs->pc = r27;
+			return 2;
+		}
+	} while (0);
+
+	do { /* PaX: patched PLT emulation #2 */
+		unsigned int ldah, lda, br;
+
+		err = get_user(ldah, (unsigned int *)regs->pc);
+		err |= get_user(lda, (unsigned int *)(regs->pc+4));
+		err |= get_user(br, (unsigned int *)(regs->pc+8));
+
+		if (err)
+			break;
+
+		if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
+		    (lda & 0xFFFF0000U) == 0xA77B0000U &&
+		    (br & 0xFFE00000U) == 0xC3E00000U)
+		{
+			unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
+			unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
+			unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
+
+			regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
+			regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
+			return 2;
+		}
+	} while (0);
+
+	do { /* PaX: unpatched PLT emulation */
+		unsigned int br;
+
+		err = get_user(br, (unsigned int *)regs->pc);
+
+		if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
+			unsigned int br2, ldq, nop, jmp;
+			unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
+
+			addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
+			err = get_user(br2, (unsigned int *)addr);
+			err |= get_user(ldq, (unsigned int *)(addr+4));
+			err |= get_user(nop, (unsigned int *)(addr+8));
+			err |= get_user(jmp, (unsigned int *)(addr+12));
+			err |= get_user(resolver, (unsigned long *)(addr+16));
+
+			if (err)
+				break;
+
+			if (br2 == 0xC3600000U &&
+			    ldq == 0xA77B000CU &&
+			    nop == 0x47FF041FU &&
+			    jmp == 0x6B7B0000U)
+			{
+				regs->r28 = regs->pc+4;
+				regs->r27 = addr+16;
+				regs->pc = resolver;
+				return 3;
+			}
+		}
+	} while (0);
+#endif
+
+	return 1;
+}
+
+void pax_report_insns(void *pc, void *sp)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 5; i++) {
+		unsigned int c;
+		if (get_user(c, (unsigned int *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%08x ", c);
+	}
+	printk("\n");
+}
+#endif
 
 /*
  * This routine handles page faults.  It determines the address,
@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
  good_area:
 	si_code = SEGV_ACCERR;
 	if (cause < 0) {
-		if (!(vma->vm_flags & VM_EXEC))
+		if (!(vma->vm_flags & VM_EXEC)) {
+
+#ifdef CONFIG_PAX_PAGEEXEC
+			if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
+				goto bad_area;
+
+			up_read(&mm->mmap_sem);
+			switch (pax_handle_fetch_fault(regs)) {
+
+#ifdef CONFIG_PAX_EMUPLT
+			case 2:
+			case 3:
+				return;
+#endif
+
+			}
+			pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
+			do_group_exit(SIGKILL);
+#else
 			goto bad_area;
+#endif
+
+		}
 	} else if (!cause) {
 		/* Allow reads even for write-only mappings */
 		if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
261 262 263
diff -urNp linux-2.6.30.8/arch/arm/include/asm/atomic.h linux-2.6.30.8/arch/arm/include/asm/atomic.h
--- linux-2.6.30.8/arch/arm/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/include/asm/atomic.h	2009-07-30 09:48:09.876636955 -0400
264 265 266 267 268 269 270
@@ -235,6 +235,9 @@ static inline int atomic_add_unless(atom
 
 #define atomic_inc(v)		atomic_add(1, v)
 #define atomic_dec(v)		atomic_sub(1, v)
+#define atomic_inc_unchecked(v)		atomic_inc(v)
+#define atomic_add_unchecked(i, v)	atomic_add(i, v)
+#define atomic_sub_unchecked(i, v)	atomic_sub(i, v)
271 272 273
 
 #define atomic_inc_and_test(v)	(atomic_add_return(1, v) == 0)
 #define atomic_dec_and_test(v)	(atomic_sub_return(1, v) == 0)
274 275 276
diff -urNp linux-2.6.30.8/arch/arm/include/asm/elf.h linux-2.6.30.8/arch/arm/include/asm/elf.h
--- linux-2.6.30.8/arch/arm/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/include/asm/elf.h	2009-07-30 09:48:09.877630671 -0400
277
@@ -103,7 +103,14 @@ extern int arm_elf_read_implies_exec(con
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    the loader.  We need to make sure that it is out of the way of the program
    that it will "exec", and that there is sufficient room for the brk.  */
 
-#define ELF_ET_DYN_BASE	(2 * TASK_SIZE / 3)
+#define ELF_ET_DYN_BASE		(TASK_SIZE / 3 * 2)
+
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	0x00008000UL
+
+#define PAX_DELTA_MMAP_LEN	((current->personality == PER_LINUX_32BIT) ? 16 : 10)
+#define PAX_DELTA_STACK_LEN	((current->personality == PER_LINUX_32BIT) ? 16 : 10)
+#endif
 
 /* When the program starts, a1 contains a pointer to a function to be 
    registered with atexit, as per the SVR4 ABI.  A value of 0 means we 
293 294 295
diff -urNp linux-2.6.30.8/arch/arm/include/asm/kmap_types.h linux-2.6.30.8/arch/arm/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/arm/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/include/asm/kmap_types.h	2009-07-30 09:48:09.878525050 -0400
296
@@ -19,6 +19,7 @@ enum km_type {
297 298
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
299
 	KM_L2_CACHE,
300 301 302 303
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
304 305 306
diff -urNp linux-2.6.30.8/arch/arm/include/asm/uaccess.h linux-2.6.30.8/arch/arm/include/asm/uaccess.h
--- linux-2.6.30.8/arch/arm/include/asm/uaccess.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/include/asm/uaccess.h	2009-07-30 09:48:09.878525050 -0400
307 308 309
@@ -398,6 +398,9 @@ extern unsigned long __must_check __strn
 
 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
310
 {
311 312 313
+	if ((long)n < 0)
+		return n;
+
314 315
 	if (access_ok(VERIFY_READ, from, n))
 		n = __copy_from_user(to, from, n);
316 317 318 319 320 321 322 323 324 325
 	else /* security hole - plug it */
@@ -407,6 +410,9 @@ static inline unsigned long __must_check
 
 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
 {
+	if ((long)n < 0)
+		return n;
+
 	if (access_ok(VERIFY_WRITE, to, n))
 		n = __copy_to_user(to, from, n);
326
 	return n;
327 328 329
diff -urNp linux-2.6.30.8/arch/arm/mach-ns9xxx/clock.c linux-2.6.30.8/arch/arm/mach-ns9xxx/clock.c
--- linux-2.6.30.8/arch/arm/mach-ns9xxx/clock.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/mach-ns9xxx/clock.c	2009-07-30 09:48:09.879705308 -0400
330 331 332 333 334 335 336 337 338
@@ -195,7 +195,7 @@ static int clk_debugfs_open(struct inode
 	return single_open(file, clk_debugfs_show, NULL);
 }
 
-static struct file_operations clk_debugfs_operations = {
+static const struct file_operations clk_debugfs_operations = {
 	.open = clk_debugfs_open,
 	.read = seq_read,
 	.llseek = seq_lseek,
339 340 341
diff -urNp linux-2.6.30.8/arch/arm/mm/mmap.c linux-2.6.30.8/arch/arm/mm/mmap.c
--- linux-2.6.30.8/arch/arm/mm/mmap.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/arm/mm/mmap.c	2009-07-30 09:48:09.881684524 -0400
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
@@ -62,6 +62,10 @@ arch_get_unmapped_area(struct file *filp
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+#ifdef CONFIG_PAX_RANDMMAP
+	if (!(mm->pax_flags & MF_PAX_RANDMMAP))
+#endif
+
 	if (addr) {
 		if (do_align)
 			addr = COLOUR_ALIGN(addr, pgoff);
@@ -74,10 +78,10 @@ arch_get_unmapped_area(struct file *filp
 			return addr;
 	}
 	if (len > mm->cached_hole_size) {
-	        start_addr = addr = mm->free_area_cache;
+		start_addr = addr = mm->free_area_cache;
 	} else {
-	        start_addr = addr = TASK_UNMAPPED_BASE;
-	        mm->cached_hole_size = 0;
+		start_addr = addr = mm->mmap_base;
+		mm->cached_hole_size = 0;
 	}
 
 full_search:
@@ -93,8 +97,8 @@ full_search:
 			 * Start a new search - just in case we missed
 			 * some holes.
 			 */
-			if (start_addr != TASK_UNMAPPED_BASE) {
-				start_addr = addr = TASK_UNMAPPED_BASE;
+			if (start_addr != mm->mmap_base) {
+				start_addr = addr = mm->mmap_base;
 				mm->cached_hole_size = 0;
 				goto full_search;
 			}
378 379 380
diff -urNp linux-2.6.30.8/arch/avr32/include/asm/atomic.h linux-2.6.30.8/arch/avr32/include/asm/atomic.h
--- linux-2.6.30.8/arch/avr32/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/avr32/include/asm/atomic.h	2009-07-30 09:48:09.881684524 -0400
381 382 383 384 385 386 387 388 389 390 391 392 393
@@ -176,9 +176,12 @@ static inline int atomic_sub_if_positive
 #define atomic_cmpxchg(v, o, n)	(cmpxchg(&((v)->counter), (o), (n)))
 
 #define atomic_sub(i, v)	(void)atomic_sub_return(i, v)
+#define atomic_sub_unchecked(i, v)	atomic_sub((i), (v))
 #define atomic_add(i, v)	(void)atomic_add_return(i, v)
+#define atomic_add_unchecked(i, v)	atomic_add((i), (v))
 #define atomic_dec(v)		atomic_sub(1, (v))
 #define atomic_inc(v)		atomic_add(1, (v))
+#define atomic_inc_unchecked(v)	atomic_inc(v)
 
 #define atomic_dec_return(v)	atomic_sub_return(1, v)
 #define atomic_inc_return(v)	atomic_add_return(1, v)
394 395 396
diff -urNp linux-2.6.30.8/arch/avr32/include/asm/elf.h linux-2.6.30.8/arch/avr32/include/asm/elf.h
--- linux-2.6.30.8/arch/avr32/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/avr32/include/asm/elf.h	2009-07-30 09:48:09.881684524 -0400
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
    the loader.  We need to make sure that it is out of the way of the program
    that it will "exec", and that there is sufficient room for the brk.  */
 
-#define ELF_ET_DYN_BASE         (2 * TASK_SIZE / 3)
+#define ELF_ET_DYN_BASE		(TASK_SIZE / 3 * 2)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	0x00001000UL
+
+#define PAX_DELTA_MMAP_LEN	15
+#define PAX_DELTA_STACK_LEN	15
+#endif
 
 /* This yields a mask that user programs can use to figure out what
    instruction set this CPU supports.  This could be done in user space,
413 414 415
diff -urNp linux-2.6.30.8/arch/avr32/include/asm/kmap_types.h linux-2.6.30.8/arch/avr32/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/avr32/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/avr32/include/asm/kmap_types.h	2009-07-30 09:48:09.882650296 -0400
416 417 418 419 420 421 422 423 424 425
@@ -22,7 +22,8 @@ D(10)	KM_IRQ0,
 D(11)	KM_IRQ1,
 D(12)	KM_SOFTIRQ0,
 D(13)	KM_SOFTIRQ1,
-D(14)	KM_TYPE_NR
+D(14)	KM_CLEARPAGE,
+D(15)	KM_TYPE_NR
 };
 
 #undef D
426 427 428
diff -urNp linux-2.6.30.8/arch/avr32/mm/fault.c linux-2.6.30.8/arch/avr32/mm/fault.c
--- linux-2.6.30.8/arch/avr32/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/avr32/mm/fault.c	2009-07-30 09:48:09.882650296 -0400
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
 
 int exception_trace = 1;
 
+#ifdef CONFIG_PAX_PAGEEXEC
+void pax_report_insns(void *pc, void *sp)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 20; i++) {
+		unsigned char c;
+		if (get_user(c, (unsigned char *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%02x ", c);
+	}
+	printk("\n");
+}
+#endif
+
 /*
  * This routine handles page faults. It determines the address and the
  * problem, and then passes it off to one of the appropriate routines.
@@ -157,6 +174,16 @@ bad_area:
 	up_read(&mm->mmap_sem);
 
 	if (user_mode(regs)) {
+
+#ifdef CONFIG_PAX_PAGEEXEC
+		if (mm->pax_flags & MF_PAX_PAGEEXEC) {
+			if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
+				pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
+				do_group_exit(SIGKILL);
+			}
+		}
+#endif
+
 		if (exception_trace && printk_ratelimit())
 			printk("%s%s[%d]: segfault at %08lx pc %08lx "
 			       "sp %08lx ecr %lu\n",
470 471 472
diff -urNp linux-2.6.30.8/arch/blackfin/include/asm/atomic.h linux-2.6.30.8/arch/blackfin/include/asm/atomic.h
--- linux-2.6.30.8/arch/blackfin/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/blackfin/include/asm/atomic.h	2009-07-30 09:48:09.882650296 -0400
473 474 475 476 477 478 479 480 481 482
@@ -178,6 +178,9 @@ static inline void atomic_set_mask(unsig
 
 #endif /* !CONFIG_SMP */
 
+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
+#define atomic_inc_unchecked(v) atomic_inc((v))
 #define atomic_add_negative(a, v)	(atomic_add_return((a), (v)) < 0)
 #define atomic_dec_return(v) atomic_sub_return(1,(v))
 #define atomic_inc_return(v) atomic_add_return(1,(v))
483 484 485
diff -urNp linux-2.6.30.8/arch/blackfin/include/asm/kmap_types.h linux-2.6.30.8/arch/blackfin/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/blackfin/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/blackfin/include/asm/kmap_types.h	2009-07-30 09:48:09.883618875 -0400
486 487 488 489 490 491 492 493
@@ -15,6 +15,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
494 495 496
diff -urNp linux-2.6.30.8/arch/blackfin/mach-bf561/coreb.c linux-2.6.30.8/arch/blackfin/mach-bf561/coreb.c
--- linux-2.6.30.8/arch/blackfin/mach-bf561/coreb.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/blackfin/mach-bf561/coreb.c	2009-07-30 09:48:09.883618875 -0400
497 498 499 500 501 502 503 504 505
@@ -292,7 +292,7 @@ static int coreb_ioctl(struct inode *ino
 	return retval;
 }
 
-static struct file_operations coreb_fops = {
+static const struct file_operations coreb_fops = {
 	.owner = THIS_MODULE,
 	.llseek = coreb_lseek,
 	.read = coreb_read,
506 507 508
diff -urNp linux-2.6.30.8/arch/cris/arch-v10/drivers/sync_serial.c linux-2.6.30.8/arch/cris/arch-v10/drivers/sync_serial.c
--- linux-2.6.30.8/arch/cris/arch-v10/drivers/sync_serial.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/cris/arch-v10/drivers/sync_serial.c	2009-07-30 09:48:09.883618875 -0400
509 510 511 512 513 514 515 516 517
@@ -244,7 +244,7 @@ static unsigned sync_serial_prescale_sha
 
 #define NUMBER_OF_PORTS 2
 
-static struct file_operations sync_serial_fops = {
+static const struct file_operations sync_serial_fops = {
 	.owner   = THIS_MODULE,
 	.write   = sync_serial_write,
 	.read    = sync_serial_read,
518 519 520
diff -urNp linux-2.6.30.8/arch/cris/arch-v32/drivers/mach-fs/gpio.c linux-2.6.30.8/arch/cris/arch-v32/drivers/mach-fs/gpio.c
--- linux-2.6.30.8/arch/cris/arch-v32/drivers/mach-fs/gpio.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/cris/arch-v32/drivers/mach-fs/gpio.c	2009-07-30 12:06:52.081911892 -0400
521 522 523 524 525 526 527 528 529
@@ -855,7 +855,7 @@ gpio_leds_ioctl(unsigned int cmd, unsign
 	return 0;
 }
 
-struct file_operations gpio_fops = {
+struct struct file_operations gpio_fops = {
 	.owner       = THIS_MODULE,
 	.poll        = gpio_poll,
 	.ioctl       = gpio_ioctl,
530 531 532
diff -urNp linux-2.6.30.8/arch/cris/include/asm/atomic.h linux-2.6.30.8/arch/cris/include/asm/atomic.h
--- linux-2.6.30.8/arch/cris/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/cris/include/asm/atomic.h	2009-07-30 09:48:09.884412595 -0400
533 534 535 536 537 538 539 540 541 542 543
@@ -152,6 +152,10 @@ static inline int atomic_add_unless(atom
 }
 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
+#define atomic_inc_unchecked(v) atomic_inc((v))
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
+
 /* Atomic operations are already serializing */
 #define smp_mb__before_atomic_dec()    barrier()
 #define smp_mb__after_atomic_dec()     barrier()
544 545 546
diff -urNp linux-2.6.30.8/arch/cris/include/asm/kmap_types.h linux-2.6.30.8/arch/cris/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/cris/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/cris/include/asm/kmap_types.h	2009-07-30 09:48:09.884412595 -0400
547 548 549 550 551 552 553 554
@@ -19,6 +19,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
555 556 557
diff -urNp linux-2.6.30.8/arch/frv/include/asm/atomic.h linux-2.6.30.8/arch/frv/include/asm/atomic.h
--- linux-2.6.30.8/arch/frv/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/frv/include/asm/atomic.h	2009-07-30 09:48:09.885412202 -0400
558 559 560 561 562 563 564 565 566 567 568
@@ -114,6 +114,10 @@ static inline void atomic_dec(atomic_t *
 	atomic_sub_return(1, v);
 }
 
+#define atomic_inc_unchecked(v)		atomic_inc(v)
+#define atomic_add_unchecked(i,v)	atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v)	atomic_sub((i),(v))
+
 #define atomic_dec_return(v)		atomic_sub_return(1, (v))
 #define atomic_inc_return(v)		atomic_add_return(1, (v))
 
569 570 571
diff -urNp linux-2.6.30.8/arch/frv/include/asm/kmap_types.h linux-2.6.30.8/arch/frv/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/frv/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/frv/include/asm/kmap_types.h	2009-07-30 09:48:09.885412202 -0400
572 573 574 575 576 577 578 579
@@ -23,6 +23,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
580 581 582
diff -urNp linux-2.6.30.8/arch/h8300/include/asm/atomic.h linux-2.6.30.8/arch/h8300/include/asm/atomic.h
--- linux-2.6.30.8/arch/h8300/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/h8300/include/asm/atomic.h	2009-07-30 09:48:09.885412202 -0400
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
@@ -26,6 +26,7 @@ static __inline__ int atomic_add_return(
 }
 
 #define atomic_add(i, v) atomic_add_return(i, v)
+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
 #define atomic_add_negative(a, v)	(atomic_add_return((a), (v)) < 0)
 
 static __inline__ int atomic_sub_return(int i, atomic_t *v)
@@ -38,6 +39,7 @@ static __inline__ int atomic_sub_return(
 }
 
 #define atomic_sub(i, v) atomic_sub_return(i, v)
+#define atomic_subUnchecked(i, v) atomic_sub(i, v)
 #define atomic_sub_and_test(i,v) (atomic_sub_return(i, v) == 0)
 
 static __inline__ int atomic_inc_return(atomic_t *v)
@@ -51,6 +53,7 @@ static __inline__ int atomic_inc_return(
 }
 
 #define atomic_inc(v) atomic_inc_return(v)
+#define atomic_inc_unchecked(v) atomic_inc(v)
 
 /*
  * atomic_inc_and_test - increment and test
607 608 609
diff -urNp linux-2.6.30.8/arch/h8300/include/asm/kmap_types.h linux-2.6.30.8/arch/h8300/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/h8300/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/h8300/include/asm/kmap_types.h	2009-07-30 09:48:09.885412202 -0400
610 611 612 613 614 615 616 617
@@ -15,6 +15,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
618 619 620
diff -urNp linux-2.6.30.8/arch/ia64/ia32/binfmt_elf32.c linux-2.6.30.8/arch/ia64/ia32/binfmt_elf32.c
--- linux-2.6.30.8/arch/ia64/ia32/binfmt_elf32.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/ia32/binfmt_elf32.c	2009-07-30 09:48:09.886522893 -0400
621 622 623 624 625 626 627 628 629 630 631 632 633 634
@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
 
 #define elf_read_implies_exec(ex, have_pt_gnu_stack)	(!(have_pt_gnu_stack))
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
+
+#define PAX_DELTA_MMAP_LEN	(current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
+#define PAX_DELTA_STACK_LEN	(current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
+#endif
+
 /* Ugly but avoids duplication */
 #include "../../../fs/binfmt_elf.c"
 
635 636 637 638 639 640 641 642 643 644 645 646 647 648
@@ -69,11 +76,11 @@ ia32_install_gate_page (struct vm_area_s
 }
 
 
-static struct vm_operations_struct ia32_shared_page_vm_ops = {
+static const struct vm_operations_struct ia32_shared_page_vm_ops = {
 	.fault = ia32_install_shared_page
 };
 
-static struct vm_operations_struct ia32_gate_page_vm_ops = {
+static const struct vm_operations_struct ia32_gate_page_vm_ops = {
 	.fault = ia32_install_gate_page
 };
 
649 650 651
diff -urNp linux-2.6.30.8/arch/ia64/ia32/ia32priv.h linux-2.6.30.8/arch/ia64/ia32/ia32priv.h
--- linux-2.6.30.8/arch/ia64/ia32/ia32priv.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/ia32/ia32priv.h	2009-07-30 09:48:09.886522893 -0400
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
 #define ELF_DATA	ELFDATA2LSB
 #define ELF_ARCH	EM_386
 
-#define IA32_STACK_TOP		IA32_PAGE_OFFSET
+#ifdef CONFIG_PAX_RANDUSTACK
+#define __IA32_DELTA_STACK	(current->mm->delta_stack)
+#else
+#define __IA32_DELTA_STACK	0UL
+#endif
+
+#define IA32_STACK_TOP		(IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
+
 #define IA32_GATE_OFFSET	IA32_PAGE_OFFSET
 #define IA32_GATE_END		IA32_PAGE_OFFSET + PAGE_SIZE
 
668 669 670
diff -urNp linux-2.6.30.8/arch/ia64/include/asm/atomic.h linux-2.6.30.8/arch/ia64/include/asm/atomic.h
--- linux-2.6.30.8/arch/ia64/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/include/asm/atomic.h	2009-07-30 09:48:09.886522893 -0400
671 672 673 674 675 676 677 678 679 680 681 682
@@ -201,8 +201,11 @@ atomic64_add_negative (__s64 i, atomic64
 #define atomic64_inc_and_test(v)	(atomic64_add_return(1, (v)) == 0)
 
 #define atomic_add(i,v)			atomic_add_return((i), (v))
+#define atomic_add_unchecked(i,v)	atomic_add((i), (v))
 #define atomic_sub(i,v)			atomic_sub_return((i), (v))
+#define atomic_sub_unchecked(i,v)	atomic_sub((i), (v))
 #define atomic_inc(v)			atomic_add(1, (v))
+#define atomic_inc_unchecked(v)		atomic_inc(v)
 #define atomic_dec(v)			atomic_sub(1, (v))
 
 #define atomic64_add(i,v)		atomic64_add_return((i), (v))
683 684 685
diff -urNp linux-2.6.30.8/arch/ia64/include/asm/elf.h linux-2.6.30.8/arch/ia64/include/asm/elf.h
--- linux-2.6.30.8/arch/ia64/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/include/asm/elf.h	2009-07-30 09:48:09.887468908 -0400
686 687 688 689 690 691 692 693 694 695 696 697 698 699
@@ -43,6 +43,13 @@
  */
 #define ELF_ET_DYN_BASE		(TASK_UNMAPPED_BASE + 0x800000000UL)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
+
+#define PAX_DELTA_MMAP_LEN	(current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
+#define PAX_DELTA_STACK_LEN	(current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
+#endif
+
 #define PT_IA_64_UNWIND		0x70000001
 
 /* IA-64 relocations: */
700 701 702
diff -urNp linux-2.6.30.8/arch/ia64/include/asm/kmap_types.h linux-2.6.30.8/arch/ia64/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/ia64/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/include/asm/kmap_types.h	2009-07-30 09:48:09.887468908 -0400
703 704 705 706 707 708 709 710 711 712
@@ -22,7 +22,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_CLEARPAGE,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
713 714 715
diff -urNp linux-2.6.30.8/arch/ia64/include/asm/pgtable.h linux-2.6.30.8/arch/ia64/include/asm/pgtable.h
--- linux-2.6.30.8/arch/ia64/include/asm/pgtable.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/include/asm/pgtable.h	2009-07-30 09:48:09.887468908 -0400
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
@@ -143,6 +143,17 @@
 #define PAGE_READONLY	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
 #define PAGE_COPY	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
 #define PAGE_COPY_EXEC	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
+
+#ifdef CONFIG_PAX_PAGEEXEC
+# define PAGE_SHARED_NOEXEC	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
+# define PAGE_READONLY_NOEXEC	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
+# define PAGE_COPY_NOEXEC	__pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
+#else
+# define PAGE_SHARED_NOEXEC	PAGE_SHARED
+# define PAGE_READONLY_NOEXEC	PAGE_READONLY
+# define PAGE_COPY_NOEXEC	PAGE_COPY
+#endif
+
 #define PAGE_GATE	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
 #define PAGE_KERNEL	__pgprot(__DIRTY_BITS  | _PAGE_PL_0 | _PAGE_AR_RWX)
 #define PAGE_KERNELRX	__pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
734 735 736
diff -urNp linux-2.6.30.8/arch/ia64/include/asm/uaccess.h linux-2.6.30.8/arch/ia64/include/asm/uaccess.h
--- linux-2.6.30.8/arch/ia64/include/asm/uaccess.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/include/asm/uaccess.h	2009-07-30 11:10:48.660249525 -0400
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
 	const void *__cu_from = (from);							\
 	long __cu_len = (n);								\
 											\
-	if (__access_ok(__cu_to, __cu_len, get_fs()))					\
+	if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs()))	\
 		__cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len);	\
 	__cu_len;									\
 })
@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
 	long __cu_len = (n);								\
 											\
 	__chk_user_ptr(__cu_from);							\
-	if (__access_ok(__cu_from, __cu_len, get_fs()))					\
+	if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs()))	\
 		__cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len);	\
 	__cu_len;									\
 })
755 756 757
diff -urNp linux-2.6.30.8/arch/ia64/kernel/module.c linux-2.6.30.8/arch/ia64/kernel/module.c
--- linux-2.6.30.8/arch/ia64/kernel/module.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/kernel/module.c	2009-07-30 09:48:09.888412729 -0400
758 759 760 761 762 763 764 765 766 767
@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
 void
 module_free (struct module *mod, void *module_region)
 {
-	if (mod && mod->arch.init_unw_table &&
-	    module_region == mod->module_init) {
+	if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
 		unw_remove_unwind_table(mod->arch.init_unw_table);
 		mod->arch.init_unw_table = NULL;
 	}
768
@@ -499,15 +498,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
 }
 
 static inline int
+in_init_rx (const struct module *mod, uint64_t addr)
+{
+	return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
+}
+
+static inline int
+in_init_rw (const struct module *mod, uint64_t addr)
+{
+	return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
+}
+
+static inline int
 in_init (const struct module *mod, uint64_t addr)
 {
-	return addr - (uint64_t) mod->module_init < mod->init_size;
+	return in_init_rx(mod, addr) || in_init_rw(mod, addr);
+}
+
+static inline int
+in_core_rx (const struct module *mod, uint64_t addr)
+{
+	return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
+}
+
+static inline int
+in_core_rw (const struct module *mod, uint64_t addr)
+{
+	return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
 }
 
 static inline int
 in_core (const struct module *mod, uint64_t addr)
 {
-	return addr - (uint64_t) mod->module_core < mod->core_size;
+	return in_core_rx(mod, addr) || in_core_rw(mod, addr);
 }
 
 static inline int
810
@@ -690,7 +713,14 @@ do_reloc (struct module *mod, uint8_t r_
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
 		break;
 
 	      case RV_BDREL:
-		val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
+		if (in_init_rx(mod, val))
+			val -= (uint64_t) mod->module_init_rx;
+		else if (in_init_rw(mod, val))
+			val -= (uint64_t) mod->module_init_rw;
+		else if (in_core_rx(mod, val))
+			val -= (uint64_t) mod->module_core_rx;
+		else if (in_core_rw(mod, val))
+			val -= (uint64_t) mod->module_core_rw;
 		break;
 
 	      case RV_LTV:
826
@@ -824,15 +854,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
 		 *     addresses have been selected...
 		 */
 		uint64_t gp;
-		if (mod->core_size > MAX_LTOFF)
+		if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
 			/*
 			 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
 			 * at the end of the module.
 			 */
-			gp = mod->core_size - MAX_LTOFF / 2;
+			gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
 		else
-			gp = mod->core_size / 2;
-		gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
+			gp = (mod->core_size_rx + mod->core_size_rw) / 2;
+		gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
 		mod->arch.gp = gp;
 		DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
 	}
846 847 848
diff -urNp linux-2.6.30.8/arch/ia64/kernel/sys_ia64.c linux-2.6.30.8/arch/ia64/kernel/sys_ia64.c
--- linux-2.6.30.8/arch/ia64/kernel/sys_ia64.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/kernel/sys_ia64.c	2009-07-30 09:48:09.888412729 -0400
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
 	if (REGION_NUMBER(addr) == RGN_HPAGE)
 		addr = 0;
 #endif
+
+#ifdef CONFIG_PAX_RANDMMAP
+	if (mm->pax_flags & MF_PAX_RANDMMAP)
+		addr = mm->free_area_cache;
+	else
+#endif
+
 	if (!addr)
 		addr = mm->free_area_cache;
 
@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
 	for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
 		/* At this point:  (!vma || addr < vma->vm_end). */
 		if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
-			if (start_addr != TASK_UNMAPPED_BASE) {
+			if (start_addr != mm->mmap_base) {
 				/* Start a new search --- just in case we missed some holes.  */
-				addr = TASK_UNMAPPED_BASE;
+				addr = mm->mmap_base;
 				goto full_search;
 			}
 			return -ENOMEM;
875 876 877
diff -urNp linux-2.6.30.8/arch/ia64/mm/fault.c linux-2.6.30.8/arch/ia64/mm/fault.c
--- linux-2.6.30.8/arch/ia64/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/mm/fault.c	2009-07-30 09:48:09.889484146 -0400
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned 
 	return pte_present(pte);
 }
 
+#ifdef CONFIG_PAX_PAGEEXEC
+void pax_report_insns(void *pc, void *sp)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 8; i++) {
+		unsigned int c;
+		if (get_user(c, (unsigned int *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%08x ", c);
+	}
+	printk("\n");
+}
+#endif
+
 void __kprobes
 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
 {
@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
 	mask = (  (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
 		| (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
 
-	if ((vma->vm_flags & mask) != mask)
+	if ((vma->vm_flags & mask) != mask) {
+
+#ifdef CONFIG_PAX_PAGEEXEC
+		if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
+			if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
+				goto bad_area;
+
+			up_read(&mm->mmap_sem);
+			pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
+			do_group_exit(SIGKILL);
+		}
+#endif
+
 		goto bad_area;
 
+	}
+
   survive:
 	/*
 	 * If for any reason at all we couldn't handle the fault, make
927 928 929
diff -urNp linux-2.6.30.8/arch/ia64/mm/init.c linux-2.6.30.8/arch/ia64/mm/init.c
--- linux-2.6.30.8/arch/ia64/mm/init.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/ia64/mm/init.c	2009-07-30 09:48:09.889484146 -0400
930
@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
 		vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
 		vma->vm_end = vma->vm_start + PAGE_SIZE;
 		vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
+
+#ifdef CONFIG_PAX_PAGEEXEC
+		if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
+			vma->vm_flags &= ~VM_EXEC;
+
+#ifdef CONFIG_PAX_MPROTECT
+			if (current->mm->pax_flags & MF_PAX_MPROTECT)
+				vma->vm_flags &= ~VM_MAYEXEC;
+#endif
+
+		}
+#endif
+
 		vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 		down_write(&current->mm->mmap_sem);
 		if (insert_vm_struct(current->mm, vma)) {
950 951 952
diff -urNp linux-2.6.30.8/arch/m32r/include/asm/atomic.h linux-2.6.30.8/arch/m32r/include/asm/atomic.h
--- linux-2.6.30.8/arch/m32r/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m32r/include/asm/atomic.h	2009-07-30 09:48:09.889484146 -0400
953 954 955 956 957 958 959 960 961 962 963
@@ -308,6 +308,10 @@ static __inline__ void atomic_set_mask(u
 	local_irq_restore(flags);
 }
 
+#define atomic_inc_unchecked(v)		atomic_inc(v)
+#define atomic_add_unchecked(i,v)	atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v)	atomic_sub((i),(v))
+
 /* Atomic operations are already serializing on m32r */
 #define smp_mb__before_atomic_dec()	barrier()
 #define smp_mb__after_atomic_dec()	barrier()
964 965 966
diff -urNp linux-2.6.30.8/arch/m32r/include/asm/kmap_types.h linux-2.6.30.8/arch/m32r/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/m32r/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m32r/include/asm/kmap_types.h	2009-07-30 09:48:09.890443797 -0400
967 968 969 970 971 972 973 974 975 976
@@ -21,7 +21,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_CLEARPAGE,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
977 978 979
diff -urNp linux-2.6.30.8/arch/m32r/lib/usercopy.c linux-2.6.30.8/arch/m32r/lib/usercopy.c
--- linux-2.6.30.8/arch/m32r/lib/usercopy.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m32r/lib/usercopy.c	2009-07-30 09:48:09.890443797 -0400
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
@@ -14,6 +14,9 @@
 unsigned long
 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
+	if ((long)n < 0)
+		return n;
+
 	prefetch(from);
 	if (access_ok(VERIFY_WRITE, to, n))
 		__copy_user(to,from,n);
@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, 
 unsigned long
 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+	if ((long)n < 0)
+		return n;
+
997 998 999
 	prefetchw(to);
 	if (access_ok(VERIFY_READ, from, n))
 		__copy_user_zeroing(to,from,n);
1000 1001 1002
diff -urNp linux-2.6.30.8/arch/m68k/include/asm/atomic_mm.h linux-2.6.30.8/arch/m68k/include/asm/atomic_mm.h
--- linux-2.6.30.8/arch/m68k/include/asm/atomic_mm.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m68k/include/asm/atomic_mm.h	2009-07-30 09:48:09.890443797 -0400
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
@@ -186,6 +186,10 @@ static __inline__ int atomic_add_unless(
 
 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
+#define atomic_inc_unchecked(v) atomic_inc((v))
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
+
 /* Atomic operations are already serializing */
 #define smp_mb__before_atomic_dec()	barrier()
 #define smp_mb__after_atomic_dec()	barrier()
1014 1015 1016
diff -urNp linux-2.6.30.8/arch/m68k/include/asm/atomic_no.h linux-2.6.30.8/arch/m68k/include/asm/atomic_no.h
--- linux-2.6.30.8/arch/m68k/include/asm/atomic_no.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m68k/include/asm/atomic_no.h	2009-07-30 09:48:09.890443797 -0400
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
@@ -151,5 +151,9 @@ static __inline__ int atomic_add_unless(
 #define atomic_dec_return(v) atomic_sub_return(1,(v))
 #define atomic_inc_return(v) atomic_add_return(1,(v))
 
+#define atomic_inc_unchecked(v) atomic_inc((v))
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
+
 #include <asm-generic/atomic.h>
 #endif /* __ARCH_M68KNOMMU_ATOMIC __ */
1027 1028 1029
diff -urNp linux-2.6.30.8/arch/m68k/include/asm/kmap_types.h linux-2.6.30.8/arch/m68k/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/m68k/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/m68k/include/asm/kmap_types.h	2009-07-30 09:48:09.891413194 -0400
1030 1031 1032 1033 1034 1035 1036 1037
@@ -15,6 +15,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
1038 1039 1040
diff -urNp linux-2.6.30.8/arch/mips/include/asm/atomic.h linux-2.6.30.8/arch/mips/include/asm/atomic.h
--- linux-2.6.30.8/arch/mips/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/include/asm/atomic.h	2009-07-30 09:48:09.891413194 -0400
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
@@ -381,6 +381,9 @@ static __inline__ int atomic_add_unless(
  * Atomically increments @v by 1.
  */
 #define atomic_inc(v) atomic_add(1, (v))
+#define atomic_inc_unchecked(v) atomic_inc(v)
+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
 
 /*
  * atomic_dec - decrement and test
1051 1052 1053
diff -urNp linux-2.6.30.8/arch/mips/include/asm/elf.h linux-2.6.30.8/arch/mips/include/asm/elf.h
--- linux-2.6.30.8/arch/mips/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/include/asm/elf.h	2009-07-30 09:48:09.891413194 -0400
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
@@ -364,4 +364,11 @@ extern int dump_task_fpu(struct task_str
 #define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
 #endif
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
+
+#define PAX_DELTA_MMAP_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#define PAX_DELTA_STACK_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#endif
+
 #endif /* _ASM_ELF_H */
1066 1067 1068
diff -urNp linux-2.6.30.8/arch/mips/include/asm/kmap_types.h linux-2.6.30.8/arch/mips/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/mips/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/include/asm/kmap_types.h	2009-07-30 09:48:09.892412592 -0400
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
@@ -22,7 +22,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_CLEARPAGE,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
1079 1080 1081
diff -urNp linux-2.6.30.8/arch/mips/include/asm/page.h linux-2.6.30.8/arch/mips/include/asm/page.h
--- linux-2.6.30.8/arch/mips/include/asm/page.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/include/asm/page.h	2009-07-30 09:48:09.892412592 -0400
1082
@@ -85,7 +85,7 @@ extern void copy_user_highpage(struct pa
1083 1084 1085 1086 1087 1088 1089 1090
   #ifdef CONFIG_CPU_MIPS32
     typedef struct { unsigned long pte_low, pte_high; } pte_t;
     #define pte_val(x)    ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
-    #define __pte(x)      ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
+    #define __pte(x)      ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
   #else
      typedef struct { unsigned long long pte; } pte_t;
      #define pte_val(x)	((x).pte)
1091 1092 1093
diff -urNp linux-2.6.30.8/arch/mips/include/asm/system.h linux-2.6.30.8/arch/mips/include/asm/system.h
--- linux-2.6.30.8/arch/mips/include/asm/system.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/include/asm/system.h	2009-07-30 09:48:09.892412592 -0400
1094 1095 1096 1097 1098 1099 1100 1101
@@ -217,6 +217,6 @@ extern void per_cpu_trap_init(void);
  */
 #define __ARCH_WANT_UNLOCKED_CTXSW
 
-extern unsigned long arch_align_stack(unsigned long sp);
+#define arch_align_stack(x) ((x) & ALMASK)
 
 #endif /* _ASM_SYSTEM_H */
1102 1103 1104
diff -urNp linux-2.6.30.8/arch/mips/kernel/binfmt_elfn32.c linux-2.6.30.8/arch/mips/kernel/binfmt_elfn32.c
--- linux-2.6.30.8/arch/mips/kernel/binfmt_elfn32.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/kernel/binfmt_elfn32.c	2009-07-30 09:48:09.892412592 -0400
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
 #undef ELF_ET_DYN_BASE
 #define ELF_ET_DYN_BASE         (TASK32_SIZE / 3 * 2)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
+
+#define PAX_DELTA_MMAP_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#define PAX_DELTA_STACK_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#endif
+
 #include <asm/processor.h>
 #include <linux/module.h>
 #include <linux/elfcore.h>
1119 1120 1121
diff -urNp linux-2.6.30.8/arch/mips/kernel/binfmt_elfo32.c linux-2.6.30.8/arch/mips/kernel/binfmt_elfo32.c
--- linux-2.6.30.8/arch/mips/kernel/binfmt_elfo32.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/kernel/binfmt_elfo32.c	2009-07-30 09:48:09.893444022 -0400
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
 #undef ELF_ET_DYN_BASE
 #define ELF_ET_DYN_BASE         (TASK32_SIZE / 3 * 2)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
+
+#define PAX_DELTA_MMAP_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#define PAX_DELTA_STACK_LEN	(test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#endif
+
 #include <asm/processor.h>
 #include <linux/module.h>
 #include <linux/elfcore.h>
1136 1137 1138
diff -urNp linux-2.6.30.8/arch/mips/kernel/process.c linux-2.6.30.8/arch/mips/kernel/process.c
--- linux-2.6.30.8/arch/mips/kernel/process.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/kernel/process.c	2009-07-30 09:48:09.893444022 -0400
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
@@ -457,15 +457,3 @@ unsigned long get_wchan(struct task_stru
 out:
 	return pc;
 }
-
-/*
- * Don't forget that the stack pointer must be aligned on a 8 bytes
- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
- */
-unsigned long arch_align_stack(unsigned long sp)
-{
-	if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
-		sp -= get_random_int() & ~PAGE_MASK;
-
-	return sp & ALMASK;
-}
1155 1156 1157
diff -urNp linux-2.6.30.8/arch/mips/kernel/syscall.c linux-2.6.30.8/arch/mips/kernel/syscall.c
--- linux-2.6.30.8/arch/mips/kernel/syscall.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/kernel/syscall.c	2009-07-30 09:48:09.893444022 -0400
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
@@ -99,6 +99,11 @@ unsigned long arch_get_unmapped_area(str
 	do_color_align = 0;
 	if (filp || (flags & MAP_SHARED))
 		do_color_align = 1;
+
+#ifdef CONFIG_PAX_RANDMMAP
+	if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
+#endif
+
 	if (addr) {
 		if (do_color_align)
 			addr = COLOUR_ALIGN(addr, pgoff);
@@ -109,7 +114,7 @@ unsigned long arch_get_unmapped_area(str
 		    (!vmm || addr + len <= vmm->vm_start))
 			return addr;
 	}
-	addr = TASK_UNMAPPED_BASE;
+	addr = current->mm->mmap_base;
 	if (do_color_align)
 		addr = COLOUR_ALIGN(addr, pgoff);
 	else
1179 1180 1181
diff -urNp linux-2.6.30.8/arch/mips/mm/fault.c linux-2.6.30.8/arch/mips/mm/fault.c
--- linux-2.6.30.8/arch/mips/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mips/mm/fault.c	2009-07-30 09:48:09.896533953 -0400
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
@@ -26,6 +26,23 @@
 #include <asm/ptrace.h>
 #include <asm/highmem.h>		/* For VMALLOC_END */
 
+#ifdef CONFIG_PAX_PAGEEXEC
+void pax_report_insns(void *pc)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 5; i++) {
+		unsigned int c;
+		if (get_user(c, (unsigned int *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%08x ", c);
+	}
+	printk("\n");
+}
+#endif
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
1206 1207 1208
diff -urNp linux-2.6.30.8/arch/mn10300/include/asm/atomic.h linux-2.6.30.8/arch/mn10300/include/asm/atomic.h
--- linux-2.6.30.8/arch/mn10300/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mn10300/include/asm/atomic.h	2009-07-30 09:48:09.897612189 -0400
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
@@ -145,6 +145,10 @@ static inline void atomic_clear_mask(uns
 #define atomic_xchg(ptr, v)		(xchg(&(ptr)->counter, (v)))
 #define atomic_cmpxchg(v, old, new)	(cmpxchg(&((v)->counter), (old), (new)))
 
+#define atomic_inc_unchecked(v)		atomic_inc(v)
+#define atomic_add_unchecked(i,v)	atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v)	atomic_sub((i),(v))
+
 /* Atomic operations are already serializing on MN10300??? */
 #define smp_mb__before_atomic_dec()	barrier()
 #define smp_mb__after_atomic_dec()	barrier()
1220 1221 1222
diff -urNp linux-2.6.30.8/arch/mn10300/include/asm/kmap_types.h linux-2.6.30.8/arch/mn10300/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/mn10300/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mn10300/include/asm/kmap_types.h	2009-07-30 09:48:09.897612189 -0400
1223 1224 1225 1226 1227 1228 1229 1230
@@ -25,6 +25,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
1231 1232 1233
diff -urNp linux-2.6.30.8/arch/mn10300/kernel/setup.c linux-2.6.30.8/arch/mn10300/kernel/setup.c
--- linux-2.6.30.8/arch/mn10300/kernel/setup.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/mn10300/kernel/setup.c	2009-07-30 09:48:09.897612189 -0400
1234
@@ -285,7 +285,7 @@ static void c_stop(struct seq_file *m, v
1235 1236 1237 1238 1239 1240 1241 1242
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
 	.start	= c_start,
 	.next	= c_next,
 	.stop	= c_stop,
1243 1244 1245
diff -urNp linux-2.6.30.8/arch/parisc/include/asm/atomic.h linux-2.6.30.8/arch/parisc/include/asm/atomic.h
--- linux-2.6.30.8/arch/parisc/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/include/asm/atomic.h	2009-07-30 09:48:09.898625493 -0400
1246 1247 1248
@@ -223,8 +223,11 @@ static __inline__ int atomic_add_unless(
 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
1249
 #define atomic_add(i,v)	((void)(__atomic_add_return( ((int)(i)),(v))))
1250
+#define atomic_add_unchecked(i,v)	atomic_add((i), (v))
1251
 #define atomic_sub(i,v)	((void)(__atomic_add_return(-((int)(i)),(v))))
1252 1253 1254 1255 1256
+#define atomic_sub_unchecked(i,v)	atomic_sub((i), (v))
 #define atomic_inc(v)	((void)(__atomic_add_return(   1,(v))))
+#define atomic_inc_unchecked(v)	atomic_inc(v)
 #define atomic_dec(v)	((void)(__atomic_add_return(  -1,(v))))
 
1257
 #define atomic_add_return(i,v)	(__atomic_add_return( ((int)(i)),(v)))
1258 1259 1260
diff -urNp linux-2.6.30.8/arch/parisc/include/asm/elf.h linux-2.6.30.8/arch/parisc/include/asm/elf.h
--- linux-2.6.30.8/arch/parisc/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/include/asm/elf.h	2009-07-30 09:48:09.898625493 -0400
1261
@@ -343,6 +343,13 @@ struct pt_regs;	/* forward declaration..
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
 
 #define ELF_ET_DYN_BASE         (TASK_UNMAPPED_BASE + 0x01000000)
 
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	0x10000UL
+
+#define PAX_DELTA_MMAP_LEN	16
+#define PAX_DELTA_STACK_LEN	16
+#endif
+
 /* This yields a mask that user programs can use to figure out what
    instruction set this CPU supports.  This could be done in user space,
    but it's not easy, and we've already done it here.  */
1275 1276 1277
diff -urNp linux-2.6.30.8/arch/parisc/include/asm/kmap_types.h linux-2.6.30.8/arch/parisc/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/parisc/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/include/asm/kmap_types.h	2009-07-30 09:48:09.898625493 -0400
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
@@ -22,7 +22,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_CLEARPAGE,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
1288 1289 1290
diff -urNp linux-2.6.30.8/arch/parisc/include/asm/pgtable.h linux-2.6.30.8/arch/parisc/include/asm/pgtable.h
--- linux-2.6.30.8/arch/parisc/include/asm/pgtable.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/include/asm/pgtable.h	2009-07-30 09:48:09.898625493 -0400
1291
@@ -207,6 +207,17 @@
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
 #define PAGE_EXECREAD   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
 #define PAGE_COPY       PAGE_EXECREAD
 #define PAGE_RWX        __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
+
+#ifdef CONFIG_PAX_PAGEEXEC
+# define PAGE_SHARED_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
+# define PAGE_COPY_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
+# define PAGE_READONLY_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
+#else
+# define PAGE_SHARED_NOEXEC	PAGE_SHARED
+# define PAGE_COPY_NOEXEC	PAGE_COPY
+# define PAGE_READONLY_NOEXEC	PAGE_READONLY
+#endif
+
 #define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
 #define PAGE_KERNEL_RO	__pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
 #define PAGE_KERNEL_UNC	__pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
1309 1310 1311
diff -urNp linux-2.6.30.8/arch/parisc/kernel/module.c linux-2.6.30.8/arch/parisc/kernel/module.c
--- linux-2.6.30.8/arch/parisc/kernel/module.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/kernel/module.c	2009-07-30 09:48:09.899565255 -0400
1312
@@ -91,16 +91,38 @@
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
 
 /* three functions to determine where in the module core
  * or init pieces the location is */
+static inline int in_init_rx(struct module *me, void *loc)
+{
+	return (loc >= me->module_init_rx &&
+		loc < (me->module_init_rx + me->init_size_rx));
+}
+
+static inline int in_init_rw(struct module *me, void *loc)
+{
+	return (loc >= me->module_init_rw &&
+		loc < (me->module_init_rw + me->init_size_rw));
+}
+
 static inline int in_init(struct module *me, void *loc)
 {
-	return (loc >= me->module_init &&
-		loc <= (me->module_init + me->init_size));
+	return in_init_rx(me, loc) || in_init_rw(me, loc);
+}
+
+static inline int in_core_rx(struct module *me, void *loc)
+{
+	return (loc >= me->module_core_rx &&
+		loc < (me->module_core_rx + me->core_size_rx));
+}
+
+static inline int in_core_rw(struct module *me, void *loc)
+{
+	return (loc >= me->module_core_rw &&
+		loc < (me->module_core_rw + me->core_size_rw));
 }
 
 static inline int in_core(struct module *me, void *loc)
 {
-	return (loc >= me->module_core &&
-		loc <= (me->module_core + me->core_size));
+	return in_core_rx(me, loc) || in_core_rw(me, loc);
 }
 
 static inline int in_local(struct module *me, void *loc)
1355
@@ -334,13 +356,13 @@ int module_frob_arch_sections(CONST Elf_
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
 	}
 
 	/* align things a bit */
-	me->core_size = ALIGN(me->core_size, 16);
-	me->arch.got_offset = me->core_size;
-	me->core_size += gots * sizeof(struct got_entry);
-
-	me->core_size = ALIGN(me->core_size, 16);
-	me->arch.fdesc_offset = me->core_size;
-	me->core_size += fdescs * sizeof(Elf_Fdesc);
+	me->core_size_rw = ALIGN(me->core_size_rw, 16);
+	me->arch.got_offset = me->core_size_rw;
+	me->core_size_rw += gots * sizeof(struct got_entry);
+
+	me->core_size_rw = ALIGN(me->core_size_rw, 16);
+	me->arch.fdesc_offset = me->core_size_rw;
+	me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
 
 	me->arch.got_max = gots;
 	me->arch.fdesc_max = fdescs;
1376
@@ -358,7 +380,7 @@ static Elf64_Word get_got(struct module 
1377 1378 1379 1380 1381 1382 1383 1384
 
 	BUG_ON(value == 0);
 
-	got = me->module_core + me->arch.got_offset;
+	got = me->module_core_rw + me->arch.got_offset;
 	for (i = 0; got[i].addr; i++)
 		if (got[i].addr == value)
 			goto out;
1385
@@ -376,7 +398,7 @@ static Elf64_Word get_got(struct module 
1386 1387 1388 1389 1390 1391 1392 1393
 #ifdef CONFIG_64BIT
 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
 {
-	Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
+	Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
 
 	if (!value) {
 		printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1394
@@ -394,7 +416,7 @@ static Elf_Addr get_fdesc(struct module 
1395 1396 1397 1398 1399 1400 1401 1402
 
 	/* Create new one */
 	fdesc->addr = value;
-	fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
+	fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
 	return (Elf_Addr)fdesc;
 }
 #endif /* CONFIG_64BIT */
1403
@@ -810,7 +832,7 @@ register_unwind_table(struct module *me,
1404 1405 1406 1407 1408 1409 1410 1411
 
 	table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
 	end = table + sechdrs[me->arch.unwind_section].sh_size;
-	gp = (Elf_Addr)me->module_core + me->arch.got_offset;
+	gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
 
 	DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
 	       me->arch.unwind_section, table, end, gp);
1412 1413 1414
diff -urNp linux-2.6.30.8/arch/parisc/kernel/sys_parisc.c linux-2.6.30.8/arch/parisc/kernel/sys_parisc.c
--- linux-2.6.30.8/arch/parisc/kernel/sys_parisc.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/kernel/sys_parisc.c	2009-07-30 09:48:09.899565255 -0400
1415 1416 1417 1418 1419 1420 1421 1422 1423
@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
 	if (flags & MAP_FIXED)
 		return addr;
 	if (!addr)
-		addr = TASK_UNMAPPED_BASE;
+		addr = current->mm->mmap_base;
 
 	if (filp) {
 		addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1424 1425 1426
diff -urNp linux-2.6.30.8/arch/parisc/kernel/traps.c linux-2.6.30.8/arch/parisc/kernel/traps.c
--- linux-2.6.30.8/arch/parisc/kernel/traps.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/kernel/traps.c	2009-07-30 09:48:09.900676754 -0400
1427
@@ -734,9 +734,7 @@ void notrace handle_interruption(int cod
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
 
 			down_read(&current->mm->mmap_sem);
 			vma = find_vma(current->mm,regs->iaoq[0]);
-			if (vma && (regs->iaoq[0] >= vma->vm_start)
-				&& (vma->vm_flags & VM_EXEC)) {
-
+			if (vma && (regs->iaoq[0] >= vma->vm_start)) {
 				fault_address = regs->iaoq[0];
 				fault_space = regs->iasq[0];
 
1438 1439 1440
diff -urNp linux-2.6.30.8/arch/parisc/mm/fault.c linux-2.6.30.8/arch/parisc/mm/fault.c
--- linux-2.6.30.8/arch/parisc/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/parisc/mm/fault.c	2009-07-30 09:48:09.900676754 -0400
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
@@ -16,6 +16,7 @@
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
+#include <linux/unistd.h>
 
 #include <asm/uaccess.h>
 #include <asm/traps.h>
@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
 static unsigned long
 parisc_acctyp(unsigned long code, unsigned int inst)
 {
-	if (code == 6 || code == 16)
+	if (code == 6 || code == 7 || code == 16)
 	    return VM_EXEC;
 
 	switch (inst & 0xf0000000) {
@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
 			}
 #endif
 
+#ifdef CONFIG_PAX_PAGEEXEC
+/*
+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
+ *
+ * returns 1 when task should be killed
+ *         2 when rt_sigreturn trampoline was detected
+ *         3 when unpatched PLT trampoline was detected
+ */
+static int pax_handle_fetch_fault(struct pt_regs *regs)
+{
+
+#ifdef CONFIG_PAX_EMUPLT
+	int err;
+
+	do { /* PaX: unpatched PLT emulation */
+		unsigned int bl, depwi;
+
+		err = get_user(bl, (unsigned int *)instruction_pointer(regs));
+		err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
+
+		if (err)
+			break;
+
+		if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
+			unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
+
+			err = get_user(ldw, (unsigned int *)addr);
+			err |= get_user(bv, (unsigned int *)(addr+4));
+			err |= get_user(ldw2, (unsigned int *)(addr+8));
+
+			if (err)
+				break;
+
+			if (ldw == 0x0E801096U &&
+			    bv == 0xEAC0C000U &&
+			    ldw2 == 0x0E881095U)
+			{
+				unsigned int resolver, map;
+
+				err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
+				err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
+				if (err)
+					break;
+
+				regs->gr[20] = instruction_pointer(regs)+8;
+				regs->gr[21] = map;
+				regs->gr[22] = resolver;
+				regs->iaoq[0] = resolver | 3UL;
+				regs->iaoq[1] = regs->iaoq[0] + 4;
+				return 3;
+			}
+		}
+	} while (0);
+#endif
+
+#ifdef CONFIG_PAX_EMUTRAMP
+
+#ifndef CONFIG_PAX_EMUSIGRT
+	if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
+		return 1;
+#endif
+
+	do { /* PaX: rt_sigreturn emulation */
+		unsigned int ldi1, ldi2, bel, nop;
+
+		err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
+		err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
+		err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
+		err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
+
+		if (err)
+			break;
+
+		if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
+		    ldi2 == 0x3414015AU &&
+		    bel == 0xE4008200U &&
+		    nop == 0x08000240U)
+		{
+			regs->gr[25] = (ldi1 & 2) >> 1;
+			regs->gr[20] = __NR_rt_sigreturn;
+			regs->gr[31] = regs->iaoq[1] + 16;
+			regs->sr[0] = regs->iasq[1];
+			regs->iaoq[0] = 0x100UL;
+			regs->iaoq[1] = regs->iaoq[0] + 4;
+			regs->iasq[0] = regs->sr[2];
+			regs->iasq[1] = regs->sr[2];
+			return 2;
+		}
+	} while (0);
+#endif
+
+	return 1;
+}
+
+void pax_report_insns(void *pc, void *sp)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 5; i++) {
+		unsigned int c;
+		if (get_user(c, (unsigned int *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%08x ", c);
+	}
+	printk("\n");
+}
+#endif
+
 int fixup_exception(struct pt_regs *regs)
 {
 	const struct exception_table_entry *fix;
@@ -193,8 +304,33 @@ good_area:
 
 	acc_type = parisc_acctyp(code,regs->iir);
 
-	if ((vma->vm_flags & acc_type) != acc_type)
+	if ((vma->vm_flags & acc_type) != acc_type) {
+
+#ifdef CONFIG_PAX_PAGEEXEC
+		if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
+		    (address & ~3UL) == instruction_pointer(regs))
+		{
+			up_read(&mm->mmap_sem);
+			switch (pax_handle_fetch_fault(regs)) {
+
+#ifdef CONFIG_PAX_EMUPLT
+			case 3:
+				return;
+#endif
+
+#ifdef CONFIG_PAX_EMUTRAMP
+			case 2:
+				return;
+#endif
+
+			}
+			pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
+			do_group_exit(SIGKILL);
+		}
+#endif
+
 		goto bad_area;
+	}
 
 	/*
 	 * If for any reason at all we couldn't handle the fault, make
1610 1611 1612
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/atomic.h linux-2.6.30.8/arch/powerpc/include/asm/atomic.h
--- linux-2.6.30.8/arch/powerpc/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/atomic.h	2009-07-30 09:48:09.900676754 -0400
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
@@ -244,6 +244,10 @@ static __inline__ int atomic_dec_if_posi
 	return t;
 }
 
+#define atomic_inc_unchecked(v) atomic_inc((v))
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
+
 #define smp_mb__before_atomic_dec()     smp_mb()
 #define smp_mb__after_atomic_dec()      smp_mb()
 #define smp_mb__before_atomic_inc()     smp_mb()
1624 1625 1626
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/elf.h linux-2.6.30.8/arch/powerpc/include/asm/elf.h
--- linux-2.6.30.8/arch/powerpc/include/asm/elf.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/elf.h	2009-07-30 09:48:09.901536944 -0400
1627 1628 1629
@@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
    the loader.  We need to make sure that it is out of the way of the program
    that it will "exec", and that there is sufficient room for the brk.  */
1630
 
1631 1632 1633 1634
-extern unsigned long randomize_et_dyn(unsigned long base);
-#define ELF_ET_DYN_BASE		(randomize_et_dyn(0x20000000))
+#define ELF_ET_DYN_BASE		(0x20000000)
+
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
+#ifdef CONFIG_PAX_ASLR
+#define PAX_ELF_ET_DYN_BASE	(0x10000000UL)
+
+#ifdef __powerpc64__
+#define PAX_DELTA_MMAP_LEN	(test_thread_flag(TIF_32BIT) ? 16 : 28)
+#define PAX_DELTA_STACK_LEN	(test_thread_flag(TIF_32BIT) ? 16 : 28)
+#else
+#define PAX_DELTA_MMAP_LEN	15
+#define PAX_DELTA_STACK_LEN	15
+#endif
+#endif
1646
 
1647 1648
 /*
  * Our registers are always unsigned longs, whether we're a 32 bit
1649 1650 1651
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/kmap_types.h linux-2.6.30.8/arch/powerpc/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/powerpc/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/kmap_types.h	2009-07-30 09:48:09.901536944 -0400
1652 1653 1654 1655 1656 1657 1658 1659
@@ -26,6 +26,7 @@ enum km_type {
 	KM_SOFTIRQ1,
 	KM_PPC_SYNC_PAGE,
 	KM_PPC_SYNC_ICACHE,
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
1660 1661 1662
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/page_64.h linux-2.6.30.8/arch/powerpc/include/asm/page_64.h
--- linux-2.6.30.8/arch/powerpc/include/asm/page_64.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/page_64.h	2009-07-30 09:48:09.902599231 -0400
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
@@ -170,15 +170,18 @@ do {						\
  * stack by default, so in the absense of a PT_GNU_STACK program header
  * we turn execute permission off.
  */
-#define VM_STACK_DEFAULT_FLAGS32	(VM_READ | VM_WRITE | VM_EXEC | \
-					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+#define VM_STACK_DEFAULT_FLAGS32 \
+	(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
+	 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
 #define VM_STACK_DEFAULT_FLAGS64	(VM_READ | VM_WRITE | \
 					 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
+#ifndef CONFIG_PAX_PAGEEXEC
 #define VM_STACK_DEFAULT_FLAGS \
 	(test_thread_flag(TIF_32BIT) ? \
 	 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
+#endif
 
 #include <asm-generic/page.h>
 
1684 1685 1686
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/page.h linux-2.6.30.8/arch/powerpc/include/asm/page.h
--- linux-2.6.30.8/arch/powerpc/include/asm/page.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/page.h	2009-07-30 09:48:09.902599231 -0400
1687
@@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
  * and needs to be executable.  This means the whole heap ends
  * up being executable.
  */
-#define VM_DATA_DEFAULT_FLAGS32	(VM_READ | VM_WRITE | VM_EXEC | \
-				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+#define VM_DATA_DEFAULT_FLAGS32 \
+	(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
+	 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
 #define VM_DATA_DEFAULT_FLAGS64	(VM_READ | VM_WRITE | \
 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1699 1700 1701
diff -urNp linux-2.6.30.8/arch/powerpc/include/asm/uaccess.h linux-2.6.30.8/arch/powerpc/include/asm/uaccess.h
--- linux-2.6.30.8/arch/powerpc/include/asm/uaccess.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/include/asm/uaccess.h	2009-07-30 11:10:48.774534063 -0400
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
@@ -334,6 +334,9 @@ static inline unsigned long copy_from_us
 {
 	unsigned long over;
 
+	if (((long)n < 0) || (n > INT_MAX))
+		return n;
+
 	if (access_ok(VERIFY_READ, from, n))
 		return __copy_tofrom_user((__force void __user *)to, from, n);
 	if ((unsigned long)from < TASK_SIZE) {
@@ -349,6 +352,9 @@ static inline unsigned long copy_to_user
 {
 	unsigned long over;
 
+	if (((long)n < 0) || (n > INT_MAX))
+		return n;
+
 	if (access_ok(VERIFY_WRITE, to, n))
 		return __copy_tofrom_user(to, (__force void __user *)from, n);
 	if ((unsigned long)to < TASK_SIZE) {
1722 1723 1724
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/module_32.c linux-2.6.30.8/arch/powerpc/kernel/module_32.c
--- linux-2.6.30.8/arch/powerpc/kernel/module_32.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/module_32.c	2009-07-30 09:48:09.903567873 -0400
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
 			me->arch.core_plt_section = i;
 	}
 	if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
-		printk("Module doesn't contain .plt or .init.plt sections.\n");
+		printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
 		return -ENOEXEC;
 	}
 
@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
 
 	DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
 	/* Init, or core PLT? */
-	if (location >= mod->module_core
-	    && location < mod->module_core + mod->core_size)
+	if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
+	    (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
 		entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
-	else
+	else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
+		 (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
 		entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
+	else {
+		printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
+		return ~0UL;
+	}
 
 	/* Find this entry, or if that fails, the next avail. entry */
 	while (entry->jump[0]) {
1754 1755 1756
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/process.c linux-2.6.30.8/arch/powerpc/kernel/process.c
--- linux-2.6.30.8/arch/powerpc/kernel/process.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/process.c	2009-07-30 09:48:09.903567873 -0400
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
@@ -1147,36 +1147,3 @@ unsigned long arch_align_stack(unsigned 
 		sp -= get_random_int() & ~PAGE_MASK;
 	return sp & ~0xf;
 }
-
-static inline unsigned long brk_rnd(void)
-{
-        unsigned long rnd = 0;
-
-	/* 8MB for 32bit, 1GB for 64bit */
-	if (is_32bit_task())
-		rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
-	else
-		rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
-
-	return rnd << PAGE_SHIFT;
-}
-
-unsigned long arch_randomize_brk(struct mm_struct *mm)
-{
-	unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
-
-	if (ret < mm->brk)
-		return mm->brk;
-
-	return ret;
-}
-
-unsigned long randomize_et_dyn(unsigned long base)
-{
-	unsigned long ret = PAGE_ALIGN(base + brk_rnd());
-
-	if (ret < base)
-		return base;
-
-	return ret;
-}
1794 1795 1796
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/setup-common.c linux-2.6.30.8/arch/powerpc/kernel/setup-common.c
--- linux-2.6.30.8/arch/powerpc/kernel/setup-common.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/setup-common.c	2009-07-30 09:48:09.903567873 -0400
1797
@@ -328,7 +328,7 @@ static void c_stop(struct seq_file *m, v
1798 1799 1800 1801 1802 1803 1804 1805
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
 	.start =c_start,
 	.next =	c_next,
 	.stop =	c_stop,
1806 1807 1808
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/signal_32.c linux-2.6.30.8/arch/powerpc/kernel/signal_32.c
--- linux-2.6.30.8/arch/powerpc/kernel/signal_32.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/signal_32.c	2009-07-30 09:48:09.903567873 -0400
1809 1810 1811 1812 1813 1814 1815 1816 1817
@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
 	/* Save user registers on the stack */
 	frame = &rt_sf->uc.uc_mcontext;
 	addr = frame;
-	if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
+	if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
 		if (save_user_regs(regs, frame, 0, 1))
 			goto badframe;
 		regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
1818 1819 1820
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/signal_64.c linux-2.6.30.8/arch/powerpc/kernel/signal_64.c
--- linux-2.6.30.8/arch/powerpc/kernel/signal_64.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/signal_64.c	2009-07-30 09:48:09.905069777 -0400
1821 1822 1823 1824 1825 1826 1827 1828 1829
@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
 	current->thread.fpscr.val = 0;
 
 	/* Set up to return from userspace. */
-	if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
+	if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
 		regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
 	} else {
 		err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
1830 1831 1832
diff -urNp linux-2.6.30.8/arch/powerpc/kernel/vdso.c linux-2.6.30.8/arch/powerpc/kernel/vdso.c
--- linux-2.6.30.8/arch/powerpc/kernel/vdso.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kernel/vdso.c	2009-07-30 09:48:09.905069777 -0400
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850
@@ -211,7 +211,7 @@ int arch_setup_additional_pages(struct l
 	vdso_base = VDSO32_MBASE;
 #endif
 
-	current->mm->context.vdso_base = 0;
+	current->mm->context.vdso_base = ~0UL;
 
 	/* vDSO has a problem and was disabled, just don't "enable" it for the
 	 * process
@@ -228,7 +228,7 @@ int arch_setup_additional_pages(struct l
 	 */
 	down_write(&mm->mmap_sem);
 	vdso_base = get_unmapped_area(NULL, vdso_base,
-				      vdso_pages << PAGE_SHIFT, 0, 0);
+				      vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
 	if (IS_ERR_VALUE(vdso_base)) {
 		rc = vdso_base;
 		goto fail_mmapsem;
1851 1852 1853
diff -urNp linux-2.6.30.8/arch/powerpc/kvm/timing.c linux-2.6.30.8/arch/powerpc/kvm/timing.c
--- linux-2.6.30.8/arch/powerpc/kvm/timing.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/kvm/timing.c	2009-07-30 09:48:09.905069777 -0400
1854 1855 1856 1857 1858 1859 1860 1861 1862
@@ -201,7 +201,7 @@ static int kvmppc_exit_timing_open(struc
 	return single_open(file, kvmppc_exit_timing_show, inode->i_private);
 }
 
-static struct file_operations kvmppc_exit_timing_fops = {
+static const struct file_operations kvmppc_exit_timing_fops = {
 	.owner   = THIS_MODULE,
 	.open    = kvmppc_exit_timing_open,
 	.read    = seq_read,
1863 1864 1865
diff -urNp linux-2.6.30.8/arch/powerpc/lib/usercopy_64.c linux-2.6.30.8/arch/powerpc/lib/usercopy_64.c
--- linux-2.6.30.8/arch/powerpc/lib/usercopy_64.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/lib/usercopy_64.c	2009-07-30 11:10:48.798471204 -0400
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
@@ -11,6 +11,9 @@
 
 unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+	if (unlikely(((long)n < 0) || (n > INT_MAX)))
+		return n;
+
 	if (likely(access_ok(VERIFY_READ, from, n)))
 		n = __copy_from_user(to, from, n);
 	else
@@ -20,6 +23,9 @@ unsigned long copy_from_user(void *to, c
 
 unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
 {
+	if (unlikely(((long)n < 0) || (n > INT_MAX)))
+		return n;
+
 	if (likely(access_ok(VERIFY_WRITE, to, n)))
 		n = __copy_to_user(to, from, n);
 	return n;
1886 1887 1888
diff -urNp linux-2.6.30.8/arch/powerpc/mm/fault.c linux-2.6.30.8/arch/powerpc/mm/fault.c
--- linux-2.6.30.8/arch/powerpc/mm/fault.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/mm/fault.c	2009-07-30 09:48:09.905534132 -0400
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
@@ -29,6 +29,10 @@
 #include <linux/module.h>
 #include <linux/kprobes.h>
 #include <linux/kdebug.h>
+#include <linux/slab.h>
+#include <linux/pagemap.h>
+#include <linux/compiler.h>
+#include <linux/unistd.h>
 
 #include <asm/firmware.h>
 #include <asm/page.h>
@@ -63,6 +67,363 @@ static inline int notify_page_fault(stru
 }
 #endif
 
+#ifdef CONFIG_PAX_EMUSIGRT
+void pax_syscall_close(struct vm_area_struct *vma)
+{
+	vma->vm_mm->call_syscall = 0UL;
+}
+
+static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+	unsigned int *kaddr;
+
+	vmf->page = alloc_page(GFP_HIGHUSER);
+	if (!vmf->page)
+		return VM_FAULT_OOM;
+
+	kaddr = kmap(vmf->page);
+	memset(kaddr, 0, PAGE_SIZE);
+	kaddr[0] = 0x44000002U; /* sc */
+	__flush_dcache_icache(kaddr);
+	kunmap(vmf->page);
+	return VM_FAULT_MAJOR;
+}
+
1926
+static const struct vm_operations_struct pax_vm_ops = {
1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272
+	.close = pax_syscall_close,
+	.fault = pax_syscall_fault
+};
+
+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
+{
+	int ret;
+
+	vma->vm_mm = current->mm;
+	vma->vm_start = addr;
+	vma->vm_end = addr + PAGE_SIZE;
+	vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
+	vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
+	vma->vm_ops = &pax_vm_ops;
+
+	ret = insert_vm_struct(current->mm, vma);
+	if (ret)
+		return ret;
+
+	++current->mm->total_vm;
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_PAX_PAGEEXEC
+/*
+ * PaX: decide what to do with offenders (regs->nip = fault address)
+ *
+ * returns 1 when task should be killed
+ *         2 when patched GOT trampoline was detected
+ *         3 when patched PLT trampoline was detected
+ *         4 when unpatched PLT trampoline was detected
+ *         5 when sigreturn trampoline was detected
+ *         6 when rt_sigreturn trampoline was detected
+ */
+static int pax_handle_fetch_fault(struct pt_regs *regs)
+{
+
+#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
+	int err;
+#endif
+
+#ifdef CONFIG_PAX_EMUPLT
+	do { /* PaX: patched GOT emulation */
+		unsigned int blrl;
+
+		err = get_user(blrl, (unsigned int *)regs->nip);
+
+		if (!err && blrl == 0x4E800021U) {
+			unsigned long temp = regs->nip;
+
+			regs->nip = regs->link & 0xFFFFFFFCUL;
+			regs->link = temp + 4UL;
+			return 2;
+		}
+	} while (0);
+
+	do { /* PaX: patched PLT emulation #1 */
+		unsigned int b;
+
+		err = get_user(b, (unsigned int *)regs->nip);
+
+		if (!err && (b & 0xFC000003U) == 0x48000000U) {
+			regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
+			return 3;
+		}
+	} while (0);
+
+	do { /* PaX: unpatched PLT emulation #1 */
+		unsigned int li, b;
+
+		err = get_user(li, (unsigned int *)regs->nip);
+		err |= get_user(b, (unsigned int *)(regs->nip+4));
+
+		if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
+			unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
+			unsigned long addr = b | 0xFC000000UL;
+
+			addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
+			err = get_user(rlwinm, (unsigned int *)addr);
+			err |= get_user(add, (unsigned int *)(addr+4));
+			err |= get_user(li2, (unsigned int *)(addr+8));
+			err |= get_user(addis2, (unsigned int *)(addr+12));
+			err |= get_user(mtctr, (unsigned int *)(addr+16));
+			err |= get_user(li3, (unsigned int *)(addr+20));
+			err |= get_user(addis3, (unsigned int *)(addr+24));
+			err |= get_user(bctr, (unsigned int *)(addr+28));
+
+			if (err)
+				break;
+
+			if (rlwinm == 0x556C083CU &&
+			    add == 0x7D6C5A14U &&
+			    (li2 & 0xFFFF0000U) == 0x39800000U &&
+			    (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
+			    mtctr == 0x7D8903A6U &&
+			    (li3 & 0xFFFF0000U) == 0x39800000U &&
+			    (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
+			    bctr == 0x4E800420U)
+			{
+				regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
+				regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->ctr += (addis2 & 0xFFFFU) << 16;
+				regs->nip = regs->ctr;
+				return 4;
+			}
+		}
+	} while (0);
+
+#if 0
+	do { /* PaX: unpatched PLT emulation #2 */
+		unsigned int lis, lwzu, b, bctr;
+
+		err = get_user(lis, (unsigned int *)regs->nip);
+		err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
+		err |= get_user(b, (unsigned int *)(regs->nip+8));
+		err |= get_user(bctr, (unsigned int *)(regs->nip+12));
+
+		if (err)
+			break;
+
+		if ((lis & 0xFFFF0000U) == 0x39600000U &&
+		    (lwzu & 0xU) == 0xU &&
+		    (b & 0xFC000003U) == 0x48000000U &&
+		    bctr == 0x4E800420U)
+		{
+			unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
+			unsigned long addr = b | 0xFC000000UL;
+
+			addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
+			err = get_user(addis, (unsigned int *)addr);
+			err |= get_user(addi, (unsigned int *)(addr+4));
+			err |= get_user(rlwinm, (unsigned int *)(addr+8));
+			err |= get_user(add, (unsigned int *)(addr+12));
+			err |= get_user(li2, (unsigned int *)(addr+16));
+			err |= get_user(addis2, (unsigned int *)(addr+20));
+			err |= get_user(mtctr, (unsigned int *)(addr+24));
+			err |= get_user(li3, (unsigned int *)(addr+28));
+			err |= get_user(addis3, (unsigned int *)(addr+32));
+			err |= get_user(bctr, (unsigned int *)(addr+36));
+
+			if (err)
+				break;
+
+			if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
+			    (addi & 0xFFFF0000U) == 0x396B0000U &&
+			    rlwinm == 0x556C083CU &&
+			    add == 0x7D6C5A14U &&
+			    (li2 & 0xFFFF0000U) == 0x39800000U &&
+			    (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
+			    mtctr == 0x7D8903A6U &&
+			    (li3 & 0xFFFF0000U) == 0x39800000U &&
+			    (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
+			    bctr == 0x4E800420U)
+			{
+				regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
+				regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				regs->ctr += (addis2 & 0xFFFFU) << 16;
+				regs->nip = regs->ctr;
+				return 4;
+			}
+		}
+	} while (0);
+#endif
+
+	do { /* PaX: unpatched PLT emulation #3 */
+		unsigned int li, b;
+
+		err = get_user(li, (unsigned int *)regs->nip);
+		err |= get_user(b, (unsigned int *)(regs->nip+4));
+
+		if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
+			unsigned int addis, lwz, mtctr, bctr;
+			unsigned long addr = b | 0xFC000000UL;
+
+			addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
+			err = get_user(addis, (unsigned int *)addr);
+			err |= get_user(lwz, (unsigned int *)(addr+4));
+			err |= get_user(mtctr, (unsigned int *)(addr+8));
+			err |= get_user(bctr, (unsigned int *)(addr+12));
+
+			if (err)
+				break;
+
+			if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
+			    (lwz & 0xFFFF0000U) == 0x816B0000U &&
+			    mtctr == 0x7D6903A6U &&
+			    bctr == 0x4E800420U)
+			{
+				unsigned int r11;
+
+				addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+				addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
+
+				err = get_user(r11, (unsigned int *)addr);
+				if (err)
+					break;
+
+				regs->gpr[PT_R11] = r11;
+				regs->ctr = r11;
+				regs->nip = r11;
+				return 4;
+			}
+		}
+	} while (0);
+#endif
+
+#ifdef CONFIG_PAX_EMUSIGRT
+	do { /* PaX: sigreturn emulation */
+		unsigned int li, sc;
+
+		err = get_user(li, (unsigned int *)regs->nip);
+		err |= get_user(sc, (unsigned int *)(regs->nip+4));
+
+		if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
+			struct vm_area_struct *vma;
+			unsigned long call_syscall;
+
+			down_read(&current->mm->mmap_sem);
+			call_syscall = current->mm->call_syscall;
+			up_read(&current->mm->mmap_sem);
+			if (likely(call_syscall))
+				goto emulate;
+
+			vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
+
+			down_write(&current->mm->mmap_sem);
+			if (current->mm->call_syscall) {
+				call_syscall = current->mm->call_syscall;
+				up_write(&current->mm->mmap_sem);
+				if (vma)
+					kmem_cache_free(vm_area_cachep, vma);
+				goto emulate;
+			}
+
+			call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
+			if (!vma || (call_syscall & ~PAGE_MASK)) {
+				up_write(&current->mm->mmap_sem);
+				if (vma)
+					kmem_cache_free(vm_area_cachep, vma);
+				return 1;
+			}
+
+			if (pax_insert_vma(vma, call_syscall)) {
+				up_write(&current->mm->mmap_sem);
+				kmem_cache_free(vm_area_cachep, vma);
+				return 1;
+			}
+
+			current->mm->call_syscall = call_syscall;
+			up_write(&current->mm->mmap_sem);
+
+emulate:
+			regs->gpr[PT_R0] = __NR_sigreturn;
+			regs->nip = call_syscall;
+			return 5;
+		}
+	} while (0);
+
+	do { /* PaX: rt_sigreturn emulation */
+		unsigned int li, sc;
+
+		err = get_user(li, (unsigned int *)regs->nip);
+		err |= get_user(sc, (unsigned int *)(regs->nip+4));
+
+		if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
+			struct vm_area_struct *vma;
+			unsigned int call_syscall;
+
+			down_read(&current->mm->mmap_sem);
+			call_syscall = current->mm->call_syscall;
+			up_read(&current->mm->mmap_sem);
+			if (likely(call_syscall))
+				goto rt_emulate;
+
+			vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
+
+			down_write(&current->mm->mmap_sem);
+			if (current->mm->call_syscall) {
+				call_syscall = current->mm->call_syscall;
+				up_write(&current->mm->mmap_sem);
+				if (vma)
+					kmem_cache_free(vm_area_cachep, vma);
+				goto rt_emulate;
+			}
+
+			call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
+			if (!vma || (call_syscall & ~PAGE_MASK)) {
+				up_write(&current->mm->mmap_sem);
+				if (vma)
+					kmem_cache_free(vm_area_cachep, vma);
+				return 1;
+			}
+
+			if (pax_insert_vma(vma, call_syscall)) {
+				up_write(&current->mm->mmap_sem);
+				kmem_cache_free(vm_area_cachep, vma);
+				return 1;
+			}
+
+			current->mm->call_syscall = call_syscall;
+			up_write(&current->mm->mmap_sem);
+
+rt_emulate:
+			regs->gpr[PT_R0] = __NR_rt_sigreturn;
+			regs->nip = call_syscall;
+			return 6;
+		}
+	} while (0);
+#endif
+
+	return 1;
+}
+
+void pax_report_insns(void *pc, void *sp)
+{
+	unsigned long i;
+
+	printk(KERN_ERR "PAX: bytes at PC: ");
+	for (i = 0; i < 5; i++) {
+		unsigned int c;
+		if (get_user(c, (unsigned int *)pc+i))
+			printk(KERN_CONT "???????? ");
+		else
+			printk(KERN_CONT "%08x ", c);
+	}
+	printk("\n");
+}
+#endif
+
 /*
  * Check whether the instruction at regs->nip is a store using
  * an update addressing form which will update r1.
@@ -133,7 +494,7 @@ int __kprobes do_page_fault(struct pt_re
 	 * indicate errors in DSISR but can validly be set in SRR1.
 	 */
 	if (trap == 0x400)
-		error_code &= 0x48200000;
+		error_code &= 0x58200000;
 	else
 		is_write = error_code & DSISR_ISSTORE;
 #else
2273
@@ -327,6 +688,37 @@ bad_area:
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
 bad_area_nosemaphore:
 	/* User mode accesses cause a SIGSEGV */
 	if (user_mode(regs)) {
+
+#ifdef CONFIG_PAX_PAGEEXEC
+		if (mm->pax_flags & MF_PAX_PAGEEXEC) {
+#ifdef CONFIG_PPC64
+			if (is_exec && (error_code & DSISR_PROTFAULT)) {
+#else
+			if (is_exec && regs->nip == address) {
+#endif
+				switch (pax_handle_fetch_fault(regs)) {
+
+#ifdef CONFIG_PAX_EMUPLT
+				case 2:
+				case 3:
+				case 4:
+					return 0;
+#endif
+
+#ifdef CONFIG_PAX_EMUSIGRT
+				case 5:
+				case 6:
+					return 0;
+#endif
+
+				}
+
+				pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
+				do_group_exit(SIGKILL);
+			}
+		}
+#endif
+
 		_exception(SIGSEGV, regs, code, address);
 		return 0;
 	}
2311 2312 2313
diff -urNp linux-2.6.30.8/arch/powerpc/mm/mmap_64.c linux-2.6.30.8/arch/powerpc/mm/mmap_64.c
--- linux-2.6.30.8/arch/powerpc/mm/mmap_64.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/mm/mmap_64.c	2009-07-30 09:48:09.905534132 -0400
2314
@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
 	 */
 	if (mmap_is_legacy()) {
 		mm->mmap_base = TASK_UNMAPPED_BASE;
+
+#ifdef CONFIG_PAX_RANDMMAP
+		if (mm->pax_flags & MF_PAX_RANDMMAP)
+			mm->mmap_base += mm->delta_mmap;
+#endif
+
 		mm->get_unmapped_area = arch_get_unmapped_area;
 		mm->unmap_area = arch_unmap_area;
 	} else {
 		mm->mmap_base = mmap_base();
+
+#ifdef CONFIG_PAX_RANDMMAP
+		if (mm->pax_flags & MF_PAX_RANDMMAP)
+			mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
+#endif
+
 		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
 		mm->unmap_area = arch_unmap_area_topdown;
 	}
2337 2338 2339
diff -urNp linux-2.6.30.8/arch/powerpc/platforms/cell/spufs/file.c linux-2.6.30.8/arch/powerpc/platforms/cell/spufs/file.c
--- linux-2.6.30.8/arch/powerpc/platforms/cell/spufs/file.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/platforms/cell/spufs/file.c	2009-07-30 09:48:09.906622773 -0400
2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366
@@ -147,7 +147,7 @@ static int __fops ## _open(struct inode 
 	__simple_attr_check_format(__fmt, 0ull);			\
 	return spufs_attr_open(inode, file, __get, __set, __fmt);	\
 }									\
-static struct file_operations __fops = {				\
+static const struct file_operations __fops = {				\
 	.owner	 = THIS_MODULE,						\
 	.open	 = __fops ## _open,					\
 	.release = spufs_attr_release,					\
@@ -309,7 +309,7 @@ static int spufs_mem_mmap_access(struct 
 	return len;
 }
 
-static struct vm_operations_struct spufs_mem_mmap_vmops = {
+static const struct vm_operations_struct spufs_mem_mmap_vmops = {
 	.fault = spufs_mem_mmap_fault,
 	.access = spufs_mem_mmap_access,
 };
@@ -436,7 +436,7 @@ static int spufs_cntl_mmap_fault(struct 
 	return spufs_ps_fault(vma, vmf, 0x4000, SPUFS_CNTL_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_cntl_mmap_vmops = {
+static const struct vm_operations_struct spufs_cntl_mmap_vmops = {
 	.fault = spufs_cntl_mmap_fault,
 };
 
2367
@@ -1143,7 +1143,7 @@ spufs_signal1_mmap_fault(struct vm_area_
2368 2369 2370 2371 2372 2373 2374 2375
 #endif
 }
 
-static struct vm_operations_struct spufs_signal1_mmap_vmops = {
+static const struct vm_operations_struct spufs_signal1_mmap_vmops = {
 	.fault = spufs_signal1_mmap_fault,
 };
 
2376
@@ -1279,7 +1279,7 @@ spufs_signal2_mmap_fault(struct vm_area_
2377 2378 2379 2380 2381 2382 2383 2384
 #endif
 }
 
-static struct vm_operations_struct spufs_signal2_mmap_vmops = {
+static const struct vm_operations_struct spufs_signal2_mmap_vmops = {
 	.fault = spufs_signal2_mmap_fault,
 };
 
2385
@@ -1397,7 +1397,7 @@ spufs_mss_mmap_fault(struct vm_area_stru
2386 2387 2388 2389 2390 2391 2392 2393
 	return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_mss_mmap_vmops = {
+static const struct vm_operations_struct spufs_mss_mmap_vmops = {
 	.fault = spufs_mss_mmap_fault,
 };
 
2394
@@ -1458,7 +1458,7 @@ spufs_psmap_mmap_fault(struct vm_area_st
2395 2396 2397 2398 2399 2400 2401 2402
 	return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_psmap_mmap_vmops = {
+static const struct vm_operations_struct spufs_psmap_mmap_vmops = {
 	.fault = spufs_psmap_mmap_fault,
 };
 
2403
@@ -1517,7 +1517,7 @@ spufs_mfc_mmap_fault(struct vm_area_stru
2404 2405 2406 2407 2408 2409 2410 2411
 	return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_mfc_mmap_vmops = {
+static const struct vm_operations_struct spufs_mfc_mmap_vmops = {
 	.fault = spufs_mfc_mmap_fault,
 };
 
2412 2413 2414
diff -urNp linux-2.6.30.8/arch/powerpc/platforms/pseries/dtl.c linux-2.6.30.8/arch/powerpc/platforms/pseries/dtl.c
--- linux-2.6.30.8/arch/powerpc/platforms/pseries/dtl.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/platforms/pseries/dtl.c	2009-07-30 12:06:52.084821916 -0400
2415 2416 2417 2418 2419 2420 2421 2422 2423
@@ -209,7 +209,7 @@ static ssize_t dtl_file_read(struct file
 	return n_read * sizeof(struct dtl_entry);
 }
 
-static struct file_operations dtl_fops = {
+static const struct file_operations dtl_fops = {
 	.open		= dtl_file_open,
 	.release	= dtl_file_release,
 	.read		= dtl_file_read,
2424 2425 2426
diff -urNp linux-2.6.30.8/arch/powerpc/platforms/pseries/hvCall_inst.c linux-2.6.30.8/arch/powerpc/platforms/pseries/hvCall_inst.c
--- linux-2.6.30.8/arch/powerpc/platforms/pseries/hvCall_inst.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/powerpc/platforms/pseries/hvCall_inst.c	2009-07-30 09:48:09.906622773 -0400
2427 2428 2429 2430 2431 2432 2433 2434 2435
@@ -71,7 +71,7 @@ static int hc_show(struct seq_file *m, v
 	return 0;
 }
 
-static struct seq_operations hcall_inst_seq_ops = {
+static const struct seq_operations hcall_inst_seq_ops = {
         .start = hc_start,
         .next  = hc_next,
         .stop  = hc_stop,
2436 2437 2438
diff -urNp linux-2.6.30.8/arch/s390/hypfs/inode.c linux-2.6.30.8/arch/s390/hypfs/inode.c
--- linux-2.6.30.8/arch/s390/hypfs/inode.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/s390/hypfs/inode.c	2009-07-30 09:48:09.907613298 -0400
2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456
@@ -41,7 +41,7 @@ struct hypfs_sb_info {
 
 static const struct file_operations hypfs_file_ops;
 static struct file_system_type hypfs_type;
-static struct super_operations hypfs_s_ops;
+static const struct super_operations hypfs_s_ops;
 
 /* start of list of all dentries, which have to be deleted on update */
 static struct dentry *hypfs_last_dentry;
@@ -476,7 +476,7 @@ static struct file_system_type hypfs_typ
 	.kill_sb	= hypfs_kill_super
 };
 
-static struct super_operations hypfs_s_ops = {
+static const struct super_operations hypfs_s_ops = {
 	.statfs		= simple_statfs,
 	.drop_inode	= hypfs_drop_inode,
 	.show_options	= hypfs_show_options,
2457 2458 2459
diff -urNp linux-2.6.30.8/arch/s390/include/asm/atomic.h linux-2.6.30.8/arch/s390/include/asm/atomic.h
--- linux-2.6.30.8/arch/s390/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/s390/include/asm/atomic.h	2009-07-30 09:48:09.908552392 -0400
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
@@ -82,8 +82,10 @@ static __inline__ int atomic_add_return(
 	return __CS_LOOP(v, i, "ar");
 }
 #define atomic_add(_i, _v)		atomic_add_return(_i, _v)
+#define atomic_add_unchecked(_i, _v)	atomic_add((_i), (_v))
 #define atomic_add_negative(_i, _v)	(atomic_add_return(_i, _v) < 0)
 #define atomic_inc(_v)			atomic_add_return(1, _v)
+#define atomic_inc_unchecked(_v)	atomic_inc(_v)
 #define atomic_inc_return(_v)		atomic_add_return(1, _v)
 #define atomic_inc_and_test(_v)		(atomic_add_return(1, _v) == 0)
 
@@ -92,6 +94,7 @@ static __inline__ int atomic_sub_return(
 	return __CS_LOOP(v, i, "sr");
 }
 #define atomic_sub(_i, _v)		atomic_sub_return(_i, _v)
+#define atomic_sub_unchecked(_i, _v)	atomic_sub((_i), (_v))
 #define atomic_sub_and_test(_i, _v)	(atomic_sub_return(_i, _v) == 0)
 #define atomic_dec(_v)			atomic_sub_return(1, _v)
 #define atomic_dec_return(_v)		atomic_sub_return(1, _v)
2479 2480 2481
diff -urNp linux-2.6.30.8/arch/s390/include/asm/kmap_types.h linux-2.6.30.8/arch/s390/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/s390/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/s390/include/asm/kmap_types.h	2009-07-30 09:48:09.908552392 -0400
2482 2483 2484 2485 2486 2487 2488 2489
@@ -16,6 +16,7 @@ enum km_type {
 	KM_IRQ1,
 	KM_SOFTIRQ0,
 	KM_SOFTIRQ1,	
+	KM_CLEARPAGE,
 	KM_TYPE_NR
 };
 
2490 2491 2492
diff -urNp linux-2.6.30.8/arch/s390/include/asm/uaccess.h linux-2.6.30.8/arch/s390/include/asm/uaccess.h
--- linux-2.6.30.8/arch/s390/include/asm/uaccess.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/s390/include/asm/uaccess.h	2009-07-30 09:48:09.908552392 -0400
2493 2494 2495
@@ -232,6 +232,10 @@ static inline unsigned long __must_check
 copy_to_user(void __user *to, const void *from, unsigned long n)
 {
2496
 	might_sleep();
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
+
+	if ((long)n < 0)
+		return n;
+
 	if (access_ok(VERIFY_WRITE, to, n))
 		n = __copy_to_user(to, from, n);
 	return n;
@@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void
 static inline unsigned long __must_check
 __copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+	if ((long)n < 0)
+		return n;
+
 	if (__builtin_constant_p(n) && (n <= 256))
 		return uaccess.copy_from_user_small(n, from, to);
 	else
@@ -283,6 +290,10 @@ static inline unsigned long __must_check
 copy_from_user(void *to, const void __user *from, unsigned long n)
 {
 	might_sleep();
+
+	if ((long)n < 0)
+		return n;
+
2522 2523
 	if (access_ok(VERIFY_READ, from, n))
 		n = __copy_from_user(to, from, n);
2524
 	else
2525 2526 2527
diff -urNp linux-2.6.30.8/arch/s390/kernel/module.c linux-2.6.30.8/arch/s390/kernel/module.c
--- linux-2.6.30.8/arch/s390/kernel/module.c	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/s390/kernel/module.c	2009-07-30 09:48:09.908552392 -0400
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571
@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
 
 	/* Increase core size by size of got & plt and set start
 	   offsets for got and plt. */
-	me->core_size = ALIGN(me->core_size, 4);
-	me->arch.got_offset = me->core_size;
-	me->core_size += me->arch.got_size;
-	me->arch.plt_offset = me->core_size;
-	me->core_size += me->arch.plt_size;
+	me->core_size_rw = ALIGN(me->core_size_rw, 4);
+	me->arch.got_offset = me->core_size_rw;
+	me->core_size_rw += me->arch.got_size;
+	me->arch.plt_offset = me->core_size_rx;
+	me->core_size_rx += me->arch.plt_size;
 	return 0;
 }
 
@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
 		if (info->got_initialized == 0) {
 			Elf_Addr *gotent;
 
-			gotent = me->module_core + me->arch.got_offset +
+			gotent = me->module_core_rw + me->arch.got_offset +
 				info->got_offset;
 			*gotent = val;
 			info->got_initialized = 1;
@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
 		else if (r_type == R_390_GOTENT ||
 			 r_type == R_390_GOTPLTENT)
 			*(unsigned int *) loc =
-				(val + (Elf_Addr) me->module_core - loc) >> 1;
+				(val + (Elf_Addr) me->module_core_rw - loc) >> 1;
 		else if (r_type == R_390_GOT64 ||
 			 r_type == R_390_GOTPLT64)
 			*(unsigned long *) loc = val;
@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
 	case R_390_PLTOFF64:	/* 16 bit offset from GOT to PLT. */
 		if (info->plt_initialized == 0) {
 			unsigned int *ip;
-			ip = me->module_core + me->arch.plt_offset +
+			ip = me->module_core_rx + me->arch.plt_offset +
 				info->plt_offset;
 #ifndef CONFIG_64BIT
 			ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
2572 2573 2574 2575 2576 2577 2578 2579 2580 2581
@@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
 			       val - loc + 0xffffUL < 0x1ffffeUL) ||
 			      (r_type == R_390_PLT32DBL &&
 			       val - loc + 0xffffffffULL < 0x1fffffffeULL)))
-				val = (Elf_Addr) me->module_core +
+				val = (Elf_Addr) me->module_core_rx +
 					me->arch.plt_offset +
 					info->plt_offset;
 			val += rela->r_addend - loc;
@@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2582 2583 2584 2585 2586 2587 2588 2589
 	case R_390_GOTOFF32:	/* 32 bit offset to GOT.  */
 	case R_390_GOTOFF64:	/* 64 bit offset to GOT. */
 		val = val + rela->r_addend -
-			((Elf_Addr) me->module_core + me->arch.got_offset);
+			((Elf_Addr) me->module_core_rw + me->arch.got_offset);
 		if (r_type == R_390_GOTOFF16)
 			*(unsigned short *) loc = val;
 		else if (r_type == R_390_GOTOFF32)
2590
@@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2591 2592 2593 2594 2595 2596 2597 2598
 		break;
 	case R_390_GOTPC:	/* 32 bit PC relative offset to GOT. */
 	case R_390_GOTPCDBL:	/* 32 bit PC rel. off. to GOT shifted by 1. */
-		val = (Elf_Addr) me->module_core + me->arch.got_offset +
+		val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
 			rela->r_addend - loc;
 		if (r_type == R_390_GOTPC)
 			*(unsigned int *) loc = val;
2599 2600 2601
diff -urNp linux-2.6.30.8/arch/sh/include/asm/atomic.h linux-2.6.30.8/arch/sh/include/asm/atomic.h
--- linux-2.6.30.8/arch/sh/include/asm/atomic.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/sh/include/asm/atomic.h	2009-07-30 09:48:09.909647067 -0400
2602 2603 2604 2605 2606 2607 2608 2609 2610 2611
@@ -43,6 +43,9 @@
 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
 
 #define atomic_inc(v) atomic_add(1,(v))
+#define atomic_inc_unchecked(v) atomic_inc(v)
+#define atomic_add_unchecked(i,v) atomic_add((i),(v))
+#define atomic_sub_unchecked(i,v) atomic_sub((i),(v))
 #define atomic_dec(v) atomic_sub(1,(v))
 
 #ifndef CONFIG_GUSA_RB
2612 2613 2614
diff -urNp linux-2.6.30.8/arch/sh/include/asm/kmap_types.h linux-2.6.30.8/arch/sh/include/asm/kmap_types.h
--- linux-2.6.30.8/arch/sh/include/asm/kmap_types.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/sh/include/asm/kmap_types.h	2009-07-30 09:48:09.909647067 -0400
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624
@@ -24,7 +24,8 @@ D(9)	KM_IRQ0,
 D(10)	KM_IRQ1,
 D(11)	KM_SOFTIRQ0,
 D(12)	KM_SOFTIRQ1,
-D(13)	KM_TYPE_NR
+D(13)	KM_CLEARPAGE,
+D(14)	KM_TYPE_NR
 };
 
 #undef D
2625 2626 2627
diff -urNp linux-2.6.30.8/arch/sparc/include/asm/atomic_32.h linux-2.6.30.8/arch/sparc/include/asm/atomic_32.h
--- linux-2.6.30.8/arch/sparc/include/asm/atomic_32.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/sparc/include/asm/atomic_32.h	2009-07-30 09:48:09.910522181 -0400
2628
@@ -28,8 +28,11 @@ extern void atomic_set(atomic_t *, int);
2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639
 #define atomic_read(v)          ((v)->counter)
 
 #define atomic_add(i, v)	((void)__atomic_add_return( (int)(i), (v)))
+#define atomic_add_unchecked(i, v)	atomic_add((i), (v))
 #define atomic_sub(i, v)	((void)__atomic_add_return(-(int)(i), (v)))
+#define atomic_sub_unchecked(i, v)	atomic_sub((i), (v))
 #define atomic_inc(v)		((void)__atomic_add_return(        1, (v)))
+#define atomic_inc_unchecked(v)	atomic_inc(v)
 #define atomic_dec(v)		((void)__atomic_add_return(       -1, (v)))
 
 #define atomic_add_return(i, v)	(__atomic_add_return( (int)(i), (v)))
2640 2641 2642
diff -urNp linux-2.6.30.8/arch/sparc/include/asm/atomic_64.h linux-2.6.30.8/arch/sparc/include/asm/atomic_64.h
--- linux-2.6.30.8/arch/sparc/include/asm/atomic_64.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/sparc/include/asm/atomic_64.h	2009-07-30 09:48:09.910522181 -0400
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
@@ -20,8 +20,10 @@
 #define atomic64_set(v, i)	(((v)->counter) = i)
 
 extern void atomic_add(int, atomic_t *);
+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
 extern void atomic64_add(int, atomic64_t *);
 extern void atomic_sub(int, atomic_t *);
+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
 extern void atomic64_sub(int, atomic64_t *);
 
 extern int atomic_add_ret(int, atomic_t *);
@@ -59,6 +61,7 @@ extern int atomic64_sub_ret(int, atomic6
 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
 
 #define atomic_inc(v) atomic_add(1, v)
+#define atomic_inc_unchecked(v) atomic_inc(v)
 #define atomic64_inc(v) atomic64_add(1, v)
 
 #define atomic_dec(v) atomic_sub(1, v)
2662 2663 2664
diff -urNp linux-2.6.30.8/arch/sparc/include/asm/elf_32.h linux-2.6.30.8/arch/sparc/include/asm/elf_32.h
--- linux-2.6.30.8/arch/sparc/include/asm/elf_32.h	2009-07-24 17:47:51.000000000 -0400
+++ linux-2.6.30.8/arch/sparc/include/asm/elf_32.h	2009-07-30 09:48:09.910522181 -0400
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678
@@ -116,6 +116,13 @@ ty