Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/hardened-patchset:XT_PAX commit in: 3.0.7/
Date: Wed, 02 Nov 2011 23:20:31
Message-Id: 346846be4533d393006d8749ecea52d359efd3bb.blueness@gentoo
1 commit: 346846be4533d393006d8749ecea52d359efd3bb
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Wed Nov 2 23:20:13 2011 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 2 23:20:13 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-patchset.git;a=commit;h=346846be
7
8 First working version of XT_PAX
9
10 ---
11 3.0.7/4430_remove-legacy-ei-pax.patch | 87 ++++++----
12 3.0.7/4440_Rename-PT_PAX-to-XT_PAX.patch | 207 +++++++++++++++++++++++
13 3.0.7/4450_Use-XT_PAX-insteadof-PT_PAX.patch | 227 ++++++++++++++++++++++++++
14 3.0.7/4450_add-xt-pax.patch | 97 -----------
15 4 files changed, 486 insertions(+), 132 deletions(-)
16
17 diff --git a/3.0.7/4430_remove-legacy-ei-pax.patch b/3.0.7/4430_remove-legacy-ei-pax.patch
18 index dc5a894..476cbc4 100644
19 --- a/3.0.7/4430_remove-legacy-ei-pax.patch
20 +++ b/3.0.7/4430_remove-legacy-ei-pax.patch
21 @@ -1,13 +1,22 @@
22 -From: Anthony G. Basile <blueness@g.o>
23 +From 08b996f6537c593b67a371605dc16f8ad30121dd Mon Sep 17 00:00:00 2001
24 +From: root <root@xt-pax.(none)>
25 +Date: Wed, 2 Nov 2011 10:23:01 +0000
26 +Subject: [PATCH 1/3] Remove EI_PAX
27
28 -This patch removes all references to legacy EI_PAX markings
29 -in favor of PT_PAX. It should be applied immediately after
30 -the grsecurity patch.
31 +---
32 + fs/binfmt_elf.c | 55 +++----------------------------------------
33 + grsecurity/Kconfig | 2 -
34 + include/linux/elf.h | 2 -
35 + include/linux/grsecurity.h | 8 +++---
36 + include/linux/mm_types.h | 2 +-
37 + security/Kconfig | 21 +---------------
38 + 6 files changed, 11 insertions(+), 79 deletions(-)
39
40 -diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41 ---- a/fs/binfmt_elf.c 2011-10-25 17:42:18.000000000 -0400
42 -+++ b/fs/binfmt_elf.c 2011-10-25 17:49:46.000000000 -0400
43 -@@ -553,7 +553,7 @@
44 +diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45 +index 9f89be2..4779b9f 100644
46 +--- a/fs/binfmt_elf.c
47 ++++ b/fs/binfmt_elf.c
48 +@@ -553,7 +553,7 @@ out:
49 return error;
50 }
51
52 @@ -16,7 +25,7 @@ diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
53 static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
54 {
55 unsigned long pax_flags = 0UL;
56 -@@ -639,50 +639,7 @@
57 +@@ -639,50 +639,7 @@ static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata
58 }
59 #endif
60
61 @@ -68,7 +77,7 @@ diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
62 static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
63 {
64 unsigned long pax_flags = 0UL;
65 -@@ -692,10 +649,6 @@
66 +@@ -692,10 +649,6 @@ static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct
67 int found_flags = 0;
68 #endif
69
70 @@ -79,7 +88,7 @@ diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
71 #ifdef CONFIG_PAX_PT_PAX_FLAGS
72 for (i = 0UL; i < elf_ex->e_phnum; i++)
73 if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
74 -@@ -718,7 +671,7 @@
75 +@@ -718,7 +671,7 @@ static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct
76 }
77 #endif
78
79 @@ -88,7 +97,7 @@ diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
80 if (found_flags == 0) {
81 struct elf_phdr phdr;
82 memset(&phdr, 0, sizeof(phdr));
83 -@@ -951,7 +904,7 @@
84 +@@ -951,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
85
86 current->mm->def_flags = 0;
87
88 @@ -97,10 +106,11 @@ diff -Naur a/fs/binfmt_elf.c b/fs/binfmt_elf.c
89 if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
90 send_sig(SIGKILL, current, 0);
91 goto out_free_dentry;
92 -diff -Naur a/grsecurity/Kconfig b/grsecurity/Kconfig
93 ---- a/grsecurity/Kconfig 2011-10-25 17:42:18.000000000 -0400
94 -+++ b/grsecurity/Kconfig 2011-10-25 17:44:35.000000000 -0400
95 -@@ -47,7 +47,6 @@
96 +diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
97 +index 2df8a14..5090312 100644
98 +--- a/grsecurity/Kconfig
99 ++++ b/grsecurity/Kconfig
100 +@@ -47,7 +47,6 @@ config GRKERNSEC_LOW
101 config GRKERNSEC_MEDIUM
102 bool "Medium"
103 select PAX
104 @@ -108,7 +118,7 @@ diff -Naur a/grsecurity/Kconfig b/grsecurity/Kconfig
105 select PAX_PT_PAX_FLAGS
106 select PAX_HAVE_ACL_FLAGS
107 select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
108 -@@ -143,7 +142,6 @@
109 +@@ -143,7 +142,6 @@ config GRKERNSEC_HIGH
110 select PAX_RANDMMAP
111 select PAX_NOEXEC
112 select PAX_MPROTECT
113 @@ -116,10 +126,11 @@ diff -Naur a/grsecurity/Kconfig b/grsecurity/Kconfig
114 select PAX_PT_PAX_FLAGS
115 select PAX_HAVE_ACL_FLAGS
116 select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
117 -diff -Naur a/include/linux/elf.h b/include/linux/elf.h
118 ---- a/include/linux/elf.h 2011-10-25 17:42:18.000000000 -0400
119 -+++ b/include/linux/elf.h 2011-10-25 17:44:35.000000000 -0400
120 -@@ -370,8 +370,6 @@
121 +diff --git a/include/linux/elf.h b/include/linux/elf.h
122 +index cb14c08..5cd548b 100644
123 +--- a/include/linux/elf.h
124 ++++ b/include/linux/elf.h
125 +@@ -370,8 +370,6 @@ typedef struct elf64_shdr {
126 #define EI_OSABI 7
127 #define EI_PAD 8
128
129 @@ -128,9 +139,10 @@ diff -Naur a/include/linux/elf.h b/include/linux/elf.h
130 #define ELFMAG0 0x7f /* EI_MAG */
131 #define ELFMAG1 'E'
132 #define ELFMAG2 'L'
133 -diff -Naur a/include/linux/grsecurity.h b/include/linux/grsecurity.h
134 ---- a/include/linux/grsecurity.h 2011-10-25 17:42:18.000000000 -0400
135 -+++ b/include/linux/grsecurity.h 2011-10-25 17:44:35.000000000 -0400
136 +diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
137 +index 9a067c3..5a4078a 100644
138 +--- a/include/linux/grsecurity.h
139 ++++ b/include/linux/grsecurity.h
140 @@ -12,11 +12,11 @@
141 #if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
142 #error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
143 @@ -147,10 +159,11 @@ diff -Naur a/include/linux/grsecurity.h b/include/linux/grsecurity.h
144 #endif
145 #if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
146 #error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
147 -diff -Naur a/include/linux/mm_types.h b/include/linux/mm_types.h
148 ---- a/include/linux/mm_types.h 2011-10-25 17:42:18.000000000 -0400
149 -+++ b/include/linux/mm_types.h 2011-10-25 17:44:35.000000000 -0400
150 -@@ -319,7 +319,7 @@
151 +diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
152 +index 00e8ce6..3b82044 100644
153 +--- a/include/linux/mm_types.h
154 ++++ b/include/linux/mm_types.h
155 +@@ -319,7 +319,7 @@ struct mm_struct {
156 struct cpumask cpumask_allocation;
157 #endif
158
159 @@ -159,10 +172,11 @@ diff -Naur a/include/linux/mm_types.h b/include/linux/mm_types.h
160 unsigned long pax_flags;
161 #endif
162
163 -diff -Naur a/security/Kconfig b/security/Kconfig
164 ---- a/security/Kconfig 2011-10-25 17:42:19.000000000 -0400
165 -+++ b/security/Kconfig 2011-10-25 17:44:35.000000000 -0400
166 -@@ -51,20 +51,6 @@
167 +diff --git a/security/Kconfig b/security/Kconfig
168 +index 9ace91e..49af5e8 100644
169 +--- a/security/Kconfig
170 ++++ b/security/Kconfig
171 +@@ -51,20 +51,6 @@ config PAX_SOFTMODE
172 line option on boot. Furthermore you can control various PaX features
173 at runtime via the entries in /proc/sys/kernel/pax.
174
175 @@ -183,7 +197,7 @@ diff -Naur a/security/Kconfig b/security/Kconfig
176 config PAX_PT_PAX_FLAGS
177 bool 'Use ELF program header marking'
178 help
179 -@@ -79,9 +65,6 @@
180 +@@ -79,9 +65,6 @@ config PAX_PT_PAX_FLAGS
181 If your toolchain does not support PT_PAX_FLAGS markings,
182 you can create one in most cases with 'paxctl -C'.
183
184 @@ -193,7 +207,7 @@ diff -Naur a/security/Kconfig b/security/Kconfig
185 choice
186 prompt 'MAC system integration'
187 default PAX_HAVE_ACL_FLAGS
188 -@@ -113,7 +96,7 @@
189 +@@ -113,7 +96,7 @@ menu "Non-executable pages"
190
191 config PAX_NOEXEC
192 bool "Enforce non-executable pages"
193 @@ -202,7 +216,7 @@ diff -Naur a/security/Kconfig b/security/Kconfig
194 help
195 By design some architectures do not allow for protecting memory
196 pages against execution or even if they do, Linux does not make
197 -@@ -360,7 +343,7 @@
198 +@@ -360,7 +343,7 @@ menu "Address Space Layout Randomization"
199
200 config PAX_ASLR
201 bool "Address Space Layout Randomization"
202 @@ -211,3 +225,6 @@ diff -Naur a/security/Kconfig b/security/Kconfig
203 help
204 Many if not most exploit techniques rely on the knowledge of
205 certain addresses in the attacked program. The following options
206 +--
207 +1.7.3.4
208 +
209
210 diff --git a/3.0.7/4440_Rename-PT_PAX-to-XT_PAX.patch b/3.0.7/4440_Rename-PT_PAX-to-XT_PAX.patch
211 new file mode 100644
212 index 0000000..8069f58
213 --- /dev/null
214 +++ b/3.0.7/4440_Rename-PT_PAX-to-XT_PAX.patch
215 @@ -0,0 +1,207 @@
216 +From aabe9e7d87edded9bdc232cbfe224a8ca7e95d2d Mon Sep 17 00:00:00 2001
217 +From: Anthony G. Basile <blueness@g.o>
218 +Date: Wed, 2 Nov 2011 10:29:14 +0000
219 +Subject: [PATCH 2/3] Rename PT_PAX to XT_PAX
220 +
221 +---
222 + fs/binfmt_elf.c | 16 ++++++++--------
223 + grsecurity/Kconfig | 4 ++--
224 + include/linux/elf.h | 2 +-
225 + include/linux/grsecurity.h | 8 ++++----
226 + include/linux/mm_types.h | 2 +-
227 + security/Kconfig | 23 +++++++----------------
228 + 6 files changed, 23 insertions(+), 32 deletions(-)
229 +
230 +diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
231 +index 4779b9f..75d6e2b 100644
232 +--- a/fs/binfmt_elf.c
233 ++++ b/fs/binfmt_elf.c
234 +@@ -553,7 +553,7 @@ out:
235 + return error;
236 + }
237 +
238 +-#if (defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
239 ++#if (defined(CONFIG_PAX_XT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
240 + static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
241 + {
242 + unsigned long pax_flags = 0UL;
243 +@@ -596,7 +596,7 @@ static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata
244 + }
245 + #endif
246 +
247 +-#ifdef CONFIG_PAX_PT_PAX_FLAGS
248 ++#ifdef CONFIG_PAX_XT_PAX_FLAGS
249 + static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
250 + {
251 + unsigned long pax_flags = 0UL;
252 +@@ -639,19 +639,19 @@ static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata
253 + }
254 + #endif
255 +
256 +-#if defined(CONFIG_PAX_PT_PAX_FLAGS)
257 ++#if defined(CONFIG_PAX_XT_PAX_FLAGS)
258 + static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
259 + {
260 + unsigned long pax_flags = 0UL;
261 +
262 +-#ifdef CONFIG_PAX_PT_PAX_FLAGS
263 ++#ifdef CONFIG_PAX_XT_PAX_FLAGS
264 + unsigned long i;
265 + int found_flags = 0;
266 + #endif
267 +
268 +-#ifdef CONFIG_PAX_PT_PAX_FLAGS
269 ++#ifdef CONFIG_PAX_XT_PAX_FLAGS
270 + for (i = 0UL; i < elf_ex->e_phnum; i++)
271 +- if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
272 ++ if (elf_phdata[i].p_type == XT_PAX_FLAGS) {
273 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
274 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
275 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
276 +@@ -671,7 +671,7 @@ static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct
277 + }
278 + #endif
279 +
280 +-#if defined(CONFIG_PAX_PT_PAX_FLAGS)
281 ++#if defined(CONFIG_PAX_XT_PAX_FLAGS)
282 + if (found_flags == 0) {
283 + struct elf_phdr phdr;
284 + memset(&phdr, 0, sizeof(phdr));
285 +@@ -904,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
286 +
287 + current->mm->def_flags = 0;
288 +
289 +-#if defined(CONFIG_PAX_PT_PAX_FLAGS)
290 ++#if defined(CONFIG_PAX_XT_PAX_FLAGS)
291 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
292 + send_sig(SIGKILL, current, 0);
293 + goto out_free_dentry;
294 +diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
295 +index 5090312..7da631a 100644
296 +--- a/grsecurity/Kconfig
297 ++++ b/grsecurity/Kconfig
298 +@@ -47,7 +47,7 @@ config GRKERNSEC_LOW
299 + config GRKERNSEC_MEDIUM
300 + bool "Medium"
301 + select PAX
302 +- select PAX_PT_PAX_FLAGS
303 ++ select PAX_XT_PAX_FLAGS
304 + select PAX_HAVE_ACL_FLAGS
305 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
306 + select GRKERNSEC_CHROOT
307 +@@ -142,7 +142,7 @@ config GRKERNSEC_HIGH
308 + select PAX_RANDMMAP
309 + select PAX_NOEXEC
310 + select PAX_MPROTECT
311 +- select PAX_PT_PAX_FLAGS
312 ++ select PAX_XT_PAX_FLAGS
313 + select PAX_HAVE_ACL_FLAGS
314 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
315 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
316 +diff --git a/include/linux/elf.h b/include/linux/elf.h
317 +index 5cd548b..e5046be 100644
318 +--- a/include/linux/elf.h
319 ++++ b/include/linux/elf.h
320 +@@ -51,7 +51,7 @@ typedef __s64 Elf64_Sxword;
321 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
322 + #define PT_GNU_RELRO (PT_LOOS + 0x474e552)
323 +
324 +-#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
325 ++#define XT_PAX_FLAGS (PT_LOOS + 0x5041580)
326 +
327 + /* Constants for the e_flags field */
328 + #define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
329 +diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
330 +index 5a4078a..eda5926 100644
331 +--- a/include/linux/grsecurity.h
332 ++++ b/include/linux/grsecurity.h
333 +@@ -12,11 +12,11 @@
334 + #if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
335 + #error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
336 + #endif
337 +-#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
338 +-#error "CONFIG_PAX_NOEXEC enabled, but CONFIG_PAX_PT_PAX_FLAGS is not enabled."
339 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_XT_PAX_FLAGS)
340 ++#error "CONFIG_PAX_NOEXEC enabled, but CONFIG_PAX_XT_PAX_FLAGS is not enabled."
341 + #endif
342 +-#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
343 +-#error "CONFIG_PAX_ASLR enabled, but CONFIG_PAX_PT_PAX_FLAGS is not enabled."
344 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_XT_PAX_FLAGS)
345 ++#error "CONFIG_PAX_ASLR enabled, but CONFIG_PAX_XT_PAX_FLAGS is not enabled."
346 + #endif
347 + #if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
348 + #error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
349 +diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
350 +index 3b82044..8cf64ce 100644
351 +--- a/include/linux/mm_types.h
352 ++++ b/include/linux/mm_types.h
353 +@@ -319,7 +319,7 @@ struct mm_struct {
354 + struct cpumask cpumask_allocation;
355 + #endif
356 +
357 +-#if defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
358 ++#if defined(CONFIG_PAX_XT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
359 + unsigned long pax_flags;
360 + #endif
361 +
362 +diff --git a/security/Kconfig b/security/Kconfig
363 +index 49af5e8..dcac773 100644
364 +--- a/security/Kconfig
365 ++++ b/security/Kconfig
366 +@@ -40,30 +40,21 @@ menu "PaX Control"
367 +
368 + config PAX_SOFTMODE
369 + bool 'Support soft mode'
370 +- select PAX_PT_PAX_FLAGS
371 ++ select PAX_XT_PAX_FLAGS
372 + help
373 + Enabling this option will allow you to run PaX in soft mode, that
374 + is, PaX features will not be enforced by default, only on executables
375 +- marked explicitly. You must also enable PT_PAX_FLAGS support as it
376 ++ marked explicitly. You must also enable XT_PAX_FLAGS support as it
377 + is the only way to mark executables for soft mode use.
378 +
379 + Soft mode can be activated by using the "pax_softmode=1" kernel command
380 + line option on boot. Furthermore you can control various PaX features
381 + at runtime via the entries in /proc/sys/kernel/pax.
382 +
383 +-config PAX_PT_PAX_FLAGS
384 +- bool 'Use ELF program header marking'
385 ++config PAX_XT_PAX_FLAGS
386 ++ bool 'Use filesystem extended attribute marking'
387 + help
388 +- Enabling this option will allow you to control PaX features on
389 +- a per executable basis via the 'paxctl' utility available at
390 +- http://pax.grsecurity.net/. The control flags will be read from
391 +- a PaX specific ELF program header (PT_PAX_FLAGS). This marking
392 +- has the benefits of supporting both soft mode and being fully
393 +- integrated into the toolchain (the binutils patch is available
394 +- from http://pax.grsecurity.net).
395 +-
396 +- If your toolchain does not support PT_PAX_FLAGS markings,
397 +- you can create one in most cases with 'paxctl -C'.
398 ++ TODO: add a description
399 +
400 + choice
401 + prompt 'MAC system integration'
402 +@@ -96,7 +87,7 @@ menu "Non-executable pages"
403 +
404 + config PAX_NOEXEC
405 + bool "Enforce non-executable pages"
406 +- depends on (PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
407 ++ depends on (PAX_XT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
408 + help
409 + By design some architectures do not allow for protecting memory
410 + pages against execution or even if they do, Linux does not make
411 +@@ -343,7 +334,7 @@ menu "Address Space Layout Randomization"
412 +
413 + config PAX_ASLR
414 + bool "Address Space Layout Randomization"
415 +- depends on PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
416 ++ depends on PAX_XT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
417 + help
418 + Many if not most exploit techniques rely on the knowledge of
419 + certain addresses in the attacked program. The following options
420 +--
421 +1.7.3.4
422 +
423
424 diff --git a/3.0.7/4450_Use-XT_PAX-insteadof-PT_PAX.patch b/3.0.7/4450_Use-XT_PAX-insteadof-PT_PAX.patch
425 new file mode 100644
426 index 0000000..926d764
427 --- /dev/null
428 +++ b/3.0.7/4450_Use-XT_PAX-insteadof-PT_PAX.patch
429 @@ -0,0 +1,227 @@
430 +From 0183e57845ef783197aee28755a037e1813aeed8 Mon Sep 17 00:00:00 2001
431 +From: Anthony G. Basile <blueness@g.o>
432 +Date: Wed, 2 Nov 2011 23:09:54 +0000
433 +Subject: [PATCH 3/3] Use XT_PAX instead of PT_PAX
434 +
435 +---
436 + fs/binfmt_elf.c | 103 ++++++++++++++++++++++++-------------------------
437 + include/linux/xattr.h | 3 +
438 + 2 files changed, 53 insertions(+), 53 deletions(-)
439 +
440 +diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
441 +index 75d6e2b..da3837c 100644
442 +--- a/fs/binfmt_elf.c
443 ++++ b/fs/binfmt_elf.c
444 +@@ -32,6 +32,7 @@
445 + #include <linux/elf.h>
446 + #include <linux/utsname.h>
447 + #include <linux/coredump.h>
448 ++#include <linux/xattr.h>
449 + #include <asm/uaccess.h>
450 + #include <asm/param.h>
451 + #include <asm/page.h>
452 +@@ -554,17 +555,17 @@ out:
453 + }
454 +
455 + #if (defined(CONFIG_PAX_XT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
456 +-static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
457 ++static unsigned long pax_parse_softmode(unsigned long read_flags)
458 + {
459 + unsigned long pax_flags = 0UL;
460 +
461 + #ifdef CONFIG_PAX_PAGEEXEC
462 +- if (elf_phdata->p_flags & PF_PAGEEXEC)
463 ++ if (read_flags & PF_PAGEEXEC)
464 + pax_flags |= MF_PAX_PAGEEXEC;
465 + #endif
466 +
467 + #ifdef CONFIG_PAX_SEGMEXEC
468 +- if (elf_phdata->p_flags & PF_SEGMEXEC)
469 ++ if (read_flags & PF_SEGMEXEC)
470 + pax_flags |= MF_PAX_SEGMEXEC;
471 + #endif
472 +
473 +@@ -578,17 +579,17 @@ static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata
474 + #endif
475 +
476 + #ifdef CONFIG_PAX_EMUTRAMP
477 +- if (elf_phdata->p_flags & PF_EMUTRAMP)
478 ++ if (read_flags & PF_EMUTRAMP)
479 + pax_flags |= MF_PAX_EMUTRAMP;
480 + #endif
481 +
482 + #ifdef CONFIG_PAX_MPROTECT
483 +- if (elf_phdata->p_flags & PF_MPROTECT)
484 ++ if (read_flags & PF_MPROTECT)
485 + pax_flags |= MF_PAX_MPROTECT;
486 + #endif
487 +
488 + #if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
489 +- if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
490 ++ if (randomize_va_space && (read_flags & PF_RANDMMAP))
491 + pax_flags |= MF_PAX_RANDMMAP;
492 + #endif
493 +
494 +@@ -597,17 +598,17 @@ static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata
495 + #endif
496 +
497 + #ifdef CONFIG_PAX_XT_PAX_FLAGS
498 +-static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
499 ++static unsigned long pax_parse_hardmode(unsigned long read_flags)
500 + {
501 + unsigned long pax_flags = 0UL;
502 +
503 + #ifdef CONFIG_PAX_PAGEEXEC
504 +- if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
505 ++ if (!(read_flags & PF_NOPAGEEXEC))
506 + pax_flags |= MF_PAX_PAGEEXEC;
507 + #endif
508 +
509 + #ifdef CONFIG_PAX_SEGMEXEC
510 +- if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
511 ++ if (!(read_flags & PF_NOSEGMEXEC))
512 + pax_flags |= MF_PAX_SEGMEXEC;
513 + #endif
514 +
515 +@@ -621,17 +622,17 @@ static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata
516 + #endif
517 +
518 + #ifdef CONFIG_PAX_EMUTRAMP
519 +- if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
520 ++ if (!(read_flags & PF_NOEMUTRAMP))
521 + pax_flags |= MF_PAX_EMUTRAMP;
522 + #endif
523 +
524 + #ifdef CONFIG_PAX_MPROTECT
525 +- if (!(elf_phdata->p_flags & PF_NOMPROTECT))
526 ++ if (!(read_flags & PF_NOMPROTECT))
527 + pax_flags |= MF_PAX_MPROTECT;
528 + #endif
529 +
530 + #if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
531 +- if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
532 ++ if (randomize_va_space && !(read_flags & PF_NORANDMMAP))
533 + pax_flags |= MF_PAX_RANDMMAP;
534 + #endif
535 +
536 +@@ -639,51 +640,46 @@ static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata
537 + }
538 + #endif
539 +
540 +-#if defined(CONFIG_PAX_XT_PAX_FLAGS)
541 +-static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
542 ++#ifdef CONFIG_PAX_XT_PAX_FLAGS
543 ++static long pax_parse_xattr_flags(struct dentry * dentry)
544 + {
545 + unsigned long pax_flags = 0UL;
546 ++ unsigned long read_flags = 0UL;
547 ++ struct inode * inode = dentry->d_inode;
548 ++
549 ++ if (inode->i_op->getxattr)
550 ++ if (inode->i_op->getxattr(dentry, XATTR_PAX, &read_flags, sizeof(long)) <= 0)
551 ++ read_flags = PF_NOEMUTRAMP;
552 ++
553 ++ char buf[8];
554 ++ buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = '-';
555 ++ buf[6] = 0;
556 ++
557 ++ if (read_flags & PF_PAGEEXEC) buf[0] = 'P';
558 ++ if (read_flags & PF_NOPAGEEXEC) buf[0] = 'p';
559 ++ if (read_flags & PF_SEGMEXEC) buf[1] = 'S';
560 ++ if (read_flags & PF_NOSEGMEXEC) buf[1] = 's';
561 ++ if (read_flags & PF_MPROTECT) buf[2] = 'M';
562 ++ if (read_flags & PF_NOMPROTECT) buf[2] = 'm';
563 ++ if (read_flags & PF_EMUTRAMP) buf[3] = 'E';
564 ++ if (read_flags & PF_NOEMUTRAMP) buf[3] = 'e';
565 ++ if (read_flags & PF_RANDMMAP) buf[4] = 'R';
566 ++ if (read_flags & PF_NORANDMMAP) buf[4] = 'r';
567 ++ printk("\t%s\n", buf);
568 ++
569 ++ if (((read_flags & PF_PAGEEXEC) && (read_flags & PF_NOPAGEEXEC)) ||
570 ++ ((read_flags & PF_SEGMEXEC) && (read_flags & PF_NOSEGMEXEC)) ||
571 ++ ((read_flags & PF_EMUTRAMP) && (read_flags & PF_NOEMUTRAMP)) ||
572 ++ ((read_flags & PF_MPROTECT) && (read_flags & PF_NOMPROTECT)) ||
573 ++ ((read_flags & PF_RANDMMAP) && (read_flags & PF_NORANDMMAP)))
574 ++ return -EINVAL;
575 +
576 +-#ifdef CONFIG_PAX_XT_PAX_FLAGS
577 +- unsigned long i;
578 +- int found_flags = 0;
579 +-#endif
580 +-
581 +-#ifdef CONFIG_PAX_XT_PAX_FLAGS
582 +- for (i = 0UL; i < elf_ex->e_phnum; i++)
583 +- if (elf_phdata[i].p_type == XT_PAX_FLAGS) {
584 +- if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
585 +- ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
586 +- ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
587 +- ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
588 +- ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
589 +- return -EINVAL;
590 +-
591 +-#ifdef CONFIG_PAX_SOFTMODE
592 +- if (pax_softmode)
593 +- pax_flags = pax_parse_softmode(&elf_phdata[i]);
594 +- else
595 +-#endif
596 +-
597 +- pax_flags = pax_parse_hardmode(&elf_phdata[i]);
598 +- found_flags = 1;
599 +- break;
600 +- }
601 +-#endif
602 +-
603 +-#if defined(CONFIG_PAX_XT_PAX_FLAGS)
604 +- if (found_flags == 0) {
605 +- struct elf_phdr phdr;
606 +- memset(&phdr, 0, sizeof(phdr));
607 +- phdr.p_flags = PF_NOEMUTRAMP;
608 + #ifdef CONFIG_PAX_SOFTMODE
609 +- if (pax_softmode)
610 +- pax_flags = pax_parse_softmode(&phdr);
611 +- else
612 +-#endif
613 +- pax_flags = pax_parse_hardmode(&phdr);
614 +- }
615 ++ if (pax_softmode)
616 ++ pax_flags = pax_parse_softmode(read_flags);
617 ++ else
618 + #endif
619 ++ pax_flags = pax_parse_hardmode(read_flags);
620 +
621 + if (0 > pax_check_flags(&pax_flags))
622 + return -EINVAL;
623 +@@ -747,6 +743,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
624 + struct elfhdr interp_elf_ex;
625 + } *loc;
626 + unsigned long pax_task_size = TASK_SIZE;
627 ++ struct dentry * dentry = bprm->file->f_path.dentry;
628 +
629 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
630 + if (!loc) {
631 +@@ -905,7 +902,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
632 + current->mm->def_flags = 0;
633 +
634 + #if defined(CONFIG_PAX_XT_PAX_FLAGS)
635 +- if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
636 ++ if (0 > pax_parse_xattr_flags(dentry)) {
637 + send_sig(SIGKILL, current, 0);
638 + goto out_free_dentry;
639 + }
640 +diff --git a/include/linux/xattr.h b/include/linux/xattr.h
641 +index aed54c5..53636e4 100644
642 +--- a/include/linux/xattr.h
643 ++++ b/include/linux/xattr.h
644 +@@ -49,6 +49,9 @@
645 + #define XATTR_CAPS_SUFFIX "capability"
646 + #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
647 +
648 ++#define XATTR_PAX_SUFFIX "pax"
649 ++#define XATTR_PAX XATTR_USER_PREFIX XATTR_PAX_SUFFIX
650 ++
651 + #ifdef __KERNEL__
652 +
653 + #include <linux/types.h>
654 +--
655 +1.7.3.4
656 +
657
658 diff --git a/3.0.7/4450_add-xt-pax.patch b/3.0.7/4450_add-xt-pax.patch
659 deleted file mode 100644
660 index 0b6a018..0000000
661 --- a/3.0.7/4450_add-xt-pax.patch
662 +++ /dev/null
663 @@ -1,97 +0,0 @@
664 -diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
665 -index 4779b9f..f769a78 100644
666 ---- a/fs/binfmt_elf.c
667 -+++ b/fs/binfmt_elf.c
668 -@@ -32,6 +32,7 @@
669 - #include <linux/elf.h>
670 - #include <linux/utsname.h>
671 - #include <linux/coredump.h>
672 -+#include <linux/xattr.h>
673 - #include <asm/uaccess.h>
674 - #include <asm/param.h>
675 - #include <asm/page.h>
676 -@@ -647,9 +648,7 @@ static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct
677 - #ifdef CONFIG_PAX_PT_PAX_FLAGS
678 - unsigned long i;
679 - int found_flags = 0;
680 --#endif
681 -
682 --#ifdef CONFIG_PAX_PT_PAX_FLAGS
683 - for (i = 0UL; i < elf_ex->e_phnum; i++)
684 - if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
685 - if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
686 -@@ -693,6 +692,21 @@ static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct
687 - }
688 - #endif
689 -
690 -+#if defined(CONFIG_PAX_XT_PAX_FLAGS)
691 -+static long pax_parse_xattr_flags(struct dentry *dentry)
692 -+{
693 -+ unsigned long pax_flags = 0UL;
694 -+
695 -+ struct inode *inode = dentry->d_inode;
696 -+ int size = inode->i_op->getxattr(dentry, XATTR_PAX, &pax_flags, sizeof(long));
697 -+ if (size == -ENODATA || size == -EOPNOTSUPP)
698 -+ return -EINVAL;
699 -+
700 -+ current->mm->pax_flags = pax_flags;
701 -+ return 0;
702 -+}
703 -+#endif
704 -+
705 - /*
706 - * These are the functions used to load ELF style executables and shared
707 - * libraries. There is no binary dependent code anywhere else.
708 -@@ -747,6 +761,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
709 - struct elfhdr interp_elf_ex;
710 - } *loc;
711 - unsigned long pax_task_size = TASK_SIZE;
712 -+ struct dentry *dentry = bprm->file->f_path.dentry;
713 -
714 - loc = kmalloc(sizeof(*loc), GFP_KERNEL);
715 - if (!loc) {
716 -@@ -911,6 +926,13 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
717 - }
718 - #endif
719 -
720 -+#if defined(CONFIG_PAX_XT_PAX_FLAGS)
721 -+ if (0 > pax_parse_xattr_flags(dentry)) {
722 -+ send_sig(SIGKILL, current, 0);
723 -+ goto out_free_dentry;
724 -+ }
725 -+#endif
726 -+
727 - #ifdef CONFIG_PAX_HAVE_ACL_FLAGS
728 - pax_set_initial_flags(bprm);
729 - #elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
730 -diff --git a/include/linux/xattr.h b/include/linux/xattr.h
731 -index aed54c5..0ba8e8f 100644
732 ---- a/include/linux/xattr.h
733 -+++ b/include/linux/xattr.h
734 -@@ -49,6 +49,10 @@
735 - #define XATTR_CAPS_SUFFIX "capability"
736 - #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
737 -
738 -+/* PaX namespace */
739 -+#define XATTR_PAX_SUFFICE "pax"
740 -+#define XATTR_PAX XATTR_USER_PREFIX XATTR_PAX_SUFFICE
741 -+
742 - #ifdef __KERNEL__
743 -
744 - #include <linux/types.h>
745 -diff --git a/security/Kconfig b/security/Kconfig
746 -index de3cb0d..a3199ed 100644
747 ---- a/security/Kconfig
748 -+++ b/security/Kconfig
749 -@@ -65,6 +65,11 @@ config PAX_PT_PAX_FLAGS
750 - If your toolchain does not support PT_PAX_FLAGS markings,
751 - you can create one in most cases with 'paxctl -C'.
752 -
753 -+config PAX_XT_PAX_FLAGS
754 -+ bool 'Use Extended Attribute marking'
755 -+ help
756 -+ TODO: use xattr field 'user.pax' for markings
757 -+
758 - choice
759 - prompt 'MAC system integration'
760 - default PAX_HAVE_ACL_FLAGS