-
Notifications
You must be signed in to change notification settings - Fork 14
/
pax-linux-2.6.25.17-test30.patch
22487 lines (21009 loc) · 737 KB
/
pax-linux-2.6.25.17-test30.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
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
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
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
875
876
877
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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/Documentation/dontdiff linux-2.6.25.17-pax/Documentation/dontdiff
--- linux-2.6.25.17/Documentation/dontdiff 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/Documentation/dontdiff 2008-07-01 23:11:48.000000000 +0200
@@ -3,6 +3,7 @@
*.bin
*.cpio
*.css
+*.dbg
*.dvi
*.eps
*.gif
@@ -52,9 +53,14 @@ COPYING
CREDITS
CVS
ChangeSet
+GPATH
+GRTAGS
+GSYMS
+GTAGS
Image
Kerntypes
MODS.txt
+Module.markers
Module.symvers
PENDING
SCCS
@@ -89,6 +95,7 @@ config_data.gz*
conmakehash
consolemap_deftbl.c*
crc32table.h*
+cpustr.h
cscope.*
defkeymap.c*
devlist.h*
@@ -137,11 +144,13 @@ miboot*
mk_elfconfig
mkboot
mkbugboot
+mkcpustr
mkdep
mkprep
mktables
mktree
modpost
+modules.order
modversions.h*
offset.h
offsets.h
@@ -172,20 +181,24 @@ sm_tbl*
split-include
tags
tftpboot.img
+timeconst.h
times.h*
tkparse
trix_boot.h
utsrelease.h*
-vdso.lds
+vdso*.lds
version.h*
vmlinux
vmlinux-*
vmlinux.aout
-vmlinux*.lds*
+vmlinux.bin.all
+vmlinux*.lds
+vmlinux.relocs
vmlinux*.scr
-vsyscall.lds
+vsyscall*.lds
wanxlfw.inc
uImage
unifdef
+utsrelease.h
zImage*
zconf.hash.c
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/Makefile linux-2.6.25.17-pax/Makefile
--- linux-2.6.25.17/Makefile 2008-09-08 14:04:55.000000000 +0200
+++ linux-2.6.25.17-pax/Makefile 2008-09-08 14:07:05.000000000 +0200
@@ -214,7 +214,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
HOSTCC = gcc
HOSTCXX = g++
-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
+HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
# Decide whether to build built-in, modular, or both.
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/alpha/kernel/module.c linux-2.6.25.17-pax/arch/alpha/kernel/module.c
--- linux-2.6.25.17/arch/alpha/kernel/module.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/alpha/kernel/module.c 2008-06-22 15:46:49.000000000 +0200
@@ -176,7 +176,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++) {
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/alpha/kernel/osf_sys.c linux-2.6.25.17-pax/arch/alpha/kernel/osf_sys.c
--- linux-2.6.25.17/arch/alpha/kernel/osf_sys.c 2008-06-22 15:44:41.000000000 +0200
+++ linux-2.6.25.17-pax/arch/alpha/kernel/osf_sys.c 2008-06-22 15:46:49.000000000 +0200
@@ -1288,6 +1288,10 @@ arch_get_unmapped_area(struct file *filp
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) || !filp)
+#endif
+
if (addr) {
addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
if (addr != (unsigned long) -ENOMEM)
@@ -1295,8 +1299,8 @@ arch_get_unmapped_area(struct file *filp
}
/* 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;
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/alpha/mm/fault.c linux-2.6.25.17-pax/arch/alpha/mm/fault.c
--- linux-2.6.25.17/arch/alpha/mm/fault.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/alpha/mm/fault.c 2008-06-22 15:46:49.000000000 +0200
@@ -23,6 +23,7 @@
#include <linux/smp.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/binfmts.h>
#include <asm/system.h>
#include <asm/uaccess.h>
@@ -54,6 +55,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 +250,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)))
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/arm/mm/mmap.c linux-2.6.25.17-pax/arch/arm/mm/mmap.c
--- linux-2.6.25.17/arch/arm/mm/mmap.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/arm/mm/mmap.c 2008-06-22 15:46:49.000000000 +0200
@@ -60,6 +60,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) || !filp)
+#endif
+
if (addr) {
if (do_align)
addr = COLOUR_ALIGN(addr, pgoff);
@@ -72,10 +76,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:
@@ -91,8 +95,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;
}
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/avr32/mm/fault.c linux-2.6.25.17-pax/arch/avr32/mm/fault.c
--- linux-2.6.25.17/arch/avr32/mm/fault.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/avr32/mm/fault.c 2008-06-22 15:46:49.000000000 +0200
@@ -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",
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/ia32/binfmt_elf32.c linux-2.6.25.17-pax/arch/ia64/ia32/binfmt_elf32.c
--- linux-2.6.25.17/arch/ia64/ia32/binfmt_elf32.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/ia32/binfmt_elf32.c 2008-06-22 15:46:49.000000000 +0200
@@ -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"
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/ia32/ia32priv.h linux-2.6.25.17-pax/arch/ia64/ia32/ia32priv.h
--- linux-2.6.25.17/arch/ia64/ia32/ia32priv.h 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/ia32/ia32priv.h 2008-06-22 15:46:49.000000000 +0200
@@ -303,7 +303,14 @@ struct old_linux32_dirent {
#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
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/kernel/module.c linux-2.6.25.17-pax/arch/ia64/kernel/module.c
--- linux-2.6.25.17/arch/ia64/kernel/module.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/kernel/module.c 2008-06-22 15:46:49.000000000 +0200
@@ -321,7 +321,7 @@ module_alloc (unsigned long size)
void
module_free (struct module *mod, void *module_region)
{
- if (mod->arch.init_unw_table && module_region == mod->module_init) {
+ if (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;
}
@@ -499,15 +499,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
}
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
@@ -691,7 +715,14 @@ do_reloc (struct module *mod, uint8_t r_
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:
@@ -825,15 +856,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
* 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);
}
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/kernel/sys_ia64.c linux-2.6.25.17-pax/arch/ia64/kernel/sys_ia64.c
--- linux-2.6.25.17/arch/ia64/kernel/sys_ia64.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/kernel/sys_ia64.c 2008-06-22 15:46:49.000000000 +0200
@@ -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 && filp)
+ 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;
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/mm/fault.c linux-2.6.25.17-pax/arch/ia64/mm/fault.c
--- linux-2.6.25.17/arch/ia64/mm/fault.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/mm/fault.c 2008-06-22 15:46:49.000000000 +0200
@@ -10,6 +10,7 @@
#include <linux/interrupt.h>
#include <linux/kprobes.h>
#include <linux/kdebug.h>
+#include <linux/binfmts.h>
#include <asm/pgtable.h>
#include <asm/processor.h>
@@ -72,6 +73,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 +163,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
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/ia64/mm/init.c linux-2.6.25.17-pax/arch/ia64/mm/init.c
--- linux-2.6.25.17/arch/ia64/mm/init.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/ia64/mm/init.c 2008-06-22 15:46:49.000000000 +0200
@@ -128,6 +128,19 @@ ia64_init_addr_space (void)
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(¤t->mm->mmap_sem);
if (insert_vm_struct(current->mm, vma)) {
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/mips/kernel/binfmt_elfn32.c linux-2.6.25.17-pax/arch/mips/kernel/binfmt_elfn32.c
--- linux-2.6.25.17/arch/mips/kernel/binfmt_elfn32.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/mips/kernel/binfmt_elfn32.c 2008-06-22 15:46:49.000000000 +0200
@@ -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 ((current->thread.mflags & MF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
+
+#define PAX_DELTA_MMAP_LEN ((current->thread.mflags & MF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#define PAX_DELTA_STACK_LEN ((current->thread.mflags & MF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#endif
+
#include <asm/processor.h>
#include <linux/module.h>
#include <linux/elfcore.h>
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/mips/kernel/binfmt_elfo32.c linux-2.6.25.17-pax/arch/mips/kernel/binfmt_elfo32.c
--- linux-2.6.25.17/arch/mips/kernel/binfmt_elfo32.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/mips/kernel/binfmt_elfo32.c 2008-06-22 15:46:49.000000000 +0200
@@ -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 ((current->thread.mflags & MF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
+
+#define PAX_DELTA_MMAP_LEN ((current->thread.mflags & MF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#define PAX_DELTA_STACK_LEN ((current->thread.mflags & MF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
+#endif
+
#include <asm/processor.h>
#include <linux/module.h>
#include <linux/elfcore.h>
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/mips/kernel/syscall.c linux-2.6.25.17-pax/arch/mips/kernel/syscall.c
--- linux-2.6.25.17/arch/mips/kernel/syscall.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/mips/kernel/syscall.c 2008-06-22 15:46:49.000000000 +0200
@@ -93,6 +93,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) || !filp)
+#endif
+
if (addr) {
if (do_color_align)
addr = COLOUR_ALIGN(addr, pgoff);
@@ -103,7 +108,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
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/mips/mm/fault.c linux-2.6.25.17-pax/arch/mips/mm/fault.c
--- linux-2.6.25.17/arch/mips/mm/fault.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/mips/mm/fault.c 2008-06-22 15:46:49.000000000 +0200
@@ -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
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/parisc/kernel/module.c linux-2.6.25.17-pax/arch/parisc/kernel/module.c
--- linux-2.6.25.17/arch/parisc/kernel/module.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/parisc/kernel/module.c 2008-06-22 15:46:49.000000000 +0200
@@ -73,16 +73,38 @@
/* 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)
@@ -296,21 +318,21 @@ int module_frob_arch_sections(CONST Elf_
}
/* 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 = ALIGN(me->core_size, 16);
- me->arch.stub_offset = me->core_size;
- me->core_size += stubs * sizeof(struct stub_entry);
-
- me->init_size = ALIGN(me->init_size, 16);
- me->arch.init_stub_offset = me->init_size;
- me->init_size += init_stubs * sizeof(struct stub_entry);
+ 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->core_size_rx = ALIGN(me->core_size_rx, 16);
+ me->arch.stub_offset = me->core_size_rx;
+ me->core_size_rx += stubs * sizeof(struct stub_entry);
+
+ me->init_size_rx = ALIGN(me->init_size_rx, 16);
+ me->arch.init_stub_offset = me->init_size_rx;
+ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
me->arch.got_max = gots;
me->arch.fdesc_max = fdescs;
@@ -330,7 +352,7 @@ static Elf64_Word get_got(struct module
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;
@@ -348,7 +370,7 @@ static Elf64_Word get_got(struct module
#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);
@@ -366,7 +388,7 @@ static Elf_Addr get_fdesc(struct module
/* 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 */
@@ -386,12 +408,12 @@ static Elf_Addr get_stub(struct module *
if(init_section) {
i = me->arch.init_stub_count++;
BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
- stub = me->module_init + me->arch.init_stub_offset +
+ stub = me->module_init_rx + me->arch.init_stub_offset +
i * sizeof(struct stub_entry);
} else {
i = me->arch.stub_count++;
BUG_ON(me->arch.stub_count > me->arch.stub_max);
- stub = me->module_core + me->arch.stub_offset +
+ stub = me->module_core_rx + me->arch.stub_offset +
i * sizeof(struct stub_entry);
}
@@ -759,7 +781,7 @@ register_unwind_table(struct module *me,
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);
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/parisc/kernel/sys_parisc.c linux-2.6.25.17-pax/arch/parisc/kernel/sys_parisc.c
--- linux-2.6.25.17/arch/parisc/kernel/sys_parisc.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/parisc/kernel/sys_parisc.c 2008-06-22 15:46:49.000000000 +0200
@@ -111,7 +111,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);
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/parisc/kernel/traps.c linux-2.6.25.17-pax/arch/parisc/kernel/traps.c
--- linux-2.6.25.17/arch/parisc/kernel/traps.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/parisc/kernel/traps.c 2008-06-22 15:46:49.000000000 +0200
@@ -732,9 +732,7 @@ void handle_interruption(int code, struc
down_read(¤t->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];
diff -NurpX linux-2.6.25.17-pax/Documentation/dontdiff linux-2.6.25.17/arch/parisc/mm/fault.c linux-2.6.25.17-pax/arch/parisc/mm/fault.c
--- linux-2.6.25.17/arch/parisc/mm/fault.c 2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25.17-pax/arch/parisc/mm/fault.c 2008-06-22 15:46:49.000000000 +0200
@@ -16,6 +16,8 @@
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/unistd.h>
+#include <linux/binfmts.h>
#include <asm/uaccess.h>
#include <asm/traps.h>
@@ -53,7 +55,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 +141,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
+
void do_page_fault(struct pt_regs *regs, unsigned long code,
unsigned long address)
{
@@ -165,8 +277,33 @@ good_area:
acc_type = parisc_acctyp(code,regs->iir);