]>
Commit | Line | Data |
---|---|---|
de855c5d AM |
1 | diff -urNp linux-2.6.29.6/arch/alpha/include/asm/atomic.h linux-2.6.29.6/arch/alpha/include/asm/atomic.h |
2 | --- linux-2.6.29.6/arch/alpha/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
3 | +++ linux-2.6.29.6/arch/alpha/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
4 | @@ -246,6 +246,9 @@ static __inline__ int atomic64_add_unles | |
5 | #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0) | |
6 | ||
7 | #define atomic_inc(v) atomic_add(1,(v)) | |
8 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
9 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
10 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
11 | #define atomic64_inc(v) atomic64_add(1,(v)) | |
12 | ||
13 | #define atomic_dec(v) atomic_sub(1,(v)) | |
14 | diff -urNp linux-2.6.29.6/arch/alpha/include/asm/elf.h linux-2.6.29.6/arch/alpha/include/asm/elf.h | |
15 | --- linux-2.6.29.6/arch/alpha/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
16 | +++ linux-2.6.29.6/arch/alpha/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17 | @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N |
18 | ||
19 | #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) | |
20 | ||
21 | +#ifdef CONFIG_PAX_ASLR | |
22 | +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL) | |
23 | + | |
24 | +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28) | |
25 | +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19) | |
26 | +#endif | |
27 | + | |
28 | /* $0 is set by ld.so to a pointer to a function which might be | |
29 | registered using atexit. This provides a mean for the dynamic | |
30 | linker to call DT_FINI functions for shared libraries that have | |
de855c5d AM |
31 | diff -urNp linux-2.6.29.6/arch/alpha/include/asm/kmap_types.h linux-2.6.29.6/arch/alpha/include/asm/kmap_types.h |
32 | --- linux-2.6.29.6/arch/alpha/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
33 | +++ linux-2.6.29.6/arch/alpha/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34 | @@ -24,7 +24,8 @@ D(9) KM_IRQ0, |
35 | D(10) KM_IRQ1, | |
36 | D(11) KM_SOFTIRQ0, | |
37 | D(12) KM_SOFTIRQ1, | |
38 | -D(13) KM_TYPE_NR | |
39 | +D(13) KM_CLEARPAGE, | |
40 | +D(14) KM_TYPE_NR | |
41 | }; | |
42 | ||
43 | #undef D | |
de855c5d AM |
44 | diff -urNp linux-2.6.29.6/arch/alpha/include/asm/pgtable.h linux-2.6.29.6/arch/alpha/include/asm/pgtable.h |
45 | --- linux-2.6.29.6/arch/alpha/include/asm/pgtable.h 2009-07-02 19:41:20.000000000 -0400 | |
46 | +++ linux-2.6.29.6/arch/alpha/include/asm/pgtable.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
47 | @@ -101,6 +101,17 @@ struct vm_area_struct; |
48 | #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS) | |
49 | #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW) | |
50 | #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW) | |
51 | + | |
52 | +#ifdef CONFIG_PAX_PAGEEXEC | |
53 | +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE) | |
54 | +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE) | |
55 | +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE) | |
56 | +#else | |
57 | +# define PAGE_SHARED_NOEXEC PAGE_SHARED | |
58 | +# define PAGE_COPY_NOEXEC PAGE_COPY | |
59 | +# define PAGE_READONLY_NOEXEC PAGE_READONLY | |
60 | +#endif | |
61 | + | |
62 | #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE) | |
63 | ||
64 | #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x)) | |
de855c5d AM |
65 | diff -urNp linux-2.6.29.6/arch/alpha/kernel/module.c linux-2.6.29.6/arch/alpha/kernel/module.c |
66 | --- linux-2.6.29.6/arch/alpha/kernel/module.c 2009-07-02 19:41:20.000000000 -0400 | |
67 | +++ linux-2.6.29.6/arch/alpha/kernel/module.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
68 | @@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, |
69 | ||
70 | /* The small sections were sorted to the end of the segment. | |
71 | The following should definitely cover them. */ | |
72 | - gp = (u64)me->module_core + me->core_size - 0x8000; | |
73 | + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000; | |
74 | got = sechdrs[me->arch.gotsecindex].sh_addr; | |
75 | ||
76 | for (i = 0; i < n; i++) { | |
de855c5d AM |
77 | diff -urNp linux-2.6.29.6/arch/alpha/kernel/osf_sys.c linux-2.6.29.6/arch/alpha/kernel/osf_sys.c |
78 | --- linux-2.6.29.6/arch/alpha/kernel/osf_sys.c 2009-07-02 19:41:20.000000000 -0400 | |
79 | +++ linux-2.6.29.6/arch/alpha/kernel/osf_sys.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
80 | @@ -1217,6 +1217,10 @@ arch_get_unmapped_area(struct file *filp |
81 | merely specific addresses, but regions of memory -- perhaps | |
82 | this feature should be incorporated into all ports? */ | |
83 | ||
84 | +#ifdef CONFIG_PAX_RANDMMAP | |
85 | + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP)) | |
86 | +#endif | |
87 | + | |
88 | if (addr) { | |
89 | addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit); | |
90 | if (addr != (unsigned long) -ENOMEM) | |
91 | @@ -1224,8 +1228,8 @@ arch_get_unmapped_area(struct file *filp | |
92 | } | |
93 | ||
94 | /* Next, try allocating at TASK_UNMAPPED_BASE. */ | |
95 | - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE), | |
96 | - len, limit); | |
97 | + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit); | |
98 | + | |
99 | if (addr != (unsigned long) -ENOMEM) | |
100 | return addr; | |
101 | ||
de855c5d AM |
102 | diff -urNp linux-2.6.29.6/arch/alpha/mm/fault.c linux-2.6.29.6/arch/alpha/mm/fault.c |
103 | --- linux-2.6.29.6/arch/alpha/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
104 | +++ linux-2.6.29.6/arch/alpha/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
105 | @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct * |
106 | __reload_thread(pcb); | |
107 | } | |
108 | ||
109 | +#ifdef CONFIG_PAX_PAGEEXEC | |
110 | +/* | |
111 | + * PaX: decide what to do with offenders (regs->pc = fault address) | |
112 | + * | |
113 | + * returns 1 when task should be killed | |
114 | + * 2 when patched PLT trampoline was detected | |
115 | + * 3 when unpatched PLT trampoline was detected | |
116 | + */ | |
117 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
118 | +{ | |
119 | + | |
120 | +#ifdef CONFIG_PAX_EMUPLT | |
121 | + int err; | |
122 | + | |
123 | + do { /* PaX: patched PLT emulation #1 */ | |
124 | + unsigned int ldah, ldq, jmp; | |
125 | + | |
126 | + err = get_user(ldah, (unsigned int *)regs->pc); | |
127 | + err |= get_user(ldq, (unsigned int *)(regs->pc+4)); | |
128 | + err |= get_user(jmp, (unsigned int *)(regs->pc+8)); | |
129 | + | |
130 | + if (err) | |
131 | + break; | |
132 | + | |
133 | + if ((ldah & 0xFFFF0000U) == 0x277B0000U && | |
134 | + (ldq & 0xFFFF0000U) == 0xA77B0000U && | |
135 | + jmp == 0x6BFB0000U) | |
136 | + { | |
137 | + unsigned long r27, addr; | |
138 | + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16; | |
139 | + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL; | |
140 | + | |
141 | + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL); | |
142 | + err = get_user(r27, (unsigned long *)addr); | |
143 | + if (err) | |
144 | + break; | |
145 | + | |
146 | + regs->r27 = r27; | |
147 | + regs->pc = r27; | |
148 | + return 2; | |
149 | + } | |
150 | + } while (0); | |
151 | + | |
152 | + do { /* PaX: patched PLT emulation #2 */ | |
153 | + unsigned int ldah, lda, br; | |
154 | + | |
155 | + err = get_user(ldah, (unsigned int *)regs->pc); | |
156 | + err |= get_user(lda, (unsigned int *)(regs->pc+4)); | |
157 | + err |= get_user(br, (unsigned int *)(regs->pc+8)); | |
158 | + | |
159 | + if (err) | |
160 | + break; | |
161 | + | |
162 | + if ((ldah & 0xFFFF0000U) == 0x277B0000U && | |
163 | + (lda & 0xFFFF0000U) == 0xA77B0000U && | |
164 | + (br & 0xFFE00000U) == 0xC3E00000U) | |
165 | + { | |
166 | + unsigned long addr = br | 0xFFFFFFFFFFE00000UL; | |
167 | + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16; | |
168 | + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL; | |
169 | + | |
170 | + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL); | |
171 | + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2); | |
172 | + return 2; | |
173 | + } | |
174 | + } while (0); | |
175 | + | |
176 | + do { /* PaX: unpatched PLT emulation */ | |
177 | + unsigned int br; | |
178 | + | |
179 | + err = get_user(br, (unsigned int *)regs->pc); | |
180 | + | |
181 | + if (!err && (br & 0xFFE00000U) == 0xC3800000U) { | |
182 | + unsigned int br2, ldq, nop, jmp; | |
183 | + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver; | |
184 | + | |
185 | + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2); | |
186 | + err = get_user(br2, (unsigned int *)addr); | |
187 | + err |= get_user(ldq, (unsigned int *)(addr+4)); | |
188 | + err |= get_user(nop, (unsigned int *)(addr+8)); | |
189 | + err |= get_user(jmp, (unsigned int *)(addr+12)); | |
190 | + err |= get_user(resolver, (unsigned long *)(addr+16)); | |
191 | + | |
192 | + if (err) | |
193 | + break; | |
194 | + | |
195 | + if (br2 == 0xC3600000U && | |
196 | + ldq == 0xA77B000CU && | |
197 | + nop == 0x47FF041FU && | |
198 | + jmp == 0x6B7B0000U) | |
199 | + { | |
200 | + regs->r28 = regs->pc+4; | |
201 | + regs->r27 = addr+16; | |
202 | + regs->pc = resolver; | |
203 | + return 3; | |
204 | + } | |
205 | + } | |
206 | + } while (0); | |
207 | +#endif | |
208 | + | |
209 | + return 1; | |
210 | +} | |
211 | + | |
212 | +void pax_report_insns(void *pc, void *sp) | |
213 | +{ | |
214 | + unsigned long i; | |
215 | + | |
216 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
217 | + for (i = 0; i < 5; i++) { | |
218 | + unsigned int c; | |
219 | + if (get_user(c, (unsigned int *)pc+i)) | |
220 | + printk(KERN_CONT "???????? "); | |
221 | + else | |
222 | + printk(KERN_CONT "%08x ", c); | |
223 | + } | |
224 | + printk("\n"); | |
225 | +} | |
226 | +#endif | |
227 | ||
228 | /* | |
229 | * This routine handles page faults. It determines the address, | |
230 | @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns | |
231 | good_area: | |
232 | si_code = SEGV_ACCERR; | |
233 | if (cause < 0) { | |
234 | - if (!(vma->vm_flags & VM_EXEC)) | |
235 | + if (!(vma->vm_flags & VM_EXEC)) { | |
236 | + | |
237 | +#ifdef CONFIG_PAX_PAGEEXEC | |
238 | + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc) | |
239 | + goto bad_area; | |
240 | + | |
241 | + up_read(&mm->mmap_sem); | |
242 | + switch (pax_handle_fetch_fault(regs)) { | |
243 | + | |
244 | +#ifdef CONFIG_PAX_EMUPLT | |
245 | + case 2: | |
246 | + case 3: | |
247 | + return; | |
248 | +#endif | |
249 | + | |
250 | + } | |
251 | + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp()); | |
252 | + do_group_exit(SIGKILL); | |
253 | +#else | |
254 | goto bad_area; | |
255 | +#endif | |
256 | + | |
257 | + } | |
258 | } else if (!cause) { | |
259 | /* Allow reads even for write-only mappings */ | |
260 | if (!(vma->vm_flags & (VM_READ | VM_WRITE))) | |
de855c5d AM |
261 | diff -urNp linux-2.6.29.6/arch/arm/include/asm/atomic.h linux-2.6.29.6/arch/arm/include/asm/atomic.h |
262 | --- linux-2.6.29.6/arch/arm/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
263 | +++ linux-2.6.29.6/arch/arm/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
264 | @@ -191,6 +191,9 @@ static inline int atomic_add_unless(atom | |
265 | #define atomic_inc(v) (void) atomic_add_return(1, v) | |
266 | #define atomic_sub(i, v) (void) atomic_sub_return(i, v) | |
267 | #define atomic_dec(v) (void) atomic_sub_return(1, v) | |
268 | +#define atomic_inc_unchecked(v) (void) atomic_inc(v) | |
269 | +#define atomic_add_unchecked(i, v) (void) atomic_add(i, v) | |
270 | +#define atomic_sub_unchecked(i, v) (void) atomic_sub(i, v) | |
271 | ||
272 | #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0) | |
273 | #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0) | |
274 | diff -urNp linux-2.6.29.6/arch/arm/include/asm/elf.h linux-2.6.29.6/arch/arm/include/asm/elf.h | |
275 | --- linux-2.6.29.6/arch/arm/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
276 | +++ linux-2.6.29.6/arch/arm/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
277 | @@ -100,7 +100,14 @@ extern int arm_elf_read_implies_exec(con | |
2380c486 JR |
278 | the loader. We need to make sure that it is out of the way of the program |
279 | that it will "exec", and that there is sufficient room for the brk. */ | |
280 | ||
281 | -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3) | |
282 | +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) | |
283 | + | |
284 | +#ifdef CONFIG_PAX_ASLR | |
285 | +#define PAX_ELF_ET_DYN_BASE 0x00008000UL | |
286 | + | |
287 | +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10) | |
288 | +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10) | |
289 | +#endif | |
290 | ||
291 | /* When the program starts, a1 contains a pointer to a function to be | |
292 | registered with atexit, as per the SVR4 ABI. A value of 0 means we | |
de855c5d AM |
293 | diff -urNp linux-2.6.29.6/arch/arm/include/asm/kmap_types.h linux-2.6.29.6/arch/arm/include/asm/kmap_types.h |
294 | --- linux-2.6.29.6/arch/arm/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
295 | +++ linux-2.6.29.6/arch/arm/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
296 | @@ -18,6 +18,7 @@ enum km_type { |
297 | KM_IRQ1, | |
298 | KM_SOFTIRQ0, | |
299 | KM_SOFTIRQ1, | |
300 | + KM_CLEARPAGE, | |
301 | KM_TYPE_NR | |
302 | }; | |
303 | ||
de855c5d AM |
304 | diff -urNp linux-2.6.29.6/arch/arm/include/asm/uaccess.h linux-2.6.29.6/arch/arm/include/asm/uaccess.h |
305 | --- linux-2.6.29.6/arch/arm/include/asm/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
306 | +++ linux-2.6.29.6/arch/arm/include/asm/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
307 | @@ -400,7 +400,7 @@ static inline unsigned long __must_check | |
308 | { | |
309 | if (access_ok(VERIFY_READ, from, n)) | |
310 | n = __copy_from_user(to, from, n); | |
311 | - else /* security hole - plug it */ | |
312 | + else if ((long)n > 0) /* security hole - plug it -- good idea! */ | |
313 | memset(to, 0, n); | |
314 | return n; | |
315 | } | |
316 | diff -urNp linux-2.6.29.6/arch/arm/mm/mmap.c linux-2.6.29.6/arch/arm/mm/mmap.c | |
317 | --- linux-2.6.29.6/arch/arm/mm/mmap.c 2009-07-02 19:41:20.000000000 -0400 | |
318 | +++ linux-2.6.29.6/arch/arm/mm/mmap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
319 | @@ -62,6 +62,10 @@ arch_get_unmapped_area(struct file *filp |
320 | if (len > TASK_SIZE) | |
321 | return -ENOMEM; | |
322 | ||
323 | +#ifdef CONFIG_PAX_RANDMMAP | |
324 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
325 | +#endif | |
326 | + | |
327 | if (addr) { | |
328 | if (do_align) | |
329 | addr = COLOUR_ALIGN(addr, pgoff); | |
330 | @@ -74,10 +78,10 @@ arch_get_unmapped_area(struct file *filp | |
331 | return addr; | |
332 | } | |
333 | if (len > mm->cached_hole_size) { | |
334 | - start_addr = addr = mm->free_area_cache; | |
335 | + start_addr = addr = mm->free_area_cache; | |
336 | } else { | |
337 | - start_addr = addr = TASK_UNMAPPED_BASE; | |
338 | - mm->cached_hole_size = 0; | |
339 | + start_addr = addr = mm->mmap_base; | |
340 | + mm->cached_hole_size = 0; | |
341 | } | |
342 | ||
343 | full_search: | |
344 | @@ -93,8 +97,8 @@ full_search: | |
345 | * Start a new search - just in case we missed | |
346 | * some holes. | |
347 | */ | |
348 | - if (start_addr != TASK_UNMAPPED_BASE) { | |
349 | - start_addr = addr = TASK_UNMAPPED_BASE; | |
350 | + if (start_addr != mm->mmap_base) { | |
351 | + start_addr = addr = mm->mmap_base; | |
352 | mm->cached_hole_size = 0; | |
353 | goto full_search; | |
354 | } | |
de855c5d AM |
355 | diff -urNp linux-2.6.29.6/arch/avr32/include/asm/atomic.h linux-2.6.29.6/arch/avr32/include/asm/atomic.h |
356 | --- linux-2.6.29.6/arch/avr32/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
357 | +++ linux-2.6.29.6/arch/avr32/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
358 | @@ -176,9 +176,12 @@ static inline int atomic_sub_if_positive | |
359 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) | |
360 | ||
361 | #define atomic_sub(i, v) (void)atomic_sub_return(i, v) | |
362 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
363 | #define atomic_add(i, v) (void)atomic_add_return(i, v) | |
364 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
365 | #define atomic_dec(v) atomic_sub(1, (v)) | |
366 | #define atomic_inc(v) atomic_add(1, (v)) | |
367 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
368 | ||
369 | #define atomic_dec_return(v) atomic_sub_return(1, v) | |
370 | #define atomic_inc_return(v) atomic_add_return(1, v) | |
371 | diff -urNp linux-2.6.29.6/arch/avr32/include/asm/elf.h linux-2.6.29.6/arch/avr32/include/asm/elf.h | |
372 | --- linux-2.6.29.6/arch/avr32/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
373 | +++ linux-2.6.29.6/arch/avr32/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
374 | @@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg |
375 | the loader. We need to make sure that it is out of the way of the program | |
376 | that it will "exec", and that there is sufficient room for the brk. */ | |
377 | ||
378 | -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3) | |
379 | +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) | |
380 | ||
381 | +#ifdef CONFIG_PAX_ASLR | |
382 | +#define PAX_ELF_ET_DYN_BASE 0x00001000UL | |
383 | + | |
384 | +#define PAX_DELTA_MMAP_LEN 15 | |
385 | +#define PAX_DELTA_STACK_LEN 15 | |
386 | +#endif | |
387 | ||
388 | /* This yields a mask that user programs can use to figure out what | |
389 | instruction set this CPU supports. This could be done in user space, | |
de855c5d AM |
390 | diff -urNp linux-2.6.29.6/arch/avr32/include/asm/kmap_types.h linux-2.6.29.6/arch/avr32/include/asm/kmap_types.h |
391 | --- linux-2.6.29.6/arch/avr32/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
392 | +++ linux-2.6.29.6/arch/avr32/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
393 | @@ -22,7 +22,8 @@ D(10) KM_IRQ0, |
394 | D(11) KM_IRQ1, | |
395 | D(12) KM_SOFTIRQ0, | |
396 | D(13) KM_SOFTIRQ1, | |
397 | -D(14) KM_TYPE_NR | |
398 | +D(14) KM_CLEARPAGE, | |
399 | +D(15) KM_TYPE_NR | |
400 | }; | |
401 | ||
402 | #undef D | |
de855c5d AM |
403 | diff -urNp linux-2.6.29.6/arch/avr32/mm/fault.c linux-2.6.29.6/arch/avr32/mm/fault.c |
404 | --- linux-2.6.29.6/arch/avr32/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
405 | +++ linux-2.6.29.6/arch/avr32/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
406 | @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru |
407 | ||
408 | int exception_trace = 1; | |
409 | ||
410 | +#ifdef CONFIG_PAX_PAGEEXEC | |
411 | +void pax_report_insns(void *pc, void *sp) | |
412 | +{ | |
413 | + unsigned long i; | |
414 | + | |
415 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
416 | + for (i = 0; i < 20; i++) { | |
417 | + unsigned char c; | |
418 | + if (get_user(c, (unsigned char *)pc+i)) | |
419 | + printk(KERN_CONT "???????? "); | |
420 | + else | |
421 | + printk(KERN_CONT "%02x ", c); | |
422 | + } | |
423 | + printk("\n"); | |
424 | +} | |
425 | +#endif | |
426 | + | |
427 | /* | |
428 | * This routine handles page faults. It determines the address and the | |
429 | * problem, and then passes it off to one of the appropriate routines. | |
430 | @@ -157,6 +174,16 @@ bad_area: | |
431 | up_read(&mm->mmap_sem); | |
432 | ||
433 | if (user_mode(regs)) { | |
434 | + | |
435 | +#ifdef CONFIG_PAX_PAGEEXEC | |
436 | + if (mm->pax_flags & MF_PAX_PAGEEXEC) { | |
437 | + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) { | |
438 | + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp); | |
439 | + do_group_exit(SIGKILL); | |
440 | + } | |
441 | + } | |
442 | +#endif | |
443 | + | |
444 | if (exception_trace && printk_ratelimit()) | |
445 | printk("%s%s[%d]: segfault at %08lx pc %08lx " | |
446 | "sp %08lx ecr %lu\n", | |
de855c5d AM |
447 | diff -urNp linux-2.6.29.6/arch/blackfin/include/asm/atomic.h linux-2.6.29.6/arch/blackfin/include/asm/atomic.h |
448 | --- linux-2.6.29.6/arch/blackfin/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
449 | +++ linux-2.6.29.6/arch/blackfin/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
450 | @@ -178,6 +178,9 @@ static inline void atomic_set_mask(unsig | |
451 | ||
452 | #endif /* !CONFIG_SMP */ | |
453 | ||
454 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
455 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
456 | +#define atomic_inc_unchecked(v) atomic_inc((v)) | |
457 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) | |
458 | #define atomic_dec_return(v) atomic_sub_return(1,(v)) | |
459 | #define atomic_inc_return(v) atomic_add_return(1,(v)) | |
460 | diff -urNp linux-2.6.29.6/arch/blackfin/include/asm/kmap_types.h linux-2.6.29.6/arch/blackfin/include/asm/kmap_types.h | |
461 | --- linux-2.6.29.6/arch/blackfin/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
462 | +++ linux-2.6.29.6/arch/blackfin/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
463 | @@ -15,6 +15,7 @@ enum km_type { |
464 | KM_IRQ1, | |
465 | KM_SOFTIRQ0, | |
466 | KM_SOFTIRQ1, | |
467 | + KM_CLEARPAGE, | |
468 | KM_TYPE_NR | |
469 | }; | |
470 | ||
de855c5d AM |
471 | diff -urNp linux-2.6.29.6/arch/cris/include/asm/atomic.h linux-2.6.29.6/arch/cris/include/asm/atomic.h |
472 | --- linux-2.6.29.6/arch/cris/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
473 | +++ linux-2.6.29.6/arch/cris/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
474 | @@ -152,6 +152,10 @@ static inline int atomic_add_unless(atom | |
475 | } | |
476 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | |
477 | ||
478 | +#define atomic_inc_unchecked(v) atomic_inc((v)) | |
479 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
480 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
481 | + | |
482 | /* Atomic operations are already serializing */ | |
483 | #define smp_mb__before_atomic_dec() barrier() | |
484 | #define smp_mb__after_atomic_dec() barrier() | |
485 | diff -urNp linux-2.6.29.6/arch/cris/include/asm/kmap_types.h linux-2.6.29.6/arch/cris/include/asm/kmap_types.h | |
486 | --- linux-2.6.29.6/arch/cris/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
487 | +++ linux-2.6.29.6/arch/cris/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
488 | @@ -19,6 +19,7 @@ enum km_type { |
489 | KM_IRQ1, | |
490 | KM_SOFTIRQ0, | |
491 | KM_SOFTIRQ1, | |
492 | + KM_CLEARPAGE, | |
493 | KM_TYPE_NR | |
494 | }; | |
495 | ||
de855c5d AM |
496 | diff -urNp linux-2.6.29.6/arch/h8300/include/asm/atomic.h linux-2.6.29.6/arch/h8300/include/asm/atomic.h |
497 | --- linux-2.6.29.6/arch/h8300/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
498 | +++ linux-2.6.29.6/arch/h8300/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
499 | @@ -26,6 +26,7 @@ static __inline__ int atomic_add_return( | |
500 | } | |
501 | ||
502 | #define atomic_add(i, v) atomic_add_return(i, v) | |
503 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
504 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) | |
505 | ||
506 | static __inline__ int atomic_sub_return(int i, atomic_t *v) | |
507 | @@ -38,6 +39,7 @@ static __inline__ int atomic_sub_return( | |
508 | } | |
509 | ||
510 | #define atomic_sub(i, v) atomic_sub_return(i, v) | |
511 | +#define atomic_subUnchecked(i, v) atomic_sub(i, v) | |
512 | #define atomic_sub_and_test(i,v) (atomic_sub_return(i, v) == 0) | |
513 | ||
514 | static __inline__ int atomic_inc_return(atomic_t *v) | |
515 | @@ -51,6 +53,7 @@ static __inline__ int atomic_inc_return( | |
516 | } | |
517 | ||
518 | #define atomic_inc(v) atomic_inc_return(v) | |
519 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
520 | ||
521 | /* | |
522 | * atomic_inc_and_test - increment and test | |
523 | diff -urNp linux-2.6.29.6/arch/h8300/include/asm/kmap_types.h linux-2.6.29.6/arch/h8300/include/asm/kmap_types.h | |
524 | --- linux-2.6.29.6/arch/h8300/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
525 | +++ linux-2.6.29.6/arch/h8300/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
526 | @@ -15,6 +15,7 @@ enum km_type { |
527 | KM_IRQ1, | |
528 | KM_SOFTIRQ0, | |
529 | KM_SOFTIRQ1, | |
530 | + KM_CLEARPAGE, | |
531 | KM_TYPE_NR | |
532 | }; | |
533 | ||
de855c5d AM |
534 | diff -urNp linux-2.6.29.6/arch/ia64/ia32/binfmt_elf32.c linux-2.6.29.6/arch/ia64/ia32/binfmt_elf32.c |
535 | --- linux-2.6.29.6/arch/ia64/ia32/binfmt_elf32.c 2009-07-02 19:41:20.000000000 -0400 | |
536 | +++ linux-2.6.29.6/arch/ia64/ia32/binfmt_elf32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
537 | @@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_ |
538 | ||
539 | #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack)) | |
540 | ||
541 | +#ifdef CONFIG_PAX_ASLR | |
542 | +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL) | |
543 | + | |
544 | +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13) | |
545 | +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13) | |
546 | +#endif | |
547 | + | |
548 | /* Ugly but avoids duplication */ | |
549 | #include "../../../fs/binfmt_elf.c" | |
550 | ||
de855c5d AM |
551 | diff -urNp linux-2.6.29.6/arch/ia64/ia32/ia32priv.h linux-2.6.29.6/arch/ia64/ia32/ia32priv.h |
552 | --- linux-2.6.29.6/arch/ia64/ia32/ia32priv.h 2009-07-02 19:41:20.000000000 -0400 | |
553 | +++ linux-2.6.29.6/arch/ia64/ia32/ia32priv.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
554 | @@ -296,7 +296,14 @@ typedef struct compat_siginfo { |
555 | #define ELF_DATA ELFDATA2LSB | |
556 | #define ELF_ARCH EM_386 | |
557 | ||
558 | -#define IA32_STACK_TOP IA32_PAGE_OFFSET | |
559 | +#ifdef CONFIG_PAX_RANDUSTACK | |
560 | +#define __IA32_DELTA_STACK (current->mm->delta_stack) | |
561 | +#else | |
562 | +#define __IA32_DELTA_STACK 0UL | |
563 | +#endif | |
564 | + | |
565 | +#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK) | |
566 | + | |
567 | #define IA32_GATE_OFFSET IA32_PAGE_OFFSET | |
568 | #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE | |
569 | ||
de855c5d AM |
570 | diff -urNp linux-2.6.29.6/arch/ia64/include/asm/atomic.h linux-2.6.29.6/arch/ia64/include/asm/atomic.h |
571 | --- linux-2.6.29.6/arch/ia64/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
572 | +++ linux-2.6.29.6/arch/ia64/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
573 | @@ -201,8 +201,11 @@ atomic64_add_negative (__s64 i, atomic64 | |
574 | #define atomic64_inc_and_test(v) (atomic64_add_return(1, (v)) == 0) | |
575 | ||
576 | #define atomic_add(i,v) atomic_add_return((i), (v)) | |
577 | +#define atomic_add_unchecked(i,v) atomic_add((i), (v)) | |
578 | #define atomic_sub(i,v) atomic_sub_return((i), (v)) | |
579 | +#define atomic_sub_unchecked(i,v) atomic_sub((i), (v)) | |
580 | #define atomic_inc(v) atomic_add(1, (v)) | |
581 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
582 | #define atomic_dec(v) atomic_sub(1, (v)) | |
583 | ||
584 | #define atomic64_add(i,v) atomic64_add_return((i), (v)) | |
585 | diff -urNp linux-2.6.29.6/arch/ia64/include/asm/elf.h linux-2.6.29.6/arch/ia64/include/asm/elf.h | |
586 | --- linux-2.6.29.6/arch/ia64/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
587 | +++ linux-2.6.29.6/arch/ia64/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
588 | @@ -43,6 +43,13 @@ |
589 | */ | |
590 | #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL) | |
591 | ||
592 | +#ifdef CONFIG_PAX_ASLR | |
593 | +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL) | |
594 | + | |
595 | +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13) | |
596 | +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13) | |
597 | +#endif | |
598 | + | |
599 | #define PT_IA_64_UNWIND 0x70000001 | |
600 | ||
601 | /* IA-64 relocations: */ | |
de855c5d AM |
602 | diff -urNp linux-2.6.29.6/arch/ia64/include/asm/kmap_types.h linux-2.6.29.6/arch/ia64/include/asm/kmap_types.h |
603 | --- linux-2.6.29.6/arch/ia64/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
604 | +++ linux-2.6.29.6/arch/ia64/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
605 | @@ -22,7 +22,8 @@ D(9) KM_IRQ0, |
606 | D(10) KM_IRQ1, | |
607 | D(11) KM_SOFTIRQ0, | |
608 | D(12) KM_SOFTIRQ1, | |
609 | -D(13) KM_TYPE_NR | |
610 | +D(13) KM_CLEARPAGE, | |
611 | +D(14) KM_TYPE_NR | |
612 | }; | |
613 | ||
614 | #undef D | |
de855c5d AM |
615 | diff -urNp linux-2.6.29.6/arch/ia64/include/asm/pgtable.h linux-2.6.29.6/arch/ia64/include/asm/pgtable.h |
616 | --- linux-2.6.29.6/arch/ia64/include/asm/pgtable.h 2009-07-02 19:41:20.000000000 -0400 | |
617 | +++ linux-2.6.29.6/arch/ia64/include/asm/pgtable.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
618 | @@ -143,6 +143,17 @@ |
619 | #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R) | |
620 | #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R) | |
621 | #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX) | |
622 | + | |
623 | +#ifdef CONFIG_PAX_PAGEEXEC | |
624 | +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW) | |
625 | +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R) | |
626 | +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R) | |
627 | +#else | |
628 | +# define PAGE_SHARED_NOEXEC PAGE_SHARED | |
629 | +# define PAGE_READONLY_NOEXEC PAGE_READONLY | |
630 | +# define PAGE_COPY_NOEXEC PAGE_COPY | |
631 | +#endif | |
632 | + | |
633 | #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX) | |
634 | #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX) | |
635 | #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX) | |
de855c5d AM |
636 | diff -urNp linux-2.6.29.6/arch/ia64/include/asm/uaccess.h linux-2.6.29.6/arch/ia64/include/asm/uaccess.h |
637 | --- linux-2.6.29.6/arch/ia64/include/asm/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
638 | +++ linux-2.6.29.6/arch/ia64/include/asm/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
639 | @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _ | |
640 | const void *__cu_from = (from); \ | |
641 | long __cu_len = (n); \ | |
642 | \ | |
643 | - if (__access_ok(__cu_to, __cu_len, get_fs())) \ | |
644 | + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \ | |
645 | __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \ | |
646 | __cu_len; \ | |
647 | }) | |
648 | @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _ | |
649 | long __cu_len = (n); \ | |
650 | \ | |
651 | __chk_user_ptr(__cu_from); \ | |
652 | - if (__access_ok(__cu_from, __cu_len, get_fs())) \ | |
653 | + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \ | |
654 | __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \ | |
655 | __cu_len; \ | |
656 | }) | |
657 | diff -urNp linux-2.6.29.6/arch/ia64/kernel/module.c linux-2.6.29.6/arch/ia64/kernel/module.c | |
658 | --- linux-2.6.29.6/arch/ia64/kernel/module.c 2009-07-02 19:41:20.000000000 -0400 | |
659 | +++ linux-2.6.29.6/arch/ia64/kernel/module.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
660 | @@ -312,8 +312,7 @@ module_alloc (unsigned long size) |
661 | void | |
662 | module_free (struct module *mod, void *module_region) | |
663 | { | |
664 | - if (mod && mod->arch.init_unw_table && | |
665 | - module_region == mod->module_init) { | |
666 | + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) { | |
667 | unw_remove_unwind_table(mod->arch.init_unw_table); | |
668 | mod->arch.init_unw_table = NULL; | |
669 | } | |
670 | @@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd | |
671 | } | |
672 | ||
673 | static inline int | |
674 | +in_init_rx (const struct module *mod, uint64_t addr) | |
675 | +{ | |
676 | + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx; | |
677 | +} | |
678 | + | |
679 | +static inline int | |
680 | +in_init_rw (const struct module *mod, uint64_t addr) | |
681 | +{ | |
682 | + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw; | |
683 | +} | |
684 | + | |
685 | +static inline int | |
686 | in_init (const struct module *mod, uint64_t addr) | |
687 | { | |
688 | - return addr - (uint64_t) mod->module_init < mod->init_size; | |
689 | + return in_init_rx(mod, addr) || in_init_rw(mod, addr); | |
690 | +} | |
691 | + | |
692 | +static inline int | |
693 | +in_core_rx (const struct module *mod, uint64_t addr) | |
694 | +{ | |
695 | + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx; | |
696 | +} | |
697 | + | |
698 | +static inline int | |
699 | +in_core_rw (const struct module *mod, uint64_t addr) | |
700 | +{ | |
701 | + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw; | |
702 | } | |
703 | ||
704 | static inline int | |
705 | in_core (const struct module *mod, uint64_t addr) | |
706 | { | |
707 | - return addr - (uint64_t) mod->module_core < mod->core_size; | |
708 | + return in_core_rx(mod, addr) || in_core_rw(mod, addr); | |
709 | } | |
710 | ||
711 | static inline int | |
712 | @@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_ | |
713 | break; | |
714 | ||
715 | case RV_BDREL: | |
716 | - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core); | |
717 | + if (in_init_rx(mod, val)) | |
718 | + val -= (uint64_t) mod->module_init_rx; | |
719 | + else if (in_init_rw(mod, val)) | |
720 | + val -= (uint64_t) mod->module_init_rw; | |
721 | + else if (in_core_rx(mod, val)) | |
722 | + val -= (uint64_t) mod->module_core_rx; | |
723 | + else if (in_core_rw(mod, val)) | |
724 | + val -= (uint64_t) mod->module_core_rw; | |
725 | break; | |
726 | ||
727 | case RV_LTV: | |
728 | @@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, | |
729 | * addresses have been selected... | |
730 | */ | |
731 | uint64_t gp; | |
732 | - if (mod->core_size > MAX_LTOFF) | |
733 | + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF) | |
734 | /* | |
735 | * This takes advantage of fact that SHF_ARCH_SMALL gets allocated | |
736 | * at the end of the module. | |
737 | */ | |
738 | - gp = mod->core_size - MAX_LTOFF / 2; | |
739 | + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2; | |
740 | else | |
741 | - gp = mod->core_size / 2; | |
742 | - gp = (uint64_t) mod->module_core + ((gp + 7) & -8); | |
743 | + gp = (mod->core_size_rx + mod->core_size_rw) / 2; | |
744 | + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8); | |
745 | mod->arch.gp = gp; | |
746 | DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp); | |
747 | } | |
de855c5d AM |
748 | diff -urNp linux-2.6.29.6/arch/ia64/kernel/sys_ia64.c linux-2.6.29.6/arch/ia64/kernel/sys_ia64.c |
749 | --- linux-2.6.29.6/arch/ia64/kernel/sys_ia64.c 2009-07-02 19:41:20.000000000 -0400 | |
750 | +++ linux-2.6.29.6/arch/ia64/kernel/sys_ia64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
751 | @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil |
752 | if (REGION_NUMBER(addr) == RGN_HPAGE) | |
753 | addr = 0; | |
754 | #endif | |
755 | + | |
756 | +#ifdef CONFIG_PAX_RANDMMAP | |
757 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
758 | + addr = mm->free_area_cache; | |
759 | + else | |
760 | +#endif | |
761 | + | |
762 | if (!addr) | |
763 | addr = mm->free_area_cache; | |
764 | ||
765 | @@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil | |
766 | for (vma = find_vma(mm, addr); ; vma = vma->vm_next) { | |
767 | /* At this point: (!vma || addr < vma->vm_end). */ | |
768 | if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) { | |
769 | - if (start_addr != TASK_UNMAPPED_BASE) { | |
770 | + if (start_addr != mm->mmap_base) { | |
771 | /* Start a new search --- just in case we missed some holes. */ | |
772 | - addr = TASK_UNMAPPED_BASE; | |
773 | + addr = mm->mmap_base; | |
774 | goto full_search; | |
775 | } | |
776 | return -ENOMEM; | |
de855c5d AM |
777 | diff -urNp linux-2.6.29.6/arch/ia64/mm/fault.c linux-2.6.29.6/arch/ia64/mm/fault.c |
778 | --- linux-2.6.29.6/arch/ia64/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
779 | +++ linux-2.6.29.6/arch/ia64/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
780 | @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned |
781 | return pte_present(pte); | |
782 | } | |
783 | ||
784 | +#ifdef CONFIG_PAX_PAGEEXEC | |
785 | +void pax_report_insns(void *pc, void *sp) | |
786 | +{ | |
787 | + unsigned long i; | |
788 | + | |
789 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
790 | + for (i = 0; i < 8; i++) { | |
791 | + unsigned int c; | |
792 | + if (get_user(c, (unsigned int *)pc+i)) | |
793 | + printk(KERN_CONT "???????? "); | |
794 | + else | |
795 | + printk(KERN_CONT "%08x ", c); | |
796 | + } | |
797 | + printk("\n"); | |
798 | +} | |
799 | +#endif | |
800 | + | |
801 | void __kprobes | |
802 | ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs) | |
803 | { | |
804 | @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres | |
805 | mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT) | |
806 | | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT)); | |
807 | ||
808 | - if ((vma->vm_flags & mask) != mask) | |
809 | + if ((vma->vm_flags & mask) != mask) { | |
810 | + | |
811 | +#ifdef CONFIG_PAX_PAGEEXEC | |
812 | + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) { | |
813 | + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip) | |
814 | + goto bad_area; | |
815 | + | |
816 | + up_read(&mm->mmap_sem); | |
817 | + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12); | |
818 | + do_group_exit(SIGKILL); | |
819 | + } | |
820 | +#endif | |
821 | + | |
822 | goto bad_area; | |
823 | ||
824 | + } | |
825 | + | |
826 | survive: | |
827 | /* | |
828 | * If for any reason at all we couldn't handle the fault, make | |
de855c5d AM |
829 | diff -urNp linux-2.6.29.6/arch/ia64/mm/init.c linux-2.6.29.6/arch/ia64/mm/init.c |
830 | --- linux-2.6.29.6/arch/ia64/mm/init.c 2009-07-02 19:41:20.000000000 -0400 | |
831 | +++ linux-2.6.29.6/arch/ia64/mm/init.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
832 | @@ -121,6 +121,19 @@ ia64_init_addr_space (void) |
833 | vma->vm_start = current->thread.rbs_bot & PAGE_MASK; | |
834 | vma->vm_end = vma->vm_start + PAGE_SIZE; | |
835 | vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT; | |
836 | + | |
837 | +#ifdef CONFIG_PAX_PAGEEXEC | |
838 | + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) { | |
839 | + vma->vm_flags &= ~VM_EXEC; | |
840 | + | |
841 | +#ifdef CONFIG_PAX_MPROTECT | |
842 | + if (current->mm->pax_flags & MF_PAX_MPROTECT) | |
843 | + vma->vm_flags &= ~VM_MAYEXEC; | |
844 | +#endif | |
845 | + | |
846 | + } | |
847 | +#endif | |
848 | + | |
849 | vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
850 | down_write(¤t->mm->mmap_sem); | |
851 | if (insert_vm_struct(current->mm, vma)) { | |
de855c5d AM |
852 | diff -urNp linux-2.6.29.6/arch/m32r/lib/usercopy.c linux-2.6.29.6/arch/m32r/lib/usercopy.c |
853 | --- linux-2.6.29.6/arch/m32r/lib/usercopy.c 2009-07-02 19:41:20.000000000 -0400 | |
854 | +++ linux-2.6.29.6/arch/m32r/lib/usercopy.c 2009-07-09 22:13:39.000000000 -0400 | |
855 | @@ -26,7 +26,7 @@ __generic_copy_from_user(void *to, const | |
856 | prefetchw(to); | |
857 | if (access_ok(VERIFY_READ, from, n)) | |
858 | __copy_user_zeroing(to,from,n); | |
859 | - else | |
860 | + else if ((long)n > 0) | |
861 | memset(to, 0, n); | |
862 | return n; | |
863 | } | |
864 | diff -urNp linux-2.6.29.6/arch/m68k/include/asm/atomic_mm.h linux-2.6.29.6/arch/m68k/include/asm/atomic_mm.h | |
865 | --- linux-2.6.29.6/arch/m68k/include/asm/atomic_mm.h 2009-07-02 19:41:20.000000000 -0400 | |
866 | +++ linux-2.6.29.6/arch/m68k/include/asm/atomic_mm.h 2009-07-09 22:20:50.000000000 -0400 | |
867 | @@ -186,6 +186,10 @@ static __inline__ int atomic_add_unless( | |
868 | ||
869 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | |
870 | ||
871 | +#define atomic_inc_unchecked(v) atomic_inc((v)) | |
872 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
873 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
874 | + | |
875 | /* Atomic operations are already serializing */ | |
876 | #define smp_mb__before_atomic_dec() barrier() | |
877 | #define smp_mb__after_atomic_dec() barrier() | |
878 | diff -urNp linux-2.6.29.6/arch/m68k/include/asm/atomic_no.h linux-2.6.29.6/arch/m68k/include/asm/atomic_no.h | |
879 | --- linux-2.6.29.6/arch/m68k/include/asm/atomic_no.h 2009-07-02 19:41:20.000000000 -0400 | |
880 | +++ linux-2.6.29.6/arch/m68k/include/asm/atomic_no.h 2009-07-09 22:13:39.000000000 -0400 | |
881 | @@ -151,5 +151,9 @@ static __inline__ int atomic_add_unless( | |
882 | #define atomic_dec_return(v) atomic_sub_return(1,(v)) | |
883 | #define atomic_inc_return(v) atomic_add_return(1,(v)) | |
884 | ||
885 | +#define atomic_inc_unchecked(v) atomic_inc((v)) | |
886 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
887 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
888 | + | |
889 | #include <asm-generic/atomic.h> | |
890 | #endif /* __ARCH_M68KNOMMU_ATOMIC __ */ | |
891 | diff -urNp linux-2.6.29.6/arch/m68k/include/asm/kmap_types_mm.h linux-2.6.29.6/arch/m68k/include/asm/kmap_types_mm.h | |
892 | --- linux-2.6.29.6/arch/m68k/include/asm/kmap_types_mm.h 2009-07-02 19:41:20.000000000 -0400 | |
893 | +++ linux-2.6.29.6/arch/m68k/include/asm/kmap_types_mm.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
894 | @@ -15,6 +15,7 @@ enum km_type { |
895 | KM_IRQ1, | |
896 | KM_SOFTIRQ0, | |
897 | KM_SOFTIRQ1, | |
898 | + KM_CLEARPAGE, | |
899 | KM_TYPE_NR | |
900 | }; | |
901 | ||
de855c5d AM |
902 | diff -urNp linux-2.6.29.6/arch/m68k/include/asm/kmap_types_no.h linux-2.6.29.6/arch/m68k/include/asm/kmap_types_no.h |
903 | --- linux-2.6.29.6/arch/m68k/include/asm/kmap_types_no.h 2009-07-02 19:41:20.000000000 -0400 | |
904 | +++ linux-2.6.29.6/arch/m68k/include/asm/kmap_types_no.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
905 | @@ -15,6 +15,7 @@ enum km_type { |
906 | KM_IRQ1, | |
907 | KM_SOFTIRQ0, | |
908 | KM_SOFTIRQ1, | |
909 | + KM_CLEARPAGE, | |
910 | KM_TYPE_NR | |
911 | }; | |
912 | ||
de855c5d AM |
913 | diff -urNp linux-2.6.29.6/arch/mips/include/asm/atomic.h linux-2.6.29.6/arch/mips/include/asm/atomic.h |
914 | --- linux-2.6.29.6/arch/mips/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
915 | +++ linux-2.6.29.6/arch/mips/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
916 | @@ -381,6 +381,9 @@ static __inline__ int atomic_add_unless( | |
917 | * Atomically increments @v by 1. | |
918 | */ | |
919 | #define atomic_inc(v) atomic_add(1, (v)) | |
920 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
921 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
922 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
923 | ||
924 | /* | |
925 | * atomic_dec - decrement and test | |
926 | diff -urNp linux-2.6.29.6/arch/mips/include/asm/elf.h linux-2.6.29.6/arch/mips/include/asm/elf.h | |
927 | --- linux-2.6.29.6/arch/mips/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
928 | +++ linux-2.6.29.6/arch/mips/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
929 | @@ -364,4 +364,11 @@ extern int dump_task_fpu(struct task_str |
930 | #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) | |
931 | #endif | |
932 | ||
933 | +#ifdef CONFIG_PAX_ASLR | |
934 | +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL) | |
935 | + | |
936 | +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
937 | +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
938 | +#endif | |
939 | + | |
940 | #endif /* _ASM_ELF_H */ | |
de855c5d AM |
941 | diff -urNp linux-2.6.29.6/arch/mips/include/asm/kmap_types.h linux-2.6.29.6/arch/mips/include/asm/kmap_types.h |
942 | --- linux-2.6.29.6/arch/mips/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
943 | +++ linux-2.6.29.6/arch/mips/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
944 | @@ -22,7 +22,8 @@ D(9) KM_IRQ0, |
945 | D(10) KM_IRQ1, | |
946 | D(11) KM_SOFTIRQ0, | |
947 | D(12) KM_SOFTIRQ1, | |
948 | -D(13) KM_TYPE_NR | |
949 | +D(13) KM_CLEARPAGE, | |
950 | +D(14) KM_TYPE_NR | |
951 | }; | |
952 | ||
953 | #undef D | |
de855c5d AM |
954 | diff -urNp linux-2.6.29.6/arch/mips/include/asm/page.h linux-2.6.29.6/arch/mips/include/asm/page.h |
955 | --- linux-2.6.29.6/arch/mips/include/asm/page.h 2009-07-02 19:41:20.000000000 -0400 | |
956 | +++ linux-2.6.29.6/arch/mips/include/asm/page.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
957 | @@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa |
958 | #ifdef CONFIG_CPU_MIPS32 | |
959 | typedef struct { unsigned long pte_low, pte_high; } pte_t; | |
960 | #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) | |
961 | - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; }) | |
962 | + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; }) | |
963 | #else | |
964 | typedef struct { unsigned long long pte; } pte_t; | |
965 | #define pte_val(x) ((x).pte) | |
de855c5d AM |
966 | diff -urNp linux-2.6.29.6/arch/mips/include/asm/system.h linux-2.6.29.6/arch/mips/include/asm/system.h |
967 | --- linux-2.6.29.6/arch/mips/include/asm/system.h 2009-07-02 19:41:20.000000000 -0400 | |
968 | +++ linux-2.6.29.6/arch/mips/include/asm/system.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
969 | @@ -217,6 +217,6 @@ extern void per_cpu_trap_init(void); |
970 | */ | |
971 | #define __ARCH_WANT_UNLOCKED_CTXSW | |
972 | ||
973 | -extern unsigned long arch_align_stack(unsigned long sp); | |
974 | +#define arch_align_stack(x) ((x) & ALMASK) | |
975 | ||
976 | #endif /* _ASM_SYSTEM_H */ | |
de855c5d AM |
977 | diff -urNp linux-2.6.29.6/arch/mips/kernel/binfmt_elfn32.c linux-2.6.29.6/arch/mips/kernel/binfmt_elfn32.c |
978 | --- linux-2.6.29.6/arch/mips/kernel/binfmt_elfn32.c 2009-07-02 19:41:20.000000000 -0400 | |
979 | +++ linux-2.6.29.6/arch/mips/kernel/binfmt_elfn32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
980 | @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N |
981 | #undef ELF_ET_DYN_BASE | |
982 | #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2) | |
983 | ||
984 | +#ifdef CONFIG_PAX_ASLR | |
985 | +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL) | |
986 | + | |
987 | +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
988 | +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
989 | +#endif | |
990 | + | |
991 | #include <asm/processor.h> | |
992 | #include <linux/module.h> | |
993 | #include <linux/elfcore.h> | |
de855c5d AM |
994 | diff -urNp linux-2.6.29.6/arch/mips/kernel/binfmt_elfo32.c linux-2.6.29.6/arch/mips/kernel/binfmt_elfo32.c |
995 | --- linux-2.6.29.6/arch/mips/kernel/binfmt_elfo32.c 2009-07-02 19:41:20.000000000 -0400 | |
996 | +++ linux-2.6.29.6/arch/mips/kernel/binfmt_elfo32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
997 | @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N |
998 | #undef ELF_ET_DYN_BASE | |
999 | #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2) | |
1000 | ||
1001 | +#ifdef CONFIG_PAX_ASLR | |
1002 | +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL) | |
1003 | + | |
1004 | +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
1005 | +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT) | |
1006 | +#endif | |
1007 | + | |
1008 | #include <asm/processor.h> | |
1009 | #include <linux/module.h> | |
1010 | #include <linux/elfcore.h> | |
de855c5d AM |
1011 | diff -urNp linux-2.6.29.6/arch/mips/kernel/process.c linux-2.6.29.6/arch/mips/kernel/process.c |
1012 | --- linux-2.6.29.6/arch/mips/kernel/process.c 2009-07-02 19:41:20.000000000 -0400 | |
1013 | +++ linux-2.6.29.6/arch/mips/kernel/process.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1014 | @@ -457,15 +457,3 @@ unsigned long get_wchan(struct task_stru |
1015 | out: | |
1016 | return pc; | |
1017 | } | |
1018 | - | |
1019 | -/* | |
1020 | - * Don't forget that the stack pointer must be aligned on a 8 bytes | |
1021 | - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI. | |
1022 | - */ | |
1023 | -unsigned long arch_align_stack(unsigned long sp) | |
1024 | -{ | |
1025 | - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) | |
1026 | - sp -= get_random_int() & ~PAGE_MASK; | |
1027 | - | |
1028 | - return sp & ALMASK; | |
1029 | -} | |
de855c5d AM |
1030 | diff -urNp linux-2.6.29.6/arch/mips/kernel/syscall.c linux-2.6.29.6/arch/mips/kernel/syscall.c |
1031 | --- linux-2.6.29.6/arch/mips/kernel/syscall.c 2009-07-02 19:41:20.000000000 -0400 | |
1032 | +++ linux-2.6.29.6/arch/mips/kernel/syscall.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1033 | @@ -99,6 +99,11 @@ unsigned long arch_get_unmapped_area(str |
1034 | do_color_align = 0; | |
1035 | if (filp || (flags & MAP_SHARED)) | |
1036 | do_color_align = 1; | |
1037 | + | |
1038 | +#ifdef CONFIG_PAX_RANDMMAP | |
1039 | + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP)) | |
1040 | +#endif | |
1041 | + | |
1042 | if (addr) { | |
1043 | if (do_color_align) | |
1044 | addr = COLOUR_ALIGN(addr, pgoff); | |
1045 | @@ -109,7 +114,7 @@ unsigned long arch_get_unmapped_area(str | |
1046 | (!vmm || addr + len <= vmm->vm_start)) | |
1047 | return addr; | |
1048 | } | |
1049 | - addr = TASK_UNMAPPED_BASE; | |
1050 | + addr = current->mm->mmap_base; | |
1051 | if (do_color_align) | |
1052 | addr = COLOUR_ALIGN(addr, pgoff); | |
1053 | else | |
de855c5d AM |
1054 | diff -urNp linux-2.6.29.6/arch/mips/mm/fault.c linux-2.6.29.6/arch/mips/mm/fault.c |
1055 | --- linux-2.6.29.6/arch/mips/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
1056 | +++ linux-2.6.29.6/arch/mips/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1057 | @@ -26,6 +26,23 @@ |
1058 | #include <asm/ptrace.h> | |
1059 | #include <asm/highmem.h> /* For VMALLOC_END */ | |
1060 | ||
1061 | +#ifdef CONFIG_PAX_PAGEEXEC | |
1062 | +void pax_report_insns(void *pc) | |
1063 | +{ | |
1064 | + unsigned long i; | |
1065 | + | |
1066 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
1067 | + for (i = 0; i < 5; i++) { | |
1068 | + unsigned int c; | |
1069 | + if (get_user(c, (unsigned int *)pc+i)) | |
1070 | + printk(KERN_CONT "???????? "); | |
1071 | + else | |
1072 | + printk(KERN_CONT "%08x ", c); | |
1073 | + } | |
1074 | + printk("\n"); | |
1075 | +} | |
1076 | +#endif | |
1077 | + | |
1078 | /* | |
1079 | * This routine handles page faults. It determines the address, | |
1080 | * and the problem, and then passes it off to one of the appropriate | |
de855c5d AM |
1081 | diff -urNp linux-2.6.29.6/arch/parisc/include/asm/atomic.h linux-2.6.29.6/arch/parisc/include/asm/atomic.h |
1082 | --- linux-2.6.29.6/arch/parisc/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
1083 | +++ linux-2.6.29.6/arch/parisc/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
1084 | @@ -223,8 +223,11 @@ static __inline__ int atomic_add_unless( | |
1085 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | |
1086 | ||
1087 | #define atomic_add(i,v) ((void)(__atomic_add_return( ((int)i),(v)))) | |
1088 | +#define atomic_add_unchecked(i,v) atomic_add((i), (v)) | |
1089 | #define atomic_sub(i,v) ((void)(__atomic_add_return(-((int)i),(v)))) | |
1090 | +#define atomic_sub_unchecked(i,v) atomic_sub((i), (v)) | |
1091 | #define atomic_inc(v) ((void)(__atomic_add_return( 1,(v)))) | |
1092 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
1093 | #define atomic_dec(v) ((void)(__atomic_add_return( -1,(v)))) | |
1094 | ||
1095 | #define atomic_add_return(i,v) (__atomic_add_return( ((int)i),(v))) | |
1096 | diff -urNp linux-2.6.29.6/arch/parisc/include/asm/elf.h linux-2.6.29.6/arch/parisc/include/asm/elf.h | |
1097 | --- linux-2.6.29.6/arch/parisc/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
1098 | +++ linux-2.6.29.6/arch/parisc/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1099 | @@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration.. |
1100 | ||
1101 | #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) | |
1102 | ||
1103 | +#ifdef CONFIG_PAX_ASLR | |
1104 | +#define PAX_ELF_ET_DYN_BASE 0x10000UL | |
1105 | + | |
1106 | +#define PAX_DELTA_MMAP_LEN 16 | |
1107 | +#define PAX_DELTA_STACK_LEN 16 | |
1108 | +#endif | |
1109 | + | |
1110 | /* This yields a mask that user programs can use to figure out what | |
1111 | instruction set this CPU supports. This could be done in user space, | |
1112 | but it's not easy, and we've already done it here. */ | |
de855c5d AM |
1113 | diff -urNp linux-2.6.29.6/arch/parisc/include/asm/kmap_types.h linux-2.6.29.6/arch/parisc/include/asm/kmap_types.h |
1114 | --- linux-2.6.29.6/arch/parisc/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
1115 | +++ linux-2.6.29.6/arch/parisc/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1116 | @@ -22,7 +22,8 @@ D(9) KM_IRQ0, |
1117 | D(10) KM_IRQ1, | |
1118 | D(11) KM_SOFTIRQ0, | |
1119 | D(12) KM_SOFTIRQ1, | |
1120 | -D(13) KM_TYPE_NR | |
1121 | +D(13) KM_CLEARPAGE, | |
1122 | +D(14) KM_TYPE_NR | |
1123 | }; | |
1124 | ||
1125 | #undef D | |
de855c5d AM |
1126 | diff -urNp linux-2.6.29.6/arch/parisc/include/asm/pgtable.h linux-2.6.29.6/arch/parisc/include/asm/pgtable.h |
1127 | --- linux-2.6.29.6/arch/parisc/include/asm/pgtable.h 2009-07-02 19:41:20.000000000 -0400 | |
1128 | +++ linux-2.6.29.6/arch/parisc/include/asm/pgtable.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1129 | @@ -202,6 +202,17 @@ |
1130 | #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED) | |
1131 | #define PAGE_COPY PAGE_EXECREAD | |
1132 | #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED) | |
1133 | + | |
1134 | +#ifdef CONFIG_PAX_PAGEEXEC | |
1135 | +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED) | |
1136 | +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED) | |
1137 | +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED) | |
1138 | +#else | |
1139 | +# define PAGE_SHARED_NOEXEC PAGE_SHARED | |
1140 | +# define PAGE_COPY_NOEXEC PAGE_COPY | |
1141 | +# define PAGE_READONLY_NOEXEC PAGE_READONLY | |
1142 | +#endif | |
1143 | + | |
1144 | #define PAGE_KERNEL __pgprot(_PAGE_KERNEL) | |
1145 | #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE) | |
1146 | #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE) | |
de855c5d AM |
1147 | diff -urNp linux-2.6.29.6/arch/parisc/kernel/module.c linux-2.6.29.6/arch/parisc/kernel/module.c |
1148 | --- linux-2.6.29.6/arch/parisc/kernel/module.c 2009-07-02 19:41:20.000000000 -0400 | |
1149 | +++ linux-2.6.29.6/arch/parisc/kernel/module.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1150 | @@ -93,16 +93,38 @@ |
1151 | ||
1152 | /* three functions to determine where in the module core | |
1153 | * or init pieces the location is */ | |
1154 | +static inline int in_init_rx(struct module *me, void *loc) | |
1155 | +{ | |
1156 | + return (loc >= me->module_init_rx && | |
1157 | + loc < (me->module_init_rx + me->init_size_rx)); | |
1158 | +} | |
1159 | + | |
1160 | +static inline int in_init_rw(struct module *me, void *loc) | |
1161 | +{ | |
1162 | + return (loc >= me->module_init_rw && | |
1163 | + loc < (me->module_init_rw + me->init_size_rw)); | |
1164 | +} | |
1165 | + | |
1166 | static inline int in_init(struct module *me, void *loc) | |
1167 | { | |
1168 | - return (loc >= me->module_init && | |
1169 | - loc <= (me->module_init + me->init_size)); | |
1170 | + return in_init_rx(me, loc) || in_init_rw(me, loc); | |
1171 | +} | |
1172 | + | |
1173 | +static inline int in_core_rx(struct module *me, void *loc) | |
1174 | +{ | |
1175 | + return (loc >= me->module_core_rx && | |
1176 | + loc < (me->module_core_rx + me->core_size_rx)); | |
1177 | +} | |
1178 | + | |
1179 | +static inline int in_core_rw(struct module *me, void *loc) | |
1180 | +{ | |
1181 | + return (loc >= me->module_core_rw && | |
1182 | + loc < (me->module_core_rw + me->core_size_rw)); | |
1183 | } | |
1184 | ||
1185 | static inline int in_core(struct module *me, void *loc) | |
1186 | { | |
1187 | - return (loc >= me->module_core && | |
1188 | - loc <= (me->module_core + me->core_size)); | |
1189 | + return in_core_rx(me, loc) || in_core_rw(me, loc); | |
1190 | } | |
1191 | ||
1192 | static inline int in_local(struct module *me, void *loc) | |
1193 | @@ -340,13 +362,13 @@ int module_frob_arch_sections(CONST Elf_ | |
1194 | } | |
1195 | ||
1196 | /* align things a bit */ | |
1197 | - me->core_size = ALIGN(me->core_size, 16); | |
1198 | - me->arch.got_offset = me->core_size; | |
1199 | - me->core_size += gots * sizeof(struct got_entry); | |
1200 | - | |
1201 | - me->core_size = ALIGN(me->core_size, 16); | |
1202 | - me->arch.fdesc_offset = me->core_size; | |
1203 | - me->core_size += fdescs * sizeof(Elf_Fdesc); | |
1204 | + me->core_size_rw = ALIGN(me->core_size_rw, 16); | |
1205 | + me->arch.got_offset = me->core_size_rw; | |
1206 | + me->core_size_rw += gots * sizeof(struct got_entry); | |
1207 | + | |
1208 | + me->core_size_rw = ALIGN(me->core_size_rw, 16); | |
1209 | + me->arch.fdesc_offset = me->core_size_rw; | |
1210 | + me->core_size_rw += fdescs * sizeof(Elf_Fdesc); | |
1211 | ||
1212 | me->arch.got_max = gots; | |
1213 | me->arch.fdesc_max = fdescs; | |
1214 | @@ -364,7 +386,7 @@ static Elf64_Word get_got(struct module | |
1215 | ||
1216 | BUG_ON(value == 0); | |
1217 | ||
1218 | - got = me->module_core + me->arch.got_offset; | |
1219 | + got = me->module_core_rw + me->arch.got_offset; | |
1220 | for (i = 0; got[i].addr; i++) | |
1221 | if (got[i].addr == value) | |
1222 | goto out; | |
1223 | @@ -382,7 +404,7 @@ static Elf64_Word get_got(struct module | |
1224 | #ifdef CONFIG_64BIT | |
1225 | static Elf_Addr get_fdesc(struct module *me, unsigned long value) | |
1226 | { | |
1227 | - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset; | |
1228 | + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset; | |
1229 | ||
1230 | if (!value) { | |
1231 | printk(KERN_ERR "%s: zero OPD requested!\n", me->name); | |
1232 | @@ -400,7 +422,7 @@ static Elf_Addr get_fdesc(struct module | |
1233 | ||
1234 | /* Create new one */ | |
1235 | fdesc->addr = value; | |
1236 | - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset; | |
1237 | + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset; | |
1238 | return (Elf_Addr)fdesc; | |
1239 | } | |
1240 | #endif /* CONFIG_64BIT */ | |
1241 | @@ -816,7 +838,7 @@ register_unwind_table(struct module *me, | |
1242 | ||
1243 | table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr; | |
1244 | end = table + sechdrs[me->arch.unwind_section].sh_size; | |
1245 | - gp = (Elf_Addr)me->module_core + me->arch.got_offset; | |
1246 | + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset; | |
1247 | ||
1248 | DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n", | |
1249 | me->arch.unwind_section, table, end, gp); | |
de855c5d AM |
1250 | diff -urNp linux-2.6.29.6/arch/parisc/kernel/sys_parisc.c linux-2.6.29.6/arch/parisc/kernel/sys_parisc.c |
1251 | --- linux-2.6.29.6/arch/parisc/kernel/sys_parisc.c 2009-07-02 19:41:20.000000000 -0400 | |
1252 | +++ linux-2.6.29.6/arch/parisc/kernel/sys_parisc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1253 | @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str |
1254 | if (flags & MAP_FIXED) | |
1255 | return addr; | |
1256 | if (!addr) | |
1257 | - addr = TASK_UNMAPPED_BASE; | |
1258 | + addr = current->mm->mmap_base; | |
1259 | ||
1260 | if (filp) { | |
1261 | addr = get_shared_area(filp->f_mapping, addr, len, pgoff); | |
de855c5d AM |
1262 | diff -urNp linux-2.6.29.6/arch/parisc/kernel/traps.c linux-2.6.29.6/arch/parisc/kernel/traps.c |
1263 | --- linux-2.6.29.6/arch/parisc/kernel/traps.c 2009-07-02 19:41:20.000000000 -0400 | |
1264 | +++ linux-2.6.29.6/arch/parisc/kernel/traps.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1265 | @@ -731,9 +731,7 @@ void handle_interruption(int code, struc |
1266 | ||
1267 | down_read(¤t->mm->mmap_sem); | |
1268 | vma = find_vma(current->mm,regs->iaoq[0]); | |
1269 | - if (vma && (regs->iaoq[0] >= vma->vm_start) | |
1270 | - && (vma->vm_flags & VM_EXEC)) { | |
1271 | - | |
1272 | + if (vma && (regs->iaoq[0] >= vma->vm_start)) { | |
1273 | fault_address = regs->iaoq[0]; | |
1274 | fault_space = regs->iasq[0]; | |
1275 | ||
de855c5d AM |
1276 | diff -urNp linux-2.6.29.6/arch/parisc/mm/fault.c linux-2.6.29.6/arch/parisc/mm/fault.c |
1277 | --- linux-2.6.29.6/arch/parisc/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
1278 | +++ linux-2.6.29.6/arch/parisc/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1279 | @@ -16,6 +16,7 @@ |
1280 | #include <linux/sched.h> | |
1281 | #include <linux/interrupt.h> | |
1282 | #include <linux/module.h> | |
1283 | +#include <linux/unistd.h> | |
1284 | ||
1285 | #include <asm/uaccess.h> | |
1286 | #include <asm/traps.h> | |
1287 | @@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex | |
1288 | static unsigned long | |
1289 | parisc_acctyp(unsigned long code, unsigned int inst) | |
1290 | { | |
1291 | - if (code == 6 || code == 16) | |
1292 | + if (code == 6 || code == 7 || code == 16) | |
1293 | return VM_EXEC; | |
1294 | ||
1295 | switch (inst & 0xf0000000) { | |
1296 | @@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign | |
1297 | } | |
1298 | #endif | |
1299 | ||
1300 | +#ifdef CONFIG_PAX_PAGEEXEC | |
1301 | +/* | |
1302 | + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address) | |
1303 | + * | |
1304 | + * returns 1 when task should be killed | |
1305 | + * 2 when rt_sigreturn trampoline was detected | |
1306 | + * 3 when unpatched PLT trampoline was detected | |
1307 | + */ | |
1308 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
1309 | +{ | |
1310 | + | |
1311 | +#ifdef CONFIG_PAX_EMUPLT | |
1312 | + int err; | |
1313 | + | |
1314 | + do { /* PaX: unpatched PLT emulation */ | |
1315 | + unsigned int bl, depwi; | |
1316 | + | |
1317 | + err = get_user(bl, (unsigned int *)instruction_pointer(regs)); | |
1318 | + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4)); | |
1319 | + | |
1320 | + if (err) | |
1321 | + break; | |
1322 | + | |
1323 | + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) { | |
1324 | + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12; | |
1325 | + | |
1326 | + err = get_user(ldw, (unsigned int *)addr); | |
1327 | + err |= get_user(bv, (unsigned int *)(addr+4)); | |
1328 | + err |= get_user(ldw2, (unsigned int *)(addr+8)); | |
1329 | + | |
1330 | + if (err) | |
1331 | + break; | |
1332 | + | |
1333 | + if (ldw == 0x0E801096U && | |
1334 | + bv == 0xEAC0C000U && | |
1335 | + ldw2 == 0x0E881095U) | |
1336 | + { | |
1337 | + unsigned int resolver, map; | |
1338 | + | |
1339 | + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8)); | |
1340 | + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12)); | |
1341 | + if (err) | |
1342 | + break; | |
1343 | + | |
1344 | + regs->gr[20] = instruction_pointer(regs)+8; | |
1345 | + regs->gr[21] = map; | |
1346 | + regs->gr[22] = resolver; | |
1347 | + regs->iaoq[0] = resolver | 3UL; | |
1348 | + regs->iaoq[1] = regs->iaoq[0] + 4; | |
1349 | + return 3; | |
1350 | + } | |
1351 | + } | |
1352 | + } while (0); | |
1353 | +#endif | |
1354 | + | |
1355 | +#ifdef CONFIG_PAX_EMUTRAMP | |
1356 | + | |
1357 | +#ifndef CONFIG_PAX_EMUSIGRT | |
1358 | + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP)) | |
1359 | + return 1; | |
1360 | +#endif | |
1361 | + | |
1362 | + do { /* PaX: rt_sigreturn emulation */ | |
1363 | + unsigned int ldi1, ldi2, bel, nop; | |
1364 | + | |
1365 | + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs)); | |
1366 | + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4)); | |
1367 | + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8)); | |
1368 | + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12)); | |
1369 | + | |
1370 | + if (err) | |
1371 | + break; | |
1372 | + | |
1373 | + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) && | |
1374 | + ldi2 == 0x3414015AU && | |
1375 | + bel == 0xE4008200U && | |
1376 | + nop == 0x08000240U) | |
1377 | + { | |
1378 | + regs->gr[25] = (ldi1 & 2) >> 1; | |
1379 | + regs->gr[20] = __NR_rt_sigreturn; | |
1380 | + regs->gr[31] = regs->iaoq[1] + 16; | |
1381 | + regs->sr[0] = regs->iasq[1]; | |
1382 | + regs->iaoq[0] = 0x100UL; | |
1383 | + regs->iaoq[1] = regs->iaoq[0] + 4; | |
1384 | + regs->iasq[0] = regs->sr[2]; | |
1385 | + regs->iasq[1] = regs->sr[2]; | |
1386 | + return 2; | |
1387 | + } | |
1388 | + } while (0); | |
1389 | +#endif | |
1390 | + | |
1391 | + return 1; | |
1392 | +} | |
1393 | + | |
1394 | +void pax_report_insns(void *pc, void *sp) | |
1395 | +{ | |
1396 | + unsigned long i; | |
1397 | + | |
1398 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
1399 | + for (i = 0; i < 5; i++) { | |
1400 | + unsigned int c; | |
1401 | + if (get_user(c, (unsigned int *)pc+i)) | |
1402 | + printk(KERN_CONT "???????? "); | |
1403 | + else | |
1404 | + printk(KERN_CONT "%08x ", c); | |
1405 | + } | |
1406 | + printk("\n"); | |
1407 | +} | |
1408 | +#endif | |
1409 | + | |
1410 | int fixup_exception(struct pt_regs *regs) | |
1411 | { | |
1412 | const struct exception_table_entry *fix; | |
1413 | @@ -193,8 +304,33 @@ good_area: | |
1414 | ||
1415 | acc_type = parisc_acctyp(code,regs->iir); | |
1416 | ||
1417 | - if ((vma->vm_flags & acc_type) != acc_type) | |
1418 | + if ((vma->vm_flags & acc_type) != acc_type) { | |
1419 | + | |
1420 | +#ifdef CONFIG_PAX_PAGEEXEC | |
1421 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) && | |
1422 | + (address & ~3UL) == instruction_pointer(regs)) | |
1423 | + { | |
1424 | + up_read(&mm->mmap_sem); | |
1425 | + switch (pax_handle_fetch_fault(regs)) { | |
1426 | + | |
1427 | +#ifdef CONFIG_PAX_EMUPLT | |
1428 | + case 3: | |
1429 | + return; | |
1430 | +#endif | |
1431 | + | |
1432 | +#ifdef CONFIG_PAX_EMUTRAMP | |
1433 | + case 2: | |
1434 | + return; | |
1435 | +#endif | |
1436 | + | |
1437 | + } | |
1438 | + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]); | |
1439 | + do_group_exit(SIGKILL); | |
1440 | + } | |
1441 | +#endif | |
1442 | + | |
1443 | goto bad_area; | |
1444 | + } | |
1445 | ||
1446 | /* | |
1447 | * If for any reason at all we couldn't handle the fault, make | |
de855c5d AM |
1448 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/atomic.h linux-2.6.29.6/arch/powerpc/include/asm/atomic.h |
1449 | --- linux-2.6.29.6/arch/powerpc/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
1450 | +++ linux-2.6.29.6/arch/powerpc/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
1451 | @@ -244,6 +244,10 @@ static __inline__ int atomic_dec_if_posi | |
1452 | return t; | |
1453 | } | |
1454 | ||
1455 | +#define atomic_inc_unchecked(v) atomic_inc((v)) | |
1456 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
1457 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
1458 | + | |
1459 | #define smp_mb__before_atomic_dec() smp_mb() | |
1460 | #define smp_mb__after_atomic_dec() smp_mb() | |
1461 | #define smp_mb__before_atomic_inc() smp_mb() | |
1462 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/elf.h linux-2.6.29.6/arch/powerpc/include/asm/elf.h | |
1463 | --- linux-2.6.29.6/arch/powerpc/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
1464 | +++ linux-2.6.29.6/arch/powerpc/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1465 | @@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E |
1466 | ||
1467 | #define ELF_ET_DYN_BASE (0x20000000) | |
1468 | ||
1469 | +#ifdef CONFIG_PAX_ASLR | |
1470 | +#define PAX_ELF_ET_DYN_BASE (0x10000000UL) | |
1471 | + | |
1472 | +#ifdef __powerpc64__ | |
1473 | +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28) | |
1474 | +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28) | |
1475 | +#else | |
1476 | +#define PAX_DELTA_MMAP_LEN 15 | |
1477 | +#define PAX_DELTA_STACK_LEN 15 | |
1478 | +#endif | |
1479 | +#endif | |
1480 | + | |
1481 | /* | |
1482 | * Our registers are always unsigned longs, whether we're a 32 bit | |
1483 | * process or 64 bit, on either a 64 bit or 32 bit kernel. | |
de855c5d AM |
1484 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/kmap_types.h linux-2.6.29.6/arch/powerpc/include/asm/kmap_types.h |
1485 | --- linux-2.6.29.6/arch/powerpc/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
1486 | +++ linux-2.6.29.6/arch/powerpc/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1487 | @@ -26,6 +26,7 @@ enum km_type { |
1488 | KM_SOFTIRQ1, | |
1489 | KM_PPC_SYNC_PAGE, | |
1490 | KM_PPC_SYNC_ICACHE, | |
1491 | + KM_CLEARPAGE, | |
1492 | KM_TYPE_NR | |
1493 | }; | |
1494 | ||
de855c5d AM |
1495 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/page_64.h linux-2.6.29.6/arch/powerpc/include/asm/page_64.h |
1496 | --- linux-2.6.29.6/arch/powerpc/include/asm/page_64.h 2009-07-02 19:41:20.000000000 -0400 | |
1497 | +++ linux-2.6.29.6/arch/powerpc/include/asm/page_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1498 | @@ -170,15 +170,18 @@ do { \ |
1499 | * stack by default, so in the absense of a PT_GNU_STACK program header | |
1500 | * we turn execute permission off. | |
1501 | */ | |
1502 | -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \ | |
1503 | - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
1504 | +#define VM_STACK_DEFAULT_FLAGS32 \ | |
1505 | + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \ | |
1506 | + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
1507 | ||
1508 | #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \ | |
1509 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
1510 | ||
1511 | +#ifndef CONFIG_PAX_PAGEEXEC | |
1512 | #define VM_STACK_DEFAULT_FLAGS \ | |
1513 | (test_thread_flag(TIF_32BIT) ? \ | |
1514 | VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64) | |
1515 | +#endif | |
1516 | ||
1517 | #include <asm-generic/page.h> | |
1518 | ||
de855c5d AM |
1519 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/page.h linux-2.6.29.6/arch/powerpc/include/asm/page.h |
1520 | --- linux-2.6.29.6/arch/powerpc/include/asm/page.h 2009-07-02 19:41:20.000000000 -0400 | |
1521 | +++ linux-2.6.29.6/arch/powerpc/include/asm/page.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1522 | @@ -114,8 +114,9 @@ extern phys_addr_t kernstart_addr; |
1523 | * and needs to be executable. This means the whole heap ends | |
1524 | * up being executable. | |
1525 | */ | |
1526 | -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \ | |
1527 | - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
1528 | +#define VM_DATA_DEFAULT_FLAGS32 \ | |
1529 | + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \ | |
1530 | + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
1531 | ||
1532 | #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \ | |
1533 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | |
de855c5d AM |
1534 | diff -urNp linux-2.6.29.6/arch/powerpc/include/asm/uaccess.h linux-2.6.29.6/arch/powerpc/include/asm/uaccess.h |
1535 | --- linux-2.6.29.6/arch/powerpc/include/asm/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
1536 | +++ linux-2.6.29.6/arch/powerpc/include/asm/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
1537 | @@ -334,6 +334,9 @@ static inline unsigned long copy_from_us | |
1538 | { | |
1539 | unsigned long over; | |
1540 | ||
1541 | + if (((long)n < 0) || (n > INT_MAX)) | |
1542 | + return n; | |
1543 | + | |
1544 | if (access_ok(VERIFY_READ, from, n)) | |
1545 | return __copy_tofrom_user((__force void __user *)to, from, n); | |
1546 | if ((unsigned long)from < TASK_SIZE) { | |
1547 | @@ -349,6 +352,9 @@ static inline unsigned long copy_to_user | |
1548 | { | |
1549 | unsigned long over; | |
1550 | ||
1551 | + if (((long)n < 0) || (n > INT_MAX)) | |
1552 | + return n; | |
1553 | + | |
1554 | if (access_ok(VERIFY_WRITE, to, n)) | |
1555 | return __copy_tofrom_user(to, (__force void __user *)from, n); | |
1556 | if ((unsigned long)to < TASK_SIZE) { | |
1557 | diff -urNp linux-2.6.29.6/arch/powerpc/kernel/module_32.c linux-2.6.29.6/arch/powerpc/kernel/module_32.c | |
1558 | --- linux-2.6.29.6/arch/powerpc/kernel/module_32.c 2009-07-02 19:41:20.000000000 -0400 | |
1559 | +++ linux-2.6.29.6/arch/powerpc/kernel/module_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1560 | @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr |
1561 | me->arch.core_plt_section = i; | |
1562 | } | |
1563 | if (!me->arch.core_plt_section || !me->arch.init_plt_section) { | |
1564 | - printk("Module doesn't contain .plt or .init.plt sections.\n"); | |
1565 | + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name); | |
1566 | return -ENOEXEC; | |
1567 | } | |
1568 | ||
1569 | @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati | |
1570 | ||
1571 | DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location); | |
1572 | /* Init, or core PLT? */ | |
1573 | - if (location >= mod->module_core | |
1574 | - && location < mod->module_core + mod->core_size) | |
1575 | + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) || | |
1576 | + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw)) | |
1577 | entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr; | |
1578 | - else | |
1579 | + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) || | |
1580 | + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw)) | |
1581 | entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr; | |
1582 | + else { | |
1583 | + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name); | |
1584 | + return ~0UL; | |
1585 | + } | |
1586 | ||
1587 | /* Find this entry, or if that fails, the next avail. entry */ | |
1588 | while (entry->jump[0]) { | |
de855c5d AM |
1589 | diff -urNp linux-2.6.29.6/arch/powerpc/kernel/signal_32.c linux-2.6.29.6/arch/powerpc/kernel/signal_32.c |
1590 | --- linux-2.6.29.6/arch/powerpc/kernel/signal_32.c 2009-07-02 19:41:20.000000000 -0400 | |
1591 | +++ linux-2.6.29.6/arch/powerpc/kernel/signal_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1592 | @@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig |
1593 | /* Save user registers on the stack */ | |
1594 | frame = &rt_sf->uc.uc_mcontext; | |
1595 | addr = frame; | |
1596 | - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) { | |
1597 | + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) { | |
1598 | if (save_user_regs(regs, frame, 0, 1)) | |
1599 | goto badframe; | |
1600 | regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp; | |
de855c5d AM |
1601 | diff -urNp linux-2.6.29.6/arch/powerpc/kernel/signal_64.c linux-2.6.29.6/arch/powerpc/kernel/signal_64.c |
1602 | --- linux-2.6.29.6/arch/powerpc/kernel/signal_64.c 2009-07-02 19:41:20.000000000 -0400 | |
1603 | +++ linux-2.6.29.6/arch/powerpc/kernel/signal_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1604 | @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct |
1605 | current->thread.fpscr.val = 0; | |
1606 | ||
1607 | /* Set up to return from userspace. */ | |
1608 | - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) { | |
1609 | + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) { | |
1610 | regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp; | |
1611 | } else { | |
1612 | err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]); | |
de855c5d AM |
1613 | diff -urNp linux-2.6.29.6/arch/powerpc/kernel/vdso.c linux-2.6.29.6/arch/powerpc/kernel/vdso.c |
1614 | --- linux-2.6.29.6/arch/powerpc/kernel/vdso.c 2009-07-02 19:41:20.000000000 -0400 | |
1615 | +++ linux-2.6.29.6/arch/powerpc/kernel/vdso.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1616 | @@ -211,7 +211,7 @@ int arch_setup_additional_pages(struct l |
1617 | vdso_base = VDSO32_MBASE; | |
1618 | #endif | |
1619 | ||
1620 | - current->mm->context.vdso_base = 0; | |
1621 | + current->mm->context.vdso_base = ~0UL; | |
1622 | ||
1623 | /* vDSO has a problem and was disabled, just don't "enable" it for the | |
1624 | * process | |
1625 | @@ -228,7 +228,7 @@ int arch_setup_additional_pages(struct l | |
1626 | */ | |
1627 | down_write(&mm->mmap_sem); | |
1628 | vdso_base = get_unmapped_area(NULL, vdso_base, | |
1629 | - vdso_pages << PAGE_SHIFT, 0, 0); | |
1630 | + vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE); | |
1631 | if (IS_ERR_VALUE(vdso_base)) { | |
1632 | rc = vdso_base; | |
1633 | goto fail_mmapsem; | |
de855c5d AM |
1634 | diff -urNp linux-2.6.29.6/arch/powerpc/lib/usercopy_64.c linux-2.6.29.6/arch/powerpc/lib/usercopy_64.c |
1635 | --- linux-2.6.29.6/arch/powerpc/lib/usercopy_64.c 2009-07-02 19:41:20.000000000 -0400 | |
1636 | +++ linux-2.6.29.6/arch/powerpc/lib/usercopy_64.c 2009-07-09 22:13:39.000000000 -0400 | |
1637 | @@ -11,6 +11,9 @@ | |
1638 | ||
1639 | unsigned long copy_from_user(void *to, const void __user *from, unsigned long n) | |
1640 | { | |
1641 | + if (unlikely(((long)n < 0) || (n > INT_MAX))) | |
1642 | + return n; | |
1643 | + | |
1644 | if (likely(access_ok(VERIFY_READ, from, n))) | |
1645 | n = __copy_from_user(to, from, n); | |
1646 | else | |
1647 | @@ -20,6 +23,9 @@ unsigned long copy_from_user(void *to, c | |
1648 | ||
1649 | unsigned long copy_to_user(void __user *to, const void *from, unsigned long n) | |
1650 | { | |
1651 | + if (unlikely(((long)n < 0) || (n > INT_MAX))) | |
1652 | + return n; | |
1653 | + | |
1654 | if (likely(access_ok(VERIFY_WRITE, to, n))) | |
1655 | n = __copy_to_user(to, from, n); | |
1656 | return n; | |
1657 | diff -urNp linux-2.6.29.6/arch/powerpc/mm/fault.c linux-2.6.29.6/arch/powerpc/mm/fault.c | |
1658 | --- linux-2.6.29.6/arch/powerpc/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
1659 | +++ linux-2.6.29.6/arch/powerpc/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
1660 | @@ -29,6 +29,10 @@ |
1661 | #include <linux/module.h> | |
1662 | #include <linux/kprobes.h> | |
1663 | #include <linux/kdebug.h> | |
1664 | +#include <linux/slab.h> | |
1665 | +#include <linux/pagemap.h> | |
1666 | +#include <linux/compiler.h> | |
1667 | +#include <linux/unistd.h> | |
1668 | ||
1669 | #include <asm/firmware.h> | |
1670 | #include <asm/page.h> | |
1671 | @@ -63,6 +67,363 @@ static inline int notify_page_fault(stru | |
1672 | } | |
1673 | #endif | |
1674 | ||
1675 | +#ifdef CONFIG_PAX_EMUSIGRT | |
1676 | +void pax_syscall_close(struct vm_area_struct *vma) | |
1677 | +{ | |
1678 | + vma->vm_mm->call_syscall = 0UL; | |
1679 | +} | |
1680 | + | |
1681 | +static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |
1682 | +{ | |
1683 | + unsigned int *kaddr; | |
1684 | + | |
1685 | + vmf->page = alloc_page(GFP_HIGHUSER); | |
1686 | + if (!vmf->page) | |
1687 | + return VM_FAULT_OOM; | |
1688 | + | |
1689 | + kaddr = kmap(vmf->page); | |
1690 | + memset(kaddr, 0, PAGE_SIZE); | |
1691 | + kaddr[0] = 0x44000002U; /* sc */ | |
1692 | + __flush_dcache_icache(kaddr); | |
1693 | + kunmap(vmf->page); | |
1694 | + return VM_FAULT_MAJOR; | |
1695 | +} | |
1696 | + | |
1697 | +static struct vm_operations_struct pax_vm_ops = { | |
1698 | + .close = pax_syscall_close, | |
1699 | + .fault = pax_syscall_fault | |
1700 | +}; | |
1701 | + | |
1702 | +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr) | |
1703 | +{ | |
1704 | + int ret; | |
1705 | + | |
1706 | + vma->vm_mm = current->mm; | |
1707 | + vma->vm_start = addr; | |
1708 | + vma->vm_end = addr + PAGE_SIZE; | |
1709 | + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC; | |
1710 | + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
1711 | + vma->vm_ops = &pax_vm_ops; | |
1712 | + | |
1713 | + ret = insert_vm_struct(current->mm, vma); | |
1714 | + if (ret) | |
1715 | + return ret; | |
1716 | + | |
1717 | + ++current->mm->total_vm; | |
1718 | + return 0; | |
1719 | +} | |
1720 | +#endif | |
1721 | + | |
1722 | +#ifdef CONFIG_PAX_PAGEEXEC | |
1723 | +/* | |
1724 | + * PaX: decide what to do with offenders (regs->nip = fault address) | |
1725 | + * | |
1726 | + * returns 1 when task should be killed | |
1727 | + * 2 when patched GOT trampoline was detected | |
1728 | + * 3 when patched PLT trampoline was detected | |
1729 | + * 4 when unpatched PLT trampoline was detected | |
1730 | + * 5 when sigreturn trampoline was detected | |
1731 | + * 6 when rt_sigreturn trampoline was detected | |
1732 | + */ | |
1733 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
1734 | +{ | |
1735 | + | |
1736 | +#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT) | |
1737 | + int err; | |
1738 | +#endif | |
1739 | + | |
1740 | +#ifdef CONFIG_PAX_EMUPLT | |
1741 | + do { /* PaX: patched GOT emulation */ | |
1742 | + unsigned int blrl; | |
1743 | + | |
1744 | + err = get_user(blrl, (unsigned int *)regs->nip); | |
1745 | + | |
1746 | + if (!err && blrl == 0x4E800021U) { | |
1747 | + unsigned long temp = regs->nip; | |
1748 | + | |
1749 | + regs->nip = regs->link & 0xFFFFFFFCUL; | |
1750 | + regs->link = temp + 4UL; | |
1751 | + return 2; | |
1752 | + } | |
1753 | + } while (0); | |
1754 | + | |
1755 | + do { /* PaX: patched PLT emulation #1 */ | |
1756 | + unsigned int b; | |
1757 | + | |
1758 | + err = get_user(b, (unsigned int *)regs->nip); | |
1759 | + | |
1760 | + if (!err && (b & 0xFC000003U) == 0x48000000U) { | |
1761 | + regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL); | |
1762 | + return 3; | |
1763 | + } | |
1764 | + } while (0); | |
1765 | + | |
1766 | + do { /* PaX: unpatched PLT emulation #1 */ | |
1767 | + unsigned int li, b; | |
1768 | + | |
1769 | + err = get_user(li, (unsigned int *)regs->nip); | |
1770 | + err |= get_user(b, (unsigned int *)(regs->nip+4)); | |
1771 | + | |
1772 | + if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) { | |
1773 | + unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr; | |
1774 | + unsigned long addr = b | 0xFC000000UL; | |
1775 | + | |
1776 | + addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL); | |
1777 | + err = get_user(rlwinm, (unsigned int *)addr); | |
1778 | + err |= get_user(add, (unsigned int *)(addr+4)); | |
1779 | + err |= get_user(li2, (unsigned int *)(addr+8)); | |
1780 | + err |= get_user(addis2, (unsigned int *)(addr+12)); | |
1781 | + err |= get_user(mtctr, (unsigned int *)(addr+16)); | |
1782 | + err |= get_user(li3, (unsigned int *)(addr+20)); | |
1783 | + err |= get_user(addis3, (unsigned int *)(addr+24)); | |
1784 | + err |= get_user(bctr, (unsigned int *)(addr+28)); | |
1785 | + | |
1786 | + if (err) | |
1787 | + break; | |
1788 | + | |
1789 | + if (rlwinm == 0x556C083CU && | |
1790 | + add == 0x7D6C5A14U && | |
1791 | + (li2 & 0xFFFF0000U) == 0x39800000U && | |
1792 | + (addis2 & 0xFFFF0000U) == 0x3D8C0000U && | |
1793 | + mtctr == 0x7D8903A6U && | |
1794 | + (li3 & 0xFFFF0000U) == 0x39800000U && | |
1795 | + (addis3 & 0xFFFF0000U) == 0x3D8C0000U && | |
1796 | + bctr == 0x4E800420U) | |
1797 | + { | |
1798 | + regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1799 | + regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1800 | + regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16; | |
1801 | + regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1802 | + regs->ctr += (addis2 & 0xFFFFU) << 16; | |
1803 | + regs->nip = regs->ctr; | |
1804 | + return 4; | |
1805 | + } | |
1806 | + } | |
1807 | + } while (0); | |
1808 | + | |
1809 | +#if 0 | |
1810 | + do { /* PaX: unpatched PLT emulation #2 */ | |
1811 | + unsigned int lis, lwzu, b, bctr; | |
1812 | + | |
1813 | + err = get_user(lis, (unsigned int *)regs->nip); | |
1814 | + err |= get_user(lwzu, (unsigned int *)(regs->nip+4)); | |
1815 | + err |= get_user(b, (unsigned int *)(regs->nip+8)); | |
1816 | + err |= get_user(bctr, (unsigned int *)(regs->nip+12)); | |
1817 | + | |
1818 | + if (err) | |
1819 | + break; | |
1820 | + | |
1821 | + if ((lis & 0xFFFF0000U) == 0x39600000U && | |
1822 | + (lwzu & 0xU) == 0xU && | |
1823 | + (b & 0xFC000003U) == 0x48000000U && | |
1824 | + bctr == 0x4E800420U) | |
1825 | + { | |
1826 | + unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr; | |
1827 | + unsigned long addr = b | 0xFC000000UL; | |
1828 | + | |
1829 | + addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL); | |
1830 | + err = get_user(addis, (unsigned int *)addr); | |
1831 | + err |= get_user(addi, (unsigned int *)(addr+4)); | |
1832 | + err |= get_user(rlwinm, (unsigned int *)(addr+8)); | |
1833 | + err |= get_user(add, (unsigned int *)(addr+12)); | |
1834 | + err |= get_user(li2, (unsigned int *)(addr+16)); | |
1835 | + err |= get_user(addis2, (unsigned int *)(addr+20)); | |
1836 | + err |= get_user(mtctr, (unsigned int *)(addr+24)); | |
1837 | + err |= get_user(li3, (unsigned int *)(addr+28)); | |
1838 | + err |= get_user(addis3, (unsigned int *)(addr+32)); | |
1839 | + err |= get_user(bctr, (unsigned int *)(addr+36)); | |
1840 | + | |
1841 | + if (err) | |
1842 | + break; | |
1843 | + | |
1844 | + if ((addis & 0xFFFF0000U) == 0x3D6B0000U && | |
1845 | + (addi & 0xFFFF0000U) == 0x396B0000U && | |
1846 | + rlwinm == 0x556C083CU && | |
1847 | + add == 0x7D6C5A14U && | |
1848 | + (li2 & 0xFFFF0000U) == 0x39800000U && | |
1849 | + (addis2 & 0xFFFF0000U) == 0x3D8C0000U && | |
1850 | + mtctr == 0x7D8903A6U && | |
1851 | + (li3 & 0xFFFF0000U) == 0x39800000U && | |
1852 | + (addis3 & 0xFFFF0000U) == 0x3D8C0000U && | |
1853 | + bctr == 0x4E800420U) | |
1854 | + { | |
1855 | + regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1856 | + regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1857 | + regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16; | |
1858 | + regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1859 | + regs->ctr += (addis2 & 0xFFFFU) << 16; | |
1860 | + regs->nip = regs->ctr; | |
1861 | + return 4; | |
1862 | + } | |
1863 | + } | |
1864 | + } while (0); | |
1865 | +#endif | |
1866 | + | |
1867 | + do { /* PaX: unpatched PLT emulation #3 */ | |
1868 | + unsigned int li, b; | |
1869 | + | |
1870 | + err = get_user(li, (unsigned int *)regs->nip); | |
1871 | + err |= get_user(b, (unsigned int *)(regs->nip+4)); | |
1872 | + | |
1873 | + if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) { | |
1874 | + unsigned int addis, lwz, mtctr, bctr; | |
1875 | + unsigned long addr = b | 0xFC000000UL; | |
1876 | + | |
1877 | + addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL); | |
1878 | + err = get_user(addis, (unsigned int *)addr); | |
1879 | + err |= get_user(lwz, (unsigned int *)(addr+4)); | |
1880 | + err |= get_user(mtctr, (unsigned int *)(addr+8)); | |
1881 | + err |= get_user(bctr, (unsigned int *)(addr+12)); | |
1882 | + | |
1883 | + if (err) | |
1884 | + break; | |
1885 | + | |
1886 | + if ((addis & 0xFFFF0000U) == 0x3D6B0000U && | |
1887 | + (lwz & 0xFFFF0000U) == 0x816B0000U && | |
1888 | + mtctr == 0x7D6903A6U && | |
1889 | + bctr == 0x4E800420U) | |
1890 | + { | |
1891 | + unsigned int r11; | |
1892 | + | |
1893 | + addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1894 | + addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL); | |
1895 | + | |
1896 | + err = get_user(r11, (unsigned int *)addr); | |
1897 | + if (err) | |
1898 | + break; | |
1899 | + | |
1900 | + regs->gpr[PT_R11] = r11; | |
1901 | + regs->ctr = r11; | |
1902 | + regs->nip = r11; | |
1903 | + return 4; | |
1904 | + } | |
1905 | + } | |
1906 | + } while (0); | |
1907 | +#endif | |
1908 | + | |
1909 | +#ifdef CONFIG_PAX_EMUSIGRT | |
1910 | + do { /* PaX: sigreturn emulation */ | |
1911 | + unsigned int li, sc; | |
1912 | + | |
1913 | + err = get_user(li, (unsigned int *)regs->nip); | |
1914 | + err |= get_user(sc, (unsigned int *)(regs->nip+4)); | |
1915 | + | |
1916 | + if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) { | |
1917 | + struct vm_area_struct *vma; | |
1918 | + unsigned long call_syscall; | |
1919 | + | |
1920 | + down_read(¤t->mm->mmap_sem); | |
1921 | + call_syscall = current->mm->call_syscall; | |
1922 | + up_read(¤t->mm->mmap_sem); | |
1923 | + if (likely(call_syscall)) | |
1924 | + goto emulate; | |
1925 | + | |
1926 | + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
1927 | + | |
1928 | + down_write(¤t->mm->mmap_sem); | |
1929 | + if (current->mm->call_syscall) { | |
1930 | + call_syscall = current->mm->call_syscall; | |
1931 | + up_write(¤t->mm->mmap_sem); | |
1932 | + if (vma) | |
1933 | + kmem_cache_free(vm_area_cachep, vma); | |
1934 | + goto emulate; | |
1935 | + } | |
1936 | + | |
1937 | + call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE); | |
1938 | + if (!vma || (call_syscall & ~PAGE_MASK)) { | |
1939 | + up_write(¤t->mm->mmap_sem); | |
1940 | + if (vma) | |
1941 | + kmem_cache_free(vm_area_cachep, vma); | |
1942 | + return 1; | |
1943 | + } | |
1944 | + | |
1945 | + if (pax_insert_vma(vma, call_syscall)) { | |
1946 | + up_write(¤t->mm->mmap_sem); | |
1947 | + kmem_cache_free(vm_area_cachep, vma); | |
1948 | + return 1; | |
1949 | + } | |
1950 | + | |
1951 | + current->mm->call_syscall = call_syscall; | |
1952 | + up_write(¤t->mm->mmap_sem); | |
1953 | + | |
1954 | +emulate: | |
1955 | + regs->gpr[PT_R0] = __NR_sigreturn; | |
1956 | + regs->nip = call_syscall; | |
1957 | + return 5; | |
1958 | + } | |
1959 | + } while (0); | |
1960 | + | |
1961 | + do { /* PaX: rt_sigreturn emulation */ | |
1962 | + unsigned int li, sc; | |
1963 | + | |
1964 | + err = get_user(li, (unsigned int *)regs->nip); | |
1965 | + err |= get_user(sc, (unsigned int *)(regs->nip+4)); | |
1966 | + | |
1967 | + if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) { | |
1968 | + struct vm_area_struct *vma; | |
1969 | + unsigned int call_syscall; | |
1970 | + | |
1971 | + down_read(¤t->mm->mmap_sem); | |
1972 | + call_syscall = current->mm->call_syscall; | |
1973 | + up_read(¤t->mm->mmap_sem); | |
1974 | + if (likely(call_syscall)) | |
1975 | + goto rt_emulate; | |
1976 | + | |
1977 | + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
1978 | + | |
1979 | + down_write(¤t->mm->mmap_sem); | |
1980 | + if (current->mm->call_syscall) { | |
1981 | + call_syscall = current->mm->call_syscall; | |
1982 | + up_write(¤t->mm->mmap_sem); | |
1983 | + if (vma) | |
1984 | + kmem_cache_free(vm_area_cachep, vma); | |
1985 | + goto rt_emulate; | |
1986 | + } | |
1987 | + | |
1988 | + call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE); | |
1989 | + if (!vma || (call_syscall & ~PAGE_MASK)) { | |
1990 | + up_write(¤t->mm->mmap_sem); | |
1991 | + if (vma) | |
1992 | + kmem_cache_free(vm_area_cachep, vma); | |
1993 | + return 1; | |
1994 | + } | |
1995 | + | |
1996 | + if (pax_insert_vma(vma, call_syscall)) { | |
1997 | + up_write(¤t->mm->mmap_sem); | |
1998 | + kmem_cache_free(vm_area_cachep, vma); | |
1999 | + return 1; | |
2000 | + } | |
2001 | + | |
2002 | + current->mm->call_syscall = call_syscall; | |
2003 | + up_write(¤t->mm->mmap_sem); | |
2004 | + | |
2005 | +rt_emulate: | |
2006 | + regs->gpr[PT_R0] = __NR_rt_sigreturn; | |
2007 | + regs->nip = call_syscall; | |
2008 | + return 6; | |
2009 | + } | |
2010 | + } while (0); | |
2011 | +#endif | |
2012 | + | |
2013 | + return 1; | |
2014 | +} | |
2015 | + | |
2016 | +void pax_report_insns(void *pc, void *sp) | |
2017 | +{ | |
2018 | + unsigned long i; | |
2019 | + | |
2020 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
2021 | + for (i = 0; i < 5; i++) { | |
2022 | + unsigned int c; | |
2023 | + if (get_user(c, (unsigned int *)pc+i)) | |
2024 | + printk(KERN_CONT "???????? "); | |
2025 | + else | |
2026 | + printk(KERN_CONT "%08x ", c); | |
2027 | + } | |
2028 | + printk("\n"); | |
2029 | +} | |
2030 | +#endif | |
2031 | + | |
2032 | /* | |
2033 | * Check whether the instruction at regs->nip is a store using | |
2034 | * an update addressing form which will update r1. | |
2035 | @@ -133,7 +494,7 @@ int __kprobes do_page_fault(struct pt_re | |
2036 | * indicate errors in DSISR but can validly be set in SRR1. | |
2037 | */ | |
2038 | if (trap == 0x400) | |
2039 | - error_code &= 0x48200000; | |
2040 | + error_code &= 0x58200000; | |
2041 | else | |
2042 | is_write = error_code & DSISR_ISSTORE; | |
2043 | #else | |
2044 | @@ -339,6 +700,37 @@ bad_area: | |
2045 | bad_area_nosemaphore: | |
2046 | /* User mode accesses cause a SIGSEGV */ | |
2047 | if (user_mode(regs)) { | |
2048 | + | |
2049 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2050 | + if (mm->pax_flags & MF_PAX_PAGEEXEC) { | |
2051 | +#ifdef CONFIG_PPC64 | |
2052 | + if (is_exec && (error_code & DSISR_PROTFAULT)) { | |
2053 | +#else | |
2054 | + if (is_exec && regs->nip == address) { | |
2055 | +#endif | |
2056 | + switch (pax_handle_fetch_fault(regs)) { | |
2057 | + | |
2058 | +#ifdef CONFIG_PAX_EMUPLT | |
2059 | + case 2: | |
2060 | + case 3: | |
2061 | + case 4: | |
2062 | + return 0; | |
2063 | +#endif | |
2064 | + | |
2065 | +#ifdef CONFIG_PAX_EMUSIGRT | |
2066 | + case 5: | |
2067 | + case 6: | |
2068 | + return 0; | |
2069 | +#endif | |
2070 | + | |
2071 | + } | |
2072 | + | |
2073 | + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]); | |
2074 | + do_group_exit(SIGKILL); | |
2075 | + } | |
2076 | + } | |
2077 | +#endif | |
2078 | + | |
2079 | _exception(SIGSEGV, regs, code, address); | |
2080 | return 0; | |
2081 | } | |
de855c5d AM |
2082 | diff -urNp linux-2.6.29.6/arch/powerpc/mm/mmap.c linux-2.6.29.6/arch/powerpc/mm/mmap.c |
2083 | --- linux-2.6.29.6/arch/powerpc/mm/mmap.c 2009-07-02 19:41:20.000000000 -0400 | |
2084 | +++ linux-2.6.29.6/arch/powerpc/mm/mmap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2085 | @@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str |
2086 | */ | |
2087 | if (mmap_is_legacy()) { | |
2088 | mm->mmap_base = TASK_UNMAPPED_BASE; | |
2089 | + | |
2090 | +#ifdef CONFIG_PAX_RANDMMAP | |
2091 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
2092 | + mm->mmap_base += mm->delta_mmap; | |
2093 | +#endif | |
2094 | + | |
2095 | mm->get_unmapped_area = arch_get_unmapped_area; | |
2096 | mm->unmap_area = arch_unmap_area; | |
2097 | } else { | |
2098 | mm->mmap_base = mmap_base(); | |
2099 | + | |
2100 | +#ifdef CONFIG_PAX_RANDMMAP | |
2101 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
2102 | + mm->mmap_base -= mm->delta_mmap + mm->delta_stack; | |
2103 | +#endif | |
2104 | + | |
2105 | mm->get_unmapped_area = arch_get_unmapped_area_topdown; | |
2106 | mm->unmap_area = arch_unmap_area_topdown; | |
2107 | } | |
de855c5d AM |
2108 | diff -urNp linux-2.6.29.6/arch/s390/include/asm/atomic.h linux-2.6.29.6/arch/s390/include/asm/atomic.h |
2109 | --- linux-2.6.29.6/arch/s390/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
2110 | +++ linux-2.6.29.6/arch/s390/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
2111 | @@ -82,8 +82,10 @@ static __inline__ int atomic_add_return( | |
2112 | return __CS_LOOP(v, i, "ar"); | |
2113 | } | |
2114 | #define atomic_add(_i, _v) atomic_add_return(_i, _v) | |
2115 | +#define atomic_add_unchecked(_i, _v) atomic_add((_i), (_v)) | |
2116 | #define atomic_add_negative(_i, _v) (atomic_add_return(_i, _v) < 0) | |
2117 | #define atomic_inc(_v) atomic_add_return(1, _v) | |
2118 | +#define atomic_inc_unchecked(_v) atomic_inc(_v) | |
2119 | #define atomic_inc_return(_v) atomic_add_return(1, _v) | |
2120 | #define atomic_inc_and_test(_v) (atomic_add_return(1, _v) == 0) | |
2121 | ||
2122 | @@ -92,6 +94,7 @@ static __inline__ int atomic_sub_return( | |
2123 | return __CS_LOOP(v, i, "sr"); | |
2124 | } | |
2125 | #define atomic_sub(_i, _v) atomic_sub_return(_i, _v) | |
2126 | +#define atomic_sub_unchecked(_i, _v) atomic_sub((_i), (_v)) | |
2127 | #define atomic_sub_and_test(_i, _v) (atomic_sub_return(_i, _v) == 0) | |
2128 | #define atomic_dec(_v) atomic_sub_return(1, _v) | |
2129 | #define atomic_dec_return(_v) atomic_sub_return(1, _v) | |
2130 | diff -urNp linux-2.6.29.6/arch/s390/include/asm/kmap_types.h linux-2.6.29.6/arch/s390/include/asm/kmap_types.h | |
2131 | --- linux-2.6.29.6/arch/s390/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
2132 | +++ linux-2.6.29.6/arch/s390/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2133 | @@ -16,6 +16,7 @@ enum km_type { |
2134 | KM_IRQ1, | |
2135 | KM_SOFTIRQ0, | |
2136 | KM_SOFTIRQ1, | |
2137 | + KM_CLEARPAGE, | |
2138 | KM_TYPE_NR | |
2139 | }; | |
2140 | ||
de855c5d AM |
2141 | diff -urNp linux-2.6.29.6/arch/s390/include/asm/uaccess.h linux-2.6.29.6/arch/s390/include/asm/uaccess.h |
2142 | --- linux-2.6.29.6/arch/s390/include/asm/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
2143 | +++ linux-2.6.29.6/arch/s390/include/asm/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
2144 | @@ -285,7 +285,7 @@ copy_from_user(void *to, const void __us | |
2145 | might_sleep(); | |
2146 | if (access_ok(VERIFY_READ, from, n)) | |
2147 | n = __copy_from_user(to, from, n); | |
2148 | - else | |
2149 | + else if ((long)n > 0) | |
2150 | memset(to, 0, n); | |
2151 | return n; | |
2152 | } | |
2153 | diff -urNp linux-2.6.29.6/arch/s390/kernel/module.c linux-2.6.29.6/arch/s390/kernel/module.c | |
2154 | --- linux-2.6.29.6/arch/s390/kernel/module.c 2009-07-02 19:41:20.000000000 -0400 | |
2155 | +++ linux-2.6.29.6/arch/s390/kernel/module.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2156 | @@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, |
2157 | ||
2158 | /* Increase core size by size of got & plt and set start | |
2159 | offsets for got and plt. */ | |
2160 | - me->core_size = ALIGN(me->core_size, 4); | |
2161 | - me->arch.got_offset = me->core_size; | |
2162 | - me->core_size += me->arch.got_size; | |
2163 | - me->arch.plt_offset = me->core_size; | |
2164 | - me->core_size += me->arch.plt_size; | |
2165 | + me->core_size_rw = ALIGN(me->core_size_rw, 4); | |
2166 | + me->arch.got_offset = me->core_size_rw; | |
2167 | + me->core_size_rw += me->arch.got_size; | |
2168 | + me->arch.plt_offset = me->core_size_rx; | |
2169 | + me->core_size_rx += me->arch.plt_size; | |
2170 | return 0; | |
2171 | } | |
2172 | ||
2173 | @@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2174 | if (info->got_initialized == 0) { | |
2175 | Elf_Addr *gotent; | |
2176 | ||
2177 | - gotent = me->module_core + me->arch.got_offset + | |
2178 | + gotent = me->module_core_rw + me->arch.got_offset + | |
2179 | info->got_offset; | |
2180 | *gotent = val; | |
2181 | info->got_initialized = 1; | |
2182 | @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2183 | else if (r_type == R_390_GOTENT || | |
2184 | r_type == R_390_GOTPLTENT) | |
2185 | *(unsigned int *) loc = | |
2186 | - (val + (Elf_Addr) me->module_core - loc) >> 1; | |
2187 | + (val + (Elf_Addr) me->module_core_rw - loc) >> 1; | |
2188 | else if (r_type == R_390_GOT64 || | |
2189 | r_type == R_390_GOTPLT64) | |
2190 | *(unsigned long *) loc = val; | |
2191 | @@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2192 | case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */ | |
2193 | if (info->plt_initialized == 0) { | |
2194 | unsigned int *ip; | |
2195 | - ip = me->module_core + me->arch.plt_offset + | |
2196 | + ip = me->module_core_rx + me->arch.plt_offset + | |
2197 | info->plt_offset; | |
2198 | #ifndef CONFIG_64BIT | |
2199 | ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */ | |
2200 | @@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2201 | val = me->arch.plt_offset - me->arch.got_offset + | |
2202 | info->plt_offset + rela->r_addend; | |
2203 | else | |
2204 | - val = (Elf_Addr) me->module_core + | |
2205 | + val = (Elf_Addr) me->module_core_rx + | |
2206 | me->arch.plt_offset + info->plt_offset + | |
2207 | rela->r_addend - loc; | |
2208 | if (r_type == R_390_PLT16DBL) | |
2209 | @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2210 | case R_390_GOTOFF32: /* 32 bit offset to GOT. */ | |
2211 | case R_390_GOTOFF64: /* 64 bit offset to GOT. */ | |
2212 | val = val + rela->r_addend - | |
2213 | - ((Elf_Addr) me->module_core + me->arch.got_offset); | |
2214 | + ((Elf_Addr) me->module_core_rw + me->arch.got_offset); | |
2215 | if (r_type == R_390_GOTOFF16) | |
2216 | *(unsigned short *) loc = val; | |
2217 | else if (r_type == R_390_GOTOFF32) | |
2218 | @@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base | |
2219 | break; | |
2220 | case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */ | |
2221 | case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */ | |
2222 | - val = (Elf_Addr) me->module_core + me->arch.got_offset + | |
2223 | + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset + | |
2224 | rela->r_addend - loc; | |
2225 | if (r_type == R_390_GOTPC) | |
2226 | *(unsigned int *) loc = val; | |
de855c5d AM |
2227 | diff -urNp linux-2.6.29.6/arch/sh/include/asm/atomic.h linux-2.6.29.6/arch/sh/include/asm/atomic.h |
2228 | --- linux-2.6.29.6/arch/sh/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
2229 | +++ linux-2.6.29.6/arch/sh/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
2230 | @@ -43,6 +43,9 @@ | |
2231 | #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) | |
2232 | ||
2233 | #define atomic_inc(v) atomic_add(1,(v)) | |
2234 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
2235 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
2236 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
2237 | #define atomic_dec(v) atomic_sub(1,(v)) | |
2238 | ||
2239 | #ifndef CONFIG_GUSA_RB | |
2240 | diff -urNp linux-2.6.29.6/arch/sh/include/asm/kmap_types.h linux-2.6.29.6/arch/sh/include/asm/kmap_types.h | |
2241 | --- linux-2.6.29.6/arch/sh/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
2242 | +++ linux-2.6.29.6/arch/sh/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2243 | @@ -24,7 +24,8 @@ D(9) KM_IRQ0, |
2244 | D(10) KM_IRQ1, | |
2245 | D(11) KM_SOFTIRQ0, | |
2246 | D(12) KM_SOFTIRQ1, | |
2247 | -D(13) KM_TYPE_NR | |
2248 | +D(13) KM_CLEARPAGE, | |
2249 | +D(14) KM_TYPE_NR | |
2250 | }; | |
2251 | ||
2252 | #undef D | |
de855c5d AM |
2253 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/atomic_32.h linux-2.6.29.6/arch/sparc/include/asm/atomic_32.h |
2254 | --- linux-2.6.29.6/arch/sparc/include/asm/atomic_32.h 2009-07-02 19:41:20.000000000 -0400 | |
2255 | +++ linux-2.6.29.6/arch/sparc/include/asm/atomic_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2256 | @@ -26,8 +26,11 @@ extern void atomic_set(atomic_t *, int); | |
2257 | #define atomic_read(v) ((v)->counter) | |
2258 | ||
2259 | #define atomic_add(i, v) ((void)__atomic_add_return( (int)(i), (v))) | |
2260 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
2261 | #define atomic_sub(i, v) ((void)__atomic_add_return(-(int)(i), (v))) | |
2262 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
2263 | #define atomic_inc(v) ((void)__atomic_add_return( 1, (v))) | |
2264 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
2265 | #define atomic_dec(v) ((void)__atomic_add_return( -1, (v))) | |
2266 | ||
2267 | #define atomic_add_return(i, v) (__atomic_add_return( (int)(i), (v))) | |
2268 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/atomic_64.h linux-2.6.29.6/arch/sparc/include/asm/atomic_64.h | |
2269 | --- linux-2.6.29.6/arch/sparc/include/asm/atomic_64.h 2009-07-02 19:41:20.000000000 -0400 | |
2270 | +++ linux-2.6.29.6/arch/sparc/include/asm/atomic_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2271 | @@ -20,8 +20,10 @@ | |
2272 | #define atomic64_set(v, i) (((v)->counter) = i) | |
2273 | ||
2274 | extern void atomic_add(int, atomic_t *); | |
2275 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
2276 | extern void atomic64_add(int, atomic64_t *); | |
2277 | extern void atomic_sub(int, atomic_t *); | |
2278 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
2279 | extern void atomic64_sub(int, atomic64_t *); | |
2280 | ||
2281 | extern int atomic_add_ret(int, atomic_t *); | |
2282 | @@ -59,6 +61,7 @@ extern int atomic64_sub_ret(int, atomic6 | |
2283 | #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0) | |
2284 | ||
2285 | #define atomic_inc(v) atomic_add(1, v) | |
2286 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
2287 | #define atomic64_inc(v) atomic64_add(1, v) | |
2288 | ||
2289 | #define atomic_dec(v) atomic_sub(1, v) | |
2290 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/elf_32.h linux-2.6.29.6/arch/sparc/include/asm/elf_32.h | |
2291 | --- linux-2.6.29.6/arch/sparc/include/asm/elf_32.h 2009-07-02 19:41:20.000000000 -0400 | |
2292 | +++ linux-2.6.29.6/arch/sparc/include/asm/elf_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2293 | @@ -116,6 +116,13 @@ typedef struct { |
2294 | ||
2295 | #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE) | |
2296 | ||
2297 | +#ifdef CONFIG_PAX_ASLR | |
2298 | +#define PAX_ELF_ET_DYN_BASE 0x10000UL | |
2299 | + | |
2300 | +#define PAX_DELTA_MMAP_LEN 16 | |
2301 | +#define PAX_DELTA_STACK_LEN 16 | |
2302 | +#endif | |
2303 | + | |
2304 | /* This yields a mask that user programs can use to figure out what | |
2305 | instruction set this cpu supports. This can NOT be done in userspace | |
2306 | on Sparc. */ | |
de855c5d AM |
2307 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/elf_64.h linux-2.6.29.6/arch/sparc/include/asm/elf_64.h |
2308 | --- linux-2.6.29.6/arch/sparc/include/asm/elf_64.h 2009-07-02 19:41:20.000000000 -0400 | |
2309 | +++ linux-2.6.29.6/arch/sparc/include/asm/elf_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2310 | @@ -163,6 +163,12 @@ typedef struct { |
2311 | #define ELF_ET_DYN_BASE 0x0000010000000000UL | |
2312 | #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL | |
2313 | ||
2314 | +#ifdef CONFIG_PAX_ASLR | |
2315 | +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL) | |
2316 | + | |
2317 | +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 ) | |
2318 | +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 ) | |
2319 | +#endif | |
2320 | ||
2321 | /* This yields a mask that user programs can use to figure out what | |
2322 | instruction set this cpu supports. */ | |
de855c5d AM |
2323 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/kmap_types.h linux-2.6.29.6/arch/sparc/include/asm/kmap_types.h |
2324 | --- linux-2.6.29.6/arch/sparc/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
2325 | +++ linux-2.6.29.6/arch/sparc/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2326 | @@ -19,6 +19,7 @@ enum km_type { |
2327 | KM_IRQ1, | |
2328 | KM_SOFTIRQ0, | |
2329 | KM_SOFTIRQ1, | |
2330 | + KM_CLEARPAGE, | |
2331 | KM_TYPE_NR | |
2332 | }; | |
2333 | ||
de855c5d AM |
2334 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/pgtable_32.h linux-2.6.29.6/arch/sparc/include/asm/pgtable_32.h |
2335 | --- linux-2.6.29.6/arch/sparc/include/asm/pgtable_32.h 2009-07-02 19:41:20.000000000 -0400 | |
2336 | +++ linux-2.6.29.6/arch/sparc/include/asm/pgtable_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2337 | @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd) |
2338 | BTFIXUPDEF_INT(page_none) | |
2339 | BTFIXUPDEF_INT(page_copy) | |
2340 | BTFIXUPDEF_INT(page_readonly) | |
2341 | + | |
2342 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2343 | +BTFIXUPDEF_INT(page_shared_noexec) | |
2344 | +BTFIXUPDEF_INT(page_copy_noexec) | |
2345 | +BTFIXUPDEF_INT(page_readonly_noexec) | |
2346 | +#endif | |
2347 | + | |
2348 | BTFIXUPDEF_INT(page_kernel) | |
2349 | ||
2350 | #define PMD_SHIFT SUN4C_PMD_SHIFT | |
2351 | @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED; | |
2352 | #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy)) | |
2353 | #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly)) | |
2354 | ||
2355 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2356 | +extern pgprot_t PAGE_SHARED_NOEXEC; | |
2357 | +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec)) | |
2358 | +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec)) | |
2359 | +#else | |
2360 | +# define PAGE_SHARED_NOEXEC PAGE_SHARED | |
2361 | +# define PAGE_COPY_NOEXEC PAGE_COPY | |
2362 | +# define PAGE_READONLY_NOEXEC PAGE_READONLY | |
2363 | +#endif | |
2364 | + | |
2365 | extern unsigned long page_kernel; | |
2366 | ||
2367 | #ifdef MODULE | |
de855c5d AM |
2368 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.29.6/arch/sparc/include/asm/pgtsrmmu.h |
2369 | --- linux-2.6.29.6/arch/sparc/include/asm/pgtsrmmu.h 2009-07-02 19:41:20.000000000 -0400 | |
2370 | +++ linux-2.6.29.6/arch/sparc/include/asm/pgtsrmmu.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2371 | @@ -115,6 +115,13 @@ |
2372 | SRMMU_EXEC | SRMMU_REF) | |
2373 | #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \ | |
2374 | SRMMU_EXEC | SRMMU_REF) | |
2375 | + | |
2376 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2377 | +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF) | |
2378 | +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF) | |
2379 | +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF) | |
2380 | +#endif | |
2381 | + | |
2382 | #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \ | |
2383 | SRMMU_DIRTY | SRMMU_REF) | |
2384 | ||
de855c5d AM |
2385 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/uaccess_32.h linux-2.6.29.6/arch/sparc/include/asm/uaccess_32.h |
2386 | --- linux-2.6.29.6/arch/sparc/include/asm/uaccess_32.h 2009-07-02 19:41:20.000000000 -0400 | |
2387 | +++ linux-2.6.29.6/arch/sparc/include/asm/uaccess_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2388 | @@ -246,7 +246,7 @@ extern unsigned long __copy_user(void __ | |
2389 | ||
2390 | static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n) | |
2391 | { | |
2392 | - if (n && __access_ok((unsigned long) to, n)) | |
2393 | + if (((int)n > 0) && __access_ok((unsigned long) to, n)) | |
2394 | return __copy_user(to, (__force void __user *) from, n); | |
2395 | else | |
2396 | return n; | |
2397 | @@ -259,7 +259,7 @@ static inline unsigned long __copy_to_us | |
2398 | ||
2399 | static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n) | |
2400 | { | |
2401 | - if (n && __access_ok((unsigned long) from, n)) | |
2402 | + if (((int)n > 0) && __access_ok((unsigned long) from, n)) | |
2403 | return __copy_user((__force void __user *) to, from, n); | |
2404 | else | |
2405 | return n; | |
2406 | diff -urNp linux-2.6.29.6/arch/sparc/include/asm/uaccess_64.h linux-2.6.29.6/arch/sparc/include/asm/uaccess_64.h | |
2407 | --- linux-2.6.29.6/arch/sparc/include/asm/uaccess_64.h 2009-07-02 19:41:20.000000000 -0400 | |
2408 | +++ linux-2.6.29.6/arch/sparc/include/asm/uaccess_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2409 | @@ -212,7 +212,12 @@ extern unsigned long copy_from_user_fixu | |
2410 | static inline unsigned long __must_check | |
2411 | copy_from_user(void *to, const void __user *from, unsigned long size) | |
2412 | { | |
2413 | - unsigned long ret = ___copy_from_user(to, from, size); | |
2414 | + unsigned long ret; | |
2415 | + | |
2416 | + if (unlikely(((long)size > INT_MAX) || ((long)size < 0))) | |
2417 | + return size; | |
2418 | + | |
2419 | + ret = ___copy_from_user(to, from, size); | |
2420 | ||
2421 | if (unlikely(ret)) | |
2422 | ret = copy_from_user_fixup(to, from, size); | |
2423 | @@ -228,7 +233,12 @@ extern unsigned long copy_to_user_fixup( | |
2424 | static inline unsigned long __must_check | |
2425 | copy_to_user(void __user *to, const void *from, unsigned long size) | |
2426 | { | |
2427 | - unsigned long ret = ___copy_to_user(to, from, size); | |
2428 | + unsigned long ret; | |
2429 | + | |
2430 | + if (unlikely(((long)size > INT_MAX) || ((long)size < 0))) | |
2431 | + return size; | |
2432 | + | |
2433 | + ret = ___copy_to_user(to, from, size); | |
2434 | ||
2435 | if (unlikely(ret)) | |
2436 | ret = copy_to_user_fixup(to, from, size); | |
2437 | diff -urNp linux-2.6.29.6/arch/sparc/kernel/Makefile linux-2.6.29.6/arch/sparc/kernel/Makefile | |
2438 | --- linux-2.6.29.6/arch/sparc/kernel/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
2439 | +++ linux-2.6.29.6/arch/sparc/kernel/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2440 | @@ -3,7 +3,7 @@ |
2441 | # | |
2442 | ||
2443 | asflags-y := -ansi | |
2444 | -ccflags-y := -Werror | |
2445 | +#ccflags-y := -Werror | |
2446 | ||
2447 | extra-y := head_$(BITS).o | |
2448 | extra-y += init_task.o | |
de855c5d AM |
2449 | diff -urNp linux-2.6.29.6/arch/sparc/kernel/sys_sparc_32.c linux-2.6.29.6/arch/sparc/kernel/sys_sparc_32.c |
2450 | --- linux-2.6.29.6/arch/sparc/kernel/sys_sparc_32.c 2009-07-02 19:41:20.000000000 -0400 | |
2451 | +++ linux-2.6.29.6/arch/sparc/kernel/sys_sparc_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2452 | @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str |
2453 | if (ARCH_SUN4C && len > 0x20000000) | |
2454 | return -ENOMEM; | |
2455 | if (!addr) | |
2456 | - addr = TASK_UNMAPPED_BASE; | |
2457 | + addr = current->mm->mmap_base; | |
2458 | ||
2459 | if (flags & MAP_SHARED) | |
2460 | addr = COLOUR_ALIGN(addr); | |
de855c5d AM |
2461 | diff -urNp linux-2.6.29.6/arch/sparc/kernel/sys_sparc_64.c linux-2.6.29.6/arch/sparc/kernel/sys_sparc_64.c |
2462 | --- linux-2.6.29.6/arch/sparc/kernel/sys_sparc_64.c 2009-07-02 19:41:20.000000000 -0400 | |
2463 | +++ linux-2.6.29.6/arch/sparc/kernel/sys_sparc_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2464 | @@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(str |
2465 | /* We do not accept a shared mapping if it would violate | |
2466 | * cache aliasing constraints. | |
2467 | */ | |
2468 | - if ((flags & MAP_SHARED) && | |
2469 | + if ((filp || (flags & MAP_SHARED)) && | |
2470 | ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) | |
2471 | return -EINVAL; | |
2472 | return addr; | |
2473 | @@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(str | |
2474 | if (filp || (flags & MAP_SHARED)) | |
2475 | do_color_align = 1; | |
2476 | ||
2477 | +#ifdef CONFIG_PAX_RANDMMAP | |
2478 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
2479 | +#endif | |
2480 | + | |
2481 | if (addr) { | |
2482 | if (do_color_align) | |
2483 | addr = COLOUR_ALIGN(addr, pgoff); | |
2484 | @@ -153,9 +157,9 @@ unsigned long arch_get_unmapped_area(str | |
2485 | } | |
2486 | ||
2487 | if (len > mm->cached_hole_size) { | |
2488 | - start_addr = addr = mm->free_area_cache; | |
2489 | + start_addr = addr = mm->free_area_cache; | |
2490 | } else { | |
2491 | - start_addr = addr = TASK_UNMAPPED_BASE; | |
2492 | ++ start_addr = addr = mm->mmap_base; | |
2493 | mm->cached_hole_size = 0; | |
2494 | } | |
2495 | ||
2496 | @@ -175,8 +179,8 @@ full_search: | |
2497 | vma = find_vma(mm, VA_EXCLUDE_END); | |
2498 | } | |
2499 | if (unlikely(task_size < addr)) { | |
2500 | - if (start_addr != TASK_UNMAPPED_BASE) { | |
2501 | - start_addr = addr = TASK_UNMAPPED_BASE; | |
2502 | + if (start_addr != mm->mmap_base) { | |
2503 | + start_addr = addr = mm->mmap_base; | |
2504 | mm->cached_hole_size = 0; | |
2505 | goto full_search; | |
2506 | } | |
2507 | @@ -216,7 +220,7 @@ arch_get_unmapped_area_topdown(struct fi | |
2508 | /* We do not accept a shared mapping if it would violate | |
2509 | * cache aliasing constraints. | |
2510 | */ | |
2511 | - if ((flags & MAP_SHARED) && | |
2512 | + if ((filp || (flags & MAP_SHARED)) && | |
2513 | ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) | |
2514 | return -EINVAL; | |
2515 | return addr; | |
2516 | @@ -380,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_str | |
2517 | current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY || | |
2518 | sysctl_legacy_va_layout) { | |
2519 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; | |
2520 | + | |
2521 | +#ifdef CONFIG_PAX_RANDMMAP | |
2522 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
2523 | + mm->mmap_base += mm->delta_mmap; | |
2524 | +#endif | |
2525 | + | |
2526 | mm->get_unmapped_area = arch_get_unmapped_area; | |
2527 | mm->unmap_area = arch_unmap_area; | |
2528 | } else { | |
2529 | @@ -394,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_str | |
2530 | gap = (task_size / 6 * 5); | |
2531 | ||
2532 | mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor); | |
2533 | + | |
2534 | +#ifdef CONFIG_PAX_RANDMMAP | |
2535 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
2536 | + mm->mmap_base -= mm->delta_mmap + mm->delta_stack; | |
2537 | +#endif | |
2538 | + | |
2539 | mm->get_unmapped_area = arch_get_unmapped_area_topdown; | |
2540 | mm->unmap_area = arch_unmap_area_topdown; | |
2541 | } | |
de855c5d AM |
2542 | diff -urNp linux-2.6.29.6/arch/sparc/Makefile linux-2.6.29.6/arch/sparc/Makefile |
2543 | --- linux-2.6.29.6/arch/sparc/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
2544 | +++ linux-2.6.29.6/arch/sparc/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2545 | @@ -81,7 +81,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc |
2546 | # Export what is needed by arch/sparc/boot/Makefile | |
2547 | export VMLINUX_INIT VMLINUX_MAIN | |
2548 | VMLINUX_INIT := $(head-y) $(init-y) | |
2549 | -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ | |
2550 | +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/ | |
2551 | VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y) | |
2552 | VMLINUX_MAIN += $(drivers-y) $(net-y) | |
2553 | ||
de855c5d AM |
2554 | diff -urNp linux-2.6.29.6/arch/sparc/mm/fault_32.c linux-2.6.29.6/arch/sparc/mm/fault_32.c |
2555 | --- linux-2.6.29.6/arch/sparc/mm/fault_32.c 2009-07-02 19:41:20.000000000 -0400 | |
2556 | +++ linux-2.6.29.6/arch/sparc/mm/fault_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2557 | @@ -21,6 +21,9 @@ |
2558 | #include <linux/interrupt.h> | |
2559 | #include <linux/module.h> | |
2560 | #include <linux/kdebug.h> | |
2561 | +#include <linux/slab.h> | |
2562 | +#include <linux/pagemap.h> | |
2563 | +#include <linux/compiler.h> | |
2564 | ||
2565 | #include <asm/system.h> | |
2566 | #include <asm/page.h> | |
2567 | @@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str | |
2568 | return safe_compute_effective_address(regs, insn); | |
2569 | } | |
2570 | ||
2571 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2572 | +void pax_emuplt_close(struct vm_area_struct *vma) | |
2573 | +{ | |
2574 | + vma->vm_mm->call_dl_resolve = 0UL; | |
2575 | +} | |
2576 | + | |
2577 | +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |
2578 | +{ | |
2579 | + unsigned int *kaddr; | |
2580 | + | |
2581 | + vmf->page = alloc_page(GFP_HIGHUSER); | |
2582 | + if (!vmf->page) | |
2583 | + return VM_FAULT_OOM; | |
2584 | + | |
2585 | + kaddr = kmap(vmf->page); | |
2586 | + memset(kaddr, 0, PAGE_SIZE); | |
2587 | + kaddr[0] = 0x9DE3BFA8U; /* save */ | |
2588 | + flush_dcache_page(vmf->page); | |
2589 | + kunmap(vmf->page); | |
2590 | + return VM_FAULT_MAJOR; | |
2591 | +} | |
2592 | + | |
2593 | +static struct vm_operations_struct pax_vm_ops = { | |
2594 | + .close = pax_emuplt_close, | |
2595 | + .fault = pax_emuplt_fault | |
2596 | +}; | |
2597 | + | |
2598 | +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr) | |
2599 | +{ | |
2600 | + int ret; | |
2601 | + | |
2602 | + vma->vm_mm = current->mm; | |
2603 | + vma->vm_start = addr; | |
2604 | + vma->vm_end = addr + PAGE_SIZE; | |
2605 | + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC; | |
2606 | + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
2607 | + vma->vm_ops = &pax_vm_ops; | |
2608 | + | |
2609 | + ret = insert_vm_struct(current->mm, vma); | |
2610 | + if (ret) | |
2611 | + return ret; | |
2612 | + | |
2613 | + ++current->mm->total_vm; | |
2614 | + return 0; | |
2615 | +} | |
2616 | + | |
2617 | +/* | |
2618 | + * PaX: decide what to do with offenders (regs->pc = fault address) | |
2619 | + * | |
2620 | + * returns 1 when task should be killed | |
2621 | + * 2 when patched PLT trampoline was detected | |
2622 | + * 3 when unpatched PLT trampoline was detected | |
2623 | + */ | |
2624 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
2625 | +{ | |
2626 | + | |
2627 | +#ifdef CONFIG_PAX_EMUPLT | |
2628 | + int err; | |
2629 | + | |
2630 | + do { /* PaX: patched PLT emulation #1 */ | |
2631 | + unsigned int sethi1, sethi2, jmpl; | |
2632 | + | |
2633 | + err = get_user(sethi1, (unsigned int *)regs->pc); | |
2634 | + err |= get_user(sethi2, (unsigned int *)(regs->pc+4)); | |
2635 | + err |= get_user(jmpl, (unsigned int *)(regs->pc+8)); | |
2636 | + | |
2637 | + if (err) | |
2638 | + break; | |
2639 | + | |
2640 | + if ((sethi1 & 0xFFC00000U) == 0x03000000U && | |
2641 | + (sethi2 & 0xFFC00000U) == 0x03000000U && | |
2642 | + (jmpl & 0xFFFFE000U) == 0x81C06000U) | |
2643 | + { | |
2644 | + unsigned int addr; | |
2645 | + | |
2646 | + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10; | |
2647 | + addr = regs->u_regs[UREG_G1]; | |
2648 | + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U); | |
2649 | + regs->pc = addr; | |
2650 | + regs->npc = addr+4; | |
2651 | + return 2; | |
2652 | + } | |
2653 | + } while (0); | |
2654 | + | |
2655 | + { /* PaX: patched PLT emulation #2 */ | |
2656 | + unsigned int ba; | |
2657 | + | |
2658 | + err = get_user(ba, (unsigned int *)regs->pc); | |
2659 | + | |
2660 | + if (!err && (ba & 0xFFC00000U) == 0x30800000U) { | |
2661 | + unsigned int addr; | |
2662 | + | |
2663 | + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2); | |
2664 | + regs->pc = addr; | |
2665 | + regs->npc = addr+4; | |
2666 | + return 2; | |
2667 | + } | |
2668 | + } | |
2669 | + | |
2670 | + do { /* PaX: patched PLT emulation #3 */ | |
2671 | + unsigned int sethi, jmpl, nop; | |
2672 | + | |
2673 | + err = get_user(sethi, (unsigned int *)regs->pc); | |
2674 | + err |= get_user(jmpl, (unsigned int *)(regs->pc+4)); | |
2675 | + err |= get_user(nop, (unsigned int *)(regs->pc+8)); | |
2676 | + | |
2677 | + if (err) | |
2678 | + break; | |
2679 | + | |
2680 | + if ((sethi & 0xFFC00000U) == 0x03000000U && | |
2681 | + (jmpl & 0xFFFFE000U) == 0x81C06000U && | |
2682 | + nop == 0x01000000U) | |
2683 | + { | |
2684 | + unsigned int addr; | |
2685 | + | |
2686 | + addr = (sethi & 0x003FFFFFU) << 10; | |
2687 | + regs->u_regs[UREG_G1] = addr; | |
2688 | + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U); | |
2689 | + regs->pc = addr; | |
2690 | + regs->npc = addr+4; | |
2691 | + return 2; | |
2692 | + } | |
2693 | + } while (0); | |
2694 | + | |
2695 | + do { /* PaX: unpatched PLT emulation step 1 */ | |
2696 | + unsigned int sethi, ba, nop; | |
2697 | + | |
2698 | + err = get_user(sethi, (unsigned int *)regs->pc); | |
2699 | + err |= get_user(ba, (unsigned int *)(regs->pc+4)); | |
2700 | + err |= get_user(nop, (unsigned int *)(regs->pc+8)); | |
2701 | + | |
2702 | + if (err) | |
2703 | + break; | |
2704 | + | |
2705 | + if ((sethi & 0xFFC00000U) == 0x03000000U && | |
2706 | + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) && | |
2707 | + nop == 0x01000000U) | |
2708 | + { | |
2709 | + unsigned int addr, save, call; | |
2710 | + | |
2711 | + if ((ba & 0xFFC00000U) == 0x30800000U) | |
2712 | + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2); | |
2713 | + else | |
2714 | + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2); | |
2715 | + | |
2716 | + err = get_user(save, (unsigned int *)addr); | |
2717 | + err |= get_user(call, (unsigned int *)(addr+4)); | |
2718 | + err |= get_user(nop, (unsigned int *)(addr+8)); | |
2719 | + if (err) | |
2720 | + break; | |
2721 | + | |
2722 | + if (save == 0x9DE3BFA8U && | |
2723 | + (call & 0xC0000000U) == 0x40000000U && | |
2724 | + nop == 0x01000000U) | |
2725 | + { | |
2726 | + struct vm_area_struct *vma; | |
2727 | + unsigned long call_dl_resolve; | |
2728 | + | |
2729 | + down_read(¤t->mm->mmap_sem); | |
2730 | + call_dl_resolve = current->mm->call_dl_resolve; | |
2731 | + up_read(¤t->mm->mmap_sem); | |
2732 | + if (likely(call_dl_resolve)) | |
2733 | + goto emulate; | |
2734 | + | |
2735 | + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
2736 | + | |
2737 | + down_write(¤t->mm->mmap_sem); | |
2738 | + if (current->mm->call_dl_resolve) { | |
2739 | + call_dl_resolve = current->mm->call_dl_resolve; | |
2740 | + up_write(¤t->mm->mmap_sem); | |
2741 | + if (vma) | |
2742 | + kmem_cache_free(vm_area_cachep, vma); | |
2743 | + goto emulate; | |
2744 | + } | |
2745 | + | |
2746 | + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE); | |
2747 | + if (!vma || (call_dl_resolve & ~PAGE_MASK)) { | |
2748 | + up_write(¤t->mm->mmap_sem); | |
2749 | + if (vma) | |
2750 | + kmem_cache_free(vm_area_cachep, vma); | |
2751 | + return 1; | |
2752 | + } | |
2753 | + | |
2754 | + if (pax_insert_vma(vma, call_dl_resolve)) { | |
2755 | + up_write(¤t->mm->mmap_sem); | |
2756 | + kmem_cache_free(vm_area_cachep, vma); | |
2757 | + return 1; | |
2758 | + } | |
2759 | + | |
2760 | + current->mm->call_dl_resolve = call_dl_resolve; | |
2761 | + up_write(¤t->mm->mmap_sem); | |
2762 | + | |
2763 | +emulate: | |
2764 | + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10; | |
2765 | + regs->pc = call_dl_resolve; | |
2766 | + regs->npc = addr+4; | |
2767 | + return 3; | |
2768 | + } | |
2769 | + } | |
2770 | + } while (0); | |
2771 | + | |
2772 | + do { /* PaX: unpatched PLT emulation step 2 */ | |
2773 | + unsigned int save, call, nop; | |
2774 | + | |
2775 | + err = get_user(save, (unsigned int *)(regs->pc-4)); | |
2776 | + err |= get_user(call, (unsigned int *)regs->pc); | |
2777 | + err |= get_user(nop, (unsigned int *)(regs->pc+4)); | |
2778 | + if (err) | |
2779 | + break; | |
2780 | + | |
2781 | + if (save == 0x9DE3BFA8U && | |
2782 | + (call & 0xC0000000U) == 0x40000000U && | |
2783 | + nop == 0x01000000U) | |
2784 | + { | |
2785 | + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2); | |
2786 | + | |
2787 | + regs->u_regs[UREG_RETPC] = regs->pc; | |
2788 | + regs->pc = dl_resolve; | |
2789 | + regs->npc = dl_resolve+4; | |
2790 | + return 3; | |
2791 | + } | |
2792 | + } while (0); | |
2793 | +#endif | |
2794 | + | |
2795 | + return 1; | |
2796 | +} | |
2797 | + | |
2798 | +void pax_report_insns(void *pc, void *sp) | |
2799 | +{ | |
2800 | + unsigned long i; | |
2801 | + | |
2802 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
2803 | + for (i = 0; i < 5; i++) { | |
2804 | + unsigned int c; | |
2805 | + if (get_user(c, (unsigned int *)pc+i)) | |
2806 | + printk(KERN_CONT "???????? "); | |
2807 | + else | |
2808 | + printk(KERN_CONT "%08x ", c); | |
2809 | + } | |
2810 | + printk("\n"); | |
2811 | +} | |
2812 | +#endif | |
2813 | + | |
2814 | asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, | |
2815 | unsigned long address) | |
2816 | { | |
2817 | @@ -231,6 +477,24 @@ good_area: | |
2818 | if(!(vma->vm_flags & VM_WRITE)) | |
2819 | goto bad_area; | |
2820 | } else { | |
2821 | + | |
2822 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2823 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) { | |
2824 | + up_read(&mm->mmap_sem); | |
2825 | + switch (pax_handle_fetch_fault(regs)) { | |
2826 | + | |
2827 | +#ifdef CONFIG_PAX_EMUPLT | |
2828 | + case 2: | |
2829 | + case 3: | |
2830 | + return; | |
2831 | +#endif | |
2832 | + | |
2833 | + } | |
2834 | + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]); | |
2835 | + do_group_exit(SIGKILL); | |
2836 | + } | |
2837 | +#endif | |
2838 | + | |
2839 | /* Allow reads even for write-only mappings */ | |
2840 | if(!(vma->vm_flags & (VM_READ | VM_EXEC))) | |
2841 | goto bad_area; | |
de855c5d AM |
2842 | diff -urNp linux-2.6.29.6/arch/sparc/mm/fault_64.c linux-2.6.29.6/arch/sparc/mm/fault_64.c |
2843 | --- linux-2.6.29.6/arch/sparc/mm/fault_64.c 2009-07-02 19:41:20.000000000 -0400 | |
2844 | +++ linux-2.6.29.6/arch/sparc/mm/fault_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
2845 | @@ -20,6 +20,9 @@ |
2846 | #include <linux/kprobes.h> | |
2847 | #include <linux/kdebug.h> | |
2848 | #include <linux/percpu.h> | |
2849 | +#include <linux/slab.h> | |
2850 | +#include <linux/pagemap.h> | |
2851 | +#include <linux/compiler.h> | |
2852 | ||
2853 | #include <asm/page.h> | |
2854 | #include <asm/pgtable.h> | |
2855 | @@ -249,6 +252,367 @@ static void noinline bogus_32bit_fault_a | |
2856 | show_regs(regs); | |
2857 | } | |
2858 | ||
2859 | +#ifdef CONFIG_PAX_PAGEEXEC | |
2860 | +#ifdef CONFIG_PAX_EMUPLT | |
2861 | +static void pax_emuplt_close(struct vm_area_struct *vma) | |
2862 | +{ | |
2863 | + vma->vm_mm->call_dl_resolve = 0UL; | |
2864 | +} | |
2865 | + | |
2866 | +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |
2867 | +{ | |
2868 | + unsigned int *kaddr; | |
2869 | + | |
2870 | + vmf->page = alloc_page(GFP_HIGHUSER); | |
2871 | + if (!vmf->page) | |
2872 | + return VM_FAULT_OOM; | |
2873 | + | |
2874 | + kaddr = kmap(vmf->page); | |
2875 | + memset(kaddr, 0, PAGE_SIZE); | |
2876 | + kaddr[0] = 0x9DE3BFA8U; /* save */ | |
2877 | + flush_dcache_page(vmf->page); | |
2878 | + kunmap(vmf->page); | |
2879 | + return VM_FAULT_MAJOR; | |
2880 | +} | |
2881 | + | |
2882 | +static struct vm_operations_struct pax_vm_ops = { | |
2883 | + .close = pax_emuplt_close, | |
2884 | + .fault = pax_emuplt_fault | |
2885 | +}; | |
2886 | + | |
2887 | +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr) | |
2888 | +{ | |
2889 | + int ret; | |
2890 | + | |
2891 | + vma->vm_mm = current->mm; | |
2892 | + vma->vm_start = addr; | |
2893 | + vma->vm_end = addr + PAGE_SIZE; | |
2894 | + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC; | |
2895 | + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
2896 | + vma->vm_ops = &pax_vm_ops; | |
2897 | + | |
2898 | + ret = insert_vm_struct(current->mm, vma); | |
2899 | + if (ret) | |
2900 | + return ret; | |
2901 | + | |
2902 | + ++current->mm->total_vm; | |
2903 | + return 0; | |
2904 | +} | |
2905 | +#endif | |
2906 | + | |
2907 | +/* | |
2908 | + * PaX: decide what to do with offenders (regs->tpc = fault address) | |
2909 | + * | |
2910 | + * returns 1 when task should be killed | |
2911 | + * 2 when patched PLT trampoline was detected | |
2912 | + * 3 when unpatched PLT trampoline was detected | |
2913 | + */ | |
2914 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
2915 | +{ | |
2916 | + | |
2917 | +#ifdef CONFIG_PAX_EMUPLT | |
2918 | + int err; | |
2919 | + | |
2920 | + do { /* PaX: patched PLT emulation #1 */ | |
2921 | + unsigned int sethi1, sethi2, jmpl; | |
2922 | + | |
2923 | + err = get_user(sethi1, (unsigned int *)regs->tpc); | |
2924 | + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4)); | |
2925 | + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8)); | |
2926 | + | |
2927 | + if (err) | |
2928 | + break; | |
2929 | + | |
2930 | + if ((sethi1 & 0xFFC00000U) == 0x03000000U && | |
2931 | + (sethi2 & 0xFFC00000U) == 0x03000000U && | |
2932 | + (jmpl & 0xFFFFE000U) == 0x81C06000U) | |
2933 | + { | |
2934 | + unsigned long addr; | |
2935 | + | |
2936 | + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10; | |
2937 | + addr = regs->u_regs[UREG_G1]; | |
2938 | + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL); | |
2939 | + regs->tpc = addr; | |
2940 | + regs->tnpc = addr+4; | |
2941 | + return 2; | |
2942 | + } | |
2943 | + } while (0); | |
2944 | + | |
2945 | + { /* PaX: patched PLT emulation #2 */ | |
2946 | + unsigned int ba; | |
2947 | + | |
2948 | + err = get_user(ba, (unsigned int *)regs->tpc); | |
2949 | + | |
2950 | + if (!err && (ba & 0xFFC00000U) == 0x30800000U) { | |
2951 | + unsigned long addr; | |
2952 | + | |
2953 | + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2); | |
2954 | + regs->tpc = addr; | |
2955 | + regs->tnpc = addr+4; | |
2956 | + return 2; | |
2957 | + } | |
2958 | + } | |
2959 | + | |
2960 | + do { /* PaX: patched PLT emulation #3 */ | |
2961 | + unsigned int sethi, jmpl, nop; | |
2962 | + | |
2963 | + err = get_user(sethi, (unsigned int *)regs->tpc); | |
2964 | + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4)); | |
2965 | + err |= get_user(nop, (unsigned int *)(regs->tpc+8)); | |
2966 | + | |
2967 | + if (err) | |
2968 | + break; | |
2969 | + | |
2970 | + if ((sethi & 0xFFC00000U) == 0x03000000U && | |
2971 | + (jmpl & 0xFFFFE000U) == 0x81C06000U && | |
2972 | + nop == 0x01000000U) | |
2973 | + { | |
2974 | + unsigned long addr; | |
2975 | + | |
2976 | + addr = (sethi & 0x003FFFFFU) << 10; | |
2977 | + regs->u_regs[UREG_G1] = addr; | |
2978 | + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL); | |
2979 | + regs->tpc = addr; | |
2980 | + regs->tnpc = addr+4; | |
2981 | + return 2; | |
2982 | + } | |
2983 | + } while (0); | |
2984 | + | |
2985 | + do { /* PaX: patched PLT emulation #4 */ | |
2986 | + unsigned int mov1, call, mov2; | |
2987 | + | |
2988 | + err = get_user(mov1, (unsigned int *)regs->tpc); | |
2989 | + err |= get_user(call, (unsigned int *)(regs->tpc+4)); | |
2990 | + err |= get_user(mov2, (unsigned int *)(regs->tpc+8)); | |
2991 | + | |
2992 | + if (err) | |
2993 | + break; | |
2994 | + | |
2995 | + if (mov1 == 0x8210000FU && | |
2996 | + (call & 0xC0000000U) == 0x40000000U && | |
2997 | + mov2 == 0x9E100001U) | |
2998 | + { | |
2999 | + unsigned long addr; | |
3000 | + | |
3001 | + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC]; | |
3002 | + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2); | |
3003 | + regs->tpc = addr; | |
3004 | + regs->tnpc = addr+4; | |
3005 | + return 2; | |
3006 | + } | |
3007 | + } while (0); | |
3008 | + | |
3009 | + do { /* PaX: patched PLT emulation #5 */ | |
3010 | + unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop; | |
3011 | + | |
3012 | + err = get_user(sethi1, (unsigned int *)regs->tpc); | |
3013 | + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4)); | |
3014 | + err |= get_user(or1, (unsigned int *)(regs->tpc+8)); | |
3015 | + err |= get_user(or2, (unsigned int *)(regs->tpc+12)); | |
3016 | + err |= get_user(sllx, (unsigned int *)(regs->tpc+16)); | |
3017 | + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20)); | |
3018 | + err |= get_user(nop, (unsigned int *)(regs->tpc+24)); | |
3019 | + | |
3020 | + if (err) | |
3021 | + break; | |
3022 | + | |
3023 | + if ((sethi1 & 0xFFC00000U) == 0x03000000U && | |
3024 | + (sethi2 & 0xFFC00000U) == 0x0B000000U && | |
3025 | + (or1 & 0xFFFFE000U) == 0x82106000U && | |
3026 | + (or2 & 0xFFFFE000U) == 0x8A116000U && | |
3027 | + sllx == 0x83287020 && | |
3028 | + jmpl == 0x81C04005U && | |
3029 | + nop == 0x01000000U) | |
3030 | + { | |
3031 | + unsigned long addr; | |
3032 | + | |
3033 | + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU); | |
3034 | + regs->u_regs[UREG_G1] <<= 32; | |
3035 | + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU); | |
3036 | + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5]; | |
3037 | + regs->tpc = addr; | |
3038 | + regs->tnpc = addr+4; | |
3039 | + return 2; | |
3040 | + } | |
3041 | + } while (0); | |
3042 | + | |
3043 | + do { /* PaX: patched PLT emulation #6 */ | |
3044 | + unsigned int sethi1, sethi2, sllx, or, jmpl, nop; | |
3045 | + | |
3046 | + err = get_user(sethi1, (unsigned int *)regs->tpc); | |
3047 | + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4)); | |
3048 | + err |= get_user(sllx, (unsigned int *)(regs->tpc+8)); | |
3049 | + err |= get_user(or, (unsigned int *)(regs->tpc+12)); | |
3050 | + err |= get_user(jmpl, (unsigned int *)(regs->tpc+16)); | |
3051 | + err |= get_user(nop, (unsigned int *)(regs->tpc+20)); | |
3052 | + | |
3053 | + if (err) | |
3054 | + break; | |
3055 | + | |
3056 | + if ((sethi1 & 0xFFC00000U) == 0x03000000U && | |
3057 | + (sethi2 & 0xFFC00000U) == 0x0B000000U && | |
3058 | + sllx == 0x83287020 && | |
3059 | + (or & 0xFFFFE000U) == 0x8A116000U && | |
3060 | + jmpl == 0x81C04005U && | |
3061 | + nop == 0x01000000U) | |
3062 | + { | |
3063 | + unsigned long addr; | |
3064 | + | |
3065 | + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10; | |
3066 | + regs->u_regs[UREG_G1] <<= 32; | |
3067 | + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU); | |
3068 | + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5]; | |
3069 | + regs->tpc = addr; | |
3070 | + regs->tnpc = addr+4; | |
3071 | + return 2; | |
3072 | + } | |
3073 | + } while (0); | |
3074 | + | |
3075 | + do { /* PaX: patched PLT emulation #7 */ | |
3076 | + unsigned int sethi, ba, nop; | |
3077 | + | |
3078 | + err = get_user(sethi, (unsigned int *)regs->tpc); | |
3079 | + err |= get_user(ba, (unsigned int *)(regs->tpc+4)); | |
3080 | + err |= get_user(nop, (unsigned int *)(regs->tpc+8)); | |
3081 | + | |
3082 | + if (err) | |
3083 | + break; | |
3084 | + | |
3085 | + if ((sethi & 0xFFC00000U) == 0x03000000U && | |
3086 | + (ba & 0xFFF00000U) == 0x30600000U && | |
3087 | + nop == 0x01000000U) | |
3088 | + { | |
3089 | + unsigned long addr; | |
3090 | + | |
3091 | + addr = (sethi & 0x003FFFFFU) << 10; | |
3092 | + regs->u_regs[UREG_G1] = addr; | |
3093 | + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2); | |
3094 | + regs->tpc = addr; | |
3095 | + regs->tnpc = addr+4; | |
3096 | + return 2; | |
3097 | + } | |
3098 | + } while (0); | |
3099 | + | |
3100 | + do { /* PaX: unpatched PLT emulation step 1 */ | |
3101 | + unsigned int sethi, ba, nop; | |
3102 | + | |
3103 | + err = get_user(sethi, (unsigned int *)regs->tpc); | |
3104 | + err |= get_user(ba, (unsigned int *)(regs->tpc+4)); | |
3105 | + err |= get_user(nop, (unsigned int *)(regs->tpc+8)); | |
3106 | + | |
3107 | + if (err) | |
3108 | + break; | |
3109 | + | |
3110 | + if ((sethi & 0xFFC00000U) == 0x03000000U && | |
3111 | + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) && | |
3112 | + nop == 0x01000000U) | |
3113 | + { | |
3114 | + unsigned long addr; | |
3115 | + unsigned int save, call; | |
3116 | + | |
3117 | + if ((ba & 0xFFC00000U) == 0x30800000U) | |
3118 | + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2); | |
3119 | + else | |
3120 | + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2); | |
3121 | + | |
3122 | + err = get_user(save, (unsigned int *)addr); | |
3123 | + err |= get_user(call, (unsigned int *)(addr+4)); | |
3124 | + err |= get_user(nop, (unsigned int *)(addr+8)); | |
3125 | + if (err) | |
3126 | + break; | |
3127 | + | |
3128 | + if (save == 0x9DE3BFA8U && | |
3129 | + (call & 0xC0000000U) == 0x40000000U && | |
3130 | + nop == 0x01000000U) | |
3131 | + { | |
3132 | + struct vm_area_struct *vma; | |
3133 | + unsigned long call_dl_resolve; | |
3134 | + | |
3135 | + down_read(¤t->mm->mmap_sem); | |
3136 | + call_dl_resolve = current->mm->call_dl_resolve; | |
3137 | + up_read(¤t->mm->mmap_sem); | |
3138 | + if (likely(call_dl_resolve)) | |
3139 | + goto emulate; | |
3140 | + | |
3141 | + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
3142 | + | |
3143 | + down_write(¤t->mm->mmap_sem); | |
3144 | + if (current->mm->call_dl_resolve) { | |
3145 | + call_dl_resolve = current->mm->call_dl_resolve; | |
3146 | + up_write(¤t->mm->mmap_sem); | |
3147 | + if (vma) | |
3148 | + kmem_cache_free(vm_area_cachep, vma); | |
3149 | + goto emulate; | |
3150 | + } | |
3151 | + | |
3152 | + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE); | |
3153 | + if (!vma || (call_dl_resolve & ~PAGE_MASK)) { | |
3154 | + up_write(¤t->mm->mmap_sem); | |
3155 | + if (vma) | |
3156 | + kmem_cache_free(vm_area_cachep, vma); | |
3157 | + return 1; | |
3158 | + } | |
3159 | + | |
3160 | + if (pax_insert_vma(vma, call_dl_resolve)) { | |
3161 | + up_write(¤t->mm->mmap_sem); | |
3162 | + kmem_cache_free(vm_area_cachep, vma); | |
3163 | + return 1; | |
3164 | + } | |
3165 | + | |
3166 | + current->mm->call_dl_resolve = call_dl_resolve; | |
3167 | + up_write(¤t->mm->mmap_sem); | |
3168 | + | |
3169 | +emulate: | |
3170 | + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10; | |
3171 | + regs->tpc = call_dl_resolve; | |
3172 | + regs->tnpc = addr+4; | |
3173 | + return 3; | |
3174 | + } | |
3175 | + } | |
3176 | + } while (0); | |
3177 | + | |
3178 | + do { /* PaX: unpatched PLT emulation step 2 */ | |
3179 | + unsigned int save, call, nop; | |
3180 | + | |
3181 | + err = get_user(save, (unsigned int *)(regs->tpc-4)); | |
3182 | + err |= get_user(call, (unsigned int *)regs->tpc); | |
3183 | + err |= get_user(nop, (unsigned int *)(regs->tpc+4)); | |
3184 | + if (err) | |
3185 | + break; | |
3186 | + | |
3187 | + if (save == 0x9DE3BFA8U && | |
3188 | + (call & 0xC0000000U) == 0x40000000U && | |
3189 | + nop == 0x01000000U) | |
3190 | + { | |
3191 | + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2); | |
3192 | + | |
3193 | + regs->u_regs[UREG_RETPC] = regs->tpc; | |
3194 | + regs->tpc = dl_resolve; | |
3195 | + regs->tnpc = dl_resolve+4; | |
3196 | + return 3; | |
3197 | + } | |
3198 | + } while (0); | |
3199 | +#endif | |
3200 | + | |
3201 | + return 1; | |
3202 | +} | |
3203 | + | |
3204 | +void pax_report_insns(void *pc, void *sp) | |
3205 | +{ | |
3206 | + unsigned long i; | |
3207 | + | |
3208 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
3209 | + for (i = 0; i < 5; i++) { | |
3210 | + unsigned int c; | |
3211 | + if (get_user(c, (unsigned int *)pc+i)) | |
3212 | + printk(KERN_CONT "???????? "); | |
3213 | + else | |
3214 | + printk(KERN_CONT "%08x ", c); | |
3215 | + } | |
3216 | + printk("\n"); | |
3217 | +} | |
3218 | +#endif | |
3219 | + | |
3220 | asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) | |
3221 | { | |
3222 | struct mm_struct *mm = current->mm; | |
3223 | @@ -315,6 +679,29 @@ asmlinkage void __kprobes do_sparc64_fau | |
3224 | if (!vma) | |
3225 | goto bad_area; | |
3226 | ||
3227 | +#ifdef CONFIG_PAX_PAGEEXEC | |
3228 | + /* PaX: detect ITLB misses on non-exec pages */ | |
3229 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address && | |
3230 | + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB)) | |
3231 | + { | |
3232 | + if (address != regs->tpc) | |
3233 | + goto good_area; | |
3234 | + | |
3235 | + up_read(&mm->mmap_sem); | |
3236 | + switch (pax_handle_fetch_fault(regs)) { | |
3237 | + | |
3238 | +#ifdef CONFIG_PAX_EMUPLT | |
3239 | + case 2: | |
3240 | + case 3: | |
3241 | + return; | |
3242 | +#endif | |
3243 | + | |
3244 | + } | |
3245 | + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS)); | |
3246 | + do_group_exit(SIGKILL); | |
3247 | + } | |
3248 | +#endif | |
3249 | + | |
3250 | /* Pure DTLB misses do not tell us whether the fault causing | |
3251 | * load/store/atomic was a write or not, it only says that there | |
3252 | * was no match. So in such a case we (carefully) read the | |
de855c5d AM |
3253 | diff -urNp linux-2.6.29.6/arch/sparc/mm/init_32.c linux-2.6.29.6/arch/sparc/mm/init_32.c |
3254 | --- linux-2.6.29.6/arch/sparc/mm/init_32.c 2009-07-02 19:41:20.000000000 -0400 | |
3255 | +++ linux-2.6.29.6/arch/sparc/mm/init_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3256 | @@ -316,6 +316,9 @@ extern void device_scan(void); |
3257 | pgprot_t PAGE_SHARED __read_mostly; | |
3258 | EXPORT_SYMBOL(PAGE_SHARED); | |
3259 | ||
3260 | +pgprot_t PAGE_SHARED_NOEXEC __read_mostly; | |
3261 | +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC); | |
3262 | + | |
3263 | void __init paging_init(void) | |
3264 | { | |
3265 | switch(sparc_cpu_model) { | |
3266 | @@ -341,17 +344,17 @@ void __init paging_init(void) | |
3267 | ||
3268 | /* Initialize the protection map with non-constant, MMU dependent values. */ | |
3269 | protection_map[0] = PAGE_NONE; | |
3270 | - protection_map[1] = PAGE_READONLY; | |
3271 | - protection_map[2] = PAGE_COPY; | |
3272 | - protection_map[3] = PAGE_COPY; | |
3273 | + protection_map[1] = PAGE_READONLY_NOEXEC; | |
3274 | + protection_map[2] = PAGE_COPY_NOEXEC; | |
3275 | + protection_map[3] = PAGE_COPY_NOEXEC; | |
3276 | protection_map[4] = PAGE_READONLY; | |
3277 | protection_map[5] = PAGE_READONLY; | |
3278 | protection_map[6] = PAGE_COPY; | |
3279 | protection_map[7] = PAGE_COPY; | |
3280 | protection_map[8] = PAGE_NONE; | |
3281 | - protection_map[9] = PAGE_READONLY; | |
3282 | - protection_map[10] = PAGE_SHARED; | |
3283 | - protection_map[11] = PAGE_SHARED; | |
3284 | + protection_map[9] = PAGE_READONLY_NOEXEC; | |
3285 | + protection_map[10] = PAGE_SHARED_NOEXEC; | |
3286 | + protection_map[11] = PAGE_SHARED_NOEXEC; | |
3287 | protection_map[12] = PAGE_READONLY; | |
3288 | protection_map[13] = PAGE_READONLY; | |
3289 | protection_map[14] = PAGE_SHARED; | |
de855c5d AM |
3290 | diff -urNp linux-2.6.29.6/arch/sparc/mm/Makefile linux-2.6.29.6/arch/sparc/mm/Makefile |
3291 | --- linux-2.6.29.6/arch/sparc/mm/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
3292 | +++ linux-2.6.29.6/arch/sparc/mm/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3293 | @@ -2,7 +2,7 @@ |
3294 | # | |
3295 | ||
3296 | asflags-y := -ansi | |
3297 | -ccflags-y := -Werror | |
3298 | +#ccflags-y := -Werror | |
3299 | ||
3300 | obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o | |
3301 | obj-y += fault_$(BITS).o | |
de855c5d AM |
3302 | diff -urNp linux-2.6.29.6/arch/sparc/mm/srmmu.c linux-2.6.29.6/arch/sparc/mm/srmmu.c |
3303 | --- linux-2.6.29.6/arch/sparc/mm/srmmu.c 2009-07-02 19:41:20.000000000 -0400 | |
3304 | +++ linux-2.6.29.6/arch/sparc/mm/srmmu.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3305 | @@ -2148,6 +2148,13 @@ void __init ld_mmu_srmmu(void) |
3306 | PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED); | |
3307 | BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY)); | |
3308 | BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY)); | |
3309 | + | |
3310 | +#ifdef CONFIG_PAX_PAGEEXEC | |
3311 | + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC); | |
3312 | + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC)); | |
3313 | + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC)); | |
3314 | +#endif | |
3315 | + | |
3316 | BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL)); | |
3317 | page_kernel = pgprot_val(SRMMU_PAGE_KERNEL); | |
3318 | ||
de855c5d AM |
3319 | diff -urNp linux-2.6.29.6/arch/um/include/asm/kmap_types.h linux-2.6.29.6/arch/um/include/asm/kmap_types.h |
3320 | --- linux-2.6.29.6/arch/um/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
3321 | +++ linux-2.6.29.6/arch/um/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3322 | @@ -23,6 +23,7 @@ enum km_type { |
3323 | KM_IRQ1, | |
3324 | KM_SOFTIRQ0, | |
3325 | KM_SOFTIRQ1, | |
3326 | + KM_CLEARPAGE, | |
3327 | KM_TYPE_NR | |
3328 | }; | |
3329 | ||
de855c5d AM |
3330 | diff -urNp linux-2.6.29.6/arch/um/include/asm/page.h linux-2.6.29.6/arch/um/include/asm/page.h |
3331 | --- linux-2.6.29.6/arch/um/include/asm/page.h 2009-07-02 19:41:20.000000000 -0400 | |
3332 | +++ linux-2.6.29.6/arch/um/include/asm/page.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3333 | @@ -14,6 +14,9 @@ |
3334 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) | |
3335 | #define PAGE_MASK (~(PAGE_SIZE-1)) | |
3336 | ||
3337 | +#define ktla_ktva(addr) (addr) | |
3338 | +#define ktva_ktla(addr) (addr) | |
3339 | + | |
3340 | #ifndef __ASSEMBLY__ | |
3341 | ||
3342 | struct page; | |
de855c5d AM |
3343 | diff -urNp linux-2.6.29.6/arch/um/sys-i386/syscalls.c linux-2.6.29.6/arch/um/sys-i386/syscalls.c |
3344 | --- linux-2.6.29.6/arch/um/sys-i386/syscalls.c 2009-07-02 19:41:20.000000000 -0400 | |
3345 | +++ linux-2.6.29.6/arch/um/sys-i386/syscalls.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3346 | @@ -11,6 +11,21 @@ |
3347 | #include "asm/uaccess.h" | |
3348 | #include "asm/unistd.h" | |
3349 | ||
3350 | +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags) | |
3351 | +{ | |
3352 | + unsigned long pax_task_size = TASK_SIZE; | |
3353 | + | |
3354 | +#ifdef CONFIG_PAX_SEGMEXEC | |
3355 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) | |
3356 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
3357 | +#endif | |
3358 | + | |
3359 | + if (len > pax_task_size || addr > pax_task_size - len) | |
3360 | + return -EINVAL; | |
3361 | + | |
3362 | + return 0; | |
3363 | +} | |
3364 | + | |
3365 | /* | |
3366 | * Perform the select(nd, in, out, ex, tv) and mmap() system | |
3367 | * calls. Linux/i386 didn't use to be able to handle more than | |
de855c5d AM |
3368 | diff -urNp linux-2.6.29.6/arch/x86/boot/bitops.h linux-2.6.29.6/arch/x86/boot/bitops.h |
3369 | --- linux-2.6.29.6/arch/x86/boot/bitops.h 2009-07-02 19:41:20.000000000 -0400 | |
3370 | +++ linux-2.6.29.6/arch/x86/boot/bitops.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3371 | @@ -26,7 +26,7 @@ static inline int variable_test_bit(int |
3372 | u8 v; | |
3373 | const u32 *p = (const u32 *)addr; | |
3374 | ||
3375 | - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr)); | |
3376 | + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr)); | |
3377 | return v; | |
3378 | } | |
3379 | ||
3380 | @@ -37,7 +37,7 @@ static inline int variable_test_bit(int | |
3381 | ||
3382 | static inline void set_bit(int nr, void *addr) | |
3383 | { | |
3384 | - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr)); | |
3385 | + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr)); | |
3386 | } | |
3387 | ||
3388 | #endif /* BOOT_BITOPS_H */ | |
de855c5d AM |
3389 | diff -urNp linux-2.6.29.6/arch/x86/boot/boot.h linux-2.6.29.6/arch/x86/boot/boot.h |
3390 | --- linux-2.6.29.6/arch/x86/boot/boot.h 2009-07-02 19:41:20.000000000 -0400 | |
3391 | +++ linux-2.6.29.6/arch/x86/boot/boot.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3392 | @@ -80,7 +80,7 @@ static inline void io_delay(void) |
3393 | static inline u16 ds(void) | |
3394 | { | |
3395 | u16 seg; | |
3396 | - asm("movw %%ds,%0" : "=rm" (seg)); | |
3397 | + asm volatile("movw %%ds,%0" : "=rm" (seg)); | |
3398 | return seg; | |
3399 | } | |
3400 | ||
3401 | @@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t | |
3402 | static inline int memcmp(const void *s1, const void *s2, size_t len) | |
3403 | { | |
3404 | u8 diff; | |
3405 | - asm("repe; cmpsb; setnz %0" | |
3406 | + asm volatile("repe; cmpsb; setnz %0" | |
3407 | : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); | |
3408 | return diff; | |
3409 | } | |
de855c5d AM |
3410 | diff -urNp linux-2.6.29.6/arch/x86/boot/compressed/head_32.S linux-2.6.29.6/arch/x86/boot/compressed/head_32.S |
3411 | --- linux-2.6.29.6/arch/x86/boot/compressed/head_32.S 2009-07-02 19:41:20.000000000 -0400 | |
3412 | +++ linux-2.6.29.6/arch/x86/boot/compressed/head_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3413 | @@ -70,7 +70,7 @@ startup_32: |
3414 | addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx | |
3415 | andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx | |
3416 | #else | |
3417 | - movl $LOAD_PHYSICAL_ADDR, %ebx | |
3418 | + movl $____LOAD_PHYSICAL_ADDR, %ebx | |
3419 | #endif | |
3420 | ||
3421 | /* Replace the compressed data size with the uncompressed size */ | |
3422 | @@ -80,8 +80,8 @@ startup_32: | |
3423 | /* Add 8 bytes for every 32K input block */ | |
3424 | shrl $12, %eax | |
3425 | addl %eax, %ebx | |
3426 | - /* Add 32K + 18 bytes of extra slack */ | |
3427 | - addl $(32768 + 18), %ebx | |
3428 | + /* Add 64K of extra slack */ | |
3429 | + addl $65536, %ebx | |
3430 | /* Align on a 4K boundary */ | |
3431 | addl $4095, %ebx | |
3432 | andl $~4095, %ebx | |
3433 | @@ -105,7 +105,7 @@ startup_32: | |
3434 | addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp | |
3435 | andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp | |
3436 | #else | |
3437 | - movl $LOAD_PHYSICAL_ADDR, %ebp | |
3438 | + movl $____LOAD_PHYSICAL_ADDR, %ebp | |
3439 | #endif | |
3440 | ||
3441 | /* | |
3442 | @@ -160,16 +160,15 @@ relocated: | |
3443 | * and where it was actually loaded. | |
3444 | */ | |
3445 | movl %ebp, %ebx | |
3446 | - subl $LOAD_PHYSICAL_ADDR, %ebx | |
3447 | + subl $____LOAD_PHYSICAL_ADDR, %ebx | |
3448 | jz 2f /* Nothing to be done if loaded at compiled addr. */ | |
3449 | /* | |
3450 | * Process relocations. | |
3451 | */ | |
3452 | ||
3453 | 1: subl $4, %edi | |
3454 | - movl 0(%edi), %ecx | |
3455 | - testl %ecx, %ecx | |
3456 | - jz 2f | |
3457 | + movl (%edi), %ecx | |
3458 | + jecxz 2f | |
3459 | addl %ebx, -__PAGE_OFFSET(%ebx, %ecx) | |
3460 | jmp 1b | |
3461 | 2: | |
de855c5d AM |
3462 | diff -urNp linux-2.6.29.6/arch/x86/boot/compressed/misc.c linux-2.6.29.6/arch/x86/boot/compressed/misc.c |
3463 | --- linux-2.6.29.6/arch/x86/boot/compressed/misc.c 2009-07-02 19:41:20.000000000 -0400 | |
3464 | +++ linux-2.6.29.6/arch/x86/boot/compressed/misc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3465 | @@ -373,7 +373,7 @@ static void parse_elf(void *output) |
3466 | case PT_LOAD: | |
3467 | #ifdef CONFIG_RELOCATABLE | |
3468 | dest = output; | |
3469 | - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR); | |
3470 | + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR); | |
3471 | #else | |
3472 | dest = (void *)(phdr->p_paddr); | |
3473 | #endif | |
3474 | @@ -425,7 +425,7 @@ asmlinkage void decompress_kernel(void * | |
3475 | if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff)) | |
3476 | error("Destination address too large"); | |
3477 | #ifndef CONFIG_RELOCATABLE | |
3478 | - if ((u32)output != LOAD_PHYSICAL_ADDR) | |
3479 | + if ((u32)output != ____LOAD_PHYSICAL_ADDR) | |
3480 | error("Wrong destination address"); | |
3481 | #endif | |
3482 | #endif | |
de855c5d AM |
3483 | diff -urNp linux-2.6.29.6/arch/x86/boot/compressed/relocs.c linux-2.6.29.6/arch/x86/boot/compressed/relocs.c |
3484 | --- linux-2.6.29.6/arch/x86/boot/compressed/relocs.c 2009-07-02 19:41:20.000000000 -0400 | |
3485 | +++ linux-2.6.29.6/arch/x86/boot/compressed/relocs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3486 | @@ -10,8 +10,11 @@ |
3487 | #define USE_BSD | |
3488 | #include <endian.h> | |
3489 | ||
3490 | +#include "../../../../include/linux/autoconf.h" | |
3491 | + | |
3492 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
3493 | static Elf32_Ehdr ehdr; | |
3494 | +static Elf32_Phdr *phdr; | |
3495 | static unsigned long reloc_count, reloc_idx; | |
3496 | static unsigned long *relocs; | |
3497 | ||
3498 | @@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp) | |
3499 | } | |
3500 | } | |
3501 | ||
3502 | +static void read_phdrs(FILE *fp) | |
3503 | +{ | |
3504 | + int i; | |
3505 | + | |
3506 | + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr)); | |
3507 | + if (!phdr) { | |
3508 | + die("Unable to allocate %d program headers\n", | |
3509 | + ehdr.e_phnum); | |
3510 | + } | |
3511 | + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) { | |
3512 | + die("Seek to %d failed: %s\n", | |
3513 | + ehdr.e_phoff, strerror(errno)); | |
3514 | + } | |
3515 | + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) { | |
3516 | + die("Cannot read ELF program headers: %s\n", | |
3517 | + strerror(errno)); | |
3518 | + } | |
3519 | + for(i = 0; i < ehdr.e_phnum; i++) { | |
3520 | + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type); | |
3521 | + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset); | |
3522 | + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr); | |
3523 | + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr); | |
3524 | + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz); | |
3525 | + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz); | |
3526 | + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags); | |
3527 | + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align); | |
3528 | + } | |
3529 | + | |
3530 | +} | |
3531 | + | |
3532 | static void read_shdrs(FILE *fp) | |
3533 | { | |
3534 | int i; | |
3535 | @@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp) | |
3536 | static void read_relocs(FILE *fp) | |
3537 | { | |
3538 | int i,j; | |
3539 | + uint32_t base; | |
3540 | + | |
3541 | for (i = 0; i < ehdr.e_shnum; i++) { | |
3542 | struct section *sec = &secs[i]; | |
3543 | if (sec->shdr.sh_type != SHT_REL) { | |
3544 | @@ -360,9 +395,18 @@ static void read_relocs(FILE *fp) | |
3545 | die("Cannot read symbol table: %s\n", | |
3546 | strerror(errno)); | |
3547 | } | |
3548 | + base = 0; | |
3549 | + for (j = 0; j < ehdr.e_phnum; j++) { | |
3550 | + if (phdr[j].p_type != PT_LOAD ) | |
3551 | + continue; | |
3552 | + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz) | |
3553 | + continue; | |
3554 | + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr; | |
3555 | + break; | |
3556 | + } | |
3557 | for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) { | |
3558 | Elf32_Rel *rel = &sec->reltab[j]; | |
3559 | - rel->r_offset = elf32_to_cpu(rel->r_offset); | |
3560 | + rel->r_offset = elf32_to_cpu(rel->r_offset) + base; | |
3561 | rel->r_info = elf32_to_cpu(rel->r_info); | |
3562 | } | |
3563 | } | |
3564 | @@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El | |
3565 | if (sym->st_shndx == SHN_ABS) { | |
3566 | continue; | |
3567 | } | |
3568 | + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */ | |
3569 | + if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10)) | |
3570 | + continue; | |
3571 | +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32) | |
3572 | + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */ | |
3573 | + if (!strcmp(sec_name(sym->st_shndx), ".init.text")) | |
3574 | + continue; | |
3575 | + if (!strcmp(sec_name(sym->st_shndx), ".exit.text")) | |
3576 | + continue; | |
3577 | + if (!strcmp(sec_name(sym->st_shndx), ".text.head")) { | |
3578 | + if (strcmp(sym_name(sym_strtab, sym), "__init_end") && | |
3579 | + strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET")) | |
3580 | + continue; | |
3581 | + } | |
3582 | + if (!strcmp(sec_name(sym->st_shndx), ".text")) | |
3583 | + continue; | |
3584 | +#endif | |
3585 | if (r_type == R_386_PC32) { | |
3586 | /* PC relative relocations don't need to be adjusted */ | |
3587 | } | |
3588 | @@ -631,6 +692,7 @@ int main(int argc, char **argv) | |
3589 | fname, strerror(errno)); | |
3590 | } | |
3591 | read_ehdr(fp); | |
3592 | + read_phdrs(fp); | |
3593 | read_shdrs(fp); | |
3594 | read_strtabs(fp); | |
3595 | read_symtabs(fp); | |
de855c5d AM |
3596 | diff -urNp linux-2.6.29.6/arch/x86/boot/cpucheck.c linux-2.6.29.6/arch/x86/boot/cpucheck.c |
3597 | --- linux-2.6.29.6/arch/x86/boot/cpucheck.c 2009-07-02 19:41:20.000000000 -0400 | |
3598 | +++ linux-2.6.29.6/arch/x86/boot/cpucheck.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3599 | @@ -74,7 +74,7 @@ static int has_fpu(void) |
3600 | u16 fcw = -1, fsw = -1; | |
3601 | u32 cr0; | |
3602 | ||
3603 | - asm("movl %%cr0,%0" : "=r" (cr0)); | |
3604 | + asm volatile("movl %%cr0,%0" : "=r" (cr0)); | |
3605 | if (cr0 & (X86_CR0_EM|X86_CR0_TS)) { | |
3606 | cr0 &= ~(X86_CR0_EM|X86_CR0_TS); | |
3607 | asm volatile("movl %0,%%cr0" : : "r" (cr0)); | |
3608 | @@ -90,7 +90,7 @@ static int has_eflag(u32 mask) | |
3609 | { | |
3610 | u32 f0, f1; | |
3611 | ||
3612 | - asm("pushfl ; " | |
3613 | + asm volatile("pushfl ; " | |
3614 | "pushfl ; " | |
3615 | "popl %0 ; " | |
3616 | "movl %0,%1 ; " | |
3617 | @@ -115,7 +115,7 @@ static void get_flags(void) | |
3618 | set_bit(X86_FEATURE_FPU, cpu.flags); | |
3619 | ||
3620 | if (has_eflag(X86_EFLAGS_ID)) { | |
3621 | - asm("cpuid" | |
3622 | + asm volatile("cpuid" | |
3623 | : "=a" (max_intel_level), | |
3624 | "=b" (cpu_vendor[0]), | |
3625 | "=d" (cpu_vendor[1]), | |
3626 | @@ -124,7 +124,7 @@ static void get_flags(void) | |
3627 | ||
3628 | if (max_intel_level >= 0x00000001 && | |
3629 | max_intel_level <= 0x0000ffff) { | |
3630 | - asm("cpuid" | |
3631 | + asm volatile("cpuid" | |
3632 | : "=a" (tfms), | |
3633 | "=c" (cpu.flags[4]), | |
3634 | "=d" (cpu.flags[0]) | |
3635 | @@ -136,7 +136,7 @@ static void get_flags(void) | |
3636 | cpu.model += ((tfms >> 16) & 0xf) << 4; | |
3637 | } | |
3638 | ||
3639 | - asm("cpuid" | |
3640 | + asm volatile("cpuid" | |
3641 | : "=a" (max_amd_level) | |
3642 | : "a" (0x80000000) | |
3643 | : "ebx", "ecx", "edx"); | |
3644 | @@ -144,7 +144,7 @@ static void get_flags(void) | |
3645 | if (max_amd_level >= 0x80000001 && | |
3646 | max_amd_level <= 0x8000ffff) { | |
3647 | u32 eax = 0x80000001; | |
3648 | - asm("cpuid" | |
3649 | + asm volatile("cpuid" | |
3650 | : "+a" (eax), | |
3651 | "=c" (cpu.flags[6]), | |
3652 | "=d" (cpu.flags[1]) | |
3653 | @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r | |
3654 | u32 ecx = MSR_K7_HWCR; | |
3655 | u32 eax, edx; | |
3656 | ||
3657 | - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3658 | + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3659 | eax &= ~(1 << 15); | |
3660 | - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3661 | + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3662 | ||
3663 | get_flags(); /* Make sure it really did something */ | |
3664 | err = check_flags(); | |
3665 | @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r | |
3666 | u32 ecx = MSR_VIA_FCR; | |
3667 | u32 eax, edx; | |
3668 | ||
3669 | - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3670 | + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3671 | eax |= (1<<1)|(1<<7); | |
3672 | - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3673 | + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3674 | ||
3675 | set_bit(X86_FEATURE_CX8, cpu.flags); | |
3676 | err = check_flags(); | |
3677 | @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r | |
3678 | u32 eax, edx; | |
3679 | u32 level = 1; | |
3680 | ||
3681 | - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3682 | - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx)); | |
3683 | - asm("cpuid" | |
3684 | + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx)); | |
3685 | + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx)); | |
3686 | + asm volatile("cpuid" | |
3687 | : "+a" (level), "=d" (cpu.flags[0]) | |
3688 | : : "ecx", "ebx"); | |
3689 | - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3690 | + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx)); | |
3691 | ||
3692 | err = check_flags(); | |
3693 | } | |
de855c5d AM |
3694 | diff -urNp linux-2.6.29.6/arch/x86/boot/edd.c linux-2.6.29.6/arch/x86/boot/edd.c |
3695 | --- linux-2.6.29.6/arch/x86/boot/edd.c 2009-07-02 19:41:20.000000000 -0400 | |
3696 | +++ linux-2.6.29.6/arch/x86/boot/edd.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3697 | @@ -81,7 +81,7 @@ static int get_edd_info(u8 devno, struct |
3698 | ax = 0x4100; | |
3699 | bx = EDDMAGIC1; | |
3700 | dx = devno; | |
3701 | - asm("pushfl; stc; int $0x13; setc %%al; popfl" | |
3702 | + asm volatile("pushfl; stc; int $0x13; setc %%al; popfl" | |
3703 | : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx) | |
3704 | : : "esi", "edi"); | |
3705 | ||
3706 | @@ -100,7 +100,7 @@ static int get_edd_info(u8 devno, struct | |
3707 | ei->params.length = sizeof(ei->params); | |
3708 | ax = 0x4800; | |
3709 | dx = devno; | |
3710 | - asm("pushfl; int $0x13; popfl" | |
3711 | + asm volatile("pushfl; int $0x13; popfl" | |
3712 | : "+a" (ax), "+d" (dx), "=m" (ei->params) | |
3713 | : "S" (&ei->params) | |
3714 | : "ebx", "ecx", "edi"); | |
3715 | @@ -111,7 +111,7 @@ static int get_edd_info(u8 devno, struct | |
3716 | ax = 0x0800; | |
3717 | dx = devno; | |
3718 | di = 0; | |
3719 | - asm("pushw %%es; " | |
3720 | + asm volatile("pushw %%es; " | |
3721 | "movw %%di,%%es; " | |
3722 | "pushfl; stc; int $0x13; setc %%al; popfl; " | |
3723 | "popw %%es" | |
de855c5d AM |
3724 | diff -urNp linux-2.6.29.6/arch/x86/boot/main.c linux-2.6.29.6/arch/x86/boot/main.c |
3725 | --- linux-2.6.29.6/arch/x86/boot/main.c 2009-07-02 19:41:20.000000000 -0400 | |
3726 | +++ linux-2.6.29.6/arch/x86/boot/main.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3727 | @@ -78,7 +78,7 @@ static void query_ist(void) |
3728 | if (cpu.level < 6) | |
3729 | return; | |
3730 | ||
3731 | - asm("int $0x15" | |
3732 | + asm volatile("int $0x15" | |
3733 | : "=a" (boot_params.ist_info.signature), | |
3734 | "=b" (boot_params.ist_info.command), | |
3735 | "=c" (boot_params.ist_info.event), | |
de855c5d AM |
3736 | diff -urNp linux-2.6.29.6/arch/x86/boot/mca.c linux-2.6.29.6/arch/x86/boot/mca.c |
3737 | --- linux-2.6.29.6/arch/x86/boot/mca.c 2009-07-02 19:41:20.000000000 -0400 | |
3738 | +++ linux-2.6.29.6/arch/x86/boot/mca.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3739 | @@ -19,7 +19,7 @@ int query_mca(void) |
3740 | u8 err; | |
3741 | u16 es, bx, len; | |
3742 | ||
3743 | - asm("pushw %%es ; " | |
3744 | + asm volatile("pushw %%es ; " | |
3745 | "int $0x15 ; " | |
3746 | "setc %0 ; " | |
3747 | "movw %%es, %1 ; " | |
de855c5d AM |
3748 | diff -urNp linux-2.6.29.6/arch/x86/boot/memory.c linux-2.6.29.6/arch/x86/boot/memory.c |
3749 | --- linux-2.6.29.6/arch/x86/boot/memory.c 2009-07-02 19:41:20.000000000 -0400 | |
3750 | +++ linux-2.6.29.6/arch/x86/boot/memory.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 | 3751 | @@ -30,7 +30,7 @@ static int detect_memory_e820(void) |
de855c5d AM |
3752 | /* Important: %edx and %esi are clobbered by some BIOSes, |
3753 | so they must be either used for the error output | |
2380c486 JR |
3754 | or explicitly marked clobbered. */ |
3755 | - asm("int $0x15; setc %0" | |
3756 | + asm volatile("int $0x15; setc %0" | |
3757 | : "=d" (err), "+b" (next), "=a" (id), "+c" (size), | |
3758 | "=m" (*desc) | |
de855c5d AM |
3759 | : "D" (desc), "d" (SMAP), "a" (0xe820) |
3760 | @@ -66,7 +66,7 @@ static int detect_memory_e801(void) | |
2380c486 JR |
3761 | |
3762 | bx = cx = dx = 0; | |
3763 | ax = 0xe801; | |
3764 | - asm("stc; int $0x15; setc %0" | |
3765 | + asm volatile("stc; int $0x15; setc %0" | |
3766 | : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx)); | |
3767 | ||
3768 | if (err) | |
de855c5d | 3769 | @@ -96,7 +96,7 @@ static int detect_memory_88(void) |
2380c486 JR |
3770 | u8 err; |
3771 | ||
3772 | ax = 0x8800; | |
3773 | - asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax)); | |
3774 | + asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax)); | |
3775 | ||
3776 | boot_params.screen_info.ext_mem_k = ax; | |
3777 | ||
de855c5d AM |
3778 | diff -urNp linux-2.6.29.6/arch/x86/boot/video.c linux-2.6.29.6/arch/x86/boot/video.c |
3779 | --- linux-2.6.29.6/arch/x86/boot/video.c 2009-07-02 19:41:20.000000000 -0400 | |
3780 | +++ linux-2.6.29.6/arch/x86/boot/video.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3781 | @@ -23,7 +23,7 @@ static void store_cursor_position(void) |
3782 | ||
3783 | ax = 0x0300; | |
3784 | bx = 0; | |
3785 | - asm(INT10 | |
3786 | + asm volatile(INT10 | |
3787 | : "=d" (curpos), "+a" (ax), "+b" (bx) | |
3788 | : : "ecx", "esi", "edi"); | |
3789 | ||
3790 | @@ -38,7 +38,7 @@ static void store_video_mode(void) | |
3791 | /* N.B.: the saving of the video page here is a bit silly, | |
3792 | since we pretty much assume page 0 everywhere. */ | |
3793 | ax = 0x0f00; | |
3794 | - asm(INT10 | |
3795 | + asm volatile(INT10 | |
3796 | : "+a" (ax), "=b" (page) | |
3797 | : : "ecx", "edx", "esi", "edi"); | |
3798 | ||
de855c5d AM |
3799 | diff -urNp linux-2.6.29.6/arch/x86/boot/video-vesa.c linux-2.6.29.6/arch/x86/boot/video-vesa.c |
3800 | --- linux-2.6.29.6/arch/x86/boot/video-vesa.c 2009-07-02 19:41:20.000000000 -0400 | |
3801 | +++ linux-2.6.29.6/arch/x86/boot/video-vesa.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3802 | @@ -41,7 +41,7 @@ static int vesa_probe(void) |
3803 | ||
3804 | ax = 0x4f00; | |
3805 | di = (size_t)&vginfo; | |
3806 | - asm(INT10 | |
3807 | + asm volatile(INT10 | |
3808 | : "+a" (ax), "+D" (di), "=m" (vginfo) | |
3809 | : : "ebx", "ecx", "edx", "esi"); | |
3810 | ||
3811 | @@ -68,7 +68,7 @@ static int vesa_probe(void) | |
3812 | ax = 0x4f01; | |
3813 | cx = mode; | |
3814 | di = (size_t)&vminfo; | |
3815 | - asm(INT10 | |
3816 | + asm volatile(INT10 | |
3817 | : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo) | |
3818 | : : "ebx", "edx", "esi"); | |
3819 | ||
3820 | @@ -120,7 +120,7 @@ static int vesa_set_mode(struct mode_inf | |
3821 | ax = 0x4f01; | |
3822 | cx = vesa_mode; | |
3823 | di = (size_t)&vminfo; | |
3824 | - asm(INT10 | |
3825 | + asm volatile(INT10 | |
3826 | : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo) | |
3827 | : : "ebx", "edx", "esi"); | |
3828 | ||
3829 | @@ -202,19 +202,20 @@ static void vesa_dac_set_8bits(void) | |
3830 | /* Save the VESA protected mode info */ | |
3831 | static void vesa_store_pm_info(void) | |
3832 | { | |
3833 | - u16 ax, bx, di, es; | |
3834 | + u16 ax, bx, cx, di, es; | |
3835 | ||
3836 | ax = 0x4f0a; | |
3837 | - bx = di = 0; | |
3838 | - asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es" | |
3839 | - : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di) | |
3840 | - : : "ecx", "esi"); | |
3841 | + bx = cx = di = 0; | |
3842 | + asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es" | |
3843 | + : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di) | |
3844 | + : : "esi"); | |
3845 | ||
3846 | if (ax != 0x004f) | |
3847 | return; | |
3848 | ||
3849 | boot_params.screen_info.vesapm_seg = es; | |
3850 | boot_params.screen_info.vesapm_off = di; | |
3851 | + boot_params.screen_info.vesapm_size = cx; | |
3852 | } | |
3853 | ||
3854 | /* | |
3855 | @@ -268,7 +269,7 @@ void vesa_store_edid(void) | |
3856 | /* Note: The VBE DDC spec is different from the main VESA spec; | |
3857 | we genuinely have to assume all registers are destroyed here. */ | |
3858 | ||
3859 | - asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es" | |
3860 | + asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es" | |
3861 | : "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di) | |
3862 | : : "esi", "edx"); | |
3863 | ||
3864 | @@ -283,7 +284,7 @@ void vesa_store_edid(void) | |
3865 | cx = 0; /* Controller 0 */ | |
3866 | dx = 0; /* EDID block number */ | |
3867 | di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */ | |
3868 | - asm(INT10 | |
3869 | + asm volatile(INT10 | |
3870 | : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info), | |
3871 | "+c" (cx), "+D" (di) | |
3872 | : : "esi"); | |
de855c5d AM |
3873 | diff -urNp linux-2.6.29.6/arch/x86/boot/video-vga.c linux-2.6.29.6/arch/x86/boot/video-vga.c |
3874 | --- linux-2.6.29.6/arch/x86/boot/video-vga.c 2009-07-02 19:41:20.000000000 -0400 | |
3875 | +++ linux-2.6.29.6/arch/x86/boot/video-vga.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3876 | @@ -225,7 +225,7 @@ static int vga_probe(void) |
3877 | }; | |
3878 | u8 vga_flag; | |
3879 | ||
3880 | - asm(INT10 | |
3881 | + asm volatile(INT10 | |
3882 | : "=b" (ega_bx) | |
3883 | : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ | |
3884 | : "ecx", "edx", "esi", "edi"); | |
3885 | @@ -237,7 +237,7 @@ static int vga_probe(void) | |
3886 | /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ | |
3887 | if ((u8)ega_bx != 0x10) { | |
3888 | /* EGA/VGA */ | |
3889 | - asm(INT10 | |
3890 | + asm volatile(INT10 | |
3891 | : "=a" (vga_flag) | |
3892 | : "a" (0x1a00) | |
3893 | : "ebx", "ecx", "edx", "esi", "edi"); | |
de855c5d AM |
3894 | diff -urNp linux-2.6.29.6/arch/x86/boot/voyager.c linux-2.6.29.6/arch/x86/boot/voyager.c |
3895 | --- linux-2.6.29.6/arch/x86/boot/voyager.c 2009-07-02 19:41:20.000000000 -0400 | |
3896 | +++ linux-2.6.29.6/arch/x86/boot/voyager.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3897 | @@ -23,7 +23,7 @@ int query_voyager(void) |
3898 | ||
3899 | data_ptr[0] = 0xff; /* Flag on config not found(?) */ | |
3900 | ||
3901 | - asm("pushw %%es ; " | |
3902 | + asm volatile("pushw %%es ; " | |
3903 | "int $0x15 ; " | |
3904 | "setc %0 ; " | |
3905 | "movw %%es, %1 ; " | |
de855c5d AM |
3906 | diff -urNp linux-2.6.29.6/arch/x86/ia32/ia32_signal.c linux-2.6.29.6/arch/x86/ia32/ia32_signal.c |
3907 | --- linux-2.6.29.6/arch/x86/ia32/ia32_signal.c 2009-07-02 19:41:20.000000000 -0400 | |
3908 | +++ linux-2.6.29.6/arch/x86/ia32/ia32_signal.c 2009-07-09 22:13:39.000000000 -0400 | |
3909 | @@ -387,7 +387,7 @@ static void __user *get_sigframe(struct | |
3910 | sp -= frame_size; | |
3911 | /* Align the stack pointer according to the i386 ABI, | |
3912 | * i.e. so that on function entry ((sp + 4) & 15) == 0. */ | |
3913 | - sp = ((sp + 4) & -16ul) - 4; | |
3914 | + sp = ((sp - 12) & -16ul) - 4; | |
3915 | return (void __user *) sp; | |
3916 | } | |
3917 | ||
3918 | @@ -464,7 +464,7 @@ int ia32_setup_frame(int sig, struct k_s | |
3919 | ||
3920 | #if DEBUG_SIG | |
3921 | printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", | |
3922 | - current->comm, current->pid, frame, regs->ip, frame->pretcode); | |
3923 | + current->comm, task_pid_nr(current), frame, regs->ip, frame->pretcode); | |
3924 | #endif | |
3925 | ||
3926 | return 0; | |
3927 | @@ -488,7 +488,7 @@ int ia32_setup_rt_frame(int sig, struct | |
3928 | 0xb8, | |
2380c486 JR |
3929 | __NR_ia32_rt_sigreturn, |
3930 | 0x80cd, | |
de855c5d | 3931 | - 0, |
2380c486 JR |
3932 | + 0 |
3933 | }; | |
3934 | ||
3935 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); | |
de855c5d AM |
3936 | @@ -551,7 +551,7 @@ int ia32_setup_rt_frame(int sig, struct |
3937 | ||
3938 | #if DEBUG_SIG | |
3939 | printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", | |
3940 | - current->comm, current->pid, frame, regs->ip, frame->pretcode); | |
3941 | + current->comm, task_pid_nr(current), frame, regs->ip, frame->pretcode); | |
3942 | #endif | |
3943 | ||
3944 | return 0; | |
3945 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/alternative.h linux-2.6.29.6/arch/x86/include/asm/alternative.h | |
3946 | --- linux-2.6.29.6/arch/x86/include/asm/alternative.h 2009-07-02 19:41:20.000000000 -0400 | |
3947 | +++ linux-2.6.29.6/arch/x86/include/asm/alternative.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3948 | @@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab |
3949 | " .byte 662b-661b\n" /* sourcelen */ \ | |
3950 | " .byte 664f-663f\n" /* replacementlen */ \ | |
3951 | ".previous\n" \ | |
3952 | - ".section .altinstr_replacement,\"ax\"\n" \ | |
3953 | + ".section .altinstr_replacement,\"a\"\n" \ | |
3954 | "663:\n\t" newinstr "\n664:\n" /* replacement */ \ | |
3955 | ".previous" :: "i" (feature) : "memory") | |
3956 | ||
3957 | @@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab | |
3958 | " .byte 662b-661b\n" /* sourcelen */ \ | |
3959 | " .byte 664f-663f\n" /* replacementlen */ \ | |
3960 | ".previous\n" \ | |
3961 | - ".section .altinstr_replacement,\"ax\"\n" \ | |
3962 | + ".section .altinstr_replacement,\"a\"\n" \ | |
3963 | "663:\n\t" newinstr "\n664:\n" /* replacement */ \ | |
3964 | ".previous" :: "i" (feature), ##input) | |
3965 | ||
3966 | @@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab | |
3967 | " .byte 662b-661b\n" /* sourcelen */ \ | |
3968 | " .byte 664f-663f\n" /* replacementlen */ \ | |
3969 | ".previous\n" \ | |
3970 | - ".section .altinstr_replacement,\"ax\"\n" \ | |
3971 | + ".section .altinstr_replacement,\"a\"\n" \ | |
3972 | "663:\n\t" newinstr "\n664:\n" /* replacement */ \ | |
3973 | ".previous" : output : [feat] "i" (feature), ##input) | |
3974 | ||
de855c5d AM |
3975 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/atomic_32.h linux-2.6.29.6/arch/x86/include/asm/atomic_32.h |
3976 | --- linux-2.6.29.6/arch/x86/include/asm/atomic_32.h 2009-07-02 19:41:20.000000000 -0400 | |
3977 | +++ linux-2.6.29.6/arch/x86/include/asm/atomic_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
3978 | @@ -39,7 +39,29 @@ |
3979 | */ | |
3980 | static inline void atomic_add(int i, atomic_t *v) | |
3981 | { | |
3982 | - asm volatile(LOCK_PREFIX "addl %1,%0" | |
3983 | + asm volatile(LOCK_PREFIX "addl %1,%0\n" | |
3984 | + | |
3985 | +#ifdef CONFIG_PAX_REFCOUNT | |
3986 | + "jno 0f\n" | |
3987 | + LOCK_PREFIX "subl %1,%0\n" | |
3988 | + "into\n0:\n" | |
3989 | + _ASM_EXTABLE(0b, 0b) | |
3990 | +#endif | |
3991 | + | |
3992 | + : "+m" (v->counter) | |
3993 | + : "ir" (i)); | |
3994 | +} | |
3995 | + | |
3996 | +/** | |
3997 | + * atomic_add_unchecked - add integer to atomic variable | |
3998 | + * @i: integer value to add | |
3999 | + * @v: pointer of type atomic_t | |
4000 | + * | |
4001 | + * Atomically adds @i to @v. | |
4002 | + */ | |
de855c5d | 4003 | +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v) |
2380c486 JR |
4004 | +{ |
4005 | + asm volatile(LOCK_PREFIX "addl %1,%0\n" | |
4006 | : "+m" (v->counter) | |
4007 | : "ir" (i)); | |
4008 | } | |
de855c5d | 4009 | @@ -53,7 +75,29 @@ static inline void atomic_add(int i, ato |
2380c486 JR |
4010 | */ |
4011 | static inline void atomic_sub(int i, atomic_t *v) | |
4012 | { | |
4013 | - asm volatile(LOCK_PREFIX "subl %1,%0" | |
4014 | + asm volatile(LOCK_PREFIX "subl %1,%0\n" | |
4015 | + | |
4016 | +#ifdef CONFIG_PAX_REFCOUNT | |
4017 | + "jno 0f\n" | |
4018 | + LOCK_PREFIX "addl %1,%0\n" | |
4019 | + "into\n0:\n" | |
4020 | + _ASM_EXTABLE(0b, 0b) | |
4021 | +#endif | |
4022 | + | |
de855c5d AM |
4023 | + : "+m" (v->counter) |
4024 | + : "ir" (i)); | |
4025 | +} | |
4026 | + | |
4027 | +/** | |
4028 | + * atomic_sub_unchecked - subtract integer from atomic variable | |
4029 | + * @i: integer value to subtract | |
4030 | + * @v: pointer of type atomic_t | |
4031 | + * | |
4032 | + * Atomically subtracts @i from @v. | |
4033 | + */ | |
4034 | +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v) | |
4035 | +{ | |
4036 | + asm volatile(LOCK_PREFIX "subl %1,%0\n" | |
2380c486 JR |
4037 | : "+m" (v->counter) |
4038 | : "ir" (i)); | |
4039 | } | |
de855c5d | 4040 | @@ -71,7 +115,16 @@ static inline int atomic_sub_and_test(in |
2380c486 JR |
4041 | { |
4042 | unsigned char c; | |
4043 | ||
4044 | - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1" | |
4045 | + asm volatile(LOCK_PREFIX "subl %2,%0\n" | |
4046 | + | |
4047 | +#ifdef CONFIG_PAX_REFCOUNT | |
4048 | + "jno 0f\n" | |
4049 | + LOCK_PREFIX "addl %2,%0\n" | |
4050 | + "into\n0:\n" | |
4051 | + _ASM_EXTABLE(0b, 0b) | |
4052 | +#endif | |
4053 | + | |
4054 | + "sete %1\n" | |
4055 | : "+m" (v->counter), "=qm" (c) | |
4056 | : "ir" (i) : "memory"); | |
4057 | return c; | |
de855c5d | 4058 | @@ -85,7 +138,30 @@ static inline int atomic_sub_and_test(in |
2380c486 JR |
4059 | */ |
4060 | static inline void atomic_inc(atomic_t *v) | |
4061 | { | |
4062 | - asm volatile(LOCK_PREFIX "incl %0" | |
4063 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
4064 | + | |
4065 | +#ifdef CONFIG_PAX_REFCOUNT | |
4066 | + "into\n0:\n" | |
4067 | + ".pushsection .fixup,\"ax\"\n" | |
4068 | + "1:\n" | |
4069 | + LOCK_PREFIX "decl %0\n" | |
4070 | + "jmp 0b\n" | |
4071 | + ".popsection\n" | |
4072 | + _ASM_EXTABLE(0b, 1b) | |
4073 | +#endif | |
4074 | + | |
de855c5d AM |
4075 | + : "+m" (v->counter)); |
4076 | +} | |
4077 | + | |
4078 | +/** | |
4079 | + * atomic_inc_unchecked - increment atomic variable | |
4080 | + * @v: pointer of type atomic_t | |
4081 | + * | |
4082 | + * Atomically increments @v by 1. | |
4083 | + */ | |
4084 | +static inline void atomic_inc_unchecked(atomic_unchecked_t *v) | |
4085 | +{ | |
4086 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
2380c486 JR |
4087 | : "+m" (v->counter)); |
4088 | } | |
4089 | ||
de855c5d | 4090 | @@ -97,7 +173,18 @@ static inline void atomic_inc(atomic_t * |
2380c486 JR |
4091 | */ |
4092 | static inline void atomic_dec(atomic_t *v) | |
4093 | { | |
4094 | - asm volatile(LOCK_PREFIX "decl %0" | |
4095 | + asm volatile(LOCK_PREFIX "decl %0\n" | |
4096 | + | |
4097 | +#ifdef CONFIG_PAX_REFCOUNT | |
4098 | + "into\n0:\n" | |
4099 | + ".pushsection .fixup,\"ax\"\n" | |
4100 | + "1: \n" | |
4101 | + LOCK_PREFIX "incl %0\n" | |
4102 | + "jmp 0b\n" | |
4103 | + ".popsection\n" | |
4104 | + _ASM_EXTABLE(0b, 1b) | |
4105 | +#endif | |
4106 | + | |
4107 | : "+m" (v->counter)); | |
4108 | } | |
4109 | ||
de855c5d | 4110 | @@ -113,7 +200,19 @@ static inline int atomic_dec_and_test(at |
2380c486 JR |
4111 | { |
4112 | unsigned char c; | |
4113 | ||
4114 | - asm volatile(LOCK_PREFIX "decl %0; sete %1" | |
4115 | + asm volatile(LOCK_PREFIX "decl %0\n" | |
4116 | + | |
4117 | +#ifdef CONFIG_PAX_REFCOUNT | |
4118 | + "into\n0:\n" | |
4119 | + ".pushsection .fixup,\"ax\"\n" | |
4120 | + "1: \n" | |
4121 | + LOCK_PREFIX "incl %0\n" | |
4122 | + "jmp 0b\n" | |
4123 | + ".popsection\n" | |
4124 | + _ASM_EXTABLE(0b, 1b) | |
4125 | +#endif | |
4126 | + | |
4127 | + "sete %1\n" | |
4128 | : "+m" (v->counter), "=qm" (c) | |
4129 | : : "memory"); | |
4130 | return c != 0; | |
de855c5d | 4131 | @@ -131,7 +230,19 @@ static inline int atomic_inc_and_test(at |
2380c486 JR |
4132 | { |
4133 | unsigned char c; | |
4134 | ||
4135 | - asm volatile(LOCK_PREFIX "incl %0; sete %1" | |
4136 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
4137 | + | |
4138 | +#ifdef CONFIG_PAX_REFCOUNT | |
4139 | + "into\n0:\n" | |
4140 | + ".pushsection .fixup,\"ax\"\n" | |
4141 | + "1: \n" | |
4142 | + LOCK_PREFIX "decl %0\n" | |
4143 | + "jmp 0b\n" | |
4144 | + ".popsection\n" | |
4145 | + _ASM_EXTABLE(0b, 1b) | |
4146 | +#endif | |
4147 | + | |
4148 | + "sete %1\n" | |
4149 | : "+m" (v->counter), "=qm" (c) | |
4150 | : : "memory"); | |
4151 | return c != 0; | |
de855c5d | 4152 | @@ -150,7 +261,16 @@ static inline int atomic_add_negative(in |
2380c486 JR |
4153 | { |
4154 | unsigned char c; | |
4155 | ||
4156 | - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1" | |
4157 | + asm volatile(LOCK_PREFIX "addl %2,%0\n" | |
4158 | + | |
4159 | +#ifdef CONFIG_PAX_REFCOUNT | |
4160 | + "jno 0f\n" | |
4161 | + LOCK_PREFIX "subl %2,%0\n" | |
4162 | + "into\n0:\n" | |
4163 | + _ASM_EXTABLE(0b, 0b) | |
4164 | +#endif | |
4165 | + | |
4166 | + "sets %1\n" | |
4167 | : "+m" (v->counter), "=qm" (c) | |
4168 | : "ir" (i) : "memory"); | |
4169 | return c; | |
de855c5d | 4170 | @@ -173,7 +293,15 @@ static inline int atomic_add_return(int |
2380c486 JR |
4171 | #endif |
4172 | /* Modern 486+ processor */ | |
4173 | __i = i; | |
4174 | - asm volatile(LOCK_PREFIX "xaddl %0, %1" | |
4175 | + asm volatile(LOCK_PREFIX "xaddl %0, %1\n" | |
4176 | + | |
4177 | +#ifdef CONFIG_PAX_REFCOUNT | |
4178 | + "jno 0f\n" | |
4179 | + "movl %0, %1\n" | |
4180 | + "into\n0:\n" | |
4181 | + _ASM_EXTABLE(0b, 0b) | |
4182 | +#endif | |
4183 | + | |
4184 | : "+r" (i), "+m" (v->counter) | |
4185 | : : "memory"); | |
4186 | return i + __i; | |
de855c5d | 4187 | @@ -214,17 +342,28 @@ static inline int atomic_sub_return(int |
2380c486 JR |
4188 | */ |
4189 | static inline int atomic_add_unless(atomic_t *v, int a, int u) | |
4190 | { | |
4191 | - int c, old; | |
4192 | + int c, old, new; | |
4193 | c = atomic_read(v); | |
4194 | for (;;) { | |
4195 | - if (unlikely(c == (u))) | |
4196 | + if (unlikely(c == u)) | |
4197 | break; | |
4198 | - old = atomic_cmpxchg((v), c, c + (a)); | |
4199 | + | |
4200 | + asm volatile("addl %2,%0\n" | |
4201 | + | |
4202 | +#ifdef CONFIG_PAX_REFCOUNT | |
4203 | + "into\n0:\n" | |
4204 | + _ASM_EXTABLE(0b, 0b) | |
4205 | +#endif | |
4206 | + | |
4207 | + : "=r" (new) | |
4208 | + : "0" (c), "ir" (a)); | |
4209 | + | |
4210 | + old = atomic_cmpxchg(v, c, new); | |
4211 | if (likely(old == c)) | |
4212 | break; | |
4213 | c = old; | |
4214 | } | |
4215 | - return c != (u); | |
4216 | + return c != u; | |
4217 | } | |
4218 | ||
4219 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | |
de855c5d AM |
4220 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/atomic_64.h linux-2.6.29.6/arch/x86/include/asm/atomic_64.h |
4221 | --- linux-2.6.29.6/arch/x86/include/asm/atomic_64.h 2009-07-02 19:41:20.000000000 -0400 | |
4222 | +++ linux-2.6.29.6/arch/x86/include/asm/atomic_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4223 | @@ -38,7 +38,29 @@ |
4224 | */ | |
4225 | static inline void atomic_add(int i, atomic_t *v) | |
4226 | { | |
4227 | - asm volatile(LOCK_PREFIX "addl %1,%0" | |
4228 | + asm volatile(LOCK_PREFIX "addl %1,%0\n" | |
4229 | + | |
4230 | +#ifdef CONFIG_PAX_REFCOUNT | |
4231 | + "jno 0f\n" | |
4232 | + LOCK_PREFIX "subl %1,%0\n" | |
4233 | + "int $4\n0:\n" | |
4234 | + _ASM_EXTABLE(0b, 0b) | |
4235 | +#endif | |
4236 | + | |
4237 | + : "=m" (v->counter) | |
4238 | + : "ir" (i), "m" (v->counter)); | |
4239 | +} | |
4240 | + | |
4241 | +/** | |
4242 | + * atomic_add_unchecked - add integer to atomic variable | |
4243 | + * @i: integer value to add | |
4244 | + * @v: pointer of type atomic_t | |
4245 | + * | |
4246 | + * Atomically adds @i to @v. | |
4247 | + */ | |
de855c5d | 4248 | +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v) |
2380c486 JR |
4249 | +{ |
4250 | + asm volatile(LOCK_PREFIX "addl %1,%0\n" | |
4251 | : "=m" (v->counter) | |
4252 | : "ir" (i), "m" (v->counter)); | |
4253 | } | |
de855c5d | 4254 | @@ -52,7 +74,29 @@ static inline void atomic_add(int i, ato |
2380c486 JR |
4255 | */ |
4256 | static inline void atomic_sub(int i, atomic_t *v) | |
4257 | { | |
4258 | - asm volatile(LOCK_PREFIX "subl %1,%0" | |
4259 | + asm volatile(LOCK_PREFIX "subl %1,%0\n" | |
4260 | + | |
4261 | +#ifdef CONFIG_PAX_REFCOUNT | |
4262 | + "jno 0f\n" | |
4263 | + LOCK_PREFIX "addl %1,%0\n" | |
4264 | + "int $4\n0:\n" | |
4265 | + _ASM_EXTABLE(0b, 0b) | |
4266 | +#endif | |
4267 | + | |
de855c5d AM |
4268 | + : "=m" (v->counter) |
4269 | + : "ir" (i), "m" (v->counter)); | |
4270 | +} | |
4271 | + | |
4272 | +/** | |
4273 | + * atomic_sub_unchecked - subtract the atomic variable | |
4274 | + * @i: integer value to subtract | |
4275 | + * @v: pointer of type atomic_t | |
4276 | + * | |
4277 | + * Atomically subtracts @i from @v. | |
4278 | + */ | |
4279 | +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v) | |
4280 | +{ | |
4281 | + asm volatile(LOCK_PREFIX "subl %1,%0\n" | |
2380c486 JR |
4282 | : "=m" (v->counter) |
4283 | : "ir" (i), "m" (v->counter)); | |
4284 | } | |
de855c5d | 4285 | @@ -70,7 +114,16 @@ static inline int atomic_sub_and_test(in |
2380c486 JR |
4286 | { |
4287 | unsigned char c; | |
4288 | ||
4289 | - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1" | |
4290 | + asm volatile(LOCK_PREFIX "subl %2,%0\n" | |
4291 | + | |
4292 | +#ifdef CONFIG_PAX_REFCOUNT | |
4293 | + "jno 0f\n" | |
4294 | + LOCK_PREFIX "addl %2,%0\n" | |
4295 | + "int $4\n0:\n" | |
4296 | + _ASM_EXTABLE(0b, 0b) | |
4297 | +#endif | |
4298 | + | |
4299 | + "sete %1\n" | |
4300 | : "=m" (v->counter), "=qm" (c) | |
4301 | : "ir" (i), "m" (v->counter) : "memory"); | |
4302 | return c; | |
de855c5d | 4303 | @@ -84,7 +137,32 @@ static inline int atomic_sub_and_test(in |
2380c486 JR |
4304 | */ |
4305 | static inline void atomic_inc(atomic_t *v) | |
4306 | { | |
4307 | - asm volatile(LOCK_PREFIX "incl %0" | |
4308 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
4309 | + | |
4310 | +#ifdef CONFIG_PAX_REFCOUNT | |
4311 | + "jno 0f\n" | |
4312 | + "int $4\n0:\n" | |
4313 | + ".pushsection .fixup,\"ax\"\n" | |
4314 | + "1:\n" | |
4315 | + LOCK_PREFIX "decl %0\n" | |
4316 | + "jmp 0b\n" | |
4317 | + ".popsection\n" | |
4318 | + _ASM_EXTABLE(0b, 1b) | |
4319 | +#endif | |
4320 | + | |
de855c5d AM |
4321 | + : "=m" (v->counter) |
4322 | + : "m" (v->counter)); | |
4323 | +} | |
4324 | + | |
4325 | +/** | |
4326 | + * atomic_inc_unchecked - increment atomic variable | |
4327 | + * @v: pointer of type atomic_t | |
4328 | + * | |
4329 | + * Atomically increments @v by 1. | |
4330 | + */ | |
4331 | +static inline void atomic_inc_unchecked(atomic_unchecked_t *v) | |
4332 | +{ | |
4333 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
2380c486 JR |
4334 | : "=m" (v->counter) |
4335 | : "m" (v->counter)); | |
4336 | } | |
de855c5d | 4337 | @@ -97,7 +175,19 @@ static inline void atomic_inc(atomic_t * |
2380c486 JR |
4338 | */ |
4339 | static inline void atomic_dec(atomic_t *v) | |
4340 | { | |
4341 | - asm volatile(LOCK_PREFIX "decl %0" | |
4342 | + asm volatile(LOCK_PREFIX "decl %0\n" | |
4343 | + | |
4344 | +#ifdef CONFIG_PAX_REFCOUNT | |
4345 | + "jno 0f\n" | |
4346 | + "int $4\n0:\n" | |
4347 | + ".pushsection .fixup,\"ax\"\n" | |
4348 | + "1: \n" | |
4349 | + LOCK_PREFIX "incl %0\n" | |
4350 | + "jmp 0b\n" | |
4351 | + ".popsection\n" | |
4352 | + _ASM_EXTABLE(0b, 1b) | |
4353 | +#endif | |
4354 | + | |
4355 | : "=m" (v->counter) | |
4356 | : "m" (v->counter)); | |
4357 | } | |
de855c5d | 4358 | @@ -114,7 +204,20 @@ static inline int atomic_dec_and_test(at |
2380c486 JR |
4359 | { |
4360 | unsigned char c; | |
4361 | ||
4362 | - asm volatile(LOCK_PREFIX "decl %0; sete %1" | |
4363 | + asm volatile(LOCK_PREFIX "decl %0\n" | |
4364 | + | |
4365 | +#ifdef CONFIG_PAX_REFCOUNT | |
4366 | + "jno 0f\n" | |
4367 | + "int $4\n0:\n" | |
4368 | + ".pushsection .fixup,\"ax\"\n" | |
4369 | + "1: \n" | |
4370 | + LOCK_PREFIX "incl %0\n" | |
4371 | + "jmp 0b\n" | |
4372 | + ".popsection\n" | |
4373 | + _ASM_EXTABLE(0b, 1b) | |
4374 | +#endif | |
4375 | + | |
4376 | + "sete %1\n" | |
4377 | : "=m" (v->counter), "=qm" (c) | |
4378 | : "m" (v->counter) : "memory"); | |
4379 | return c != 0; | |
de855c5d | 4380 | @@ -132,7 +235,20 @@ static inline int atomic_inc_and_test(at |
2380c486 JR |
4381 | { |
4382 | unsigned char c; | |
4383 | ||
4384 | - asm volatile(LOCK_PREFIX "incl %0; sete %1" | |
4385 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
4386 | + | |
4387 | +#ifdef CONFIG_PAX_REFCOUNT | |
4388 | + "jno 0f\n" | |
4389 | + "int $4\n0:\n" | |
4390 | + ".pushsection .fixup,\"ax\"\n" | |
4391 | + "1: \n" | |
4392 | + LOCK_PREFIX "decl %0\n" | |
4393 | + "jmp 0b\n" | |
4394 | + ".popsection\n" | |
4395 | + _ASM_EXTABLE(0b, 1b) | |
4396 | +#endif | |
4397 | + | |
4398 | + "sete %1\n" | |
4399 | : "=m" (v->counter), "=qm" (c) | |
4400 | : "m" (v->counter) : "memory"); | |
4401 | return c != 0; | |
de855c5d | 4402 | @@ -151,7 +267,16 @@ static inline int atomic_add_negative(in |
2380c486 JR |
4403 | { |
4404 | unsigned char c; | |
4405 | ||
4406 | - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1" | |
4407 | + asm volatile(LOCK_PREFIX "addl %2,%0\n" | |
4408 | + | |
4409 | +#ifdef CONFIG_PAX_REFCOUNT | |
4410 | + "jno 0f\n" | |
4411 | + LOCK_PREFIX "subl %2,%0\n" | |
4412 | + "int $4\n0:\n" | |
4413 | + _ASM_EXTABLE(0b, 0b) | |
4414 | +#endif | |
4415 | + | |
4416 | + "sets %1\n" | |
4417 | : "=m" (v->counter), "=qm" (c) | |
4418 | : "ir" (i), "m" (v->counter) : "memory"); | |
4419 | return c; | |
de855c5d | 4420 | @@ -167,7 +292,15 @@ static inline int atomic_add_negative(in |
2380c486 JR |
4421 | static inline int atomic_add_return(int i, atomic_t *v) |
4422 | { | |
4423 | int __i = i; | |
4424 | - asm volatile(LOCK_PREFIX "xaddl %0, %1" | |
4425 | + asm volatile(LOCK_PREFIX "xaddl %0, %1\n" | |
4426 | + | |
4427 | +#ifdef CONFIG_PAX_REFCOUNT | |
4428 | + "jno 0f\n" | |
4429 | + "movl %0, %1\n" | |
4430 | + "int $4\n0:\n" | |
4431 | + _ASM_EXTABLE(0b, 0b) | |
4432 | +#endif | |
4433 | + | |
4434 | : "+r" (i), "+m" (v->counter) | |
4435 | : : "memory"); | |
4436 | return i + __i; | |
de855c5d | 4437 | @@ -212,7 +345,15 @@ static inline int atomic_sub_return(int |
2380c486 JR |
4438 | */ |
4439 | static inline void atomic64_add(long i, atomic64_t *v) | |
4440 | { | |
4441 | - asm volatile(LOCK_PREFIX "addq %1,%0" | |
4442 | + asm volatile(LOCK_PREFIX "addq %1,%0\n" | |
4443 | + | |
4444 | +#ifdef CONFIG_PAX_REFCOUNT | |
4445 | + "jno 0f\n" | |
4446 | + LOCK_PREFIX "subq %1,%0\n" | |
4447 | + "int $4\n0:\n" | |
4448 | + _ASM_EXTABLE(0b, 0b) | |
4449 | +#endif | |
4450 | + | |
4451 | : "=m" (v->counter) | |
4452 | : "er" (i), "m" (v->counter)); | |
4453 | } | |
de855c5d | 4454 | @@ -226,7 +367,15 @@ static inline void atomic64_add(long i, |
2380c486 JR |
4455 | */ |
4456 | static inline void atomic64_sub(long i, atomic64_t *v) | |
4457 | { | |
4458 | - asm volatile(LOCK_PREFIX "subq %1,%0" | |
4459 | + asm volatile(LOCK_PREFIX "subq %1,%0\n" | |
4460 | + | |
4461 | +#ifdef CONFIG_PAX_REFCOUNT | |
4462 | + "jno 0f\n" | |
4463 | + LOCK_PREFIX "addq %1,%0\n" | |
4464 | + "int $4\n0:\n" | |
4465 | + _ASM_EXTABLE(0b, 0b) | |
4466 | +#endif | |
4467 | + | |
4468 | : "=m" (v->counter) | |
4469 | : "er" (i), "m" (v->counter)); | |
4470 | } | |
de855c5d | 4471 | @@ -244,7 +393,16 @@ static inline int atomic64_sub_and_test( |
2380c486 JR |
4472 | { |
4473 | unsigned char c; | |
4474 | ||
4475 | - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1" | |
4476 | + asm volatile(LOCK_PREFIX "subq %2,%0\n" | |
4477 | + | |
4478 | +#ifdef CONFIG_PAX_REFCOUNT | |
4479 | + "jno 0f\n" | |
4480 | + LOCK_PREFIX "addq %2,%0\n" | |
4481 | + "int $4\n0:\n" | |
4482 | + _ASM_EXTABLE(0b, 0b) | |
4483 | +#endif | |
4484 | + | |
4485 | + "sete %1\n" | |
4486 | : "=m" (v->counter), "=qm" (c) | |
4487 | : "er" (i), "m" (v->counter) : "memory"); | |
4488 | return c; | |
de855c5d | 4489 | @@ -258,7 +416,19 @@ static inline int atomic64_sub_and_test( |
2380c486 JR |
4490 | */ |
4491 | static inline void atomic64_inc(atomic64_t *v) | |
4492 | { | |
4493 | - asm volatile(LOCK_PREFIX "incq %0" | |
4494 | + asm volatile(LOCK_PREFIX "incq %0\n" | |
4495 | + | |
4496 | +#ifdef CONFIG_PAX_REFCOUNT | |
4497 | + "jno 0f\n" | |
4498 | + "int $4\n0:\n" | |
4499 | + ".pushsection .fixup,\"ax\"\n" | |
4500 | + "1:\n" | |
4501 | + LOCK_PREFIX "decq %0\n" | |
4502 | + "jmp 0b\n" | |
4503 | + ".popsection\n" | |
4504 | + _ASM_EXTABLE(0b, 1b) | |
4505 | +#endif | |
4506 | + | |
4507 | : "=m" (v->counter) | |
4508 | : "m" (v->counter)); | |
4509 | } | |
de855c5d | 4510 | @@ -271,7 +441,19 @@ static inline void atomic64_inc(atomic64 |
2380c486 JR |
4511 | */ |
4512 | static inline void atomic64_dec(atomic64_t *v) | |
4513 | { | |
4514 | - asm volatile(LOCK_PREFIX "decq %0" | |
4515 | + asm volatile(LOCK_PREFIX "decq %0\n" | |
4516 | + | |
4517 | +#ifdef CONFIG_PAX_REFCOUNT | |
4518 | + "jno 0f\n" | |
4519 | + "int $4\n0:\n" | |
4520 | + ".pushsection .fixup,\"ax\"\n" | |
4521 | + "1: \n" | |
4522 | + LOCK_PREFIX "incq %0\n" | |
4523 | + "jmp 0b\n" | |
4524 | + ".popsection\n" | |
4525 | + _ASM_EXTABLE(0b, 1b) | |
4526 | +#endif | |
4527 | + | |
4528 | : "=m" (v->counter) | |
4529 | : "m" (v->counter)); | |
4530 | } | |
de855c5d | 4531 | @@ -288,7 +470,20 @@ static inline int atomic64_dec_and_test( |
2380c486 JR |
4532 | { |
4533 | unsigned char c; | |
4534 | ||
4535 | - asm volatile(LOCK_PREFIX "decq %0; sete %1" | |
4536 | + asm volatile(LOCK_PREFIX "decq %0\n" | |
4537 | + | |
4538 | +#ifdef CONFIG_PAX_REFCOUNT | |
4539 | + "jno 0f\n" | |
4540 | + "int $4\n0:\n" | |
4541 | + ".pushsection .fixup,\"ax\"\n" | |
4542 | + "1: \n" | |
4543 | + LOCK_PREFIX "incq %0\n" | |
4544 | + "jmp 0b\n" | |
4545 | + ".popsection\n" | |
4546 | + _ASM_EXTABLE(0b, 1b) | |
4547 | +#endif | |
4548 | + | |
4549 | + "sete %1\n" | |
4550 | : "=m" (v->counter), "=qm" (c) | |
4551 | : "m" (v->counter) : "memory"); | |
4552 | return c != 0; | |
de855c5d | 4553 | @@ -306,7 +501,20 @@ static inline int atomic64_inc_and_test( |
2380c486 JR |
4554 | { |
4555 | unsigned char c; | |
4556 | ||
4557 | - asm volatile(LOCK_PREFIX "incq %0; sete %1" | |
4558 | + asm volatile(LOCK_PREFIX "incq %0\n" | |
4559 | + | |
4560 | +#ifdef CONFIG_PAX_REFCOUNT | |
4561 | + "jno 0f\n" | |
4562 | + "int $4\n0:\n" | |
4563 | + ".pushsection .fixup,\"ax\"\n" | |
4564 | + "1: \n" | |
4565 | + LOCK_PREFIX "decq %0\n" | |
4566 | + "jmp 0b\n" | |
4567 | + ".popsection\n" | |
4568 | + _ASM_EXTABLE(0b, 1b) | |
4569 | +#endif | |
4570 | + | |
4571 | + "sete %1\n" | |
4572 | : "=m" (v->counter), "=qm" (c) | |
4573 | : "m" (v->counter) : "memory"); | |
4574 | return c != 0; | |
de855c5d | 4575 | @@ -325,7 +533,16 @@ static inline int atomic64_add_negative( |
2380c486 JR |
4576 | { |
4577 | unsigned char c; | |
4578 | ||
4579 | - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1" | |
4580 | + asm volatile(LOCK_PREFIX "addq %2,%0\n" | |
4581 | + | |
4582 | +#ifdef CONFIG_PAX_REFCOUNT | |
4583 | + "jno 0f\n" | |
4584 | + LOCK_PREFIX "subq %2,%0\n" | |
4585 | + "int $4\n0:\n" | |
4586 | + _ASM_EXTABLE(0b, 0b) | |
4587 | +#endif | |
4588 | + | |
4589 | + "sets %1\n" | |
4590 | : "=m" (v->counter), "=qm" (c) | |
4591 | : "er" (i), "m" (v->counter) : "memory"); | |
4592 | return c; | |
de855c5d | 4593 | @@ -341,7 +558,15 @@ static inline int atomic64_add_negative( |
2380c486 JR |
4594 | static inline long atomic64_add_return(long i, atomic64_t *v) |
4595 | { | |
4596 | long __i = i; | |
4597 | - asm volatile(LOCK_PREFIX "xaddq %0, %1;" | |
4598 | + asm volatile(LOCK_PREFIX "xaddq %0, %1\n" | |
4599 | + | |
4600 | +#ifdef CONFIG_PAX_REFCOUNT | |
4601 | + "jno 0f\n" | |
4602 | + "movq %0, %1\n" | |
4603 | + "int $4\n0:\n" | |
4604 | + _ASM_EXTABLE(0b, 0b) | |
4605 | +#endif | |
4606 | + | |
4607 | : "+r" (i), "+m" (v->counter) | |
4608 | : : "memory"); | |
4609 | return i + __i; | |
de855c5d | 4610 | @@ -372,17 +597,29 @@ static inline long atomic64_sub_return(l |
2380c486 JR |
4611 | */ |
4612 | static inline int atomic_add_unless(atomic_t *v, int a, int u) | |
4613 | { | |
4614 | - int c, old; | |
4615 | + int c, old, new; | |
4616 | c = atomic_read(v); | |
4617 | for (;;) { | |
4618 | - if (unlikely(c == (u))) | |
4619 | + if (unlikely(c == u)) | |
4620 | break; | |
4621 | - old = atomic_cmpxchg((v), c, c + (a)); | |
4622 | + | |
4623 | + asm volatile("addl %2,%0\n" | |
4624 | + | |
4625 | +#ifdef CONFIG_PAX_REFCOUNT | |
4626 | + "jno 0f\n" | |
4627 | + "int $4\n0:\n" | |
4628 | + _ASM_EXTABLE(0b, 0b) | |
4629 | +#endif | |
4630 | + | |
4631 | + : "=r" (new) | |
4632 | + : "0" (c), "ir" (a)); | |
4633 | + | |
4634 | + old = atomic_cmpxchg(v, c, new); | |
4635 | if (likely(old == c)) | |
4636 | break; | |
4637 | c = old; | |
4638 | } | |
4639 | - return c != (u); | |
4640 | + return c != u; | |
4641 | } | |
4642 | ||
4643 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | |
de855c5d | 4644 | @@ -398,17 +635,29 @@ static inline int atomic_add_unless(atom |
2380c486 JR |
4645 | */ |
4646 | static inline int atomic64_add_unless(atomic64_t *v, long a, long u) | |
4647 | { | |
4648 | - long c, old; | |
4649 | + long c, old, new; | |
4650 | c = atomic64_read(v); | |
4651 | for (;;) { | |
4652 | - if (unlikely(c == (u))) | |
4653 | + if (unlikely(c == u)) | |
4654 | break; | |
4655 | - old = atomic64_cmpxchg((v), c, c + (a)); | |
4656 | + | |
4657 | + asm volatile("addq %2,%0\n" | |
4658 | + | |
4659 | +#ifdef CONFIG_PAX_REFCOUNT | |
4660 | + "jno 0f\n" | |
4661 | + "int $4\n0:\n" | |
4662 | + _ASM_EXTABLE(0b, 0b) | |
4663 | +#endif | |
4664 | + | |
4665 | + : "=r" (new) | |
4666 | + : "0" (c), "er" (a)); | |
4667 | + | |
4668 | + old = atomic64_cmpxchg((v), c, new); | |
4669 | if (likely(old == c)) | |
4670 | break; | |
4671 | c = old; | |
4672 | } | |
4673 | - return c != (u); | |
4674 | + return c != u; | |
4675 | } | |
4676 | ||
4677 | /** | |
de855c5d AM |
4678 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/boot.h linux-2.6.29.6/arch/x86/include/asm/boot.h |
4679 | --- linux-2.6.29.6/arch/x86/include/asm/boot.h 2009-07-02 19:41:20.000000000 -0400 | |
4680 | +++ linux-2.6.29.6/arch/x86/include/asm/boot.h 2009-07-09 22:13:39.000000000 -0400 | |
4681 | @@ -11,10 +11,15 @@ | |
4682 | #define ASK_VGA 0xfffd /* ask for it at bootup */ | |
2380c486 JR |
4683 | |
4684 | /* Physical address where kernel should be loaded. */ | |
4685 | -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \ | |
4686 | +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \ | |
4687 | + (CONFIG_PHYSICAL_ALIGN - 1)) \ | |
4688 | & ~(CONFIG_PHYSICAL_ALIGN - 1)) | |
4689 | ||
4690 | +#ifndef __ASSEMBLY__ | |
4691 | +extern unsigned char __LOAD_PHYSICAL_ADDR[]; | |
4692 | +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR) | |
4693 | +#endif | |
4694 | + | |
de855c5d AM |
4695 | #ifdef CONFIG_X86_64 |
4696 | #define BOOT_HEAP_SIZE 0x7000 | |
4697 | #define BOOT_STACK_SIZE 0x4000 | |
4698 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/cache.h linux-2.6.29.6/arch/x86/include/asm/cache.h | |
4699 | --- linux-2.6.29.6/arch/x86/include/asm/cache.h 2009-07-02 19:41:20.000000000 -0400 | |
4700 | +++ linux-2.6.29.6/arch/x86/include/asm/cache.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4701 | @@ -6,6 +6,7 @@ |
4702 | #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) | |
4703 | ||
4704 | #define __read_mostly __attribute__((__section__(".data.read_mostly"))) | |
4705 | +#define __read_only __attribute__((__section__(".data.read_only"))) | |
4706 | ||
4707 | #ifdef CONFIG_X86_VSMP | |
4708 | /* vSMP Internode cacheline shift */ | |
de855c5d AM |
4709 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/checksum_32.h linux-2.6.29.6/arch/x86/include/asm/checksum_32.h |
4710 | --- linux-2.6.29.6/arch/x86/include/asm/checksum_32.h 2009-07-02 19:41:20.000000000 -0400 | |
4711 | +++ linux-2.6.29.6/arch/x86/include/asm/checksum_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4712 | @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene |
4713 | int len, __wsum sum, | |
4714 | int *src_err_ptr, int *dst_err_ptr); | |
4715 | ||
4716 | +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst, | |
4717 | + int len, __wsum sum, | |
4718 | + int *src_err_ptr, int *dst_err_ptr); | |
4719 | + | |
4720 | +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst, | |
4721 | + int len, __wsum sum, | |
4722 | + int *src_err_ptr, int *dst_err_ptr); | |
4723 | + | |
4724 | /* | |
4725 | * Note: when you get a NULL pointer exception here this means someone | |
4726 | * passed in an incorrect kernel address to one of these functions. | |
4727 | @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f | |
4728 | int *err_ptr) | |
4729 | { | |
4730 | might_sleep(); | |
4731 | - return csum_partial_copy_generic((__force void *)src, dst, | |
4732 | + return csum_partial_copy_generic_from_user((__force void *)src, dst, | |
4733 | len, sum, err_ptr, NULL); | |
4734 | } | |
4735 | ||
4736 | @@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us | |
4737 | { | |
4738 | might_sleep(); | |
4739 | if (access_ok(VERIFY_WRITE, dst, len)) | |
4740 | - return csum_partial_copy_generic(src, (__force void *)dst, | |
4741 | + return csum_partial_copy_generic_to_user(src, (__force void *)dst, | |
4742 | len, sum, NULL, err_ptr); | |
4743 | ||
4744 | if (len) | |
de855c5d AM |
4745 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/desc.h linux-2.6.29.6/arch/x86/include/asm/desc.h |
4746 | --- linux-2.6.29.6/arch/x86/include/asm/desc.h 2009-07-02 19:41:20.000000000 -0400 | |
4747 | +++ linux-2.6.29.6/arch/x86/include/asm/desc.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4748 | @@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_ |
4749 | desc->base1 = (info->base_addr & 0x00ff0000) >> 16; | |
4750 | desc->type = (info->read_exec_only ^ 1) << 1; | |
4751 | desc->type |= info->contents << 2; | |
4752 | + desc->type |= info->seg_not_present ^ 1; | |
4753 | desc->s = 1; | |
4754 | desc->dpl = 0x3; | |
4755 | desc->p = info->seg_not_present ^ 1; | |
4756 | @@ -32,16 +33,12 @@ static inline void fill_ldt(struct desc_ | |
4757 | } | |
4758 | ||
4759 | extern struct desc_ptr idt_descr; | |
4760 | -extern gate_desc idt_table[]; | |
4761 | - | |
4762 | -struct gdt_page { | |
4763 | - struct desc_struct gdt[GDT_ENTRIES]; | |
4764 | -} __attribute__((aligned(PAGE_SIZE))); | |
4765 | -DECLARE_PER_CPU(struct gdt_page, gdt_page); | |
4766 | +extern gate_desc idt_table[256]; | |
4767 | ||
4768 | +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)]; | |
4769 | static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu) | |
4770 | { | |
4771 | - return per_cpu(gdt_page, cpu).gdt; | |
4772 | + return cpu_gdt_table[cpu]; | |
4773 | } | |
4774 | ||
4775 | #ifdef CONFIG_X86_64 | |
4776 | @@ -115,19 +112,48 @@ static inline void paravirt_free_ldt(str | |
4777 | static inline void native_write_idt_entry(gate_desc *idt, int entry, | |
4778 | const gate_desc *gate) | |
4779 | { | |
4780 | + | |
4781 | +#ifdef CONFIG_PAX_KERNEXEC | |
4782 | + unsigned long cr0; | |
4783 | + | |
4784 | + pax_open_kernel(cr0); | |
4785 | +#endif | |
4786 | + | |
4787 | memcpy(&idt[entry], gate, sizeof(*gate)); | |
4788 | + | |
4789 | +#ifdef CONFIG_PAX_KERNEXEC | |
4790 | + pax_close_kernel(cr0); | |
4791 | +#endif | |
4792 | + | |
4793 | } | |
4794 | ||
4795 | static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, | |
4796 | const void *desc) | |
4797 | { | |
4798 | + | |
4799 | +#ifdef CONFIG_PAX_KERNEXEC | |
4800 | + unsigned long cr0; | |
4801 | + | |
4802 | + pax_open_kernel(cr0); | |
4803 | +#endif | |
4804 | + | |
4805 | memcpy(&ldt[entry], desc, 8); | |
4806 | + | |
4807 | +#ifdef CONFIG_PAX_KERNEXEC | |
4808 | + pax_close_kernel(cr0); | |
4809 | +#endif | |
4810 | + | |
4811 | } | |
4812 | ||
4813 | static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry, | |
4814 | const void *desc, int type) | |
4815 | { | |
4816 | unsigned int size; | |
4817 | + | |
4818 | +#ifdef CONFIG_PAX_KERNEXEC | |
4819 | + unsigned long cr0; | |
4820 | +#endif | |
4821 | + | |
4822 | switch (type) { | |
4823 | case DESC_TSS: | |
4824 | size = sizeof(tss_desc); | |
4825 | @@ -139,7 +165,17 @@ static inline void native_write_gdt_entr | |
4826 | size = sizeof(struct desc_struct); | |
4827 | break; | |
4828 | } | |
4829 | + | |
4830 | +#ifdef CONFIG_PAX_KERNEXEC | |
4831 | + pax_open_kernel(cr0); | |
4832 | +#endif | |
4833 | + | |
4834 | memcpy(&gdt[entry], desc, size); | |
4835 | + | |
4836 | +#ifdef CONFIG_PAX_KERNEXEC | |
4837 | + pax_close_kernel(cr0); | |
4838 | +#endif | |
4839 | + | |
4840 | } | |
4841 | ||
4842 | static inline void pack_descriptor(struct desc_struct *desc, unsigned long base, | |
4843 | @@ -211,7 +247,19 @@ static inline void native_set_ldt(const | |
4844 | ||
4845 | static inline void native_load_tr_desc(void) | |
4846 | { | |
4847 | + | |
4848 | +#ifdef CONFIG_PAX_KERNEXEC | |
4849 | + unsigned long cr0; | |
4850 | + | |
4851 | + pax_open_kernel(cr0); | |
4852 | +#endif | |
4853 | + | |
4854 | asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8)); | |
4855 | + | |
4856 | +#ifdef CONFIG_PAX_KERNEXEC | |
4857 | + pax_close_kernel(cr0); | |
4858 | +#endif | |
4859 | + | |
4860 | } | |
4861 | ||
4862 | static inline void native_load_gdt(const struct desc_ptr *dtr) | |
4863 | @@ -246,8 +294,19 @@ static inline void native_load_tls(struc | |
4864 | unsigned int i; | |
4865 | struct desc_struct *gdt = get_cpu_gdt_table(cpu); | |
4866 | ||
4867 | +#ifdef CONFIG_PAX_KERNEXEC | |
4868 | + unsigned long cr0; | |
4869 | + | |
4870 | + pax_open_kernel(cr0); | |
4871 | +#endif | |
4872 | + | |
4873 | for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++) | |
4874 | gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i]; | |
4875 | + | |
4876 | +#ifdef CONFIG_PAX_KERNEXEC | |
4877 | + pax_close_kernel(cr0); | |
4878 | +#endif | |
4879 | + | |
4880 | } | |
4881 | ||
4882 | #define _LDT_empty(info) \ | |
4883 | @@ -379,6 +438,18 @@ static inline void set_system_intr_gate_ | |
4884 | _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS); | |
4885 | } | |
4886 | ||
4887 | +#ifdef CONFIG_X86_32 | |
4888 | +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu) | |
4889 | +{ | |
4890 | + struct desc_struct d; | |
4891 | + | |
4892 | + if (likely(limit)) | |
4893 | + limit = (limit - 1UL) >> PAGE_SHIFT; | |
4894 | + pack_descriptor(&d, base, limit, 0xFB, 0xC); | |
4895 | + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S); | |
4896 | +} | |
4897 | +#endif | |
4898 | + | |
4899 | #else | |
4900 | /* | |
4901 | * GET_DESC_BASE reads the descriptor base of the specified segment. | |
de855c5d AM |
4902 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/e820.h linux-2.6.29.6/arch/x86/include/asm/e820.h |
4903 | --- linux-2.6.29.6/arch/x86/include/asm/e820.h 2009-07-02 19:41:20.000000000 -0400 | |
4904 | +++ linux-2.6.29.6/arch/x86/include/asm/e820.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4905 | @@ -135,7 +135,7 @@ extern char *memory_setup(void); |
4906 | #define ISA_END_ADDRESS 0x100000 | |
4907 | #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS) | |
4908 | ||
4909 | -#define BIOS_BEGIN 0x000a0000 | |
4910 | +#define BIOS_BEGIN 0x000c0000 | |
4911 | #define BIOS_END 0x00100000 | |
4912 | ||
4913 | #ifdef __KERNEL__ | |
de855c5d AM |
4914 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/elf.h linux-2.6.29.6/arch/x86/include/asm/elf.h |
4915 | --- linux-2.6.29.6/arch/x86/include/asm/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
4916 | +++ linux-2.6.29.6/arch/x86/include/asm/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4917 | @@ -252,7 +252,25 @@ extern int force_personality32; |
4918 | the loader. We need to make sure that it is out of the way of the program | |
4919 | that it will "exec", and that there is sufficient room for the brk. */ | |
4920 | ||
4921 | +#ifdef CONFIG_PAX_SEGMEXEC | |
4922 | +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2) | |
4923 | +#else | |
4924 | #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) | |
4925 | +#endif | |
4926 | + | |
4927 | +#ifdef CONFIG_PAX_ASLR | |
4928 | +#ifdef CONFIG_X86_32 | |
4929 | +#define PAX_ELF_ET_DYN_BASE 0x10000000UL | |
4930 | + | |
4931 | +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16) | |
4932 | +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16) | |
4933 | +#else | |
4934 | +#define PAX_ELF_ET_DYN_BASE 0x400000UL | |
4935 | + | |
4936 | +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32) | |
4937 | +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32) | |
4938 | +#endif | |
4939 | +#endif | |
4940 | ||
4941 | /* This yields a mask that user programs can use to figure out what | |
4942 | instruction set this CPU supports. This could be done in user space, | |
4943 | @@ -304,8 +322,7 @@ do { \ | |
4944 | #define ARCH_DLINFO \ | |
4945 | do { \ | |
4946 | if (vdso_enabled) \ | |
4947 | - NEW_AUX_ENT(AT_SYSINFO_EHDR, \ | |
4948 | - (unsigned long)current->mm->context.vdso); \ | |
4949 | + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\ | |
4950 | } while (0) | |
4951 | ||
4952 | #define AT_SYSINFO 32 | |
4953 | @@ -316,7 +333,7 @@ do { \ | |
4954 | ||
4955 | #endif /* !CONFIG_X86_32 */ | |
4956 | ||
4957 | -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso) | |
4958 | +#define VDSO_CURRENT_BASE (current->mm->context.vdso) | |
4959 | ||
4960 | #define VDSO_ENTRY \ | |
4961 | ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall)) | |
4962 | @@ -330,7 +347,4 @@ extern int arch_setup_additional_pages(s | |
4963 | extern int syscall32_setup_pages(struct linux_binprm *, int exstack); | |
4964 | #define compat_arch_setup_additional_pages syscall32_setup_pages | |
4965 | ||
4966 | -extern unsigned long arch_randomize_brk(struct mm_struct *mm); | |
4967 | -#define arch_randomize_brk arch_randomize_brk | |
4968 | - | |
4969 | #endif /* _ASM_X86_ELF_H */ | |
de855c5d AM |
4970 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/futex.h linux-2.6.29.6/arch/x86/include/asm/futex.h |
4971 | --- linux-2.6.29.6/arch/x86/include/asm/futex.h 2009-07-02 19:41:20.000000000 -0400 | |
4972 | +++ linux-2.6.29.6/arch/x86/include/asm/futex.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
4973 | @@ -11,6 +11,40 @@ |
4974 | #include <asm/processor.h> | |
4975 | #include <asm/system.h> | |
4976 | ||
4977 | +#ifdef CONFIG_X86_32 | |
4978 | +#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ | |
4979 | + asm volatile( \ | |
4980 | + "movw\t%w6, %%ds\n" \ | |
4981 | + "1:\t" insn "\n" \ | |
4982 | + "2:\tpushl\t%%ss\n" \ | |
4983 | + "\tpopl\t%%ds\n" \ | |
4984 | + "\t.section .fixup,\"ax\"\n" \ | |
4985 | + "3:\tmov\t%3, %1\n" \ | |
4986 | + "\tjmp\t2b\n" \ | |
4987 | + "\t.previous\n" \ | |
4988 | + _ASM_EXTABLE(1b, 3b) \ | |
4989 | + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \ | |
4990 | + : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS)) | |
4991 | + | |
4992 | +#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \ | |
4993 | + asm volatile("movw\t%w7, %%es\n" \ | |
4994 | + "1:\tmovl\t%%es:%2, %0\n" \ | |
4995 | + "\tmovl\t%0, %3\n" \ | |
4996 | + "\t" insn "\n" \ | |
4997 | + "2:\t" LOCK_PREFIX "cmpxchgl %3, %%es:%2\n"\ | |
4998 | + "\tjnz\t1b\n" \ | |
4999 | + "3:\tpushl\t%%ss\n" \ | |
5000 | + "\tpopl\t%%es\n" \ | |
5001 | + "\t.section .fixup,\"ax\"\n" \ | |
5002 | + "4:\tmov\t%5, %1\n" \ | |
5003 | + "\tjmp\t3b\n" \ | |
5004 | + "\t.previous\n" \ | |
5005 | + _ASM_EXTABLE(1b, 4b) \ | |
5006 | + _ASM_EXTABLE(2b, 4b) \ | |
5007 | + : "=&a" (oldval), "=&r" (ret), \ | |
5008 | + "+m" (*uaddr), "=&r" (tem) \ | |
5009 | + : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS)) | |
5010 | +#else | |
5011 | #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ | |
5012 | asm volatile("1:\t" insn "\n" \ | |
5013 | "2:\t.section .fixup,\"ax\"\n" \ | |
5014 | @@ -36,8 +70,9 @@ | |
5015 | : "=&a" (oldval), "=&r" (ret), \ | |
5016 | "+m" (*uaddr), "=&r" (tem) \ | |
5017 | : "r" (oparg), "i" (-EFAULT), "1" (0)) | |
5018 | +#endif | |
5019 | ||
5020 | -static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr) | |
5021 | +static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr) | |
5022 | { | |
5023 | int op = (encoded_op >> 28) & 7; | |
5024 | int cmp = (encoded_op >> 24) & 15; | |
5025 | @@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser | |
5026 | ||
5027 | switch (op) { | |
5028 | case FUTEX_OP_SET: | |
5029 | +#ifdef CONFIG_X86_32 | |
5030 | + __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg); | |
5031 | +#else | |
5032 | __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg); | |
5033 | +#endif | |
5034 | break; | |
5035 | case FUTEX_OP_ADD: | |
5036 | +#ifdef CONFIG_X86_32 | |
5037 | + __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %%ds:%2", ret, oldval, | |
5038 | + uaddr, oparg); | |
5039 | +#else | |
5040 | __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval, | |
5041 | uaddr, oparg); | |
5042 | +#endif | |
5043 | break; | |
5044 | case FUTEX_OP_OR: | |
5045 | __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg); | |
5046 | @@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser | |
5047 | return ret; | |
5048 | } | |
5049 | ||
5050 | -static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, | |
5051 | +static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, | |
5052 | int newval) | |
5053 | { | |
5054 | ||
5055 | @@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i | |
5056 | if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) | |
5057 | return -EFAULT; | |
5058 | ||
5059 | - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n" | |
5060 | + asm volatile( | |
5061 | +#ifdef CONFIG_X86_32 | |
5062 | + "\tmovw %w5, %%ds\n" | |
5063 | + "1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n" | |
5064 | + "2:\tpushl %%ss\n" | |
5065 | + "\tpopl %%ds\n" | |
5066 | + "\t.section .fixup, \"ax\"\n" | |
5067 | +#else | |
5068 | + "1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n" | |
5069 | "2:\t.section .fixup, \"ax\"\n" | |
5070 | +#endif | |
5071 | "3:\tmov %2, %0\n" | |
5072 | "\tjmp 2b\n" | |
5073 | "\t.previous\n" | |
5074 | _ASM_EXTABLE(1b, 3b) | |
5075 | : "=a" (oldval), "+m" (*uaddr) | |
5076 | +#ifdef CONFIG_X86_32 | |
5077 | + : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS) | |
5078 | +#else | |
5079 | : "i" (-EFAULT), "r" (newval), "0" (oldval) | |
5080 | +#endif | |
5081 | : "memory" | |
5082 | ); | |
5083 | ||
de855c5d AM |
5084 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/i387.h linux-2.6.29.6/arch/x86/include/asm/i387.h |
5085 | --- linux-2.6.29.6/arch/x86/include/asm/i387.h 2009-07-02 19:41:20.000000000 -0400 | |
5086 | +++ linux-2.6.29.6/arch/x86/include/asm/i387.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5087 | @@ -203,13 +203,8 @@ static inline void restore_fpu(struct ta |
5088 | } | |
5089 | ||
5090 | /* We need a safe address that is cheap to find and that is already | |
5091 | - in L1 during context switch. The best choices are unfortunately | |
5092 | - different for UP and SMP */ | |
5093 | -#ifdef CONFIG_SMP | |
5094 | -#define safe_address (__per_cpu_offset[0]) | |
5095 | -#else | |
5096 | -#define safe_address (kstat_cpu(0).cpustat.user) | |
5097 | -#endif | |
5098 | + in L1 during context switch. */ | |
5099 | +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0) | |
5100 | ||
5101 | /* | |
5102 | * These must be called with preempt disabled | |
de855c5d AM |
5103 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/io_64.h linux-2.6.29.6/arch/x86/include/asm/io_64.h |
5104 | --- linux-2.6.29.6/arch/x86/include/asm/io_64.h 2009-07-02 19:41:20.000000000 -0400 | |
5105 | +++ linux-2.6.29.6/arch/x86/include/asm/io_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5106 | @@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne |
5107 | } | |
5108 | #endif | |
5109 | ||
5110 | +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE | |
5111 | +static inline int valid_phys_addr_range (unsigned long addr, size_t count) | |
5112 | +{ | |
5113 | + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0; | |
5114 | +} | |
5115 | + | |
5116 | +static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count) | |
5117 | +{ | |
5118 | + return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0; | |
5119 | +} | |
5120 | + | |
5121 | /* | |
5122 | * Change "struct page" to physical address. | |
5123 | */ | |
de855c5d AM |
5124 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/irqflags.h linux-2.6.29.6/arch/x86/include/asm/irqflags.h |
5125 | --- linux-2.6.29.6/arch/x86/include/asm/irqflags.h 2009-07-02 19:41:20.000000000 -0400 | |
5126 | +++ linux-2.6.29.6/arch/x86/include/asm/irqflags.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5127 | @@ -141,6 +141,8 @@ static inline unsigned long __raw_local_ |
5128 | #define INTERRUPT_RETURN iret | |
5129 | #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit | |
5130 | #define GET_CR0_INTO_EAX movl %cr0, %eax | |
5131 | +#define GET_CR0_INTO_EDX movl %cr0, %edx | |
5132 | +#define SET_CR0_FROM_EDX movl %edx, %cr0 | |
5133 | #endif | |
5134 | ||
5135 | ||
de855c5d AM |
5136 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/kmap_types.h linux-2.6.29.6/arch/x86/include/asm/kmap_types.h |
5137 | --- linux-2.6.29.6/arch/x86/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
5138 | +++ linux-2.6.29.6/arch/x86/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5139 | @@ -21,7 +21,8 @@ D(9) KM_IRQ0, |
5140 | D(10) KM_IRQ1, | |
5141 | D(11) KM_SOFTIRQ0, | |
5142 | D(12) KM_SOFTIRQ1, | |
5143 | -D(13) KM_TYPE_NR | |
5144 | +D(13) KM_CLEARPAGE, | |
5145 | +D(14) KM_TYPE_NR | |
5146 | }; | |
5147 | ||
5148 | #undef D | |
de855c5d AM |
5149 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/kvm_host.h linux-2.6.29.6/arch/x86/include/asm/kvm_host.h |
5150 | --- linux-2.6.29.6/arch/x86/include/asm/kvm_host.h 2009-07-02 19:41:20.000000000 -0400 | |
5151 | +++ linux-2.6.29.6/arch/x86/include/asm/kvm_host.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5152 | @@ -494,7 +494,7 @@ struct kvm_x86_ops { |
5153 | int (*get_mt_mask_shift)(void); | |
5154 | }; | |
5155 | ||
5156 | -extern struct kvm_x86_ops *kvm_x86_ops; | |
5157 | +extern const struct kvm_x86_ops *kvm_x86_ops; | |
5158 | ||
5159 | int kvm_mmu_module_init(void); | |
5160 | void kvm_mmu_module_exit(void); | |
de855c5d AM |
5161 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/linkage.h linux-2.6.29.6/arch/x86/include/asm/linkage.h |
5162 | --- linux-2.6.29.6/arch/x86/include/asm/linkage.h 2009-07-02 19:41:20.000000000 -0400 | |
5163 | +++ linux-2.6.29.6/arch/x86/include/asm/linkage.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5164 | @@ -7,6 +7,11 @@ |
5165 | #ifdef CONFIG_X86_64 | |
5166 | #define __ALIGN .p2align 4,,15 | |
5167 | #define __ALIGN_STR ".p2align 4,,15" | |
5168 | +#else | |
5169 | +#ifdef CONFIG_X86_ALIGNMENT_16 | |
5170 | +#define __ALIGN .align 16,0x90 | |
5171 | +#define __ALIGN_STR ".align 16,0x90" | |
5172 | +#endif | |
5173 | #endif | |
5174 | ||
5175 | #ifdef CONFIG_X86_32 | |
5176 | @@ -52,11 +57,6 @@ | |
5177 | ||
5178 | #endif | |
5179 | ||
5180 | -#ifdef CONFIG_X86_ALIGNMENT_16 | |
5181 | -#define __ALIGN .align 16,0x90 | |
5182 | -#define __ALIGN_STR ".align 16,0x90" | |
5183 | -#endif | |
5184 | - | |
5185 | /* | |
5186 | * to check ENTRY_X86/END_X86 and | |
5187 | * KPROBE_ENTRY_X86/KPROBE_END_X86 | |
de855c5d AM |
5188 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/local.h linux-2.6.29.6/arch/x86/include/asm/local.h |
5189 | --- linux-2.6.29.6/arch/x86/include/asm/local.h 2009-07-02 19:41:20.000000000 -0400 | |
5190 | +++ linux-2.6.29.6/arch/x86/include/asm/local.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5191 | @@ -18,26 +18,90 @@ typedef struct { |
5192 | ||
5193 | static inline void local_inc(local_t *l) | |
5194 | { | |
5195 | - asm volatile(_ASM_INC "%0" | |
5196 | + asm volatile(_ASM_INC "%0\n" | |
5197 | + | |
5198 | +#ifdef CONFIG_PAX_REFCOUNT | |
5199 | +#ifdef CONFIG_X86_32 | |
5200 | + "into\n0:\n" | |
5201 | +#else | |
5202 | + "jno 0f\n" | |
5203 | + "int $4\n0:\n" | |
5204 | +#endif | |
5205 | + ".pushsection .fixup,\"ax\"\n" | |
5206 | + "1:\n" | |
5207 | + _ASM_DEC "%0\n" | |
5208 | + "jmp 0b\n" | |
5209 | + ".popsection\n" | |
5210 | + _ASM_EXTABLE(0b, 1b) | |
5211 | +#endif | |
5212 | + | |
5213 | : "+m" (l->a.counter)); | |
5214 | } | |
5215 | ||
5216 | static inline void local_dec(local_t *l) | |
5217 | { | |
5218 | - asm volatile(_ASM_DEC "%0" | |
5219 | + asm volatile(_ASM_DEC "%0\n" | |
5220 | + | |
5221 | +#ifdef CONFIG_PAX_REFCOUNT | |
5222 | +#ifdef CONFIG_X86_32 | |
5223 | + "into\n0:\n" | |
5224 | +#else | |
5225 | + "jno 0f\n" | |
5226 | + "int $4\n0:\n" | |
5227 | +#endif | |
5228 | + ".pushsection .fixup,\"ax\"\n" | |
5229 | + "1:\n" | |
5230 | + _ASM_INC "%0\n" | |
5231 | + "jmp 0b\n" | |
5232 | + ".popsection\n" | |
5233 | + _ASM_EXTABLE(0b, 1b) | |
5234 | +#endif | |
5235 | + | |
5236 | : "+m" (l->a.counter)); | |
5237 | } | |
5238 | ||
5239 | static inline void local_add(long i, local_t *l) | |
5240 | { | |
5241 | - asm volatile(_ASM_ADD "%1,%0" | |
5242 | + asm volatile(_ASM_ADD "%1,%0\n" | |
5243 | + | |
5244 | +#ifdef CONFIG_PAX_REFCOUNT | |
5245 | +#ifdef CONFIG_X86_32 | |
5246 | + "into\n0:\n" | |
5247 | +#else | |
5248 | + "jno 0f\n" | |
5249 | + "int $4\n0:\n" | |
5250 | +#endif | |
5251 | + ".pushsection .fixup,\"ax\"\n" | |
5252 | + "1:\n" | |
5253 | + _ASM_SUB "%1,%0\n" | |
5254 | + "jmp 0b\n" | |
5255 | + ".popsection\n" | |
5256 | + _ASM_EXTABLE(0b, 1b) | |
5257 | +#endif | |
5258 | + | |
5259 | : "+m" (l->a.counter) | |
5260 | : "ir" (i)); | |
5261 | } | |
5262 | ||
5263 | static inline void local_sub(long i, local_t *l) | |
5264 | { | |
5265 | - asm volatile(_ASM_SUB "%1,%0" | |
5266 | + asm volatile(_ASM_SUB "%1,%0\n" | |
5267 | + | |
5268 | +#ifdef CONFIG_PAX_REFCOUNT | |
5269 | +#ifdef CONFIG_X86_32 | |
5270 | + "into\n0:\n" | |
5271 | +#else | |
5272 | + "jno 0f\n" | |
5273 | + "int $4\n0:\n" | |
5274 | +#endif | |
5275 | + ".pushsection .fixup,\"ax\"\n" | |
5276 | + "1:\n" | |
5277 | + _ASM_ADD "%1,%0\n" | |
5278 | + "jmp 0b\n" | |
5279 | + ".popsection\n" | |
5280 | + _ASM_EXTABLE(0b, 1b) | |
5281 | +#endif | |
5282 | + | |
5283 | : "+m" (l->a.counter) | |
5284 | : "ir" (i)); | |
5285 | } | |
5286 | @@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon | |
5287 | { | |
5288 | unsigned char c; | |
5289 | ||
5290 | - asm volatile(_ASM_SUB "%2,%0; sete %1" | |
5291 | + asm volatile(_ASM_SUB "%2,%0\n" | |
5292 | + | |
5293 | +#ifdef CONFIG_PAX_REFCOUNT | |
5294 | +#ifdef CONFIG_X86_32 | |
5295 | + "into\n0:\n" | |
5296 | +#else | |
5297 | + "jno 0f\n" | |
5298 | + "int $4\n0:\n" | |
5299 | +#endif | |
5300 | + ".pushsection .fixup,\"ax\"\n" | |
5301 | + "1:\n" | |
5302 | + _ASM_ADD "%2,%0\n" | |
5303 | + "jmp 0b\n" | |
5304 | + ".popsection\n" | |
5305 | + _ASM_EXTABLE(0b, 1b) | |
5306 | +#endif | |
5307 | + | |
5308 | + "sete %1\n" | |
5309 | : "+m" (l->a.counter), "=qm" (c) | |
5310 | : "ir" (i) : "memory"); | |
5311 | return c; | |
5312 | @@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc | |
5313 | { | |
5314 | unsigned char c; | |
5315 | ||
5316 | - asm volatile(_ASM_DEC "%0; sete %1" | |
5317 | + asm volatile(_ASM_DEC "%0\n" | |
5318 | + | |
5319 | +#ifdef CONFIG_PAX_REFCOUNT | |
5320 | +#ifdef CONFIG_X86_32 | |
5321 | + "into\n0:\n" | |
5322 | +#else | |
5323 | + "jno 0f\n" | |
5324 | + "int $4\n0:\n" | |
5325 | +#endif | |
5326 | + ".pushsection .fixup,\"ax\"\n" | |
5327 | + "1:\n" | |
5328 | + _ASM_INC "%0\n" | |
5329 | + "jmp 0b\n" | |
5330 | + ".popsection\n" | |
5331 | + _ASM_EXTABLE(0b, 1b) | |
5332 | +#endif | |
5333 | + | |
5334 | + "sete %1\n" | |
5335 | : "+m" (l->a.counter), "=qm" (c) | |
5336 | : : "memory"); | |
5337 | return c != 0; | |
5338 | @@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc | |
5339 | { | |
5340 | unsigned char c; | |
5341 | ||
5342 | - asm volatile(_ASM_INC "%0; sete %1" | |
5343 | + asm volatile(_ASM_INC "%0\n" | |
5344 | + | |
5345 | +#ifdef CONFIG_PAX_REFCOUNT | |
5346 | +#ifdef CONFIG_X86_32 | |
5347 | + "into\n0:\n" | |
5348 | +#else | |
5349 | + "jno 0f\n" | |
5350 | + "int $4\n0:\n" | |
5351 | +#endif | |
5352 | + ".pushsection .fixup,\"ax\"\n" | |
5353 | + "1:\n" | |
5354 | + _ASM_DEC "%0\n" | |
5355 | + "jmp 0b\n" | |
5356 | + ".popsection\n" | |
5357 | + _ASM_EXTABLE(0b, 1b) | |
5358 | +#endif | |
5359 | + | |
5360 | + "sete %1\n" | |
5361 | : "+m" (l->a.counter), "=qm" (c) | |
5362 | : : "memory"); | |
5363 | return c != 0; | |
5364 | @@ -110,7 +225,24 @@ static inline int local_add_negative(lon | |
5365 | { | |
5366 | unsigned char c; | |
5367 | ||
5368 | - asm volatile(_ASM_ADD "%2,%0; sets %1" | |
5369 | + asm volatile(_ASM_ADD "%2,%0\n" | |
5370 | + | |
5371 | +#ifdef CONFIG_PAX_REFCOUNT | |
5372 | +#ifdef CONFIG_X86_32 | |
5373 | + "into\n0:\n" | |
5374 | +#else | |
5375 | + "jno 0f\n" | |
5376 | + "int $4\n0:\n" | |
5377 | +#endif | |
5378 | + ".pushsection .fixup,\"ax\"\n" | |
5379 | + "1:\n" | |
5380 | + _ASM_SUB "%2,%0\n" | |
5381 | + "jmp 0b\n" | |
5382 | + ".popsection\n" | |
5383 | + _ASM_EXTABLE(0b, 1b) | |
5384 | +#endif | |
5385 | + | |
5386 | + "sets %1\n" | |
5387 | : "+m" (l->a.counter), "=qm" (c) | |
5388 | : "ir" (i) : "memory"); | |
5389 | return c; | |
5390 | @@ -133,7 +265,23 @@ static inline long local_add_return(long | |
5391 | #endif | |
5392 | /* Modern 486+ processor */ | |
5393 | __i = i; | |
5394 | - asm volatile(_ASM_XADD "%0, %1;" | |
5395 | + asm volatile(_ASM_XADD "%0, %1\n" | |
5396 | + | |
5397 | +#ifdef CONFIG_PAX_REFCOUNT | |
5398 | +#ifdef CONFIG_X86_32 | |
5399 | + "into\n0:\n" | |
5400 | +#else | |
5401 | + "jno 0f\n" | |
5402 | + "int $4\n0:\n" | |
5403 | +#endif | |
5404 | + ".pushsection .fixup,\"ax\"\n" | |
5405 | + "1:\n" | |
5406 | + _ASM_MOV "%0,%1\n" | |
5407 | + "jmp 0b\n" | |
5408 | + ".popsection\n" | |
5409 | + _ASM_EXTABLE(0b, 1b) | |
5410 | +#endif | |
5411 | + | |
5412 | : "+r" (i), "+m" (l->a.counter) | |
5413 | : : "memory"); | |
5414 | return i + __i; | |
de855c5d AM |
5415 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/mach-default/apm.h linux-2.6.29.6/arch/x86/include/asm/mach-default/apm.h |
5416 | --- linux-2.6.29.6/arch/x86/include/asm/mach-default/apm.h 2009-07-02 19:41:20.000000000 -0400 | |
5417 | +++ linux-2.6.29.6/arch/x86/include/asm/mach-default/apm.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5418 | @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 |
5419 | __asm__ __volatile__(APM_DO_ZERO_SEGS | |
5420 | "pushl %%edi\n\t" | |
5421 | "pushl %%ebp\n\t" | |
5422 | - "lcall *%%cs:apm_bios_entry\n\t" | |
5423 | + "lcall *%%ss:apm_bios_entry\n\t" | |
5424 | "setc %%al\n\t" | |
5425 | "popl %%ebp\n\t" | |
5426 | "popl %%edi\n\t" | |
5427 | @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as | |
5428 | __asm__ __volatile__(APM_DO_ZERO_SEGS | |
5429 | "pushl %%edi\n\t" | |
5430 | "pushl %%ebp\n\t" | |
5431 | - "lcall *%%cs:apm_bios_entry\n\t" | |
5432 | + "lcall *%%ss:apm_bios_entry\n\t" | |
5433 | "setc %%bl\n\t" | |
5434 | "popl %%ebp\n\t" | |
5435 | "popl %%edi\n\t" | |
de855c5d AM |
5436 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/mman.h linux-2.6.29.6/arch/x86/include/asm/mman.h |
5437 | --- linux-2.6.29.6/arch/x86/include/asm/mman.h 2009-07-02 19:41:20.000000000 -0400 | |
5438 | +++ linux-2.6.29.6/arch/x86/include/asm/mman.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5439 | @@ -17,4 +17,14 @@ |
5440 | #define MCL_CURRENT 1 /* lock all current mappings */ | |
5441 | #define MCL_FUTURE 2 /* lock all future mappings */ | |
5442 | ||
5443 | +#ifdef __KERNEL__ | |
5444 | +#ifndef __ASSEMBLY__ | |
5445 | +#ifdef CONFIG_X86_32 | |
5446 | +#define arch_mmap_check i386_mmap_check | |
5447 | +int i386_mmap_check(unsigned long addr, unsigned long len, | |
5448 | + unsigned long flags); | |
5449 | +#endif | |
5450 | +#endif | |
5451 | +#endif | |
5452 | + | |
5453 | #endif /* _ASM_X86_MMAN_H */ | |
de855c5d AM |
5454 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/mmu_context_32.h linux-2.6.29.6/arch/x86/include/asm/mmu_context_32.h |
5455 | --- linux-2.6.29.6/arch/x86/include/asm/mmu_context_32.h 2009-07-02 19:41:20.000000000 -0400 | |
5456 | +++ linux-2.6.29.6/arch/x86/include/asm/mmu_context_32.h 2009-07-09 22:13:39.000000000 -0400 | |
5457 | @@ -14,11 +14,15 @@ static inline void switch_mm(struct mm_s | |
5458 | struct task_struct *tsk) | |
5459 | { | |
5460 | int cpu = smp_processor_id(); | |
5461 | +#ifdef CONFIG_SMP | |
5462 | + int tlbstate = TLBSTATE_OK; | |
5463 | +#endif | |
5464 | ||
5465 | if (likely(prev != next)) { | |
5466 | /* stop flush ipis for the previous mm */ | |
5467 | cpu_clear(cpu, prev->cpu_vm_mask); | |
5468 | #ifdef CONFIG_SMP | |
5469 | + tlbstate = x86_read_percpu(cpu_tlbstate.state); | |
5470 | x86_write_percpu(cpu_tlbstate.state, TLBSTATE_OK); | |
5471 | x86_write_percpu(cpu_tlbstate.active_mm, next); | |
5472 | #endif | |
5473 | @@ -32,6 +36,26 @@ static inline void switch_mm(struct mm_s | |
2380c486 JR |
5474 | */ |
5475 | if (unlikely(prev->context.ldt != next->context.ldt)) | |
5476 | load_LDT_nolock(&next->context); | |
5477 | + | |
5478 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP) | |
5479 | + if (!nx_enabled) { | |
5480 | + smp_mb__before_clear_bit(); | |
5481 | + cpu_clear(cpu, prev->context.cpu_user_cs_mask); | |
5482 | + smp_mb__after_clear_bit(); | |
5483 | + cpu_set(cpu, next->context.cpu_user_cs_mask); | |
5484 | + } | |
5485 | +#endif | |
5486 | + | |
5487 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
5488 | + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base || | |
de855c5d AM |
5489 | + prev->context.user_cs_limit != next->context.user_cs_limit |
5490 | +#ifdef CONFIG_SMP | |
5491 | + || tlbstate != TLBSTATE_OK | |
5492 | +#endif | |
5493 | + )) | |
2380c486 JR |
5494 | + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu); |
5495 | +#endif | |
5496 | + | |
5497 | } | |
5498 | #ifdef CONFIG_SMP | |
5499 | else { | |
de855c5d | 5500 | @@ -44,6 +68,19 @@ static inline void switch_mm(struct mm_s |
2380c486 JR |
5501 | */ |
5502 | load_cr3(next->pgd); | |
5503 | load_LDT_nolock(&next->context); | |
5504 | + | |
5505 | +#ifdef CONFIG_PAX_PAGEEXEC | |
5506 | + if (!nx_enabled) | |
5507 | + cpu_set(cpu, next->context.cpu_user_cs_mask); | |
5508 | +#endif | |
5509 | + | |
5510 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
5511 | +#ifdef CONFIG_PAX_PAGEEXEC | |
5512 | + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled)) | |
5513 | +#endif | |
5514 | + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu); | |
5515 | +#endif | |
5516 | + | |
5517 | } | |
5518 | } | |
5519 | #endif | |
de855c5d AM |
5520 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/mmu.h linux-2.6.29.6/arch/x86/include/asm/mmu.h |
5521 | --- linux-2.6.29.6/arch/x86/include/asm/mmu.h 2009-07-02 19:41:20.000000000 -0400 | |
5522 | +++ linux-2.6.29.6/arch/x86/include/asm/mmu.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5523 | @@ -9,10 +9,23 @@ |
5524 | * we put the segment information here. | |
5525 | */ | |
5526 | typedef struct { | |
5527 | - void *ldt; | |
5528 | + struct desc_struct *ldt; | |
5529 | int size; | |
5530 | struct mutex lock; | |
5531 | - void *vdso; | |
5532 | + unsigned long vdso; | |
5533 | + | |
5534 | +#ifdef CONFIG_X86_32 | |
5535 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
5536 | + unsigned long user_cs_base; | |
5537 | + unsigned long user_cs_limit; | |
5538 | + | |
5539 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP) | |
5540 | + cpumask_t cpu_user_cs_mask; | |
5541 | +#endif | |
5542 | + | |
5543 | +#endif | |
5544 | +#endif | |
5545 | + | |
5546 | } mm_context_t; | |
5547 | ||
5548 | #ifdef CONFIG_SMP | |
de855c5d AM |
5549 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/module.h linux-2.6.29.6/arch/x86/include/asm/module.h |
5550 | --- linux-2.6.29.6/arch/x86/include/asm/module.h 2009-07-02 19:41:20.000000000 -0400 | |
5551 | +++ linux-2.6.29.6/arch/x86/include/asm/module.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5552 | @@ -74,7 +74,12 @@ struct mod_arch_specific {}; |
5553 | # else | |
5554 | # define MODULE_STACKSIZE "" | |
5555 | # endif | |
5556 | -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE | |
5557 | +# ifdef CONFIG_GRKERNSEC | |
5558 | +# define MODULE_GRSEC "GRSECURITY " | |
5559 | +# else | |
5560 | +# define MODULE_GRSEC "" | |
5561 | +# endif | |
5562 | +# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC | |
5563 | #endif | |
5564 | ||
5565 | #endif /* _ASM_X86_MODULE_H */ | |
de855c5d AM |
5566 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/page_32.h linux-2.6.29.6/arch/x86/include/asm/page_32.h |
5567 | --- linux-2.6.29.6/arch/x86/include/asm/page_32.h 2009-07-02 19:41:20.000000000 -0400 | |
5568 | +++ linux-2.6.29.6/arch/x86/include/asm/page_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5569 | @@ -13,6 +13,23 @@ |
5570 | */ | |
5571 | #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) | |
5572 | ||
5573 | +#ifdef CONFIG_PAX_KERNEXEC | |
5574 | +#ifndef __ASSEMBLY__ | |
5575 | +extern unsigned char MODULES_VADDR[]; | |
5576 | +extern unsigned char MODULES_END[]; | |
5577 | +extern unsigned char KERNEL_TEXT_OFFSET[]; | |
5578 | +#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET) | |
5579 | +#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET) | |
5580 | +#endif | |
5581 | +#else | |
5582 | +#define ktla_ktva(addr) (addr) | |
5583 | +#define ktva_ktla(addr) (addr) | |
5584 | +#endif | |
5585 | + | |
5586 | +#ifdef CONFIG_PAX_PAGEEXEC | |
5587 | +#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1 | |
5588 | +#endif | |
5589 | + | |
5590 | #ifdef CONFIG_4KSTACKS | |
5591 | #define THREAD_ORDER 0 | |
5592 | #else | |
de855c5d AM |
5593 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/page_64.h linux-2.6.29.6/arch/x86/include/asm/page_64.h |
5594 | --- linux-2.6.29.6/arch/x86/include/asm/page_64.h 2009-07-02 19:41:20.000000000 -0400 | |
5595 | +++ linux-2.6.29.6/arch/x86/include/asm/page_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5596 | @@ -49,6 +49,9 @@ |
5597 | #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START) | |
5598 | #define __START_KERNEL_map _AC(0xffffffff80000000, UL) | |
5599 | ||
5600 | +#define ktla_ktva(addr) (addr) | |
5601 | +#define ktva_ktla(addr) (addr) | |
5602 | + | |
5603 | /* See Documentation/x86_64/mm.txt for a description of the memory map. */ | |
5604 | #define __PHYSICAL_MASK_SHIFT 46 | |
5605 | #define __VIRTUAL_MASK_SHIFT 48 | |
5606 | @@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign | |
5607 | #define pfn_valid(pfn) ((pfn) < max_pfn) | |
5608 | #endif | |
5609 | ||
5610 | +#define nx_enabled (1) | |
5611 | ||
5612 | #endif /* _ASM_X86_PAGE_64_H */ | |
de855c5d AM |
5613 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/paravirt.h linux-2.6.29.6/arch/x86/include/asm/paravirt.h |
5614 | --- linux-2.6.29.6/arch/x86/include/asm/paravirt.h 2009-07-02 19:41:20.000000000 -0400 | |
5615 | +++ linux-2.6.29.6/arch/x86/include/asm/paravirt.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5616 | @@ -1558,7 +1558,7 @@ static inline unsigned long __raw_local_ |
5617 | #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax | |
5618 | #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4) | |
5619 | #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4) | |
5620 | -#define PARA_INDIRECT(addr) *%cs:addr | |
5621 | +#define PARA_INDIRECT(addr) *%ss:addr | |
5622 | #endif | |
5623 | ||
5624 | #define INTERRUPT_RETURN \ | |
de855c5d AM |
5625 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pda.h linux-2.6.29.6/arch/x86/include/asm/pda.h |
5626 | --- linux-2.6.29.6/arch/x86/include/asm/pda.h 2009-07-02 19:41:20.000000000 -0400 | |
5627 | +++ linux-2.6.29.6/arch/x86/include/asm/pda.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5628 | @@ -16,11 +16,9 @@ struct x8664_pda { |
5629 | unsigned long oldrsp; /* 24 user rsp for system call */ | |
5630 | int irqcount; /* 32 Irq nesting counter. Starts -1 */ | |
5631 | unsigned int cpunumber; /* 36 Logical CPU number */ | |
5632 | -#ifdef CONFIG_CC_STACKPROTECTOR | |
5633 | unsigned long stack_canary; /* 40 stack canary value */ | |
5634 | /* gcc-ABI: this canary MUST be at | |
5635 | offset 40!!! */ | |
5636 | -#endif | |
5637 | char *irqstackptr; | |
5638 | short nodenumber; /* number of current node (32k max) */ | |
5639 | short in_bootmem; /* pda lives in bootmem */ | |
de855c5d AM |
5640 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/percpu.h linux-2.6.29.6/arch/x86/include/asm/percpu.h |
5641 | --- linux-2.6.29.6/arch/x86/include/asm/percpu.h 2009-07-02 19:41:20.000000000 -0400 | |
5642 | +++ linux-2.6.29.6/arch/x86/include/asm/percpu.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5643 | @@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda); |
5644 | ||
5645 | #define __my_cpu_offset x86_read_percpu(this_cpu_off) | |
5646 | ||
5647 | +#include <asm-generic/sections.h> | |
5648 | +#include <linux/threads.h> | |
5649 | +#define __per_cpu_offset __per_cpu_offset | |
5650 | +extern unsigned long __per_cpu_offset[NR_CPUS]; | |
5651 | +#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start) | |
5652 | + | |
5653 | /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */ | |
5654 | #define __percpu_seg "%%fs:" | |
5655 | ||
de855c5d AM |
5656 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgalloc.h linux-2.6.29.6/arch/x86/include/asm/pgalloc.h |
5657 | --- linux-2.6.29.6/arch/x86/include/asm/pgalloc.h 2009-07-02 19:41:20.000000000 -0400 | |
5658 | +++ linux-2.6.29.6/arch/x86/include/asm/pgalloc.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5659 | @@ -52,7 +52,7 @@ static inline void pmd_populate_kernel(s |
5660 | pmd_t *pmd, pte_t *pte) | |
5661 | { | |
5662 | paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT); | |
5663 | - set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE)); | |
5664 | + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE)); | |
5665 | } | |
5666 | ||
5667 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, | |
de855c5d AM |
5668 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgtable-2level.h linux-2.6.29.6/arch/x86/include/asm/pgtable-2level.h |
5669 | --- linux-2.6.29.6/arch/x86/include/asm/pgtable-2level.h 2009-07-02 19:41:20.000000000 -0400 | |
5670 | +++ linux-2.6.29.6/arch/x86/include/asm/pgtable-2level.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5671 | @@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t |
5672 | ||
5673 | static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd) | |
5674 | { | |
5675 | + | |
5676 | +#ifdef CONFIG_PAX_KERNEXEC | |
5677 | + unsigned long cr0; | |
5678 | + | |
5679 | + pax_open_kernel(cr0); | |
5680 | +#endif | |
5681 | + | |
5682 | *pmdp = pmd; | |
5683 | + | |
5684 | +#ifdef CONFIG_PAX_KERNEXEC | |
5685 | + pax_close_kernel(cr0); | |
5686 | +#endif | |
5687 | + | |
5688 | } | |
5689 | ||
5690 | static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte) | |
de855c5d AM |
5691 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgtable_32.h linux-2.6.29.6/arch/x86/include/asm/pgtable_32.h |
5692 | --- linux-2.6.29.6/arch/x86/include/asm/pgtable_32.h 2009-07-02 19:41:20.000000000 -0400 | |
5693 | +++ linux-2.6.29.6/arch/x86/include/asm/pgtable_32.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5694 | @@ -25,8 +25,6 @@ |
5695 | struct mm_struct; | |
5696 | struct vm_area_struct; | |
5697 | ||
5698 | -extern pgd_t swapper_pg_dir[1024]; | |
5699 | - | |
5700 | static inline void pgtable_cache_init(void) { } | |
5701 | static inline void check_pgt_cache(void) { } | |
5702 | void paging_init(void); | |
5703 | @@ -46,6 +44,11 @@ extern void set_pmd_pfn(unsigned long, u | |
5704 | # include <asm/pgtable-2level-defs.h> | |
5705 | #endif | |
5706 | ||
5707 | +extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; | |
5708 | +#ifdef CONFIG_X86_PAE | |
5709 | +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD]; | |
5710 | +#endif | |
5711 | + | |
5712 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) | |
5713 | #define PGDIR_MASK (~(PGDIR_SIZE - 1)) | |
5714 | ||
5715 | @@ -83,7 +86,7 @@ extern void set_pmd_pfn(unsigned long, u | |
5716 | #undef TEST_ACCESS_OK | |
5717 | ||
5718 | /* The boot page tables (all created as a single array) */ | |
5719 | -extern unsigned long pg0[]; | |
5720 | +extern pte_t pg0[]; | |
5721 | ||
5722 | #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE)) | |
5723 | ||
5724 | @@ -166,6 +169,9 @@ do { \ | |
5725 | ||
5726 | #endif /* !__ASSEMBLY__ */ | |
5727 | ||
5728 | +#define HAVE_ARCH_UNMAPPED_AREA | |
5729 | +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN | |
5730 | + | |
5731 | /* | |
5732 | * kern_addr_valid() is (1) for FLATMEM and (0) for | |
5733 | * SPARSEMEM and DISCONTIGMEM | |
de855c5d AM |
5734 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgtable-3level.h linux-2.6.29.6/arch/x86/include/asm/pgtable-3level.h |
5735 | --- linux-2.6.29.6/arch/x86/include/asm/pgtable-3level.h 2009-07-02 19:41:20.000000000 -0400 | |
5736 | +++ linux-2.6.29.6/arch/x86/include/asm/pgtable-3level.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5737 | @@ -70,12 +70,36 @@ static inline void native_set_pte_atomic |
5738 | ||
5739 | static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd) | |
5740 | { | |
5741 | + | |
5742 | +#ifdef CONFIG_PAX_KERNEXEC | |
5743 | + unsigned long cr0; | |
5744 | + | |
5745 | + pax_open_kernel(cr0); | |
5746 | +#endif | |
5747 | + | |
5748 | set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd)); | |
5749 | + | |
5750 | +#ifdef CONFIG_PAX_KERNEXEC | |
5751 | + pax_close_kernel(cr0); | |
5752 | +#endif | |
5753 | + | |
5754 | } | |
5755 | ||
5756 | static inline void native_set_pud(pud_t *pudp, pud_t pud) | |
5757 | { | |
5758 | + | |
5759 | +#ifdef CONFIG_PAX_KERNEXEC | |
5760 | + unsigned long cr0; | |
5761 | + | |
5762 | + pax_open_kernel(cr0); | |
5763 | +#endif | |
5764 | + | |
5765 | set_64bit((unsigned long long *)(pudp), native_pud_val(pud)); | |
5766 | + | |
5767 | +#ifdef CONFIG_PAX_KERNEXEC | |
5768 | + pax_close_kernel(cr0); | |
5769 | +#endif | |
5770 | + | |
5771 | } | |
5772 | ||
5773 | /* | |
de855c5d AM |
5774 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgtable_64.h linux-2.6.29.6/arch/x86/include/asm/pgtable_64.h |
5775 | --- linux-2.6.29.6/arch/x86/include/asm/pgtable_64.h 2009-07-02 19:41:20.000000000 -0400 | |
5776 | +++ linux-2.6.29.6/arch/x86/include/asm/pgtable_64.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5777 | @@ -15,9 +15,12 @@ |
5778 | ||
5779 | extern pud_t level3_kernel_pgt[512]; | |
5780 | extern pud_t level3_ident_pgt[512]; | |
5781 | +extern pud_t level3_vmalloc_pgt[512]; | |
5782 | +extern pud_t level3_vmemmap_pgt[512]; | |
5783 | extern pmd_t level2_kernel_pgt[512]; | |
5784 | extern pmd_t level2_fixmap_pgt[512]; | |
5785 | -extern pmd_t level2_ident_pgt[512]; | |
5786 | +extern pmd_t level2_ident_pgt[512*4]; | |
5787 | +extern pte_t level1_fixmap_pgt[512]; | |
5788 | extern pgd_t init_level4_pgt[]; | |
5789 | ||
5790 | #define swapper_pg_dir init_level4_pgt | |
5791 | @@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_ | |
5792 | ||
5793 | static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd) | |
5794 | { | |
5795 | + | |
5796 | +#ifdef CONFIG_PAX_KERNEXEC | |
5797 | + unsigned long cr0; | |
5798 | + | |
5799 | + pax_open_kernel(cr0); | |
5800 | +#endif | |
5801 | + | |
5802 | *pmdp = pmd; | |
5803 | + | |
5804 | +#ifdef CONFIG_PAX_KERNEXEC | |
5805 | + pax_close_kernel(cr0); | |
5806 | +#endif | |
5807 | + | |
5808 | } | |
5809 | ||
5810 | static inline void native_pmd_clear(pmd_t *pmd) | |
5811 | @@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_ | |
5812 | ||
5813 | static inline int pgd_bad(pgd_t pgd) | |
5814 | { | |
5815 | - return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE; | |
5816 | + return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE; | |
5817 | } | |
5818 | ||
5819 | static inline int pud_bad(pud_t pud) | |
5820 | { | |
5821 | - return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE; | |
5822 | + return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE; | |
5823 | } | |
5824 | ||
5825 | static inline int pmd_bad(pmd_t pmd) | |
5826 | { | |
5827 | - return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE; | |
5828 | + return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE; | |
5829 | } | |
5830 | ||
5831 | #define pte_none(x) (!pte_val((x))) | |
de855c5d AM |
5832 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/pgtable.h linux-2.6.29.6/arch/x86/include/asm/pgtable.h |
5833 | --- linux-2.6.29.6/arch/x86/include/asm/pgtable.h 2009-07-02 19:41:20.000000000 -0400 | |
5834 | +++ linux-2.6.29.6/arch/x86/include/asm/pgtable.h 2009-07-10 07:20:51.000000000 -0400 | |
2380c486 JR |
5835 | @@ -13,12 +13,11 @@ |
5836 | #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */ | |
5837 | #define _PAGE_BIT_PAT 7 /* on 4KB pages */ | |
5838 | #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */ | |
5839 | -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */ | |
5840 | +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */ | |
5841 | #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */ | |
5842 | #define _PAGE_BIT_UNUSED3 11 | |
5843 | #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */ | |
5844 | -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1 | |
5845 | -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1 | |
5846 | +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL | |
5847 | #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */ | |
5848 | ||
5849 | /* If _PAGE_BIT_PRESENT is clear, we use these: */ | |
5850 | @@ -36,7 +35,6 @@ | |
5851 | #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY) | |
5852 | #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE) | |
5853 | #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL) | |
5854 | -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1) | |
5855 | #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP) | |
5856 | #define _PAGE_UNUSED3 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3) | |
5857 | #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT) | |
5858 | @@ -48,7 +46,7 @@ | |
5859 | #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) | |
5860 | #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX) | |
5861 | #else | |
5862 | -#define _PAGE_NX (_AT(pteval_t, 0)) | |
5863 | +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3) | |
5864 | #endif | |
5865 | ||
5866 | #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE) | |
5867 | @@ -85,6 +83,9 @@ | |
5868 | #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \ | |
5869 | _PAGE_ACCESSED) | |
5870 | ||
5871 | +#define PAGE_READONLY_NOEXEC PAGE_READONLY | |
5872 | +#define PAGE_SHARED_NOEXEC PAGE_SHARED | |
5873 | + | |
5874 | #define __PAGE_KERNEL_EXEC \ | |
5875 | (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL) | |
5876 | #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX) | |
de855c5d AM |
5877 | @@ -95,8 +96,13 @@ |
5878 | #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC) | |
2380c486 JR |
5879 | #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT) |
5880 | #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD) | |
de855c5d AM |
5881 | +#ifdef CONFIG_PAX_SECURE_VSYSCALL |
5882 | +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER) | |
2380c486 | 5883 | +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER) |
de855c5d AM |
5884 | +#else |
5885 | #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER) | |
5886 | #define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT) | |
5887 | +#endif | |
2380c486 JR |
5888 | #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) |
5889 | #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE) | |
5890 | #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE) | |
de855c5d | 5891 | @@ -155,7 +161,7 @@ |
2380c486 JR |
5892 | * bits are combined, this will alow user to access the high address mapped |
5893 | * VDSO in the presence of CONFIG_COMPAT_VDSO | |
5894 | */ | |
5895 | -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */ | |
5896 | +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */ | |
5897 | #define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */ | |
5898 | #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */ | |
5899 | #endif | |
de855c5d | 5900 | @@ -183,10 +189,17 @@ extern unsigned long empty_zero_page[PAG |
2380c486 JR |
5901 | extern spinlock_t pgd_lock; |
5902 | extern struct list_head pgd_list; | |
5903 | ||
5904 | +extern pteval_t __supported_pte_mask; | |
5905 | + | |
5906 | /* | |
5907 | * The following only work if pte_present() is true. | |
5908 | * Undefined behaviour if not.. | |
5909 | */ | |
5910 | +static inline int pte_user(pte_t pte) | |
5911 | +{ | |
5912 | + return pte_val(pte) & _PAGE_USER; | |
5913 | +} | |
5914 | + | |
5915 | static inline int pte_dirty(pte_t pte) | |
5916 | { | |
5917 | return pte_flags(pte) & _PAGE_DIRTY; | |
de855c5d | 5918 | @@ -255,9 +268,29 @@ static inline pte_t pte_wrprotect(pte_t |
2380c486 JR |
5919 | return __pte(pte_val(pte) & ~_PAGE_RW); |
5920 | } | |
5921 | ||
5922 | +static inline pte_t pte_mkread(pte_t pte) | |
5923 | +{ | |
5924 | + return __pte(pte_val(pte) | _PAGE_USER); | |
5925 | +} | |
5926 | + | |
5927 | static inline pte_t pte_mkexec(pte_t pte) | |
5928 | { | |
5929 | - return __pte(pte_val(pte) & ~_PAGE_NX); | |
5930 | +#ifdef CONFIG_X86_PAE | |
5931 | + if (__supported_pte_mask & _PAGE_NX) | |
5932 | + return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX); | |
5933 | + else | |
5934 | +#endif | |
5935 | + return __pte(pte_val(pte) | _PAGE_USER); | |
5936 | +} | |
5937 | + | |
5938 | +static inline pte_t pte_exprotect(pte_t pte) | |
5939 | +{ | |
5940 | +#ifdef CONFIG_X86_PAE | |
5941 | + if (__supported_pte_mask & _PAGE_NX) | |
5942 | + return __pte(pte_val(pte) | _PAGE_NX); | |
5943 | + else | |
5944 | +#endif | |
5945 | + return __pte(pte_val(pte) & ~_PAGE_USER); | |
5946 | } | |
5947 | ||
5948 | static inline pte_t pte_mkdirty(pte_t pte) | |
de855c5d | 5949 | @@ -300,8 +333,6 @@ static inline pte_t pte_mkspecial(pte_t |
2380c486 JR |
5950 | return __pte(pte_val(pte) | _PAGE_SPECIAL); |
5951 | } | |
5952 | ||
5953 | -extern pteval_t __supported_pte_mask; | |
5954 | - | |
5955 | /* | |
5956 | * Mask out unsupported bits in a present pgprot. Non-present pgprots | |
5957 | * can use those bits for other purposes, so leave them be. | |
de855c5d | 5958 | @@ -601,7 +632,19 @@ static inline void ptep_set_wrprotect(st |
2380c486 JR |
5959 | */ |
5960 | static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count) | |
5961 | { | |
5962 | - memcpy(dst, src, count * sizeof(pgd_t)); | |
5963 | + | |
5964 | +#ifdef CONFIG_PAX_KERNEXEC | |
5965 | + unsigned long cr0; | |
5966 | + | |
5967 | + pax_open_kernel(cr0); | |
5968 | +#endif | |
5969 | + | |
5970 | + memcpy(dst, src, count * sizeof(pgd_t)); | |
5971 | + | |
5972 | +#ifdef CONFIG_PAX_KERNEXEC | |
5973 | + pax_close_kernel(cr0); | |
5974 | +#endif | |
5975 | + | |
5976 | } | |
5977 | ||
5978 | ||
de855c5d AM |
5979 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/processor.h linux-2.6.29.6/arch/x86/include/asm/processor.h |
5980 | --- linux-2.6.29.6/arch/x86/include/asm/processor.h 2009-07-02 19:41:20.000000000 -0400 | |
5981 | +++ linux-2.6.29.6/arch/x86/include/asm/processor.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
5982 | @@ -275,7 +275,7 @@ struct tss_struct { |
5983 | ||
5984 | } ____cacheline_aligned; | |
5985 | ||
5986 | -DECLARE_PER_CPU(struct tss_struct, init_tss); | |
5987 | +extern struct tss_struct init_tss[NR_CPUS]; | |
5988 | ||
5989 | /* | |
5990 | * Save the original ist values for checking stack pointers during debugging | |
5991 | @@ -839,11 +839,20 @@ static inline void spin_lock_prefetch(co | |
5992 | * User space process size: 3GB (default). | |
5993 | */ | |
5994 | #define TASK_SIZE PAGE_OFFSET | |
5995 | + | |
5996 | +#ifdef CONFIG_PAX_SEGMEXEC | |
5997 | +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2) | |
5998 | +#endif | |
5999 | + | |
6000 | +#ifdef CONFIG_PAX_SEGMEXEC | |
6001 | +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE) | |
6002 | +#else | |
6003 | #define STACK_TOP TASK_SIZE | |
6004 | -#define STACK_TOP_MAX STACK_TOP | |
6005 | +#endif | |
6006 | +#define STACK_TOP_MAX TASK_SIZE | |
6007 | ||
6008 | #define INIT_THREAD { \ | |
6009 | - .sp0 = sizeof(init_stack) + (long)&init_stack, \ | |
6010 | + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \ | |
6011 | .vm86_info = NULL, \ | |
6012 | .sysenter_cs = __KERNEL_CS, \ | |
6013 | .io_bitmap_ptr = NULL, \ | |
6014 | @@ -858,7 +867,7 @@ static inline void spin_lock_prefetch(co | |
6015 | */ | |
6016 | #define INIT_TSS { \ | |
6017 | .x86_tss = { \ | |
6018 | - .sp0 = sizeof(init_stack) + (long)&init_stack, \ | |
6019 | + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \ | |
6020 | .ss0 = __KERNEL_DS, \ | |
6021 | .ss1 = __KERNEL_CS, \ | |
6022 | .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \ | |
6023 | @@ -869,11 +878,7 @@ static inline void spin_lock_prefetch(co | |
6024 | extern unsigned long thread_saved_pc(struct task_struct *tsk); | |
6025 | ||
6026 | #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long)) | |
6027 | -#define KSTK_TOP(info) \ | |
6028 | -({ \ | |
6029 | - unsigned long *__ptr = (unsigned long *)(info); \ | |
6030 | - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \ | |
6031 | -}) | |
6032 | +#define KSTK_TOP(info) ((info)->task.thread.sp0) | |
6033 | ||
6034 | /* | |
6035 | * The below -8 is to reserve 8 bytes on top of the ring0 stack. | |
6036 | @@ -888,7 +893,7 @@ extern unsigned long thread_saved_pc(str | |
6037 | #define task_pt_regs(task) \ | |
6038 | ({ \ | |
6039 | struct pt_regs *__regs__; \ | |
6040 | - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \ | |
6041 | + __regs__ = (struct pt_regs *)((task)->thread.sp0); \ | |
6042 | __regs__ - 1; \ | |
6043 | }) | |
6044 | ||
6045 | @@ -904,7 +909,7 @@ extern unsigned long thread_saved_pc(str | |
6046 | * space during mmap's. | |
6047 | */ | |
6048 | #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \ | |
6049 | - 0xc0000000 : 0xFFFFe000) | |
6050 | + 0xc0000000 : 0xFFFFf000) | |
6051 | ||
6052 | #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \ | |
6053 | IA32_PAGE_OFFSET : TASK_SIZE64) | |
6054 | @@ -941,6 +946,10 @@ extern void start_thread(struct pt_regs | |
6055 | */ | |
6056 | #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) | |
6057 | ||
6058 | +#ifdef CONFIG_PAX_SEGMEXEC | |
6059 | +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3)) | |
6060 | +#endif | |
6061 | + | |
6062 | #define KSTK_EIP(task) (task_pt_regs(task)->ip) | |
6063 | ||
6064 | /* Get/set a process' ability to use the timestamp counter instruction */ | |
de855c5d AM |
6065 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/ptrace.h linux-2.6.29.6/arch/x86/include/asm/ptrace.h |
6066 | --- linux-2.6.29.6/arch/x86/include/asm/ptrace.h 2009-07-02 19:41:20.000000000 -0400 | |
6067 | +++ linux-2.6.29.6/arch/x86/include/asm/ptrace.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6068 | @@ -151,28 +151,29 @@ static inline unsigned long regs_return_ |
6069 | } | |
6070 | ||
6071 | /* | |
6072 | - * user_mode_vm(regs) determines whether a register set came from user mode. | |
6073 | + * user_mode(regs) determines whether a register set came from user mode. | |
6074 | * This is true if V8086 mode was enabled OR if the register set was from | |
6075 | * protected mode with RPL-3 CS value. This tricky test checks that with | |
6076 | * one comparison. Many places in the kernel can bypass this full check | |
6077 | - * if they have already ruled out V8086 mode, so user_mode(regs) can be used. | |
6078 | + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can | |
6079 | + * be used. | |
6080 | */ | |
6081 | -static inline int user_mode(struct pt_regs *regs) | |
6082 | +static inline int user_mode_novm(struct pt_regs *regs) | |
6083 | { | |
6084 | #ifdef CONFIG_X86_32 | |
6085 | return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL; | |
6086 | #else | |
6087 | - return !!(regs->cs & 3); | |
6088 | + return !!(regs->cs & SEGMENT_RPL_MASK); | |
6089 | #endif | |
6090 | } | |
6091 | ||
6092 | -static inline int user_mode_vm(struct pt_regs *regs) | |
6093 | +static inline int user_mode(struct pt_regs *regs) | |
6094 | { | |
6095 | #ifdef CONFIG_X86_32 | |
6096 | return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= | |
6097 | USER_RPL; | |
6098 | #else | |
6099 | - return user_mode(regs); | |
6100 | + return user_mode_novm(regs); | |
6101 | #endif | |
6102 | } | |
6103 | ||
de855c5d AM |
6104 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/reboot.h linux-2.6.29.6/arch/x86/include/asm/reboot.h |
6105 | --- linux-2.6.29.6/arch/x86/include/asm/reboot.h 2009-07-02 19:41:20.000000000 -0400 | |
6106 | +++ linux-2.6.29.6/arch/x86/include/asm/reboot.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6107 | @@ -18,7 +18,7 @@ extern struct machine_ops machine_ops; |
6108 | ||
6109 | void native_machine_crash_shutdown(struct pt_regs *regs); | |
6110 | void native_machine_shutdown(void); | |
6111 | -void machine_real_restart(const unsigned char *code, int length); | |
6112 | +void machine_real_restart(const unsigned char *code, unsigned int length); | |
6113 | ||
6114 | typedef void (*nmi_shootdown_cb)(int, struct die_args*); | |
6115 | void nmi_shootdown_cpus(nmi_shootdown_cb callback); | |
de855c5d AM |
6116 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/rwsem.h linux-2.6.29.6/arch/x86/include/asm/rwsem.h |
6117 | --- linux-2.6.29.6/arch/x86/include/asm/rwsem.h 2009-07-02 19:41:20.000000000 -0400 | |
6118 | +++ linux-2.6.29.6/arch/x86/include/asm/rwsem.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6119 | @@ -106,10 +106,26 @@ static inline void __down_read(struct rw |
6120 | { | |
6121 | asm volatile("# beginning down_read\n\t" | |
6122 | LOCK_PREFIX " incl (%%eax)\n\t" | |
6123 | + | |
6124 | +#ifdef CONFIG_PAX_REFCOUNT | |
6125 | +#ifdef CONFIG_X86_32 | |
6126 | + "into\n0:\n" | |
6127 | +#else | |
6128 | + "jno 0f\n" | |
6129 | + "int $4\n0:\n" | |
6130 | +#endif | |
6131 | + ".pushsection .fixup,\"ax\"\n" | |
6132 | + "1:\n" | |
6133 | + LOCK_PREFIX "decl (%%eax)\n" | |
6134 | + "jmp 0b\n" | |
6135 | + ".popsection\n" | |
6136 | + _ASM_EXTABLE(0b, 1b) | |
6137 | +#endif | |
6138 | + | |
6139 | /* adds 0x00000001, returns the old value */ | |
6140 | - " jns 1f\n" | |
6141 | + " jns 2f\n" | |
6142 | " call call_rwsem_down_read_failed\n" | |
6143 | - "1:\n\t" | |
6144 | + "2:\n\t" | |
6145 | "# ending down_read\n\t" | |
6146 | : "+m" (sem->count) | |
6147 | : "a" (sem) | |
6148 | @@ -124,13 +140,29 @@ static inline int __down_read_trylock(st | |
6149 | __s32 result, tmp; | |
6150 | asm volatile("# beginning __down_read_trylock\n\t" | |
6151 | " movl %0,%1\n\t" | |
6152 | - "1:\n\t" | |
6153 | + "2:\n\t" | |
6154 | " movl %1,%2\n\t" | |
6155 | " addl %3,%2\n\t" | |
6156 | - " jle 2f\n\t" | |
6157 | + | |
6158 | +#ifdef CONFIG_PAX_REFCOUNT | |
6159 | +#ifdef CONFIG_X86_32 | |
6160 | + "into\n0:\n" | |
6161 | +#else | |
6162 | + "jno 0f\n" | |
6163 | + "int $4\n0:\n" | |
6164 | +#endif | |
6165 | + ".pushsection .fixup,\"ax\"\n" | |
6166 | + "1:\n" | |
6167 | + "subl %3,%2\n" | |
6168 | + "jmp 0b\n" | |
6169 | + ".popsection\n" | |
6170 | + _ASM_EXTABLE(0b, 1b) | |
6171 | +#endif | |
6172 | + | |
6173 | + " jle 3f\n\t" | |
6174 | LOCK_PREFIX " cmpxchgl %2,%0\n\t" | |
6175 | - " jnz 1b\n\t" | |
6176 | - "2:\n\t" | |
6177 | + " jnz 2b\n\t" | |
6178 | + "3:\n\t" | |
6179 | "# ending __down_read_trylock\n\t" | |
6180 | : "+m" (sem->count), "=&a" (result), "=&r" (tmp) | |
6181 | : "i" (RWSEM_ACTIVE_READ_BIAS) | |
6182 | @@ -148,12 +180,28 @@ static inline void __down_write_nested(s | |
6183 | tmp = RWSEM_ACTIVE_WRITE_BIAS; | |
6184 | asm volatile("# beginning down_write\n\t" | |
6185 | LOCK_PREFIX " xadd %%edx,(%%eax)\n\t" | |
6186 | + | |
6187 | +#ifdef CONFIG_PAX_REFCOUNT | |
6188 | +#ifdef CONFIG_X86_32 | |
6189 | + "into\n0:\n" | |
6190 | +#else | |
6191 | + "jno 0f\n" | |
6192 | + "int $4\n0:\n" | |
6193 | +#endif | |
6194 | + ".pushsection .fixup,\"ax\"\n" | |
6195 | + "1:\n" | |
6196 | + "movl %%edx,(%%eax)\n" | |
6197 | + "jmp 0b\n" | |
6198 | + ".popsection\n" | |
6199 | + _ASM_EXTABLE(0b, 1b) | |
6200 | +#endif | |
6201 | + | |
6202 | /* subtract 0x0000ffff, returns the old value */ | |
6203 | " testl %%edx,%%edx\n\t" | |
6204 | /* was the count 0 before? */ | |
6205 | - " jz 1f\n" | |
6206 | + " jz 2f\n" | |
6207 | " call call_rwsem_down_write_failed\n" | |
6208 | - "1:\n" | |
6209 | + "2:\n" | |
6210 | "# ending down_write" | |
6211 | : "+m" (sem->count), "=d" (tmp) | |
6212 | : "a" (sem), "1" (tmp) | |
6213 | @@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s | |
6214 | __s32 tmp = -RWSEM_ACTIVE_READ_BIAS; | |
6215 | asm volatile("# beginning __up_read\n\t" | |
6216 | LOCK_PREFIX " xadd %%edx,(%%eax)\n\t" | |
6217 | + | |
6218 | +#ifdef CONFIG_PAX_REFCOUNT | |
6219 | +#ifdef CONFIG_X86_32 | |
6220 | + "into\n0:\n" | |
6221 | +#else | |
6222 | + "jno 0f\n" | |
6223 | + "int $4\n0:\n" | |
6224 | +#endif | |
6225 | + ".pushsection .fixup,\"ax\"\n" | |
6226 | + "1:\n" | |
6227 | + "movl %%edx,(%%eax)\n" | |
6228 | + "jmp 0b\n" | |
6229 | + ".popsection\n" | |
6230 | + _ASM_EXTABLE(0b, 1b) | |
6231 | +#endif | |
6232 | + | |
6233 | /* subtracts 1, returns the old value */ | |
6234 | - " jns 1f\n\t" | |
6235 | + " jns 2f\n\t" | |
6236 | " call call_rwsem_wake\n" | |
6237 | - "1:\n" | |
6238 | + "2:\n" | |
6239 | "# ending __up_read\n" | |
6240 | : "+m" (sem->count), "=d" (tmp) | |
6241 | : "a" (sem), "1" (tmp) | |
6242 | @@ -204,11 +268,27 @@ static inline void __up_write(struct rw_ | |
6243 | asm volatile("# beginning __up_write\n\t" | |
6244 | " movl %2,%%edx\n\t" | |
6245 | LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t" | |
6246 | + | |
6247 | +#ifdef CONFIG_PAX_REFCOUNT | |
6248 | +#ifdef CONFIG_X86_32 | |
6249 | + "into\n0:\n" | |
6250 | +#else | |
6251 | + "jno 0f\n" | |
6252 | + "int $4\n0:\n" | |
6253 | +#endif | |
6254 | + ".pushsection .fixup,\"ax\"\n" | |
6255 | + "1:\n" | |
6256 | + "movl %%edx,(%%eax)\n" | |
6257 | + "jmp 0b\n" | |
6258 | + ".popsection\n" | |
6259 | + _ASM_EXTABLE(0b, 1b) | |
6260 | +#endif | |
6261 | + | |
6262 | /* tries to transition | |
6263 | 0xffff0001 -> 0x00000000 */ | |
6264 | - " jz 1f\n" | |
6265 | + " jz 2f\n" | |
6266 | " call call_rwsem_wake\n" | |
6267 | - "1:\n\t" | |
6268 | + "2:\n\t" | |
6269 | "# ending __up_write\n" | |
6270 | : "+m" (sem->count) | |
6271 | : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS) | |
6272 | @@ -222,10 +302,26 @@ static inline void __downgrade_write(str | |
6273 | { | |
6274 | asm volatile("# beginning __downgrade_write\n\t" | |
6275 | LOCK_PREFIX " addl %2,(%%eax)\n\t" | |
6276 | + | |
6277 | +#ifdef CONFIG_PAX_REFCOUNT | |
6278 | +#ifdef CONFIG_X86_32 | |
6279 | + "into\n0:\n" | |
6280 | +#else | |
6281 | + "jno 0f\n" | |
6282 | + "int $4\n0:\n" | |
6283 | +#endif | |
6284 | + ".pushsection .fixup,\"ax\"\n" | |
6285 | + "1:\n" | |
6286 | + LOCK_PREFIX "subl %2,(%%eax)\n" | |
6287 | + "jmp 0b\n" | |
6288 | + ".popsection\n" | |
6289 | + _ASM_EXTABLE(0b, 1b) | |
6290 | +#endif | |
6291 | + | |
6292 | /* transitions 0xZZZZ0001 -> 0xYYYY0001 */ | |
6293 | - " jns 1f\n\t" | |
6294 | + " jns 2f\n\t" | |
6295 | " call call_rwsem_downgrade_wake\n" | |
6296 | - "1:\n\t" | |
6297 | + "2:\n\t" | |
6298 | "# ending __downgrade_write\n" | |
6299 | : "+m" (sem->count) | |
6300 | : "a" (sem), "i" (-RWSEM_WAITING_BIAS) | |
6301 | @@ -237,7 +333,23 @@ static inline void __downgrade_write(str | |
6302 | */ | |
6303 | static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem) | |
6304 | { | |
6305 | - asm volatile(LOCK_PREFIX "addl %1,%0" | |
6306 | + asm volatile(LOCK_PREFIX "addl %1,%0\n" | |
6307 | + | |
6308 | +#ifdef CONFIG_PAX_REFCOUNT | |
6309 | +#ifdef CONFIG_X86_32 | |
6310 | + "into\n0:\n" | |
6311 | +#else | |
6312 | + "jno 0f\n" | |
6313 | + "int $4\n0:\n" | |
6314 | +#endif | |
6315 | + ".pushsection .fixup,\"ax\"\n" | |
6316 | + "1:\n" | |
6317 | + LOCK_PREFIX "subl %1,%0\n" | |
6318 | + "jmp 0b\n" | |
6319 | + ".popsection\n" | |
6320 | + _ASM_EXTABLE(0b, 1b) | |
6321 | +#endif | |
6322 | + | |
6323 | : "+m" (sem->count) | |
6324 | : "ir" (delta)); | |
6325 | } | |
6326 | @@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in | |
6327 | { | |
6328 | int tmp = delta; | |
6329 | ||
6330 | - asm volatile(LOCK_PREFIX "xadd %0,%1" | |
6331 | + asm volatile(LOCK_PREFIX "xadd %0,%1\n" | |
6332 | + | |
6333 | +#ifdef CONFIG_PAX_REFCOUNT | |
6334 | +#ifdef CONFIG_X86_32 | |
6335 | + "into\n0:\n" | |
6336 | +#else | |
6337 | + "jno 0f\n" | |
6338 | + "int $4\n0:\n" | |
6339 | +#endif | |
6340 | + ".pushsection .fixup,\"ax\"\n" | |
6341 | + "1:\n" | |
6342 | + "movl %0,%1\n" | |
6343 | + "jmp 0b\n" | |
6344 | + ".popsection\n" | |
6345 | + _ASM_EXTABLE(0b, 1b) | |
6346 | +#endif | |
6347 | + | |
6348 | : "+r" (tmp), "+m" (sem->count) | |
6349 | : : "memory"); | |
6350 | ||
de855c5d AM |
6351 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/segment.h linux-2.6.29.6/arch/x86/include/asm/segment.h |
6352 | --- linux-2.6.29.6/arch/x86/include/asm/segment.h 2009-07-02 19:41:20.000000000 -0400 | |
6353 | +++ linux-2.6.29.6/arch/x86/include/asm/segment.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6354 | @@ -88,13 +88,19 @@ |
6355 | #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14) | |
6356 | #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8) | |
6357 | ||
6358 | -#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15) | |
6359 | +#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15) | |
6360 | #ifdef CONFIG_SMP | |
6361 | #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8) | |
6362 | #else | |
6363 | #define __KERNEL_PERCPU 0 | |
6364 | #endif | |
6365 | ||
6366 | +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16) | |
6367 | +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8) | |
6368 | + | |
6369 | +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17) | |
6370 | +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8) | |
6371 | + | |
6372 | #define GDT_ENTRY_DOUBLEFAULT_TSS 31 | |
6373 | ||
6374 | /* | |
6375 | @@ -132,7 +138,7 @@ | |
6376 | */ | |
6377 | ||
6378 | /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */ | |
6379 | -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8) | |
6380 | +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16) | |
6381 | ||
6382 | ||
6383 | #else | |
de855c5d AM |
6384 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/spinlock.h linux-2.6.29.6/arch/x86/include/asm/spinlock.h |
6385 | --- linux-2.6.29.6/arch/x86/include/asm/spinlock.h 2009-07-02 19:41:20.000000000 -0400 | |
6386 | +++ linux-2.6.29.6/arch/x86/include/asm/spinlock.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6387 | @@ -311,18 +311,50 @@ static inline int __raw_write_can_lock(r |
6388 | static inline void __raw_read_lock(raw_rwlock_t *rw) | |
6389 | { | |
6390 | asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t" | |
6391 | - "jns 1f\n" | |
6392 | - "call __read_lock_failed\n\t" | |
6393 | + | |
6394 | +#ifdef CONFIG_PAX_REFCOUNT | |
6395 | +#ifdef CONFIG_X86_32 | |
6396 | + "into\n0:\n" | |
6397 | +#else | |
6398 | + "jno 0f\n" | |
6399 | + "int $4\n0:\n" | |
6400 | +#endif | |
6401 | + ".pushsection .fixup,\"ax\"\n" | |
6402 | "1:\n" | |
6403 | + LOCK_PREFIX " addl $1,(%0)\n" | |
6404 | + "jmp 0b\n" | |
6405 | + ".popsection\n" | |
6406 | + _ASM_EXTABLE(0b, 1b) | |
6407 | +#endif | |
6408 | + | |
6409 | + "jns 2f\n" | |
6410 | + "call __read_lock_failed\n\t" | |
6411 | + "2:\n" | |
6412 | ::LOCK_PTR_REG (rw) : "memory"); | |
6413 | } | |
6414 | ||
6415 | static inline void __raw_write_lock(raw_rwlock_t *rw) | |
6416 | { | |
6417 | asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t" | |
6418 | - "jz 1f\n" | |
6419 | - "call __write_lock_failed\n\t" | |
6420 | + | |
6421 | +#ifdef CONFIG_PAX_REFCOUNT | |
6422 | +#ifdef CONFIG_X86_32 | |
6423 | + "into\n0:\n" | |
6424 | +#else | |
6425 | + "jno 0f\n" | |
6426 | + "int $4\n0:\n" | |
6427 | +#endif | |
6428 | + ".pushsection .fixup,\"ax\"\n" | |
6429 | "1:\n" | |
6430 | + LOCK_PREFIX " addl %1,(%0)\n" | |
6431 | + "jmp 0b\n" | |
6432 | + ".popsection\n" | |
6433 | + _ASM_EXTABLE(0b, 1b) | |
6434 | +#endif | |
6435 | + | |
6436 | + "jz 2f\n" | |
6437 | + "call __write_lock_failed\n\t" | |
6438 | + "2:\n" | |
6439 | ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory"); | |
6440 | } | |
6441 | ||
6442 | @@ -349,12 +381,45 @@ static inline int __raw_write_trylock(ra | |
6443 | ||
6444 | static inline void __raw_read_unlock(raw_rwlock_t *rw) | |
6445 | { | |
6446 | - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory"); | |
6447 | + asm volatile(LOCK_PREFIX "incl %0\n" | |
6448 | + | |
6449 | +#ifdef CONFIG_PAX_REFCOUNT | |
6450 | +#ifdef CONFIG_X86_32 | |
6451 | + "into\n0:\n" | |
6452 | +#else | |
6453 | + "jno 0f\n" | |
6454 | + "int $4\n0:\n" | |
6455 | +#endif | |
6456 | + ".pushsection .fixup,\"ax\"\n" | |
6457 | + "1:\n" | |
6458 | + LOCK_PREFIX "decl %0\n" | |
6459 | + "jmp 0b\n" | |
6460 | + ".popsection\n" | |
6461 | + _ASM_EXTABLE(0b, 1b) | |
6462 | +#endif | |
6463 | + | |
6464 | + :"+m" (rw->lock) : : "memory"); | |
6465 | } | |
6466 | ||
6467 | static inline void __raw_write_unlock(raw_rwlock_t *rw) | |
6468 | { | |
6469 | - asm volatile(LOCK_PREFIX "addl %1, %0" | |
6470 | + asm volatile(LOCK_PREFIX "addl %1, %0\n" | |
6471 | + | |
6472 | +#ifdef CONFIG_PAX_REFCOUNT | |
6473 | +#ifdef CONFIG_X86_32 | |
6474 | + "into\n0:\n" | |
6475 | +#else | |
6476 | + "jno 0f\n" | |
6477 | + "int $4\n0:\n" | |
6478 | +#endif | |
6479 | + ".pushsection .fixup,\"ax\"\n" | |
6480 | + "1:\n" | |
6481 | + LOCK_PREFIX "subl %1,%0\n" | |
6482 | + "jmp 0b\n" | |
6483 | + ".popsection\n" | |
6484 | + _ASM_EXTABLE(0b, 1b) | |
6485 | +#endif | |
6486 | + | |
6487 | : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory"); | |
6488 | } | |
6489 | ||
de855c5d AM |
6490 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/system.h linux-2.6.29.6/arch/x86/include/asm/system.h |
6491 | --- linux-2.6.29.6/arch/x86/include/asm/system.h 2009-07-02 19:41:20.000000000 -0400 | |
6492 | +++ linux-2.6.29.6/arch/x86/include/asm/system.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6493 | @@ -95,6 +95,8 @@ do { \ |
6494 | ".globl thread_return\n" \ | |
6495 | "thread_return:\n\t" \ | |
6496 | "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \ | |
6497 | + "movq %P[task_canary](%%rsi),%%r8\n\t" \ | |
6498 | + "movq %%r8,%%gs:%P[pda_canary]\n\t" \ | |
6499 | "movq %P[thread_info](%%rsi),%%r8\n\t" \ | |
6500 | LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \ | |
6501 | "movq %%rax,%%rdi\n\t" \ | |
6502 | @@ -106,7 +108,9 @@ do { \ | |
6503 | [ti_flags] "i" (offsetof(struct thread_info, flags)), \ | |
6504 | [tif_fork] "i" (TIF_FORK), \ | |
6505 | [thread_info] "i" (offsetof(struct task_struct, stack)), \ | |
6506 | - [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \ | |
6507 | + [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \ | |
6508 | + [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \ | |
6509 | + [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\ | |
6510 | : "memory", "cc" __EXTRA_CLOBBER) | |
6511 | #endif | |
6512 | ||
6513 | @@ -169,7 +173,7 @@ static inline unsigned long get_limit(un | |
6514 | { | |
6515 | unsigned long __limit; | |
6516 | asm("lsll %1,%0" : "=r" (__limit) : "r" (segment)); | |
6517 | - return __limit + 1; | |
6518 | + return __limit; | |
6519 | } | |
6520 | ||
6521 | static inline void native_clts(void) | |
6522 | @@ -295,6 +299,21 @@ static inline void native_wbinvd(void) | |
6523 | ||
6524 | #define stts() write_cr0(read_cr0() | X86_CR0_TS) | |
6525 | ||
6526 | +#define pax_open_kernel(cr0) \ | |
6527 | +do { \ | |
6528 | + typecheck(unsigned long, cr0); \ | |
6529 | + preempt_disable(); \ | |
6530 | + cr0 = read_cr0(); \ | |
6531 | + write_cr0(cr0 & ~X86_CR0_WP); \ | |
6532 | +} while (0) | |
6533 | + | |
6534 | +#define pax_close_kernel(cr0) \ | |
6535 | +do { \ | |
6536 | + typecheck(unsigned long, cr0); \ | |
6537 | + write_cr0(cr0); \ | |
6538 | + preempt_enable_no_resched(); \ | |
6539 | +} while (0) | |
6540 | + | |
6541 | #endif /* __KERNEL__ */ | |
6542 | ||
6543 | static inline void clflush(volatile void *__p) | |
6544 | @@ -309,7 +328,7 @@ void enable_hlt(void); | |
6545 | ||
6546 | void cpu_idle_wait(void); | |
6547 | ||
6548 | -extern unsigned long arch_align_stack(unsigned long sp); | |
6549 | +#define arch_align_stack(x) ((x) & ~0xfUL) | |
6550 | extern void free_init_pages(char *what, unsigned long begin, unsigned long end); | |
6551 | ||
6552 | void default_idle(void); | |
de855c5d AM |
6553 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/uaccess_32.h linux-2.6.29.6/arch/x86/include/asm/uaccess_32.h |
6554 | --- linux-2.6.29.6/arch/x86/include/asm/uaccess_32.h 2009-07-02 19:41:20.000000000 -0400 | |
6555 | +++ linux-2.6.29.6/arch/x86/include/asm/uaccess_32.h 2009-07-09 22:13:39.000000000 -0400 | |
6556 | @@ -62,6 +62,8 @@ __copy_to_user_inatomic(void __user *to, | |
6557 | return ret; | |
6558 | } | |
6559 | } | |
6560 | + if (!__builtin_constant_p(n)) | |
6561 | + check_object_size(from, n, true); | |
6562 | return __copy_to_user_ll(to, from, n); | |
6563 | } | |
6564 | ||
6565 | @@ -153,6 +155,8 @@ __copy_from_user(void *to, const void __ | |
6566 | return ret; | |
6567 | } | |
6568 | } | |
6569 | + if (!__builtin_constant_p(n)) | |
6570 | + check_object_size(to, n, false); | |
6571 | return __copy_from_user_ll(to, from, n); | |
6572 | } | |
6573 | ||
6574 | @@ -185,11 +189,56 @@ __copy_from_user_inatomic_nocache(void * | |
6575 | return __copy_from_user_ll_nocache_nozero(to, from, n); | |
6576 | } | |
6577 | ||
6578 | -unsigned long __must_check copy_to_user(void __user *to, | |
6579 | - const void *from, unsigned long n); | |
6580 | -unsigned long __must_check copy_from_user(void *to, | |
6581 | - const void __user *from, | |
6582 | - unsigned long n); | |
6583 | +/** | |
6584 | + * copy_to_user: - Copy a block of data into user space. | |
6585 | + * @to: Destination address, in user space. | |
6586 | + * @from: Source address, in kernel space. | |
6587 | + * @n: Number of bytes to copy. | |
6588 | + * | |
6589 | + * Context: User context only. This function may sleep. | |
6590 | + * | |
6591 | + * Copy data from kernel space to user space. | |
6592 | + * | |
6593 | + * Returns number of bytes that could not be copied. | |
6594 | + * On success, this will be zero. | |
6595 | + */ | |
6596 | +static __always_inline unsigned long __must_check | |
6597 | +copy_to_user(void __user *to, const void *from, unsigned long n) | |
6598 | +{ | |
6599 | + if (access_ok(VERIFY_WRITE, to, n)) | |
6600 | + n = __copy_to_user(to, from, n); | |
6601 | + return n; | |
6602 | +} | |
6603 | + | |
6604 | +/** | |
6605 | + * copy_from_user: - Copy a block of data from user space. | |
6606 | + * @to: Destination address, in kernel space. | |
6607 | + * @from: Source address, in user space. | |
6608 | + * @n: Number of bytes to copy. | |
6609 | + * | |
6610 | + * Context: User context only. This function may sleep. | |
6611 | + * | |
6612 | + * Copy data from user space to kernel space. | |
6613 | + * | |
6614 | + * Returns number of bytes that could not be copied. | |
6615 | + * On success, this will be zero. | |
6616 | + * | |
6617 | + * If some data could not be copied, this function will pad the copied | |
6618 | + * data to the requested size using zero bytes. | |
6619 | + */ | |
6620 | +static __always_inline unsigned long __must_check | |
6621 | +copy_from_user(void *to, const void __user *from, unsigned long n) | |
6622 | +{ | |
6623 | + if (access_ok(VERIFY_READ, from, n)) | |
6624 | + n = __copy_from_user(to, from, n); | |
6625 | + else if ((long)n > 0) { | |
6626 | + if (!__builtin_constant_p(n)) | |
6627 | + check_object_size(to, n, false); | |
6628 | + memset(to, 0, n); | |
6629 | + } | |
6630 | + return n; | |
6631 | +} | |
6632 | + | |
6633 | long __must_check strncpy_from_user(char *dst, const char __user *src, | |
6634 | long count); | |
6635 | long __must_check __strncpy_from_user(char *dst, | |
6636 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/uaccess_64.h linux-2.6.29.6/arch/x86/include/asm/uaccess_64.h | |
6637 | --- linux-2.6.29.6/arch/x86/include/asm/uaccess_64.h 2009-07-02 19:41:20.000000000 -0400 | |
6638 | +++ linux-2.6.29.6/arch/x86/include/asm/uaccess_64.h 2009-07-09 22:20:50.000000000 -0400 | |
2380c486 JR |
6639 | @@ -10,6 +10,8 @@ |
6640 | #include <linux/lockdep.h> | |
6641 | #include <asm/page.h> | |
6642 | ||
6643 | +#define set_fs(x) (current_thread_info()->addr_limit = (x)) | |
6644 | + | |
6645 | /* | |
6646 | * Copy To/From Userspace | |
6647 | */ | |
de855c5d AM |
6648 | @@ -19,20 +21,18 @@ __must_check unsigned long |
6649 | copy_user_generic(void *to, const void *from, unsigned len); | |
6650 | ||
6651 | __must_check unsigned long | |
6652 | -copy_to_user(void __user *to, const void *from, unsigned len); | |
6653 | -__must_check unsigned long | |
6654 | -copy_from_user(void *to, const void __user *from, unsigned len); | |
6655 | -__must_check unsigned long | |
6656 | copy_in_user(void __user *to, const void __user *from, unsigned len); | |
6657 | ||
6658 | static __always_inline __must_check | |
6659 | -int __copy_from_user(void *dst, const void __user *src, unsigned size) | |
6660 | +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size) | |
6661 | { | |
6662 | - int ret = 0; | |
6663 | + unsigned ret = 0; | |
6664 | ||
6665 | might_fault(); | |
6666 | - if (!__builtin_constant_p(size)) | |
6667 | + if (!__builtin_constant_p(size)) { | |
6668 | + check_object_size(dst, size, false); | |
6669 | return copy_user_generic(dst, (__force void *)src, size); | |
6670 | + } | |
6671 | switch (size) { | |
6672 | case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src, | |
6673 | ret, "b", "b", "=q", 1); | |
6674 | @@ -70,13 +70,15 @@ int __copy_from_user(void *dst, const vo | |
6675 | } | |
6676 | ||
6677 | static __always_inline __must_check | |
6678 | -int __copy_to_user(void __user *dst, const void *src, unsigned size) | |
6679 | +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size) | |
6680 | { | |
6681 | - int ret = 0; | |
6682 | + unsigned ret = 0; | |
6683 | ||
6684 | might_fault(); | |
6685 | - if (!__builtin_constant_p(size)) | |
6686 | + if (!__builtin_constant_p(size)) { | |
6687 | + check_object_size(src, size, true); | |
6688 | return copy_user_generic((__force void *)dst, src, size); | |
6689 | + } | |
6690 | switch (size) { | |
6691 | case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst, | |
6692 | ret, "b", "b", "iq", 1); | |
6693 | @@ -114,9 +116,30 @@ int __copy_to_user(void __user *dst, con | |
6694 | } | |
6695 | ||
6696 | static __always_inline __must_check | |
6697 | -int __copy_in_user(void __user *dst, const void __user *src, unsigned size) | |
6698 | +unsigned long copy_to_user(void __user *to, const void *from, unsigned len) | |
6699 | +{ | |
6700 | + if (access_ok(VERIFY_WRITE, to, len)) | |
6701 | + len = __copy_to_user(to, from, len); | |
6702 | + return len; | |
6703 | +} | |
6704 | + | |
6705 | +static __always_inline __must_check | |
6706 | +unsigned long copy_from_user(void *to, const void __user *from, unsigned len) | |
6707 | +{ | |
6708 | + if (access_ok(VERIFY_READ, from, len)) | |
6709 | + len = __copy_from_user(to, from, len); | |
6710 | + else if ((int)len > 0) { | |
6711 | + if (!__builtin_constant_p(len)) | |
6712 | + check_object_size(to, len, false); | |
6713 | + memset(to, 0, len); | |
6714 | + } | |
6715 | + return len; | |
6716 | +} | |
6717 | + | |
6718 | +static __always_inline __must_check | |
6719 | +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size) | |
6720 | { | |
6721 | - int ret = 0; | |
6722 | + unsigned ret = 0; | |
6723 | ||
6724 | might_fault(); | |
6725 | if (!__builtin_constant_p(size)) | |
6726 | @@ -179,30 +202,30 @@ __must_check unsigned long __clear_user( | |
6727 | __must_check long __copy_from_user_inatomic(void *dst, const void __user *src, | |
6728 | unsigned size); | |
6729 | ||
6730 | -static __must_check __always_inline int | |
6731 | +static __must_check __always_inline unsigned long | |
6732 | __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size) | |
6733 | { | |
6734 | return copy_user_generic((__force void *)dst, src, size); | |
6735 | } | |
6736 | ||
6737 | -extern long __copy_user_nocache(void *dst, const void __user *src, | |
6738 | +extern unsigned long __copy_user_nocache(void *dst, const void __user *src, | |
6739 | unsigned size, int zerorest); | |
6740 | ||
6741 | -static inline int __copy_from_user_nocache(void *dst, const void __user *src, | |
6742 | +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, | |
6743 | unsigned size) | |
6744 | { | |
6745 | might_sleep(); | |
6746 | return __copy_user_nocache(dst, src, size, 1); | |
6747 | } | |
6748 | ||
6749 | -static inline int __copy_from_user_inatomic_nocache(void *dst, | |
6750 | +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, | |
6751 | const void __user *src, | |
6752 | unsigned size) | |
6753 | { | |
6754 | return __copy_user_nocache(dst, src, size, 0); | |
6755 | } | |
6756 | ||
6757 | -unsigned long | |
6758 | +extern unsigned long | |
6759 | copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest); | |
6760 | ||
6761 | #endif /* _ASM_X86_UACCESS_64_H */ | |
6762 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/uaccess.h linux-2.6.29.6/arch/x86/include/asm/uaccess.h | |
6763 | --- linux-2.6.29.6/arch/x86/include/asm/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
6764 | +++ linux-2.6.29.6/arch/x86/include/asm/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
6765 | @@ -8,8 +8,10 @@ | |
6766 | #include <linux/thread_info.h> | |
6767 | #include <linux/prefetch.h> | |
2380c486 | 6768 | #include <linux/string.h> |
de855c5d | 6769 | +#include <linux/slab.h> |
2380c486 JR |
6770 | #include <asm/asm.h> |
6771 | #include <asm/page.h> | |
6772 | +#include <asm/segment.h> | |
6773 | ||
6774 | #define VERIFY_READ 0 | |
6775 | #define VERIFY_WRITE 1 | |
de855c5d | 6776 | @@ -29,7 +31,12 @@ |
2380c486 JR |
6777 | |
6778 | #define get_ds() (KERNEL_DS) | |
6779 | #define get_fs() (current_thread_info()->addr_limit) | |
6780 | +#ifdef CONFIG_X86_32 | |
6781 | +void __set_fs(mm_segment_t x, int cpu); | |
6782 | +void set_fs(mm_segment_t x); | |
6783 | +#else | |
6784 | #define set_fs(x) (current_thread_info()->addr_limit = (x)) | |
6785 | +#endif | |
6786 | ||
6787 | #define segment_eq(a, b) ((a).seg == (b).seg) | |
6788 | ||
de855c5d | 6789 | @@ -187,9 +194,12 @@ extern int __get_user_bad(void); |
2380c486 JR |
6790 | |
6791 | #ifdef CONFIG_X86_32 | |
6792 | #define __put_user_u64(x, addr, err) \ | |
6793 | - asm volatile("1: movl %%eax,0(%2)\n" \ | |
6794 | - "2: movl %%edx,4(%2)\n" \ | |
6795 | + asm volatile(" movw %w5,%%ds\n" \ | |
6796 | + "1: movl %%eax,%%ds:0(%2)\n" \ | |
6797 | + "2: movl %%edx,%%ds:4(%2)\n" \ | |
6798 | "3:\n" \ | |
6799 | + " pushl %%ss\n" \ | |
6800 | + " popl %%ds\n" \ | |
6801 | ".section .fixup,\"ax\"\n" \ | |
6802 | "4: movl %3,%0\n" \ | |
6803 | " jmp 3b\n" \ | |
de855c5d | 6804 | @@ -197,7 +207,8 @@ extern int __get_user_bad(void); |
2380c486 JR |
6805 | _ASM_EXTABLE(1b, 4b) \ |
6806 | _ASM_EXTABLE(2b, 4b) \ | |
6807 | : "=r" (err) \ | |
6808 | - : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err)) | |
6809 | + : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \ | |
6810 | + "r"(__USER_DS)) | |
6811 | ||
6812 | #define __put_user_x8(x, ptr, __ret_pu) \ | |
6813 | asm volatile("call __put_user_8" : "=a" (__ret_pu) \ | |
de855c5d | 6814 | @@ -338,6 +349,22 @@ do { \ |
2380c486 JR |
6815 | } \ |
6816 | } while (0) | |
6817 | ||
6818 | +#ifdef CONFIG_X86_32 | |
6819 | +#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \ | |
6820 | + asm volatile(" movw %w5,%%ds\n" \ | |
6821 | + "1: mov"itype" %%ds:%2,%"rtype"1\n" \ | |
6822 | + "2:\n" \ | |
6823 | + " pushl %%ss\n" \ | |
6824 | + " popl %%ds\n" \ | |
6825 | + ".section .fixup,\"ax\"\n" \ | |
6826 | + "3: movl %3,%0\n" \ | |
6827 | + " xor"itype" %"rtype"1,%"rtype"1\n" \ | |
6828 | + " jmp 2b\n" \ | |
6829 | + ".previous\n" \ | |
6830 | + _ASM_EXTABLE(1b, 3b) \ | |
6831 | + : "=r" (err), ltype (x) \ | |
6832 | + : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS)) | |
6833 | +#else | |
6834 | #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \ | |
6835 | asm volatile("1: mov"itype" %2,%"rtype"1\n" \ | |
6836 | "2:\n" \ | |
de855c5d | 6837 | @@ -349,6 +376,7 @@ do { \ |
2380c486 JR |
6838 | _ASM_EXTABLE(1b, 3b) \ |
6839 | : "=r" (err), ltype(x) \ | |
6840 | : "m" (__m(addr)), "i" (errret), "0" (err)) | |
6841 | +#endif | |
6842 | ||
6843 | #define __put_user_nocheck(x, ptr, size) \ | |
6844 | ({ \ | |
de855c5d | 6845 | @@ -375,6 +403,22 @@ struct __large_struct { unsigned long bu |
2380c486 JR |
6846 | * we do not write to any memory gcc knows about, so there are no |
6847 | * aliasing issues. | |
6848 | */ | |
6849 | +#ifdef CONFIG_X86_32 | |
6850 | +#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \ | |
6851 | + asm volatile(" movw %w5,%%ds\n" \ | |
6852 | + "1: mov"itype" %"rtype"1,%%ds:%2\n" \ | |
6853 | + "2:\n" \ | |
6854 | + " pushl %%ss\n" \ | |
6855 | + " popl %%ds\n" \ | |
6856 | + ".section .fixup,\"ax\"\n" \ | |
6857 | + "3: movl %3,%0\n" \ | |
6858 | + " jmp 2b\n" \ | |
6859 | + ".previous\n" \ | |
6860 | + _ASM_EXTABLE(1b, 3b) \ | |
6861 | + : "=r"(err) \ | |
6862 | + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\ | |
6863 | + "r"(__USER_DS)) | |
6864 | +#else | |
6865 | #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \ | |
6866 | asm volatile("1: mov"itype" %"rtype"1,%2\n" \ | |
6867 | "2:\n" \ | |
de855c5d | 6868 | @@ -385,6 +429,7 @@ struct __large_struct { unsigned long bu |
2380c486 JR |
6869 | _ASM_EXTABLE(1b, 3b) \ |
6870 | : "=r"(err) \ | |
6871 | : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err)) | |
6872 | +#endif | |
6873 | /** | |
6874 | * __get_user: - Get a simple variable from user space, with less checking. | |
6875 | * @x: Variable to store result. | |
de855c5d | 6876 | @@ -445,6 +490,7 @@ extern struct movsl_mask { |
2380c486 JR |
6877 | |
6878 | #define ARCH_HAS_NOCACHE_UACCESS 1 | |
6879 | ||
6880 | +#define ARCH_HAS_SORT_EXTABLE | |
6881 | #ifdef CONFIG_X86_32 | |
6882 | # include "uaccess_32.h" | |
6883 | #else | |
de855c5d AM |
6884 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/vgtod.h linux-2.6.29.6/arch/x86/include/asm/vgtod.h |
6885 | --- linux-2.6.29.6/arch/x86/include/asm/vgtod.h 2009-07-02 19:41:20.000000000 -0400 | |
6886 | +++ linux-2.6.29.6/arch/x86/include/asm/vgtod.h 2009-07-09 22:13:39.000000000 -0400 | |
6887 | @@ -14,6 +14,7 @@ struct vsyscall_gtod_data { | |
6888 | int sysctl_enabled; | |
6889 | struct timezone sys_tz; | |
6890 | struct { /* extract of a clocksource struct */ | |
6891 | + char name[8]; | |
6892 | cycle_t (*vread)(void); | |
6893 | cycle_t cycle_last; | |
6894 | cycle_t mask; | |
6895 | diff -urNp linux-2.6.29.6/arch/x86/include/asm/vsyscall.h linux-2.6.29.6/arch/x86/include/asm/vsyscall.h | |
6896 | --- linux-2.6.29.6/arch/x86/include/asm/vsyscall.h 2009-07-02 19:41:20.000000000 -0400 | |
6897 | +++ linux-2.6.29.6/arch/x86/include/asm/vsyscall.h 2009-07-09 22:13:39.000000000 -0400 | |
6898 | @@ -15,9 +15,10 @@ enum vsyscall_num { | |
6899 | ||
6900 | #ifdef __KERNEL__ | |
6901 | #include <linux/seqlock.h> | |
6902 | +#include <linux/getcpu.h> | |
6903 | +#include <linux/time.h> | |
6904 | ||
6905 | #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16))) | |
6906 | -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16))) | |
6907 | ||
6908 | /* Definitions for CONFIG_GENERIC_TIME definitions */ | |
6909 | #define __section_vsyscall_gtod_data __attribute__ \ | |
6910 | @@ -31,7 +32,6 @@ enum vsyscall_num { | |
6911 | #define VGETCPU_LSL 2 | |
6912 | ||
6913 | extern int __vgetcpu_mode; | |
6914 | -extern volatile unsigned long __jiffies; | |
6915 | ||
6916 | /* kernel space (writeable) */ | |
6917 | extern int vgetcpu_mode; | |
6918 | @@ -39,6 +39,9 @@ extern struct timezone sys_tz; | |
6919 | ||
6920 | extern void map_vsyscall(void); | |
6921 | ||
6922 | +extern int vgettimeofday(struct timeval * tv, struct timezone * tz); | |
6923 | +extern time_t vtime(time_t *t); | |
6924 | +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache); | |
6925 | #endif /* __KERNEL__ */ | |
6926 | ||
6927 | #endif /* _ASM_X86_VSYSCALL_H */ | |
6928 | diff -urNp linux-2.6.29.6/arch/x86/Kconfig linux-2.6.29.6/arch/x86/Kconfig | |
6929 | --- linux-2.6.29.6/arch/x86/Kconfig 2009-07-02 19:41:20.000000000 -0400 | |
6930 | +++ linux-2.6.29.6/arch/x86/Kconfig 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6931 | @@ -993,7 +993,7 @@ config PAGE_OFFSET |
6932 | hex | |
6933 | default 0xB0000000 if VMSPLIT_3G_OPT | |
6934 | default 0x80000000 if VMSPLIT_2G | |
6935 | - default 0x78000000 if VMSPLIT_2G_OPT | |
6936 | + default 0x70000000 if VMSPLIT_2G_OPT | |
6937 | default 0x40000000 if VMSPLIT_1G | |
6938 | default 0xC0000000 | |
6939 | depends on X86_32 | |
6940 | @@ -1408,8 +1408,7 @@ config KEXEC_JUMP | |
6941 | config PHYSICAL_START | |
6942 | hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP) | |
6943 | default "0x1000000" if X86_NUMAQ | |
6944 | - default "0x200000" if X86_64 | |
6945 | - default "0x100000" | |
6946 | + default "0x200000" | |
6947 | help | |
6948 | This gives the physical address where the kernel is loaded. | |
6949 | ||
6950 | @@ -1501,9 +1500,9 @@ config HOTPLUG_CPU | |
6951 | Say N if you want to disable CPU hotplug. | |
6952 | ||
6953 | config COMPAT_VDSO | |
6954 | - def_bool y | |
6955 | + def_bool n | |
6956 | prompt "Compat VDSO support" | |
6957 | - depends on X86_32 || IA32_EMULATION | |
6958 | + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC | |
6959 | help | |
6960 | Map the 32-bit VDSO to the predictable old-style address too. | |
6961 | ---help--- | |
de855c5d AM |
6962 | diff -urNp linux-2.6.29.6/arch/x86/Kconfig.cpu linux-2.6.29.6/arch/x86/Kconfig.cpu |
6963 | --- linux-2.6.29.6/arch/x86/Kconfig.cpu 2009-07-02 19:41:20.000000000 -0400 | |
6964 | +++ linux-2.6.29.6/arch/x86/Kconfig.cpu 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6965 | @@ -333,7 +333,7 @@ config X86_PPRO_FENCE |
6966 | ||
6967 | config X86_F00F_BUG | |
6968 | def_bool y | |
6969 | - depends on M586MMX || M586TSC || M586 || M486 || M386 | |
6970 | + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC | |
6971 | ||
6972 | config X86_WP_WORKS_OK | |
6973 | def_bool y | |
6974 | @@ -353,7 +353,7 @@ config X86_POPAD_OK | |
6975 | ||
6976 | config X86_ALIGNMENT_16 | |
6977 | def_bool y | |
6978 | - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1 | |
6979 | + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1 | |
6980 | ||
6981 | config X86_INTEL_USERCOPY | |
6982 | def_bool y | |
6983 | @@ -399,7 +399,7 @@ config X86_CMPXCHG64 | |
6984 | # generates cmov. | |
6985 | config X86_CMOV | |
6986 | def_bool y | |
6987 | - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64) | |
6988 | + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64) | |
6989 | ||
6990 | config X86_MINIMUM_CPU_FAMILY | |
6991 | int | |
de855c5d AM |
6992 | diff -urNp linux-2.6.29.6/arch/x86/Kconfig.debug linux-2.6.29.6/arch/x86/Kconfig.debug |
6993 | --- linux-2.6.29.6/arch/x86/Kconfig.debug 2009-07-02 19:41:20.000000000 -0400 | |
6994 | +++ linux-2.6.29.6/arch/x86/Kconfig.debug 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
6995 | @@ -107,7 +107,7 @@ config X86_PTDUMP |
6996 | config DEBUG_RODATA | |
6997 | bool "Write protect kernel read-only data structures" | |
6998 | default y | |
6999 | - depends on DEBUG_KERNEL | |
7000 | + depends on DEBUG_KERNEL && BROKEN | |
7001 | help | |
7002 | Mark the kernel read-only data as write-protected in the pagetables, | |
7003 | in order to catch accidental (and incorrect) writes to such const | |
de855c5d AM |
7004 | diff -urNp linux-2.6.29.6/arch/x86/kernel/acpi/boot.c linux-2.6.29.6/arch/x86/kernel/acpi/boot.c |
7005 | --- linux-2.6.29.6/arch/x86/kernel/acpi/boot.c 2009-07-02 19:41:20.000000000 -0400 | |
7006 | +++ linux-2.6.29.6/arch/x86/kernel/acpi/boot.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7007 | @@ -1705,7 +1705,7 @@ static struct dmi_system_id __initdata a |
7008 | DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"), | |
7009 | }, | |
7010 | }, | |
7011 | - {} | |
7012 | + { NULL, NULL, {{0, {0}}}, NULL} | |
7013 | }; | |
7014 | ||
7015 | /* | |
de855c5d AM |
7016 | diff -urNp linux-2.6.29.6/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.29.6/arch/x86/kernel/acpi/realmode/wakeup.S |
7017 | --- linux-2.6.29.6/arch/x86/kernel/acpi/realmode/wakeup.S 2009-07-02 19:41:20.000000000 -0400 | |
7018 | +++ linux-2.6.29.6/arch/x86/kernel/acpi/realmode/wakeup.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7019 | @@ -104,7 +104,7 @@ _start: |
7020 | movl %eax, %ecx | |
7021 | orl %edx, %ecx | |
7022 | jz 1f | |
7023 | - movl $0xc0000080, %ecx | |
7024 | + mov $MSR_EFER, %ecx | |
7025 | wrmsr | |
7026 | 1: | |
7027 | ||
de855c5d AM |
7028 | diff -urNp linux-2.6.29.6/arch/x86/kernel/acpi/sleep.c linux-2.6.29.6/arch/x86/kernel/acpi/sleep.c |
7029 | --- linux-2.6.29.6/arch/x86/kernel/acpi/sleep.c 2009-07-02 19:41:20.000000000 -0400 | |
7030 | +++ linux-2.6.29.6/arch/x86/kernel/acpi/sleep.c 2009-07-09 22:13:39.000000000 -0400 | |
7031 | @@ -11,11 +11,12 @@ | |
7032 | #include <linux/cpumask.h> | |
7033 | #include <asm/segment.h> | |
7034 | #include <asm/desc.h> | |
7035 | +#include <asm/e820.h> | |
7036 | ||
7037 | #include "realmode/wakeup.h" | |
7038 | #include "sleep.h" | |
7039 | ||
7040 | -unsigned long acpi_wakeup_address; | |
7041 | +unsigned long acpi_wakeup_address = 0x2000; | |
7042 | unsigned long acpi_realmode_flags; | |
7043 | ||
7044 | /* address in low memory of the wakeup routine. */ | |
7045 | @@ -37,6 +38,10 @@ int acpi_save_state_mem(void) | |
2380c486 JR |
7046 | { |
7047 | struct wakeup_header *header; | |
7048 | ||
7049 | +#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC) | |
7050 | + unsigned long cr0; | |
7051 | +#endif | |
7052 | + | |
7053 | if (!acpi_realmode) { | |
7054 | printk(KERN_ERR "Could not allocate memory during boot, " | |
7055 | "S3 disabled\n"); | |
de855c5d | 7056 | @@ -99,8 +104,18 @@ int acpi_save_state_mem(void) |
2380c486 JR |
7057 | header->trampoline_segment = setup_trampoline() >> 4; |
7058 | #ifdef CONFIG_SMP | |
7059 | stack_start.sp = temp_stack + sizeof(temp_stack); | |
7060 | + | |
7061 | +#ifdef CONFIG_PAX_KERNEXEC | |
7062 | + pax_open_kernel(cr0); | |
7063 | +#endif | |
7064 | + | |
7065 | early_gdt_descr.address = | |
7066 | (unsigned long)get_cpu_gdt_table(smp_processor_id()); | |
7067 | + | |
7068 | +#ifdef CONFIG_PAX_KERNEXEC | |
7069 | + pax_close_kernel(cr0); | |
7070 | +#endif | |
7071 | + | |
7072 | #endif | |
7073 | initial_code = (unsigned long)wakeup_long64; | |
7074 | saved_magic = 0x123456789abcdef0; | |
de855c5d AM |
7075 | @@ -133,14 +148,8 @@ void __init acpi_reserve_bootmem(void) |
7076 | return; | |
7077 | } | |
7078 | ||
7079 | - acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE); | |
7080 | - | |
7081 | - if (!acpi_realmode) { | |
7082 | - printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n"); | |
7083 | - return; | |
7084 | - } | |
7085 | - | |
7086 | - acpi_wakeup_address = virt_to_phys((void *)acpi_realmode); | |
7087 | + reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code"); | |
7088 | + acpi_realmode = (unsigned long)__va(acpi_wakeup_address);; | |
7089 | } | |
7090 | ||
7091 | ||
7092 | diff -urNp linux-2.6.29.6/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.29.6/arch/x86/kernel/acpi/wakeup_32.S | |
7093 | --- linux-2.6.29.6/arch/x86/kernel/acpi/wakeup_32.S 2009-07-02 19:41:20.000000000 -0400 | |
7094 | +++ linux-2.6.29.6/arch/x86/kernel/acpi/wakeup_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7095 | @@ -30,13 +30,11 @@ wakeup_pmode_return: |
7096 | # and restore the stack ... but you need gdt for this to work | |
7097 | movl saved_context_esp, %esp | |
7098 | ||
7099 | - movl %cs:saved_magic, %eax | |
7100 | - cmpl $0x12345678, %eax | |
7101 | + cmpl $0x12345678, saved_magic | |
7102 | jne bogus_magic | |
7103 | ||
7104 | # jump to place where we left off | |
7105 | - movl saved_eip, %eax | |
7106 | - jmp *%eax | |
7107 | + jmp *(saved_eip) | |
7108 | ||
7109 | bogus_magic: | |
7110 | jmp bogus_magic | |
de855c5d AM |
7111 | diff -urNp linux-2.6.29.6/arch/x86/kernel/alternative.c linux-2.6.29.6/arch/x86/kernel/alternative.c |
7112 | --- linux-2.6.29.6/arch/x86/kernel/alternative.c 2009-07-02 19:41:20.000000000 -0400 | |
7113 | +++ linux-2.6.29.6/arch/x86/kernel/alternative.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7114 | @@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc |
7115 | ||
7116 | BUG_ON(p->len > MAX_PATCH_LEN); | |
7117 | /* prep the buffer with the original instructions */ | |
7118 | - memcpy(insnbuf, p->instr, p->len); | |
7119 | + memcpy(insnbuf, ktla_ktva(p->instr), p->len); | |
7120 | used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf, | |
7121 | (unsigned long)p->instr, p->len); | |
7122 | ||
7123 | @@ -473,11 +473,26 @@ void __init alternative_instructions(voi | |
7124 | * instructions. And on the local CPU you need to be protected again NMI or MCE | |
7125 | * handlers seeing an inconsistent instruction while you patch. | |
7126 | */ | |
7127 | -void *text_poke_early(void *addr, const void *opcode, size_t len) | |
7128 | +void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len) | |
7129 | { | |
7130 | unsigned long flags; | |
7131 | + | |
7132 | +#ifdef CONFIG_PAX_KERNEXEC | |
7133 | + unsigned long cr0; | |
7134 | +#endif | |
7135 | + | |
7136 | local_irq_save(flags); | |
7137 | - memcpy(addr, opcode, len); | |
7138 | + | |
7139 | +#ifdef CONFIG_PAX_KERNEXEC | |
7140 | + pax_open_kernel(cr0); | |
7141 | +#endif | |
7142 | + | |
7143 | + memcpy(ktla_ktva(addr), opcode, len); | |
7144 | + | |
7145 | +#ifdef CONFIG_PAX_KERNEXEC | |
7146 | + pax_close_kernel(cr0); | |
7147 | +#endif | |
7148 | + | |
7149 | local_irq_restore(flags); | |
7150 | sync_core(); | |
7151 | /* Could also do a CLFLUSH here to speed up CPU recovery; but | |
7152 | @@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const | |
7153 | */ | |
7154 | void *__kprobes text_poke(void *addr, const void *opcode, size_t len) | |
7155 | { | |
7156 | - unsigned long flags; | |
7157 | - char *vaddr; | |
7158 | - int nr_pages = 2; | |
7159 | + unsigned char *vaddr = ktla_ktva(addr); | |
7160 | struct page *pages[2]; | |
7161 | - int i; | |
7162 | + size_t i; | |
7163 | + | |
7164 | + if (!core_kernel_text((unsigned long)addr) | |
7165 | ||
7166 | - if (!core_kernel_text((unsigned long)addr)) { | |
7167 | - pages[0] = vmalloc_to_page(addr); | |
7168 | - pages[1] = vmalloc_to_page(addr + PAGE_SIZE); | |
7169 | +#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
7170 | + && (vaddr < MODULES_VADDR || MODULES_END < vaddr) | |
7171 | +#endif | |
7172 | + | |
7173 | + ) { | |
7174 | + pages[0] = vmalloc_to_page(vaddr); | |
7175 | + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE); | |
7176 | } else { | |
7177 | - pages[0] = virt_to_page(addr); | |
7178 | + pages[0] = virt_to_page(vaddr); | |
7179 | WARN_ON(!PageReserved(pages[0])); | |
7180 | - pages[1] = virt_to_page(addr + PAGE_SIZE); | |
7181 | + pages[1] = virt_to_page(vaddr + PAGE_SIZE); | |
7182 | } | |
7183 | BUG_ON(!pages[0]); | |
7184 | - if (!pages[1]) | |
7185 | - nr_pages = 1; | |
7186 | - vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); | |
7187 | - BUG_ON(!vaddr); | |
7188 | - local_irq_save(flags); | |
7189 | - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len); | |
7190 | - local_irq_restore(flags); | |
7191 | - vunmap(vaddr); | |
7192 | - sync_core(); | |
7193 | - /* Could also do a CLFLUSH here to speed up CPU recovery; but | |
7194 | - that causes hangs on some VIA CPUs. */ | |
7195 | + text_poke_early(addr, opcode, len); | |
7196 | for (i = 0; i < len; i++) | |
7197 | - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]); | |
7198 | + BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]); | |
7199 | return addr; | |
7200 | } | |
de855c5d AM |
7201 | diff -urNp linux-2.6.29.6/arch/x86/kernel/apm_32.c linux-2.6.29.6/arch/x86/kernel/apm_32.c |
7202 | --- linux-2.6.29.6/arch/x86/kernel/apm_32.c 2009-07-02 19:41:20.000000000 -0400 | |
7203 | +++ linux-2.6.29.6/arch/x86/kernel/apm_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7204 | @@ -403,7 +403,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq |
7205 | static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue); | |
7206 | static struct apm_user *user_list; | |
7207 | static DEFINE_SPINLOCK(user_list_lock); | |
7208 | -static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } }; | |
7209 | +static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } }; | |
7210 | ||
7211 | static const char driver_version[] = "1.16ac"; /* no spaces */ | |
7212 | ||
7213 | @@ -598,19 +598,42 @@ static u8 apm_bios_call(u32 func, u32 eb | |
7214 | struct desc_struct save_desc_40; | |
7215 | struct desc_struct *gdt; | |
7216 | ||
7217 | +#ifdef CONFIG_PAX_KERNEXEC | |
7218 | + unsigned long cr0; | |
7219 | +#endif | |
7220 | + | |
7221 | cpus = apm_save_cpus(); | |
7222 | ||
7223 | cpu = get_cpu(); | |
7224 | gdt = get_cpu_gdt_table(cpu); | |
7225 | save_desc_40 = gdt[0x40 / 8]; | |
7226 | + | |
7227 | +#ifdef CONFIG_PAX_KERNEXEC | |
7228 | + pax_open_kernel(cr0); | |
7229 | +#endif | |
7230 | + | |
7231 | gdt[0x40 / 8] = bad_bios_desc; | |
7232 | ||
7233 | +#ifdef CONFIG_PAX_KERNEXEC | |
7234 | + pax_close_kernel(cr0); | |
7235 | +#endif | |
7236 | + | |
7237 | apm_irq_save(flags); | |
7238 | APM_DO_SAVE_SEGS; | |
7239 | apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi); | |
7240 | APM_DO_RESTORE_SEGS; | |
7241 | apm_irq_restore(flags); | |
7242 | + | |
7243 | +#ifdef CONFIG_PAX_KERNEXEC | |
7244 | + pax_open_kernel(cr0); | |
7245 | +#endif | |
7246 | + | |
7247 | gdt[0x40 / 8] = save_desc_40; | |
7248 | + | |
7249 | +#ifdef CONFIG_PAX_KERNEXEC | |
7250 | + pax_close_kernel(cr0); | |
7251 | +#endif | |
7252 | + | |
7253 | put_cpu(); | |
7254 | apm_restore_cpus(cpus); | |
7255 | ||
7256 | @@ -641,19 +664,42 @@ static u8 apm_bios_call_simple(u32 func, | |
7257 | struct desc_struct save_desc_40; | |
7258 | struct desc_struct *gdt; | |
7259 | ||
7260 | +#ifdef CONFIG_PAX_KERNEXEC | |
7261 | + unsigned long cr0; | |
7262 | +#endif | |
7263 | + | |
7264 | cpus = apm_save_cpus(); | |
7265 | ||
7266 | cpu = get_cpu(); | |
7267 | gdt = get_cpu_gdt_table(cpu); | |
7268 | save_desc_40 = gdt[0x40 / 8]; | |
7269 | + | |
7270 | +#ifdef CONFIG_PAX_KERNEXEC | |
7271 | + pax_open_kernel(cr0); | |
7272 | +#endif | |
7273 | + | |
7274 | gdt[0x40 / 8] = bad_bios_desc; | |
7275 | ||
7276 | +#ifdef CONFIG_PAX_KERNEXEC | |
7277 | + pax_close_kernel(cr0); | |
7278 | +#endif | |
7279 | + | |
7280 | apm_irq_save(flags); | |
7281 | APM_DO_SAVE_SEGS; | |
7282 | error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax); | |
7283 | APM_DO_RESTORE_SEGS; | |
7284 | apm_irq_restore(flags); | |
7285 | + | |
7286 | +#ifdef CONFIG_PAX_KERNEXEC | |
7287 | + pax_open_kernel(cr0); | |
7288 | +#endif | |
7289 | + | |
7290 | gdt[0x40 / 8] = save_desc_40; | |
7291 | + | |
7292 | +#ifdef CONFIG_PAX_KERNEXEC | |
7293 | + pax_close_kernel(cr0); | |
7294 | +#endif | |
7295 | + | |
7296 | put_cpu(); | |
7297 | apm_restore_cpus(cpus); | |
7298 | return error; | |
7299 | @@ -925,7 +971,7 @@ recalc: | |
7300 | ||
7301 | static void apm_power_off(void) | |
7302 | { | |
7303 | - unsigned char po_bios_call[] = { | |
7304 | + const unsigned char po_bios_call[] = { | |
7305 | 0xb8, 0x00, 0x10, /* movw $0x1000,ax */ | |
7306 | 0x8e, 0xd0, /* movw ax,ss */ | |
7307 | 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */ | |
7308 | @@ -1876,7 +1922,10 @@ static const struct file_operations apm_ | |
7309 | static struct miscdevice apm_device = { | |
7310 | APM_MINOR_DEV, | |
7311 | "apm_bios", | |
7312 | - &apm_bios_fops | |
7313 | + &apm_bios_fops, | |
7314 | + {NULL, NULL}, | |
7315 | + NULL, | |
7316 | + NULL | |
7317 | }; | |
7318 | ||
7319 | ||
7320 | @@ -2197,7 +2246,7 @@ static struct dmi_system_id __initdata a | |
7321 | { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, | |
7322 | }, | |
7323 | ||
7324 | - { } | |
7325 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL} | |
7326 | }; | |
7327 | ||
7328 | /* | |
7329 | @@ -2215,6 +2264,10 @@ static int __init apm_init(void) | |
7330 | struct desc_struct *gdt; | |
7331 | int err; | |
7332 | ||
7333 | +#ifdef CONFIG_PAX_KERNEXEC | |
7334 | + unsigned long cr0; | |
7335 | +#endif | |
7336 | + | |
7337 | dmi_check_system(apm_dmi_table); | |
7338 | ||
7339 | if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) { | |
7340 | @@ -2288,9 +2341,18 @@ static int __init apm_init(void) | |
7341 | * This is for buggy BIOS's that refer to (real mode) segment 0x40 | |
7342 | * even though they are called in protected mode. | |
7343 | */ | |
7344 | + | |
7345 | +#ifdef CONFIG_PAX_KERNEXEC | |
7346 | + pax_open_kernel(cr0); | |
7347 | +#endif | |
7348 | + | |
7349 | set_base(bad_bios_desc, __va((unsigned long)0x40 << 4)); | |
7350 | _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4)); | |
7351 | ||
7352 | +#ifdef CONFIG_PAX_KERNEXEC | |
7353 | + pax_close_kernel(cr0); | |
7354 | +#endif | |
7355 | + | |
7356 | /* | |
7357 | * Set up the long jump entry point to the APM BIOS, which is called | |
7358 | * from inline assembly. | |
7359 | @@ -2309,6 +2371,11 @@ static int __init apm_init(void) | |
7360 | * code to that CPU. | |
7361 | */ | |
7362 | gdt = get_cpu_gdt_table(0); | |
7363 | + | |
7364 | +#ifdef CONFIG_PAX_KERNEXEC | |
7365 | + pax_open_kernel(cr0); | |
7366 | +#endif | |
7367 | + | |
7368 | set_base(gdt[APM_CS >> 3], | |
7369 | __va((unsigned long)apm_info.bios.cseg << 4)); | |
7370 | set_base(gdt[APM_CS_16 >> 3], | |
7371 | @@ -2316,6 +2383,10 @@ static int __init apm_init(void) | |
7372 | set_base(gdt[APM_DS >> 3], | |
7373 | __va((unsigned long)apm_info.bios.dseg << 4)); | |
7374 | ||
7375 | +#ifdef CONFIG_PAX_KERNEXEC | |
7376 | + pax_close_kernel(cr0); | |
7377 | +#endif | |
7378 | + | |
7379 | proc_create("apm", 0, NULL, &apm_file_ops); | |
7380 | ||
7381 | kapmd_task = kthread_create(apm, NULL, "kapmd"); | |
de855c5d AM |
7382 | diff -urNp linux-2.6.29.6/arch/x86/kernel/asm-offsets_32.c linux-2.6.29.6/arch/x86/kernel/asm-offsets_32.c |
7383 | --- linux-2.6.29.6/arch/x86/kernel/asm-offsets_32.c 2009-07-02 19:41:20.000000000 -0400 | |
7384 | +++ linux-2.6.29.6/arch/x86/kernel/asm-offsets_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7385 | @@ -100,6 +100,7 @@ void foo(void) |
7386 | DEFINE(PTRS_PER_PTE, PTRS_PER_PTE); | |
7387 | DEFINE(PTRS_PER_PMD, PTRS_PER_PMD); | |
7388 | DEFINE(PTRS_PER_PGD, PTRS_PER_PGD); | |
7389 | + DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE); | |
7390 | ||
7391 | OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx); | |
7392 | ||
7393 | @@ -113,6 +114,7 @@ void foo(void) | |
7394 | OFFSET(PV_CPU_iret, pv_cpu_ops, iret); | |
7395 | OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit); | |
7396 | OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0); | |
7397 | + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0); | |
7398 | #endif | |
7399 | ||
7400 | #ifdef CONFIG_XEN | |
de855c5d AM |
7401 | diff -urNp linux-2.6.29.6/arch/x86/kernel/asm-offsets_64.c linux-2.6.29.6/arch/x86/kernel/asm-offsets_64.c |
7402 | --- linux-2.6.29.6/arch/x86/kernel/asm-offsets_64.c 2009-07-02 19:41:20.000000000 -0400 | |
7403 | +++ linux-2.6.29.6/arch/x86/kernel/asm-offsets_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7404 | @@ -124,6 +124,7 @@ int main(void) |
7405 | ENTRY(cr8); | |
7406 | BLANK(); | |
7407 | #undef ENTRY | |
7408 | + DEFINE(TSS_size, sizeof(struct tss_struct)); | |
7409 | DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist)); | |
7410 | BLANK(); | |
7411 | DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx)); | |
de855c5d AM |
7412 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/common.c linux-2.6.29.6/arch/x86/kernel/cpu/common.c |
7413 | --- linux-2.6.29.6/arch/x86/kernel/cpu/common.c 2009-07-02 19:41:20.000000000 -0400 | |
7414 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/common.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7415 | @@ -2,7 +2,6 @@ |
7416 | #include <linux/kernel.h> | |
7417 | #include <linux/sched.h> | |
7418 | #include <linux/string.h> | |
7419 | -#include <linux/bootmem.h> | |
7420 | #include <linux/bitops.h> | |
7421 | #include <linux/module.h> | |
7422 | #include <linux/kgdb.h> | |
7423 | @@ -62,59 +61,6 @@ cpumask_t cpu_sibling_setup_map; | |
7424 | ||
7425 | static struct cpu_dev *this_cpu __cpuinitdata; | |
7426 | ||
7427 | -#ifdef CONFIG_X86_64 | |
7428 | -/* We need valid kernel segments for data and code in long mode too | |
7429 | - * IRET will check the segment types kkeil 2000/10/28 | |
7430 | - * Also sysret mandates a special GDT layout | |
7431 | - */ | |
7432 | -/* The TLS descriptors are currently at a different place compared to i386. | |
7433 | - Hopefully nobody expects them at a fixed place (Wine?) */ | |
7434 | -DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { | |
7435 | - [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } }, | |
7436 | - [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } }, | |
7437 | - [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } }, | |
7438 | - [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } }, | |
7439 | - [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } }, | |
7440 | - [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } }, | |
7441 | -} }; | |
7442 | -#else | |
7443 | -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = { | |
7444 | - [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } }, | |
7445 | - [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } }, | |
7446 | - [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } }, | |
7447 | - [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } }, | |
7448 | - /* | |
7449 | - * Segments used for calling PnP BIOS have byte granularity. | |
7450 | - * They code segments and data segments have fixed 64k limits, | |
7451 | - * the transfer segment sizes are set at run time. | |
7452 | - */ | |
7453 | - /* 32-bit code */ | |
7454 | - [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } }, | |
7455 | - /* 16-bit code */ | |
7456 | - [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } }, | |
7457 | - /* 16-bit data */ | |
7458 | - [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } }, | |
7459 | - /* 16-bit data */ | |
7460 | - [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } }, | |
7461 | - /* 16-bit data */ | |
7462 | - [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } }, | |
7463 | - /* | |
7464 | - * The APM segments have byte granularity and their bases | |
7465 | - * are set at run time. All have 64k limits. | |
7466 | - */ | |
7467 | - /* 32-bit code */ | |
7468 | - [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } }, | |
7469 | - /* 16-bit code */ | |
7470 | - [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } }, | |
7471 | - /* data */ | |
7472 | - [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } }, | |
7473 | - | |
7474 | - [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } }, | |
7475 | - [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } }, | |
7476 | -} }; | |
7477 | -#endif | |
7478 | -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page); | |
7479 | - | |
7480 | #ifdef CONFIG_X86_32 | |
7481 | static int cachesize_override __cpuinitdata = -1; | |
7482 | static int disable_x86_serial_nr __cpuinitdata = 1; | |
7483 | @@ -248,7 +194,7 @@ void switch_to_new_gdt(void) | |
7484 | { | |
7485 | struct desc_ptr gdt_descr; | |
7486 | ||
7487 | - gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id()); | |
7488 | + gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id()); | |
7489 | gdt_descr.size = GDT_SIZE - 1; | |
7490 | load_gdt(&gdt_descr); | |
7491 | #ifdef CONFIG_X86_32 | |
7492 | @@ -708,6 +654,10 @@ static void __cpuinit identify_cpu(struc | |
7493 | * we do "generic changes." | |
7494 | */ | |
7495 | ||
7496 | +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF) | |
7497 | + setup_clear_cpu_cap(X86_FEATURE_SEP); | |
7498 | +#endif | |
7499 | + | |
7500 | /* If the model name is still unset, do table lookup. */ | |
7501 | if (!c->x86_model_id[0]) { | |
7502 | char *p; | |
7503 | @@ -880,7 +830,7 @@ __setup("clearcpuid=", setup_disablecpui | |
7504 | struct x8664_pda **_cpu_pda __read_mostly; | |
7505 | EXPORT_SYMBOL(_cpu_pda); | |
7506 | ||
7507 | -struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table }; | |
7508 | +struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table }; | |
7509 | ||
7510 | static char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss; | |
7511 | ||
7512 | @@ -979,7 +929,7 @@ struct pt_regs * __cpuinit idle_regs(str | |
7513 | void __cpuinit cpu_init(void) | |
7514 | { | |
7515 | int cpu = stack_smp_processor_id(); | |
7516 | - struct tss_struct *t = &per_cpu(init_tss, cpu); | |
7517 | + struct tss_struct *t = init_tss + cpu; | |
7518 | struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu); | |
7519 | unsigned long v; | |
7520 | char *estacks = NULL; | |
7521 | @@ -1100,7 +1050,7 @@ void __cpuinit cpu_init(void) | |
7522 | { | |
7523 | int cpu = smp_processor_id(); | |
7524 | struct task_struct *curr = current; | |
7525 | - struct tss_struct *t = &per_cpu(init_tss, cpu); | |
7526 | + struct tss_struct *t = init_tss + cpu; | |
7527 | struct thread_struct *thread = &curr->thread; | |
7528 | ||
7529 | if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) { | |
de855c5d AM |
7530 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c |
7531 | --- linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2009-07-02 19:41:20.000000000 -0400 | |
7532 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7533 | @@ -581,7 +581,7 @@ static const struct dmi_system_id sw_any |
7534 | DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"), | |
7535 | }, | |
7536 | }, | |
7537 | - { } | |
7538 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
7539 | }; | |
7540 | #endif | |
7541 | ||
de855c5d AM |
7542 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c |
7543 | --- linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2009-07-02 19:41:20.000000000 -0400 | |
7544 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7545 | @@ -225,7 +225,7 @@ static struct cpu_model models[] = |
7546 | { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL }, | |
7547 | { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL }, | |
7548 | ||
7549 | - { NULL, } | |
7550 | + { NULL, NULL, 0, NULL} | |
7551 | }; | |
7552 | #undef _BANIAS | |
7553 | #undef BANIAS | |
de855c5d AM |
7554 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/intel.c linux-2.6.29.6/arch/x86/kernel/cpu/intel.c |
7555 | --- linux-2.6.29.6/arch/x86/kernel/cpu/intel.c 2009-07-02 19:41:20.000000000 -0400 | |
7556 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/intel.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7557 | @@ -94,7 +94,7 @@ static void __cpuinit trap_init_f00f_bug |
7558 | * Update the IDT descriptor and reload the IDT so that | |
7559 | * it uses the read-only mapped virtual address. | |
7560 | */ | |
7561 | - idt_descr.address = fix_to_virt(FIX_F00F_IDT); | |
7562 | + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT); | |
7563 | load_idt(&idt_descr); | |
7564 | } | |
7565 | #endif | |
de855c5d AM |
7566 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/mcheck/mce_64.c linux-2.6.29.6/arch/x86/kernel/cpu/mcheck/mce_64.c |
7567 | --- linux-2.6.29.6/arch/x86/kernel/cpu/mcheck/mce_64.c 2009-07-02 19:41:20.000000000 -0400 | |
7568 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/mcheck/mce_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7569 | @@ -678,6 +678,7 @@ static struct miscdevice mce_log_device |
7570 | MISC_MCELOG_MINOR, | |
7571 | "mcelog", | |
7572 | &mce_chrdev_ops, | |
7573 | + {NULL, NULL}, NULL, NULL | |
7574 | }; | |
7575 | ||
7576 | static unsigned long old_cr4 __initdata; | |
de855c5d AM |
7577 | diff -urNp linux-2.6.29.6/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.29.6/arch/x86/kernel/cpu/mtrr/generic.c |
7578 | --- linux-2.6.29.6/arch/x86/kernel/cpu/mtrr/generic.c 2009-07-02 19:41:20.000000000 -0400 | |
7579 | +++ linux-2.6.29.6/arch/x86/kernel/cpu/mtrr/generic.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7580 | @@ -23,14 +23,14 @@ static struct fixed_range_block fixed_ra |
7581 | { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */ | |
7582 | { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */ | |
7583 | { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */ | |
7584 | - {} | |
7585 | + { 0, 0 } | |
7586 | }; | |
7587 | ||
7588 | static unsigned long smp_changes_mask; | |
7589 | static int mtrr_state_set; | |
7590 | u64 mtrr_tom2; | |
7591 | ||
7592 | -struct mtrr_state_type mtrr_state = {}; | |
7593 | +struct mtrr_state_type mtrr_state; | |
7594 | EXPORT_SYMBOL_GPL(mtrr_state); | |
7595 | ||
7596 | static int __initdata mtrr_show; | |
de855c5d AM |
7597 | diff -urNp linux-2.6.29.6/arch/x86/kernel/crash.c linux-2.6.29.6/arch/x86/kernel/crash.c |
7598 | --- linux-2.6.29.6/arch/x86/kernel/crash.c 2009-07-02 19:41:20.000000000 -0400 | |
7599 | +++ linux-2.6.29.6/arch/x86/kernel/crash.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7600 | @@ -43,7 +43,7 @@ static void kdump_nmi_callback(int cpu, |
7601 | regs = args->regs; | |
7602 | ||
7603 | #ifdef CONFIG_X86_32 | |
7604 | - if (!user_mode_vm(regs)) { | |
7605 | + if (!user_mode(regs)) { | |
7606 | crash_fixup_ss_esp(&fixed_regs, regs); | |
7607 | regs = &fixed_regs; | |
7608 | } | |
de855c5d AM |
7609 | diff -urNp linux-2.6.29.6/arch/x86/kernel/doublefault_32.c linux-2.6.29.6/arch/x86/kernel/doublefault_32.c |
7610 | --- linux-2.6.29.6/arch/x86/kernel/doublefault_32.c 2009-07-02 19:41:20.000000000 -0400 | |
7611 | +++ linux-2.6.29.6/arch/x86/kernel/doublefault_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7612 | @@ -11,7 +11,7 @@ |
7613 | ||
7614 | #define DOUBLEFAULT_STACKSIZE (1024) | |
7615 | static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE]; | |
7616 | -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE) | |
7617 | +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2) | |
7618 | ||
7619 | #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM) | |
7620 | ||
7621 | @@ -21,7 +21,7 @@ static void doublefault_fn(void) | |
7622 | unsigned long gdt, tss; | |
7623 | ||
7624 | store_gdt(&gdt_desc); | |
7625 | - gdt = gdt_desc.address; | |
7626 | + gdt = (unsigned long)gdt_desc.address; | |
7627 | ||
7628 | printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size); | |
7629 | ||
7630 | @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach | |
7631 | /* 0x2 bit is always set */ | |
7632 | .flags = X86_EFLAGS_SF | 0x2, | |
7633 | .sp = STACK_START, | |
7634 | - .es = __USER_DS, | |
7635 | + .es = __KERNEL_DS, | |
7636 | .cs = __KERNEL_CS, | |
7637 | .ss = __KERNEL_DS, | |
7638 | - .ds = __USER_DS, | |
7639 | + .ds = __KERNEL_DS, | |
7640 | .fs = __KERNEL_PERCPU, | |
7641 | ||
7642 | .__cr3 = __pa_nodebug(swapper_pg_dir), | |
de855c5d AM |
7643 | diff -urNp linux-2.6.29.6/arch/x86/kernel/dumpstack_32.c linux-2.6.29.6/arch/x86/kernel/dumpstack_32.c |
7644 | --- linux-2.6.29.6/arch/x86/kernel/dumpstack_32.c 2009-07-02 19:41:20.000000000 -0400 | |
7645 | +++ linux-2.6.29.6/arch/x86/kernel/dumpstack_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7646 | @@ -107,11 +107,12 @@ void show_registers(struct pt_regs *regs |
7647 | * When in-kernel, we also print out the stack and code at the | |
7648 | * time of the fault.. | |
7649 | */ | |
7650 | - if (!user_mode_vm(regs)) { | |
7651 | + if (!user_mode(regs)) { | |
7652 | unsigned int code_prologue = code_bytes * 43 / 64; | |
7653 | unsigned int code_len = code_bytes; | |
7654 | unsigned char c; | |
7655 | u8 *ip; | |
7656 | + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]); | |
7657 | ||
7658 | printk(KERN_EMERG "Stack:\n"); | |
7659 | show_stack_log_lvl(NULL, regs, ®s->sp, | |
7660 | @@ -119,10 +120,10 @@ void show_registers(struct pt_regs *regs | |
7661 | ||
7662 | printk(KERN_EMERG "Code: "); | |
7663 | ||
7664 | - ip = (u8 *)regs->ip - code_prologue; | |
7665 | + ip = (u8 *)regs->ip - code_prologue + cs_base; | |
7666 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | |
7667 | /* try starting at IP */ | |
7668 | - ip = (u8 *)regs->ip; | |
7669 | + ip = (u8 *)regs->ip + cs_base; | |
7670 | code_len = code_len - code_prologue + 1; | |
7671 | } | |
7672 | for (i = 0; i < code_len; i++, ip++) { | |
7673 | @@ -131,7 +132,7 @@ void show_registers(struct pt_regs *regs | |
7674 | printk(" Bad EIP value."); | |
7675 | break; | |
7676 | } | |
7677 | - if (ip == (u8 *)regs->ip) | |
7678 | + if (ip == (u8 *)regs->ip + cs_base) | |
7679 | printk("<%02x> ", c); | |
7680 | else | |
7681 | printk("%02x ", c); | |
7682 | @@ -144,6 +145,7 @@ int is_valid_bugaddr(unsigned long ip) | |
7683 | { | |
7684 | unsigned short ud2; | |
7685 | ||
7686 | + ip = ktla_ktva(ip); | |
7687 | if (ip < PAGE_OFFSET) | |
7688 | return 0; | |
7689 | if (probe_kernel_address((unsigned short *)ip, ud2)) | |
de855c5d AM |
7690 | diff -urNp linux-2.6.29.6/arch/x86/kernel/dumpstack.c linux-2.6.29.6/arch/x86/kernel/dumpstack.c |
7691 | --- linux-2.6.29.6/arch/x86/kernel/dumpstack.c 2009-07-02 19:41:20.000000000 -0400 | |
7692 | +++ linux-2.6.29.6/arch/x86/kernel/dumpstack.c 2009-07-09 22:13:39.000000000 -0400 | |
7693 | @@ -178,7 +178,7 @@ void dump_stack(void) | |
7694 | #endif | |
7695 | ||
7696 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | |
7697 | - current->pid, current->comm, print_tainted(), | |
7698 | + task_pid_nr(current), current->comm, print_tainted(), | |
7699 | init_utsname()->release, | |
7700 | (int)strcspn(init_utsname()->version, " "), | |
7701 | init_utsname()->version); | |
2380c486 JR |
7702 | @@ -288,7 +288,7 @@ void die(const char *str, struct pt_regs |
7703 | unsigned long flags = oops_begin(); | |
7704 | int sig = SIGSEGV; | |
7705 | ||
7706 | - if (!user_mode_vm(regs)) | |
7707 | + if (!user_mode(regs)) | |
7708 | report_bug(regs->ip, regs); | |
7709 | ||
7710 | if (__die(str, regs, err)) | |
de855c5d AM |
7711 | diff -urNp linux-2.6.29.6/arch/x86/kernel/e820.c linux-2.6.29.6/arch/x86/kernel/e820.c |
7712 | --- linux-2.6.29.6/arch/x86/kernel/e820.c 2009-07-02 19:41:20.000000000 -0400 | |
7713 | +++ linux-2.6.29.6/arch/x86/kernel/e820.c 2009-07-09 22:13:39.000000000 -0400 | |
7714 | @@ -698,7 +698,10 @@ struct early_res { | |
7715 | }; | |
7716 | static struct early_res early_res[MAX_EARLY_RES] __initdata = { | |
7717 | { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */ | |
7718 | - {} | |
7719 | +#ifdef CONFIG_VM86 | |
7720 | + { PAGE_SIZE, ISA_START_ADDRESS, "V86 mode memory", 1 }, | |
7721 | +#endif | |
7722 | + { 0, 0, {0}, 0 } | |
7723 | }; | |
7724 | ||
7725 | static int __init find_overlapped_early(u64 start, u64 end) | |
7726 | diff -urNp linux-2.6.29.6/arch/x86/kernel/efi_32.c linux-2.6.29.6/arch/x86/kernel/efi_32.c | |
7727 | --- linux-2.6.29.6/arch/x86/kernel/efi_32.c 2009-07-02 19:41:20.000000000 -0400 | |
7728 | +++ linux-2.6.29.6/arch/x86/kernel/efi_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7729 | @@ -38,70 +38,38 @@ |
7730 | */ | |
7731 | ||
7732 | static unsigned long efi_rt_eflags; | |
7733 | -static pgd_t efi_bak_pg_dir_pointer[2]; | |
7734 | +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS]; | |
7735 | ||
7736 | -void efi_call_phys_prelog(void) | |
7737 | +void __init efi_call_phys_prelog(void) | |
7738 | { | |
7739 | - unsigned long cr4; | |
7740 | - unsigned long temp; | |
7741 | struct desc_ptr gdt_descr; | |
7742 | ||
7743 | local_irq_save(efi_rt_eflags); | |
7744 | ||
7745 | - /* | |
7746 | - * If I don't have PAE, I should just duplicate two entries in page | |
7747 | - * directory. If I have PAE, I just need to duplicate one entry in | |
7748 | - * page directory. | |
7749 | - */ | |
7750 | - cr4 = read_cr4_safe(); | |
7751 | ||
7752 | - if (cr4 & X86_CR4_PAE) { | |
7753 | - efi_bak_pg_dir_pointer[0].pgd = | |
7754 | - swapper_pg_dir[pgd_index(0)].pgd; | |
7755 | - swapper_pg_dir[0].pgd = | |
7756 | - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; | |
7757 | - } else { | |
7758 | - efi_bak_pg_dir_pointer[0].pgd = | |
7759 | - swapper_pg_dir[pgd_index(0)].pgd; | |
7760 | - efi_bak_pg_dir_pointer[1].pgd = | |
7761 | - swapper_pg_dir[pgd_index(0x400000)].pgd; | |
7762 | - swapper_pg_dir[pgd_index(0)].pgd = | |
7763 | - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; | |
7764 | - temp = PAGE_OFFSET + 0x400000; | |
7765 | - swapper_pg_dir[pgd_index(0x400000)].pgd = | |
7766 | - swapper_pg_dir[pgd_index(temp)].pgd; | |
7767 | - } | |
7768 | + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS); | |
7769 | + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY, | |
7770 | + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY)); | |
7771 | ||
7772 | /* | |
7773 | * After the lock is released, the original page table is restored. | |
7774 | */ | |
7775 | __flush_tlb_all(); | |
7776 | ||
7777 | - gdt_descr.address = __pa(get_cpu_gdt_table(0)); | |
7778 | + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0)); | |
7779 | gdt_descr.size = GDT_SIZE - 1; | |
7780 | load_gdt(&gdt_descr); | |
7781 | } | |
7782 | ||
7783 | -void efi_call_phys_epilog(void) | |
7784 | +void __init efi_call_phys_epilog(void) | |
7785 | { | |
7786 | - unsigned long cr4; | |
7787 | struct desc_ptr gdt_descr; | |
7788 | ||
7789 | - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0); | |
7790 | + gdt_descr.address = get_cpu_gdt_table(0); | |
7791 | gdt_descr.size = GDT_SIZE - 1; | |
7792 | load_gdt(&gdt_descr); | |
7793 | ||
7794 | - cr4 = read_cr4_safe(); | |
7795 | - | |
7796 | - if (cr4 & X86_CR4_PAE) { | |
7797 | - swapper_pg_dir[pgd_index(0)].pgd = | |
7798 | - efi_bak_pg_dir_pointer[0].pgd; | |
7799 | - } else { | |
7800 | - swapper_pg_dir[pgd_index(0)].pgd = | |
7801 | - efi_bak_pg_dir_pointer[0].pgd; | |
7802 | - swapper_pg_dir[pgd_index(0x400000)].pgd = | |
7803 | - efi_bak_pg_dir_pointer[1].pgd; | |
7804 | - } | |
7805 | + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS); | |
7806 | ||
7807 | /* | |
7808 | * After the lock is released, the original page table is restored. | |
de855c5d AM |
7809 | diff -urNp linux-2.6.29.6/arch/x86/kernel/efi_stub_32.S linux-2.6.29.6/arch/x86/kernel/efi_stub_32.S |
7810 | --- linux-2.6.29.6/arch/x86/kernel/efi_stub_32.S 2009-07-02 19:41:20.000000000 -0400 | |
7811 | +++ linux-2.6.29.6/arch/x86/kernel/efi_stub_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7812 | @@ -6,6 +6,7 @@ |
7813 | */ | |
7814 | ||
7815 | #include <linux/linkage.h> | |
7816 | +#include <linux/init.h> | |
7817 | #include <asm/page.h> | |
7818 | ||
7819 | /* | |
7820 | @@ -20,7 +21,7 @@ | |
7821 | * service functions will comply with gcc calling convention, too. | |
7822 | */ | |
7823 | ||
7824 | -.text | |
7825 | +__INIT | |
7826 | ENTRY(efi_call_phys) | |
7827 | /* | |
7828 | * 0. The function can only be called in Linux kernel. So CS has been | |
7829 | @@ -36,9 +37,7 @@ ENTRY(efi_call_phys) | |
7830 | * The mapping of lower virtual memory has been created in prelog and | |
7831 | * epilog. | |
7832 | */ | |
7833 | - movl $1f, %edx | |
7834 | - subl $__PAGE_OFFSET, %edx | |
7835 | - jmp *%edx | |
7836 | + jmp 1f-__PAGE_OFFSET | |
7837 | 1: | |
7838 | ||
7839 | /* | |
7840 | @@ -47,14 +46,8 @@ ENTRY(efi_call_phys) | |
7841 | * parameter 2, ..., param n. To make things easy, we save the return | |
7842 | * address of efi_call_phys in a global variable. | |
7843 | */ | |
7844 | - popl %edx | |
7845 | - movl %edx, saved_return_addr | |
7846 | - /* get the function pointer into ECX*/ | |
7847 | - popl %ecx | |
7848 | - movl %ecx, efi_rt_function_ptr | |
7849 | - movl $2f, %edx | |
7850 | - subl $__PAGE_OFFSET, %edx | |
7851 | - pushl %edx | |
7852 | + popl (saved_return_addr) | |
7853 | + popl (efi_rt_function_ptr) | |
7854 | ||
7855 | /* | |
7856 | * 3. Clear PG bit in %CR0. | |
7857 | @@ -73,9 +66,8 @@ ENTRY(efi_call_phys) | |
7858 | /* | |
7859 | * 5. Call the physical function. | |
7860 | */ | |
7861 | - jmp *%ecx | |
7862 | + call *(efi_rt_function_ptr-__PAGE_OFFSET) | |
7863 | ||
7864 | -2: | |
7865 | /* | |
7866 | * 6. After EFI runtime service returns, control will return to | |
7867 | * following instruction. We'd better readjust stack pointer first. | |
7868 | @@ -88,34 +80,27 @@ ENTRY(efi_call_phys) | |
7869 | movl %cr0, %edx | |
7870 | orl $0x80000000, %edx | |
7871 | movl %edx, %cr0 | |
7872 | - jmp 1f | |
7873 | -1: | |
7874 | + | |
7875 | /* | |
7876 | * 8. Now restore the virtual mode from flat mode by | |
7877 | * adding EIP with PAGE_OFFSET. | |
7878 | */ | |
7879 | - movl $1f, %edx | |
7880 | - jmp *%edx | |
7881 | + jmp 1f+__PAGE_OFFSET | |
7882 | 1: | |
7883 | ||
7884 | /* | |
7885 | * 9. Balance the stack. And because EAX contain the return value, | |
7886 | * we'd better not clobber it. | |
7887 | */ | |
7888 | - leal efi_rt_function_ptr, %edx | |
7889 | - movl (%edx), %ecx | |
7890 | - pushl %ecx | |
7891 | + pushl (efi_rt_function_ptr) | |
7892 | ||
7893 | /* | |
7894 | - * 10. Push the saved return address onto the stack and return. | |
7895 | + * 10. Return to the saved return address. | |
7896 | */ | |
7897 | - leal saved_return_addr, %edx | |
7898 | - movl (%edx), %ecx | |
7899 | - pushl %ecx | |
7900 | - ret | |
7901 | + jmpl *(saved_return_addr) | |
7902 | .previous | |
7903 | ||
7904 | -.data | |
7905 | +__INITDATA | |
7906 | saved_return_addr: | |
7907 | .long 0 | |
7908 | efi_rt_function_ptr: | |
de855c5d AM |
7909 | diff -urNp linux-2.6.29.6/arch/x86/kernel/entry_32.S linux-2.6.29.6/arch/x86/kernel/entry_32.S |
7910 | --- linux-2.6.29.6/arch/x86/kernel/entry_32.S 2009-07-02 19:41:20.000000000 -0400 | |
7911 | +++ linux-2.6.29.6/arch/x86/kernel/entry_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
7912 | @@ -101,7 +101,7 @@ |
7913 | #define resume_userspace_sig resume_userspace | |
7914 | #endif | |
7915 | ||
7916 | -#define SAVE_ALL \ | |
7917 | +#define __SAVE_ALL(_DS) \ | |
7918 | cld; \ | |
7919 | pushl %fs; \ | |
7920 | CFI_ADJUST_CFA_OFFSET 4;\ | |
7921 | @@ -133,12 +133,26 @@ | |
7922 | pushl %ebx; \ | |
7923 | CFI_ADJUST_CFA_OFFSET 4;\ | |
7924 | CFI_REL_OFFSET ebx, 0;\ | |
7925 | - movl $(__USER_DS), %edx; \ | |
7926 | + movl $(_DS), %edx; \ | |
7927 | movl %edx, %ds; \ | |
7928 | movl %edx, %es; \ | |
7929 | movl $(__KERNEL_PERCPU), %edx; \ | |
7930 | movl %edx, %fs | |
7931 | ||
7932 | +#ifdef CONFIG_PAX_KERNEXEC | |
7933 | +#define SAVE_ALL \ | |
7934 | + __SAVE_ALL(__KERNEL_DS); \ | |
7935 | + GET_CR0_INTO_EDX; \ | |
7936 | + movl %edx, %esi; \ | |
7937 | + orl $X86_CR0_WP, %edx; \ | |
7938 | + xorl %edx, %esi; \ | |
7939 | + SET_CR0_FROM_EDX | |
7940 | +#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF) | |
7941 | +#define SAVE_ALL __SAVE_ALL(__KERNEL_DS) | |
7942 | +#else | |
7943 | +#define SAVE_ALL __SAVE_ALL(__USER_DS) | |
7944 | +#endif | |
7945 | + | |
7946 | #define RESTORE_INT_REGS \ | |
7947 | popl %ebx; \ | |
7948 | CFI_ADJUST_CFA_OFFSET -4;\ | |
7949 | @@ -229,6 +243,11 @@ ENTRY(ret_from_fork) | |
7950 | CFI_ADJUST_CFA_OFFSET 4 | |
7951 | popfl | |
7952 | CFI_ADJUST_CFA_OFFSET -4 | |
7953 | + | |
7954 | +#ifdef CONFIG_PAX_KERNEXEC | |
7955 | + xorl %esi, %esi | |
7956 | +#endif | |
7957 | + | |
7958 | jmp syscall_exit | |
7959 | CFI_ENDPROC | |
7960 | END(ret_from_fork) | |
7961 | @@ -252,7 +271,17 @@ check_userspace: | |
7962 | movb PT_CS(%esp), %al | |
7963 | andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax | |
7964 | cmpl $USER_RPL, %eax | |
7965 | + | |
7966 | +#ifdef CONFIG_PAX_KERNEXEC | |
7967 | + jae resume_userspace | |
7968 | + | |
7969 | + GET_CR0_INTO_EDX | |
7970 | + xorl %esi, %edx | |
7971 | + SET_CR0_FROM_EDX | |
7972 | + jmp resume_kernel | |
7973 | +#else | |
7974 | jb resume_kernel # not returning to v8086 or userspace | |
7975 | +#endif | |
7976 | ||
7977 | ENTRY(resume_userspace) | |
7978 | LOCKDEP_SYS_EXIT | |
7979 | @@ -314,10 +343,9 @@ sysenter_past_esp: | |
7980 | /*CFI_REL_OFFSET cs, 0*/ | |
7981 | /* | |
7982 | * Push current_thread_info()->sysenter_return to the stack. | |
7983 | - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words | |
7984 | - * pushed above; +8 corresponds to copy_thread's esp0 setting. | |
7985 | */ | |
7986 | - pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp) | |
7987 | + GET_THREAD_INFO(%ebp) | |
7988 | + pushl TI_sysenter_return(%ebp) | |
7989 | CFI_ADJUST_CFA_OFFSET 4 | |
7990 | CFI_REL_OFFSET eip, 0 | |
7991 | ||
7992 | @@ -330,9 +358,19 @@ sysenter_past_esp: | |
7993 | * Load the potential sixth argument from user stack. | |
7994 | * Careful about security. | |
7995 | */ | |
7996 | + movl PT_OLDESP(%esp),%ebp | |
7997 | + | |
7998 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
7999 | + mov PT_OLDSS(%esp),%ds | |
8000 | +1: movl %ds:(%ebp),%ebp | |
8001 | + push %ss | |
8002 | + pop %ds | |
8003 | +#else | |
8004 | cmpl $__PAGE_OFFSET-3,%ebp | |
8005 | jae syscall_fault | |
8006 | 1: movl (%ebp),%ebp | |
8007 | +#endif | |
8008 | + | |
8009 | movl %ebp,PT_EBP(%esp) | |
8010 | .section __ex_table,"a" | |
8011 | .align 4 | |
8012 | @@ -356,12 +394,23 @@ sysenter_do_call: | |
8013 | testw $_TIF_ALLWORK_MASK, %cx | |
8014 | jne sysexit_audit | |
8015 | sysenter_exit: | |
8016 | + | |
8017 | +#ifdef CONFIG_PAX_RANDKSTACK | |
8018 | + pushl %eax | |
8019 | + CFI_ADJUST_CFA_OFFSET 4 | |
8020 | + call pax_randomize_kstack | |
8021 | + popl %eax | |
8022 | + CFI_ADJUST_CFA_OFFSET -4 | |
8023 | +#endif | |
8024 | + | |
8025 | /* if something modifies registers it must also disable sysexit */ | |
8026 | movl PT_EIP(%esp), %edx | |
8027 | movl PT_OLDESP(%esp), %ecx | |
8028 | xorl %ebp,%ebp | |
8029 | TRACE_IRQS_ON | |
8030 | 1: mov PT_FS(%esp), %fs | |
8031 | +2: mov PT_DS(%esp), %ds | |
8032 | +3: mov PT_ES(%esp), %es | |
8033 | ENABLE_INTERRUPTS_SYSEXIT | |
8034 | ||
8035 | #ifdef CONFIG_AUDITSYSCALL | |
8036 | @@ -404,11 +453,17 @@ sysexit_audit: | |
8037 | ||
8038 | CFI_ENDPROC | |
8039 | .pushsection .fixup,"ax" | |
8040 | -2: movl $0,PT_FS(%esp) | |
8041 | +4: movl $0,PT_FS(%esp) | |
8042 | + jmp 1b | |
8043 | +5: movl $0,PT_DS(%esp) | |
8044 | + jmp 1b | |
8045 | +6: movl $0,PT_ES(%esp) | |
8046 | jmp 1b | |
8047 | .section __ex_table,"a" | |
8048 | .align 4 | |
8049 | - .long 1b,2b | |
8050 | + .long 1b,4b | |
8051 | + .long 2b,5b | |
8052 | + .long 3b,6b | |
8053 | .popsection | |
8054 | ENDPROC(ia32_sysenter_target) | |
8055 | ||
8056 | @@ -438,6 +493,10 @@ syscall_exit: | |
8057 | testw $_TIF_ALLWORK_MASK, %cx # current->work | |
8058 | jne syscall_exit_work | |
8059 | ||
8060 | +#ifdef CONFIG_PAX_RANDKSTACK | |
8061 | + call pax_randomize_kstack | |
8062 | +#endif | |
8063 | + | |
8064 | restore_all: | |
8065 | movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS | |
8066 | # Warning: PT_OLDSS(%esp) contains the wrong/random values if we | |
8067 | @@ -531,25 +590,19 @@ work_resched: | |
8068 | ||
8069 | work_notifysig: # deal with pending signals and | |
8070 | # notify-resume requests | |
8071 | + movl %esp, %eax | |
8072 | #ifdef CONFIG_VM86 | |
8073 | testl $X86_EFLAGS_VM, PT_EFLAGS(%esp) | |
8074 | - movl %esp, %eax | |
8075 | - jne work_notifysig_v86 # returning to kernel-space or | |
8076 | + jz 1f # returning to kernel-space or | |
8077 | # vm86-space | |
8078 | - xorl %edx, %edx | |
8079 | - call do_notify_resume | |
8080 | - jmp resume_userspace_sig | |
8081 | ||
8082 | - ALIGN | |
8083 | -work_notifysig_v86: | |
8084 | pushl %ecx # save ti_flags for do_notify_resume | |
8085 | CFI_ADJUST_CFA_OFFSET 4 | |
8086 | call save_v86_state # %eax contains pt_regs pointer | |
8087 | popl %ecx | |
8088 | CFI_ADJUST_CFA_OFFSET -4 | |
8089 | movl %eax, %esp | |
8090 | -#else | |
8091 | - movl %esp, %eax | |
8092 | +1: | |
8093 | #endif | |
8094 | xorl %edx, %edx | |
8095 | call do_notify_resume | |
8096 | @@ -584,6 +637,10 @@ END(syscall_exit_work) | |
8097 | ||
8098 | RING0_INT_FRAME # can't unwind into user space anyway | |
8099 | syscall_fault: | |
8100 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
8101 | + push %ss | |
8102 | + pop %ds | |
8103 | +#endif | |
8104 | GET_THREAD_INFO(%ebp) | |
8105 | movl $-EFAULT,PT_EAX(%esp) | |
8106 | jmp resume_userspace | |
8107 | @@ -595,17 +652,24 @@ syscall_badsys: | |
8108 | END(syscall_badsys) | |
8109 | CFI_ENDPROC | |
8110 | ||
8111 | -#define FIXUP_ESPFIX_STACK \ | |
8112 | - /* since we are on a wrong stack, we cant make it a C code :( */ \ | |
8113 | - PER_CPU(gdt_page, %ebx); \ | |
8114 | - GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \ | |
8115 | - addl %esp, %eax; \ | |
8116 | - pushl $__KERNEL_DS; \ | |
8117 | - CFI_ADJUST_CFA_OFFSET 4; \ | |
8118 | - pushl %eax; \ | |
8119 | - CFI_ADJUST_CFA_OFFSET 4; \ | |
8120 | - lss (%esp), %esp; \ | |
8121 | +.macro FIXUP_ESPFIX_STACK | |
8122 | + /* since we are on a wrong stack, we cant make it a C code :( */ | |
8123 | +#ifdef CONFIG_SMP | |
8124 | + movl PER_CPU_VAR(cpu_number), %ebx; | |
8125 | + shll $PAGE_SHIFT_asm, %ebx; | |
8126 | + addl $cpu_gdt_table, %ebx; | |
8127 | +#else | |
8128 | + movl $cpu_gdt_table, %ebx; | |
8129 | +#endif | |
8130 | + GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); | |
8131 | + addl %esp, %eax; | |
8132 | + pushl $__KERNEL_DS; | |
8133 | + CFI_ADJUST_CFA_OFFSET 4; | |
8134 | + pushl %eax; | |
8135 | + CFI_ADJUST_CFA_OFFSET 4; | |
8136 | + lss (%esp), %esp; | |
8137 | CFI_ADJUST_CFA_OFFSET -8; | |
8138 | +.endm | |
8139 | #define UNWIND_ESPFIX_STACK \ | |
8140 | movl %ss, %eax; \ | |
8141 | /* see if on espfix stack */ \ | |
8142 | @@ -1052,7 +1116,6 @@ return_to_handler: | |
8143 | ret | |
8144 | #endif | |
8145 | ||
8146 | -.section .rodata,"a" | |
8147 | #include "syscall_table_32.S" | |
8148 | ||
8149 | syscall_table_size=(.-sys_call_table) | |
8150 | @@ -1106,12 +1169,21 @@ error_code: | |
8151 | popl %ecx | |
8152 | CFI_ADJUST_CFA_OFFSET -4 | |
8153 | /*CFI_REGISTER es, ecx*/ | |
8154 | + | |
8155 | +#ifdef CONFIG_PAX_KERNEXEC | |
8156 | + GET_CR0_INTO_EDX | |
8157 | + movl %edx, %esi | |
8158 | + orl $X86_CR0_WP, %edx | |
8159 | + xorl %edx, %esi | |
8160 | + SET_CR0_FROM_EDX | |
8161 | +#endif | |
8162 | + | |
8163 | movl PT_FS(%esp), %edi # get the function address | |
8164 | movl PT_ORIG_EAX(%esp), %edx # get the error code | |
8165 | movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart | |
8166 | mov %ecx, PT_FS(%esp) | |
8167 | /*CFI_REL_OFFSET fs, ES*/ | |
8168 | - movl $(__USER_DS), %ecx | |
8169 | + movl $(__KERNEL_DS), %ecx | |
8170 | movl %ecx, %ds | |
8171 | movl %ecx, %es | |
8172 | TRACE_IRQS_OFF | |
8173 | @@ -1206,6 +1278,13 @@ nmi_stack_correct: | |
8174 | xorl %edx,%edx # zero error code | |
8175 | movl %esp,%eax # pt_regs pointer | |
8176 | call do_nmi | |
8177 | + | |
8178 | +#ifdef CONFIG_PAX_KERNEXEC | |
8179 | + GET_CR0_INTO_EDX | |
8180 | + xorl %esi, %edx | |
8181 | + SET_CR0_FROM_EDX | |
8182 | +#endif | |
8183 | + | |
8184 | jmp restore_nocheck_notrace | |
8185 | CFI_ENDPROC | |
8186 | ||
8187 | @@ -1246,6 +1325,13 @@ nmi_espfix_stack: | |
8188 | FIXUP_ESPFIX_STACK # %eax == %esp | |
8189 | xorl %edx,%edx # zero error code | |
8190 | call do_nmi | |
8191 | + | |
8192 | +#ifdef CONFIG_PAX_KERNEXEC | |
8193 | + GET_CR0_INTO_EDX | |
8194 | + xorl %esi, %edx | |
8195 | + SET_CR0_FROM_EDX | |
8196 | +#endif | |
8197 | + | |
8198 | RESTORE_REGS | |
8199 | lss 12+4(%esp), %esp # back to espfix stack | |
8200 | CFI_ADJUST_CFA_OFFSET -24 | |
de855c5d AM |
8201 | diff -urNp linux-2.6.29.6/arch/x86/kernel/entry_64.S linux-2.6.29.6/arch/x86/kernel/entry_64.S |
8202 | --- linux-2.6.29.6/arch/x86/kernel/entry_64.S 2009-07-02 19:41:20.000000000 -0400 | |
8203 | +++ linux-2.6.29.6/arch/x86/kernel/entry_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8204 | @@ -1073,10 +1073,11 @@ ENTRY(\sym) |
8205 | TRACE_IRQS_OFF | |
8206 | movq %rsp,%rdi /* pt_regs pointer */ | |
8207 | xorl %esi,%esi /* no error code */ | |
8208 | - movq %gs:pda_data_offset, %rbp | |
8209 | - subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | |
8210 | + imul $TSS_size, %gs:pda_cpunumber, %ebp | |
8211 | + lea init_tss(%rbp), %rbp | |
8212 | + subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp) | |
8213 | call \do_sym | |
8214 | - addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | |
8215 | + addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp) | |
8216 | jmp paranoid_exit /* %ebx: no swapgs flag */ | |
8217 | CFI_ENDPROC | |
8218 | END(\sym) | |
de855c5d AM |
8219 | diff -urNp linux-2.6.29.6/arch/x86/kernel/ftrace.c linux-2.6.29.6/arch/x86/kernel/ftrace.c |
8220 | --- linux-2.6.29.6/arch/x86/kernel/ftrace.c 2009-07-02 19:41:20.000000000 -0400 | |
8221 | +++ linux-2.6.29.6/arch/x86/kernel/ftrace.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8222 | @@ -250,9 +250,9 @@ int ftrace_update_ftrace_func(ftrace_fun |
8223 | unsigned char old[MCOUNT_INSN_SIZE], *new; | |
8224 | int ret; | |
8225 | ||
8226 | - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE); | |
8227 | + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE); | |
8228 | new = ftrace_call_replace(ip, (unsigned long)func); | |
8229 | - ret = ftrace_modify_code(ip, old, new); | |
8230 | + ret = ftrace_modify_code(ktla_ktva(ip), old, new); | |
8231 | ||
8232 | return ret; | |
8233 | } | |
de855c5d AM |
8234 | diff -urNp linux-2.6.29.6/arch/x86/kernel/head32.c linux-2.6.29.6/arch/x86/kernel/head32.c |
8235 | --- linux-2.6.29.6/arch/x86/kernel/head32.c 2009-07-02 19:41:20.000000000 -0400 | |
8236 | +++ linux-2.6.29.6/arch/x86/kernel/head32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8237 | @@ -13,12 +13,13 @@ |
8238 | #include <asm/e820.h> | |
8239 | #include <asm/bios_ebda.h> | |
8240 | #include <asm/trampoline.h> | |
8241 | +#include <asm/boot.h> | |
8242 | ||
8243 | void __init i386_start_kernel(void) | |
8244 | { | |
8245 | reserve_trampoline_memory(); | |
8246 | ||
8247 | - reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS"); | |
8248 | + reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS"); | |
8249 | ||
8250 | #ifdef CONFIG_BLK_DEV_INITRD | |
8251 | /* Reserve INITRD */ | |
de855c5d AM |
8252 | diff -urNp linux-2.6.29.6/arch/x86/kernel/head_32.S linux-2.6.29.6/arch/x86/kernel/head_32.S |
8253 | --- linux-2.6.29.6/arch/x86/kernel/head_32.S 2009-07-02 19:41:20.000000000 -0400 | |
8254 | +++ linux-2.6.29.6/arch/x86/kernel/head_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8255 | @@ -19,6 +19,7 @@ |
8256 | #include <asm/asm-offsets.h> | |
8257 | #include <asm/setup.h> | |
8258 | #include <asm/processor-flags.h> | |
8259 | +#include <asm/msr-index.h> | |
8260 | ||
8261 | /* Physical address */ | |
8262 | #define pa(X) ((X) - __PAGE_OFFSET) | |
8263 | @@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm) | |
8264 | LOW_PAGES = LOW_PAGES + 0x1000000 | |
8265 | #endif | |
8266 | ||
8267 | -#if PTRS_PER_PMD > 1 | |
8268 | -PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD | |
8269 | -#else | |
8270 | -PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD) | |
8271 | -#endif | |
8272 | +PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE) | |
8273 | BOOTBITMAP_SIZE = LOW_PAGES / 8 | |
8274 | ALLOCATOR_SLOP = 4 | |
8275 | ||
8276 | INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm | |
8277 | ||
8278 | /* | |
8279 | + * Real beginning of normal "text" segment | |
8280 | + */ | |
8281 | +ENTRY(stext) | |
8282 | +ENTRY(_stext) | |
8283 | + | |
8284 | +.section .text.startup,"ax",@progbits | |
8285 | + ljmp $(__BOOT_CS),$phys_startup_32 | |
8286 | + | |
8287 | +/* | |
8288 | * 32-bit kernel entrypoint; only used by the boot CPU. On entry, | |
8289 | * %esi points to the real-mode code as a 32-bit pointer. | |
8290 | * CS and DS must be 4 GB flat segments, but we don't depend on | |
8291 | @@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + | |
8292 | * can. | |
8293 | */ | |
8294 | .section .text.head,"ax",@progbits | |
8295 | + | |
8296 | +#ifdef CONFIG_PAX_KERNEXEC | |
8297 | +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */ | |
8298 | +.fill 4096,1,0xcc | |
8299 | +#endif | |
8300 | + | |
8301 | ENTRY(startup_32) | |
8302 | /* test KEEP_SEGMENTS flag to see if the bootloader is asking | |
8303 | us to not reload segments */ | |
8304 | @@ -99,6 +111,56 @@ ENTRY(startup_32) | |
8305 | movl %eax,%gs | |
8306 | 2: | |
8307 | ||
8308 | + movl $pa(cpu_gdt_table),%edi | |
8309 | + movl $__per_cpu_start,%eax | |
8310 | + movw %ax,__KERNEL_PERCPU + 2(%edi) | |
8311 | + rorl $16,%eax | |
8312 | + movb %al,__KERNEL_PERCPU + 4(%edi) | |
8313 | + movb %ah,__KERNEL_PERCPU + 7(%edi) | |
8314 | + movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax | |
8315 | + subl $__per_cpu_start,%eax | |
8316 | + movw %ax,__KERNEL_PERCPU + 0(%edi) | |
8317 | + | |
8318 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
8319 | + /* check for VMware */ | |
8320 | + movl $0x564d5868,%eax | |
8321 | + xorl %ebx,%ebx | |
8322 | + movl $0xa,%ecx | |
8323 | + movl $0x5658,%edx | |
8324 | + in (%dx),%eax | |
8325 | + cmpl $0x564d5868,%ebx | |
8326 | + jz 2f | |
8327 | + | |
8328 | + movl $NR_CPUS,%ecx | |
8329 | + movl $pa(cpu_gdt_table),%edi | |
8330 | +1: | |
8331 | + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi) | |
8332 | + addl $PAGE_SIZE_asm,%edi | |
8333 | + loop 1b | |
8334 | +2: | |
8335 | +#endif | |
8336 | + | |
8337 | +#ifdef CONFIG_PAX_KERNEXEC | |
8338 | + movl $pa(boot_gdt),%edi | |
8339 | + movl $KERNEL_TEXT_OFFSET,%eax | |
8340 | + movw %ax,__BOOT_CS + 2(%edi) | |
8341 | + rorl $16,%eax | |
8342 | + movb %al,__BOOT_CS + 4(%edi) | |
8343 | + movb %ah,__BOOT_CS + 7(%edi) | |
8344 | + rorl $16,%eax | |
8345 | + | |
8346 | + movl $NR_CPUS,%ecx | |
8347 | + movl $pa(cpu_gdt_table),%edi | |
8348 | +1: | |
8349 | + movw %ax,__KERNEL_CS + 2(%edi) | |
8350 | + rorl $16,%eax | |
8351 | + movb %al,__KERNEL_CS + 4(%edi) | |
8352 | + movb %ah,__KERNEL_CS + 7(%edi) | |
8353 | + rorl $16,%eax | |
8354 | + addl $PAGE_SIZE_asm,%edi | |
8355 | + loop 1b | |
8356 | +#endif | |
8357 | + | |
8358 | /* | |
8359 | * Clear BSS first so that there are no surprises... | |
8360 | */ | |
8361 | @@ -142,9 +204,7 @@ ENTRY(startup_32) | |
8362 | cmpl $num_subarch_entries, %eax | |
8363 | jae bad_subarch | |
8364 | ||
8365 | - movl pa(subarch_entries)(,%eax,4), %eax | |
8366 | - subl $__PAGE_OFFSET, %eax | |
8367 | - jmp *%eax | |
8368 | + jmp *pa(subarch_entries)(,%eax,4) | |
8369 | ||
8370 | bad_subarch: | |
8371 | WEAK(lguest_entry) | |
8372 | @@ -156,9 +216,9 @@ WEAK(xen_entry) | |
8373 | __INITDATA | |
8374 | ||
8375 | subarch_entries: | |
8376 | - .long default_entry /* normal x86/PC */ | |
8377 | - .long lguest_entry /* lguest hypervisor */ | |
8378 | - .long xen_entry /* Xen hypervisor */ | |
8379 | + .long pa(default_entry) /* normal x86/PC */ | |
8380 | + .long pa(lguest_entry) /* lguest hypervisor */ | |
8381 | + .long pa(xen_entry) /* Xen hypervisor */ | |
8382 | num_subarch_entries = (. - subarch_entries) / 4 | |
8383 | .previous | |
8384 | #endif /* CONFIG_PARAVIRT */ | |
8385 | @@ -220,8 +280,7 @@ default_entry: | |
8386 | movl %eax, pa(max_pfn_mapped) | |
8387 | ||
8388 | /* Do early initialization of the fixmap area */ | |
8389 | - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax | |
8390 | - movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8) | |
8391 | + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8) | |
8392 | #else /* Not PAE */ | |
8393 | ||
8394 | page_pde_offset = (__PAGE_OFFSET >> 20); | |
8395 | @@ -253,8 +312,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20); | |
8396 | movl %eax, pa(max_pfn_mapped) | |
8397 | ||
8398 | /* Do early initialization of the fixmap area */ | |
8399 | - movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax | |
8400 | - movl %eax,pa(swapper_pg_dir+0xffc) | |
8401 | + movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc) | |
8402 | #endif | |
8403 | jmp 3f | |
8404 | /* | |
8405 | @@ -318,13 +376,16 @@ ENTRY(startup_32_smp) | |
8406 | jnc 6f | |
8407 | ||
8408 | /* Setup EFER (Extended Feature Enable Register) */ | |
8409 | - movl $0xc0000080, %ecx | |
8410 | + movl $MSR_EFER, %ecx | |
8411 | rdmsr | |
8412 | ||
8413 | btsl $11, %eax | |
8414 | /* Make changes effective */ | |
8415 | wrmsr | |
8416 | ||
8417 | + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4) | |
8418 | + movl $1,pa(nx_enabled) | |
8419 | + | |
8420 | 6: | |
8421 | ||
8422 | /* | |
8423 | @@ -350,9 +411,7 @@ ENTRY(startup_32_smp) | |
8424 | ||
8425 | #ifdef CONFIG_SMP | |
8426 | cmpb $0, ready | |
8427 | - jz 1f /* Initial CPU cleans BSS */ | |
8428 | - jmp checkCPUtype | |
8429 | -1: | |
8430 | + jnz checkCPUtype /* Initial CPU cleans BSS */ | |
8431 | #endif /* CONFIG_SMP */ | |
8432 | ||
8433 | /* | |
8434 | @@ -429,12 +488,12 @@ is386: movl $2,%ecx # set MP | |
8435 | ljmp $(__KERNEL_CS),$1f | |
8436 | 1: movl $(__KERNEL_DS),%eax # reload all the segment registers | |
8437 | movl %eax,%ss # after changing gdt. | |
8438 | - movl %eax,%fs # gets reset once there's real percpu | |
8439 | - | |
8440 | - movl $(__USER_DS),%eax # DS/ES contains default USER segment | |
8441 | movl %eax,%ds | |
8442 | movl %eax,%es | |
8443 | ||
8444 | + movl $(__KERNEL_PERCPU), %eax | |
8445 | + movl %eax,%fs # set this cpu's percpu | |
8446 | + | |
8447 | xorl %eax,%eax # Clear GS and LDT | |
8448 | movl %eax,%gs | |
8449 | lldt %ax | |
8450 | @@ -444,12 +503,6 @@ is386: movl $2,%ecx # set MP | |
8451 | #ifdef CONFIG_SMP | |
8452 | movb ready, %cl | |
8453 | movb $1, ready | |
8454 | - cmpb $0,%cl # the first CPU calls start_kernel | |
8455 | - je 1f | |
8456 | - movl $(__KERNEL_PERCPU), %eax | |
8457 | - movl %eax,%fs # set this cpu's percpu | |
8458 | - movl (stack_start), %esp | |
8459 | -1: | |
8460 | #endif /* CONFIG_SMP */ | |
8461 | jmp *(initial_code) | |
8462 | ||
8463 | @@ -535,15 +588,15 @@ early_page_fault: | |
8464 | jmp early_fault | |
8465 | ||
8466 | early_fault: | |
8467 | - cld | |
8468 | #ifdef CONFIG_PRINTK | |
8469 | + cmpl $2,%ss:early_recursion_flag | |
8470 | + je hlt_loop | |
8471 | + incl %ss:early_recursion_flag | |
8472 | + cld | |
8473 | pusha | |
8474 | movl $(__KERNEL_DS),%eax | |
8475 | movl %eax,%ds | |
8476 | movl %eax,%es | |
8477 | - cmpl $2,early_recursion_flag | |
8478 | - je hlt_loop | |
8479 | - incl early_recursion_flag | |
8480 | movl %cr2,%eax | |
8481 | pushl %eax | |
8482 | pushl %edx /* trapno */ | |
8483 | @@ -553,8 +606,8 @@ early_fault: | |
8484 | #else | |
8485 | call printk | |
8486 | #endif | |
8487 | -#endif | |
8488 | call dump_stack | |
8489 | +#endif | |
8490 | hlt_loop: | |
8491 | hlt | |
8492 | jmp hlt_loop | |
8493 | @@ -562,8 +615,11 @@ hlt_loop: | |
8494 | /* This is the default interrupt "handler" :-) */ | |
8495 | ALIGN | |
8496 | ignore_int: | |
8497 | - cld | |
8498 | #ifdef CONFIG_PRINTK | |
8499 | + cmpl $2,%ss:early_recursion_flag | |
8500 | + je hlt_loop | |
8501 | + incl %ss:early_recursion_flag | |
8502 | + cld | |
8503 | pushl %eax | |
8504 | pushl %ecx | |
8505 | pushl %edx | |
8506 | @@ -572,9 +628,6 @@ ignore_int: | |
8507 | movl $(__KERNEL_DS),%eax | |
8508 | movl %eax,%ds | |
8509 | movl %eax,%es | |
8510 | - cmpl $2,early_recursion_flag | |
8511 | - je hlt_loop | |
8512 | - incl early_recursion_flag | |
8513 | pushl 16(%esp) | |
8514 | pushl 24(%esp) | |
8515 | pushl 32(%esp) | |
8516 | @@ -599,36 +652,41 @@ ignore_int: | |
8517 | ENTRY(initial_code) | |
8518 | .long i386_start_kernel | |
8519 | ||
8520 | -.section .text | |
8521 | -/* | |
8522 | - * Real beginning of normal "text" segment | |
8523 | - */ | |
8524 | -ENTRY(stext) | |
8525 | -ENTRY(_stext) | |
8526 | - | |
8527 | /* | |
8528 | * BSS section | |
8529 | */ | |
8530 | -.section ".bss.page_aligned","wa" | |
8531 | - .align PAGE_SIZE_asm | |
8532 | #ifdef CONFIG_X86_PAE | |
8533 | +.section .swapper_pg_pmd,"a",@progbits | |
8534 | swapper_pg_pmd: | |
8535 | .fill 1024*KPMDS,4,0 | |
8536 | #else | |
8537 | +.section .swapper_pg_dir,"a",@progbits | |
8538 | ENTRY(swapper_pg_dir) | |
8539 | .fill 1024,4,0 | |
8540 | #endif | |
8541 | swapper_pg_fixmap: | |
8542 | .fill 1024,4,0 | |
8543 | + | |
8544 | +.section .empty_zero_page,"a",@progbits | |
8545 | ENTRY(empty_zero_page) | |
8546 | .fill 4096,1,0 | |
8547 | + | |
8548 | +/* | |
8549 | + * The IDT has to be page-aligned to simplify the Pentium | |
8550 | + * F0 0F bug workaround.. We have a special link segment | |
8551 | + * for this. | |
8552 | + */ | |
8553 | +.section .idt,"a",@progbits | |
8554 | +ENTRY(idt_table) | |
8555 | + .fill 256,8,0 | |
8556 | + | |
8557 | /* | |
8558 | * This starts the data section. | |
8559 | */ | |
8560 | +.data | |
8561 | + | |
8562 | #ifdef CONFIG_X86_PAE | |
8563 | -.section ".data.page_aligned","wa" | |
8564 | - /* Page-aligned for the benefit of paravirt? */ | |
8565 | - .align PAGE_SIZE_asm | |
8566 | +.section .swapper_pg_dir,"a",@progbits | |
8567 | ENTRY(swapper_pg_dir) | |
8568 | .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */ | |
8569 | # if KPMDS == 3 | |
8570 | @@ -651,11 +709,12 @@ ENTRY(swapper_pg_dir) | |
8571 | ||
8572 | .data | |
8573 | ENTRY(stack_start) | |
8574 | - .long init_thread_union+THREAD_SIZE | |
8575 | + .long init_thread_union+THREAD_SIZE-8 | |
8576 | .long __BOOT_DS | |
8577 | ||
8578 | ready: .byte 0 | |
8579 | ||
8580 | +.section .rodata,"a",@progbits | |
8581 | early_recursion_flag: | |
8582 | .long 0 | |
8583 | ||
8584 | @@ -691,7 +750,7 @@ fault_msg: | |
8585 | .word 0 # 32 bit align gdt_desc.address | |
8586 | boot_gdt_descr: | |
8587 | .word __BOOT_DS+7 | |
8588 | - .long boot_gdt - __PAGE_OFFSET | |
8589 | + .long pa(boot_gdt) | |
8590 | ||
8591 | .word 0 # 32-bit align idt_desc.address | |
8592 | idt_descr: | |
8593 | @@ -702,7 +761,7 @@ idt_descr: | |
8594 | .word 0 # 32 bit align gdt_desc.address | |
8595 | ENTRY(early_gdt_descr) | |
8596 | .word GDT_ENTRIES*8-1 | |
8597 | - .long per_cpu__gdt_page /* Overwritten for secondary CPUs */ | |
8598 | + .long cpu_gdt_table /* Overwritten for secondary CPUs */ | |
8599 | ||
8600 | /* | |
8601 | * The boot_gdt must mirror the equivalent in setup.S and is | |
8602 | @@ -711,5 +770,59 @@ ENTRY(early_gdt_descr) | |
8603 | .align L1_CACHE_BYTES | |
8604 | ENTRY(boot_gdt) | |
8605 | .fill GDT_ENTRY_BOOT_CS,8,0 | |
8606 | - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */ | |
8607 | - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */ | |
8608 | + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */ | |
8609 | + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */ | |
8610 | + | |
8611 | + .align PAGE_SIZE_asm | |
8612 | +ENTRY(cpu_gdt_table) | |
8613 | + .rept NR_CPUS | |
8614 | + .quad 0x0000000000000000 /* NULL descriptor */ | |
8615 | + .quad 0x0000000000000000 /* 0x0b reserved */ | |
8616 | + .quad 0x0000000000000000 /* 0x13 reserved */ | |
8617 | + .quad 0x0000000000000000 /* 0x1b reserved */ | |
8618 | + .quad 0x0000000000000000 /* 0x20 unused */ | |
8619 | + .quad 0x0000000000000000 /* 0x28 unused */ | |
8620 | + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */ | |
8621 | + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */ | |
8622 | + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */ | |
8623 | + .quad 0x0000000000000000 /* 0x4b reserved */ | |
8624 | + .quad 0x0000000000000000 /* 0x53 reserved */ | |
8625 | + .quad 0x0000000000000000 /* 0x5b reserved */ | |
8626 | + | |
8627 | + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */ | |
8628 | + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */ | |
8629 | + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */ | |
8630 | + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */ | |
8631 | + | |
8632 | + .quad 0x0000000000000000 /* 0x80 TSS descriptor */ | |
8633 | + .quad 0x0000000000000000 /* 0x88 LDT descriptor */ | |
8634 | + | |
8635 | + /* | |
8636 | + * Segments used for calling PnP BIOS have byte granularity. | |
8637 | + * The code segments and data segments have fixed 64k limits, | |
8638 | + * the transfer segment sizes are set at run time. | |
8639 | + */ | |
8640 | + .quad 0x00409b000000ffff /* 0x90 32-bit code */ | |
8641 | + .quad 0x00009b000000ffff /* 0x98 16-bit code */ | |
8642 | + .quad 0x000093000000ffff /* 0xa0 16-bit data */ | |
8643 | + .quad 0x0000930000000000 /* 0xa8 16-bit data */ | |
8644 | + .quad 0x0000930000000000 /* 0xb0 16-bit data */ | |
8645 | + | |
8646 | + /* | |
8647 | + * The APM segments have byte granularity and their bases | |
8648 | + * are set at run time. All have 64k limits. | |
8649 | + */ | |
8650 | + .quad 0x00409b000000ffff /* 0xb8 APM CS code */ | |
8651 | + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */ | |
8652 | + .quad 0x004093000000ffff /* 0xc8 APM DS data */ | |
8653 | + | |
8654 | + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */ | |
8655 | + .quad 0x0040930000000000 /* 0xd8 - PERCPU */ | |
8656 | + .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */ | |
8657 | + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */ | |
8658 | + .quad 0x0000000000000000 /* 0xf0 - unused */ | |
8659 | + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */ | |
8660 | + | |
8661 | + /* Be sure this is zeroed to avoid false validations in Xen */ | |
8662 | + .fill PAGE_SIZE_asm - GDT_SIZE,1,0 | |
8663 | + .endr | |
de855c5d AM |
8664 | diff -urNp linux-2.6.29.6/arch/x86/kernel/head64.c linux-2.6.29.6/arch/x86/kernel/head64.c |
8665 | --- linux-2.6.29.6/arch/x86/kernel/head64.c 2009-07-02 19:41:20.000000000 -0400 | |
8666 | +++ linux-2.6.29.6/arch/x86/kernel/head64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8667 | @@ -94,6 +94,8 @@ void __init x86_64_start_kernel(char * r |
8668 | /* clear bss before set_intr_gate with early_idt_handler */ | |
8669 | clear_bss(); | |
8670 | ||
8671 | + x86_64_init_pda(); | |
8672 | + | |
8673 | /* Make NULL pointers segfault */ | |
8674 | zap_identity_mappings(); | |
8675 | ||
8676 | @@ -112,8 +114,6 @@ void __init x86_64_start_kernel(char * r | |
8677 | if (console_loglevel == 10) | |
8678 | early_printk("Kernel alive\n"); | |
8679 | ||
8680 | - x86_64_init_pda(); | |
8681 | - | |
8682 | x86_64_start_reservations(real_mode_data); | |
8683 | } | |
8684 | ||
de855c5d AM |
8685 | diff -urNp linux-2.6.29.6/arch/x86/kernel/head_64.S linux-2.6.29.6/arch/x86/kernel/head_64.S |
8686 | --- linux-2.6.29.6/arch/x86/kernel/head_64.S 2009-07-02 19:41:20.000000000 -0400 | |
8687 | +++ linux-2.6.29.6/arch/x86/kernel/head_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8688 | @@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET |
8689 | L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET) | |
8690 | L4_START_KERNEL = pgd_index(__START_KERNEL_map) | |
8691 | L3_START_KERNEL = pud_index(__START_KERNEL_map) | |
8692 | +L4_VMALLOC_START = pgd_index(VMALLOC_START) | |
8693 | +L3_VMALLOC_START = pud_index(VMALLOC_START) | |
8694 | +L4_VMEMMAP_START = pgd_index(VMEMMAP_START) | |
8695 | +L3_VMEMMAP_START = pud_index(VMEMMAP_START) | |
8696 | ||
8697 | .text | |
8698 | .section .text.head | |
8699 | @@ -85,35 +89,22 @@ startup_64: | |
8700 | */ | |
8701 | addq %rbp, init_level4_pgt + 0(%rip) | |
8702 | addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip) | |
8703 | + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip) | |
8704 | + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip) | |
8705 | addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip) | |
8706 | ||
8707 | addq %rbp, level3_ident_pgt + 0(%rip) | |
8708 | + addq %rbp, level3_ident_pgt + 8(%rip) | |
8709 | + addq %rbp, level3_ident_pgt + 16(%rip) | |
8710 | + addq %rbp, level3_ident_pgt + 24(%rip) | |
8711 | ||
8712 | - addq %rbp, level3_kernel_pgt + (510*8)(%rip) | |
8713 | - addq %rbp, level3_kernel_pgt + (511*8)(%rip) | |
8714 | + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip) | |
8715 | ||
8716 | - addq %rbp, level2_fixmap_pgt + (506*8)(%rip) | |
8717 | + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip) | |
8718 | + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip) | |
8719 | ||
8720 | - /* Add an Identity mapping if I am above 1G */ | |
8721 | - leaq _text(%rip), %rdi | |
8722 | - andq $PMD_PAGE_MASK, %rdi | |
8723 | - | |
8724 | - movq %rdi, %rax | |
8725 | - shrq $PUD_SHIFT, %rax | |
8726 | - andq $(PTRS_PER_PUD - 1), %rax | |
8727 | - jz ident_complete | |
8728 | - | |
8729 | - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx | |
8730 | - leaq level3_ident_pgt(%rip), %rbx | |
8731 | - movq %rdx, 0(%rbx, %rax, 8) | |
8732 | - | |
8733 | - movq %rdi, %rax | |
8734 | - shrq $PMD_SHIFT, %rax | |
8735 | - andq $(PTRS_PER_PMD - 1), %rax | |
8736 | - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx | |
8737 | - leaq level2_spare_pgt(%rip), %rbx | |
8738 | - movq %rdx, 0(%rbx, %rax, 8) | |
8739 | -ident_complete: | |
8740 | + addq %rbp, level2_fixmap_pgt + (506*8)(%rip) | |
8741 | + addq %rbp, level2_fixmap_pgt + (507*8)(%rip) | |
8742 | ||
8743 | /* | |
8744 | * Fixup the kernel text+data virtual addresses. Note that | |
8745 | @@ -187,6 +178,10 @@ ENTRY(secondary_startup_64) | |
8746 | btl $20,%edi /* No Execute supported? */ | |
8747 | jnc 1f | |
8748 | btsl $_EFER_NX, %eax | |
8749 | + leaq init_level4_pgt(%rip), %rdi | |
8750 | + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi) | |
8751 | + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi) | |
8752 | + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi) | |
8753 | 1: wrmsr /* Make changes effective */ | |
8754 | ||
8755 | /* Setup cr0 */ | |
8756 | @@ -257,16 +252,16 @@ ENTRY(secondary_startup_64) | |
8757 | .align 8 | |
8758 | ENTRY(initial_code) | |
8759 | .quad x86_64_start_kernel | |
8760 | - __FINITDATA | |
8761 | ||
8762 | ENTRY(stack_start) | |
8763 | .quad init_thread_union+THREAD_SIZE-8 | |
8764 | .word 0 | |
8765 | + __FINITDATA | |
8766 | ||
8767 | bad_address: | |
8768 | jmp bad_address | |
8769 | ||
8770 | - .section ".init.text","ax" | |
8771 | + __INIT | |
8772 | #ifdef CONFIG_EARLY_PRINTK | |
8773 | .globl early_idt_handlers | |
8774 | early_idt_handlers: | |
8775 | @@ -311,18 +306,23 @@ ENTRY(early_idt_handler) | |
8776 | #endif /* EARLY_PRINTK */ | |
8777 | 1: hlt | |
8778 | jmp 1b | |
8779 | + .previous | |
8780 | ||
8781 | #ifdef CONFIG_EARLY_PRINTK | |
8782 | + __INITDATA | |
8783 | early_recursion_flag: | |
8784 | .long 0 | |
8785 | + .previous | |
8786 | ||
8787 | + .section .rodata,"a",@progbits | |
8788 | early_idt_msg: | |
8789 | .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n" | |
8790 | early_idt_ripmsg: | |
8791 | .asciz "RIP %s\n" | |
8792 | -#endif /* CONFIG_EARLY_PRINTK */ | |
8793 | .previous | |
8794 | +#endif /* CONFIG_EARLY_PRINTK */ | |
8795 | ||
8796 | + .section .rodata,"a",@progbits | |
8797 | .balign PAGE_SIZE | |
8798 | ||
8799 | #define NEXT_PAGE(name) \ | |
8800 | @@ -347,13 +347,27 @@ NEXT_PAGE(init_level4_pgt) | |
8801 | .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8802 | .org init_level4_pgt + L4_PAGE_OFFSET*8, 0 | |
8803 | .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8804 | + .org init_level4_pgt + L4_VMALLOC_START*8, 0 | |
8805 | + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8806 | + .org init_level4_pgt + L4_VMEMMAP_START*8, 0 | |
8807 | + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8808 | .org init_level4_pgt + L4_START_KERNEL*8, 0 | |
8809 | /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */ | |
8810 | .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE | |
8811 | ||
8812 | NEXT_PAGE(level3_ident_pgt) | |
8813 | .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8814 | - .fill 511,8,0 | |
8815 | + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE | |
8816 | + .quad level2_ident_pgt + 2*PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE | |
8817 | + .quad level2_ident_pgt + 3*PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE | |
8818 | + .fill 508,8,0 | |
8819 | + | |
8820 | +NEXT_PAGE(level3_vmalloc_pgt) | |
8821 | + .fill 512,8,0 | |
8822 | + | |
8823 | +NEXT_PAGE(level3_vmemmap_pgt) | |
8824 | + .fill L3_VMEMMAP_START,8,0 | |
8825 | + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8826 | ||
8827 | NEXT_PAGE(level3_kernel_pgt) | |
8828 | .fill L3_START_KERNEL,8,0 | |
8829 | @@ -361,20 +375,27 @@ NEXT_PAGE(level3_kernel_pgt) | |
8830 | .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE | |
8831 | .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE | |
8832 | ||
8833 | +NEXT_PAGE(level2_vmemmap_pgt) | |
8834 | + .fill 512,8,0 | |
8835 | + | |
8836 | NEXT_PAGE(level2_fixmap_pgt) | |
8837 | .fill 506,8,0 | |
8838 | .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE | |
8839 | - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */ | |
8840 | - .fill 5,8,0 | |
8841 | + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE | |
8842 | + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */ | |
8843 | + .fill 4,8,0 | |
8844 | ||
8845 | NEXT_PAGE(level1_fixmap_pgt) | |
8846 | .fill 512,8,0 | |
8847 | ||
8848 | -NEXT_PAGE(level2_ident_pgt) | |
8849 | - /* Since I easily can, map the first 1G. | |
8850 | +NEXT_PAGE(level1_vsyscall_pgt) | |
8851 | + .fill 512,8,0 | |
8852 | + | |
8853 | + /* Since I easily can, map the first 4G. | |
8854 | * Don't set NX because code runs from these pages. | |
8855 | */ | |
8856 | - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) | |
8857 | +NEXT_PAGE(level2_ident_pgt) | |
8858 | + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 4*PTRS_PER_PMD) | |
8859 | ||
8860 | NEXT_PAGE(level2_kernel_pgt) | |
8861 | /* | |
8862 | @@ -387,32 +408,48 @@ NEXT_PAGE(level2_kernel_pgt) | |
8863 | * If you want to increase this then increase MODULES_VADDR | |
8864 | * too.) | |
8865 | */ | |
8866 | - PMDS(0, __PAGE_KERNEL_LARGE_EXEC, | |
8867 | - KERNEL_IMAGE_SIZE/PMD_SIZE) | |
8868 | - | |
8869 | -NEXT_PAGE(level2_spare_pgt) | |
8870 | - .fill 512, 8, 0 | |
8871 | + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) | |
8872 | ||
8873 | #undef PMDS | |
8874 | #undef NEXT_PAGE | |
8875 | ||
8876 | - .data | |
8877 | + .align PAGE_SIZE | |
8878 | +ENTRY(cpu_gdt_table) | |
8879 | + .rept NR_CPUS | |
8880 | + .quad 0x0000000000000000 /* NULL descriptor */ | |
8881 | + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */ | |
8882 | + .quad 0x00af9b000000ffff /* __KERNEL_CS */ | |
8883 | + .quad 0x00cf93000000ffff /* __KERNEL_DS */ | |
8884 | + .quad 0x00cffb000000ffff /* __USER32_CS */ | |
8885 | + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */ | |
8886 | + .quad 0x00affb000000ffff /* __USER_CS */ | |
8887 | + .quad 0x0 /* unused */ | |
8888 | + .quad 0,0 /* TSS */ | |
8889 | + .quad 0,0 /* LDT */ | |
8890 | + .quad 0,0,0 /* three TLS descriptors */ | |
8891 | + .quad 0x0000f40000000000 /* node/CPU stored in limit */ | |
8892 | + /* asm/segment.h:GDT_ENTRIES must match this */ | |
8893 | + | |
8894 | + /* zero the remaining page */ | |
8895 | + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0 | |
8896 | + .endr | |
8897 | + | |
8898 | .align 16 | |
8899 | .globl early_gdt_descr | |
8900 | early_gdt_descr: | |
8901 | .word GDT_ENTRIES*8-1 | |
8902 | - .quad per_cpu__gdt_page | |
8903 | + .quad cpu_gdt_table | |
8904 | ||
8905 | ENTRY(phys_base) | |
8906 | /* This must match the first entry in level2_kernel_pgt */ | |
8907 | .quad 0x0000000000000000 | |
8908 | ||
8909 | #include "../../x86/xen/xen-head.S" | |
8910 | - | |
8911 | - .section .bss, "aw", @nobits | |
8912 | + | |
8913 | + .section .rodata,"a",@progbits | |
8914 | .align L1_CACHE_BYTES | |
8915 | ENTRY(idt_table) | |
8916 | - .skip 256 * 16 | |
8917 | + .fill 512,8,0 | |
8918 | ||
8919 | .section .bss.page_aligned, "aw", @nobits | |
8920 | .align PAGE_SIZE | |
de855c5d AM |
8921 | diff -urNp linux-2.6.29.6/arch/x86/kernel/i386_ksyms_32.c linux-2.6.29.6/arch/x86/kernel/i386_ksyms_32.c |
8922 | --- linux-2.6.29.6/arch/x86/kernel/i386_ksyms_32.c 2009-07-02 19:41:20.000000000 -0400 | |
8923 | +++ linux-2.6.29.6/arch/x86/kernel/i386_ksyms_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8924 | @@ -10,8 +10,12 @@ |
8925 | EXPORT_SYMBOL(mcount); | |
8926 | #endif | |
8927 | ||
8928 | +EXPORT_SYMBOL_GPL(cpu_gdt_table); | |
8929 | + | |
8930 | /* Networking helper routines. */ | |
8931 | EXPORT_SYMBOL(csum_partial_copy_generic); | |
8932 | +EXPORT_SYMBOL(csum_partial_copy_generic_to_user); | |
8933 | +EXPORT_SYMBOL(csum_partial_copy_generic_from_user); | |
8934 | ||
8935 | EXPORT_SYMBOL(__get_user_1); | |
8936 | EXPORT_SYMBOL(__get_user_2); | |
8937 | @@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr); | |
8938 | ||
8939 | EXPORT_SYMBOL(csum_partial); | |
8940 | EXPORT_SYMBOL(empty_zero_page); | |
8941 | + | |
8942 | +#ifdef CONFIG_PAX_KERNEXEC | |
8943 | +EXPORT_SYMBOL(KERNEL_TEXT_OFFSET); | |
8944 | +#endif | |
de855c5d AM |
8945 | diff -urNp linux-2.6.29.6/arch/x86/kernel/init_task.c linux-2.6.29.6/arch/x86/kernel/init_task.c |
8946 | --- linux-2.6.29.6/arch/x86/kernel/init_task.c 2009-07-02 19:41:20.000000000 -0400 | |
8947 | +++ linux-2.6.29.6/arch/x86/kernel/init_task.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8948 | @@ -40,5 +40,5 @@ EXPORT_SYMBOL(init_task); |
8949 | * section. Since TSS's are completely CPU-local, we want them | |
8950 | * on exact cacheline boundaries, to eliminate cacheline ping-pong. | |
8951 | */ | |
8952 | -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS; | |
8953 | - | |
8954 | +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS }; | |
8955 | +EXPORT_SYMBOL(init_tss); | |
de855c5d AM |
8956 | diff -urNp linux-2.6.29.6/arch/x86/kernel/ioport.c linux-2.6.29.6/arch/x86/kernel/ioport.c |
8957 | --- linux-2.6.29.6/arch/x86/kernel/ioport.c 2009-07-02 19:41:20.000000000 -0400 | |
8958 | +++ linux-2.6.29.6/arch/x86/kernel/ioport.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
8959 | @@ -6,6 +6,7 @@ |
8960 | #include <linux/sched.h> | |
8961 | #include <linux/kernel.h> | |
8962 | #include <linux/capability.h> | |
8963 | +#include <linux/security.h> | |
8964 | #include <linux/errno.h> | |
8965 | #include <linux/types.h> | |
8966 | #include <linux/ioport.h> | |
8967 | @@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long | |
8968 | ||
8969 | if ((from + num <= from) || (from + num > IO_BITMAP_BITS)) | |
8970 | return -EINVAL; | |
8971 | +#ifdef CONFIG_GRKERNSEC_IO | |
8972 | + if (turn_on) { | |
8973 | + gr_handle_ioperm(); | |
8974 | + return -EPERM; | |
8975 | + } | |
8976 | +#endif | |
8977 | if (turn_on && !capable(CAP_SYS_RAWIO)) | |
8978 | return -EPERM; | |
8979 | ||
8980 | @@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long | |
8981 | * because the ->io_bitmap_max value must match the bitmap | |
8982 | * contents: | |
8983 | */ | |
8984 | - tss = &per_cpu(init_tss, get_cpu()); | |
8985 | + tss = init_tss + get_cpu(); | |
8986 | ||
8987 | set_bitmap(t->io_bitmap_ptr, from, num, !turn_on); | |
8988 | ||
8989 | @@ -122,8 +129,13 @@ static int do_iopl(unsigned int level, s | |
8990 | return -EINVAL; | |
8991 | /* Trying to gain more privileges? */ | |
8992 | if (level > old) { | |
8993 | +#ifdef CONFIG_GRKERNSEC_IO | |
8994 | + gr_handle_iopl(); | |
8995 | + return -EPERM; | |
8996 | +#else | |
8997 | if (!capable(CAP_SYS_RAWIO)) | |
8998 | return -EPERM; | |
8999 | +#endif | |
9000 | } | |
9001 | regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12); | |
9002 | ||
de855c5d AM |
9003 | diff -urNp linux-2.6.29.6/arch/x86/kernel/irq_32.c linux-2.6.29.6/arch/x86/kernel/irq_32.c |
9004 | --- linux-2.6.29.6/arch/x86/kernel/irq_32.c 2009-07-02 19:41:20.000000000 -0400 | |
9005 | +++ linux-2.6.29.6/arch/x86/kernel/irq_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9006 | @@ -93,7 +93,7 @@ execute_on_irq_stack(int overflow, struc |
9007 | return 0; | |
9008 | ||
9009 | /* build the stack frame on the IRQ stack */ | |
9010 | - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx)); | |
9011 | + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8); | |
9012 | irqctx->tinfo.task = curctx->tinfo.task; | |
9013 | irqctx->tinfo.previous_esp = current_stack_pointer; | |
9014 | ||
9015 | @@ -174,7 +174,7 @@ asmlinkage void do_softirq(void) | |
9016 | irqctx->tinfo.previous_esp = current_stack_pointer; | |
9017 | ||
9018 | /* build the stack frame on the softirq stack */ | |
9019 | - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx)); | |
9020 | + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8); | |
9021 | ||
9022 | call_on_stack(__do_softirq, isp); | |
9023 | /* | |
de855c5d AM |
9024 | diff -urNp linux-2.6.29.6/arch/x86/kernel/kprobes.c linux-2.6.29.6/arch/x86/kernel/kprobes.c |
9025 | --- linux-2.6.29.6/arch/x86/kernel/kprobes.c 2009-07-02 19:41:20.000000000 -0400 | |
9026 | +++ linux-2.6.29.6/arch/x86/kernel/kprobes.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9027 | @@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f |
9028 | char op; | |
9029 | s32 raddr; | |
9030 | } __attribute__((packed)) * jop; | |
9031 | - jop = (struct __arch_jmp_op *)from; | |
9032 | + | |
9033 | +#ifdef CONFIG_PAX_KERNEXEC | |
9034 | + unsigned long cr0; | |
9035 | +#endif | |
9036 | + | |
9037 | + jop = (struct __arch_jmp_op *)(ktla_ktva(from)); | |
9038 | + | |
9039 | +#ifdef CONFIG_PAX_KERNEXEC | |
9040 | + pax_open_kernel(cr0); | |
9041 | +#endif | |
9042 | + | |
9043 | jop->raddr = (s32)((long)(to) - ((long)(from) + 5)); | |
9044 | jop->op = RELATIVEJUMP_INSTRUCTION; | |
9045 | + | |
9046 | +#ifdef CONFIG_PAX_KERNEXEC | |
9047 | + pax_close_kernel(cr0); | |
9048 | +#endif | |
9049 | + | |
9050 | } | |
9051 | ||
9052 | /* | |
9053 | @@ -345,16 +360,29 @@ static void __kprobes fix_riprel(struct | |
9054 | ||
9055 | static void __kprobes arch_copy_kprobe(struct kprobe *p) | |
9056 | { | |
9057 | - memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t)); | |
9058 | + | |
9059 | +#ifdef CONFIG_PAX_KERNEXEC | |
9060 | + unsigned long cr0; | |
9061 | +#endif | |
9062 | + | |
9063 | +#ifdef CONFIG_PAX_KERNEXEC | |
9064 | + pax_open_kernel(cr0); | |
9065 | +#endif | |
9066 | + | |
9067 | + memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t)); | |
9068 | + | |
9069 | +#ifdef CONFIG_PAX_KERNEXEC | |
9070 | + pax_close_kernel(cr0); | |
9071 | +#endif | |
9072 | ||
9073 | fix_riprel(p); | |
9074 | ||
9075 | - if (can_boost(p->addr)) | |
9076 | + if (can_boost(ktla_ktva(p->addr))) | |
9077 | p->ainsn.boostable = 0; | |
9078 | else | |
9079 | p->ainsn.boostable = -1; | |
9080 | ||
9081 | - p->opcode = *p->addr; | |
9082 | + p->opcode = *(ktla_ktva(p->addr)); | |
9083 | } | |
9084 | ||
9085 | int __kprobes arch_prepare_kprobe(struct kprobe *p) | |
9086 | @@ -432,7 +460,7 @@ static void __kprobes prepare_singlestep | |
9087 | if (p->opcode == BREAKPOINT_INSTRUCTION) | |
9088 | regs->ip = (unsigned long)p->addr; | |
9089 | else | |
9090 | - regs->ip = (unsigned long)p->ainsn.insn; | |
9091 | + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn); | |
9092 | } | |
9093 | ||
9094 | void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, | |
9095 | @@ -453,7 +481,7 @@ static void __kprobes setup_singlestep(s | |
9096 | if (p->ainsn.boostable == 1 && !p->post_handler) { | |
9097 | /* Boost up -- we can execute copied instructions directly */ | |
9098 | reset_current_kprobe(); | |
9099 | - regs->ip = (unsigned long)p->ainsn.insn; | |
9100 | + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn); | |
9101 | preempt_enable_no_resched(); | |
9102 | return; | |
9103 | } | |
9104 | @@ -523,7 +551,7 @@ static int __kprobes kprobe_handler(stru | |
9105 | struct kprobe_ctlblk *kcb; | |
9106 | ||
9107 | addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t)); | |
9108 | - if (*addr != BREAKPOINT_INSTRUCTION) { | |
9109 | + if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) { | |
9110 | /* | |
9111 | * The breakpoint instruction was removed right | |
9112 | * after we hit it. Another cpu has removed | |
9113 | @@ -774,7 +802,7 @@ static void __kprobes resume_execution(s | |
9114 | struct pt_regs *regs, struct kprobe_ctlblk *kcb) | |
9115 | { | |
9116 | unsigned long *tos = stack_addr(regs); | |
9117 | - unsigned long copy_ip = (unsigned long)p->ainsn.insn; | |
9118 | + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn); | |
9119 | unsigned long orig_ip = (unsigned long)p->addr; | |
9120 | kprobe_opcode_t *insn = p->ainsn.insn; | |
9121 | ||
9122 | @@ -957,7 +985,7 @@ int __kprobes kprobe_exceptions_notify(s | |
9123 | struct die_args *args = data; | |
9124 | int ret = NOTIFY_DONE; | |
9125 | ||
9126 | - if (args->regs && user_mode_vm(args->regs)) | |
9127 | + if (args->regs && user_mode(args->regs)) | |
9128 | return ret; | |
9129 | ||
9130 | switch (val) { | |
de855c5d AM |
9131 | diff -urNp linux-2.6.29.6/arch/x86/kernel/ldt.c linux-2.6.29.6/arch/x86/kernel/ldt.c |
9132 | --- linux-2.6.29.6/arch/x86/kernel/ldt.c 2009-07-02 19:41:20.000000000 -0400 | |
9133 | +++ linux-2.6.29.6/arch/x86/kernel/ldt.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9134 | @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i |
9135 | if (reload) { | |
9136 | #ifdef CONFIG_SMP | |
9137 | preempt_disable(); | |
9138 | - load_LDT(pc); | |
9139 | + load_LDT_nolock(pc); | |
9140 | if (!cpus_equal(current->mm->cpu_vm_mask, | |
9141 | cpumask_of_cpu(smp_processor_id()))) | |
9142 | smp_call_function(flush_ldt, current->mm, 1); | |
9143 | preempt_enable(); | |
9144 | #else | |
9145 | - load_LDT(pc); | |
9146 | + load_LDT_nolock(pc); | |
9147 | #endif | |
9148 | } | |
9149 | if (oldsize) { | |
9150 | @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t | |
9151 | return err; | |
9152 | ||
9153 | for (i = 0; i < old->size; i++) | |
9154 | - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE); | |
9155 | + write_ldt_entry(new->ldt, i, old->ldt + i); | |
9156 | return 0; | |
9157 | } | |
9158 | ||
9159 | @@ -115,6 +115,24 @@ int init_new_context(struct task_struct | |
9160 | retval = copy_ldt(&mm->context, &old_mm->context); | |
9161 | mutex_unlock(&old_mm->context.lock); | |
9162 | } | |
9163 | + | |
9164 | + if (tsk == current) { | |
9165 | + mm->context.vdso = ~0UL; | |
9166 | + | |
9167 | +#ifdef CONFIG_X86_32 | |
9168 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
9169 | + mm->context.user_cs_base = 0UL; | |
9170 | + mm->context.user_cs_limit = ~0UL; | |
9171 | + | |
9172 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP) | |
9173 | + cpus_clear(mm->context.cpu_user_cs_mask); | |
9174 | +#endif | |
9175 | + | |
9176 | +#endif | |
9177 | +#endif | |
9178 | + | |
9179 | + } | |
9180 | + | |
9181 | return retval; | |
9182 | } | |
9183 | ||
9184 | @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u | |
9185 | } | |
9186 | } | |
9187 | ||
9188 | +#ifdef CONFIG_PAX_SEGMEXEC | |
9189 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) { | |
9190 | + error = -EINVAL; | |
9191 | + goto out_unlock; | |
9192 | + } | |
9193 | +#endif | |
9194 | + | |
9195 | fill_ldt(&ldt, &ldt_info); | |
9196 | if (oldmode) | |
9197 | ldt.avl = 0; | |
de855c5d AM |
9198 | diff -urNp linux-2.6.29.6/arch/x86/kernel/machine_kexec_32.c linux-2.6.29.6/arch/x86/kernel/machine_kexec_32.c |
9199 | --- linux-2.6.29.6/arch/x86/kernel/machine_kexec_32.c 2009-07-02 19:41:20.000000000 -0400 | |
9200 | +++ linux-2.6.29.6/arch/x86/kernel/machine_kexec_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9201 | @@ -26,7 +26,7 @@ |
9202 | #include <asm/system.h> | |
9203 | #include <asm/cacheflush.h> | |
9204 | ||
9205 | -static void set_idt(void *newidt, __u16 limit) | |
9206 | +static void set_idt(struct desc_struct *newidt, __u16 limit) | |
9207 | { | |
9208 | struct desc_ptr curidt; | |
9209 | ||
9210 | @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 | |
9211 | } | |
9212 | ||
9213 | ||
9214 | -static void set_gdt(void *newgdt, __u16 limit) | |
9215 | +static void set_gdt(struct desc_struct *newgdt, __u16 limit) | |
9216 | { | |
9217 | struct desc_ptr curgdt; | |
9218 | ||
9219 | @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image) | |
9220 | } | |
9221 | ||
9222 | control_page = page_address(image->control_code_page); | |
9223 | - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE); | |
9224 | + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE); | |
9225 | ||
9226 | relocate_kernel_ptr = control_page; | |
9227 | page_list[PA_CONTROL_PAGE] = __pa(control_page); | |
de855c5d AM |
9228 | diff -urNp linux-2.6.29.6/arch/x86/kernel/module_32.c linux-2.6.29.6/arch/x86/kernel/module_32.c |
9229 | --- linux-2.6.29.6/arch/x86/kernel/module_32.c 2009-07-02 19:41:20.000000000 -0400 | |
9230 | +++ linux-2.6.29.6/arch/x86/kernel/module_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9231 | @@ -23,6 +23,9 @@ |
9232 | #include <linux/kernel.h> | |
9233 | #include <linux/bug.h> | |
9234 | ||
9235 | +#include <asm/desc.h> | |
9236 | +#include <asm/pgtable.h> | |
9237 | + | |
9238 | #if 0 | |
9239 | #define DEBUGP printk | |
9240 | #else | |
9241 | @@ -33,9 +36,31 @@ void *module_alloc(unsigned long size) | |
9242 | { | |
9243 | if (size == 0) | |
9244 | return NULL; | |
9245 | + | |
9246 | +#ifdef CONFIG_PAX_KERNEXEC | |
9247 | + return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); | |
9248 | +#else | |
9249 | return vmalloc_exec(size); | |
9250 | +#endif | |
9251 | + | |
9252 | } | |
9253 | ||
9254 | +#ifdef CONFIG_PAX_KERNEXEC | |
9255 | +void *module_alloc_exec(unsigned long size) | |
9256 | +{ | |
9257 | + struct vm_struct *area; | |
9258 | + | |
9259 | + if (size == 0) | |
9260 | + return NULL; | |
9261 | + | |
9262 | + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END); | |
9263 | + if (area) | |
9264 | + return area->addr; | |
9265 | + | |
9266 | + return NULL; | |
9267 | +} | |
9268 | +EXPORT_SYMBOL(module_alloc_exec); | |
9269 | +#endif | |
9270 | ||
9271 | /* Free memory returned from module_alloc */ | |
9272 | void module_free(struct module *mod, void *module_region) | |
9273 | @@ -45,6 +70,45 @@ void module_free(struct module *mod, voi | |
9274 | table entries. */ | |
9275 | } | |
9276 | ||
9277 | +#ifdef CONFIG_PAX_KERNEXEC | |
9278 | +void module_free_exec(struct module *mod, void *module_region) | |
9279 | +{ | |
9280 | + struct vm_struct **p, *tmp; | |
9281 | + | |
9282 | + if (!module_region) | |
9283 | + return; | |
9284 | + | |
9285 | + if ((PAGE_SIZE-1) & (unsigned long)module_region) { | |
9286 | + printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region); | |
9287 | + WARN_ON(1); | |
9288 | + return; | |
9289 | + } | |
9290 | + | |
9291 | + write_lock(&vmlist_lock); | |
9292 | + for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next) | |
9293 | + if (tmp->addr == module_region) | |
9294 | + break; | |
9295 | + | |
9296 | + if (tmp) { | |
9297 | + unsigned long cr0; | |
9298 | + | |
9299 | + pax_open_kernel(cr0); | |
9300 | + memset(tmp->addr, 0xCC, tmp->size); | |
9301 | + pax_close_kernel(cr0); | |
9302 | + | |
9303 | + *p = tmp->next; | |
9304 | + kfree(tmp); | |
9305 | + } | |
9306 | + write_unlock(&vmlist_lock); | |
9307 | + | |
9308 | + if (!tmp) { | |
9309 | + printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n", | |
9310 | + module_region); | |
9311 | + WARN_ON(1); | |
9312 | + } | |
9313 | +} | |
9314 | +#endif | |
9315 | + | |
9316 | /* We don't need anything special. */ | |
9317 | int module_frob_arch_sections(Elf_Ehdr *hdr, | |
9318 | Elf_Shdr *sechdrs, | |
9319 | @@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs, | |
9320 | unsigned int i; | |
9321 | Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr; | |
9322 | Elf32_Sym *sym; | |
9323 | - uint32_t *location; | |
9324 | + uint32_t *plocation, location; | |
9325 | + | |
9326 | +#ifdef CONFIG_PAX_KERNEXEC | |
9327 | + unsigned long cr0; | |
9328 | +#endif | |
9329 | ||
9330 | DEBUGP("Applying relocate section %u to %u\n", relsec, | |
9331 | sechdrs[relsec].sh_info); | |
9332 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | |
9333 | /* This is where to make the change */ | |
9334 | - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | |
9335 | - + rel[i].r_offset; | |
9336 | + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset; | |
9337 | + location = (uint32_t)plocation; | |
9338 | + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR) | |
9339 | + plocation = ktla_ktva((void *)plocation); | |
9340 | /* This is the symbol it is referring to. Note that all | |
9341 | undefined symbols have been resolved. */ | |
9342 | sym = (Elf32_Sym *)sechdrs[symindex].sh_addr | |
9343 | @@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs, | |
9344 | ||
9345 | switch (ELF32_R_TYPE(rel[i].r_info)) { | |
9346 | case R_386_32: | |
9347 | + | |
9348 | +#ifdef CONFIG_PAX_KERNEXEC | |
9349 | + pax_open_kernel(cr0); | |
9350 | +#endif | |
9351 | + | |
9352 | /* We add the value into the location given */ | |
9353 | - *location += sym->st_value; | |
9354 | + *plocation += sym->st_value; | |
9355 | + | |
9356 | +#ifdef CONFIG_PAX_KERNEXEC | |
9357 | + pax_close_kernel(cr0); | |
9358 | +#endif | |
9359 | + | |
9360 | break; | |
9361 | case R_386_PC32: | |
9362 | + | |
9363 | +#ifdef CONFIG_PAX_KERNEXEC | |
9364 | + pax_open_kernel(cr0); | |
9365 | +#endif | |
9366 | + | |
9367 | /* Add the value, subtract its postition */ | |
9368 | - *location += sym->st_value - (uint32_t)location; | |
9369 | + *plocation += sym->st_value - location; | |
9370 | + | |
9371 | +#ifdef CONFIG_PAX_KERNEXEC | |
9372 | + pax_close_kernel(cr0); | |
9373 | +#endif | |
9374 | + | |
9375 | break; | |
9376 | default: | |
9377 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", | |
de855c5d AM |
9378 | diff -urNp linux-2.6.29.6/arch/x86/kernel/module_64.c linux-2.6.29.6/arch/x86/kernel/module_64.c |
9379 | --- linux-2.6.29.6/arch/x86/kernel/module_64.c 2009-07-02 19:41:20.000000000 -0400 | |
9380 | +++ linux-2.6.29.6/arch/x86/kernel/module_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9381 | @@ -40,7 +40,7 @@ void module_free(struct module *mod, voi |
9382 | table entries. */ | |
9383 | } | |
9384 | ||
9385 | -void *module_alloc(unsigned long size) | |
9386 | +static void *__module_alloc(unsigned long size, pgprot_t prot) | |
9387 | { | |
9388 | struct vm_struct *area; | |
9389 | ||
9390 | @@ -54,8 +54,31 @@ void *module_alloc(unsigned long size) | |
9391 | if (!area) | |
9392 | return NULL; | |
9393 | ||
9394 | - return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC); | |
9395 | + return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot); | |
9396 | +} | |
9397 | + | |
9398 | +#ifdef CONFIG_PAX_KERNEXEC | |
9399 | +void *module_alloc(unsigned long size) | |
9400 | +{ | |
9401 | + return __module_alloc(size, PAGE_KERNEL); | |
9402 | +} | |
9403 | + | |
9404 | +void module_free_exec(struct module *mod, void *module_region) | |
9405 | +{ | |
9406 | + module_free(mod, module_region); | |
9407 | +} | |
9408 | + | |
9409 | +void *module_alloc_exec(unsigned long size) | |
9410 | +{ | |
9411 | + return __module_alloc(size, PAGE_KERNEL_RX); | |
9412 | } | |
9413 | +#else | |
9414 | +void *module_alloc(unsigned long size) | |
9415 | +{ | |
9416 | + return __module_alloc(size, PAGE_KERNEL_EXEC); | |
9417 | +} | |
9418 | +#endif | |
9419 | + | |
9420 | #endif | |
9421 | ||
9422 | /* We don't need anything special. */ | |
9423 | @@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd | |
9424 | Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr; | |
9425 | Elf64_Sym *sym; | |
9426 | void *loc; | |
9427 | - u64 val; | |
9428 | + u64 val; | |
9429 | + | |
9430 | +#ifdef CONFIG_PAX_KERNEXEC | |
9431 | + unsigned long cr0; | |
9432 | +#endif | |
9433 | ||
9434 | DEBUGP("Applying relocate section %u to %u\n", relsec, | |
9435 | sechdrs[relsec].sh_info); | |
9436 | @@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd | |
9437 | case R_X86_64_NONE: | |
9438 | break; | |
9439 | case R_X86_64_64: | |
9440 | + | |
9441 | +#ifdef CONFIG_PAX_KERNEXEC | |
9442 | + pax_open_kernel(cr0); | |
9443 | +#endif | |
9444 | + | |
9445 | *(u64 *)loc = val; | |
9446 | + | |
9447 | +#ifdef CONFIG_PAX_KERNEXEC | |
9448 | + pax_close_kernel(cr0); | |
9449 | +#endif | |
9450 | + | |
9451 | break; | |
9452 | case R_X86_64_32: | |
9453 | + | |
9454 | +#ifdef CONFIG_PAX_KERNEXEC | |
9455 | + pax_open_kernel(cr0); | |
9456 | +#endif | |
9457 | + | |
9458 | *(u32 *)loc = val; | |
9459 | + | |
9460 | +#ifdef CONFIG_PAX_KERNEXEC | |
9461 | + pax_close_kernel(cr0); | |
9462 | +#endif | |
9463 | + | |
9464 | if (val != *(u32 *)loc) | |
9465 | goto overflow; | |
9466 | break; | |
9467 | case R_X86_64_32S: | |
9468 | + | |
9469 | +#ifdef CONFIG_PAX_KERNEXEC | |
9470 | + pax_open_kernel(cr0); | |
9471 | +#endif | |
9472 | + | |
9473 | *(s32 *)loc = val; | |
9474 | + | |
9475 | +#ifdef CONFIG_PAX_KERNEXEC | |
9476 | + pax_close_kernel(cr0); | |
9477 | +#endif | |
9478 | + | |
9479 | if ((s64)val != *(s32 *)loc) | |
9480 | goto overflow; | |
9481 | break; | |
9482 | case R_X86_64_PC32: | |
9483 | val -= (u64)loc; | |
9484 | + | |
9485 | +#ifdef CONFIG_PAX_KERNEXEC | |
9486 | + pax_open_kernel(cr0); | |
9487 | +#endif | |
9488 | + | |
9489 | *(u32 *)loc = val; | |
9490 | + | |
9491 | +#ifdef CONFIG_PAX_KERNEXEC | |
9492 | + pax_close_kernel(cr0); | |
9493 | +#endif | |
9494 | + | |
9495 | #if 0 | |
9496 | if ((s64)val != *(s32 *)loc) | |
9497 | goto overflow; | |
de855c5d AM |
9498 | diff -urNp linux-2.6.29.6/arch/x86/kernel/paravirt.c linux-2.6.29.6/arch/x86/kernel/paravirt.c |
9499 | --- linux-2.6.29.6/arch/x86/kernel/paravirt.c 2009-07-02 19:41:20.000000000 -0400 | |
9500 | +++ linux-2.6.29.6/arch/x86/kernel/paravirt.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9501 | @@ -44,7 +44,7 @@ void _paravirt_nop(void) |
9502 | { | |
9503 | } | |
9504 | ||
9505 | -static void __init default_banner(void) | |
9506 | +static void default_banner(void) | |
9507 | { | |
9508 | printk(KERN_INFO "Booting paravirtualized kernel on %s\n", | |
9509 | pv_info.name); | |
9510 | @@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn | |
9511 | if (insn_len > len || start == NULL) | |
9512 | insn_len = len; | |
9513 | else | |
9514 | - memcpy(insnbuf, start, insn_len); | |
9515 | + memcpy(insnbuf, ktla_ktva(start), insn_len); | |
9516 | ||
9517 | return insn_len; | |
9518 | } | |
9519 | @@ -294,21 +294,21 @@ void arch_flush_lazy_cpu_mode(void) | |
9520 | preempt_enable(); | |
9521 | } | |
9522 | ||
9523 | -struct pv_info pv_info = { | |
9524 | +struct pv_info pv_info __read_only = { | |
9525 | .name = "bare hardware", | |
9526 | .paravirt_enabled = 0, | |
9527 | .kernel_rpl = 0, | |
9528 | .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */ | |
9529 | }; | |
9530 | ||
9531 | -struct pv_init_ops pv_init_ops = { | |
9532 | +struct pv_init_ops pv_init_ops __read_only = { | |
9533 | .patch = native_patch, | |
9534 | .banner = default_banner, | |
9535 | .arch_setup = paravirt_nop, | |
9536 | .memory_setup = machine_specific_memory_setup, | |
9537 | }; | |
9538 | ||
9539 | -struct pv_time_ops pv_time_ops = { | |
9540 | +struct pv_time_ops pv_time_ops __read_only = { | |
9541 | .time_init = hpet_time_init, | |
9542 | .get_wallclock = native_get_wallclock, | |
9543 | .set_wallclock = native_set_wallclock, | |
9544 | @@ -316,7 +316,7 @@ struct pv_time_ops pv_time_ops = { | |
9545 | .get_tsc_khz = native_calibrate_tsc, | |
9546 | }; | |
9547 | ||
9548 | -struct pv_irq_ops pv_irq_ops = { | |
9549 | +struct pv_irq_ops pv_irq_ops __read_only = { | |
9550 | .init_IRQ = native_init_IRQ, | |
9551 | .save_fl = native_save_fl, | |
9552 | .restore_fl = native_restore_fl, | |
9553 | @@ -329,7 +329,7 @@ struct pv_irq_ops pv_irq_ops = { | |
9554 | #endif | |
9555 | }; | |
9556 | ||
9557 | -struct pv_cpu_ops pv_cpu_ops = { | |
9558 | +struct pv_cpu_ops pv_cpu_ops __read_only = { | |
9559 | .cpuid = native_cpuid, | |
9560 | .get_debugreg = native_get_debugreg, | |
9561 | .set_debugreg = native_set_debugreg, | |
9562 | @@ -391,7 +391,7 @@ struct pv_cpu_ops pv_cpu_ops = { | |
9563 | }, | |
9564 | }; | |
9565 | ||
9566 | -struct pv_apic_ops pv_apic_ops = { | |
9567 | +struct pv_apic_ops pv_apic_ops __read_only = { | |
9568 | #ifdef CONFIG_X86_LOCAL_APIC | |
9569 | .setup_boot_clock = setup_boot_APIC_clock, | |
9570 | .setup_secondary_clock = setup_secondary_APIC_clock, | |
9571 | @@ -399,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = { | |
9572 | #endif | |
9573 | }; | |
9574 | ||
9575 | -struct pv_mmu_ops pv_mmu_ops = { | |
9576 | +struct pv_mmu_ops pv_mmu_ops __read_only = { | |
9577 | #ifndef CONFIG_X86_64 | |
9578 | .pagetable_setup_start = native_pagetable_setup_start, | |
9579 | .pagetable_setup_done = native_pagetable_setup_done, | |
de855c5d AM |
9580 | diff -urNp linux-2.6.29.6/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.29.6/arch/x86/kernel/paravirt-spinlocks.c |
9581 | --- linux-2.6.29.6/arch/x86/kernel/paravirt-spinlocks.c 2009-07-02 19:41:20.000000000 -0400 | |
9582 | +++ linux-2.6.29.6/arch/x86/kernel/paravirt-spinlocks.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9583 | @@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t * |
9584 | __raw_spin_lock(lock); | |
9585 | } | |
9586 | ||
9587 | -struct pv_lock_ops pv_lock_ops = { | |
9588 | +struct pv_lock_ops pv_lock_ops __read_only = { | |
9589 | #ifdef CONFIG_SMP | |
9590 | .spin_is_locked = __ticket_spin_is_locked, | |
9591 | .spin_is_contended = __ticket_spin_is_contended, | |
de855c5d AM |
9592 | diff -urNp linux-2.6.29.6/arch/x86/kernel/process_32.c linux-2.6.29.6/arch/x86/kernel/process_32.c |
9593 | --- linux-2.6.29.6/arch/x86/kernel/process_32.c 2009-07-02 19:41:20.000000000 -0400 | |
9594 | +++ linux-2.6.29.6/arch/x86/kernel/process_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9595 | @@ -66,8 +66,10 @@ asmlinkage void ret_from_fork(void) __as |
9596 | DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task; | |
9597 | EXPORT_PER_CPU_SYMBOL(current_task); | |
9598 | ||
9599 | +#ifdef CONFIG_SMP | |
9600 | DEFINE_PER_CPU(int, cpu_number); | |
9601 | EXPORT_PER_CPU_SYMBOL(cpu_number); | |
9602 | +#endif | |
9603 | ||
9604 | /* | |
9605 | * Return saved PC of a blocked thread. | |
9606 | @@ -75,6 +77,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number); | |
9607 | unsigned long thread_saved_pc(struct task_struct *tsk) | |
9608 | { | |
9609 | return ((unsigned long *)tsk->thread.sp)[3]; | |
9610 | +//XXX return tsk->thread.eip; | |
9611 | } | |
9612 | ||
9613 | #ifndef CONFIG_SMP | |
9614 | @@ -129,7 +132,7 @@ void __show_regs(struct pt_regs *regs, i | |
9615 | unsigned short ss, gs; | |
9616 | const char *board; | |
9617 | ||
9618 | - if (user_mode_vm(regs)) { | |
9619 | + if (user_mode(regs)) { | |
9620 | sp = regs->sp; | |
9621 | ss = regs->ss & 0xffff; | |
9622 | savesegment(gs, gs); | |
9623 | @@ -210,8 +213,8 @@ int kernel_thread(int (*fn)(void *), voi | |
9624 | regs.bx = (unsigned long) fn; | |
9625 | regs.dx = (unsigned long) arg; | |
9626 | ||
9627 | - regs.ds = __USER_DS; | |
9628 | - regs.es = __USER_DS; | |
9629 | + regs.ds = __KERNEL_DS; | |
9630 | + regs.es = __KERNEL_DS; | |
9631 | regs.fs = __KERNEL_PERCPU; | |
9632 | regs.orig_ax = -1; | |
9633 | regs.ip = (unsigned long) kernel_thread_helper; | |
9634 | @@ -233,7 +236,7 @@ void exit_thread(void) | |
9635 | struct task_struct *tsk = current; | |
9636 | struct thread_struct *t = &tsk->thread; | |
9637 | int cpu = get_cpu(); | |
9638 | - struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
9639 | + struct tss_struct *tss = init_tss + cpu; | |
9640 | ||
9641 | kfree(t->io_bitmap_ptr); | |
9642 | t->io_bitmap_ptr = NULL; | |
9643 | @@ -256,6 +259,7 @@ void flush_thread(void) | |
9644 | { | |
9645 | struct task_struct *tsk = current; | |
9646 | ||
9647 | + loadsegment(gs, 0); | |
9648 | tsk->thread.debugreg0 = 0; | |
9649 | tsk->thread.debugreg1 = 0; | |
9650 | tsk->thread.debugreg2 = 0; | |
9651 | @@ -295,7 +299,7 @@ int copy_thread(int nr, unsigned long cl | |
9652 | struct task_struct *tsk; | |
9653 | int err; | |
9654 | ||
9655 | - childregs = task_pt_regs(p); | |
9656 | + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8; | |
9657 | *childregs = *regs; | |
9658 | childregs->ax = 0; | |
9659 | childregs->sp = sp; | |
9660 | @@ -324,6 +328,7 @@ int copy_thread(int nr, unsigned long cl | |
9661 | * Set a new TLS for the child thread? | |
9662 | */ | |
9663 | if (clone_flags & CLONE_SETTLS) | |
9664 | +//XXX needs set_fs()? | |
9665 | err = do_set_thread_area(p, -1, | |
9666 | (struct user_desc __user *)childregs->si, 0); | |
9667 | ||
9668 | @@ -514,7 +519,7 @@ __switch_to(struct task_struct *prev_p, | |
9669 | struct thread_struct *prev = &prev_p->thread, | |
9670 | *next = &next_p->thread; | |
9671 | int cpu = smp_processor_id(); | |
9672 | - struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
9673 | + struct tss_struct *tss = init_tss + cpu; | |
9674 | ||
9675 | /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */ | |
9676 | ||
9677 | @@ -542,6 +547,11 @@ __switch_to(struct task_struct *prev_p, | |
9678 | */ | |
9679 | savesegment(gs, prev->gs); | |
9680 | ||
9681 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
9682 | + if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit)) | |
9683 | + __set_fs(task_thread_info(next_p)->addr_limit, cpu); | |
9684 | +#endif | |
9685 | + | |
9686 | /* | |
9687 | * Load the per-thread Thread-Local Storage descriptor. | |
9688 | */ | |
9689 | @@ -680,15 +690,27 @@ unsigned long get_wchan(struct task_stru | |
9690 | return 0; | |
9691 | } | |
9692 | ||
9693 | -unsigned long arch_align_stack(unsigned long sp) | |
9694 | +#ifdef CONFIG_PAX_RANDKSTACK | |
9695 | +asmlinkage void pax_randomize_kstack(void) | |
9696 | { | |
9697 | - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) | |
9698 | - sp -= get_random_int() % 8192; | |
9699 | - return sp & ~0xf; | |
9700 | -} | |
9701 | + struct thread_struct *thread = ¤t->thread; | |
9702 | + unsigned long time; | |
9703 | ||
9704 | -unsigned long arch_randomize_brk(struct mm_struct *mm) | |
9705 | -{ | |
9706 | - unsigned long range_end = mm->brk + 0x02000000; | |
9707 | - return randomize_range(mm->brk, range_end, 0) ? : mm->brk; | |
9708 | + if (!randomize_va_space) | |
9709 | + return; | |
9710 | + | |
9711 | + rdtscl(time); | |
9712 | + | |
9713 | + /* P4 seems to return a 0 LSB, ignore it */ | |
9714 | +#ifdef CONFIG_MPENTIUM4 | |
9715 | + time &= 0x1EUL; | |
9716 | + time <<= 2; | |
9717 | +#else | |
9718 | + time &= 0xFUL; | |
9719 | + time <<= 3; | |
9720 | +#endif | |
9721 | + | |
9722 | + thread->sp0 ^= time; | |
9723 | + load_sp0(init_tss + smp_processor_id(), thread); | |
9724 | } | |
9725 | +#endif | |
de855c5d AM |
9726 | diff -urNp linux-2.6.29.6/arch/x86/kernel/process_64.c linux-2.6.29.6/arch/x86/kernel/process_64.c |
9727 | --- linux-2.6.29.6/arch/x86/kernel/process_64.c 2009-07-02 19:41:20.000000000 -0400 | |
9728 | +++ linux-2.6.29.6/arch/x86/kernel/process_64.c 2009-07-09 22:13:39.000000000 -0400 | |
9729 | @@ -91,7 +91,7 @@ static void __exit_idle(void) | |
9730 | void exit_idle(void) | |
9731 | { | |
9732 | /* idle loop has pid 0 */ | |
9733 | - if (current->pid) | |
9734 | + if (task_pid_nr(current)) | |
9735 | return; | |
9736 | __exit_idle(); | |
9737 | } | |
2380c486 JR |
9738 | @@ -112,6 +112,8 @@ static inline void play_dead(void) |
9739 | void cpu_idle(void) | |
9740 | { | |
9741 | current_thread_info()->status |= TS_POLLING; | |
9742 | + current->stack_canary = pax_get_random_long(); | |
9743 | + write_pda(stack_canary, current->stack_canary); | |
9744 | /* endless idle loop with no priority at all */ | |
9745 | while (1) { | |
9746 | tick_nohz_stop_sched_tick(1); | |
de855c5d AM |
9747 | @@ -160,7 +162,7 @@ void __show_regs(struct pt_regs *regs, i |
9748 | if (!board) | |
9749 | board = ""; | |
9750 | printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n", | |
9751 | - current->pid, current->comm, print_tainted(), | |
9752 | + task_pid_nr(current), current->comm, print_tainted(), | |
9753 | init_utsname()->release, | |
9754 | (int)strcspn(init_utsname()->version, " "), | |
9755 | init_utsname()->version, board); | |
2380c486 JR |
9756 | @@ -230,7 +232,7 @@ void exit_thread(void) |
9757 | struct thread_struct *t = &me->thread; | |
9758 | ||
9759 | if (me->thread.io_bitmap_ptr) { | |
9760 | - struct tss_struct *tss = &per_cpu(init_tss, get_cpu()); | |
9761 | + struct tss_struct *tss = init_tss + get_cpu(); | |
9762 | ||
9763 | kfree(t->io_bitmap_ptr); | |
9764 | t->io_bitmap_ptr = NULL; | |
9765 | @@ -537,7 +539,7 @@ __switch_to(struct task_struct *prev_p, | |
9766 | struct thread_struct *prev = &prev_p->thread; | |
9767 | struct thread_struct *next = &next_p->thread; | |
9768 | int cpu = smp_processor_id(); | |
9769 | - struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
9770 | + struct tss_struct *tss = init_tss + cpu; | |
9771 | unsigned fsindex, gsindex; | |
9772 | ||
9773 | /* we're going to use this soon, after a few expensive things */ | |
9774 | @@ -626,7 +628,6 @@ __switch_to(struct task_struct *prev_p, | |
9775 | (unsigned long)task_stack_page(next_p) + | |
9776 | THREAD_SIZE - PDA_STACKOFFSET); | |
9777 | #ifdef CONFIG_CC_STACKPROTECTOR | |
9778 | - write_pda(stack_canary, next_p->stack_canary); | |
9779 | /* | |
9780 | * Build time only check to make sure the stack_canary is at | |
9781 | * offset 40 in the pda; this is a gcc ABI requirement | |
9782 | @@ -725,12 +726,11 @@ unsigned long get_wchan(struct task_stru | |
9783 | if (!p || p == current || p->state == TASK_RUNNING) | |
9784 | return 0; | |
9785 | stack = (unsigned long)task_stack_page(p); | |
9786 | - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE) | |
9787 | + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64)) | |
9788 | return 0; | |
9789 | fp = *(u64 *)(p->thread.sp); | |
9790 | do { | |
9791 | - if (fp < (unsigned long)stack || | |
9792 | - fp >= (unsigned long)stack+THREAD_SIZE) | |
9793 | + if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64)) | |
9794 | return 0; | |
9795 | ip = *(u64 *)(fp+8); | |
9796 | if (!in_sched_functions(ip)) | |
9797 | @@ -839,16 +839,3 @@ long sys_arch_prctl(int code, unsigned l | |
9798 | { | |
9799 | return do_arch_prctl(current, code, addr); | |
9800 | } | |
9801 | - | |
9802 | -unsigned long arch_align_stack(unsigned long sp) | |
9803 | -{ | |
9804 | - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) | |
9805 | - sp -= get_random_int() % 8192; | |
9806 | - return sp & ~0xf; | |
9807 | -} | |
9808 | - | |
9809 | -unsigned long arch_randomize_brk(struct mm_struct *mm) | |
9810 | -{ | |
9811 | - unsigned long range_end = mm->brk + 0x02000000; | |
9812 | - return randomize_range(mm->brk, range_end, 0) ? : mm->brk; | |
9813 | -} | |
de855c5d AM |
9814 | diff -urNp linux-2.6.29.6/arch/x86/kernel/ptrace.c linux-2.6.29.6/arch/x86/kernel/ptrace.c |
9815 | --- linux-2.6.29.6/arch/x86/kernel/ptrace.c 2009-07-02 19:41:20.000000000 -0400 | |
9816 | +++ linux-2.6.29.6/arch/x86/kernel/ptrace.c 2009-07-09 22:13:39.000000000 -0400 | |
9817 | @@ -1377,7 +1377,7 @@ void send_sigtrap(struct task_struct *ts | |
2380c486 JR |
9818 | info.si_code = si_code; |
9819 | ||
9820 | /* User-mode ip? */ | |
9821 | - info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL; | |
9822 | + info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL; | |
9823 | ||
9824 | /* Send us the fake SIGTRAP */ | |
9825 | force_sig_info(SIGTRAP, &info, tsk); | |
de855c5d AM |
9826 | diff -urNp linux-2.6.29.6/arch/x86/kernel/reboot.c linux-2.6.29.6/arch/x86/kernel/reboot.c |
9827 | --- linux-2.6.29.6/arch/x86/kernel/reboot.c 2009-07-02 19:41:20.000000000 -0400 | |
9828 | +++ linux-2.6.29.6/arch/x86/kernel/reboot.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9829 | @@ -32,7 +32,7 @@ void (*pm_power_off)(void); |
9830 | EXPORT_SYMBOL(pm_power_off); | |
9831 | ||
9832 | static const struct desc_ptr no_idt = {}; | |
9833 | -static int reboot_mode; | |
9834 | +static unsigned short reboot_mode; | |
9835 | enum reboot_type reboot_type = BOOT_KBD; | |
9836 | int reboot_force; | |
9837 | ||
de855c5d | 9838 | @@ -234,7 +234,7 @@ static struct dmi_system_id __initdata r |
2380c486 JR |
9839 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"), |
9840 | }, | |
9841 | }, | |
9842 | - { } | |
9843 | + { NULL, NULL, {{0, {0}}}, NULL} | |
9844 | }; | |
9845 | ||
9846 | static int __init reboot_init(void) | |
de855c5d | 9847 | @@ -250,12 +250,12 @@ core_initcall(reboot_init); |
2380c486 JR |
9848 | controller to pulse the CPU reset line, which is more thorough, but |
9849 | doesn't work with at least one type of 486 motherboard. It is easy | |
9850 | to stop this code working; hence the copious comments. */ | |
9851 | -static const unsigned long long | |
9852 | -real_mode_gdt_entries [3] = | |
9853 | +static struct desc_struct | |
9854 | +real_mode_gdt_entries [3] __read_only = | |
9855 | { | |
9856 | - 0x0000000000000000ULL, /* Null descriptor */ | |
9857 | - 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */ | |
9858 | - 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */ | |
9859 | + {{{0x00000000, 0x00000000}}}, /* Null descriptor */ | |
9860 | + {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */ | |
9861 | + {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */ | |
9862 | }; | |
9863 | ||
9864 | static const struct desc_ptr | |
de855c5d | 9865 | @@ -304,7 +304,7 @@ static const unsigned char jump_to_bios |
2380c486 JR |
9866 | * specified by the code and length parameters. |
9867 | * We assume that length will aways be less that 100! | |
9868 | */ | |
9869 | -void machine_real_restart(const unsigned char *code, int length) | |
9870 | +void machine_real_restart(const unsigned char *code, unsigned int length) | |
9871 | { | |
9872 | local_irq_disable(); | |
9873 | ||
de855c5d | 9874 | @@ -324,8 +324,8 @@ void machine_real_restart(const unsigned |
2380c486 JR |
9875 | /* Remap the kernel at virtual address zero, as well as offset zero |
9876 | from the kernel segment. This assumes the kernel segment starts at | |
9877 | virtual address PAGE_OFFSET. */ | |
9878 | - memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY, | |
9879 | - sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS); | |
9880 | + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY, | |
9881 | + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY)); | |
9882 | ||
9883 | /* | |
9884 | * Use `swapper_pg_dir' as our page directory. | |
de855c5d | 9885 | @@ -337,16 +337,15 @@ void machine_real_restart(const unsigned |
2380c486 JR |
9886 | boot)". This seems like a fairly standard thing that gets set by |
9887 | REBOOT.COM programs, and the previous reset routine did this | |
9888 | too. */ | |
9889 | - *((unsigned short *)0x472) = reboot_mode; | |
9890 | + *(unsigned short *)(__va(0x472)) = reboot_mode; | |
9891 | ||
9892 | /* For the switch to real mode, copy some code to low memory. It has | |
9893 | to be in the first 64k because it is running in 16-bit mode, and it | |
9894 | has to have the same physical and virtual address, because it turns | |
9895 | off paging. Copy it near the end of the first page, out of the way | |
9896 | of BIOS variables. */ | |
9897 | - memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100), | |
9898 | - real_mode_switch, sizeof (real_mode_switch)); | |
9899 | - memcpy((void *)(0x1000 - 100), code, length); | |
9900 | + memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch)); | |
9901 | + memcpy(__va(0x1000 - 100), code, length); | |
9902 | ||
9903 | /* Set up the IDT for real mode. */ | |
9904 | load_idt(&real_mode_idt); | |
de855c5d AM |
9905 | diff -urNp linux-2.6.29.6/arch/x86/kernel/setup.c linux-2.6.29.6/arch/x86/kernel/setup.c |
9906 | --- linux-2.6.29.6/arch/x86/kernel/setup.c 2009-07-02 19:41:20.000000000 -0400 | |
9907 | +++ linux-2.6.29.6/arch/x86/kernel/setup.c 2009-07-09 22:13:39.000000000 -0400 | |
9908 | @@ -703,8 +703,8 @@ void __init setup_arch(char **cmdline_p) | |
2380c486 JR |
9909 | |
9910 | if (!boot_params.hdr.root_flags) | |
9911 | root_mountflags &= ~MS_RDONLY; | |
9912 | - init_mm.start_code = (unsigned long) _text; | |
9913 | - init_mm.end_code = (unsigned long) _etext; | |
9914 | + init_mm.start_code = ktla_ktva((unsigned long) _text); | |
9915 | + init_mm.end_code = ktla_ktva((unsigned long) _etext); | |
9916 | init_mm.end_data = (unsigned long) _edata; | |
9917 | #ifdef CONFIG_X86_32 | |
9918 | init_mm.brk = init_pg_tables_end + PAGE_OFFSET; | |
de855c5d | 9919 | @@ -712,9 +712,9 @@ void __init setup_arch(char **cmdline_p) |
2380c486 JR |
9920 | init_mm.brk = (unsigned long) &_end; |
9921 | #endif | |
9922 | ||
9923 | - code_resource.start = virt_to_phys(_text); | |
9924 | - code_resource.end = virt_to_phys(_etext)-1; | |
9925 | - data_resource.start = virt_to_phys(_etext); | |
9926 | + code_resource.start = virt_to_phys(ktla_ktva(_text)); | |
9927 | + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1; | |
9928 | + data_resource.start = virt_to_phys(_data); | |
9929 | data_resource.end = virt_to_phys(_edata)-1; | |
9930 | bss_resource.start = virt_to_phys(&__bss_start); | |
9931 | bss_resource.end = virt_to_phys(&__bss_stop)-1; | |
de855c5d AM |
9932 | diff -urNp linux-2.6.29.6/arch/x86/kernel/setup_percpu.c linux-2.6.29.6/arch/x86/kernel/setup_percpu.c |
9933 | --- linux-2.6.29.6/arch/x86/kernel/setup_percpu.c 2009-07-02 19:41:20.000000000 -0400 | |
9934 | +++ linux-2.6.29.6/arch/x86/kernel/setup_percpu.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9935 | @@ -197,7 +197,11 @@ void __init setup_per_cpu_areas(void) |
9936 | cpu, node, __pa(ptr)); | |
9937 | } | |
9938 | #endif | |
9939 | +#ifdef CONFIG_X86_32 | |
9940 | + __per_cpu_offset[cpu] = ptr - __per_cpu_start; | |
9941 | +#else | |
9942 | per_cpu_offset(cpu) = ptr - __per_cpu_start; | |
9943 | +#endif | |
9944 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); | |
9945 | } | |
9946 | ||
de855c5d AM |
9947 | diff -urNp linux-2.6.29.6/arch/x86/kernel/signal.c linux-2.6.29.6/arch/x86/kernel/signal.c |
9948 | --- linux-2.6.29.6/arch/x86/kernel/signal.c 2009-07-02 19:41:20.000000000 -0400 | |
9949 | +++ linux-2.6.29.6/arch/x86/kernel/signal.c 2009-07-09 22:13:39.000000000 -0400 | |
9950 | @@ -255,7 +255,7 @@ get_sigframe(struct k_sigaction *ka, str | |
9951 | * Align the stack pointer according to the i386 ABI, | |
9952 | * i.e. so that on function entry ((sp + 4) & 15) == 0. | |
9953 | */ | |
9954 | - sp = ((sp + 4) & -16ul) - 4; | |
9955 | + sp = ((sp - 12) & -16ul) - 4; | |
9956 | ||
9957 | return (void __user *) sp; | |
9958 | } | |
2380c486 JR |
9959 | @@ -287,9 +287,9 @@ __setup_frame(int sig, struct k_sigactio |
9960 | } | |
9961 | ||
9962 | if (current->mm->context.vdso) | |
9963 | - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn); | |
9964 | + restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn); | |
9965 | else | |
9966 | - restorer = &frame->retcode; | |
9967 | + restorer = (void __user *)&frame->retcode; | |
9968 | if (ka->sa.sa_flags & SA_RESTORER) | |
9969 | restorer = ka->sa.sa_restorer; | |
9970 | ||
9971 | @@ -360,7 +360,7 @@ static int __setup_rt_frame(int sig, str | |
9972 | return -EFAULT; | |
9973 | ||
9974 | /* Set up to return from userspace. */ | |
9975 | - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); | |
9976 | + restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); | |
9977 | if (ka->sa.sa_flags & SA_RESTORER) | |
9978 | restorer = ka->sa.sa_restorer; | |
9979 | err |= __put_user(restorer, &frame->pretcode); | |
9980 | @@ -811,7 +811,7 @@ static void do_signal(struct pt_regs *re | |
9981 | * X86_32: vm86 regs switched out by assembly code before reaching | |
9982 | * here, so testing against kernel CS suffices. | |
9983 | */ | |
9984 | - if (!user_mode(regs)) | |
9985 | + if (!user_mode_novm(regs)) | |
9986 | return; | |
9987 | ||
9988 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) | |
de855c5d AM |
9989 | diff -urNp linux-2.6.29.6/arch/x86/kernel/smpboot.c linux-2.6.29.6/arch/x86/kernel/smpboot.c |
9990 | --- linux-2.6.29.6/arch/x86/kernel/smpboot.c 2009-07-02 19:41:20.000000000 -0400 | |
9991 | +++ linux-2.6.29.6/arch/x86/kernel/smpboot.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
9992 | @@ -806,6 +806,11 @@ static int __cpuinit do_boot_cpu(int api |
9993 | .cpu = cpu, | |
9994 | .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done), | |
9995 | }; | |
9996 | + | |
9997 | +#ifdef CONFIG_PAX_KERNEXEC | |
9998 | + unsigned long cr0; | |
9999 | +#endif | |
10000 | + | |
10001 | INIT_WORK(&c_idle.work, do_fork_idle); | |
10002 | ||
10003 | #ifdef CONFIG_X86_64 | |
10004 | @@ -856,7 +861,17 @@ do_rest: | |
10005 | cpu_pda(cpu)->pcurrent = c_idle.idle; | |
10006 | clear_tsk_thread_flag(c_idle.idle, TIF_FORK); | |
10007 | #endif | |
10008 | + | |
10009 | +#ifdef CONFIG_PAX_KERNEXEC | |
10010 | + pax_open_kernel(cr0); | |
10011 | +#endif | |
10012 | + | |
10013 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); | |
10014 | + | |
10015 | +#ifdef CONFIG_PAX_KERNEXEC | |
10016 | + pax_close_kernel(cr0); | |
10017 | +#endif | |
10018 | + | |
10019 | initial_code = (unsigned long)start_secondary; | |
10020 | stack_start.sp = (void *) c_idle.idle->thread.sp; | |
10021 | ||
de855c5d AM |
10022 | diff -urNp linux-2.6.29.6/arch/x86/kernel/smpcommon.c linux-2.6.29.6/arch/x86/kernel/smpcommon.c |
10023 | --- linux-2.6.29.6/arch/x86/kernel/smpcommon.c 2009-07-02 19:41:20.000000000 -0400 | |
10024 | +++ linux-2.6.29.6/arch/x86/kernel/smpcommon.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10025 | @@ -3,9 +3,10 @@ |
10026 | */ | |
10027 | #include <linux/module.h> | |
10028 | #include <asm/smp.h> | |
10029 | +#include <asm/sections.h> | |
10030 | ||
10031 | #ifdef CONFIG_X86_32 | |
10032 | -DEFINE_PER_CPU(unsigned long, this_cpu_off); | |
10033 | +DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start; | |
10034 | EXPORT_PER_CPU_SYMBOL(this_cpu_off); | |
10035 | ||
10036 | /* | |
10037 | @@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off); | |
10038 | */ | |
10039 | __cpuinit void init_gdt(int cpu) | |
10040 | { | |
10041 | - struct desc_struct gdt; | |
10042 | + struct desc_struct d, *gdt = get_cpu_gdt_table(cpu); | |
10043 | + unsigned long base, limit; | |
10044 | ||
10045 | - pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF, | |
10046 | - 0x2 | DESCTYPE_S, 0x8); | |
10047 | - gdt.s = 1; | |
10048 | + base = per_cpu_offset(cpu); | |
10049 | + limit = PERCPU_ENOUGH_ROOM - 1; | |
10050 | + if (limit < 64*1024) | |
10051 | + pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4); | |
10052 | + else | |
10053 | + pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC); | |
10054 | ||
10055 | - write_gdt_entry(get_cpu_gdt_table(cpu), | |
10056 | - GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S); | |
10057 | + write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S); | |
10058 | ||
10059 | - per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu]; | |
10060 | + per_cpu(this_cpu_off, cpu) = base; | |
10061 | per_cpu(cpu_number, cpu) = cpu; | |
10062 | } | |
10063 | #endif | |
de855c5d AM |
10064 | diff -urNp linux-2.6.29.6/arch/x86/kernel/step.c linux-2.6.29.6/arch/x86/kernel/step.c |
10065 | --- linux-2.6.29.6/arch/x86/kernel/step.c 2009-07-02 19:41:20.000000000 -0400 | |
10066 | +++ linux-2.6.29.6/arch/x86/kernel/step.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10067 | @@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc |
10068 | * and APM bios ones we just ignore here. | |
10069 | */ | |
10070 | if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) { | |
10071 | - u32 *desc; | |
10072 | + struct desc_struct *desc; | |
10073 | unsigned long base; | |
10074 | ||
10075 | - seg &= ~7UL; | |
10076 | + seg >>= 3; | |
10077 | ||
10078 | mutex_lock(&child->mm->context.lock); | |
10079 | - if (unlikely((seg >> 3) >= child->mm->context.size)) | |
10080 | - addr = -1L; /* bogus selector, access would fault */ | |
10081 | + if (unlikely(seg >= child->mm->context.size)) | |
10082 | + addr = -EINVAL; | |
10083 | else { | |
10084 | - desc = child->mm->context.ldt + seg; | |
10085 | - base = ((desc[0] >> 16) | | |
10086 | - ((desc[1] & 0xff) << 16) | | |
10087 | - (desc[1] & 0xff000000)); | |
10088 | + desc = &child->mm->context.ldt[seg]; | |
10089 | + base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000); | |
10090 | ||
10091 | /* 16-bit code segment? */ | |
10092 | - if (!((desc[1] >> 22) & 1)) | |
10093 | + if (!((desc->b >> 22) & 1)) | |
10094 | addr &= 0xffff; | |
10095 | addr += base; | |
10096 | } | |
10097 | @@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t | |
10098 | unsigned char opcode[15]; | |
10099 | unsigned long addr = convert_ip_to_linear(child, regs); | |
10100 | ||
10101 | + if (addr == -EINVAL) | |
10102 | + return 0; | |
10103 | + | |
10104 | copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0); | |
10105 | for (i = 0; i < copied; i++) { | |
10106 | switch (opcode[i]) { | |
10107 | @@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t | |
10108 | ||
10109 | #ifdef CONFIG_X86_64 | |
10110 | case 0x40 ... 0x4f: | |
10111 | - if (regs->cs != __USER_CS) | |
10112 | + if ((regs->cs & 0xffff) != __USER_CS) | |
10113 | /* 32-bit mode: register increment */ | |
10114 | return 0; | |
10115 | /* 64-bit mode: REX prefix */ | |
de855c5d AM |
10116 | diff -urNp linux-2.6.29.6/arch/x86/kernel/syscall_table_32.S linux-2.6.29.6/arch/x86/kernel/syscall_table_32.S |
10117 | --- linux-2.6.29.6/arch/x86/kernel/syscall_table_32.S 2009-07-02 19:41:20.000000000 -0400 | |
10118 | +++ linux-2.6.29.6/arch/x86/kernel/syscall_table_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10119 | @@ -1,3 +1,4 @@ |
10120 | +.section .rodata,"a",@progbits | |
10121 | ENTRY(sys_call_table) | |
10122 | .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */ | |
10123 | .long sys_exit | |
de855c5d AM |
10124 | diff -urNp linux-2.6.29.6/arch/x86/kernel/sys_i386_32.c linux-2.6.29.6/arch/x86/kernel/sys_i386_32.c |
10125 | --- linux-2.6.29.6/arch/x86/kernel/sys_i386_32.c 2009-07-02 19:41:20.000000000 -0400 | |
10126 | +++ linux-2.6.29.6/arch/x86/kernel/sys_i386_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10127 | @@ -24,6 +24,21 @@ |
10128 | ||
10129 | #include <asm/syscalls.h> | |
10130 | ||
10131 | +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags) | |
10132 | +{ | |
10133 | + unsigned long pax_task_size = TASK_SIZE; | |
10134 | + | |
10135 | +#ifdef CONFIG_PAX_SEGMEXEC | |
10136 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) | |
10137 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
10138 | +#endif | |
10139 | + | |
10140 | + if (len > pax_task_size || addr > pax_task_size - len) | |
10141 | + return -EINVAL; | |
10142 | + | |
10143 | + return 0; | |
10144 | +} | |
10145 | + | |
10146 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | |
10147 | unsigned long prot, unsigned long flags, | |
10148 | unsigned long fd, unsigned long pgoff) | |
10149 | @@ -83,6 +98,205 @@ out: | |
10150 | return err; | |
10151 | } | |
10152 | ||
10153 | +unsigned long | |
10154 | +arch_get_unmapped_area(struct file *filp, unsigned long addr, | |
10155 | + unsigned long len, unsigned long pgoff, unsigned long flags) | |
10156 | +{ | |
10157 | + struct mm_struct *mm = current->mm; | |
10158 | + struct vm_area_struct *vma; | |
10159 | + unsigned long start_addr, pax_task_size = TASK_SIZE; | |
10160 | + | |
10161 | +#ifdef CONFIG_PAX_SEGMEXEC | |
10162 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
10163 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
10164 | +#endif | |
10165 | + | |
10166 | + if (len > pax_task_size) | |
10167 | + return -ENOMEM; | |
10168 | + | |
10169 | + if (flags & MAP_FIXED) | |
10170 | + return addr; | |
10171 | + | |
10172 | +#ifdef CONFIG_PAX_RANDMMAP | |
10173 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
10174 | +#endif | |
10175 | + | |
10176 | + if (addr) { | |
10177 | + addr = PAGE_ALIGN(addr); | |
10178 | + vma = find_vma(mm, addr); | |
10179 | + if (pax_task_size - len >= addr && | |
10180 | + (!vma || addr + len <= vma->vm_start)) | |
10181 | + return addr; | |
10182 | + } | |
10183 | + if (len > mm->cached_hole_size) { | |
10184 | + start_addr = addr = mm->free_area_cache; | |
10185 | + } else { | |
10186 | + start_addr = addr = mm->mmap_base; | |
10187 | + mm->cached_hole_size = 0; | |
10188 | + } | |
10189 | + | |
10190 | +#ifdef CONFIG_PAX_PAGEEXEC | |
10191 | + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) { | |
10192 | + start_addr = 0x00110000UL; | |
10193 | + | |
10194 | +#ifdef CONFIG_PAX_RANDMMAP | |
10195 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
10196 | + start_addr += mm->delta_mmap & 0x03FFF000UL; | |
10197 | +#endif | |
10198 | + | |
10199 | + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base) | |
10200 | + start_addr = addr = mm->mmap_base; | |
10201 | + else | |
10202 | + addr = start_addr; | |
10203 | + } | |
10204 | +#endif | |
10205 | + | |
10206 | +full_search: | |
10207 | + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) { | |
10208 | + /* At this point: (!vma || addr < vma->vm_end). */ | |
10209 | + if (pax_task_size - len < addr) { | |
10210 | + /* | |
10211 | + * Start a new search - just in case we missed | |
10212 | + * some holes. | |
10213 | + */ | |
10214 | + if (start_addr != mm->mmap_base) { | |
10215 | + start_addr = addr = mm->mmap_base; | |
10216 | + mm->cached_hole_size = 0; | |
10217 | + goto full_search; | |
10218 | + } | |
10219 | + return -ENOMEM; | |
10220 | + } | |
10221 | + if (!vma || addr + len <= vma->vm_start) { | |
10222 | + /* | |
10223 | + * Remember the place where we stopped the search: | |
10224 | + */ | |
10225 | + mm->free_area_cache = addr + len; | |
10226 | + return addr; | |
10227 | + } | |
10228 | + if (addr + mm->cached_hole_size < vma->vm_start) | |
10229 | + mm->cached_hole_size = vma->vm_start - addr; | |
10230 | + addr = vma->vm_end; | |
10231 | + if (mm->start_brk <= addr && addr < mm->mmap_base) { | |
10232 | + start_addr = addr = mm->mmap_base; | |
10233 | + mm->cached_hole_size = 0; | |
10234 | + goto full_search; | |
10235 | + } | |
10236 | + } | |
10237 | +} | |
10238 | + | |
10239 | +unsigned long | |
10240 | +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, | |
10241 | + const unsigned long len, const unsigned long pgoff, | |
10242 | + const unsigned long flags) | |
10243 | +{ | |
10244 | + struct vm_area_struct *vma; | |
10245 | + struct mm_struct *mm = current->mm; | |
10246 | + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE; | |
10247 | + | |
10248 | +#ifdef CONFIG_PAX_SEGMEXEC | |
10249 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
10250 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
10251 | +#endif | |
10252 | + | |
10253 | + /* requested length too big for entire address space */ | |
10254 | + if (len > pax_task_size) | |
10255 | + return -ENOMEM; | |
10256 | + | |
10257 | + if (flags & MAP_FIXED) | |
10258 | + return addr; | |
10259 | + | |
10260 | +#ifdef CONFIG_PAX_PAGEEXEC | |
10261 | + if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) | |
10262 | + goto bottomup; | |
10263 | +#endif | |
10264 | + | |
10265 | +#ifdef CONFIG_PAX_RANDMMAP | |
10266 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
10267 | +#endif | |
10268 | + | |
10269 | + /* requesting a specific address */ | |
10270 | + if (addr) { | |
10271 | + addr = PAGE_ALIGN(addr); | |
10272 | + vma = find_vma(mm, addr); | |
10273 | + if (pax_task_size - len >= addr && | |
10274 | + (!vma || addr + len <= vma->vm_start)) | |
10275 | + return addr; | |
10276 | + } | |
10277 | + | |
10278 | + /* check if free_area_cache is useful for us */ | |
10279 | + if (len <= mm->cached_hole_size) { | |
10280 | + mm->cached_hole_size = 0; | |
10281 | + mm->free_area_cache = mm->mmap_base; | |
10282 | + } | |
10283 | + | |
10284 | + /* either no address requested or can't fit in requested address hole */ | |
10285 | + addr = mm->free_area_cache; | |
10286 | + | |
10287 | + /* make sure it can fit in the remaining address space */ | |
10288 | + if (addr > len) { | |
10289 | + vma = find_vma(mm, addr-len); | |
10290 | + if (!vma || addr <= vma->vm_start) | |
10291 | + /* remember the address as a hint for next time */ | |
10292 | + return (mm->free_area_cache = addr-len); | |
10293 | + } | |
10294 | + | |
10295 | + if (mm->mmap_base < len) | |
10296 | + goto bottomup; | |
10297 | + | |
10298 | + addr = mm->mmap_base-len; | |
10299 | + | |
10300 | + do { | |
10301 | + /* | |
10302 | + * Lookup failure means no vma is above this address, | |
10303 | + * else if new region fits below vma->vm_start, | |
10304 | + * return with success: | |
10305 | + */ | |
10306 | + vma = find_vma(mm, addr); | |
10307 | + if (!vma || addr+len <= vma->vm_start) | |
10308 | + /* remember the address as a hint for next time */ | |
10309 | + return (mm->free_area_cache = addr); | |
10310 | + | |
10311 | + /* remember the largest hole we saw so far */ | |
10312 | + if (addr + mm->cached_hole_size < vma->vm_start) | |
10313 | + mm->cached_hole_size = vma->vm_start - addr; | |
10314 | + | |
10315 | + /* try just below the current vma->vm_start */ | |
10316 | + addr = vma->vm_start-len; | |
10317 | + } while (len < vma->vm_start); | |
10318 | + | |
10319 | +bottomup: | |
10320 | + /* | |
10321 | + * A failed mmap() very likely causes application failure, | |
10322 | + * so fall back to the bottom-up function here. This scenario | |
10323 | + * can happen with large stack limits and large mmap() | |
10324 | + * allocations. | |
10325 | + */ | |
10326 | + | |
10327 | +#ifdef CONFIG_PAX_SEGMEXEC | |
10328 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
10329 | + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE; | |
10330 | + else | |
10331 | +#endif | |
10332 | + | |
10333 | + mm->mmap_base = TASK_UNMAPPED_BASE; | |
10334 | + | |
10335 | +#ifdef CONFIG_PAX_RANDMMAP | |
10336 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
10337 | + mm->mmap_base += mm->delta_mmap; | |
10338 | +#endif | |
10339 | + | |
10340 | + mm->free_area_cache = mm->mmap_base; | |
10341 | + mm->cached_hole_size = ~0UL; | |
10342 | + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags); | |
10343 | + /* | |
10344 | + * Restore the topdown base: | |
10345 | + */ | |
10346 | + mm->mmap_base = base; | |
10347 | + mm->free_area_cache = base; | |
10348 | + mm->cached_hole_size = ~0UL; | |
10349 | + | |
10350 | + return addr; | |
10351 | +} | |
10352 | ||
10353 | struct sel_arg_struct { | |
10354 | unsigned long n; | |
de855c5d AM |
10355 | diff -urNp linux-2.6.29.6/arch/x86/kernel/sys_x86_64.c linux-2.6.29.6/arch/x86/kernel/sys_x86_64.c |
10356 | --- linux-2.6.29.6/arch/x86/kernel/sys_x86_64.c 2009-07-02 19:41:20.000000000 -0400 | |
10357 | +++ linux-2.6.29.6/arch/x86/kernel/sys_x86_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10358 | @@ -47,8 +47,8 @@ out: |
10359 | return error; | |
10360 | } | |
10361 | ||
10362 | -static void find_start_end(unsigned long flags, unsigned long *begin, | |
10363 | - unsigned long *end) | |
10364 | +static void find_start_end(struct mm_struct *mm, unsigned long flags, | |
10365 | + unsigned long *begin, unsigned long *end) | |
10366 | { | |
10367 | if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) { | |
10368 | unsigned long new_begin; | |
10369 | @@ -67,7 +67,7 @@ static void find_start_end(unsigned long | |
10370 | *begin = new_begin; | |
10371 | } | |
10372 | } else { | |
10373 | - *begin = TASK_UNMAPPED_BASE; | |
10374 | + *begin = mm->mmap_base; | |
10375 | *end = TASK_SIZE; | |
10376 | } | |
10377 | } | |
10378 | @@ -84,11 +84,15 @@ arch_get_unmapped_area(struct file *filp | |
10379 | if (flags & MAP_FIXED) | |
10380 | return addr; | |
10381 | ||
10382 | - find_start_end(flags, &begin, &end); | |
10383 | + find_start_end(mm, flags, &begin, &end); | |
10384 | ||
10385 | if (len > end) | |
10386 | return -ENOMEM; | |
10387 | ||
10388 | +#ifdef CONFIG_PAX_RANDMMAP | |
10389 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
10390 | +#endif | |
10391 | + | |
10392 | if (addr) { | |
10393 | addr = PAGE_ALIGN(addr); | |
10394 | vma = find_vma(mm, addr); | |
10395 | @@ -143,7 +147,7 @@ arch_get_unmapped_area_topdown(struct fi | |
10396 | { | |
10397 | struct vm_area_struct *vma; | |
10398 | struct mm_struct *mm = current->mm; | |
10399 | - unsigned long addr = addr0; | |
10400 | + unsigned long base = mm->mmap_base, addr = addr0; | |
10401 | ||
10402 | /* requested length too big for entire address space */ | |
10403 | if (len > TASK_SIZE) | |
10404 | @@ -156,6 +160,10 @@ arch_get_unmapped_area_topdown(struct fi | |
10405 | if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) | |
10406 | goto bottomup; | |
10407 | ||
10408 | +#ifdef CONFIG_PAX_RANDMMAP | |
10409 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
10410 | +#endif | |
10411 | + | |
10412 | /* requesting a specific address */ | |
10413 | if (addr) { | |
10414 | addr = PAGE_ALIGN(addr); | |
10415 | @@ -213,13 +221,21 @@ bottomup: | |
10416 | * can happen with large stack limits and large mmap() | |
10417 | * allocations. | |
10418 | */ | |
10419 | + mm->mmap_base = TASK_UNMAPPED_BASE; | |
10420 | + | |
10421 | +#ifdef CONFIG_PAX_RANDMMAP | |
10422 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
10423 | + mm->mmap_base += mm->delta_mmap; | |
10424 | +#endif | |
10425 | + | |
10426 | + mm->free_area_cache = mm->mmap_base; | |
10427 | mm->cached_hole_size = ~0UL; | |
10428 | - mm->free_area_cache = TASK_UNMAPPED_BASE; | |
10429 | addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags); | |
10430 | /* | |
10431 | * Restore the topdown base: | |
10432 | */ | |
10433 | - mm->free_area_cache = mm->mmap_base; | |
10434 | + mm->mmap_base = base; | |
10435 | + mm->free_area_cache = base; | |
10436 | mm->cached_hole_size = ~0UL; | |
10437 | ||
10438 | return addr; | |
de855c5d AM |
10439 | diff -urNp linux-2.6.29.6/arch/x86/kernel/time_32.c linux-2.6.29.6/arch/x86/kernel/time_32.c |
10440 | --- linux-2.6.29.6/arch/x86/kernel/time_32.c 2009-07-02 19:41:20.000000000 -0400 | |
10441 | +++ linux-2.6.29.6/arch/x86/kernel/time_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10442 | @@ -47,22 +47,32 @@ unsigned long profile_pc(struct pt_regs |
10443 | unsigned long pc = instruction_pointer(regs); | |
10444 | ||
10445 | #ifdef CONFIG_SMP | |
10446 | - if (!user_mode_vm(regs) && in_lock_functions(pc)) { | |
10447 | + if (!user_mode(regs) && in_lock_functions(pc)) { | |
10448 | #ifdef CONFIG_FRAME_POINTER | |
10449 | - return *(unsigned long *)(regs->bp + sizeof(long)); | |
10450 | + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long))); | |
10451 | #else | |
10452 | unsigned long *sp = (unsigned long *)®s->sp; | |
10453 | ||
10454 | /* Return address is either directly at stack pointer | |
10455 | or above a saved flags. Eflags has bits 22-31 zero, | |
10456 | kernel addresses don't. */ | |
10457 | + | |
10458 | +#ifdef CONFIG_PAX_KERNEXEC | |
10459 | + return ktla_ktva(sp[0]); | |
10460 | +#else | |
10461 | if (sp[0] >> 22) | |
10462 | return sp[0]; | |
10463 | if (sp[1] >> 22) | |
10464 | return sp[1]; | |
10465 | #endif | |
10466 | + | |
10467 | +#endif | |
10468 | } | |
10469 | #endif | |
10470 | + | |
10471 | + if (!user_mode(regs)) | |
10472 | + pc = ktla_ktva(pc); | |
10473 | + | |
10474 | return pc; | |
10475 | } | |
10476 | EXPORT_SYMBOL(profile_pc); | |
de855c5d AM |
10477 | diff -urNp linux-2.6.29.6/arch/x86/kernel/time_64.c linux-2.6.29.6/arch/x86/kernel/time_64.c |
10478 | --- linux-2.6.29.6/arch/x86/kernel/time_64.c 2009-07-02 19:41:20.000000000 -0400 | |
10479 | +++ linux-2.6.29.6/arch/x86/kernel/time_64.c 2009-07-09 22:13:39.000000000 -0400 | |
10480 | @@ -25,8 +25,6 @@ | |
10481 | #include <asm/time.h> | |
10482 | #include <asm/timer.h> | |
10483 | ||
10484 | -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES; | |
10485 | - | |
10486 | unsigned long profile_pc(struct pt_regs *regs) | |
10487 | { | |
10488 | unsigned long pc = instruction_pointer(regs); | |
10489 | @@ -34,7 +32,7 @@ unsigned long profile_pc(struct pt_regs | |
2380c486 JR |
10490 | /* Assume the lock function has either no stack frame or a copy |
10491 | of flags from PUSHF | |
10492 | Eflags always has bits 22 and up cleared unlike kernel addresses. */ | |
10493 | - if (!user_mode_vm(regs) && in_lock_functions(pc)) { | |
10494 | + if (!user_mode(regs) && in_lock_functions(pc)) { | |
10495 | #ifdef CONFIG_FRAME_POINTER | |
10496 | return *(unsigned long *)(regs->bp + sizeof(long)); | |
10497 | #else | |
de855c5d AM |
10498 | diff -urNp linux-2.6.29.6/arch/x86/kernel/tlb_32.c linux-2.6.29.6/arch/x86/kernel/tlb_32.c |
10499 | --- linux-2.6.29.6/arch/x86/kernel/tlb_32.c 2009-07-02 19:41:20.000000000 -0400 | |
10500 | +++ linux-2.6.29.6/arch/x86/kernel/tlb_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10501 | @@ -5,7 +5,7 @@ |
10502 | #include <asm/tlbflush.h> | |
10503 | ||
10504 | DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate) | |
10505 | - ____cacheline_aligned = { &init_mm, 0, }; | |
10506 | + ____cacheline_aligned = { &init_mm, 0, {0} }; | |
10507 | ||
10508 | /* must come after the send_IPI functions above for inlining */ | |
10509 | #include <mach_ipi.h> | |
de855c5d AM |
10510 | diff -urNp linux-2.6.29.6/arch/x86/kernel/tls.c linux-2.6.29.6/arch/x86/kernel/tls.c |
10511 | --- linux-2.6.29.6/arch/x86/kernel/tls.c 2009-07-02 19:41:20.000000000 -0400 | |
10512 | +++ linux-2.6.29.6/arch/x86/kernel/tls.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10513 | @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc |
10514 | if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) | |
10515 | return -EINVAL; | |
10516 | ||
10517 | +#ifdef CONFIG_PAX_SEGMEXEC | |
10518 | + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE)) | |
10519 | + return -EINVAL; | |
10520 | +#endif | |
10521 | + | |
10522 | set_tls_desc(p, idx, &info, 1); | |
10523 | ||
10524 | return 0; | |
de855c5d AM |
10525 | diff -urNp linux-2.6.29.6/arch/x86/kernel/traps.c linux-2.6.29.6/arch/x86/kernel/traps.c |
10526 | --- linux-2.6.29.6/arch/x86/kernel/traps.c 2009-07-02 19:41:20.000000000 -0400 | |
10527 | +++ linux-2.6.29.6/arch/x86/kernel/traps.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10528 | @@ -71,14 +71,6 @@ asmlinkage int system_call(void); |
10529 | ||
10530 | /* Do we ignore FPU interrupts ? */ | |
10531 | char ignore_fpu_irq; | |
10532 | - | |
10533 | -/* | |
10534 | - * The IDT has to be page-aligned to simplify the Pentium | |
10535 | - * F0 0F bug workaround.. We have a special link segment | |
10536 | - * for this. | |
10537 | - */ | |
10538 | -gate_desc idt_table[256] | |
10539 | - __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; | |
10540 | #endif | |
10541 | ||
10542 | DECLARE_BITMAP(used_vectors, NR_VECTORS); | |
10543 | @@ -116,7 +108,7 @@ static inline void preempt_conditional_c | |
10544 | static inline void | |
10545 | die_if_kernel(const char *str, struct pt_regs *regs, long err) | |
10546 | { | |
10547 | - if (!user_mode_vm(regs)) | |
10548 | + if (!user_mode(regs)) | |
10549 | die(str, regs, err); | |
10550 | } | |
10551 | ||
10552 | @@ -133,7 +125,7 @@ static int lazy_iobitmap_copy(void) | |
10553 | int cpu; | |
10554 | ||
10555 | cpu = get_cpu(); | |
10556 | - tss = &per_cpu(init_tss, cpu); | |
10557 | + tss = init_tss + cpu; | |
10558 | thread = ¤t->thread; | |
10559 | ||
10560 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && | |
10561 | @@ -169,7 +161,7 @@ do_trap(int trapnr, int signr, char *str | |
10562 | struct task_struct *tsk = current; | |
10563 | ||
10564 | #ifdef CONFIG_X86_32 | |
10565 | - if (regs->flags & X86_VM_MASK) { | |
10566 | + if (v8086_mode(regs)) { | |
10567 | /* | |
10568 | * traps 0, 1, 3, 4, and 5 should be forwarded to vm86. | |
10569 | * On nmi (interrupt 2), do_trap should not be called. | |
10570 | @@ -180,7 +172,7 @@ do_trap(int trapnr, int signr, char *str | |
10571 | } | |
10572 | #endif | |
10573 | ||
10574 | - if (!user_mode(regs)) | |
10575 | + if (!user_mode_novm(regs)) | |
10576 | goto kernel_trap; | |
10577 | ||
10578 | #ifdef CONFIG_X86_32 | |
de855c5d AM |
10579 | @@ -203,7 +195,7 @@ trap_signal: |
10580 | printk_ratelimit()) { | |
10581 | printk(KERN_INFO | |
10582 | "%s[%d] trap %s ip:%lx sp:%lx error:%lx", | |
10583 | - tsk->comm, tsk->pid, str, | |
10584 | + tsk->comm, task_pid_nr(tsk), str, | |
10585 | regs->ip, regs->sp, error_code); | |
10586 | print_vma_addr(" in ", regs->ip); | |
10587 | printk("\n"); | |
2380c486 JR |
10588 | @@ -222,6 +214,12 @@ kernel_trap: |
10589 | tsk->thread.trap_no = trapnr; | |
10590 | die(str, regs, error_code); | |
10591 | } | |
10592 | + | |
10593 | +#ifdef CONFIG_PAX_REFCOUNT | |
10594 | + if (trapnr == 4) | |
10595 | + pax_report_refcount_overflow(regs); | |
10596 | +#endif | |
10597 | + | |
10598 | return; | |
10599 | ||
10600 | #ifdef CONFIG_X86_32 | |
10601 | @@ -315,14 +313,30 @@ do_general_protection(struct pt_regs *re | |
10602 | return; | |
10603 | } | |
10604 | ||
10605 | - if (regs->flags & X86_VM_MASK) | |
10606 | + if (v8086_mode(regs)) | |
10607 | goto gp_in_vm86; | |
10608 | #endif | |
10609 | ||
10610 | tsk = current; | |
10611 | - if (!user_mode(regs)) | |
10612 | + if (!user_mode_novm(regs)) | |
10613 | goto gp_in_kernel; | |
10614 | ||
10615 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) | |
10616 | + if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) { | |
10617 | + struct mm_struct *mm = tsk->mm; | |
10618 | + unsigned long limit; | |
10619 | + | |
10620 | + down_write(&mm->mmap_sem); | |
10621 | + limit = mm->context.user_cs_limit; | |
10622 | + if (limit < TASK_SIZE) { | |
10623 | + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC); | |
10624 | + up_write(&mm->mmap_sem); | |
10625 | + return; | |
10626 | + } | |
10627 | + up_write(&mm->mmap_sem); | |
10628 | + } | |
10629 | +#endif | |
10630 | + | |
10631 | tsk->thread.error_code = error_code; | |
10632 | tsk->thread.trap_no = 13; | |
10633 | ||
10634 | @@ -355,6 +369,13 @@ gp_in_kernel: | |
10635 | if (notify_die(DIE_GPF, "general protection fault", regs, | |
10636 | error_code, 13, SIGSEGV) == NOTIFY_STOP) | |
10637 | return; | |
10638 | + | |
10639 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
10640 | + if ((regs->cs & 0xFFFF) == __KERNEL_CS) | |
10641 | + die("PAX: suspicious general protection fault", regs, error_code); | |
10642 | + else | |
10643 | +#endif | |
10644 | + | |
10645 | die("general protection fault", regs, error_code); | |
10646 | } | |
10647 | ||
10648 | @@ -601,7 +622,7 @@ dotraplinkage void __kprobes do_debug(st | |
10649 | } | |
10650 | ||
10651 | #ifdef CONFIG_X86_32 | |
10652 | - if (regs->flags & X86_VM_MASK) | |
10653 | + if (v8086_mode(regs)) | |
10654 | goto debug_vm86; | |
10655 | #endif | |
10656 | ||
10657 | @@ -613,7 +634,7 @@ dotraplinkage void __kprobes do_debug(st | |
10658 | * kernel space (but re-enable TF when returning to user mode). | |
10659 | */ | |
10660 | if (condition & DR_STEP) { | |
10661 | - if (!user_mode(regs)) | |
10662 | + if (!user_mode_novm(regs)) | |
10663 | goto clear_TF_reenable; | |
10664 | } | |
10665 | ||
10666 | @@ -800,7 +821,7 @@ do_simd_coprocessor_error(struct pt_regs | |
10667 | * Handle strange cache flush from user space exception | |
10668 | * in all other cases. This is undocumented behaviour. | |
10669 | */ | |
10670 | - if (regs->flags & X86_VM_MASK) { | |
10671 | + if (v8086_mode(regs)) { | |
10672 | handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code); | |
10673 | return; | |
10674 | } | |
10675 | @@ -829,19 +850,14 @@ do_spurious_interrupt_bug(struct pt_regs | |
10676 | #ifdef CONFIG_X86_32 | |
10677 | unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp) | |
10678 | { | |
10679 | - struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id()); | |
10680 | unsigned long base = (kesp - uesp) & -THREAD_SIZE; | |
10681 | unsigned long new_kesp = kesp - base; | |
10682 | unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT; | |
10683 | - __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS]; | |
10684 | + struct desc_struct ss; | |
10685 | ||
10686 | /* Set up base for espfix segment */ | |
10687 | - desc &= 0x00f0ff0000000000ULL; | |
10688 | - desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) | | |
10689 | - ((((__u64)base) << 32) & 0xff00000000000000ULL) | | |
10690 | - ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) | | |
10691 | - (lim_pages & 0xffff); | |
10692 | - *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc; | |
10693 | + pack_descriptor(&ss, base, lim_pages, 0x93, 0xC); | |
10694 | + write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S); | |
10695 | ||
10696 | return new_kesp; | |
10697 | } | |
de855c5d AM |
10698 | diff -urNp linux-2.6.29.6/arch/x86/kernel/tsc.c linux-2.6.29.6/arch/x86/kernel/tsc.c |
10699 | --- linux-2.6.29.6/arch/x86/kernel/tsc.c 2009-07-02 19:41:20.000000000 -0400 | |
10700 | +++ linux-2.6.29.6/arch/x86/kernel/tsc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10701 | @@ -765,7 +765,7 @@ static struct dmi_system_id __initdata b |
10702 | DMI_MATCH(DMI_BOARD_NAME, "2635FA0"), | |
10703 | }, | |
10704 | }, | |
10705 | - {} | |
10706 | + { NULL, NULL, {{0, {0}}}, NULL} | |
10707 | }; | |
10708 | ||
10709 | static void __init check_system_tsc_reliable(void) | |
de855c5d AM |
10710 | diff -urNp linux-2.6.29.6/arch/x86/kernel/vm86_32.c linux-2.6.29.6/arch/x86/kernel/vm86_32.c |
10711 | --- linux-2.6.29.6/arch/x86/kernel/vm86_32.c 2009-07-02 19:41:20.000000000 -0400 | |
10712 | +++ linux-2.6.29.6/arch/x86/kernel/vm86_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10713 | @@ -148,7 +148,7 @@ struct pt_regs *save_v86_state(struct ke |
10714 | do_exit(SIGSEGV); | |
10715 | } | |
10716 | ||
10717 | - tss = &per_cpu(init_tss, get_cpu()); | |
10718 | + tss = init_tss + get_cpu(); | |
10719 | current->thread.sp0 = current->thread.saved_sp0; | |
10720 | current->thread.sysenter_cs = __KERNEL_CS; | |
10721 | load_sp0(tss, ¤t->thread); | |
10722 | @@ -325,7 +325,7 @@ static void do_sys_vm86(struct kernel_vm | |
10723 | tsk->thread.saved_fs = info->regs32->fs; | |
10724 | savesegment(gs, tsk->thread.saved_gs); | |
10725 | ||
10726 | - tss = &per_cpu(init_tss, get_cpu()); | |
10727 | + tss = init_tss + get_cpu(); | |
10728 | tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0; | |
10729 | if (cpu_has_sep) | |
10730 | tsk->thread.sysenter_cs = 0; | |
de855c5d AM |
10731 | diff -urNp linux-2.6.29.6/arch/x86/kernel/vmi_32.c linux-2.6.29.6/arch/x86/kernel/vmi_32.c |
10732 | --- linux-2.6.29.6/arch/x86/kernel/vmi_32.c 2009-07-02 19:41:20.000000000 -0400 | |
10733 | +++ linux-2.6.29.6/arch/x86/kernel/vmi_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10734 | @@ -102,18 +102,43 @@ static unsigned patch_internal(int call, |
10735 | { | |
10736 | u64 reloc; | |
10737 | struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc; | |
10738 | + | |
10739 | +#ifdef CONFIG_PAX_KERNEXEC | |
10740 | + unsigned long cr0; | |
10741 | +#endif | |
10742 | + | |
10743 | reloc = call_vrom_long_func(vmi_rom, get_reloc, call); | |
10744 | switch(rel->type) { | |
10745 | case VMI_RELOCATION_CALL_REL: | |
10746 | BUG_ON(len < 5); | |
10747 | + | |
10748 | +#ifdef CONFIG_PAX_KERNEXEC | |
10749 | + pax_open_kernel(cr0); | |
10750 | +#endif | |
10751 | + | |
10752 | *(char *)insnbuf = MNEM_CALL; | |
10753 | patch_offset(insnbuf, ip, (unsigned long)rel->eip); | |
10754 | + | |
10755 | +#ifdef CONFIG_PAX_KERNEXEC | |
10756 | + pax_close_kernel(cr0); | |
10757 | +#endif | |
10758 | + | |
10759 | return 5; | |
10760 | ||
10761 | case VMI_RELOCATION_JUMP_REL: | |
10762 | BUG_ON(len < 5); | |
10763 | + | |
10764 | +#ifdef CONFIG_PAX_KERNEXEC | |
10765 | + pax_open_kernel(cr0); | |
10766 | +#endif | |
10767 | + | |
10768 | *(char *)insnbuf = MNEM_JMP; | |
10769 | patch_offset(insnbuf, ip, (unsigned long)rel->eip); | |
10770 | + | |
10771 | +#ifdef CONFIG_PAX_KERNEXEC | |
10772 | + pax_close_kernel(cr0); | |
10773 | +#endif | |
10774 | + | |
10775 | return 5; | |
10776 | ||
10777 | case VMI_RELOCATION_NOP: | |
10778 | @@ -409,13 +434,13 @@ static void vmi_set_pud(pud_t *pudp, pud | |
10779 | ||
10780 | static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) | |
10781 | { | |
10782 | - const pte_t pte = { .pte = 0 }; | |
10783 | + const pte_t pte = __pte(0ULL); | |
10784 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); | |
10785 | } | |
10786 | ||
10787 | static void vmi_pmd_clear(pmd_t *pmd) | |
10788 | { | |
10789 | - const pte_t pte = { .pte = 0 }; | |
10790 | + const pte_t pte = __pte(0ULL); | |
10791 | vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD); | |
10792 | } | |
10793 | #endif | |
10794 | @@ -443,8 +468,8 @@ vmi_startup_ipi_hook(int phys_apicid, un | |
10795 | ap.ss = __KERNEL_DS; | |
10796 | ap.esp = (unsigned long) start_esp; | |
10797 | ||
10798 | - ap.ds = __USER_DS; | |
10799 | - ap.es = __USER_DS; | |
10800 | + ap.ds = __KERNEL_DS; | |
10801 | + ap.es = __KERNEL_DS; | |
10802 | ap.fs = __KERNEL_PERCPU; | |
10803 | ap.gs = 0; | |
10804 | ||
10805 | @@ -639,12 +664,20 @@ static inline int __init activate_vmi(vo | |
10806 | u64 reloc; | |
10807 | const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc; | |
10808 | ||
10809 | +#ifdef CONFIG_PAX_KERNEXEC | |
10810 | + unsigned long cr0; | |
10811 | +#endif | |
10812 | + | |
10813 | if (call_vrom_func(vmi_rom, vmi_init) != 0) { | |
10814 | printk(KERN_ERR "VMI ROM failed to initialize!"); | |
10815 | return 0; | |
10816 | } | |
10817 | savesegment(cs, kernel_cs); | |
10818 | ||
10819 | +#ifdef CONFIG_PAX_KERNEXEC | |
10820 | + pax_open_kernel(cr0); | |
10821 | +#endif | |
10822 | + | |
10823 | pv_info.paravirt_enabled = 1; | |
10824 | pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK; | |
10825 | pv_info.name = "vmi"; | |
10826 | @@ -835,6 +868,10 @@ static inline int __init activate_vmi(vo | |
10827 | ||
10828 | para_fill(pv_irq_ops.safe_halt, Halt); | |
10829 | ||
10830 | +#ifdef CONFIG_PAX_KERNEXEC | |
10831 | + pax_close_kernel(cr0); | |
10832 | +#endif | |
10833 | + | |
10834 | /* | |
10835 | * Alternative instruction rewriting doesn't happen soon enough | |
10836 | * to convert VMI_IRET to a call instead of a jump; so we have | |
de855c5d AM |
10837 | diff -urNp linux-2.6.29.6/arch/x86/kernel/vmlinux_32.lds.S linux-2.6.29.6/arch/x86/kernel/vmlinux_32.lds.S |
10838 | --- linux-2.6.29.6/arch/x86/kernel/vmlinux_32.lds.S 2009-07-02 19:41:20.000000000 -0400 | |
10839 | +++ linux-2.6.29.6/arch/x86/kernel/vmlinux_32.lds.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
10840 | @@ -15,6 +15,20 @@ |
10841 | #include <asm/page.h> | |
10842 | #include <asm/cache.h> | |
10843 | #include <asm/boot.h> | |
10844 | +#include <asm/segment.h> | |
10845 | + | |
10846 | +#ifdef CONFIG_X86_PAE | |
10847 | +#define PMD_SHIFT 21 | |
10848 | +#else | |
10849 | +#define PMD_SHIFT 22 | |
10850 | +#endif | |
10851 | +#define PMD_SIZE (1 << PMD_SHIFT) | |
10852 | + | |
10853 | +#ifdef CONFIG_PAX_KERNEXEC | |
10854 | +#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1))) | |
10855 | +#else | |
10856 | +#define __KERNEL_TEXT_OFFSET 0 | |
10857 | +#endif | |
10858 | ||
10859 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") | |
10860 | OUTPUT_ARCH(i386) | |
10861 | @@ -22,82 +36,23 @@ ENTRY(phys_startup_32) | |
10862 | jiffies = jiffies_64; | |
10863 | ||
10864 | PHDRS { | |
10865 | - text PT_LOAD FLAGS(5); /* R_E */ | |
10866 | - data PT_LOAD FLAGS(7); /* RWE */ | |
10867 | - note PT_NOTE FLAGS(0); /* ___ */ | |
10868 | + initdata PT_LOAD FLAGS(6); /* RW_ */ | |
10869 | + percpu PT_LOAD FLAGS(6); /* RW_ */ | |
10870 | + inittext PT_LOAD FLAGS(5); /* R_E */ | |
10871 | + text PT_LOAD FLAGS(5); /* R_E */ | |
10872 | + rodata PT_LOAD FLAGS(4); /* R__ */ | |
10873 | + data PT_LOAD FLAGS(6); /* RW_ */ | |
10874 | + note PT_NOTE FLAGS(0); /* ___ */ | |
10875 | } | |
10876 | SECTIONS | |
10877 | { | |
10878 | - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR; | |
10879 | - phys_startup_32 = startup_32 - LOAD_OFFSET; | |
10880 | - | |
10881 | - .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) { | |
10882 | - _text = .; /* Text and read-only data */ | |
10883 | - *(.text.head) | |
10884 | - } :text = 0x9090 | |
10885 | - | |
10886 | - /* read-only */ | |
10887 | - .text : AT(ADDR(.text) - LOAD_OFFSET) { | |
10888 | - . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */ | |
10889 | - *(.text.page_aligned) | |
10890 | - TEXT_TEXT | |
10891 | - SCHED_TEXT | |
10892 | - LOCK_TEXT | |
10893 | - KPROBES_TEXT | |
10894 | - IRQENTRY_TEXT | |
10895 | - *(.fixup) | |
10896 | - *(.gnu.warning) | |
10897 | - _etext = .; /* End of text section */ | |
10898 | - } :text = 0x9090 | |
10899 | - | |
10900 | - NOTES :text :note | |
10901 | + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR; | |
10902 | ||
10903 | - . = ALIGN(16); /* Exception table */ | |
10904 | - __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { | |
10905 | - __start___ex_table = .; | |
10906 | - *(__ex_table) | |
10907 | - __stop___ex_table = .; | |
10908 | - } :text = 0x9090 | |
10909 | - | |
10910 | - RODATA | |
10911 | - | |
10912 | - /* writeable */ | |
10913 | - . = ALIGN(PAGE_SIZE); | |
10914 | - .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */ | |
10915 | - DATA_DATA | |
10916 | - CONSTRUCTORS | |
10917 | - } :data | |
10918 | - | |
10919 | - . = ALIGN(PAGE_SIZE); | |
10920 | - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { | |
10921 | - __nosave_begin = .; | |
10922 | - *(.data.nosave) | |
10923 | - . = ALIGN(PAGE_SIZE); | |
10924 | - __nosave_end = .; | |
10925 | - } | |
10926 | - | |
10927 | - . = ALIGN(PAGE_SIZE); | |
10928 | - .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { | |
10929 | - *(.data.page_aligned) | |
10930 | - *(.data.idt) | |
10931 | - } | |
10932 | - | |
10933 | - . = ALIGN(32); | |
10934 | - .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) { | |
10935 | - *(.data.cacheline_aligned) | |
10936 | - } | |
10937 | - | |
10938 | - /* rarely changed data like cpu maps */ | |
10939 | - . = ALIGN(32); | |
10940 | - .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { | |
10941 | - *(.data.read_mostly) | |
10942 | - _edata = .; /* End of data section */ | |
10943 | - } | |
10944 | - | |
10945 | - . = ALIGN(THREAD_SIZE); /* init_task */ | |
10946 | - .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { | |
10947 | - *(.data.init_task) | |
10948 | - } | |
10949 | + .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) { | |
10950 | + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET; | |
10951 | + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET; | |
10952 | + *(.text.startup) | |
10953 | + } :initdata | |
10954 | ||
10955 | /* might get freed after init */ | |
10956 | . = ALIGN(PAGE_SIZE); | |
10957 | @@ -115,14 +70,8 @@ SECTIONS | |
10958 | . = ALIGN(PAGE_SIZE); | |
10959 | ||
10960 | /* will be freed after init */ | |
10961 | - . = ALIGN(PAGE_SIZE); /* Init code and data */ | |
10962 | - .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { | |
10963 | - __init_begin = .; | |
10964 | - _sinittext = .; | |
10965 | - INIT_TEXT | |
10966 | - _einittext = .; | |
10967 | - } | |
10968 | .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { | |
10969 | + __init_begin = .; | |
10970 | INIT_DATA | |
10971 | } | |
10972 | . = ALIGN(16); | |
10973 | @@ -162,11 +111,6 @@ SECTIONS | |
10974 | *(.parainstructions) | |
10975 | __parainstructions_end = .; | |
10976 | } | |
10977 | - /* .exit.text is discard at runtime, not link time, to deal with references | |
10978 | - from .altinstructions and .eh_frame */ | |
10979 | - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { | |
10980 | - EXIT_TEXT | |
10981 | - } | |
10982 | .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { | |
10983 | EXIT_DATA | |
10984 | } | |
10985 | @@ -179,18 +123,139 @@ SECTIONS | |
10986 | } | |
10987 | #endif | |
10988 | . = ALIGN(PAGE_SIZE); | |
10989 | - .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) { | |
10990 | - __per_cpu_start = .; | |
10991 | - *(.data.percpu.page_aligned) | |
10992 | + per_cpu_start = .; | |
10993 | + .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) { | |
10994 | + __per_cpu_start = . + per_cpu_start; | |
10995 | + LONG(0) | |
10996 | *(.data.percpu) | |
10997 | *(.data.percpu.shared_aligned) | |
10998 | - __per_cpu_end = .; | |
10999 | - } | |
11000 | + . = ALIGN(PAGE_SIZE); | |
11001 | + *(.data.percpu.page_aligned) | |
11002 | + __per_cpu_end = . + per_cpu_start; | |
11003 | + } :percpu | |
11004 | + . += per_cpu_start; | |
11005 | . = ALIGN(PAGE_SIZE); | |
11006 | /* freed after init ends here */ | |
11007 | ||
11008 | + . = ALIGN(PAGE_SIZE); /* Init code and data */ | |
11009 | + .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) { | |
11010 | + _sinittext = .; | |
11011 | + INIT_TEXT | |
11012 | + _einittext = .; | |
11013 | + } :inittext | |
11014 | + | |
11015 | + /* .exit.text is discard at runtime, not link time, to deal with references | |
11016 | + from .altinstructions and .eh_frame */ | |
11017 | + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) { | |
11018 | + EXIT_TEXT | |
11019 | + } | |
11020 | + | |
11021 | + .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) { | |
11022 | + BYTE(0) | |
11023 | + . = ALIGN(2*PMD_SIZE) - 1; | |
11024 | + } | |
11025 | + | |
11026 | + /* freed after init ends here */ | |
11027 | + | |
11028 | + .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) { | |
11029 | + __init_end = . + __KERNEL_TEXT_OFFSET; | |
11030 | + KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET; | |
11031 | + _text = .; /* Text and read-only data */ | |
11032 | + *(.text.head) | |
11033 | + } :text = 0x9090 | |
11034 | + | |
11035 | + /* read-only */ | |
11036 | + .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) { | |
11037 | + . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */ | |
11038 | + *(.text.page_aligned) | |
11039 | + TEXT_TEXT | |
11040 | + SCHED_TEXT | |
11041 | + LOCK_TEXT | |
11042 | + KPROBES_TEXT | |
11043 | + IRQENTRY_TEXT | |
11044 | + *(.fixup) | |
11045 | + *(.gnu.warning) | |
11046 | + _etext = .; /* End of text section */ | |
11047 | + } :text = 0x9090 | |
11048 | + | |
11049 | + . += __KERNEL_TEXT_OFFSET; | |
11050 | + | |
11051 | + . = ALIGN(4096); | |
11052 | + NOTES :rodata :note | |
11053 | + | |
11054 | + . = ALIGN(16); /* Exception table */ | |
11055 | + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { | |
11056 | + __start___ex_table = .; | |
11057 | + *(__ex_table) | |
11058 | + __stop___ex_table = .; | |
11059 | + } :rodata | |
11060 | + | |
11061 | + RO_DATA(PAGE_SIZE) | |
11062 | + | |
11063 | + . = ALIGN(PAGE_SIZE); | |
11064 | + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) { | |
11065 | + *(.idt) | |
11066 | + . = ALIGN(PAGE_SIZE); | |
11067 | + *(.empty_zero_page) | |
11068 | + *(.swapper_pg_pmd) | |
11069 | + *(.swapper_pg_dir) | |
11070 | + | |
11071 | +#if defined(CONFIG_PAX_KERNEXEC) && !defined(CONFIG_MODULES) | |
11072 | + . = ALIGN(PMD_SIZE); | |
11073 | +#endif | |
11074 | + | |
11075 | + } | |
11076 | + | |
11077 | +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES) | |
11078 | + . = ALIGN(PAGE_SIZE); | |
11079 | + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) { | |
11080 | + MODULES_VADDR = .; | |
11081 | + BYTE(0) | |
11082 | + . += (6 * 1024 * 1024); | |
11083 | + . = ALIGN(PMD_SIZE); | |
11084 | + MODULES_END = . - 1; | |
11085 | + } | |
11086 | +#endif | |
11087 | + | |
11088 | + /* writeable */ | |
11089 | + . = ALIGN(PAGE_SIZE); | |
11090 | + .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */ | |
11091 | + _data = .; | |
11092 | + DATA_DATA | |
11093 | + CONSTRUCTORS | |
11094 | + } :data | |
11095 | + | |
11096 | + . = ALIGN(PAGE_SIZE); | |
11097 | + .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { | |
11098 | + __nosave_begin = .; | |
11099 | + *(.data.nosave) | |
11100 | + . = ALIGN(PAGE_SIZE); | |
11101 | + __nosave_end = .; | |
11102 | + } | |
11103 | + | |
11104 | + . = ALIGN(PAGE_SIZE); | |
11105 | + .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { | |
11106 | + *(.data.page_aligned) | |
11107 | + } | |
11108 | + | |
11109 | + . = ALIGN(32); | |
11110 | + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) { | |
11111 | + *(.data.cacheline_aligned) | |
11112 | + } | |
11113 | + | |
11114 | + /* rarely changed data like cpu maps */ | |
11115 | + . = ALIGN(32); | |
11116 | + .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { | |
11117 | + *(.data.read_mostly) | |
11118 | + _edata = .; /* End of data section */ | |
11119 | + } | |
11120 | + | |
11121 | + . = ALIGN(THREAD_SIZE); /* init_task */ | |
11122 | + .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { | |
11123 | + *(.data.init_task) | |
11124 | + } | |
11125 | + | |
11126 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { | |
11127 | - __init_end = .; | |
11128 | __bss_start = .; /* BSS */ | |
11129 | *(.bss.page_aligned) | |
11130 | *(.bss) | |
de855c5d AM |
11131 | diff -urNp linux-2.6.29.6/arch/x86/kernel/vmlinux_64.lds.S linux-2.6.29.6/arch/x86/kernel/vmlinux_64.lds.S |
11132 | --- linux-2.6.29.6/arch/x86/kernel/vmlinux_64.lds.S 2009-07-02 19:41:20.000000000 -0400 | |
11133 | +++ linux-2.6.29.6/arch/x86/kernel/vmlinux_64.lds.S 2009-07-09 22:13:39.000000000 -0400 | |
11134 | @@ -12,12 +12,12 @@ | |
11135 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") | |
11136 | OUTPUT_ARCH(i386:x86-64) | |
11137 | ENTRY(phys_startup_64) | |
11138 | -jiffies_64 = jiffies; | |
11139 | +jiffies = jiffies_64; | |
2380c486 JR |
11140 | _proxy_pda = 1; |
11141 | PHDRS { | |
11142 | text PT_LOAD FLAGS(5); /* R_E */ | |
11143 | - data PT_LOAD FLAGS(7); /* RWE */ | |
de855c5d AM |
11144 | - user PT_LOAD FLAGS(7); /* RWE */ |
11145 | + user PT_LOAD FLAGS(5); /* R_E */ | |
2380c486 | 11146 | + data PT_LOAD FLAGS(6); /* RW_ */ |
2380c486 JR |
11147 | data.init PT_LOAD FLAGS(7); /* RWE */ |
11148 | note PT_NOTE FLAGS(0); /* ___ */ | |
de855c5d | 11149 | } |
2380c486 JR |
11150 | @@ -50,17 +50,20 @@ SECTIONS |
11151 | __stop___ex_table = .; | |
11152 | } :text = 0x9090 | |
11153 | ||
11154 | - RODATA | |
11155 | + RO_DATA(PAGE_SIZE) | |
11156 | ||
11157 | +#ifdef CONFIG_PAX_KERNEXEC | |
11158 | + . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */ | |
11159 | +#else | |
11160 | . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */ | |
11161 | +#endif | |
11162 | /* Data */ | |
11163 | + _data = .; | |
11164 | .data : AT(ADDR(.data) - LOAD_OFFSET) { | |
11165 | DATA_DATA | |
11166 | CONSTRUCTORS | |
11167 | } :data | |
11168 | ||
11169 | - _edata = .; /* End of data section */ | |
11170 | - | |
11171 | . = ALIGN(PAGE_SIZE); | |
11172 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
11173 | .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) { | |
de855c5d AM |
11174 | @@ -104,10 +107,6 @@ SECTIONS |
11175 | .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) } | |
11176 | vgetcpu_mode = VVIRT(.vgetcpu_mode); | |
11177 | ||
11178 | - . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
11179 | - .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) } | |
11180 | - jiffies = VVIRT(.jiffies); | |
11181 | - | |
11182 | .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) | |
11183 | { *(.vsyscall_3) } | |
11184 | ||
11185 | @@ -124,20 +123,28 @@ SECTIONS | |
11186 | . = ALIGN(THREAD_SIZE); /* init_task */ | |
11187 | .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { | |
11188 | *(.data.init_task) | |
11189 | - }:data.init | |
11190 | + }:data | |
11191 | ||
11192 | . = ALIGN(PAGE_SIZE); | |
11193 | .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { | |
11194 | *(.data.page_aligned) | |
2380c486 JR |
11195 | } |
11196 | ||
2380c486 JR |
11197 | + . = ALIGN(PAGE_SIZE); |
11198 | + __nosave_begin = .; | |
11199 | + .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } | |
11200 | + . = ALIGN(PAGE_SIZE); | |
11201 | + __nosave_end = .; | |
11202 | + | |
11203 | + _edata = .; /* End of data section */ | |
11204 | + | |
2380c486 JR |
11205 | /* might get freed after init */ |
11206 | . = ALIGN(PAGE_SIZE); | |
11207 | __smp_alt_begin = .; | |
11208 | __smp_locks = .; | |
11209 | .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) { | |
11210 | *(.smp_locks) | |
11211 | - } | |
de855c5d | 11212 | + }:data.init |
2380c486 JR |
11213 | __smp_locks_end = .; |
11214 | . = ALIGN(PAGE_SIZE); | |
11215 | __smp_alt_end = .; | |
de855c5d | 11216 | @@ -213,16 +220,11 @@ SECTIONS |
2380c486 JR |
11217 | . = ALIGN(PAGE_SIZE); |
11218 | __init_end = .; | |
11219 | ||
11220 | - . = ALIGN(PAGE_SIZE); | |
11221 | - __nosave_begin = .; | |
11222 | - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } | |
11223 | - . = ALIGN(PAGE_SIZE); | |
11224 | - __nosave_end = .; | |
11225 | - | |
11226 | __bss_start = .; /* BSS */ | |
11227 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { | |
11228 | *(.bss.page_aligned) | |
11229 | *(.bss) | |
11230 | + . = ALIGN(2*1024*1024); | |
11231 | } | |
11232 | __bss_stop = .; | |
11233 | ||
de855c5d AM |
11234 | diff -urNp linux-2.6.29.6/arch/x86/kernel/vsyscall_64.c linux-2.6.29.6/arch/x86/kernel/vsyscall_64.c |
11235 | --- linux-2.6.29.6/arch/x86/kernel/vsyscall_64.c 2009-07-02 19:41:20.000000000 -0400 | |
11236 | +++ linux-2.6.29.6/arch/x86/kernel/vsyscall_64.c 2009-07-09 22:13:39.000000000 -0400 | |
11237 | @@ -79,6 +79,7 @@ void update_vsyscall(struct timespec *wa | |
11238 | ||
11239 | write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags); | |
11240 | /* copy vsyscall data */ | |
11241 | + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name); | |
11242 | vsyscall_gtod_data.clock.vread = clock->vread; | |
11243 | vsyscall_gtod_data.clock.cycle_last = clock->cycle_last; | |
11244 | vsyscall_gtod_data.clock.mask = clock->mask; | |
11245 | @@ -209,7 +210,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s | |
11246 | We do this here because otherwise user space would do it on | |
11247 | its own in a likely inferior way (no access to jiffies). | |
11248 | If you don't like it pass NULL. */ | |
11249 | - if (tcache && tcache->blob[0] == (j = __jiffies)) { | |
11250 | + if (tcache && tcache->blob[0] == (j = jiffies)) { | |
11251 | p = tcache->blob[1]; | |
11252 | } else if (__vgetcpu_mode == VGETCPU_RDTSCP) { | |
11253 | /* Load per CPU data from RDTSCP */ | |
11254 | @@ -248,13 +249,13 @@ static ctl_table kernel_table2[] = { | |
2380c486 JR |
11255 | .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int), |
11256 | .mode = 0644, | |
11257 | .proc_handler = vsyscall_sysctl_change }, | |
11258 | - {} | |
11259 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
11260 | }; | |
11261 | ||
11262 | static ctl_table kernel_root_table2[] = { | |
11263 | { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555, | |
11264 | .child = kernel_table2 }, | |
11265 | - {} | |
11266 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
11267 | }; | |
11268 | #endif | |
11269 | ||
de855c5d AM |
11270 | diff -urNp linux-2.6.29.6/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.29.6/arch/x86/kernel/x8664_ksyms_64.c |
11271 | --- linux-2.6.29.6/arch/x86/kernel/x8664_ksyms_64.c 2009-07-02 19:41:20.000000000 -0400 | |
11272 | +++ linux-2.6.29.6/arch/x86/kernel/x8664_ksyms_64.c 2009-07-09 22:13:39.000000000 -0400 | |
11273 | @@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8); | |
11274 | ||
11275 | EXPORT_SYMBOL(copy_user_generic); | |
11276 | EXPORT_SYMBOL(__copy_user_nocache); | |
11277 | -EXPORT_SYMBOL(copy_from_user); | |
11278 | -EXPORT_SYMBOL(copy_to_user); | |
11279 | EXPORT_SYMBOL(__copy_from_user_inatomic); | |
11280 | ||
11281 | EXPORT_SYMBOL(copy_page); | |
11282 | diff -urNp linux-2.6.29.6/arch/x86/kvm/svm.c linux-2.6.29.6/arch/x86/kvm/svm.c | |
11283 | --- linux-2.6.29.6/arch/x86/kvm/svm.c 2009-07-02 19:41:20.000000000 -0400 | |
11284 | +++ linux-2.6.29.6/arch/x86/kvm/svm.c 2009-07-09 22:13:39.000000000 -0400 | |
11285 | @@ -1525,7 +1525,19 @@ static void reload_tss(struct kvm_vcpu * | |
2380c486 JR |
11286 | int cpu = raw_smp_processor_id(); |
11287 | ||
11288 | struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu); | |
11289 | + | |
11290 | +#ifdef CONFIG_PAX_KERNEXEC | |
11291 | + unsigned long cr0; | |
11292 | + | |
11293 | + pax_open_kernel(cr0); | |
11294 | +#endif | |
11295 | + | |
11296 | svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */ | |
11297 | + | |
11298 | +#ifdef CONFIG_PAX_KERNEXEC | |
11299 | + pax_close_kernel(cr0); | |
11300 | +#endif | |
11301 | + | |
11302 | load_TR_desc(); | |
11303 | } | |
11304 | ||
de855c5d | 11305 | @@ -1936,7 +1948,7 @@ static int svm_get_mt_mask_shift(void) |
2380c486 JR |
11306 | return 0; |
11307 | } | |
11308 | ||
11309 | -static struct kvm_x86_ops svm_x86_ops = { | |
11310 | +static const struct kvm_x86_ops svm_x86_ops = { | |
11311 | .cpu_has_kvm_support = has_svm, | |
11312 | .disabled_by_bios = is_disabled, | |
11313 | .hardware_setup = svm_hardware_setup, | |
de855c5d AM |
11314 | diff -urNp linux-2.6.29.6/arch/x86/kvm/vmx.c linux-2.6.29.6/arch/x86/kvm/vmx.c |
11315 | --- linux-2.6.29.6/arch/x86/kvm/vmx.c 2009-07-02 19:41:20.000000000 -0400 | |
11316 | +++ linux-2.6.29.6/arch/x86/kvm/vmx.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11317 | @@ -497,9 +497,23 @@ static void reload_tss(void) |
11318 | struct descriptor_table gdt; | |
11319 | struct desc_struct *descs; | |
11320 | ||
11321 | +#ifdef CONFIG_PAX_KERNEXEC | |
11322 | + unsigned long cr0; | |
11323 | +#endif | |
11324 | + | |
11325 | kvm_get_gdt(&gdt); | |
11326 | descs = (void *)gdt.base; | |
11327 | + | |
11328 | +#ifdef CONFIG_PAX_KERNEXEC | |
11329 | + pax_open_kernel(cr0); | |
11330 | +#endif | |
11331 | + | |
11332 | descs[GDT_ENTRY_TSS].type = 9; /* available TSS */ | |
11333 | + | |
11334 | +#ifdef CONFIG_PAX_KERNEXEC | |
11335 | + pax_close_kernel(cr0); | |
11336 | +#endif | |
11337 | + | |
11338 | load_TR_desc(); | |
11339 | } | |
11340 | ||
de855c5d | 11341 | @@ -2182,7 +2196,7 @@ static int vmx_vcpu_setup(struct vcpu_vm |
2380c486 JR |
11342 | vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */ |
11343 | ||
11344 | asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return)); | |
11345 | - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */ | |
11346 | + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */ | |
11347 | vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0); | |
11348 | vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0); | |
11349 | vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0); | |
de855c5d | 11350 | @@ -3379,6 +3393,12 @@ static void vmx_vcpu_run(struct kvm_vcpu |
2380c486 JR |
11351 | "jmp .Lkvm_vmx_return \n\t" |
11352 | ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t" | |
11353 | ".Lkvm_vmx_return: " | |
11354 | + | |
11355 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
11356 | + "ljmp %[cs],$.Lkvm_vmx_return2\n\t" | |
11357 | + ".Lkvm_vmx_return2: " | |
11358 | +#endif | |
11359 | + | |
11360 | /* Save guest registers, load host registers, keep flags */ | |
11361 | "xchg %0, (%%"R"sp) \n\t" | |
11362 | "mov %%"R"ax, %c[rax](%0) \n\t" | |
de855c5d | 11363 | @@ -3425,6 +3445,11 @@ static void vmx_vcpu_run(struct kvm_vcpu |
2380c486 JR |
11364 | [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])), |
11365 | #endif | |
11366 | [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)) | |
11367 | + | |
11368 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
11369 | + ,[cs]"i"(__KERNEL_CS) | |
11370 | +#endif | |
11371 | + | |
11372 | : "cc", "memory" | |
11373 | , R"bx", R"di", R"si" | |
11374 | #ifdef CONFIG_X86_64 | |
de855c5d | 11375 | @@ -3441,7 +3466,7 @@ static void vmx_vcpu_run(struct kvm_vcpu |
2380c486 JR |
11376 | |
11377 | vmx_update_window_states(vcpu); | |
11378 | ||
11379 | - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); | |
11380 | + asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS)); | |
11381 | vmx->launched = 1; | |
11382 | ||
11383 | intr_info = vmcs_read32(VM_EXIT_INTR_INFO); | |
de855c5d | 11384 | @@ -3570,7 +3595,7 @@ static int vmx_get_mt_mask_shift(void) |
2380c486 JR |
11385 | return VMX_EPT_MT_EPTE_SHIFT; |
11386 | } | |
11387 | ||
11388 | -static struct kvm_x86_ops vmx_x86_ops = { | |
11389 | +static const struct kvm_x86_ops vmx_x86_ops = { | |
11390 | .cpu_has_kvm_support = cpu_has_kvm_support, | |
11391 | .disabled_by_bios = vmx_disabled_by_bios, | |
11392 | .hardware_setup = hardware_setup, | |
de855c5d AM |
11393 | diff -urNp linux-2.6.29.6/arch/x86/kvm/x86.c linux-2.6.29.6/arch/x86/kvm/x86.c |
11394 | --- linux-2.6.29.6/arch/x86/kvm/x86.c 2009-07-02 19:41:20.000000000 -0400 | |
11395 | +++ linux-2.6.29.6/arch/x86/kvm/x86.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11396 | @@ -70,44 +70,44 @@ static u64 __read_mostly efer_reserved_b |
11397 | static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, | |
11398 | struct kvm_cpuid_entry2 __user *entries); | |
11399 | ||
11400 | -struct kvm_x86_ops *kvm_x86_ops; | |
11401 | +const struct kvm_x86_ops *kvm_x86_ops; | |
11402 | EXPORT_SYMBOL_GPL(kvm_x86_ops); | |
11403 | ||
11404 | struct kvm_stats_debugfs_item debugfs_entries[] = { | |
11405 | - { "pf_fixed", VCPU_STAT(pf_fixed) }, | |
11406 | - { "pf_guest", VCPU_STAT(pf_guest) }, | |
11407 | - { "tlb_flush", VCPU_STAT(tlb_flush) }, | |
11408 | - { "invlpg", VCPU_STAT(invlpg) }, | |
11409 | - { "exits", VCPU_STAT(exits) }, | |
11410 | - { "io_exits", VCPU_STAT(io_exits) }, | |
11411 | - { "mmio_exits", VCPU_STAT(mmio_exits) }, | |
11412 | - { "signal_exits", VCPU_STAT(signal_exits) }, | |
11413 | - { "irq_window", VCPU_STAT(irq_window_exits) }, | |
11414 | - { "nmi_window", VCPU_STAT(nmi_window_exits) }, | |
11415 | - { "halt_exits", VCPU_STAT(halt_exits) }, | |
11416 | - { "halt_wakeup", VCPU_STAT(halt_wakeup) }, | |
11417 | - { "hypercalls", VCPU_STAT(hypercalls) }, | |
11418 | - { "request_irq", VCPU_STAT(request_irq_exits) }, | |
11419 | - { "request_nmi", VCPU_STAT(request_nmi_exits) }, | |
11420 | - { "irq_exits", VCPU_STAT(irq_exits) }, | |
11421 | - { "host_state_reload", VCPU_STAT(host_state_reload) }, | |
11422 | - { "efer_reload", VCPU_STAT(efer_reload) }, | |
11423 | - { "fpu_reload", VCPU_STAT(fpu_reload) }, | |
11424 | - { "insn_emulation", VCPU_STAT(insn_emulation) }, | |
11425 | - { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) }, | |
11426 | - { "irq_injections", VCPU_STAT(irq_injections) }, | |
11427 | - { "nmi_injections", VCPU_STAT(nmi_injections) }, | |
11428 | - { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) }, | |
11429 | - { "mmu_pte_write", VM_STAT(mmu_pte_write) }, | |
11430 | - { "mmu_pte_updated", VM_STAT(mmu_pte_updated) }, | |
11431 | - { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) }, | |
11432 | - { "mmu_flooded", VM_STAT(mmu_flooded) }, | |
11433 | - { "mmu_recycled", VM_STAT(mmu_recycled) }, | |
11434 | - { "mmu_cache_miss", VM_STAT(mmu_cache_miss) }, | |
11435 | - { "mmu_unsync", VM_STAT(mmu_unsync) }, | |
11436 | - { "mmu_unsync_global", VM_STAT(mmu_unsync_global) }, | |
11437 | - { "remote_tlb_flush", VM_STAT(remote_tlb_flush) }, | |
11438 | - { "largepages", VM_STAT(lpages) }, | |
11439 | + { "pf_fixed", VCPU_STAT(pf_fixed), NULL }, | |
11440 | + { "pf_guest", VCPU_STAT(pf_guest), NULL }, | |
11441 | + { "tlb_flush", VCPU_STAT(tlb_flush), NULL }, | |
11442 | + { "invlpg", VCPU_STAT(invlpg), NULL }, | |
11443 | + { "exits", VCPU_STAT(exits), NULL }, | |
11444 | + { "io_exits", VCPU_STAT(io_exits), NULL }, | |
11445 | + { "mmio_exits", VCPU_STAT(mmio_exits), NULL }, | |
11446 | + { "signal_exits", VCPU_STAT(signal_exits), NULL }, | |
11447 | + { "irq_window", VCPU_STAT(irq_window_exits), NULL }, | |
11448 | + { "nmi_window", VCPU_STAT(nmi_window_exits), NULL }, | |
11449 | + { "halt_exits", VCPU_STAT(halt_exits), NULL }, | |
11450 | + { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL }, | |
11451 | + { "hypercalls", VCPU_STAT(hypercalls), NULL }, | |
11452 | + { "request_irq", VCPU_STAT(request_irq_exits), NULL }, | |
11453 | + { "request_nmi", VCPU_STAT(request_nmi_exits), NULL }, | |
11454 | + { "irq_exits", VCPU_STAT(irq_exits), NULL }, | |
11455 | + { "host_state_reload", VCPU_STAT(host_state_reload), NULL }, | |
11456 | + { "efer_reload", VCPU_STAT(efer_reload), NULL }, | |
11457 | + { "fpu_reload", VCPU_STAT(fpu_reload), NULL }, | |
11458 | + { "insn_emulation", VCPU_STAT(insn_emulation), NULL }, | |
11459 | + { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL }, | |
11460 | + { "irq_injections", VCPU_STAT(irq_injections), NULL }, | |
11461 | + { "nmi_injections", VCPU_STAT(nmi_injections), NULL }, | |
11462 | + { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL }, | |
11463 | + { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL }, | |
11464 | + { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL }, | |
11465 | + { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL }, | |
11466 | + { "mmu_flooded", VM_STAT(mmu_flooded), NULL }, | |
11467 | + { "mmu_recycled", VM_STAT(mmu_recycled), NULL }, | |
11468 | + { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL }, | |
11469 | + { "mmu_unsync", VM_STAT(mmu_unsync), NULL }, | |
11470 | + { "mmu_unsync_global", VM_STAT(mmu_unsync_global), NULL }, | |
11471 | + { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL }, | |
11472 | + { "largepages", VM_STAT(lpages), NULL }, | |
11473 | { NULL } | |
11474 | }; | |
11475 | ||
de855c5d | 11476 | @@ -1372,7 +1372,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru |
2380c486 JR |
11477 | static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, |
11478 | struct kvm_interrupt *irq) | |
11479 | { | |
11480 | - if (irq->irq < 0 || irq->irq >= 256) | |
11481 | + if (irq->irq >= 256) | |
11482 | return -EINVAL; | |
11483 | if (irqchip_in_kernel(vcpu->kvm)) | |
11484 | return -ENXIO; | |
de855c5d | 11485 | @@ -2591,10 +2591,10 @@ int kvm_emulate_pio_string(struct kvm_vc |
2380c486 JR |
11486 | } |
11487 | EXPORT_SYMBOL_GPL(kvm_emulate_pio_string); | |
11488 | ||
11489 | -int kvm_arch_init(void *opaque) | |
11490 | +int kvm_arch_init(const void *opaque) | |
11491 | { | |
11492 | int r; | |
11493 | - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque; | |
11494 | + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque; | |
11495 | ||
11496 | if (kvm_x86_ops) { | |
11497 | printk(KERN_ERR "kvm: already loaded the other module\n"); | |
de855c5d AM |
11498 | diff -urNp linux-2.6.29.6/arch/x86/lib/checksum_32.S linux-2.6.29.6/arch/x86/lib/checksum_32.S |
11499 | --- linux-2.6.29.6/arch/x86/lib/checksum_32.S 2009-07-02 19:41:20.000000000 -0400 | |
11500 | +++ linux-2.6.29.6/arch/x86/lib/checksum_32.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11501 | @@ -28,7 +28,8 @@ |
11502 | #include <linux/linkage.h> | |
11503 | #include <asm/dwarf2.h> | |
11504 | #include <asm/errno.h> | |
11505 | - | |
11506 | +#include <asm/segment.h> | |
11507 | + | |
11508 | /* | |
11509 | * computes a partial checksum, e.g. for TCP/UDP fragments | |
11510 | */ | |
11511 | @@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic ( | |
11512 | ||
11513 | #define ARGBASE 16 | |
11514 | #define FP 12 | |
11515 | - | |
11516 | -ENTRY(csum_partial_copy_generic) | |
11517 | + | |
11518 | +ENTRY(csum_partial_copy_generic_to_user) | |
11519 | CFI_STARTPROC | |
11520 | + pushl $(__USER_DS) | |
11521 | + CFI_ADJUST_CFA_OFFSET 4 | |
11522 | + popl %es | |
11523 | + CFI_ADJUST_CFA_OFFSET -4 | |
11524 | + jmp csum_partial_copy_generic | |
11525 | + | |
11526 | +ENTRY(csum_partial_copy_generic_from_user) | |
11527 | + pushl $(__USER_DS) | |
11528 | + CFI_ADJUST_CFA_OFFSET 4 | |
11529 | + popl %ds | |
11530 | + CFI_ADJUST_CFA_OFFSET -4 | |
11531 | + | |
11532 | +ENTRY(csum_partial_copy_generic) | |
11533 | subl $4,%esp | |
11534 | CFI_ADJUST_CFA_OFFSET 4 | |
11535 | pushl %edi | |
11536 | @@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic) | |
11537 | jmp 4f | |
11538 | SRC(1: movw (%esi), %bx ) | |
11539 | addl $2, %esi | |
11540 | -DST( movw %bx, (%edi) ) | |
11541 | +DST( movw %bx, %es:(%edi) ) | |
11542 | addl $2, %edi | |
11543 | addw %bx, %ax | |
11544 | adcl $0, %eax | |
11545 | @@ -343,30 +357,30 @@ DST( movw %bx, (%edi) ) | |
11546 | SRC(1: movl (%esi), %ebx ) | |
11547 | SRC( movl 4(%esi), %edx ) | |
11548 | adcl %ebx, %eax | |
11549 | -DST( movl %ebx, (%edi) ) | |
11550 | +DST( movl %ebx, %es:(%edi) ) | |
11551 | adcl %edx, %eax | |
11552 | -DST( movl %edx, 4(%edi) ) | |
11553 | +DST( movl %edx, %es:4(%edi) ) | |
11554 | ||
11555 | SRC( movl 8(%esi), %ebx ) | |
11556 | SRC( movl 12(%esi), %edx ) | |
11557 | adcl %ebx, %eax | |
11558 | -DST( movl %ebx, 8(%edi) ) | |
11559 | +DST( movl %ebx, %es:8(%edi) ) | |
11560 | adcl %edx, %eax | |
11561 | -DST( movl %edx, 12(%edi) ) | |
11562 | +DST( movl %edx, %es:12(%edi) ) | |
11563 | ||
11564 | SRC( movl 16(%esi), %ebx ) | |
11565 | SRC( movl 20(%esi), %edx ) | |
11566 | adcl %ebx, %eax | |
11567 | -DST( movl %ebx, 16(%edi) ) | |
11568 | +DST( movl %ebx, %es:16(%edi) ) | |
11569 | adcl %edx, %eax | |
11570 | -DST( movl %edx, 20(%edi) ) | |
11571 | +DST( movl %edx, %es:20(%edi) ) | |
11572 | ||
11573 | SRC( movl 24(%esi), %ebx ) | |
11574 | SRC( movl 28(%esi), %edx ) | |
11575 | adcl %ebx, %eax | |
11576 | -DST( movl %ebx, 24(%edi) ) | |
11577 | +DST( movl %ebx, %es:24(%edi) ) | |
11578 | adcl %edx, %eax | |
11579 | -DST( movl %edx, 28(%edi) ) | |
11580 | +DST( movl %edx, %es:28(%edi) ) | |
11581 | ||
11582 | lea 32(%esi), %esi | |
11583 | lea 32(%edi), %edi | |
11584 | @@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) ) | |
11585 | shrl $2, %edx # This clears CF | |
11586 | SRC(3: movl (%esi), %ebx ) | |
11587 | adcl %ebx, %eax | |
11588 | -DST( movl %ebx, (%edi) ) | |
11589 | +DST( movl %ebx, %es:(%edi) ) | |
11590 | lea 4(%esi), %esi | |
11591 | lea 4(%edi), %edi | |
11592 | dec %edx | |
11593 | @@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) ) | |
11594 | jb 5f | |
11595 | SRC( movw (%esi), %cx ) | |
11596 | leal 2(%esi), %esi | |
11597 | -DST( movw %cx, (%edi) ) | |
11598 | +DST( movw %cx, %es:(%edi) ) | |
11599 | leal 2(%edi), %edi | |
11600 | je 6f | |
11601 | shll $16,%ecx | |
11602 | SRC(5: movb (%esi), %cl ) | |
11603 | -DST( movb %cl, (%edi) ) | |
11604 | +DST( movb %cl, %es:(%edi) ) | |
11605 | 6: addl %ecx, %eax | |
11606 | adcl $0, %eax | |
11607 | 7: | |
11608 | @@ -408,7 +422,7 @@ DST( movb %cl, (%edi) ) | |
11609 | ||
11610 | 6001: | |
11611 | movl ARGBASE+20(%esp), %ebx # src_err_ptr | |
11612 | - movl $-EFAULT, (%ebx) | |
11613 | + movl $-EFAULT, %ss:(%ebx) | |
11614 | ||
11615 | # zero the complete destination - computing the rest | |
11616 | # is too much work | |
11617 | @@ -421,11 +435,19 @@ DST( movb %cl, (%edi) ) | |
11618 | ||
11619 | 6002: | |
11620 | movl ARGBASE+24(%esp), %ebx # dst_err_ptr | |
11621 | - movl $-EFAULT,(%ebx) | |
11622 | + movl $-EFAULT,%ss:(%ebx) | |
11623 | jmp 5000b | |
11624 | ||
11625 | .previous | |
11626 | ||
11627 | + pushl %ss | |
11628 | + CFI_ADJUST_CFA_OFFSET 4 | |
11629 | + popl %ds | |
11630 | + CFI_ADJUST_CFA_OFFSET -4 | |
11631 | + pushl %ss | |
11632 | + CFI_ADJUST_CFA_OFFSET 4 | |
11633 | + popl %es | |
11634 | + CFI_ADJUST_CFA_OFFSET -4 | |
11635 | popl %ebx | |
11636 | CFI_ADJUST_CFA_OFFSET -4 | |
11637 | CFI_RESTORE ebx | |
11638 | @@ -439,26 +461,41 @@ DST( movb %cl, (%edi) ) | |
11639 | CFI_ADJUST_CFA_OFFSET -4 | |
11640 | ret | |
11641 | CFI_ENDPROC | |
11642 | -ENDPROC(csum_partial_copy_generic) | |
11643 | +ENDPROC(csum_partial_copy_generic_to_user) | |
11644 | ||
11645 | #else | |
11646 | ||
11647 | /* Version for PentiumII/PPro */ | |
11648 | ||
11649 | #define ROUND1(x) \ | |
11650 | + nop; nop; nop; \ | |
11651 | SRC(movl x(%esi), %ebx ) ; \ | |
11652 | addl %ebx, %eax ; \ | |
11653 | - DST(movl %ebx, x(%edi) ) ; | |
11654 | + DST(movl %ebx, %es:x(%edi)) ; | |
11655 | ||
11656 | #define ROUND(x) \ | |
11657 | + nop; nop; nop; \ | |
11658 | SRC(movl x(%esi), %ebx ) ; \ | |
11659 | adcl %ebx, %eax ; \ | |
11660 | - DST(movl %ebx, x(%edi) ) ; | |
11661 | + DST(movl %ebx, %es:x(%edi)) ; | |
11662 | ||
11663 | #define ARGBASE 12 | |
11664 | - | |
11665 | -ENTRY(csum_partial_copy_generic) | |
11666 | + | |
11667 | +ENTRY(csum_partial_copy_generic_to_user) | |
11668 | CFI_STARTPROC | |
11669 | + pushl $(__USER_DS) | |
11670 | + CFI_ADJUST_CFA_OFFSET 4 | |
11671 | + popl %es | |
11672 | + CFI_ADJUST_CFA_OFFSET -4 | |
11673 | + jmp csum_partial_copy_generic | |
11674 | + | |
11675 | +ENTRY(csum_partial_copy_generic_from_user) | |
11676 | + pushl $(__USER_DS) | |
11677 | + CFI_ADJUST_CFA_OFFSET 4 | |
11678 | + popl %ds | |
11679 | + CFI_ADJUST_CFA_OFFSET -4 | |
11680 | + | |
11681 | +ENTRY(csum_partial_copy_generic) | |
11682 | pushl %ebx | |
11683 | CFI_ADJUST_CFA_OFFSET 4 | |
11684 | CFI_REL_OFFSET ebx, 0 | |
11685 | @@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic) | |
11686 | subl %ebx, %edi | |
11687 | lea -1(%esi),%edx | |
11688 | andl $-32,%edx | |
11689 | - lea 3f(%ebx,%ebx), %ebx | |
11690 | + lea 3f(%ebx,%ebx,2), %ebx | |
11691 | testl %esi, %esi | |
11692 | jmp *%ebx | |
11693 | 1: addl $64,%esi | |
11694 | @@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic) | |
11695 | jb 5f | |
11696 | SRC( movw (%esi), %dx ) | |
11697 | leal 2(%esi), %esi | |
11698 | -DST( movw %dx, (%edi) ) | |
11699 | +DST( movw %dx, %es:(%edi) ) | |
11700 | leal 2(%edi), %edi | |
11701 | je 6f | |
11702 | shll $16,%edx | |
11703 | 5: | |
11704 | SRC( movb (%esi), %dl ) | |
11705 | -DST( movb %dl, (%edi) ) | |
11706 | +DST( movb %dl, %es:(%edi) ) | |
11707 | 6: addl %edx, %eax | |
11708 | adcl $0, %eax | |
11709 | 7: | |
11710 | .section .fixup, "ax" | |
11711 | 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr | |
11712 | - movl $-EFAULT, (%ebx) | |
11713 | + movl $-EFAULT, %ss:(%ebx) | |
11714 | # zero the complete destination (computing the rest is too much work) | |
11715 | movl ARGBASE+8(%esp),%edi # dst | |
11716 | movl ARGBASE+12(%esp),%ecx # len | |
11717 | @@ -523,10 +560,18 @@ DST( movb %dl, (%edi) ) | |
11718 | rep; stosb | |
11719 | jmp 7b | |
11720 | 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr | |
11721 | - movl $-EFAULT, (%ebx) | |
11722 | + movl $-EFAULT, %ss:(%ebx) | |
11723 | jmp 7b | |
11724 | .previous | |
11725 | ||
11726 | + pushl %ss | |
11727 | + CFI_ADJUST_CFA_OFFSET 4 | |
11728 | + popl %ds | |
11729 | + CFI_ADJUST_CFA_OFFSET -4 | |
11730 | + pushl %ss | |
11731 | + CFI_ADJUST_CFA_OFFSET 4 | |
11732 | + popl %es | |
11733 | + CFI_ADJUST_CFA_OFFSET -4 | |
11734 | popl %esi | |
11735 | CFI_ADJUST_CFA_OFFSET -4 | |
11736 | CFI_RESTORE esi | |
11737 | @@ -538,7 +583,7 @@ DST( movb %dl, (%edi) ) | |
11738 | CFI_RESTORE ebx | |
11739 | ret | |
11740 | CFI_ENDPROC | |
11741 | -ENDPROC(csum_partial_copy_generic) | |
11742 | +ENDPROC(csum_partial_copy_generic_to_user) | |
11743 | ||
11744 | #undef ROUND | |
11745 | #undef ROUND1 | |
de855c5d AM |
11746 | diff -urNp linux-2.6.29.6/arch/x86/lib/clear_page_64.S linux-2.6.29.6/arch/x86/lib/clear_page_64.S |
11747 | --- linux-2.6.29.6/arch/x86/lib/clear_page_64.S 2009-07-02 19:41:20.000000000 -0400 | |
11748 | +++ linux-2.6.29.6/arch/x86/lib/clear_page_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11749 | @@ -44,7 +44,7 @@ ENDPROC(clear_page) |
11750 | ||
11751 | #include <asm/cpufeature.h> | |
11752 | ||
11753 | - .section .altinstr_replacement,"ax" | |
11754 | + .section .altinstr_replacement,"a" | |
11755 | 1: .byte 0xeb /* jmp <disp8> */ | |
11756 | .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */ | |
11757 | 2: | |
de855c5d AM |
11758 | diff -urNp linux-2.6.29.6/arch/x86/lib/copy_page_64.S linux-2.6.29.6/arch/x86/lib/copy_page_64.S |
11759 | --- linux-2.6.29.6/arch/x86/lib/copy_page_64.S 2009-07-02 19:41:20.000000000 -0400 | |
11760 | +++ linux-2.6.29.6/arch/x86/lib/copy_page_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11761 | @@ -104,7 +104,7 @@ ENDPROC(copy_page) |
11762 | ||
11763 | #include <asm/cpufeature.h> | |
11764 | ||
11765 | - .section .altinstr_replacement,"ax" | |
11766 | + .section .altinstr_replacement,"a" | |
11767 | 1: .byte 0xeb /* jmp <disp8> */ | |
11768 | .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */ | |
11769 | 2: | |
de855c5d AM |
11770 | diff -urNp linux-2.6.29.6/arch/x86/lib/copy_user_64.S linux-2.6.29.6/arch/x86/lib/copy_user_64.S |
11771 | --- linux-2.6.29.6/arch/x86/lib/copy_user_64.S 2009-07-02 19:41:20.000000000 -0400 | |
11772 | +++ linux-2.6.29.6/arch/x86/lib/copy_user_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11773 | @@ -21,7 +21,7 @@ |
11774 | .byte 0xe9 /* 32bit jump */ | |
11775 | .long \orig-1f /* by default jump to orig */ | |
11776 | 1: | |
11777 | - .section .altinstr_replacement,"ax" | |
11778 | + .section .altinstr_replacement,"a" | |
11779 | 2: .byte 0xe9 /* near jump with 32bit immediate */ | |
11780 | .long \alt-1b /* offset */ /* or alternatively to alt */ | |
11781 | .previous | |
de855c5d AM |
11782 | @@ -64,31 +64,6 @@ |
11783 | #endif | |
11784 | .endm | |
11785 | ||
11786 | -/* Standard copy_to_user with segment limit checking */ | |
11787 | -ENTRY(copy_to_user) | |
11788 | - CFI_STARTPROC | |
11789 | - GET_THREAD_INFO(%rax) | |
11790 | - movq %rdi,%rcx | |
11791 | - addq %rdx,%rcx | |
11792 | - jc bad_to_user | |
11793 | - cmpq TI_addr_limit(%rax),%rcx | |
11794 | - jae bad_to_user | |
11795 | - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string | |
11796 | - CFI_ENDPROC | |
11797 | - | |
11798 | -/* Standard copy_from_user with segment limit checking */ | |
11799 | -ENTRY(copy_from_user) | |
11800 | - CFI_STARTPROC | |
11801 | - GET_THREAD_INFO(%rax) | |
11802 | - movq %rsi,%rcx | |
11803 | - addq %rdx,%rcx | |
11804 | - jc bad_from_user | |
11805 | - cmpq TI_addr_limit(%rax),%rcx | |
11806 | - jae bad_from_user | |
11807 | - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string | |
11808 | - CFI_ENDPROC | |
11809 | -ENDPROC(copy_from_user) | |
11810 | - | |
11811 | ENTRY(copy_user_generic) | |
11812 | CFI_STARTPROC | |
11813 | ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string | |
11814 | @@ -106,6 +81,8 @@ ENDPROC(__copy_from_user_inatomic) | |
2380c486 JR |
11815 | ENTRY(bad_from_user) |
11816 | bad_from_user: | |
11817 | CFI_STARTPROC | |
11818 | + testl %edx,%edx | |
11819 | + js bad_to_user | |
11820 | movl %edx,%ecx | |
11821 | xorl %eax,%eax | |
11822 | rep | |
de855c5d AM |
11823 | diff -urNp linux-2.6.29.6/arch/x86/lib/getuser.S linux-2.6.29.6/arch/x86/lib/getuser.S |
11824 | --- linux-2.6.29.6/arch/x86/lib/getuser.S 2009-07-02 19:41:20.000000000 -0400 | |
11825 | +++ linux-2.6.29.6/arch/x86/lib/getuser.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11826 | @@ -33,6 +33,7 @@ |
11827 | #include <asm/asm-offsets.h> | |
11828 | #include <asm/thread_info.h> | |
11829 | #include <asm/asm.h> | |
11830 | +#include <asm/segment.h> | |
11831 | ||
11832 | .text | |
11833 | ENTRY(__get_user_1) | |
11834 | @@ -40,7 +41,19 @@ ENTRY(__get_user_1) | |
11835 | GET_THREAD_INFO(%_ASM_DX) | |
11836 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX | |
11837 | jae bad_get_user | |
11838 | + | |
11839 | +#ifdef CONFIG_X86_32 | |
11840 | + pushl $(__USER_DS) | |
11841 | + popl %ds | |
11842 | +#endif | |
11843 | + | |
11844 | 1: movzb (%_ASM_AX),%edx | |
11845 | + | |
11846 | +#ifdef CONFIG_X86_32 | |
11847 | + pushl %ss | |
11848 | + pop %ds | |
11849 | +#endif | |
11850 | + | |
11851 | xor %eax,%eax | |
11852 | ret | |
11853 | CFI_ENDPROC | |
11854 | @@ -53,7 +66,19 @@ ENTRY(__get_user_2) | |
11855 | GET_THREAD_INFO(%_ASM_DX) | |
11856 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX | |
11857 | jae bad_get_user | |
11858 | + | |
11859 | +#ifdef CONFIG_X86_32 | |
11860 | + pushl $(__USER_DS) | |
11861 | + popl %ds | |
11862 | +#endif | |
11863 | + | |
11864 | 2: movzwl -1(%_ASM_AX),%edx | |
11865 | + | |
11866 | +#ifdef CONFIG_X86_32 | |
11867 | + pushl %ss | |
11868 | + pop %ds | |
11869 | +#endif | |
11870 | + | |
11871 | xor %eax,%eax | |
11872 | ret | |
11873 | CFI_ENDPROC | |
11874 | @@ -66,7 +91,19 @@ ENTRY(__get_user_4) | |
11875 | GET_THREAD_INFO(%_ASM_DX) | |
11876 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX | |
11877 | jae bad_get_user | |
11878 | + | |
11879 | +#ifdef CONFIG_X86_32 | |
11880 | + pushl $(__USER_DS) | |
11881 | + popl %ds | |
11882 | +#endif | |
11883 | + | |
11884 | 3: mov -3(%_ASM_AX),%edx | |
11885 | + | |
11886 | +#ifdef CONFIG_X86_32 | |
11887 | + pushl %ss | |
11888 | + pop %ds | |
11889 | +#endif | |
11890 | + | |
11891 | xor %eax,%eax | |
11892 | ret | |
11893 | CFI_ENDPROC | |
11894 | @@ -89,6 +126,12 @@ ENDPROC(__get_user_8) | |
11895 | ||
11896 | bad_get_user: | |
11897 | CFI_STARTPROC | |
11898 | + | |
11899 | +#ifdef CONFIG_X86_32 | |
11900 | + pushl %ss | |
11901 | + pop %ds | |
11902 | +#endif | |
11903 | + | |
11904 | xor %edx,%edx | |
11905 | mov $(-EFAULT),%_ASM_AX | |
11906 | ret | |
de855c5d AM |
11907 | diff -urNp linux-2.6.29.6/arch/x86/lib/memcpy_64.S linux-2.6.29.6/arch/x86/lib/memcpy_64.S |
11908 | --- linux-2.6.29.6/arch/x86/lib/memcpy_64.S 2009-07-02 19:41:20.000000000 -0400 | |
11909 | +++ linux-2.6.29.6/arch/x86/lib/memcpy_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11910 | @@ -114,7 +114,7 @@ ENDPROC(__memcpy) |
11911 | /* Some CPUs run faster using the string copy instructions. | |
11912 | It is also a lot simpler. Use this when possible */ | |
11913 | ||
11914 | - .section .altinstr_replacement,"ax" | |
11915 | + .section .altinstr_replacement,"a" | |
11916 | 1: .byte 0xeb /* jmp <disp8> */ | |
11917 | .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */ | |
11918 | 2: | |
de855c5d AM |
11919 | diff -urNp linux-2.6.29.6/arch/x86/lib/memset_64.S linux-2.6.29.6/arch/x86/lib/memset_64.S |
11920 | --- linux-2.6.29.6/arch/x86/lib/memset_64.S 2009-07-02 19:41:20.000000000 -0400 | |
11921 | +++ linux-2.6.29.6/arch/x86/lib/memset_64.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11922 | @@ -118,7 +118,7 @@ ENDPROC(__memset) |
11923 | ||
11924 | #include <asm/cpufeature.h> | |
11925 | ||
11926 | - .section .altinstr_replacement,"ax" | |
11927 | + .section .altinstr_replacement,"a" | |
11928 | 1: .byte 0xeb /* jmp <disp8> */ | |
11929 | .byte (memset_c - memset) - (2f - 1b) /* offset */ | |
11930 | 2: | |
de855c5d AM |
11931 | diff -urNp linux-2.6.29.6/arch/x86/lib/mmx_32.c linux-2.6.29.6/arch/x86/lib/mmx_32.c |
11932 | --- linux-2.6.29.6/arch/x86/lib/mmx_32.c 2009-07-02 19:41:20.000000000 -0400 | |
11933 | +++ linux-2.6.29.6/arch/x86/lib/mmx_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
11934 | @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void * |
11935 | { | |
11936 | void *p; | |
11937 | int i; | |
11938 | + unsigned long cr0; | |
11939 | ||
11940 | if (unlikely(in_interrupt())) | |
11941 | return __memcpy(to, from, len); | |
11942 | @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void * | |
11943 | kernel_fpu_begin(); | |
11944 | ||
11945 | __asm__ __volatile__ ( | |
11946 | - "1: prefetch (%0)\n" /* This set is 28 bytes */ | |
11947 | - " prefetch 64(%0)\n" | |
11948 | - " prefetch 128(%0)\n" | |
11949 | - " prefetch 192(%0)\n" | |
11950 | - " prefetch 256(%0)\n" | |
11951 | + "1: prefetch (%1)\n" /* This set is 28 bytes */ | |
11952 | + " prefetch 64(%1)\n" | |
11953 | + " prefetch 128(%1)\n" | |
11954 | + " prefetch 192(%1)\n" | |
11955 | + " prefetch 256(%1)\n" | |
11956 | "2: \n" | |
11957 | ".section .fixup, \"ax\"\n" | |
11958 | - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
11959 | + "3: \n" | |
11960 | + | |
11961 | +#ifdef CONFIG_PAX_KERNEXEC | |
11962 | + " movl %%cr0, %0\n" | |
11963 | + " movl %0, %%eax\n" | |
11964 | + " andl $0xFFFEFFFF, %%eax\n" | |
11965 | + " movl %%eax, %%cr0\n" | |
11966 | +#endif | |
11967 | + | |
11968 | + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
11969 | + | |
11970 | +#ifdef CONFIG_PAX_KERNEXEC | |
11971 | + " movl %0, %%cr0\n" | |
11972 | +#endif | |
11973 | + | |
11974 | " jmp 2b\n" | |
11975 | ".previous\n" | |
11976 | _ASM_EXTABLE(1b, 3b) | |
11977 | - : : "r" (from)); | |
11978 | + : "=&r" (cr0) : "r" (from) : "ax"); | |
11979 | ||
11980 | for ( ; i > 5; i--) { | |
11981 | __asm__ __volatile__ ( | |
11982 | - "1: prefetch 320(%0)\n" | |
11983 | - "2: movq (%0), %%mm0\n" | |
11984 | - " movq 8(%0), %%mm1\n" | |
11985 | - " movq 16(%0), %%mm2\n" | |
11986 | - " movq 24(%0), %%mm3\n" | |
11987 | - " movq %%mm0, (%1)\n" | |
11988 | - " movq %%mm1, 8(%1)\n" | |
11989 | - " movq %%mm2, 16(%1)\n" | |
11990 | - " movq %%mm3, 24(%1)\n" | |
11991 | - " movq 32(%0), %%mm0\n" | |
11992 | - " movq 40(%0), %%mm1\n" | |
11993 | - " movq 48(%0), %%mm2\n" | |
11994 | - " movq 56(%0), %%mm3\n" | |
11995 | - " movq %%mm0, 32(%1)\n" | |
11996 | - " movq %%mm1, 40(%1)\n" | |
11997 | - " movq %%mm2, 48(%1)\n" | |
11998 | - " movq %%mm3, 56(%1)\n" | |
11999 | + "1: prefetch 320(%1)\n" | |
12000 | + "2: movq (%1), %%mm0\n" | |
12001 | + " movq 8(%1), %%mm1\n" | |
12002 | + " movq 16(%1), %%mm2\n" | |
12003 | + " movq 24(%1), %%mm3\n" | |
12004 | + " movq %%mm0, (%2)\n" | |
12005 | + " movq %%mm1, 8(%2)\n" | |
12006 | + " movq %%mm2, 16(%2)\n" | |
12007 | + " movq %%mm3, 24(%2)\n" | |
12008 | + " movq 32(%1), %%mm0\n" | |
12009 | + " movq 40(%1), %%mm1\n" | |
12010 | + " movq 48(%1), %%mm2\n" | |
12011 | + " movq 56(%1), %%mm3\n" | |
12012 | + " movq %%mm0, 32(%2)\n" | |
12013 | + " movq %%mm1, 40(%2)\n" | |
12014 | + " movq %%mm2, 48(%2)\n" | |
12015 | + " movq %%mm3, 56(%2)\n" | |
12016 | ".section .fixup, \"ax\"\n" | |
12017 | - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12018 | + "3:\n" | |
12019 | + | |
12020 | +#ifdef CONFIG_PAX_KERNEXEC | |
12021 | + " movl %%cr0, %0\n" | |
12022 | + " movl %0, %%eax\n" | |
12023 | + " andl $0xFFFEFFFF, %%eax\n" | |
12024 | + " movl %%eax, %%cr0\n" | |
12025 | +#endif | |
12026 | + | |
12027 | + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12028 | + | |
12029 | +#ifdef CONFIG_PAX_KERNEXEC | |
12030 | + " movl %0, %%cr0\n" | |
12031 | +#endif | |
12032 | + | |
12033 | " jmp 2b\n" | |
12034 | ".previous\n" | |
12035 | _ASM_EXTABLE(1b, 3b) | |
12036 | - : : "r" (from), "r" (to) : "memory"); | |
12037 | + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax"); | |
12038 | ||
12039 | from += 64; | |
12040 | to += 64; | |
12041 | @@ -158,6 +187,7 @@ static void fast_clear_page(void *page) | |
12042 | static void fast_copy_page(void *to, void *from) | |
12043 | { | |
12044 | int i; | |
12045 | + unsigned long cr0; | |
12046 | ||
12047 | kernel_fpu_begin(); | |
12048 | ||
12049 | @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi | |
12050 | * but that is for later. -AV | |
12051 | */ | |
12052 | __asm__ __volatile__( | |
12053 | - "1: prefetch (%0)\n" | |
12054 | - " prefetch 64(%0)\n" | |
12055 | - " prefetch 128(%0)\n" | |
12056 | - " prefetch 192(%0)\n" | |
12057 | - " prefetch 256(%0)\n" | |
12058 | + "1: prefetch (%1)\n" | |
12059 | + " prefetch 64(%1)\n" | |
12060 | + " prefetch 128(%1)\n" | |
12061 | + " prefetch 192(%1)\n" | |
12062 | + " prefetch 256(%1)\n" | |
12063 | "2: \n" | |
12064 | ".section .fixup, \"ax\"\n" | |
12065 | - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
12066 | + "3: \n" | |
12067 | + | |
12068 | +#ifdef CONFIG_PAX_KERNEXEC | |
12069 | + " movl %%cr0, %0\n" | |
12070 | + " movl %0, %%eax\n" | |
12071 | + " andl $0xFFFEFFFF, %%eax\n" | |
12072 | + " movl %%eax, %%cr0\n" | |
12073 | +#endif | |
12074 | + | |
12075 | + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
12076 | + | |
12077 | +#ifdef CONFIG_PAX_KERNEXEC | |
12078 | + " movl %0, %%cr0\n" | |
12079 | +#endif | |
12080 | + | |
12081 | " jmp 2b\n" | |
12082 | ".previous\n" | |
12083 | - _ASM_EXTABLE(1b, 3b) : : "r" (from)); | |
12084 | + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax"); | |
12085 | ||
12086 | for (i = 0; i < (4096-320)/64; i++) { | |
12087 | __asm__ __volatile__ ( | |
12088 | - "1: prefetch 320(%0)\n" | |
12089 | - "2: movq (%0), %%mm0\n" | |
12090 | - " movntq %%mm0, (%1)\n" | |
12091 | - " movq 8(%0), %%mm1\n" | |
12092 | - " movntq %%mm1, 8(%1)\n" | |
12093 | - " movq 16(%0), %%mm2\n" | |
12094 | - " movntq %%mm2, 16(%1)\n" | |
12095 | - " movq 24(%0), %%mm3\n" | |
12096 | - " movntq %%mm3, 24(%1)\n" | |
12097 | - " movq 32(%0), %%mm4\n" | |
12098 | - " movntq %%mm4, 32(%1)\n" | |
12099 | - " movq 40(%0), %%mm5\n" | |
12100 | - " movntq %%mm5, 40(%1)\n" | |
12101 | - " movq 48(%0), %%mm6\n" | |
12102 | - " movntq %%mm6, 48(%1)\n" | |
12103 | - " movq 56(%0), %%mm7\n" | |
12104 | - " movntq %%mm7, 56(%1)\n" | |
12105 | + "1: prefetch 320(%1)\n" | |
12106 | + "2: movq (%1), %%mm0\n" | |
12107 | + " movntq %%mm0, (%2)\n" | |
12108 | + " movq 8(%1), %%mm1\n" | |
12109 | + " movntq %%mm1, 8(%2)\n" | |
12110 | + " movq 16(%1), %%mm2\n" | |
12111 | + " movntq %%mm2, 16(%2)\n" | |
12112 | + " movq 24(%1), %%mm3\n" | |
12113 | + " movntq %%mm3, 24(%2)\n" | |
12114 | + " movq 32(%1), %%mm4\n" | |
12115 | + " movntq %%mm4, 32(%2)\n" | |
12116 | + " movq 40(%1), %%mm5\n" | |
12117 | + " movntq %%mm5, 40(%2)\n" | |
12118 | + " movq 48(%1), %%mm6\n" | |
12119 | + " movntq %%mm6, 48(%2)\n" | |
12120 | + " movq 56(%1), %%mm7\n" | |
12121 | + " movntq %%mm7, 56(%2)\n" | |
12122 | ".section .fixup, \"ax\"\n" | |
12123 | - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12124 | + "3:\n" | |
12125 | + | |
12126 | +#ifdef CONFIG_PAX_KERNEXEC | |
12127 | + " movl %%cr0, %0\n" | |
12128 | + " movl %0, %%eax\n" | |
12129 | + " andl $0xFFFEFFFF, %%eax\n" | |
12130 | + " movl %%eax, %%cr0\n" | |
12131 | +#endif | |
12132 | + | |
12133 | + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12134 | + | |
12135 | +#ifdef CONFIG_PAX_KERNEXEC | |
12136 | + " movl %0, %%cr0\n" | |
12137 | +#endif | |
12138 | + | |
12139 | " jmp 2b\n" | |
12140 | ".previous\n" | |
12141 | - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory"); | |
12142 | + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax"); | |
12143 | ||
12144 | from += 64; | |
12145 | to += 64; | |
12146 | @@ -280,47 +338,76 @@ static void fast_clear_page(void *page) | |
12147 | static void fast_copy_page(void *to, void *from) | |
12148 | { | |
12149 | int i; | |
12150 | + unsigned long cr0; | |
12151 | ||
12152 | kernel_fpu_begin(); | |
12153 | ||
12154 | __asm__ __volatile__ ( | |
12155 | - "1: prefetch (%0)\n" | |
12156 | - " prefetch 64(%0)\n" | |
12157 | - " prefetch 128(%0)\n" | |
12158 | - " prefetch 192(%0)\n" | |
12159 | - " prefetch 256(%0)\n" | |
12160 | + "1: prefetch (%1)\n" | |
12161 | + " prefetch 64(%1)\n" | |
12162 | + " prefetch 128(%1)\n" | |
12163 | + " prefetch 192(%1)\n" | |
12164 | + " prefetch 256(%1)\n" | |
12165 | "2: \n" | |
12166 | ".section .fixup, \"ax\"\n" | |
12167 | - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
12168 | + "3: \n" | |
12169 | + | |
12170 | +#ifdef CONFIG_PAX_KERNEXEC | |
12171 | + " movl %%cr0, %0\n" | |
12172 | + " movl %0, %%eax\n" | |
12173 | + " andl $0xFFFEFFFF, %%eax\n" | |
12174 | + " movl %%eax, %%cr0\n" | |
12175 | +#endif | |
12176 | + | |
12177 | + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */ | |
12178 | + | |
12179 | +#ifdef CONFIG_PAX_KERNEXEC | |
12180 | + " movl %0, %%cr0\n" | |
12181 | +#endif | |
12182 | + | |
12183 | " jmp 2b\n" | |
12184 | ".previous\n" | |
12185 | - _ASM_EXTABLE(1b, 3b) : : "r" (from)); | |
12186 | + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax"); | |
12187 | ||
12188 | for (i = 0; i < 4096/64; i++) { | |
12189 | __asm__ __volatile__ ( | |
12190 | - "1: prefetch 320(%0)\n" | |
12191 | - "2: movq (%0), %%mm0\n" | |
12192 | - " movq 8(%0), %%mm1\n" | |
12193 | - " movq 16(%0), %%mm2\n" | |
12194 | - " movq 24(%0), %%mm3\n" | |
12195 | - " movq %%mm0, (%1)\n" | |
12196 | - " movq %%mm1, 8(%1)\n" | |
12197 | - " movq %%mm2, 16(%1)\n" | |
12198 | - " movq %%mm3, 24(%1)\n" | |
12199 | - " movq 32(%0), %%mm0\n" | |
12200 | - " movq 40(%0), %%mm1\n" | |
12201 | - " movq 48(%0), %%mm2\n" | |
12202 | - " movq 56(%0), %%mm3\n" | |
12203 | - " movq %%mm0, 32(%1)\n" | |
12204 | - " movq %%mm1, 40(%1)\n" | |
12205 | - " movq %%mm2, 48(%1)\n" | |
12206 | - " movq %%mm3, 56(%1)\n" | |
12207 | + "1: prefetch 320(%1)\n" | |
12208 | + "2: movq (%1), %%mm0\n" | |
12209 | + " movq 8(%1), %%mm1\n" | |
12210 | + " movq 16(%1), %%mm2\n" | |
12211 | + " movq 24(%1), %%mm3\n" | |
12212 | + " movq %%mm0, (%2)\n" | |
12213 | + " movq %%mm1, 8(%2)\n" | |
12214 | + " movq %%mm2, 16(%2)\n" | |
12215 | + " movq %%mm3, 24(%2)\n" | |
12216 | + " movq 32(%1), %%mm0\n" | |
12217 | + " movq 40(%1), %%mm1\n" | |
12218 | + " movq 48(%1), %%mm2\n" | |
12219 | + " movq 56(%1), %%mm3\n" | |
12220 | + " movq %%mm0, 32(%2)\n" | |
12221 | + " movq %%mm1, 40(%2)\n" | |
12222 | + " movq %%mm2, 48(%2)\n" | |
12223 | + " movq %%mm3, 56(%2)\n" | |
12224 | ".section .fixup, \"ax\"\n" | |
12225 | - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12226 | + "3:\n" | |
12227 | + | |
12228 | +#ifdef CONFIG_PAX_KERNEXEC | |
12229 | + " movl %%cr0, %0\n" | |
12230 | + " movl %0, %%eax\n" | |
12231 | + " andl $0xFFFEFFFF, %%eax\n" | |
12232 | + " movl %%eax, %%cr0\n" | |
12233 | +#endif | |
12234 | + | |
12235 | + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */ | |
12236 | + | |
12237 | +#ifdef CONFIG_PAX_KERNEXEC | |
12238 | + " movl %0, %%cr0\n" | |
12239 | +#endif | |
12240 | + | |
12241 | " jmp 2b\n" | |
12242 | ".previous\n" | |
12243 | _ASM_EXTABLE(1b, 3b) | |
12244 | - : : "r" (from), "r" (to) : "memory"); | |
12245 | + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax"); | |
12246 | ||
12247 | from += 64; | |
12248 | to += 64; | |
de855c5d AM |
12249 | diff -urNp linux-2.6.29.6/arch/x86/lib/putuser.S linux-2.6.29.6/arch/x86/lib/putuser.S |
12250 | --- linux-2.6.29.6/arch/x86/lib/putuser.S 2009-07-02 19:41:20.000000000 -0400 | |
12251 | +++ linux-2.6.29.6/arch/x86/lib/putuser.S 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
12252 | @@ -15,6 +15,7 @@ |
12253 | #include <asm/thread_info.h> | |
12254 | #include <asm/errno.h> | |
12255 | #include <asm/asm.h> | |
12256 | +#include <asm/segment.h> | |
12257 | ||
12258 | ||
12259 | /* | |
12260 | @@ -39,7 +40,19 @@ ENTRY(__put_user_1) | |
12261 | ENTER | |
12262 | cmp TI_addr_limit(%_ASM_BX),%_ASM_CX | |
12263 | jae bad_put_user | |
12264 | + | |
12265 | +#ifdef CONFIG_X86_32 | |
12266 | + pushl $(__USER_DS) | |
12267 | + popl %ds | |
12268 | +#endif | |
12269 | + | |
12270 | 1: movb %al,(%_ASM_CX) | |
12271 | + | |
12272 | +#ifdef CONFIG_X86_32 | |
12273 | + pushl %ss | |
12274 | + popl %ds | |
12275 | +#endif | |
12276 | + | |
12277 | xor %eax,%eax | |
12278 | EXIT | |
12279 | ENDPROC(__put_user_1) | |
12280 | @@ -50,7 +63,19 @@ ENTRY(__put_user_2) | |
12281 | sub $1,%_ASM_BX | |
12282 | cmp %_ASM_BX,%_ASM_CX | |
12283 | jae bad_put_user | |
12284 | + | |
12285 | +#ifdef CONFIG_X86_32 | |
12286 | + pushl $(__USER_DS) | |
12287 | + popl %ds | |
12288 | +#endif | |
12289 | + | |
12290 | 2: movw %ax,(%_ASM_CX) | |
12291 | + | |
12292 | +#ifdef CONFIG_X86_32 | |
12293 | + pushl %ss | |
12294 | + popl %ds | |
12295 | +#endif | |
12296 | + | |
12297 | xor %eax,%eax | |
12298 | EXIT | |
12299 | ENDPROC(__put_user_2) | |
12300 | @@ -61,7 +86,19 @@ ENTRY(__put_user_4) | |
12301 | sub $3,%_ASM_BX | |
12302 | cmp %_ASM_BX,%_ASM_CX | |
12303 | jae bad_put_user | |
12304 | + | |
12305 | +#ifdef CONFIG_X86_32 | |
12306 | + pushl $(__USER_DS) | |
12307 | + popl %ds | |
12308 | +#endif | |
12309 | + | |
12310 | 3: movl %eax,(%_ASM_CX) | |
12311 | + | |
12312 | +#ifdef CONFIG_X86_32 | |
12313 | + pushl %ss | |
12314 | + popl %ds | |
12315 | +#endif | |
12316 | + | |
12317 | xor %eax,%eax | |
12318 | EXIT | |
12319 | ENDPROC(__put_user_4) | |
12320 | @@ -72,16 +109,34 @@ ENTRY(__put_user_8) | |
12321 | sub $7,%_ASM_BX | |
12322 | cmp %_ASM_BX,%_ASM_CX | |
12323 | jae bad_put_user | |
12324 | + | |
12325 | +#ifdef CONFIG_X86_32 | |
12326 | + pushl $(__USER_DS) | |
12327 | + popl %ds | |
12328 | +#endif | |
12329 | + | |
12330 | 4: mov %_ASM_AX,(%_ASM_CX) | |
12331 | #ifdef CONFIG_X86_32 | |
12332 | 5: movl %edx,4(%_ASM_CX) | |
12333 | #endif | |
12334 | + | |
12335 | +#ifdef CONFIG_X86_32 | |
12336 | + pushl %ss | |
12337 | + popl %ds | |
12338 | +#endif | |
12339 | + | |
12340 | xor %eax,%eax | |
12341 | EXIT | |
12342 | ENDPROC(__put_user_8) | |
12343 | ||
12344 | bad_put_user: | |
12345 | CFI_STARTPROC | |
12346 | + | |
12347 | +#ifdef CONFIG_X86_32 | |
12348 | + pushl %ss | |
12349 | + popl %ds | |
12350 | +#endif | |
12351 | + | |
12352 | movl $-EFAULT,%eax | |
12353 | EXIT | |
12354 | END(bad_put_user) | |
de855c5d AM |
12355 | diff -urNp linux-2.6.29.6/arch/x86/lib/usercopy_32.c linux-2.6.29.6/arch/x86/lib/usercopy_32.c |
12356 | --- linux-2.6.29.6/arch/x86/lib/usercopy_32.c 2009-07-02 19:41:20.000000000 -0400 | |
12357 | +++ linux-2.6.29.6/arch/x86/lib/usercopy_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
12358 | @@ -36,31 +36,38 @@ static inline int __movsl_is_ok(unsigned |
12359 | * Copy a null terminated string from userspace. | |
12360 | */ | |
12361 | ||
12362 | -#define __do_strncpy_from_user(dst, src, count, res) \ | |
12363 | -do { \ | |
12364 | - int __d0, __d1, __d2; \ | |
12365 | - might_fault(); \ | |
12366 | - __asm__ __volatile__( \ | |
12367 | - " testl %1,%1\n" \ | |
12368 | - " jz 2f\n" \ | |
12369 | - "0: lodsb\n" \ | |
12370 | - " stosb\n" \ | |
12371 | - " testb %%al,%%al\n" \ | |
12372 | - " jz 1f\n" \ | |
12373 | - " decl %1\n" \ | |
12374 | - " jnz 0b\n" \ | |
12375 | - "1: subl %1,%0\n" \ | |
12376 | - "2:\n" \ | |
12377 | - ".section .fixup,\"ax\"\n" \ | |
12378 | - "3: movl %5,%0\n" \ | |
12379 | - " jmp 2b\n" \ | |
12380 | - ".previous\n" \ | |
12381 | - _ASM_EXTABLE(0b,3b) \ | |
12382 | - : "=&d"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), \ | |
12383 | - "=&D" (__d2) \ | |
12384 | - : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \ | |
12385 | - : "memory"); \ | |
12386 | -} while (0) | |
12387 | +static long __do_strncpy_from_user(char *dst, const char __user *src, long count) | |
12388 | +{ | |
12389 | + int __d0, __d1, __d2; | |
12390 | + long res = -EFAULT; | |
12391 | + | |
12392 | + might_fault(); | |
12393 | + __asm__ __volatile__( | |
12394 | + " movw %w10,%%ds\n" | |
12395 | + " testl %1,%1\n" | |
12396 | + " jz 2f\n" | |
12397 | + "0: lodsb\n" | |
12398 | + " stosb\n" | |
12399 | + " testb %%al,%%al\n" | |
12400 | + " jz 1f\n" | |
12401 | + " decl %1\n" | |
12402 | + " jnz 0b\n" | |
12403 | + "1: subl %1,%0\n" | |
12404 | + "2:\n" | |
12405 | + " pushl %%ss\n" | |
12406 | + " popl %%ds\n" | |
12407 | + ".section .fixup,\"ax\"\n" | |
12408 | + "3: movl %5,%0\n" | |
12409 | + " jmp 2b\n" | |
12410 | + ".previous\n" | |
12411 | + _ASM_EXTABLE(0b,3b) | |
12412 | + : "=&d"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), | |
12413 | + "=&D" (__d2) | |
12414 | + : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst), | |
12415 | + "r"(__USER_DS) | |
12416 | + : "memory"); | |
12417 | + return res; | |
12418 | +} | |
12419 | ||
12420 | /** | |
12421 | * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking. | |
12422 | @@ -85,9 +92,7 @@ do { \ | |
12423 | long | |
12424 | __strncpy_from_user(char *dst, const char __user *src, long count) | |
12425 | { | |
12426 | - long res; | |
12427 | - __do_strncpy_from_user(dst, src, count, res); | |
12428 | - return res; | |
12429 | + return __do_strncpy_from_user(dst, src, count); | |
12430 | } | |
12431 | EXPORT_SYMBOL(__strncpy_from_user); | |
12432 | ||
12433 | @@ -114,7 +119,7 @@ strncpy_from_user(char *dst, const char | |
12434 | { | |
12435 | long res = -EFAULT; | |
12436 | if (access_ok(VERIFY_READ, src, 1)) | |
12437 | - __do_strncpy_from_user(dst, src, count, res); | |
12438 | + res = __do_strncpy_from_user(dst, src, count); | |
12439 | return res; | |
12440 | } | |
12441 | EXPORT_SYMBOL(strncpy_from_user); | |
12442 | @@ -123,24 +128,30 @@ EXPORT_SYMBOL(strncpy_from_user); | |
12443 | * Zero Userspace | |
12444 | */ | |
12445 | ||
12446 | -#define __do_clear_user(addr,size) \ | |
12447 | -do { \ | |
12448 | - int __d0; \ | |
12449 | - might_fault(); \ | |
12450 | - __asm__ __volatile__( \ | |
12451 | - "0: rep; stosl\n" \ | |
12452 | - " movl %2,%0\n" \ | |
12453 | - "1: rep; stosb\n" \ | |
12454 | - "2:\n" \ | |
12455 | - ".section .fixup,\"ax\"\n" \ | |
12456 | - "3: lea 0(%2,%0,4),%0\n" \ | |
12457 | - " jmp 2b\n" \ | |
12458 | - ".previous\n" \ | |
12459 | - _ASM_EXTABLE(0b,3b) \ | |
12460 | - _ASM_EXTABLE(1b,2b) \ | |
12461 | - : "=&c"(size), "=&D" (__d0) \ | |
12462 | - : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \ | |
12463 | -} while (0) | |
12464 | +static unsigned long __do_clear_user(void __user *addr, unsigned long size) | |
12465 | +{ | |
12466 | + int __d0; | |
12467 | + | |
12468 | + might_fault(); | |
12469 | + __asm__ __volatile__( | |
12470 | + " movw %w6,%%es\n" | |
12471 | + "0: rep; stosl\n" | |
12472 | + " movl %2,%0\n" | |
12473 | + "1: rep; stosb\n" | |
12474 | + "2:\n" | |
12475 | + " pushl %%ss\n" | |
12476 | + " popl %%es\n" | |
12477 | + ".section .fixup,\"ax\"\n" | |
12478 | + "3: lea 0(%2,%0,4),%0\n" | |
12479 | + " jmp 2b\n" | |
12480 | + ".previous\n" | |
12481 | + _ASM_EXTABLE(0b,3b) | |
12482 | + _ASM_EXTABLE(1b,2b) | |
12483 | + : "=&c"(size), "=&D" (__d0) | |
12484 | + : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0), | |
12485 | + "r"(__USER_DS)); | |
12486 | + return size; | |
12487 | +} | |
12488 | ||
12489 | /** | |
12490 | * clear_user: - Zero a block of memory in user space. | |
12491 | @@ -157,7 +168,7 @@ clear_user(void __user *to, unsigned lon | |
12492 | { | |
12493 | might_fault(); | |
12494 | if (access_ok(VERIFY_WRITE, to, n)) | |
12495 | - __do_clear_user(to, n); | |
12496 | + n = __do_clear_user(to, n); | |
12497 | return n; | |
12498 | } | |
12499 | EXPORT_SYMBOL(clear_user); | |
12500 | @@ -176,8 +187,7 @@ EXPORT_SYMBOL(clear_user); | |
12501 | unsigned long | |
12502 | __clear_user(void __user *to, unsigned long n) | |
12503 | { | |
12504 | - __do_clear_user(to, n); | |
12505 | - return n; | |
12506 | + return __do_clear_user(to, n); | |
12507 | } | |
12508 | EXPORT_SYMBOL(__clear_user); | |
12509 | ||
12510 | @@ -200,14 +210,17 @@ long strnlen_user(const char __user *s, | |
12511 | might_fault(); | |
12512 | ||
12513 | __asm__ __volatile__( | |
12514 | + " movw %w8,%%es\n" | |
12515 | " testl %0, %0\n" | |
12516 | " jz 3f\n" | |
12517 | - " andl %0,%%ecx\n" | |
12518 | + " movl %0,%%ecx\n" | |
12519 | "0: repne; scasb\n" | |
12520 | " setne %%al\n" | |
12521 | " subl %%ecx,%0\n" | |
12522 | " addl %0,%%eax\n" | |
12523 | "1:\n" | |
12524 | + " pushl %%ss\n" | |
12525 | + " popl %%es\n" | |
12526 | ".section .fixup,\"ax\"\n" | |
12527 | "2: xorl %%eax,%%eax\n" | |
12528 | " jmp 1b\n" | |
12529 | @@ -219,7 +232,7 @@ long strnlen_user(const char __user *s, | |
12530 | " .long 0b,2b\n" | |
12531 | ".previous" | |
12532 | :"=&r" (n), "=&D" (s), "=&a" (res), "=&c" (tmp) | |
12533 | - :"0" (n), "1" (s), "2" (0), "3" (mask) | |
12534 | + :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS) | |
12535 | :"cc"); | |
12536 | return res & mask; | |
12537 | } | |
de855c5d | 12538 | @@ -227,10 +240,121 @@ EXPORT_SYMBOL(strnlen_user); |
2380c486 JR |
12539 | |
12540 | #ifdef CONFIG_X86_INTEL_USERCOPY | |
12541 | static unsigned long | |
12542 | -__copy_user_intel(void __user *to, const void *from, unsigned long size) | |
12543 | +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size) | |
2380c486 JR |
12544 | +{ |
12545 | + int d0, d1; | |
12546 | + __asm__ __volatile__( | |
de855c5d | 12547 | + " movw %w6, %%es\n" |
2380c486 JR |
12548 | + " .align 2,0x90\n" |
12549 | + "1: movl 32(%4), %%eax\n" | |
12550 | + " cmpl $67, %0\n" | |
12551 | + " jbe 3f\n" | |
12552 | + "2: movl 64(%4), %%eax\n" | |
12553 | + " .align 2,0x90\n" | |
12554 | + "3: movl 0(%4), %%eax\n" | |
12555 | + "4: movl 4(%4), %%edx\n" | |
12556 | + "5: movl %%eax, %%es:0(%3)\n" | |
12557 | + "6: movl %%edx, %%es:4(%3)\n" | |
12558 | + "7: movl 8(%4), %%eax\n" | |
12559 | + "8: movl 12(%4),%%edx\n" | |
12560 | + "9: movl %%eax, %%es:8(%3)\n" | |
12561 | + "10: movl %%edx, %%es:12(%3)\n" | |
12562 | + "11: movl 16(%4), %%eax\n" | |
12563 | + "12: movl 20(%4), %%edx\n" | |
12564 | + "13: movl %%eax, %%es:16(%3)\n" | |
12565 | + "14: movl %%edx, %%es:20(%3)\n" | |
12566 | + "15: movl 24(%4), %%eax\n" | |
12567 | + "16: movl 28(%4), %%edx\n" | |
12568 | + "17: movl %%eax, %%es:24(%3)\n" | |
12569 | + "18: movl %%edx, %%es:28(%3)\n" | |
12570 | + "19: movl 32(%4), %%eax\n" | |
12571 | + "20: movl 36(%4), %%edx\n" | |
12572 | + "21: movl %%eax, %%es:32(%3)\n" | |
12573 | + "22: movl %%edx, %%es:36(%3)\n" | |
12574 | + "23: movl 40(%4), %%eax\n" | |
12575 | + "24: movl 44(%4), %%edx\n" | |
12576 | + "25: movl %%eax, %%es:40(%3)\n" | |
12577 | + "26: movl %%edx, %%es:44(%3)\n" | |
12578 | + "27: movl 48(%4), %%eax\n" | |
12579 | + "28: movl 52(%4), %%edx\n" | |
12580 | + "29: movl %%eax, %%es:48(%3)\n" | |
12581 | + "30: movl %%edx, %%es:52(%3)\n" | |
12582 | + "31: movl 56(%4), %%eax\n" | |
12583 | + "32: movl 60(%4), %%edx\n" | |
12584 | + "33: movl %%eax, %%es:56(%3)\n" | |
12585 | + "34: movl %%edx, %%es:60(%3)\n" | |
12586 | + " addl $-64, %0\n" | |
12587 | + " addl $64, %4\n" | |
12588 | + " addl $64, %3\n" | |
12589 | + " cmpl $63, %0\n" | |
12590 | + " ja 1b\n" | |
12591 | + "35: movl %0, %%eax\n" | |
12592 | + " shrl $2, %0\n" | |
12593 | + " andl $3, %%eax\n" | |
12594 | + " cld\n" | |
12595 | + "99: rep; movsl\n" | |
12596 | + "36: movl %%eax, %0\n" | |
12597 | + "37: rep; movsb\n" | |
12598 | + "100:\n" | |
12599 | + " pushl %%ss\n" | |
de855c5d | 12600 | + " popl %%es\n" |
2380c486 JR |
12601 | + ".section .fixup,\"ax\"\n" |
12602 | + "101: lea 0(%%eax,%0,4),%0\n" | |
12603 | + " jmp 100b\n" | |
12604 | + ".previous\n" | |
12605 | + ".section __ex_table,\"a\"\n" | |
12606 | + " .align 4\n" | |
12607 | + " .long 1b,100b\n" | |
12608 | + " .long 2b,100b\n" | |
12609 | + " .long 3b,100b\n" | |
12610 | + " .long 4b,100b\n" | |
12611 | + " .long 5b,100b\n" | |
12612 | + " .long 6b,100b\n" | |
12613 | + " .long 7b,100b\n" | |
12614 | + " .long 8b,100b\n" | |
12615 | + " .long 9b,100b\n" | |
12616 | + " .long 10b,100b\n" | |
12617 | + " .long 11b,100b\n" | |
12618 | + " .long 12b,100b\n" | |
12619 | + " .long 13b,100b\n" | |
12620 | + " .long 14b,100b\n" | |
12621 | + " .long 15b,100b\n" | |
12622 | + " .long 16b,100b\n" | |
12623 | + " .long 17b,100b\n" | |
12624 | + " .long 18b,100b\n" | |
12625 | + " .long 19b,100b\n" | |
12626 | + " .long 20b,100b\n" | |
12627 | + " .long 21b,100b\n" | |
12628 | + " .long 22b,100b\n" | |
12629 | + " .long 23b,100b\n" | |
12630 | + " .long 24b,100b\n" | |
12631 | + " .long 25b,100b\n" | |
12632 | + " .long 26b,100b\n" | |
12633 | + " .long 27b,100b\n" | |
12634 | + " .long 28b,100b\n" | |
12635 | + " .long 29b,100b\n" | |
12636 | + " .long 30b,100b\n" | |
12637 | + " .long 31b,100b\n" | |
12638 | + " .long 32b,100b\n" | |
12639 | + " .long 33b,100b\n" | |
12640 | + " .long 34b,100b\n" | |
12641 | + " .long 35b,100b\n" | |
12642 | + " .long 36b,100b\n" | |
12643 | + " .long 37b,100b\n" | |
12644 | + " .long 99b,101b\n" | |
12645 | + ".previous" | |
12646 | + : "=&c"(size), "=&D" (d0), "=&S" (d1) | |
de855c5d AM |
12647 | + : "1"(to), "2"(from), "0"(size), "r"(__USER_DS) |
12648 | + : "eax", "edx", "memory"); | |
12649 | + return size; | |
12650 | +} | |
12651 | + | |
12652 | +static unsigned long | |
12653 | +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size) | |
12654 | { | |
12655 | int d0, d1; | |
12656 | __asm__ __volatile__( | |
12657 | + " movw %w6, %%ds\n" | |
12658 | " .align 2,0x90\n" | |
12659 | "1: movl 32(%4), %%eax\n" | |
12660 | " cmpl $67, %0\n" | |
12661 | @@ -239,36 +363,36 @@ __copy_user_intel(void __user *to, const | |
12662 | " .align 2,0x90\n" | |
12663 | "3: movl 0(%4), %%eax\n" | |
12664 | "4: movl 4(%4), %%edx\n" | |
12665 | - "5: movl %%eax, 0(%3)\n" | |
12666 | - "6: movl %%edx, 4(%3)\n" | |
12667 | + "5: movl %%eax, %%es:0(%3)\n" | |
12668 | + "6: movl %%edx, %%es:4(%3)\n" | |
12669 | "7: movl 8(%4), %%eax\n" | |
12670 | "8: movl 12(%4),%%edx\n" | |
12671 | - "9: movl %%eax, 8(%3)\n" | |
12672 | - "10: movl %%edx, 12(%3)\n" | |
12673 | + "9: movl %%eax, %%es:8(%3)\n" | |
12674 | + "10: movl %%edx, %%es:12(%3)\n" | |
12675 | "11: movl 16(%4), %%eax\n" | |
12676 | "12: movl 20(%4), %%edx\n" | |
12677 | - "13: movl %%eax, 16(%3)\n" | |
12678 | - "14: movl %%edx, 20(%3)\n" | |
12679 | + "13: movl %%eax, %%es:16(%3)\n" | |
12680 | + "14: movl %%edx, %%es:20(%3)\n" | |
12681 | "15: movl 24(%4), %%eax\n" | |
12682 | "16: movl 28(%4), %%edx\n" | |
12683 | - "17: movl %%eax, 24(%3)\n" | |
12684 | - "18: movl %%edx, 28(%3)\n" | |
12685 | + "17: movl %%eax, %%es:24(%3)\n" | |
12686 | + "18: movl %%edx, %%es:28(%3)\n" | |
12687 | "19: movl 32(%4), %%eax\n" | |
12688 | "20: movl 36(%4), %%edx\n" | |
12689 | - "21: movl %%eax, 32(%3)\n" | |
12690 | - "22: movl %%edx, 36(%3)\n" | |
12691 | + "21: movl %%eax, %%es:32(%3)\n" | |
12692 | + "22: movl %%edx, %%es:36(%3)\n" | |
12693 | "23: movl 40(%4), %%eax\n" | |
12694 | "24: movl 44(%4), %%edx\n" | |
12695 | - "25: movl %%eax, 40(%3)\n" | |
12696 | - "26: movl %%edx, 44(%3)\n" | |
12697 | + "25: movl %%eax, %%es:40(%3)\n" | |
12698 | + "26: movl %%edx, %%es:44(%3)\n" | |
12699 | "27: movl 48(%4), %%eax\n" | |
12700 | "28: movl 52(%4), %%edx\n" | |
12701 | - "29: movl %%eax, 48(%3)\n" | |
12702 | - "30: movl %%edx, 52(%3)\n" | |
12703 | + "29: movl %%eax, %%es:48(%3)\n" | |
12704 | + "30: movl %%edx, %%es:52(%3)\n" | |
12705 | "31: movl 56(%4), %%eax\n" | |
12706 | "32: movl 60(%4), %%edx\n" | |
12707 | - "33: movl %%eax, 56(%3)\n" | |
12708 | - "34: movl %%edx, 60(%3)\n" | |
12709 | + "33: movl %%eax, %%es:56(%3)\n" | |
12710 | + "34: movl %%edx, %%es:60(%3)\n" | |
12711 | " addl $-64, %0\n" | |
12712 | " addl $64, %4\n" | |
12713 | " addl $64, %3\n" | |
12714 | @@ -282,6 +406,8 @@ __copy_user_intel(void __user *to, const | |
12715 | "36: movl %%eax, %0\n" | |
12716 | "37: rep; movsb\n" | |
12717 | "100:\n" | |
12718 | + " pushl %%ss\n" | |
12719 | + " popl %%ds\n" | |
12720 | ".section .fixup,\"ax\"\n" | |
12721 | "101: lea 0(%%eax,%0,4),%0\n" | |
12722 | " jmp 100b\n" | |
12723 | @@ -328,7 +454,7 @@ __copy_user_intel(void __user *to, const | |
12724 | " .long 99b,101b\n" | |
12725 | ".previous" | |
12726 | : "=&c"(size), "=&D" (d0), "=&S" (d1) | |
12727 | - : "1"(to), "2"(from), "0"(size) | |
2380c486 JR |
12728 | + : "1"(to), "2"(from), "0"(size), "r"(__USER_DS) |
12729 | : "eax", "edx", "memory"); | |
12730 | return size; | |
12731 | } | |
12732 | @@ -338,6 +464,7 @@ __copy_user_zeroing_intel(void *to, cons | |
12733 | { | |
12734 | int d0, d1; | |
12735 | __asm__ __volatile__( | |
12736 | + " movw %w6, %%ds\n" | |
12737 | " .align 2,0x90\n" | |
12738 | "0: movl 32(%4), %%eax\n" | |
12739 | " cmpl $67, %0\n" | |
12740 | @@ -346,36 +473,36 @@ __copy_user_zeroing_intel(void *to, cons | |
12741 | " .align 2,0x90\n" | |
12742 | "2: movl 0(%4), %%eax\n" | |
12743 | "21: movl 4(%4), %%edx\n" | |
12744 | - " movl %%eax, 0(%3)\n" | |
12745 | - " movl %%edx, 4(%3)\n" | |
12746 | + " movl %%eax, %%es:0(%3)\n" | |
12747 | + " movl %%edx, %%es:4(%3)\n" | |
12748 | "3: movl 8(%4), %%eax\n" | |
12749 | "31: movl 12(%4),%%edx\n" | |
12750 | - " movl %%eax, 8(%3)\n" | |
12751 | - " movl %%edx, 12(%3)\n" | |
12752 | + " movl %%eax, %%es:8(%3)\n" | |
12753 | + " movl %%edx, %%es:12(%3)\n" | |
12754 | "4: movl 16(%4), %%eax\n" | |
12755 | "41: movl 20(%4), %%edx\n" | |
12756 | - " movl %%eax, 16(%3)\n" | |
12757 | - " movl %%edx, 20(%3)\n" | |
12758 | + " movl %%eax, %%es:16(%3)\n" | |
12759 | + " movl %%edx, %%es:20(%3)\n" | |
12760 | "10: movl 24(%4), %%eax\n" | |
12761 | "51: movl 28(%4), %%edx\n" | |
12762 | - " movl %%eax, 24(%3)\n" | |
12763 | - " movl %%edx, 28(%3)\n" | |
12764 | + " movl %%eax, %%es:24(%3)\n" | |
12765 | + " movl %%edx, %%es:28(%3)\n" | |
12766 | "11: movl 32(%4), %%eax\n" | |
12767 | "61: movl 36(%4), %%edx\n" | |
12768 | - " movl %%eax, 32(%3)\n" | |
12769 | - " movl %%edx, 36(%3)\n" | |
12770 | + " movl %%eax, %%es:32(%3)\n" | |
12771 | + " movl %%edx, %%es:36(%3)\n" | |
12772 | "12: movl 40(%4), %%eax\n" | |
12773 | "71: movl 44(%4), %%edx\n" | |
12774 | - " movl %%eax, 40(%3)\n" | |
12775 | - " movl %%edx, 44(%3)\n" | |
12776 | + " movl %%eax, %%es:40(%3)\n" | |
12777 | + " movl %%edx, %%es:44(%3)\n" | |
12778 | "13: movl 48(%4), %%eax\n" | |
12779 | "81: movl 52(%4), %%edx\n" | |
12780 | - " movl %%eax, 48(%3)\n" | |
12781 | - " movl %%edx, 52(%3)\n" | |
12782 | + " movl %%eax, %%es:48(%3)\n" | |
12783 | + " movl %%edx, %%es:52(%3)\n" | |
12784 | "14: movl 56(%4), %%eax\n" | |
12785 | "91: movl 60(%4), %%edx\n" | |
12786 | - " movl %%eax, 56(%3)\n" | |
12787 | - " movl %%edx, 60(%3)\n" | |
12788 | + " movl %%eax, %%es:56(%3)\n" | |
12789 | + " movl %%edx, %%es:60(%3)\n" | |
12790 | " addl $-64, %0\n" | |
12791 | " addl $64, %4\n" | |
12792 | " addl $64, %3\n" | |
12793 | @@ -389,6 +516,8 @@ __copy_user_zeroing_intel(void *to, cons | |
12794 | " movl %%eax,%0\n" | |
12795 | "7: rep; movsb\n" | |
12796 | "8:\n" | |
12797 | + " pushl %%ss\n" | |
12798 | + " popl %%ds\n" | |
12799 | ".section .fixup,\"ax\"\n" | |
12800 | "9: lea 0(%%eax,%0,4),%0\n" | |
12801 | "16: pushl %0\n" | |
12802 | @@ -423,7 +552,7 @@ __copy_user_zeroing_intel(void *to, cons | |
12803 | " .long 7b,16b\n" | |
12804 | ".previous" | |
12805 | : "=&c"(size), "=&D" (d0), "=&S" (d1) | |
12806 | - : "1"(to), "2"(from), "0"(size) | |
12807 | + : "1"(to), "2"(from), "0"(size), "r"(__USER_DS) | |
12808 | : "eax", "edx", "memory"); | |
12809 | return size; | |
12810 | } | |
12811 | @@ -439,6 +568,7 @@ static unsigned long __copy_user_zeroing | |
12812 | int d0, d1; | |
12813 | ||
12814 | __asm__ __volatile__( | |
12815 | + " movw %w6, %%ds\n" | |
12816 | " .align 2,0x90\n" | |
12817 | "0: movl 32(%4), %%eax\n" | |
12818 | " cmpl $67, %0\n" | |
12819 | @@ -447,36 +577,36 @@ static unsigned long __copy_user_zeroing | |
12820 | " .align 2,0x90\n" | |
12821 | "2: movl 0(%4), %%eax\n" | |
12822 | "21: movl 4(%4), %%edx\n" | |
12823 | - " movnti %%eax, 0(%3)\n" | |
12824 | - " movnti %%edx, 4(%3)\n" | |
12825 | + " movnti %%eax, %%es:0(%3)\n" | |
12826 | + " movnti %%edx, %%es:4(%3)\n" | |
12827 | "3: movl 8(%4), %%eax\n" | |
12828 | "31: movl 12(%4),%%edx\n" | |
12829 | - " movnti %%eax, 8(%3)\n" | |
12830 | - " movnti %%edx, 12(%3)\n" | |
12831 | + " movnti %%eax, %%es:8(%3)\n" | |
12832 | + " movnti %%edx, %%es:12(%3)\n" | |
12833 | "4: movl 16(%4), %%eax\n" | |
12834 | "41: movl 20(%4), %%edx\n" | |
12835 | - " movnti %%eax, 16(%3)\n" | |
12836 | - " movnti %%edx, 20(%3)\n" | |
12837 | + " movnti %%eax, %%es:16(%3)\n" | |
12838 | + " movnti %%edx, %%es:20(%3)\n" | |
12839 | "10: movl 24(%4), %%eax\n" | |
12840 | "51: movl 28(%4), %%edx\n" | |
12841 | - " movnti %%eax, 24(%3)\n" | |
12842 | - " movnti %%edx, 28(%3)\n" | |
12843 | + " movnti %%eax, %%es:24(%3)\n" | |
12844 | + " movnti %%edx, %%es:28(%3)\n" | |
12845 | "11: movl 32(%4), %%eax\n" | |
12846 | "61: movl 36(%4), %%edx\n" | |
12847 | - " movnti %%eax, 32(%3)\n" | |
12848 | - " movnti %%edx, 36(%3)\n" | |
12849 | + " movnti %%eax, %%es:32(%3)\n" | |
12850 | + " movnti %%edx, %%es:36(%3)\n" | |
12851 | "12: movl 40(%4), %%eax\n" | |
12852 | "71: movl 44(%4), %%edx\n" | |
12853 | - " movnti %%eax, 40(%3)\n" | |
12854 | - " movnti %%edx, 44(%3)\n" | |
12855 | + " movnti %%eax, %%es:40(%3)\n" | |
12856 | + " movnti %%edx, %%es:44(%3)\n" | |
12857 | "13: movl 48(%4), %%eax\n" | |
12858 | "81: movl 52(%4), %%edx\n" | |
12859 | - " movnti %%eax, 48(%3)\n" | |
12860 | - " movnti %%edx, 52(%3)\n" | |
12861 | + " movnti %%eax, %%es:48(%3)\n" | |
12862 | + " movnti %%edx, %%es:52(%3)\n" | |
12863 | "14: movl 56(%4), %%eax\n" | |
12864 | "91: movl 60(%4), %%edx\n" | |
12865 | - " movnti %%eax, 56(%3)\n" | |
12866 | - " movnti %%edx, 60(%3)\n" | |
12867 | + " movnti %%eax, %%es:56(%3)\n" | |
12868 | + " movnti %%edx, %%es:60(%3)\n" | |
12869 | " addl $-64, %0\n" | |
12870 | " addl $64, %4\n" | |
12871 | " addl $64, %3\n" | |
12872 | @@ -491,6 +621,8 @@ static unsigned long __copy_user_zeroing | |
12873 | " movl %%eax,%0\n" | |
12874 | "7: rep; movsb\n" | |
12875 | "8:\n" | |
12876 | + " pushl %%ss\n" | |
12877 | + " popl %%ds\n" | |
12878 | ".section .fixup,\"ax\"\n" | |
12879 | "9: lea 0(%%eax,%0,4),%0\n" | |
12880 | "16: pushl %0\n" | |
12881 | @@ -525,7 +657,7 @@ static unsigned long __copy_user_zeroing | |
12882 | " .long 7b,16b\n" | |
12883 | ".previous" | |
12884 | : "=&c"(size), "=&D" (d0), "=&S" (d1) | |
12885 | - : "1"(to), "2"(from), "0"(size) | |
12886 | + : "1"(to), "2"(from), "0"(size), "r"(__USER_DS) | |
12887 | : "eax", "edx", "memory"); | |
12888 | return size; | |
12889 | } | |
12890 | @@ -536,6 +668,7 @@ static unsigned long __copy_user_intel_n | |
12891 | int d0, d1; | |
12892 | ||
12893 | __asm__ __volatile__( | |
12894 | + " movw %w6, %%ds\n" | |
12895 | " .align 2,0x90\n" | |
12896 | "0: movl 32(%4), %%eax\n" | |
12897 | " cmpl $67, %0\n" | |
12898 | @@ -544,36 +677,36 @@ static unsigned long __copy_user_intel_n | |
12899 | " .align 2,0x90\n" | |
12900 | "2: movl 0(%4), %%eax\n" | |
12901 | "21: movl 4(%4), %%edx\n" | |
12902 | - " movnti %%eax, 0(%3)\n" | |
12903 | - " movnti %%edx, 4(%3)\n" | |
12904 | + " movnti %%eax, %%es:0(%3)\n" | |
12905 | + " movnti %%edx, %%es:4(%3)\n" | |
12906 | "3: movl 8(%4), %%eax\n" | |
12907 | "31: movl 12(%4),%%edx\n" | |
12908 | - " movnti %%eax, 8(%3)\n" | |
12909 | - " movnti %%edx, 12(%3)\n" | |
12910 | + " movnti %%eax, %%es:8(%3)\n" | |
12911 | + " movnti %%edx, %%es:12(%3)\n" | |
12912 | "4: movl 16(%4), %%eax\n" | |
12913 | "41: movl 20(%4), %%edx\n" | |
12914 | - " movnti %%eax, 16(%3)\n" | |
12915 | - " movnti %%edx, 20(%3)\n" | |
12916 | + " movnti %%eax, %%es:16(%3)\n" | |
12917 | + " movnti %%edx, %%es:20(%3)\n" | |
12918 | "10: movl 24(%4), %%eax\n" | |
12919 | "51: movl 28(%4), %%edx\n" | |
12920 | - " movnti %%eax, 24(%3)\n" | |
12921 | - " movnti %%edx, 28(%3)\n" | |
12922 | + " movnti %%eax, %%es:24(%3)\n" | |
12923 | + " movnti %%edx, %%es:28(%3)\n" | |
12924 | "11: movl 32(%4), %%eax\n" | |
12925 | "61: movl 36(%4), %%edx\n" | |
12926 | - " movnti %%eax, 32(%3)\n" | |
12927 | - " movnti %%edx, 36(%3)\n" | |
12928 | + " movnti %%eax, %%es:32(%3)\n" | |
12929 | + " movnti %%edx, %%es:36(%3)\n" | |
12930 | "12: movl 40(%4), %%eax\n" | |
12931 | "71: movl 44(%4), %%edx\n" | |
12932 | - " movnti %%eax, 40(%3)\n" | |
12933 | - " movnti %%edx, 44(%3)\n" | |
12934 | + " movnti %%eax, %%es:40(%3)\n" | |
12935 | + " movnti %%edx, %%es:44(%3)\n" | |
12936 | "13: movl 48(%4), %%eax\n" | |
12937 | "81: movl 52(%4), %%edx\n" | |
12938 | - " movnti %%eax, 48(%3)\n" | |
12939 | - " movnti %%edx, 52(%3)\n" | |
12940 | + " movnti %%eax, %%es:48(%3)\n" | |
12941 | + " movnti %%edx, %%es:52(%3)\n" | |
12942 | "14: movl 56(%4), %%eax\n" | |
12943 | "91: movl 60(%4), %%edx\n" | |
12944 | - " movnti %%eax, 56(%3)\n" | |
12945 | - " movnti %%edx, 60(%3)\n" | |
12946 | + " movnti %%eax, %%es:56(%3)\n" | |
12947 | + " movnti %%edx, %%es:60(%3)\n" | |
12948 | " addl $-64, %0\n" | |
12949 | " addl $64, %4\n" | |
12950 | " addl $64, %3\n" | |
12951 | @@ -588,6 +721,8 @@ static unsigned long __copy_user_intel_n | |
12952 | " movl %%eax,%0\n" | |
12953 | "7: rep; movsb\n" | |
12954 | "8:\n" | |
12955 | + " pushl %%ss\n" | |
12956 | + " popl %%ds\n" | |
12957 | ".section .fixup,\"ax\"\n" | |
12958 | "9: lea 0(%%eax,%0,4),%0\n" | |
12959 | "16: jmp 8b\n" | |
12960 | @@ -616,7 +751,7 @@ static unsigned long __copy_user_intel_n | |
12961 | " .long 7b,16b\n" | |
12962 | ".previous" | |
12963 | : "=&c"(size), "=&D" (d0), "=&S" (d1) | |
12964 | - : "1"(to), "2"(from), "0"(size) | |
12965 | + : "1"(to), "2"(from), "0"(size), "r"(__USER_DS) | |
12966 | : "eax", "edx", "memory"); | |
12967 | return size; | |
12968 | } | |
12969 | @@ -629,90 +764,146 @@ static unsigned long __copy_user_intel_n | |
12970 | */ | |
12971 | unsigned long __copy_user_zeroing_intel(void *to, const void __user *from, | |
12972 | unsigned long size); | |
12973 | -unsigned long __copy_user_intel(void __user *to, const void *from, | |
12974 | +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from, | |
12975 | + unsigned long size); | |
12976 | +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from, | |
12977 | unsigned long size); | |
12978 | unsigned long __copy_user_zeroing_intel_nocache(void *to, | |
12979 | const void __user *from, unsigned long size); | |
12980 | #endif /* CONFIG_X86_INTEL_USERCOPY */ | |
12981 | ||
12982 | /* Generic arbitrary sized copy. */ | |
12983 | -#define __copy_user(to, from, size) \ | |
12984 | -do { \ | |
12985 | - int __d0, __d1, __d2; \ | |
12986 | - __asm__ __volatile__( \ | |
12987 | - " cmp $7,%0\n" \ | |
12988 | - " jbe 1f\n" \ | |
12989 | - " movl %1,%0\n" \ | |
12990 | - " negl %0\n" \ | |
12991 | - " andl $7,%0\n" \ | |
12992 | - " subl %0,%3\n" \ | |
12993 | - "4: rep; movsb\n" \ | |
12994 | - " movl %3,%0\n" \ | |
12995 | - " shrl $2,%0\n" \ | |
12996 | - " andl $3,%3\n" \ | |
12997 | - " .align 2,0x90\n" \ | |
12998 | - "0: rep; movsl\n" \ | |
12999 | - " movl %3,%0\n" \ | |
13000 | - "1: rep; movsb\n" \ | |
13001 | - "2:\n" \ | |
13002 | - ".section .fixup,\"ax\"\n" \ | |
13003 | - "5: addl %3,%0\n" \ | |
13004 | - " jmp 2b\n" \ | |
13005 | - "3: lea 0(%3,%0,4),%0\n" \ | |
13006 | - " jmp 2b\n" \ | |
13007 | - ".previous\n" \ | |
13008 | - ".section __ex_table,\"a\"\n" \ | |
13009 | - " .align 4\n" \ | |
13010 | - " .long 4b,5b\n" \ | |
13011 | - " .long 0b,3b\n" \ | |
13012 | - " .long 1b,2b\n" \ | |
13013 | - ".previous" \ | |
13014 | - : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \ | |
13015 | - : "3"(size), "0"(size), "1"(to), "2"(from) \ | |
13016 | - : "memory"); \ | |
13017 | -} while (0) | |
13018 | - | |
13019 | -#define __copy_user_zeroing(to, from, size) \ | |
13020 | -do { \ | |
13021 | - int __d0, __d1, __d2; \ | |
13022 | - __asm__ __volatile__( \ | |
13023 | - " cmp $7,%0\n" \ | |
13024 | - " jbe 1f\n" \ | |
13025 | - " movl %1,%0\n" \ | |
13026 | - " negl %0\n" \ | |
13027 | - " andl $7,%0\n" \ | |
13028 | - " subl %0,%3\n" \ | |
13029 | - "4: rep; movsb\n" \ | |
13030 | - " movl %3,%0\n" \ | |
13031 | - " shrl $2,%0\n" \ | |
13032 | - " andl $3,%3\n" \ | |
13033 | - " .align 2,0x90\n" \ | |
13034 | - "0: rep; movsl\n" \ | |
13035 | - " movl %3,%0\n" \ | |
13036 | - "1: rep; movsb\n" \ | |
13037 | - "2:\n" \ | |
13038 | - ".section .fixup,\"ax\"\n" \ | |
13039 | - "5: addl %3,%0\n" \ | |
13040 | - " jmp 6f\n" \ | |
13041 | - "3: lea 0(%3,%0,4),%0\n" \ | |
13042 | - "6: pushl %0\n" \ | |
13043 | - " pushl %%eax\n" \ | |
13044 | - " xorl %%eax,%%eax\n" \ | |
13045 | - " rep; stosb\n" \ | |
13046 | - " popl %%eax\n" \ | |
13047 | - " popl %0\n" \ | |
13048 | - " jmp 2b\n" \ | |
13049 | - ".previous\n" \ | |
13050 | - ".section __ex_table,\"a\"\n" \ | |
13051 | - " .align 4\n" \ | |
13052 | - " .long 4b,5b\n" \ | |
13053 | - " .long 0b,3b\n" \ | |
13054 | - " .long 1b,6b\n" \ | |
13055 | - ".previous" \ | |
13056 | - : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \ | |
13057 | - : "3"(size), "0"(size), "1"(to), "2"(from) \ | |
13058 | - : "memory"); \ | |
13059 | -} while (0) | |
13060 | +static unsigned long | |
13061 | +__generic_copy_to_user(void __user *to, const void *from, unsigned long size) | |
13062 | +{ | |
13063 | + int __d0, __d1, __d2; | |
13064 | + | |
13065 | + __asm__ __volatile__( | |
13066 | + " movw %w8,%%es\n" | |
13067 | + " cmp $7,%0\n" | |
13068 | + " jbe 1f\n" | |
13069 | + " movl %1,%0\n" | |
13070 | + " negl %0\n" | |
13071 | + " andl $7,%0\n" | |
13072 | + " subl %0,%3\n" | |
13073 | + "4: rep; movsb\n" | |
13074 | + " movl %3,%0\n" | |
13075 | + " shrl $2,%0\n" | |
13076 | + " andl $3,%3\n" | |
13077 | + " .align 2,0x90\n" | |
13078 | + "0: rep; movsl\n" | |
13079 | + " movl %3,%0\n" | |
13080 | + "1: rep; movsb\n" | |
13081 | + "2:\n" | |
13082 | + " pushl %%ss\n" | |
13083 | + " popl %%es\n" | |
13084 | + ".section .fixup,\"ax\"\n" | |
13085 | + "5: addl %3,%0\n" | |
13086 | + " jmp 2b\n" | |
13087 | + "3: lea 0(%3,%0,4),%0\n" | |
13088 | + " jmp 2b\n" | |
13089 | + ".previous\n" | |
13090 | + ".section __ex_table,\"a\"\n" | |
13091 | + " .align 4\n" | |
13092 | + " .long 4b,5b\n" | |
13093 | + " .long 0b,3b\n" | |
13094 | + " .long 1b,2b\n" | |
13095 | + ".previous" | |
13096 | + : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) | |
13097 | + : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS) | |
13098 | + : "memory"); | |
13099 | + return size; | |
13100 | +} | |
13101 | + | |
13102 | +static unsigned long | |
13103 | +__generic_copy_from_user(void *to, const void __user *from, unsigned long size) | |
13104 | +{ | |
13105 | + int __d0, __d1, __d2; | |
13106 | + | |
13107 | + __asm__ __volatile__( | |
13108 | + " movw %w8,%%ds\n" | |
13109 | + " cmp $7,%0\n" | |
13110 | + " jbe 1f\n" | |
13111 | + " movl %1,%0\n" | |
13112 | + " negl %0\n" | |
13113 | + " andl $7,%0\n" | |
13114 | + " subl %0,%3\n" | |
13115 | + "4: rep; movsb\n" | |
13116 | + " movl %3,%0\n" | |
13117 | + " shrl $2,%0\n" | |
13118 | + " andl $3,%3\n" | |
13119 | + " .align 2,0x90\n" | |
13120 | + "0: rep; movsl\n" | |
13121 | + " movl %3,%0\n" | |
13122 | + "1: rep; movsb\n" | |
13123 | + "2:\n" | |
13124 | + " pushl %%ss\n" | |
13125 | + " popl %%ds\n" | |
13126 | + ".section .fixup,\"ax\"\n" | |
13127 | + "5: addl %3,%0\n" | |
13128 | + " jmp 2b\n" | |
13129 | + "3: lea 0(%3,%0,4),%0\n" | |
13130 | + " jmp 2b\n" | |
13131 | + ".previous\n" | |
13132 | + ".section __ex_table,\"a\"\n" | |
13133 | + " .align 4\n" | |
13134 | + " .long 4b,5b\n" | |
13135 | + " .long 0b,3b\n" | |
13136 | + " .long 1b,2b\n" | |
13137 | + ".previous" | |
13138 | + : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) | |
13139 | + : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS) | |
13140 | + : "memory"); | |
13141 | + return size; | |
13142 | +} | |
13143 | + | |
13144 | +static unsigned long | |
13145 | +__copy_user_zeroing(void *to, const void __user *from, unsigned long size) | |
13146 | +{ | |
13147 | + int __d0, __d1, __d2; | |
13148 | + | |
13149 | + __asm__ __volatile__( | |
13150 | + " movw %w8,%%ds\n" | |
13151 | + " cmp $7,%0\n" | |
13152 | + " jbe 1f\n" | |
13153 | + " movl %1,%0\n" | |
13154 | + " negl %0\n" | |
13155 | + " andl $7,%0\n" | |
13156 | + " subl %0,%3\n" | |
13157 | + "4: rep; movsb\n" | |
13158 | + " movl %3,%0\n" | |
13159 | + " shrl $2,%0\n" | |
13160 | + " andl $3,%3\n" | |
13161 | + " .align 2,0x90\n" | |
13162 | + "0: rep; movsl\n" | |
13163 | + " movl %3,%0\n" | |
13164 | + "1: rep; movsb\n" | |
13165 | + "2:\n" | |
13166 | + " pushl %%ss\n" | |
13167 | + " popl %%ds\n" | |
13168 | + ".section .fixup,\"ax\"\n" | |
13169 | + "5: addl %3,%0\n" | |
13170 | + " jmp 6f\n" | |
13171 | + "3: lea 0(%3,%0,4),%0\n" | |
13172 | + "6: pushl %0\n" | |
13173 | + " pushl %%eax\n" | |
13174 | + " xorl %%eax,%%eax\n" | |
13175 | + " rep; stosb\n" | |
13176 | + " popl %%eax\n" | |
13177 | + " popl %0\n" | |
13178 | + " jmp 2b\n" | |
13179 | + ".previous\n" | |
13180 | + ".section __ex_table,\"a\"\n" | |
13181 | + " .align 4\n" | |
13182 | + " .long 4b,5b\n" | |
13183 | + " .long 0b,3b\n" | |
13184 | + " .long 1b,6b\n" | |
13185 | + ".previous" | |
13186 | + : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) | |
13187 | + : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS) | |
13188 | + : "memory"); | |
13189 | + return size; | |
13190 | +} | |
13191 | ||
13192 | unsigned long __copy_to_user_ll(void __user *to, const void *from, | |
13193 | unsigned long n) | |
13194 | @@ -775,9 +966,9 @@ survive: | |
13195 | } | |
13196 | #endif | |
13197 | if (movsl_is_ok(to, from, n)) | |
13198 | - __copy_user(to, from, n); | |
13199 | + n = __generic_copy_to_user(to, from, n); | |
13200 | else | |
13201 | - n = __copy_user_intel(to, from, n); | |
13202 | + n = __generic_copy_to_user_intel(to, from, n); | |
13203 | return n; | |
13204 | } | |
13205 | EXPORT_SYMBOL(__copy_to_user_ll); | |
13206 | @@ -786,7 +977,7 @@ unsigned long __copy_from_user_ll(void * | |
13207 | unsigned long n) | |
13208 | { | |
13209 | if (movsl_is_ok(to, from, n)) | |
13210 | - __copy_user_zeroing(to, from, n); | |
13211 | + n = __copy_user_zeroing(to, from, n); | |
13212 | else | |
13213 | n = __copy_user_zeroing_intel(to, from, n); | |
13214 | return n; | |
13215 | @@ -797,10 +988,9 @@ unsigned long __copy_from_user_ll_nozero | |
13216 | unsigned long n) | |
13217 | { | |
13218 | if (movsl_is_ok(to, from, n)) | |
13219 | - __copy_user(to, from, n); | |
13220 | + n = __generic_copy_from_user(to, from, n); | |
13221 | else | |
13222 | - n = __copy_user_intel((void __user *)to, | |
13223 | - (const void *)from, n); | |
13224 | + n = __generic_copy_from_user_intel(to, from, n); | |
13225 | return n; | |
13226 | } | |
13227 | EXPORT_SYMBOL(__copy_from_user_ll_nozero); | |
13228 | @@ -812,9 +1002,9 @@ unsigned long __copy_from_user_ll_nocach | |
13229 | if (n > 64 && cpu_has_xmm2) | |
13230 | n = __copy_user_zeroing_intel_nocache(to, from, n); | |
13231 | else | |
13232 | - __copy_user_zeroing(to, from, n); | |
13233 | + n = __copy_user_zeroing(to, from, n); | |
13234 | #else | |
13235 | - __copy_user_zeroing(to, from, n); | |
13236 | + n = __copy_user_zeroing(to, from, n); | |
13237 | #endif | |
13238 | return n; | |
13239 | } | |
de855c5d | 13240 | @@ -827,59 +1017,37 @@ unsigned long __copy_from_user_ll_nocach |
2380c486 JR |
13241 | if (n > 64 && cpu_has_xmm2) |
13242 | n = __copy_user_intel_nocache(to, from, n); | |
13243 | else | |
13244 | - __copy_user(to, from, n); | |
13245 | + n = __generic_copy_from_user(to, from, n); | |
13246 | #else | |
13247 | - __copy_user(to, from, n); | |
13248 | + n = __generic_copy_from_user(to, from, n); | |
13249 | #endif | |
13250 | return n; | |
13251 | } | |
de855c5d AM |
13252 | EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero); |
13253 | ||
13254 | -/** | |
13255 | - * copy_to_user: - Copy a block of data into user space. | |
13256 | - * @to: Destination address, in user space. | |
13257 | - * @from: Source address, in kernel space. | |
13258 | - * @n: Number of bytes to copy. | |
13259 | - * | |
13260 | - * Context: User context only. This function may sleep. | |
13261 | - * | |
13262 | - * Copy data from kernel space to user space. | |
13263 | - * | |
13264 | - * Returns number of bytes that could not be copied. | |
13265 | - * On success, this will be zero. | |
13266 | - */ | |
13267 | -unsigned long | |
13268 | -copy_to_user(void __user *to, const void *from, unsigned long n) | |
2380c486 JR |
13269 | +#ifdef CONFIG_PAX_MEMORY_UDEREF |
13270 | +void __set_fs(mm_segment_t x, int cpu) | |
de855c5d AM |
13271 | { |
13272 | - if (access_ok(VERIFY_WRITE, to, n)) | |
13273 | - n = __copy_to_user(to, from, n); | |
13274 | - return n; | |
2380c486 JR |
13275 | + unsigned long limit = x.seg; |
13276 | + struct desc_struct d; | |
13277 | + | |
13278 | + current_thread_info()->addr_limit = x; | |
13279 | + if (likely(limit)) | |
13280 | + limit = (limit - 1UL) >> PAGE_SHIFT; | |
13281 | + pack_descriptor(&d, 0UL, limit, 0xF3, 0xC); | |
13282 | + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S); | |
de855c5d AM |
13283 | } |
13284 | -EXPORT_SYMBOL(copy_to_user); | |
13285 | ||
13286 | -/** | |
13287 | - * copy_from_user: - Copy a block of data from user space. | |
13288 | - * @to: Destination address, in kernel space. | |
13289 | - * @from: Source address, in user space. | |
13290 | - * @n: Number of bytes to copy. | |
13291 | - * | |
13292 | - * Context: User context only. This function may sleep. | |
13293 | - * | |
13294 | - * Copy data from user space to kernel space. | |
13295 | - * | |
13296 | - * Returns number of bytes that could not be copied. | |
13297 | - * On success, this will be zero. | |
13298 | - * | |
13299 | - * If some data could not be copied, this function will pad the copied | |
13300 | - * data to the requested size using zero bytes. | |
13301 | - */ | |
13302 | -unsigned long | |
13303 | -copy_from_user(void *to, const void __user *from, unsigned long n) | |
2380c486 | 13304 | +void set_fs(mm_segment_t x) |
de855c5d AM |
13305 | { |
13306 | - if (access_ok(VERIFY_READ, from, n)) | |
13307 | - n = __copy_from_user(to, from, n); | |
13308 | - else | |
13309 | - memset(to, 0, n); | |
13310 | - return n; | |
2380c486 JR |
13311 | + __set_fs(x, get_cpu()); |
13312 | + put_cpu_no_resched(); | |
de855c5d AM |
13313 | } |
13314 | -EXPORT_SYMBOL(copy_from_user); | |
2380c486 JR |
13315 | +#else |
13316 | +void set_fs(mm_segment_t x) | |
13317 | +{ | |
13318 | + current_thread_info()->addr_limit = x; | |
13319 | +} | |
13320 | +#endif | |
13321 | + | |
13322 | +EXPORT_SYMBOL(set_fs); | |
de855c5d AM |
13323 | diff -urNp linux-2.6.29.6/arch/x86/mach-voyager/voyager_basic.c linux-2.6.29.6/arch/x86/mach-voyager/voyager_basic.c |
13324 | --- linux-2.6.29.6/arch/x86/mach-voyager/voyager_basic.c 2009-07-02 19:41:20.000000000 -0400 | |
13325 | +++ linux-2.6.29.6/arch/x86/mach-voyager/voyager_basic.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
13326 | @@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg |
13327 | __u8 cmos[4]; | |
13328 | ClickMap_t *map; | |
13329 | unsigned long map_addr; | |
13330 | - unsigned long old; | |
13331 | + pte_t old; | |
13332 | ||
13333 | if (region >= CLICK_ENTRIES) { | |
13334 | printk("Voyager: Illegal ClickMap region %d\n", region); | |
13335 | @@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg | |
13336 | ||
13337 | /* steal page 0 for this */ | |
13338 | old = pg0[0]; | |
13339 | - pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT); | |
13340 | + pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT); | |
13341 | local_flush_tlb(); | |
13342 | /* now clear everything out but page 0 */ | |
13343 | map = (ClickMap_t *) (map_addr & (~PAGE_MASK)); | |
de855c5d AM |
13344 | diff -urNp linux-2.6.29.6/arch/x86/mach-voyager/voyager_smp.c linux-2.6.29.6/arch/x86/mach-voyager/voyager_smp.c |
13345 | --- linux-2.6.29.6/arch/x86/mach-voyager/voyager_smp.c 2009-07-02 19:41:20.000000000 -0400 | |
13346 | +++ linux-2.6.29.6/arch/x86/mach-voyager/voyager_smp.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
13347 | @@ -511,6 +511,10 @@ static void __init do_boot_cpu(__u8 cpu) |
13348 | __u32 *hijack_vector; | |
13349 | __u32 start_phys_address = setup_trampoline(); | |
13350 | ||
13351 | +#ifdef CONFIG_PAX_KERNEXEC | |
13352 | + unsigned long cr0; | |
13353 | +#endif | |
13354 | + | |
13355 | /* There's a clever trick to this: The linux trampoline is | |
13356 | * compiled to begin at absolute location zero, so make the | |
13357 | * address zero but have the data segment selector compensate | |
13358 | @@ -530,7 +534,17 @@ static void __init do_boot_cpu(__u8 cpu) | |
13359 | ||
13360 | init_gdt(cpu); | |
13361 | per_cpu(current_task, cpu) = idle; | |
13362 | - early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); | |
13363 | + | |
13364 | +#ifdef CONFIG_PAX_KERNEXEC | |
13365 | + pax_open_kernel(cr0); | |
13366 | +#endif | |
13367 | + | |
13368 | + early_gdt_descr.address = get_cpu_gdt_table(cpu); | |
13369 | + | |
13370 | +#ifdef CONFIG_PAX_KERNEXEC | |
13371 | + pax_close_kernel(cr0); | |
13372 | +#endif | |
13373 | + | |
13374 | irq_ctx_init(cpu); | |
13375 | ||
13376 | /* Note: Don't modify initial ss override */ | |
13377 | @@ -1144,7 +1158,7 @@ void smp_local_timer_interrupt(void) | |
13378 | per_cpu(prof_counter, cpu); | |
13379 | } | |
13380 | ||
13381 | - update_process_times(user_mode_vm(get_irq_regs())); | |
13382 | + update_process_times(user_mode(get_irq_regs())); | |
13383 | } | |
13384 | ||
13385 | if (((1 << cpu) & voyager_extended_vic_processors) == 0) | |
de855c5d AM |
13386 | diff -urNp linux-2.6.29.6/arch/x86/Makefile linux-2.6.29.6/arch/x86/Makefile |
13387 | --- linux-2.6.29.6/arch/x86/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
13388 | +++ linux-2.6.29.6/arch/x86/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
13389 | @@ -232,3 +232,12 @@ endef |
13390 | CLEAN_FILES += arch/x86/boot/fdimage \ | |
13391 | arch/x86/boot/image.iso \ | |
13392 | arch/x86/boot/mtools.conf | |
13393 | + | |
13394 | +define OLD_LD | |
13395 | + | |
13396 | +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils. | |
13397 | +*** Please upgrade your binutils to 2.18 or newer | |
13398 | +endef | |
13399 | + | |
13400 | +archprepare: | |
13401 | + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD))) | |
de855c5d AM |
13402 | diff -urNp linux-2.6.29.6/arch/x86/mm/extable.c linux-2.6.29.6/arch/x86/mm/extable.c |
13403 | --- linux-2.6.29.6/arch/x86/mm/extable.c 2009-07-02 19:41:20.000000000 -0400 | |
13404 | +++ linux-2.6.29.6/arch/x86/mm/extable.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
13405 | @@ -1,14 +1,62 @@ |
13406 | #include <linux/module.h> | |
13407 | #include <linux/spinlock.h> | |
13408 | +#include <linux/sort.h> | |
13409 | #include <asm/uaccess.h> | |
13410 | ||
13411 | +/* | |
13412 | + * The exception table needs to be sorted so that the binary | |
13413 | + * search that we use to find entries in it works properly. | |
13414 | + * This is used both for the kernel exception table and for | |
13415 | + * the exception tables of modules that get loaded. | |
13416 | + */ | |
13417 | +static int cmp_ex(const void *a, const void *b) | |
13418 | +{ | |
13419 | + const struct exception_table_entry *x = a, *y = b; | |
13420 | + | |
13421 | + /* avoid overflow */ | |
13422 | + if (x->insn > y->insn) | |
13423 | + return 1; | |
13424 | + if (x->insn < y->insn) | |
13425 | + return -1; | |
13426 | + return 0; | |
13427 | +} | |
13428 | + | |
13429 | +static void swap_ex(void *a, void *b, int size) | |
13430 | +{ | |
13431 | + struct exception_table_entry t, *x = a, *y = b; | |
13432 | + | |
13433 | +#ifdef CONFIG_PAX_KERNEXEC | |
13434 | + unsigned long cr0; | |
13435 | +#endif | |
13436 | + | |
13437 | + t = *x; | |
13438 | + | |
13439 | +#ifdef CONFIG_PAX_KERNEXEC | |
13440 | + pax_open_kernel(cr0); | |
13441 | +#endif | |
13442 | + | |
13443 | + *x = *y; | |
13444 | + *y = t; | |
13445 | + | |
13446 | +#ifdef CONFIG_PAX_KERNEXEC | |
13447 | + pax_close_kernel(cr0); | |
13448 | +#endif | |
13449 | + | |
13450 | +} | |
13451 | + | |
13452 | +void sort_extable(struct exception_table_entry *start, | |
13453 | + struct exception_table_entry *finish) | |
13454 | +{ | |
13455 | + sort(start, finish - start, sizeof(struct exception_table_entry), | |
13456 | + cmp_ex, swap_ex); | |
13457 | +} | |
13458 | ||
13459 | int fixup_exception(struct pt_regs *regs) | |
13460 | { | |
13461 | const struct exception_table_entry *fixup; | |
13462 | ||
13463 | #ifdef CONFIG_PNPBIOS | |
13464 | - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) { | |
13465 | + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) { | |
13466 | extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp; | |
13467 | extern u32 pnp_bios_is_utter_crap; | |
13468 | pnp_bios_is_utter_crap = 1; | |
de855c5d AM |
13469 | diff -urNp linux-2.6.29.6/arch/x86/mm/fault.c linux-2.6.29.6/arch/x86/mm/fault.c |
13470 | --- linux-2.6.29.6/arch/x86/mm/fault.c 2009-07-02 19:41:20.000000000 -0400 | |
13471 | +++ linux-2.6.29.6/arch/x86/mm/fault.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
13472 | @@ -26,6 +26,8 @@ |
13473 | #include <linux/kprobes.h> | |
13474 | #include <linux/uaccess.h> | |
13475 | #include <linux/kdebug.h> | |
13476 | +#include <linux/unistd.h> | |
13477 | +#include <linux/compiler.h> | |
13478 | ||
13479 | #include <asm/system.h> | |
13480 | #include <asm/desc.h> | |
13481 | @@ -67,7 +69,7 @@ static inline int notify_page_fault(stru | |
13482 | int ret = 0; | |
13483 | ||
13484 | /* kprobe_running() needs smp_processor_id() */ | |
13485 | - if (!user_mode_vm(regs)) { | |
13486 | + if (!user_mode(regs)) { | |
13487 | preempt_disable(); | |
13488 | if (kprobe_running() && kprobe_fault_handler(regs, 14)) | |
13489 | ret = 1; | |
13490 | @@ -265,6 +267,30 @@ bad: | |
13491 | #endif | |
13492 | } | |
13493 | ||
13494 | +#ifdef CONFIG_PAX_EMUTRAMP | |
13495 | +static int pax_handle_fetch_fault(struct pt_regs *regs); | |
13496 | +#endif | |
13497 | + | |
13498 | +#ifdef CONFIG_PAX_PAGEEXEC | |
13499 | +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address) | |
13500 | +{ | |
13501 | + pgd_t *pgd; | |
13502 | + pud_t *pud; | |
13503 | + pmd_t *pmd; | |
13504 | + | |
13505 | + pgd = pgd_offset(mm, address); | |
13506 | + if (!pgd_present(*pgd)) | |
13507 | + return NULL; | |
13508 | + pud = pud_offset(pgd, address); | |
13509 | + if (!pud_present(*pud)) | |
13510 | + return NULL; | |
13511 | + pmd = pmd_offset(pud, address); | |
13512 | + if (!pmd_present(*pmd)) | |
13513 | + return NULL; | |
13514 | + return pmd; | |
13515 | +} | |
13516 | +#endif | |
13517 | + | |
13518 | #ifdef CONFIG_X86_32 | |
13519 | static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) | |
13520 | { | |
13521 | @@ -351,7 +377,7 @@ static int is_errata93(struct pt_regs *r | |
13522 | static int is_errata100(struct pt_regs *regs, unsigned long address) | |
13523 | { | |
13524 | #ifdef CONFIG_X86_64 | |
13525 | - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && | |
13526 | + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && | |
13527 | (address >> 32)) | |
13528 | return 1; | |
13529 | #endif | |
13530 | @@ -386,14 +412,31 @@ static void show_fault_oops(struct pt_re | |
13531 | #endif | |
13532 | ||
13533 | #ifdef CONFIG_X86_PAE | |
13534 | - if (error_code & PF_INSTR) { | |
13535 | + if (nx_enabled && (error_code & PF_INSTR)) { | |
13536 | unsigned int level; | |
13537 | pte_t *pte = lookup_address(address, &level); | |
13538 | ||
13539 | if (pte && pte_present(*pte) && !pte_exec(*pte)) | |
13540 | printk(KERN_CRIT "kernel tried to execute " | |
13541 | "NX-protected page - exploit attempt? " | |
13542 | - "(uid: %d)\n", current_uid()); | |
13543 | + "(uid: %d, task: %s, pid: %d)\n", | |
13544 | + current_uid(), current->comm, task_pid_nr(current)); | |
13545 | + } | |
13546 | +#endif | |
13547 | + | |
13548 | +#ifdef CONFIG_PAX_KERNEXEC | |
13549 | +#ifdef CONFIG_MODULES | |
13550 | + if (init_mm.start_code <= address && address < (unsigned long)MODULES_END) | |
13551 | +#else | |
13552 | + if (init_mm.start_code <= address && address < init_mm.end_code) | |
13553 | +#endif | |
13554 | + { | |
13555 | + if (current->signal->curr_ip) | |
13556 | + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", | |
13557 | + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current_uid(), current_euid()); | |
13558 | + else | |
13559 | + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", | |
13560 | + current->comm, task_pid_nr(current), current_uid(), current_euid()); | |
13561 | } | |
13562 | #endif | |
13563 | ||
13564 | @@ -586,7 +629,6 @@ void __kprobes do_page_fault(struct pt_r | |
13565 | struct task_struct *tsk; | |
13566 | struct mm_struct *mm; | |
13567 | struct vm_area_struct *vma; | |
13568 | - unsigned long address; | |
13569 | int write, si_code; | |
13570 | int fault; | |
13571 | #ifdef CONFIG_X86_64 | |
13572 | @@ -594,13 +636,20 @@ void __kprobes do_page_fault(struct pt_r | |
13573 | int sig; | |
13574 | #endif | |
13575 | ||
13576 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) | |
13577 | + pte_t *pte; | |
13578 | + pmd_t *pmd; | |
13579 | + spinlock_t *ptl; | |
13580 | + unsigned char pte_mask; | |
13581 | +#endif | |
13582 | + | |
13583 | + /* get the address */ | |
13584 | + const unsigned long address = read_cr2(); | |
13585 | + | |
13586 | tsk = current; | |
13587 | mm = tsk->mm; | |
13588 | prefetchw(&mm->mmap_sem); | |
13589 | ||
13590 | - /* get the address */ | |
13591 | - address = read_cr2(); | |
13592 | - | |
13593 | si_code = SEGV_MAPERR; | |
13594 | ||
13595 | if (unlikely(kmmio_fault(regs, address))) | |
13596 | @@ -653,7 +702,7 @@ void __kprobes do_page_fault(struct pt_r | |
13597 | * User-mode registers count as a user access even for any | |
13598 | * potential system fault or CPU buglet. | |
13599 | */ | |
13600 | - if (user_mode_vm(regs)) { | |
13601 | + if (user_mode(regs)) { | |
13602 | local_irq_enable(); | |
13603 | error_code |= PF_USER; | |
13604 | } else if (regs->flags & X86_EFLAGS_IF) | |
13605 | @@ -669,7 +718,7 @@ void __kprobes do_page_fault(struct pt_r | |
13606 | * atomic region then we must not take the fault. | |
13607 | */ | |
13608 | if (unlikely(in_atomic() || !mm)) | |
13609 | - goto bad_area_nosemaphore; | |
13610 | + goto bad_area_nopax; | |
13611 | ||
13612 | /* | |
13613 | * When running in the kernel we expect faults to occur only to | |
13614 | @@ -690,10 +739,104 @@ void __kprobes do_page_fault(struct pt_r | |
13615 | if (!down_read_trylock(&mm->mmap_sem)) { | |
13616 | if ((error_code & PF_USER) == 0 && | |
13617 | !search_exception_tables(regs->ip)) | |
13618 | - goto bad_area_nosemaphore; | |
13619 | + goto bad_area_nopax; | |
13620 | down_read(&mm->mmap_sem); | |
13621 | } | |
13622 | ||
13623 | +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) | |
13624 | + if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) || | |
13625 | + !(mm->pax_flags & MF_PAX_PAGEEXEC)) | |
13626 | + goto not_pax_fault; | |
13627 | + | |
13628 | + /* PaX: it's our fault, let's handle it if we can */ | |
13629 | + | |
13630 | + /* PaX: take a look at read faults before acquiring any locks */ | |
13631 | + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) { | |
13632 | + /* instruction fetch attempt from a protected page in user mode */ | |
13633 | + up_read(&mm->mmap_sem); | |
13634 | + | |
13635 | +#ifdef CONFIG_PAX_EMUTRAMP | |
13636 | + switch (pax_handle_fetch_fault(regs)) { | |
13637 | + case 2: | |
13638 | + return; | |
13639 | + } | |
13640 | +#endif | |
13641 | + | |
13642 | + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp); | |
13643 | + do_group_exit(SIGKILL); | |
13644 | + } | |
13645 | + | |
13646 | + pmd = pax_get_pmd(mm, address); | |
13647 | + if (unlikely(!pmd)) | |
13648 | + goto not_pax_fault; | |
13649 | + | |
13650 | + pte = pte_offset_map_lock(mm, pmd, address, &ptl); | |
13651 | + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) { | |
13652 | + pte_unmap_unlock(pte, ptl); | |
13653 | + goto not_pax_fault; | |
13654 | + } | |
13655 | + | |
13656 | + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) { | |
13657 | + /* write attempt to a protected page in user mode */ | |
13658 | + pte_unmap_unlock(pte, ptl); | |
13659 | + goto not_pax_fault; | |
13660 | + } | |
13661 | + | |
13662 | +#ifdef CONFIG_SMP | |
13663 | + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask))) | |
13664 | +#else | |
13665 | + if (likely(address > get_limit(regs->cs))) | |
13666 | +#endif | |
13667 | + { | |
13668 | + set_pte(pte, pte_mkread(*pte)); | |
13669 | + __flush_tlb_one(address); | |
13670 | + pte_unmap_unlock(pte, ptl); | |
13671 | + up_read(&mm->mmap_sem); | |
13672 | + return; | |
13673 | + } | |
13674 | + | |
13675 | + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1)); | |
13676 | + | |
13677 | + /* | |
13678 | + * PaX: fill DTLB with user rights and retry | |
13679 | + */ | |
13680 | + __asm__ __volatile__ ( | |
13681 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
13682 | + "movw %w4,%%es\n" | |
13683 | +#endif | |
13684 | + "orb %2,(%1)\n" | |
13685 | +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC) | |
13686 | +/* | |
13687 | + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's | |
13688 | + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any* | |
13689 | + * page fault when examined during a TLB load attempt. this is true not only | |
13690 | + * for PTEs holding a non-present entry but also present entries that will | |
13691 | + * raise a page fault (such as those set up by PaX, or the copy-on-write | |
13692 | + * mechanism). in effect it means that we do *not* need to flush the TLBs | |
13693 | + * for our target pages since their PTEs are simply not in the TLBs at all. | |
13694 | + | |
13695 | + * the best thing in omitting it is that we gain around 15-20% speed in the | |
13696 | + * fast path of the page fault handler and can get rid of tracing since we | |
13697 | + * can no longer flush unintended entries. | |
13698 | + */ | |
13699 | + "invlpg (%0)\n" | |
13700 | +#endif | |
13701 | + "testb $0,%%es:(%0)\n" | |
13702 | + "xorb %3,(%1)\n" | |
13703 | +#ifdef CONFIG_PAX_MEMORY_UDEREF | |
13704 | + "pushl %%ss\n" | |
13705 | + "popl %%es\n" | |
13706 | +#endif | |
13707 | + : | |
13708 | + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS) | |
13709 | + : "memory", "cc"); | |
13710 | + pte_unmap_unlock(pte, ptl); | |
13711 | + up_read(&mm->mmap_sem); | |
13712 | + return; | |
13713 | + | |
13714 | +not_pax_fault: | |
13715 | +#endif | |
13716 | + | |
13717 | vma = find_vma(mm, address); | |
13718 | if (!vma) | |
13719 | goto bad_area; | |
13720 | @@ -701,16 +844,20 @@ void __kprobes do_page_fault(struct pt_r | |
13721 | goto good_area; | |
13722 | if (!(vma->vm_flags & VM_GROWSDOWN)) | |
13723 | goto bad_area; | |
13724 | - if (error_code & PF_USER) { | |
13725 | - /* | |
13726 | - * Accessing the stack below %sp is always a bug. | |
13727 | - * The large cushion allows instructions like enter | |
13728 | - * and pusha to work. ("enter $65535,$31" pushes | |
13729 | - * 32 pointers and then decrements %sp by 65535.) | |
13730 | - */ | |
13731 | - if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp) | |
13732 | - goto bad_area; | |
13733 | - } | |
13734 | + /* | |
13735 | + * Accessing the stack below %sp is always a bug. | |
13736 | + * The large cushion allows instructions like enter | |
13737 | + * and pusha to work. ("enter $65535,$31" pushes | |
13738 | + * 32 pointers and then decrements %sp by 65535.) | |
13739 | + */ | |
13740 | + if (address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp) | |
13741 | + goto bad_area; | |
13742 | + | |
13743 | +#ifdef CONFIG_PAX_SEGMEXEC | |
13744 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1) | |
13745 | + goto bad_area; | |
13746 | +#endif | |
13747 | + | |
13748 | if (expand_stack(vma, address)) | |
13749 | goto bad_area; | |
13750 | /* | |
13751 | @@ -720,6 +867,8 @@ void __kprobes do_page_fault(struct pt_r | |
13752 | good_area: | |
13753 | si_code = SEGV_ACCERR; | |
13754 | write = 0; | |
13755 | + if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC)) | |
13756 | + goto bad_area; | |
13757 | switch (error_code & (PF_PROT|PF_WRITE)) { | |
13758 | default: /* 3: write, present */ | |
13759 | /* fall through */ | |
de855c5d | 13760 | @@ -774,6 +923,69 @@ bad_area: |
2380c486 JR |
13761 | up_read(&mm->mmap_sem); |
13762 | ||
13763 | bad_area_nosemaphore: | |
13764 | + | |
de855c5d AM |
13765 | +#ifdef CONFIG_X86_64 |
13766 | + if (mm && (error_code & PF_INSTR)) { | |
13767 | + if (regs->ip == (unsigned long)vgettimeofday) { | |
13768 | + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday); | |
13769 | + return; | |
13770 | + } else if (regs->ip == (unsigned long)vtime) { | |
13771 | + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time); | |
13772 | + return; | |
13773 | + } else if (regs->ip == (unsigned long)vgetcpu) { | |
13774 | + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu); | |
13775 | + return; | |
13776 | + } | |
13777 | + } | |
13778 | +#endif | |
13779 | + | |
2380c486 JR |
13780 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) |
13781 | + if (mm && (error_code & PF_USER)) { | |
13782 | + unsigned long ip = regs->ip; | |
13783 | + | |
13784 | + if (v8086_mode(regs)) | |
13785 | + ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff); | |
13786 | + | |
13787 | + /* | |
13788 | + * It's possible to have interrupts off here. | |
13789 | + */ | |
13790 | + local_irq_enable(); | |
13791 | + | |
13792 | +#ifdef CONFIG_PAX_PAGEEXEC | |
13793 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && | |
13794 | + ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) { | |
13795 | + | |
13796 | +#ifdef CONFIG_PAX_EMUTRAMP | |
13797 | + switch (pax_handle_fetch_fault(regs)) { | |
13798 | + case 2: | |
13799 | + return; | |
13800 | + } | |
13801 | +#endif | |
13802 | + | |
13803 | + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp); | |
13804 | + do_group_exit(SIGKILL); | |
13805 | + } | |
13806 | +#endif | |
13807 | + | |
13808 | +#ifdef CONFIG_PAX_SEGMEXEC | |
13809 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) { | |
13810 | + | |
13811 | +#ifdef CONFIG_PAX_EMUTRAMP | |
13812 | + switch (pax_handle_fetch_fault(regs)) { | |
13813 | + case 2: | |
13814 | + return; | |
13815 | + } | |
13816 | +#endif | |
13817 | + | |
13818 | + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp); | |
13819 | + do_group_exit(SIGKILL); | |
13820 | + } | |
13821 | +#endif | |
13822 | + | |
13823 | + } | |
13824 | +#endif | |
13825 | + | |
13826 | +bad_area_nopax: | |
13827 | /* User mode accesses just cause a SIGSEGV */ | |
13828 | if (error_code & PF_USER) { | |
13829 | /* | |
de855c5d | 13830 | @@ -852,7 +1064,7 @@ no_context: |
2380c486 JR |
13831 | #ifdef CONFIG_X86_32 |
13832 | die("Oops", regs, error_code); | |
13833 | bust_spinlocks(0); | |
13834 | - do_exit(SIGKILL); | |
13835 | + do_group_exit(SIGKILL); | |
13836 | #else | |
13837 | sig = SIGKILL; | |
13838 | if (__die("Oops", regs, error_code)) | |
de855c5d | 13839 | @@ -935,3 +1147,174 @@ void vmalloc_sync_all(void) |
2380c486 JR |
13840 | } |
13841 | #endif | |
13842 | } | |
13843 | + | |
13844 | +#ifdef CONFIG_PAX_EMUTRAMP | |
13845 | +static int pax_handle_fetch_fault_32(struct pt_regs *regs) | |
13846 | +{ | |
13847 | + int err; | |
13848 | + | |
13849 | + do { /* PaX: gcc trampoline emulation #1 */ | |
13850 | + unsigned char mov1, mov2; | |
13851 | + unsigned short jmp; | |
13852 | + unsigned int addr1, addr2; | |
13853 | + | |
13854 | +#ifdef CONFIG_X86_64 | |
13855 | + if ((regs->ip + 11) >> 32) | |
13856 | + break; | |
13857 | +#endif | |
13858 | + | |
13859 | + err = get_user(mov1, (unsigned char __user *)regs->ip); | |
13860 | + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1)); | |
13861 | + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5)); | |
13862 | + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6)); | |
13863 | + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10)); | |
13864 | + | |
13865 | + if (err) | |
13866 | + break; | |
13867 | + | |
13868 | + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) { | |
13869 | + regs->cx = addr1; | |
13870 | + regs->ax = addr2; | |
13871 | + regs->ip = addr2; | |
13872 | + return 2; | |
13873 | + } | |
13874 | + } while (0); | |
13875 | + | |
13876 | + do { /* PaX: gcc trampoline emulation #2 */ | |
13877 | + unsigned char mov, jmp; | |
13878 | + unsigned int addr1, addr2; | |
13879 | + | |
13880 | +#ifdef CONFIG_X86_64 | |
13881 | + if ((regs->ip + 9) >> 32) | |
13882 | + break; | |
13883 | +#endif | |
13884 | + | |
13885 | + err = get_user(mov, (unsigned char __user *)regs->ip); | |
13886 | + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1)); | |
13887 | + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5)); | |
13888 | + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6)); | |
13889 | + | |
13890 | + if (err) | |
13891 | + break; | |
13892 | + | |
13893 | + if (mov == 0xB9 && jmp == 0xE9) { | |
13894 | + regs->cx = addr1; | |
13895 | + regs->ip = (unsigned int)(regs->ip + addr2 + 10); | |
13896 | + return 2; | |
13897 | + } | |
13898 | + } while (0); | |
13899 | + | |
13900 | + return 1; /* PaX in action */ | |
13901 | +} | |
13902 | + | |
13903 | +#ifdef CONFIG_X86_64 | |
13904 | +static int pax_handle_fetch_fault_64(struct pt_regs *regs) | |
13905 | +{ | |
13906 | + int err; | |
13907 | + | |
13908 | + do { /* PaX: gcc trampoline emulation #1 */ | |
13909 | + unsigned short mov1, mov2, jmp1; | |
13910 | + unsigned char jmp2; | |
13911 | + unsigned int addr1; | |
13912 | + unsigned long addr2; | |
13913 | + | |
13914 | + err = get_user(mov1, (unsigned short __user *)regs->ip); | |
13915 | + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2)); | |
13916 | + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6)); | |
13917 | + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8)); | |
13918 | + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16)); | |
13919 | + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18)); | |
13920 | + | |
13921 | + if (err) | |
13922 | + break; | |
13923 | + | |
13924 | + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) { | |
13925 | + regs->r11 = addr1; | |
13926 | + regs->r10 = addr2; | |
13927 | + regs->ip = addr1; | |
13928 | + return 2; | |
13929 | + } | |
13930 | + } while (0); | |
13931 | + | |
13932 | + do { /* PaX: gcc trampoline emulation #2 */ | |
13933 | + unsigned short mov1, mov2, jmp1; | |
13934 | + unsigned char jmp2; | |
13935 | + unsigned long addr1, addr2; | |
13936 | + | |
13937 | + err = get_user(mov1, (unsigned short __user *)regs->ip); | |
13938 | + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2)); | |
13939 | + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10)); | |
13940 | + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12)); | |
13941 | + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20)); | |
13942 | + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22)); | |
13943 | + | |
13944 | + if (err) | |
13945 | + break; | |
13946 | + | |
13947 | + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) { | |
13948 | + regs->r11 = addr1; | |
13949 | + regs->r10 = addr2; | |
13950 | + regs->ip = addr1; | |
13951 | + return 2; | |
13952 | + } | |
13953 | + } while (0); | |
13954 | + | |
13955 | + return 1; /* PaX in action */ | |
13956 | +} | |
13957 | +#endif | |
13958 | + | |
13959 | +/* | |
13960 | + * PaX: decide what to do with offenders (regs->ip = fault address) | |
13961 | + * | |
13962 | + * returns 1 when task should be killed | |
13963 | + * 2 when gcc trampoline was detected | |
13964 | + */ | |
13965 | +static int pax_handle_fetch_fault(struct pt_regs *regs) | |
13966 | +{ | |
13967 | + if (v8086_mode(regs)) | |
13968 | + return 1; | |
13969 | + | |
13970 | + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP)) | |
13971 | + return 1; | |
13972 | + | |
13973 | +#ifdef CONFIG_X86_32 | |
13974 | + return pax_handle_fetch_fault_32(regs); | |
13975 | +#else | |
13976 | + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) | |
13977 | + return pax_handle_fetch_fault_32(regs); | |
13978 | + else | |
13979 | + return pax_handle_fetch_fault_64(regs); | |
13980 | +#endif | |
13981 | +} | |
13982 | +#endif | |
13983 | + | |
13984 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
13985 | +void pax_report_insns(void *pc, void *sp) | |
13986 | +{ | |
13987 | + long i; | |
13988 | + | |
13989 | + printk(KERN_ERR "PAX: bytes at PC: "); | |
13990 | + for (i = 0; i < 20; i++) { | |
13991 | + unsigned char c; | |
13992 | + if (get_user(c, (unsigned char __user *)pc+i)) | |
13993 | + printk(KERN_CONT "?? "); | |
13994 | + else | |
13995 | + printk(KERN_CONT "%02x ", c); | |
13996 | + } | |
13997 | + printk("\n"); | |
13998 | + | |
13999 | + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long)); | |
14000 | + for (i = -1; i < 80 / sizeof(long); i++) { | |
14001 | + unsigned long c; | |
14002 | + if (get_user(c, (unsigned long __user *)sp+i)) | |
14003 | +#ifdef CONFIG_X86_32 | |
14004 | + printk(KERN_CONT "???????? "); | |
14005 | +#else | |
14006 | + printk(KERN_CONT "???????????????? "); | |
14007 | +#endif | |
14008 | + else | |
14009 | + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c); | |
14010 | + } | |
14011 | + printk("\n"); | |
14012 | +} | |
14013 | +#endif | |
de855c5d AM |
14014 | diff -urNp linux-2.6.29.6/arch/x86/mm/highmem_32.c linux-2.6.29.6/arch/x86/mm/highmem_32.c |
14015 | --- linux-2.6.29.6/arch/x86/mm/highmem_32.c 2009-07-02 19:41:20.000000000 -0400 | |
14016 | +++ linux-2.6.29.6/arch/x86/mm/highmem_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14017 | @@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page |
14018 | enum fixed_addresses idx; | |
14019 | unsigned long vaddr; | |
14020 | ||
14021 | +#ifdef CONFIG_PAX_KERNEXEC | |
14022 | + unsigned long cr0; | |
14023 | +#endif | |
14024 | + | |
14025 | /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */ | |
14026 | pagefault_disable(); | |
14027 | ||
14028 | @@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page | |
14029 | idx = type + KM_TYPE_NR*smp_processor_id(); | |
14030 | vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); | |
14031 | BUG_ON(!pte_none(*(kmap_pte-idx))); | |
14032 | + | |
14033 | +#ifdef CONFIG_PAX_KERNEXEC | |
14034 | + pax_open_kernel(cr0); | |
14035 | +#endif | |
14036 | + | |
14037 | set_pte(kmap_pte-idx, mk_pte(page, prot)); | |
14038 | + | |
14039 | +#ifdef CONFIG_PAX_KERNEXEC | |
14040 | + pax_close_kernel(cr0); | |
14041 | +#endif | |
14042 | + | |
14043 | arch_flush_lazy_mmu_mode(); | |
14044 | ||
14045 | return (void *)vaddr; | |
14046 | @@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km | |
14047 | unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK; | |
14048 | enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id(); | |
14049 | ||
14050 | +#ifdef CONFIG_PAX_KERNEXEC | |
14051 | + unsigned long cr0; | |
14052 | +#endif | |
14053 | + | |
14054 | /* | |
14055 | * Force other mappings to Oops if they'll try to access this pte | |
14056 | * without first remap it. Keeping stale mappings around is a bad idea | |
14057 | * also, in case the page changes cacheability attributes or becomes | |
14058 | * a protected page in a hypervisor. | |
14059 | */ | |
14060 | - if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) | |
14061 | + if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) { | |
14062 | + | |
14063 | +#ifdef CONFIG_PAX_KERNEXEC | |
14064 | + pax_open_kernel(cr0); | |
14065 | +#endif | |
14066 | + | |
14067 | kpte_clear_flush(kmap_pte-idx, vaddr); | |
14068 | - else { | |
14069 | + | |
14070 | +#ifdef CONFIG_PAX_KERNEXEC | |
14071 | + pax_close_kernel(cr0); | |
14072 | +#endif | |
14073 | + | |
14074 | + } else { | |
14075 | #ifdef CONFIG_DEBUG_HIGHMEM | |
14076 | BUG_ON(vaddr < PAGE_OFFSET); | |
14077 | BUG_ON(vaddr >= (unsigned long)high_memory); | |
14078 | @@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn, | |
14079 | enum fixed_addresses idx; | |
14080 | unsigned long vaddr; | |
14081 | ||
14082 | +#ifdef CONFIG_PAX_KERNEXEC | |
14083 | + unsigned long cr0; | |
14084 | +#endif | |
14085 | + | |
14086 | pagefault_disable(); | |
14087 | ||
14088 | idx = type + KM_TYPE_NR*smp_processor_id(); | |
14089 | vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); | |
14090 | + | |
14091 | +#ifdef CONFIG_PAX_KERNEXEC | |
14092 | + pax_open_kernel(cr0); | |
14093 | +#endif | |
14094 | + | |
14095 | set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot)); | |
14096 | + | |
14097 | +#ifdef CONFIG_PAX_KERNEXEC | |
14098 | + pax_close_kernel(cr0); | |
14099 | +#endif | |
14100 | + | |
14101 | arch_flush_lazy_mmu_mode(); | |
14102 | ||
14103 | return (void*) vaddr; | |
de855c5d AM |
14104 | diff -urNp linux-2.6.29.6/arch/x86/mm/hugetlbpage.c linux-2.6.29.6/arch/x86/mm/hugetlbpage.c |
14105 | --- linux-2.6.29.6/arch/x86/mm/hugetlbpage.c 2009-07-02 19:41:20.000000000 -0400 | |
14106 | +++ linux-2.6.29.6/arch/x86/mm/hugetlbpage.c 2009-07-09 22:13:39.000000000 -0400 | |
14107 | @@ -267,13 +267,18 @@ static unsigned long hugetlb_get_unmappe | |
2380c486 JR |
14108 | struct hstate *h = hstate_file(file); |
14109 | struct mm_struct *mm = current->mm; | |
14110 | struct vm_area_struct *vma; | |
14111 | - unsigned long start_addr; | |
14112 | + unsigned long start_addr, pax_task_size = TASK_SIZE; | |
14113 | + | |
14114 | +#ifdef CONFIG_PAX_SEGMEXEC | |
14115 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
14116 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
14117 | +#endif | |
14118 | ||
14119 | if (len > mm->cached_hole_size) { | |
14120 | - start_addr = mm->free_area_cache; | |
14121 | + start_addr = mm->free_area_cache; | |
14122 | } else { | |
14123 | - start_addr = TASK_UNMAPPED_BASE; | |
14124 | - mm->cached_hole_size = 0; | |
14125 | + start_addr = mm->mmap_base; | |
14126 | + mm->cached_hole_size = 0; | |
14127 | } | |
14128 | ||
14129 | full_search: | |
de855c5d | 14130 | @@ -281,13 +286,13 @@ full_search: |
2380c486 JR |
14131 | |
14132 | for (vma = find_vma(mm, addr); ; vma = vma->vm_next) { | |
14133 | /* At this point: (!vma || addr < vma->vm_end). */ | |
14134 | - if (TASK_SIZE - len < addr) { | |
14135 | + if (pax_task_size - len < addr) { | |
14136 | /* | |
14137 | * Start a new search - just in case we missed | |
14138 | * some holes. | |
14139 | */ | |
14140 | - if (start_addr != TASK_UNMAPPED_BASE) { | |
14141 | - start_addr = TASK_UNMAPPED_BASE; | |
14142 | + if (start_addr != mm->mmap_base) { | |
14143 | + start_addr = mm->mmap_base; | |
14144 | mm->cached_hole_size = 0; | |
14145 | goto full_search; | |
14146 | } | |
de855c5d | 14147 | @@ -310,9 +315,8 @@ static unsigned long hugetlb_get_unmappe |
2380c486 JR |
14148 | struct hstate *h = hstate_file(file); |
14149 | struct mm_struct *mm = current->mm; | |
14150 | struct vm_area_struct *vma, *prev_vma; | |
14151 | - unsigned long base = mm->mmap_base, addr = addr0; | |
14152 | + unsigned long base = mm->mmap_base, addr; | |
14153 | unsigned long largest_hole = mm->cached_hole_size; | |
14154 | - int first_time = 1; | |
14155 | ||
14156 | /* don't allow allocations above current base */ | |
14157 | if (mm->free_area_cache > base) | |
de855c5d | 14158 | @@ -322,7 +326,7 @@ static unsigned long hugetlb_get_unmappe |
2380c486 JR |
14159 | largest_hole = 0; |
14160 | mm->free_area_cache = base; | |
14161 | } | |
14162 | -try_again: | |
14163 | + | |
14164 | /* make sure it can fit in the remaining address space */ | |
14165 | if (mm->free_area_cache < len) | |
14166 | goto fail; | |
de855c5d | 14167 | @@ -364,22 +368,26 @@ try_again: |
2380c486 JR |
14168 | |
14169 | fail: | |
14170 | /* | |
14171 | - * if hint left us with no space for the requested | |
14172 | - * mapping then try again: | |
14173 | - */ | |
14174 | - if (first_time) { | |
14175 | - mm->free_area_cache = base; | |
14176 | - largest_hole = 0; | |
14177 | - first_time = 0; | |
14178 | - goto try_again; | |
14179 | - } | |
14180 | - /* | |
14181 | * A failed mmap() very likely causes application failure, | |
14182 | * so fall back to the bottom-up function here. This scenario | |
14183 | * can happen with large stack limits and large mmap() | |
14184 | * allocations. | |
14185 | */ | |
14186 | - mm->free_area_cache = TASK_UNMAPPED_BASE; | |
14187 | + | |
14188 | +#ifdef CONFIG_PAX_SEGMEXEC | |
14189 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
14190 | + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE; | |
14191 | + else | |
14192 | +#endif | |
14193 | + | |
14194 | + mm->mmap_base = TASK_UNMAPPED_BASE; | |
14195 | + | |
14196 | +#ifdef CONFIG_PAX_RANDMMAP | |
14197 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
14198 | + mm->mmap_base += mm->delta_mmap; | |
14199 | +#endif | |
14200 | + | |
14201 | + mm->free_area_cache = mm->mmap_base; | |
14202 | mm->cached_hole_size = ~0UL; | |
14203 | addr = hugetlb_get_unmapped_area_bottomup(file, addr0, | |
14204 | len, pgoff, flags); | |
de855c5d | 14205 | @@ -387,6 +395,7 @@ fail: |
2380c486 JR |
14206 | /* |
14207 | * Restore the topdown base: | |
14208 | */ | |
14209 | + mm->mmap_base = base; | |
14210 | mm->free_area_cache = base; | |
14211 | mm->cached_hole_size = ~0UL; | |
14212 | ||
de855c5d | 14213 | @@ -400,10 +409,17 @@ hugetlb_get_unmapped_area(struct file *f |
2380c486 JR |
14214 | struct hstate *h = hstate_file(file); |
14215 | struct mm_struct *mm = current->mm; | |
14216 | struct vm_area_struct *vma; | |
14217 | + unsigned long pax_task_size = TASK_SIZE; | |
14218 | ||
14219 | if (len & ~huge_page_mask(h)) | |
14220 | return -EINVAL; | |
14221 | - if (len > TASK_SIZE) | |
14222 | + | |
14223 | +#ifdef CONFIG_PAX_SEGMEXEC | |
14224 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
14225 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
14226 | +#endif | |
14227 | + | |
14228 | + if (len > pax_task_size) | |
14229 | return -ENOMEM; | |
14230 | ||
14231 | if (flags & MAP_FIXED) { | |
de855c5d | 14232 | @@ -415,7 +431,7 @@ hugetlb_get_unmapped_area(struct file *f |
2380c486 JR |
14233 | if (addr) { |
14234 | addr = ALIGN(addr, huge_page_size(h)); | |
14235 | vma = find_vma(mm, addr); | |
14236 | - if (TASK_SIZE - len >= addr && | |
14237 | + if (pax_task_size - len >= addr && | |
14238 | (!vma || addr + len <= vma->vm_start)) | |
14239 | return addr; | |
14240 | } | |
de855c5d AM |
14241 | diff -urNp linux-2.6.29.6/arch/x86/mm/init_32.c linux-2.6.29.6/arch/x86/mm/init_32.c |
14242 | --- linux-2.6.29.6/arch/x86/mm/init_32.c 2009-07-02 19:41:20.000000000 -0400 | |
14243 | +++ linux-2.6.29.6/arch/x86/mm/init_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14244 | @@ -50,6 +50,7 @@ |
14245 | #include <asm/setup.h> | |
14246 | #include <asm/cacheflush.h> | |
14247 | #include <asm/smp.h> | |
14248 | +#include <asm/desc.h> | |
14249 | ||
14250 | unsigned int __VMALLOC_RESERVE = 128 << 20; | |
14251 | ||
14252 | @@ -82,36 +83,6 @@ static __init void *alloc_low_page(void) | |
14253 | } | |
14254 | ||
14255 | /* | |
14256 | - * Creates a middle page table and puts a pointer to it in the | |
14257 | - * given global directory entry. This only returns the gd entry | |
14258 | - * in non-PAE compilation mode, since the middle layer is folded. | |
14259 | - */ | |
14260 | -static pmd_t * __init one_md_table_init(pgd_t *pgd) | |
14261 | -{ | |
14262 | - pud_t *pud; | |
14263 | - pmd_t *pmd_table; | |
14264 | - | |
14265 | -#ifdef CONFIG_X86_PAE | |
14266 | - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) { | |
14267 | - if (after_init_bootmem) | |
14268 | - pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE); | |
14269 | - else | |
14270 | - pmd_table = (pmd_t *)alloc_low_page(); | |
14271 | - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT); | |
14272 | - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT)); | |
14273 | - pud = pud_offset(pgd, 0); | |
14274 | - BUG_ON(pmd_table != pmd_offset(pud, 0)); | |
14275 | - | |
14276 | - return pmd_table; | |
14277 | - } | |
14278 | -#endif | |
14279 | - pud = pud_offset(pgd, 0); | |
14280 | - pmd_table = pmd_offset(pud, 0); | |
14281 | - | |
14282 | - return pmd_table; | |
14283 | -} | |
14284 | - | |
14285 | -/* | |
14286 | * Create a page table and place a pointer to it in a middle page | |
14287 | * directory entry: | |
14288 | */ | |
14289 | @@ -131,7 +102,11 @@ static pte_t * __init one_page_table_ini | |
14290 | page_table = (pte_t *)alloc_low_page(); | |
14291 | ||
14292 | paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT); | |
14293 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
14294 | + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE)); | |
14295 | +#else | |
14296 | set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE)); | |
14297 | +#endif | |
14298 | BUG_ON(page_table != pte_offset_kernel(pmd, 0)); | |
14299 | } | |
14300 | ||
14301 | @@ -194,6 +169,7 @@ page_table_range_init(unsigned long star | |
14302 | int pgd_idx, pmd_idx; | |
14303 | unsigned long vaddr; | |
14304 | pgd_t *pgd; | |
14305 | + pud_t *pud; | |
14306 | pmd_t *pmd; | |
14307 | pte_t *pte = NULL; | |
14308 | ||
14309 | @@ -203,8 +179,13 @@ page_table_range_init(unsigned long star | |
14310 | pgd = pgd_base + pgd_idx; | |
14311 | ||
14312 | for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) { | |
14313 | - pmd = one_md_table_init(pgd); | |
14314 | - pmd = pmd + pmd_index(vaddr); | |
14315 | + pud = pud_offset(pgd, vaddr); | |
14316 | + pmd = pmd_offset(pud, vaddr); | |
14317 | + | |
14318 | +#ifdef CONFIG_X86_PAE | |
14319 | + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT); | |
14320 | +#endif | |
14321 | + | |
14322 | for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end); | |
14323 | pmd++, pmd_idx++) { | |
14324 | pte = page_table_kmap_check(one_page_table_init(pmd), | |
14325 | @@ -216,11 +197,23 @@ page_table_range_init(unsigned long star | |
14326 | } | |
14327 | } | |
14328 | ||
14329 | -static inline int is_kernel_text(unsigned long addr) | |
14330 | +static inline int is_kernel_text(unsigned long start, unsigned long end) | |
14331 | { | |
14332 | - if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end) | |
14333 | - return 1; | |
14334 | - return 0; | |
14335 | + unsigned long etext; | |
14336 | + | |
14337 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
14338 | + etext = ktva_ktla((unsigned long)&MODULES_END); | |
14339 | +#else | |
14340 | + etext = (unsigned long)&_etext; | |
14341 | +#endif | |
14342 | + | |
14343 | + if ((start > ktla_ktva(etext) || | |
14344 | + end <= ktla_ktva((unsigned long)_stext)) && | |
14345 | + (start > ktla_ktva((unsigned long)_einittext) || | |
14346 | + end <= ktla_ktva((unsigned long)_sinittext)) && | |
14347 | + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000))) | |
14348 | + return 0; | |
14349 | + return 1; | |
14350 | } | |
14351 | ||
14352 | /* | |
14353 | @@ -233,9 +226,10 @@ static void __init kernel_physical_mappi | |
14354 | unsigned long end_pfn, | |
14355 | int use_pse) | |
14356 | { | |
14357 | - int pgd_idx, pmd_idx, pte_ofs; | |
14358 | + unsigned int pgd_idx, pmd_idx, pte_ofs; | |
14359 | unsigned long pfn; | |
14360 | pgd_t *pgd; | |
14361 | + pud_t *pud; | |
14362 | pmd_t *pmd; | |
14363 | pte_t *pte; | |
14364 | unsigned pages_2m, pages_4k; | |
14365 | @@ -265,8 +259,13 @@ repeat: | |
14366 | pfn = start_pfn; | |
14367 | pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET); | |
14368 | pgd = pgd_base + pgd_idx; | |
14369 | - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) { | |
14370 | - pmd = one_md_table_init(pgd); | |
14371 | + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) { | |
14372 | + pud = pud_offset(pgd, 0); | |
14373 | + pmd = pmd_offset(pud, 0); | |
14374 | + | |
14375 | +#ifdef CONFIG_X86_PAE | |
14376 | + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT); | |
14377 | +#endif | |
14378 | ||
14379 | if (pfn >= end_pfn) | |
14380 | continue; | |
14381 | @@ -278,14 +277,13 @@ repeat: | |
14382 | #endif | |
14383 | for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn; | |
14384 | pmd++, pmd_idx++) { | |
14385 | - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET; | |
14386 | + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET; | |
14387 | ||
14388 | /* | |
14389 | * Map with big pages if possible, otherwise | |
14390 | * create normal page tables: | |
14391 | */ | |
14392 | if (use_pse) { | |
14393 | - unsigned int addr2; | |
14394 | pgprot_t prot = PAGE_KERNEL_LARGE; | |
14395 | /* | |
14396 | * first pass will use the same initial | |
14397 | @@ -295,11 +293,7 @@ repeat: | |
14398 | __pgprot(PTE_IDENT_ATTR | | |
14399 | _PAGE_PSE); | |
14400 | ||
14401 | - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE + | |
14402 | - PAGE_OFFSET + PAGE_SIZE-1; | |
14403 | - | |
14404 | - if (is_kernel_text(addr) || | |
14405 | - is_kernel_text(addr2)) | |
14406 | + if (is_kernel_text(address, address + PMD_SIZE)) | |
14407 | prot = PAGE_KERNEL_LARGE_EXEC; | |
14408 | ||
14409 | pages_2m++; | |
14410 | @@ -316,7 +310,7 @@ repeat: | |
14411 | pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET); | |
14412 | pte += pte_ofs; | |
14413 | for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn; | |
14414 | - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) { | |
14415 | + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) { | |
14416 | pgprot_t prot = PAGE_KERNEL; | |
14417 | /* | |
14418 | * first pass will use the same initial | |
14419 | @@ -324,7 +318,7 @@ repeat: | |
14420 | */ | |
14421 | pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR); | |
14422 | ||
14423 | - if (is_kernel_text(addr)) | |
14424 | + if (is_kernel_text(address, address + PAGE_SIZE)) | |
14425 | prot = PAGE_KERNEL_EXEC; | |
14426 | ||
14427 | pages_4k++; | |
de855c5d | 14428 | @@ -369,7 +363,13 @@ repeat: |
2380c486 JR |
14429 | */ |
14430 | int devmem_is_allowed(unsigned long pagenr) | |
14431 | { | |
14432 | - if (pagenr <= 256) | |
14433 | + if (!pagenr) | |
14434 | + return 1; | |
de855c5d AM |
14435 | +#ifdef CONFIG_VM86 |
14436 | + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT)) | |
14437 | + return 1; | |
14438 | +#endif | |
2380c486 JR |
14439 | + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT)) |
14440 | return 1; | |
14441 | if (iomem_is_exclusive(pagenr << PAGE_SHIFT)) | |
14442 | return 0; | |
de855c5d | 14443 | @@ -508,7 +508,7 @@ void __init native_pagetable_setup_start |
2380c486 JR |
14444 | |
14445 | pud = pud_offset(pgd, va); | |
14446 | pmd = pmd_offset(pud, va); | |
14447 | - if (!pmd_present(*pmd)) | |
14448 | + if (!pmd_present(*pmd) || pmd_huge(*pmd)) | |
14449 | break; | |
14450 | ||
14451 | pte = pte_offset_kernel(pmd, va); | |
de855c5d | 14452 | @@ -559,9 +559,7 @@ static void __init early_ioremap_page_ta |
2380c486 JR |
14453 | |
14454 | static void __init pagetable_init(void) | |
14455 | { | |
14456 | - pgd_t *pgd_base = swapper_pg_dir; | |
14457 | - | |
14458 | - permanent_kmaps_init(pgd_base); | |
14459 | + permanent_kmaps_init(swapper_pg_dir); | |
14460 | } | |
14461 | ||
14462 | #ifdef CONFIG_ACPI_SLEEP | |
de855c5d | 14463 | @@ -569,12 +567,12 @@ static void __init pagetable_init(void) |
2380c486 JR |
14464 | * ACPI suspend needs this for resume, because things like the intel-agp |
14465 | * driver might have split up a kernel 4MB mapping. | |
14466 | */ | |
14467 | -char swsusp_pg_dir[PAGE_SIZE] | |
14468 | +pgd_t swsusp_pg_dir[PTRS_PER_PGD] | |
14469 | __attribute__ ((aligned(PAGE_SIZE))); | |
14470 | ||
14471 | static inline void save_pg_dir(void) | |
14472 | { | |
14473 | - memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE); | |
14474 | + clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD); | |
14475 | } | |
14476 | #else /* !CONFIG_ACPI_SLEEP */ | |
14477 | static inline void save_pg_dir(void) | |
de855c5d | 14478 | @@ -604,13 +602,11 @@ void zap_low_mappings(void) |
2380c486 JR |
14479 | |
14480 | int nx_enabled; | |
14481 | ||
14482 | -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP); | |
14483 | +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP); | |
14484 | EXPORT_SYMBOL_GPL(__supported_pte_mask); | |
14485 | ||
14486 | #ifdef CONFIG_X86_PAE | |
14487 | ||
14488 | -static int disable_nx __initdata; | |
14489 | - | |
14490 | /* | |
14491 | * noexec = on|off | |
14492 | * | |
de855c5d | 14493 | @@ -619,40 +615,33 @@ static int disable_nx __initdata; |
2380c486 JR |
14494 | * on Enable |
14495 | * off Disable | |
14496 | */ | |
14497 | +#if !defined(CONFIG_PAX_PAGEEXEC) | |
14498 | static int __init noexec_setup(char *str) | |
14499 | { | |
14500 | if (!str || !strcmp(str, "on")) { | |
14501 | - if (cpu_has_nx) { | |
14502 | - __supported_pte_mask |= _PAGE_NX; | |
14503 | - disable_nx = 0; | |
14504 | - } | |
14505 | + if (cpu_has_nx) | |
14506 | + nx_enabled = 1; | |
14507 | } else { | |
14508 | - if (!strcmp(str, "off")) { | |
14509 | - disable_nx = 1; | |
14510 | - __supported_pte_mask &= ~_PAGE_NX; | |
14511 | - } else { | |
14512 | + if (!strcmp(str, "off")) | |
14513 | + nx_enabled = 0; | |
14514 | + else | |
14515 | return -EINVAL; | |
14516 | - } | |
14517 | } | |
14518 | ||
14519 | return 0; | |
14520 | } | |
14521 | early_param("noexec", noexec_setup); | |
14522 | +#endif | |
14523 | ||
14524 | static void __init set_nx(void) | |
14525 | { | |
14526 | - unsigned int v[4], l, h; | |
2380c486 JR |
14527 | + if (!nx_enabled && cpu_has_nx) { |
14528 | + unsigned l, h; | |
14529 | ||
de855c5d AM |
14530 | - if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) { |
14531 | - cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]); | |
14532 | - | |
2380c486 JR |
14533 | - if ((v[3] & (1 << 20)) && !disable_nx) { |
14534 | - rdmsr(MSR_EFER, l, h); | |
14535 | - l |= EFER_NX; | |
14536 | - wrmsr(MSR_EFER, l, h); | |
14537 | - nx_enabled = 1; | |
14538 | - __supported_pte_mask |= _PAGE_NX; | |
14539 | - } | |
14540 | + __supported_pte_mask &= ~_PAGE_NX; | |
14541 | + rdmsr(MSR_EFER, l, h); | |
14542 | + l &= ~EFER_NX; | |
14543 | + wrmsr(MSR_EFER, l, h); | |
14544 | } | |
14545 | } | |
14546 | #endif | |
de855c5d | 14547 | @@ -1035,7 +1024,7 @@ void __init mem_init(void) |
2380c486 JR |
14548 | set_highmem_pages_init(); |
14549 | ||
14550 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | |
14551 | - datasize = (unsigned long) &_edata - (unsigned long) &_etext; | |
14552 | + datasize = (unsigned long) &_edata - (unsigned long) &_data; | |
14553 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | |
14554 | ||
14555 | kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT); | |
de855c5d | 14556 | @@ -1081,10 +1070,10 @@ void __init mem_init(void) |
2380c486 JR |
14557 | ((unsigned long)&__init_end - |
14558 | (unsigned long)&__init_begin) >> 10, | |
14559 | ||
14560 | - (unsigned long)&_etext, (unsigned long)&_edata, | |
14561 | - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10, | |
14562 | + (unsigned long)&_data, (unsigned long)&_edata, | |
14563 | + ((unsigned long)&_edata - (unsigned long)&_data) >> 10, | |
14564 | ||
14565 | - (unsigned long)&_text, (unsigned long)&_etext, | |
14566 | + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext), | |
14567 | ((unsigned long)&_etext - (unsigned long)&_text) >> 10); | |
14568 | ||
14569 | /* | |
de855c5d | 14570 | @@ -1227,6 +1216,46 @@ void free_init_pages(char *what, unsigne |
2380c486 JR |
14571 | |
14572 | void free_initmem(void) | |
14573 | { | |
14574 | + | |
14575 | +#ifdef CONFIG_PAX_KERNEXEC | |
14576 | + /* PaX: limit KERNEL_CS to actual size */ | |
14577 | + unsigned long addr, limit; | |
14578 | + struct desc_struct d; | |
14579 | + int cpu; | |
14580 | + pgd_t *pgd; | |
14581 | + pud_t *pud; | |
14582 | + pmd_t *pmd; | |
14583 | + | |
14584 | +#ifdef CONFIG_MODULES | |
14585 | + limit = ktva_ktla((unsigned long)&MODULES_END); | |
14586 | +#else | |
14587 | + limit = (unsigned long)&_etext; | |
14588 | +#endif | |
14589 | + limit = (limit - 1UL) >> PAGE_SHIFT; | |
14590 | + | |
14591 | + for (cpu = 0; cpu < NR_CPUS; cpu++) { | |
14592 | + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC); | |
14593 | + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S); | |
14594 | + } | |
14595 | + | |
14596 | + /* PaX: make KERNEL_CS read-only */ | |
14597 | + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) { | |
14598 | + pgd = pgd_offset_k(addr); | |
14599 | + pud = pud_offset(pgd, addr); | |
14600 | + pmd = pmd_offset(pud, addr); | |
14601 | + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW)); | |
14602 | + } | |
14603 | +#ifdef CONFIG_X86_PAE | |
14604 | + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) { | |
14605 | + pgd = pgd_offset_k(addr); | |
14606 | + pud = pud_offset(pgd, addr); | |
14607 | + pmd = pmd_offset(pud, addr); | |
14608 | + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask))); | |
14609 | + } | |
14610 | +#endif | |
14611 | + flush_tlb_all(); | |
14612 | +#endif | |
14613 | + | |
14614 | free_init_pages("unused kernel memory", | |
14615 | (unsigned long)(&__init_begin), | |
14616 | (unsigned long)(&__init_end)); | |
de855c5d AM |
14617 | diff -urNp linux-2.6.29.6/arch/x86/mm/init_64.c linux-2.6.29.6/arch/x86/mm/init_64.c |
14618 | --- linux-2.6.29.6/arch/x86/mm/init_64.c 2009-07-02 19:41:20.000000000 -0400 | |
14619 | +++ linux-2.6.29.6/arch/x86/mm/init_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14620 | @@ -175,6 +175,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig |
14621 | pmd_t *pmd; | |
14622 | pte_t *pte; | |
14623 | ||
14624 | +#ifdef CONFIG_PAX_KERNEXEC | |
14625 | + unsigned long cr0; | |
14626 | +#endif | |
14627 | + | |
14628 | pud = pud_page + pud_index(vaddr); | |
14629 | if (pud_none(*pud)) { | |
14630 | pmd = (pmd_t *) spp_getpage(); | |
14631 | @@ -196,8 +200,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig | |
14632 | } | |
14633 | ||
14634 | pte = pte_offset_kernel(pmd, vaddr); | |
14635 | + | |
14636 | +#ifdef CONFIG_PAX_KERNEXEC | |
14637 | + pax_open_kernel(cr0); | |
14638 | +#endif | |
14639 | + | |
14640 | set_pte(pte, new_pte); | |
14641 | ||
14642 | +#ifdef CONFIG_PAX_KERNEXEC | |
14643 | + pax_close_kernel(cr0); | |
14644 | +#endif | |
14645 | + | |
14646 | /* | |
14647 | * It's enough to flush this one mapping. | |
14648 | * (PGE mappings get flushed as well) | |
14649 | @@ -238,14 +251,12 @@ static void __init __init_extra_mapping( | |
14650 | pgd = pgd_offset_k((unsigned long)__va(phys)); | |
14651 | if (pgd_none(*pgd)) { | |
14652 | pud = (pud_t *) spp_getpage(); | |
14653 | - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE | | |
14654 | - _PAGE_USER)); | |
14655 | + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE)); | |
14656 | } | |
14657 | pud = pud_offset(pgd, (unsigned long)__va(phys)); | |
14658 | if (pud_none(*pud)) { | |
14659 | pmd = (pmd_t *) spp_getpage(); | |
14660 | - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | | |
14661 | - _PAGE_USER)); | |
14662 | + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE)); | |
14663 | } | |
14664 | pmd = pmd_offset(pud, phys); | |
14665 | BUG_ON(!pmd_none(*pmd)); | |
14666 | @@ -888,7 +899,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to | |
14667 | */ | |
14668 | int devmem_is_allowed(unsigned long pagenr) | |
14669 | { | |
14670 | - if (pagenr <= 256) | |
14671 | + if (!pagenr) | |
14672 | + return 1; | |
14673 | + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT)) | |
14674 | return 1; | |
14675 | if (iomem_is_exclusive(pagenr << PAGE_SHIFT)) | |
14676 | return 0; | |
14677 | @@ -979,6 +992,39 @@ void free_init_pages(char *what, unsigne | |
14678 | ||
14679 | void free_initmem(void) | |
14680 | { | |
14681 | + | |
14682 | +#ifdef CONFIG_PAX_KERNEXEC | |
14683 | + unsigned long addr, end; | |
14684 | + pgd_t *pgd; | |
14685 | + pud_t *pud; | |
14686 | + pmd_t *pmd; | |
14687 | + | |
14688 | + /* PaX: make kernel code/rodata read-only, rest non-executable */ | |
14689 | + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) { | |
14690 | + pgd = pgd_offset_k(addr); | |
14691 | + pud = pud_offset(pgd, addr); | |
14692 | + pmd = pmd_offset(pud, addr); | |
14693 | + if ((unsigned long)_text <= addr && addr < (unsigned long)_data) | |
14694 | + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW)); | |
14695 | + else | |
14696 | + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask))); | |
14697 | + } | |
14698 | + | |
14699 | + addr = (unsigned long)__va(__pa(__START_KERNEL_map)); | |
14700 | + end = addr + KERNEL_IMAGE_SIZE; | |
14701 | + for (; addr < end; addr += PMD_SIZE) { | |
14702 | + pgd = pgd_offset_k(addr); | |
14703 | + pud = pud_offset(pgd, addr); | |
14704 | + pmd = pmd_offset(pud, addr); | |
14705 | + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data))) | |
14706 | + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW)); | |
14707 | + else | |
14708 | + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask))); | |
14709 | + } | |
14710 | + | |
14711 | + flush_tlb_all(); | |
14712 | +#endif | |
14713 | + | |
14714 | free_init_pages("unused kernel memory", | |
14715 | (unsigned long)(&__init_begin), | |
14716 | (unsigned long)(&__init_end)); | |
de855c5d AM |
14717 | @@ -1116,8 +1162,8 @@ int kern_addr_valid(unsigned long addr) |
14718 | static struct vm_area_struct gate_vma = { | |
14719 | .vm_start = VSYSCALL_START, | |
14720 | .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE), | |
14721 | - .vm_page_prot = PAGE_READONLY_EXEC, | |
14722 | - .vm_flags = VM_READ | VM_EXEC | |
14723 | + .vm_page_prot = PAGE_READONLY, | |
14724 | + .vm_flags = VM_READ | |
14725 | }; | |
14726 | ||
14727 | struct vm_area_struct *get_gate_vma(struct task_struct *tsk) | |
2380c486 JR |
14728 | @@ -1151,7 +1197,7 @@ int in_gate_area_no_task(unsigned long a |
14729 | ||
14730 | const char *arch_vma_name(struct vm_area_struct *vma) | |
14731 | { | |
14732 | - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) | |
14733 | + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso) | |
14734 | return "[vdso]"; | |
14735 | if (vma == &gate_vma) | |
14736 | return "[vsyscall]"; | |
de855c5d AM |
14737 | diff -urNp linux-2.6.29.6/arch/x86/mm/iomap_32.c linux-2.6.29.6/arch/x86/mm/iomap_32.c |
14738 | --- linux-2.6.29.6/arch/x86/mm/iomap_32.c 2009-07-02 19:41:20.000000000 -0400 | |
14739 | +++ linux-2.6.29.6/arch/x86/mm/iomap_32.c 2009-07-09 22:13:39.000000000 -0400 | |
14740 | @@ -24,7 +24,7 @@ int is_io_mapping_possible(resource_size | |
14741 | { | |
14742 | #ifndef CONFIG_X86_PAE | |
14743 | /* There is no way to map greater than 1 << 32 address without PAE */ | |
14744 | - if (base + size > 0x100000000ULL) | |
14745 | + if ((u64)base + size > 0x100000000ULL) | |
14746 | return 0; | |
14747 | #endif | |
14748 | return 1; | |
14749 | diff -urNp linux-2.6.29.6/arch/x86/mm/ioremap.c linux-2.6.29.6/arch/x86/mm/ioremap.c | |
14750 | --- linux-2.6.29.6/arch/x86/mm/ioremap.c 2009-07-02 19:41:20.000000000 -0400 | |
14751 | +++ linux-2.6.29.6/arch/x86/mm/ioremap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14752 | @@ -114,8 +114,8 @@ int page_is_ram(unsigned long pagenr) |
14753 | * Second special case: Some BIOSen report the PC BIOS | |
14754 | * area (640->1Mb) as ram even though it is not. | |
14755 | */ | |
14756 | - if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) && | |
14757 | - pagenr < (BIOS_END >> PAGE_SHIFT)) | |
14758 | + if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) && | |
14759 | + pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT)) | |
14760 | return 0; | |
14761 | ||
14762 | for (i = 0; i < e820.nr_map; i++) { | |
14763 | @@ -275,6 +275,8 @@ static void __iomem *__ioremap_caller(re | |
14764 | break; | |
14765 | } | |
14766 | ||
14767 | + prot = canon_pgprot(prot); | |
14768 | + | |
14769 | /* | |
14770 | * Ok, go for it.. | |
14771 | */ | |
de855c5d | 14772 | @@ -490,7 +492,9 @@ static int __init early_ioremap_debug_se |
2380c486 JR |
14773 | early_param("early_ioremap_debug", early_ioremap_debug_setup); |
14774 | ||
14775 | static __initdata int after_paging_init; | |
14776 | -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss; | |
de855c5d | 14777 | +#ifdef CONFIG_X86_32 |
2380c486 | 14778 | +static __read_only pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __aligned(PAGE_SIZE); |
de855c5d | 14779 | +#endif |
2380c486 JR |
14780 | |
14781 | static inline pmd_t * __init early_ioremap_pmd(unsigned long addr) | |
14782 | { | |
de855c5d | 14783 | @@ -505,7 +509,11 @@ static inline pmd_t * __init early_iorem |
2380c486 JR |
14784 | |
14785 | static inline pte_t * __init early_ioremap_pte(unsigned long addr) | |
14786 | { | |
14787 | +#ifdef CONFIG_X86_32 | |
14788 | return &bm_pte[pte_index(addr)]; | |
14789 | +#else | |
14790 | + return &level1_fixmap_pgt[pte_index(addr)]; | |
14791 | +#endif | |
14792 | } | |
14793 | ||
14794 | void __init early_ioremap_init(void) | |
de855c5d | 14795 | @@ -516,8 +524,14 @@ void __init early_ioremap_init(void) |
2380c486 JR |
14796 | printk(KERN_INFO "early_ioremap_init()\n"); |
14797 | ||
14798 | pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)); | |
14799 | +#ifdef CONFIG_X86_32 | |
14800 | memset(bm_pte, 0, sizeof(bm_pte)); | |
de855c5d AM |
14801 | +#ifdef CONFIG_COMPAT_VDSO |
14802 | + pmd_populate(&init_mm, pmd, bm_pte); | |
14803 | +#else | |
2380c486 | 14804 | pmd_populate_kernel(&init_mm, pmd, bm_pte); |
de855c5d | 14805 | +#endif |
2380c486 JR |
14806 | +#endif |
14807 | ||
14808 | /* | |
14809 | * The boot-ioremap range spans multiple pmds, for which | |
de855c5d AM |
14810 | diff -urNp linux-2.6.29.6/arch/x86/mm/mmap.c linux-2.6.29.6/arch/x86/mm/mmap.c |
14811 | --- linux-2.6.29.6/arch/x86/mm/mmap.c 2009-07-02 19:41:20.000000000 -0400 | |
14812 | +++ linux-2.6.29.6/arch/x86/mm/mmap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14813 | @@ -36,7 +36,7 @@ |
14814 | * Leave an at least ~128 MB hole. | |
14815 | */ | |
14816 | #define MIN_GAP (128*1024*1024) | |
14817 | -#define MAX_GAP (TASK_SIZE/6*5) | |
14818 | +#define MAX_GAP (pax_task_size/6*5) | |
14819 | ||
14820 | /* | |
14821 | * True on X86_32 or when emulating IA32 on X86_64 | |
14822 | @@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void) | |
14823 | return rnd << PAGE_SHIFT; | |
14824 | } | |
14825 | ||
14826 | -static unsigned long mmap_base(void) | |
14827 | +static unsigned long mmap_base(struct mm_struct *mm) | |
14828 | { | |
14829 | unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur; | |
14830 | + unsigned long pax_task_size = TASK_SIZE; | |
14831 | + | |
14832 | +#ifdef CONFIG_PAX_SEGMEXEC | |
14833 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
14834 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
14835 | +#endif | |
14836 | ||
14837 | if (gap < MIN_GAP) | |
14838 | gap = MIN_GAP; | |
14839 | else if (gap > MAX_GAP) | |
14840 | gap = MAX_GAP; | |
14841 | ||
14842 | - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd()); | |
14843 | + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd()); | |
14844 | } | |
14845 | ||
14846 | /* | |
14847 | * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64 | |
14848 | * does, but not when emulating X86_32 | |
14849 | */ | |
14850 | -static unsigned long mmap_legacy_base(void) | |
14851 | +static unsigned long mmap_legacy_base(struct mm_struct *mm) | |
14852 | { | |
14853 | - if (mmap_is_ia32()) | |
14854 | + if (mmap_is_ia32()) { | |
14855 | + | |
14856 | +#ifdef CONFIG_PAX_SEGMEXEC | |
14857 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) | |
14858 | + return SEGMEXEC_TASK_UNMAPPED_BASE; | |
14859 | + else | |
14860 | +#endif | |
14861 | + | |
14862 | return TASK_UNMAPPED_BASE; | |
14863 | - else | |
14864 | + } else | |
14865 | return TASK_UNMAPPED_BASE + mmap_rnd(); | |
14866 | } | |
14867 | ||
14868 | @@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo | |
14869 | void arch_pick_mmap_layout(struct mm_struct *mm) | |
14870 | { | |
14871 | if (mmap_is_legacy()) { | |
14872 | - mm->mmap_base = mmap_legacy_base(); | |
14873 | + mm->mmap_base = mmap_legacy_base(mm); | |
14874 | + | |
14875 | +#ifdef CONFIG_PAX_RANDMMAP | |
14876 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
14877 | + mm->mmap_base += mm->delta_mmap; | |
14878 | +#endif | |
14879 | + | |
14880 | mm->get_unmapped_area = arch_get_unmapped_area; | |
14881 | mm->unmap_area = arch_unmap_area; | |
14882 | } else { | |
14883 | - mm->mmap_base = mmap_base(); | |
14884 | + mm->mmap_base = mmap_base(mm); | |
14885 | + | |
14886 | +#ifdef CONFIG_PAX_RANDMMAP | |
14887 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
14888 | + mm->mmap_base -= mm->delta_mmap + mm->delta_stack; | |
14889 | +#endif | |
14890 | + | |
14891 | mm->get_unmapped_area = arch_get_unmapped_area_topdown; | |
14892 | mm->unmap_area = arch_unmap_area_topdown; | |
14893 | } | |
de855c5d AM |
14894 | diff -urNp linux-2.6.29.6/arch/x86/mm/numa_32.c linux-2.6.29.6/arch/x86/mm/numa_32.c |
14895 | --- linux-2.6.29.6/arch/x86/mm/numa_32.c 2009-07-02 19:41:20.000000000 -0400 | |
14896 | +++ linux-2.6.29.6/arch/x86/mm/numa_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14897 | @@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int |
14898 | } | |
14899 | #endif | |
14900 | ||
14901 | -extern unsigned long find_max_low_pfn(void); | |
14902 | extern unsigned long highend_pfn, highstart_pfn; | |
14903 | ||
14904 | #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE) | |
de855c5d AM |
14905 | diff -urNp linux-2.6.29.6/arch/x86/mm/pageattr.c linux-2.6.29.6/arch/x86/mm/pageattr.c |
14906 | --- linux-2.6.29.6/arch/x86/mm/pageattr.c 2009-07-02 19:41:20.000000000 -0400 | |
14907 | +++ linux-2.6.29.6/arch/x86/mm/pageattr.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14908 | @@ -20,6 +20,7 @@ |
14909 | #include <asm/pgalloc.h> | |
14910 | #include <asm/proto.h> | |
14911 | #include <asm/pat.h> | |
14912 | +#include <asm/desc.h> | |
14913 | ||
14914 | /* | |
14915 | * The current flushing context - we pass it instead of 5 arguments: | |
de855c5d | 14916 | @@ -259,9 +260,10 @@ static inline pgprot_t static_protection |
2380c486 JR |
14917 | * Does not cover __inittext since that is gone later on. On |
14918 | * 64bit we do not enforce !NX on the low mapping | |
14919 | */ | |
14920 | - if (within(address, (unsigned long)_text, (unsigned long)_etext)) | |
14921 | + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext))) | |
14922 | pgprot_val(forbidden) |= _PAGE_NX; | |
14923 | ||
de855c5d | 14924 | +#ifdef CONFIG_DEBUG_RODATA |
2380c486 | 14925 | /* |
de855c5d AM |
14926 | * The .rodata section needs to be read-only. Using the pfn |
14927 | * catches all aliases. | |
14928 | @@ -269,6 +271,7 @@ static inline pgprot_t static_protection | |
14929 | if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT, | |
14930 | __pa((unsigned long)__end_rodata) >> PAGE_SHIFT)) | |
14931 | pgprot_val(forbidden) |= _PAGE_RW; | |
14932 | +#endif | |
14933 | ||
14934 | prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden)); | |
14935 | ||
14936 | @@ -321,8 +324,20 @@ EXPORT_SYMBOL_GPL(lookup_address); | |
2380c486 JR |
14937 | */ |
14938 | static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte) | |
14939 | { | |
14940 | + | |
14941 | +#ifdef CONFIG_PAX_KERNEXEC | |
14942 | + unsigned long cr0; | |
14943 | + | |
14944 | + pax_open_kernel(cr0); | |
14945 | +#endif | |
14946 | + | |
14947 | /* change init_mm */ | |
14948 | set_pte_atomic(kpte, pte); | |
14949 | + | |
14950 | +#ifdef CONFIG_PAX_KERNEXEC | |
14951 | + pax_close_kernel(cr0); | |
14952 | +#endif | |
14953 | + | |
14954 | #ifdef CONFIG_X86_32 | |
14955 | if (!SHARED_KERNEL_PMD) { | |
14956 | struct page *page; | |
de855c5d AM |
14957 | diff -urNp linux-2.6.29.6/arch/x86/mm/pageattr-test.c linux-2.6.29.6/arch/x86/mm/pageattr-test.c |
14958 | --- linux-2.6.29.6/arch/x86/mm/pageattr-test.c 2009-07-02 19:41:20.000000000 -0400 | |
14959 | +++ linux-2.6.29.6/arch/x86/mm/pageattr-test.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
14960 | @@ -36,7 +36,7 @@ enum { |
14961 | ||
14962 | static int pte_testbit(pte_t pte) | |
14963 | { | |
14964 | - return pte_flags(pte) & _PAGE_UNUSED1; | |
14965 | + return pte_flags(pte) & _PAGE_CPA_TEST; | |
14966 | } | |
14967 | ||
14968 | struct split_state { | |
de855c5d AM |
14969 | diff -urNp linux-2.6.29.6/arch/x86/mm/pat.c linux-2.6.29.6/arch/x86/mm/pat.c |
14970 | --- linux-2.6.29.6/arch/x86/mm/pat.c 2009-07-02 19:41:20.000000000 -0400 | |
14971 | +++ linux-2.6.29.6/arch/x86/mm/pat.c 2009-07-09 22:13:39.000000000 -0400 | |
14972 | @@ -204,7 +204,7 @@ chk_conflict(struct memtype *new, struct | |
14973 | ||
14974 | conflict: | |
14975 | printk(KERN_INFO "%s:%d conflicting memory types " | |
14976 | - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start, | |
14977 | + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start, | |
14978 | new->end, cattr_name(new->type), cattr_name(entry->type)); | |
14979 | return -EBUSY; | |
14980 | } | |
14981 | @@ -488,7 +488,7 @@ int free_memtype(u64 start, u64 end) | |
14982 | ||
14983 | if (err) { | |
14984 | printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n", | |
14985 | - current->comm, current->pid, start, end); | |
14986 | + current->comm, task_pid_nr(current), start, end); | |
14987 | } | |
2380c486 | 14988 | |
de855c5d AM |
14989 | dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end); |
14990 | @@ -590,7 +590,7 @@ int phys_mem_access_prot_allowed(struct | |
14991 | free_memtype(offset, offset + size); | |
14992 | printk(KERN_INFO | |
14993 | "%s:%d /dev/mem ioremap_change_attr failed %s for %Lx-%Lx\n", | |
14994 | - current->comm, current->pid, | |
14995 | + current->comm, task_pid_nr(current), | |
14996 | cattr_name(flags), | |
14997 | offset, (unsigned long long)(offset + size)); | |
14998 | return 0; | |
14999 | @@ -611,7 +611,7 @@ void map_devmem(unsigned long pfn, unsig | |
15000 | if (flags != want_flags) { | |
15001 | printk(KERN_INFO | |
15002 | "%s:%d /dev/mem expected mapping type %s for %Lx-%Lx, got %s\n", | |
15003 | - current->comm, current->pid, | |
15004 | + current->comm, task_pid_nr(current), | |
15005 | cattr_name(want_flags), | |
15006 | addr, (unsigned long long)(addr + size), | |
15007 | cattr_name(flags)); | |
15008 | @@ -656,7 +656,7 @@ static int reserve_pfn_range(u64 paddr, | |
15009 | free_memtype(paddr, paddr + size); | |
15010 | printk(KERN_ERR "%s:%d map pfn expected mapping type %s" | |
15011 | " for %Lx-%Lx, got %s\n", | |
15012 | - current->comm, current->pid, | |
15013 | + current->comm, task_pid_nr(current), | |
15014 | cattr_name(want_flags), | |
15015 | (unsigned long long)paddr, | |
15016 | (unsigned long long)(paddr + size), | |
15017 | @@ -685,7 +685,7 @@ static int reserve_pfn_range(u64 paddr, | |
15018 | printk(KERN_ERR | |
15019 | "%s:%d reserve_pfn_range ioremap_change_attr failed %s " | |
15020 | "for %Lx-%Lx\n", | |
15021 | - current->comm, current->pid, | |
15022 | + current->comm, task_pid_nr(current), | |
15023 | cattr_name(flags), | |
15024 | (unsigned long long)paddr, | |
15025 | (unsigned long long)(paddr + size)); | |
15026 | diff -urNp linux-2.6.29.6/arch/x86/mm/pgtable_32.c linux-2.6.29.6/arch/x86/mm/pgtable_32.c | |
15027 | --- linux-2.6.29.6/arch/x86/mm/pgtable_32.c 2009-07-02 19:41:20.000000000 -0400 | |
15028 | +++ linux-2.6.29.6/arch/x86/mm/pgtable_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15029 | @@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr, |
15030 | pmd_t *pmd; | |
15031 | pte_t *pte; | |
15032 | ||
15033 | +#ifdef CONFIG_PAX_KERNEXEC | |
15034 | + unsigned long cr0; | |
15035 | +#endif | |
15036 | + | |
15037 | pgd = swapper_pg_dir + pgd_index(vaddr); | |
15038 | if (pgd_none(*pgd)) { | |
15039 | BUG(); | |
15040 | @@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr, | |
15041 | return; | |
15042 | } | |
15043 | pte = pte_offset_kernel(pmd, vaddr); | |
15044 | + | |
15045 | +#ifdef CONFIG_PAX_KERNEXEC | |
15046 | + pax_open_kernel(cr0); | |
15047 | +#endif | |
15048 | + | |
15049 | if (pte_val(pteval)) | |
15050 | set_pte_present(&init_mm, vaddr, pte, pteval); | |
15051 | else | |
15052 | pte_clear(&init_mm, vaddr, pte); | |
15053 | ||
15054 | +#ifdef CONFIG_PAX_KERNEXEC | |
15055 | + pax_close_kernel(cr0); | |
15056 | +#endif | |
15057 | + | |
15058 | /* | |
15059 | * It's enough to flush this one mapping. | |
15060 | * (PGE mappings get flushed as well) | |
de855c5d AM |
15061 | diff -urNp linux-2.6.29.6/arch/x86/oprofile/backtrace.c linux-2.6.29.6/arch/x86/oprofile/backtrace.c |
15062 | --- linux-2.6.29.6/arch/x86/oprofile/backtrace.c 2009-07-02 19:41:20.000000000 -0400 | |
15063 | +++ linux-2.6.29.6/arch/x86/oprofile/backtrace.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15064 | @@ -37,7 +37,7 @@ static void backtrace_address(void *data |
15065 | unsigned int *depth = data; | |
15066 | ||
15067 | if ((*depth)--) | |
15068 | - oprofile_add_trace(addr); | |
15069 | + oprofile_add_trace(ktla_ktva(addr)); | |
15070 | } | |
15071 | ||
15072 | static struct stacktrace_ops backtrace_ops = { | |
15073 | @@ -78,7 +78,7 @@ x86_backtrace(struct pt_regs * const reg | |
15074 | struct frame_head *head = (struct frame_head *)frame_pointer(regs); | |
15075 | unsigned long stack = kernel_trap_sp(regs); | |
15076 | ||
15077 | - if (!user_mode_vm(regs)) { | |
15078 | + if (!user_mode(regs)) { | |
15079 | if (depth) | |
15080 | dump_trace(NULL, regs, (unsigned long *)stack, 0, | |
15081 | &backtrace_ops, &depth); | |
de855c5d AM |
15082 | diff -urNp linux-2.6.29.6/arch/x86/oprofile/op_model_p4.c linux-2.6.29.6/arch/x86/oprofile/op_model_p4.c |
15083 | --- linux-2.6.29.6/arch/x86/oprofile/op_model_p4.c 2009-07-02 19:41:20.000000000 -0400 | |
15084 | +++ linux-2.6.29.6/arch/x86/oprofile/op_model_p4.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15085 | @@ -48,7 +48,7 @@ static inline void setup_num_counters(vo |
15086 | #endif | |
15087 | } | |
15088 | ||
15089 | -static int inline addr_increment(void) | |
15090 | +static inline int addr_increment(void) | |
15091 | { | |
15092 | #ifdef CONFIG_SMP | |
15093 | return smp_num_siblings == 2 ? 2 : 1; | |
de855c5d AM |
15094 | diff -urNp linux-2.6.29.6/arch/x86/pci/common.c linux-2.6.29.6/arch/x86/pci/common.c |
15095 | --- linux-2.6.29.6/arch/x86/pci/common.c 2009-07-02 19:41:20.000000000 -0400 | |
15096 | +++ linux-2.6.29.6/arch/x86/pci/common.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15097 | @@ -367,7 +367,7 @@ static struct dmi_system_id __devinitdat |
15098 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"), | |
15099 | }, | |
15100 | }, | |
15101 | - {} | |
15102 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL} | |
15103 | }; | |
15104 | ||
15105 | void __init dmi_check_pciprobe(void) | |
de855c5d AM |
15106 | diff -urNp linux-2.6.29.6/arch/x86/pci/fixup.c linux-2.6.29.6/arch/x86/pci/fixup.c |
15107 | --- linux-2.6.29.6/arch/x86/pci/fixup.c 2009-07-02 19:41:20.000000000 -0400 | |
15108 | +++ linux-2.6.29.6/arch/x86/pci/fixup.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15109 | @@ -364,7 +364,7 @@ static struct dmi_system_id __devinitdat |
15110 | DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"), | |
15111 | }, | |
15112 | }, | |
15113 | - {} | |
15114 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
15115 | }; | |
15116 | ||
15117 | /* | |
15118 | @@ -435,7 +435,7 @@ static struct dmi_system_id __devinitdat | |
15119 | DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"), | |
15120 | }, | |
15121 | }, | |
15122 | - { } | |
15123 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
15124 | }; | |
15125 | ||
15126 | static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev) | |
de855c5d AM |
15127 | diff -urNp linux-2.6.29.6/arch/x86/pci/irq.c linux-2.6.29.6/arch/x86/pci/irq.c |
15128 | --- linux-2.6.29.6/arch/x86/pci/irq.c 2009-07-02 19:41:20.000000000 -0400 | |
15129 | +++ linux-2.6.29.6/arch/x86/pci/irq.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15130 | @@ -543,7 +543,7 @@ static __init int intel_router_probe(str |
15131 | static struct pci_device_id __initdata pirq_440gx[] = { | |
15132 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) }, | |
15133 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) }, | |
15134 | - { }, | |
15135 | + { PCI_DEVICE(0, 0) } | |
15136 | }; | |
15137 | ||
15138 | /* 440GX has a proprietary PIRQ router -- don't use it */ | |
15139 | @@ -1145,7 +1145,7 @@ static struct dmi_system_id __initdata p | |
15140 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"), | |
15141 | }, | |
15142 | }, | |
15143 | - { } | |
15144 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
15145 | }; | |
15146 | ||
15147 | int __init pcibios_irq_init(void) | |
de855c5d AM |
15148 | diff -urNp linux-2.6.29.6/arch/x86/pci/pcbios.c linux-2.6.29.6/arch/x86/pci/pcbios.c |
15149 | --- linux-2.6.29.6/arch/x86/pci/pcbios.c 2009-07-02 19:41:20.000000000 -0400 | |
15150 | +++ linux-2.6.29.6/arch/x86/pci/pcbios.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15151 | @@ -56,50 +56,120 @@ union bios32 { |
15152 | static struct { | |
15153 | unsigned long address; | |
15154 | unsigned short segment; | |
15155 | -} bios32_indirect = { 0, __KERNEL_CS }; | |
15156 | +} bios32_indirect __read_only = { 0, __PCIBIOS_CS }; | |
15157 | ||
15158 | /* | |
15159 | * Returns the entry point for the given service, NULL on error | |
15160 | */ | |
15161 | ||
15162 | -static unsigned long bios32_service(unsigned long service) | |
15163 | +static unsigned long __devinit bios32_service(unsigned long service) | |
15164 | { | |
15165 | unsigned char return_code; /* %al */ | |
15166 | unsigned long address; /* %ebx */ | |
15167 | unsigned long length; /* %ecx */ | |
15168 | unsigned long entry; /* %edx */ | |
15169 | unsigned long flags; | |
15170 | + struct desc_struct d, *gdt; | |
15171 | + | |
15172 | +#ifdef CONFIG_PAX_KERNEXEC | |
15173 | + unsigned long cr0; | |
15174 | +#endif | |
15175 | ||
15176 | local_irq_save(flags); | |
15177 | - __asm__("lcall *(%%edi); cld" | |
15178 | + | |
15179 | + gdt = get_cpu_gdt_table(smp_processor_id()); | |
15180 | + | |
15181 | +#ifdef CONFIG_PAX_KERNEXEC | |
15182 | + pax_open_kernel(cr0); | |
15183 | +#endif | |
15184 | + | |
15185 | + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC); | |
15186 | + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S); | |
15187 | + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC); | |
15188 | + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S); | |
15189 | + | |
15190 | +#ifdef CONFIG_PAX_KERNEXEC | |
15191 | + pax_close_kernel(cr0); | |
15192 | +#endif | |
15193 | + | |
15194 | + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld" | |
15195 | : "=a" (return_code), | |
15196 | "=b" (address), | |
15197 | "=c" (length), | |
15198 | "=d" (entry) | |
15199 | : "0" (service), | |
15200 | "1" (0), | |
15201 | - "D" (&bios32_indirect)); | |
15202 | + "D" (&bios32_indirect), | |
15203 | + "r"(__PCIBIOS_DS) | |
15204 | + : "memory"); | |
15205 | + | |
15206 | +#ifdef CONFIG_PAX_KERNEXEC | |
15207 | + pax_open_kernel(cr0); | |
15208 | +#endif | |
15209 | + | |
15210 | + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0; | |
15211 | + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0; | |
15212 | + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0; | |
15213 | + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0; | |
15214 | + | |
15215 | +#ifdef CONFIG_PAX_KERNEXEC | |
15216 | + pax_close_kernel(cr0); | |
15217 | +#endif | |
15218 | + | |
15219 | local_irq_restore(flags); | |
15220 | ||
15221 | switch (return_code) { | |
15222 | - case 0: | |
15223 | - return address + entry; | |
15224 | - case 0x80: /* Not present */ | |
15225 | - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service); | |
15226 | - return 0; | |
15227 | - default: /* Shouldn't happen */ | |
15228 | - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n", | |
15229 | - service, return_code); | |
15230 | + case 0: { | |
15231 | + int cpu; | |
15232 | + unsigned char flags; | |
15233 | + | |
15234 | + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry); | |
15235 | + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) { | |
15236 | + printk(KERN_WARNING "bios32_service: not valid\n"); | |
15237 | return 0; | |
15238 | + } | |
15239 | + address = address + PAGE_OFFSET; | |
15240 | + length += 16UL; /* some BIOSs underreport this... */ | |
15241 | + flags = 4; | |
15242 | + if (length >= 64*1024*1024) { | |
15243 | + length >>= PAGE_SHIFT; | |
15244 | + flags |= 8; | |
15245 | + } | |
15246 | + | |
15247 | +#ifdef CONFIG_PAX_KERNEXEC | |
15248 | + pax_open_kernel(cr0); | |
15249 | +#endif | |
15250 | + | |
15251 | + for (cpu = 0; cpu < NR_CPUS; cpu++) { | |
15252 | + gdt = get_cpu_gdt_table(cpu); | |
15253 | + pack_descriptor(&d, address, length, 0x9b, flags); | |
15254 | + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S); | |
15255 | + pack_descriptor(&d, address, length, 0x93, flags); | |
15256 | + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S); | |
15257 | + } | |
15258 | + | |
15259 | +#ifdef CONFIG_PAX_KERNEXEC | |
15260 | + pax_close_kernel(cr0); | |
15261 | +#endif | |
15262 | + | |
15263 | + return entry; | |
15264 | + } | |
15265 | + case 0x80: /* Not present */ | |
15266 | + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service); | |
15267 | + return 0; | |
15268 | + default: /* Shouldn't happen */ | |
15269 | + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n", | |
15270 | + service, return_code); | |
15271 | + return 0; | |
15272 | } | |
15273 | } | |
15274 | ||
15275 | static struct { | |
15276 | unsigned long address; | |
15277 | unsigned short segment; | |
15278 | -} pci_indirect = { 0, __KERNEL_CS }; | |
15279 | +} pci_indirect __read_only = { 0, __PCIBIOS_CS }; | |
15280 | ||
15281 | -static int pci_bios_present; | |
15282 | +static int pci_bios_present __read_only; | |
15283 | ||
15284 | static int __devinit check_pcibios(void) | |
15285 | { | |
15286 | @@ -108,11 +178,13 @@ static int __devinit check_pcibios(void) | |
15287 | unsigned long flags, pcibios_entry; | |
15288 | ||
15289 | if ((pcibios_entry = bios32_service(PCI_SERVICE))) { | |
15290 | - pci_indirect.address = pcibios_entry + PAGE_OFFSET; | |
15291 | + pci_indirect.address = pcibios_entry; | |
15292 | ||
15293 | local_irq_save(flags); | |
15294 | - __asm__( | |
15295 | - "lcall *(%%edi); cld\n\t" | |
15296 | + __asm__("movw %w6, %%ds\n\t" | |
15297 | + "lcall *%%ss:(%%edi); cld\n\t" | |
15298 | + "push %%ss\n\t" | |
15299 | + "pop %%ds\n\t" | |
15300 | "jc 1f\n\t" | |
15301 | "xor %%ah, %%ah\n" | |
15302 | "1:" | |
15303 | @@ -121,7 +193,8 @@ static int __devinit check_pcibios(void) | |
15304 | "=b" (ebx), | |
15305 | "=c" (ecx) | |
15306 | : "1" (PCIBIOS_PCI_BIOS_PRESENT), | |
15307 | - "D" (&pci_indirect) | |
15308 | + "D" (&pci_indirect), | |
15309 | + "r" (__PCIBIOS_DS) | |
15310 | : "memory"); | |
15311 | local_irq_restore(flags); | |
15312 | ||
15313 | @@ -165,7 +238,10 @@ static int pci_bios_read(unsigned int se | |
15314 | ||
15315 | switch (len) { | |
15316 | case 1: | |
15317 | - __asm__("lcall *(%%esi); cld\n\t" | |
15318 | + __asm__("movw %w6, %%ds\n\t" | |
15319 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15320 | + "push %%ss\n\t" | |
15321 | + "pop %%ds\n\t" | |
15322 | "jc 1f\n\t" | |
15323 | "xor %%ah, %%ah\n" | |
15324 | "1:" | |
15325 | @@ -174,7 +250,8 @@ static int pci_bios_read(unsigned int se | |
15326 | : "1" (PCIBIOS_READ_CONFIG_BYTE), | |
15327 | "b" (bx), | |
15328 | "D" ((long)reg), | |
15329 | - "S" (&pci_indirect)); | |
15330 | + "S" (&pci_indirect), | |
15331 | + "r" (__PCIBIOS_DS)); | |
15332 | /* | |
15333 | * Zero-extend the result beyond 8 bits, do not trust the | |
15334 | * BIOS having done it: | |
15335 | @@ -182,7 +259,10 @@ static int pci_bios_read(unsigned int se | |
15336 | *value &= 0xff; | |
15337 | break; | |
15338 | case 2: | |
15339 | - __asm__("lcall *(%%esi); cld\n\t" | |
15340 | + __asm__("movw %w6, %%ds\n\t" | |
15341 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15342 | + "push %%ss\n\t" | |
15343 | + "pop %%ds\n\t" | |
15344 | "jc 1f\n\t" | |
15345 | "xor %%ah, %%ah\n" | |
15346 | "1:" | |
15347 | @@ -191,7 +271,8 @@ static int pci_bios_read(unsigned int se | |
15348 | : "1" (PCIBIOS_READ_CONFIG_WORD), | |
15349 | "b" (bx), | |
15350 | "D" ((long)reg), | |
15351 | - "S" (&pci_indirect)); | |
15352 | + "S" (&pci_indirect), | |
15353 | + "r" (__PCIBIOS_DS)); | |
15354 | /* | |
15355 | * Zero-extend the result beyond 16 bits, do not trust the | |
15356 | * BIOS having done it: | |
15357 | @@ -199,7 +280,10 @@ static int pci_bios_read(unsigned int se | |
15358 | *value &= 0xffff; | |
15359 | break; | |
15360 | case 4: | |
15361 | - __asm__("lcall *(%%esi); cld\n\t" | |
15362 | + __asm__("movw %w6, %%ds\n\t" | |
15363 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15364 | + "push %%ss\n\t" | |
15365 | + "pop %%ds\n\t" | |
15366 | "jc 1f\n\t" | |
15367 | "xor %%ah, %%ah\n" | |
15368 | "1:" | |
15369 | @@ -208,7 +292,8 @@ static int pci_bios_read(unsigned int se | |
15370 | : "1" (PCIBIOS_READ_CONFIG_DWORD), | |
15371 | "b" (bx), | |
15372 | "D" ((long)reg), | |
15373 | - "S" (&pci_indirect)); | |
15374 | + "S" (&pci_indirect), | |
15375 | + "r" (__PCIBIOS_DS)); | |
15376 | break; | |
15377 | } | |
15378 | ||
15379 | @@ -231,7 +316,10 @@ static int pci_bios_write(unsigned int s | |
15380 | ||
15381 | switch (len) { | |
15382 | case 1: | |
15383 | - __asm__("lcall *(%%esi); cld\n\t" | |
15384 | + __asm__("movw %w6, %%ds\n\t" | |
15385 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15386 | + "push %%ss\n\t" | |
15387 | + "pop %%ds\n\t" | |
15388 | "jc 1f\n\t" | |
15389 | "xor %%ah, %%ah\n" | |
15390 | "1:" | |
15391 | @@ -240,10 +328,14 @@ static int pci_bios_write(unsigned int s | |
15392 | "c" (value), | |
15393 | "b" (bx), | |
15394 | "D" ((long)reg), | |
15395 | - "S" (&pci_indirect)); | |
15396 | + "S" (&pci_indirect), | |
15397 | + "r" (__PCIBIOS_DS)); | |
15398 | break; | |
15399 | case 2: | |
15400 | - __asm__("lcall *(%%esi); cld\n\t" | |
15401 | + __asm__("movw %w6, %%ds\n\t" | |
15402 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15403 | + "push %%ss\n\t" | |
15404 | + "pop %%ds\n\t" | |
15405 | "jc 1f\n\t" | |
15406 | "xor %%ah, %%ah\n" | |
15407 | "1:" | |
15408 | @@ -252,10 +344,14 @@ static int pci_bios_write(unsigned int s | |
15409 | "c" (value), | |
15410 | "b" (bx), | |
15411 | "D" ((long)reg), | |
15412 | - "S" (&pci_indirect)); | |
15413 | + "S" (&pci_indirect), | |
15414 | + "r" (__PCIBIOS_DS)); | |
15415 | break; | |
15416 | case 4: | |
15417 | - __asm__("lcall *(%%esi); cld\n\t" | |
15418 | + __asm__("movw %w6, %%ds\n\t" | |
15419 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15420 | + "push %%ss\n\t" | |
15421 | + "pop %%ds\n\t" | |
15422 | "jc 1f\n\t" | |
15423 | "xor %%ah, %%ah\n" | |
15424 | "1:" | |
15425 | @@ -264,7 +360,8 @@ static int pci_bios_write(unsigned int s | |
15426 | "c" (value), | |
15427 | "b" (bx), | |
15428 | "D" ((long)reg), | |
15429 | - "S" (&pci_indirect)); | |
15430 | + "S" (&pci_indirect), | |
15431 | + "r" (__PCIBIOS_DS)); | |
15432 | break; | |
15433 | } | |
15434 | ||
15435 | @@ -368,10 +465,13 @@ struct irq_routing_table * pcibios_get_i | |
15436 | ||
15437 | DBG("PCI: Fetching IRQ routing table... "); | |
15438 | __asm__("push %%es\n\t" | |
15439 | + "movw %w8, %%ds\n\t" | |
15440 | "push %%ds\n\t" | |
15441 | "pop %%es\n\t" | |
15442 | - "lcall *(%%esi); cld\n\t" | |
15443 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15444 | "pop %%es\n\t" | |
15445 | + "push %%ss\n\t" | |
15446 | + "pop %%ds\n" | |
15447 | "jc 1f\n\t" | |
15448 | "xor %%ah, %%ah\n" | |
15449 | "1:" | |
15450 | @@ -382,7 +482,8 @@ struct irq_routing_table * pcibios_get_i | |
15451 | "1" (0), | |
15452 | "D" ((long) &opt), | |
15453 | "S" (&pci_indirect), | |
15454 | - "m" (opt) | |
15455 | + "m" (opt), | |
15456 | + "r" (__PCIBIOS_DS) | |
15457 | : "memory"); | |
15458 | DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map); | |
15459 | if (ret & 0xff00) | |
15460 | @@ -406,7 +507,10 @@ int pcibios_set_irq_routing(struct pci_d | |
15461 | { | |
15462 | int ret; | |
15463 | ||
15464 | - __asm__("lcall *(%%esi); cld\n\t" | |
15465 | + __asm__("movw %w5, %%ds\n\t" | |
15466 | + "lcall *%%ss:(%%esi); cld\n\t" | |
15467 | + "push %%ss\n\t" | |
15468 | + "pop %%ds\n" | |
15469 | "jc 1f\n\t" | |
15470 | "xor %%ah, %%ah\n" | |
15471 | "1:" | |
15472 | @@ -414,7 +518,8 @@ int pcibios_set_irq_routing(struct pci_d | |
15473 | : "0" (PCIBIOS_SET_PCI_HW_INT), | |
15474 | "b" ((dev->bus->number << 8) | dev->devfn), | |
15475 | "c" ((irq << 8) | (pin + 10)), | |
15476 | - "S" (&pci_indirect)); | |
15477 | + "S" (&pci_indirect), | |
15478 | + "r" (__PCIBIOS_DS)); | |
15479 | return !(ret & 0xff00); | |
15480 | } | |
15481 | EXPORT_SYMBOL(pcibios_set_irq_routing); | |
de855c5d AM |
15482 | diff -urNp linux-2.6.29.6/arch/x86/power/cpu_32.c linux-2.6.29.6/arch/x86/power/cpu_32.c |
15483 | --- linux-2.6.29.6/arch/x86/power/cpu_32.c 2009-07-02 19:41:20.000000000 -0400 | |
15484 | +++ linux-2.6.29.6/arch/x86/power/cpu_32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15485 | @@ -67,7 +67,7 @@ static void do_fpu_end(void) |
15486 | static void fix_processor_context(void) | |
15487 | { | |
15488 | int cpu = smp_processor_id(); | |
15489 | - struct tss_struct *t = &per_cpu(init_tss, cpu); | |
15490 | + struct tss_struct *t = init_tss + cpu; | |
15491 | ||
15492 | set_tss_desc(cpu, t); /* | |
15493 | * This just modifies memory; should not be | |
de855c5d AM |
15494 | diff -urNp linux-2.6.29.6/arch/x86/power/cpu_64.c linux-2.6.29.6/arch/x86/power/cpu_64.c |
15495 | --- linux-2.6.29.6/arch/x86/power/cpu_64.c 2009-07-02 19:41:20.000000000 -0400 | |
15496 | +++ linux-2.6.29.6/arch/x86/power/cpu_64.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15497 | @@ -143,7 +143,11 @@ void restore_processor_state(void) |
15498 | static void fix_processor_context(void) | |
15499 | { | |
15500 | int cpu = smp_processor_id(); | |
15501 | - struct tss_struct *t = &per_cpu(init_tss, cpu); | |
15502 | + struct tss_struct *t = init_tss + cpu; | |
15503 | + | |
15504 | +#ifdef CONFIG_PAX_KERNEXEC | |
15505 | + unsigned long cr0; | |
15506 | +#endif | |
15507 | ||
15508 | /* | |
15509 | * This just modifies memory; should not be necessary. But... This | |
15510 | @@ -152,8 +156,16 @@ static void fix_processor_context(void) | |
15511 | */ | |
15512 | set_tss_desc(cpu, t); | |
15513 | ||
15514 | +#ifdef CONFIG_PAX_KERNEXEC | |
15515 | + pax_open_kernel(cr0); | |
15516 | +#endif | |
15517 | + | |
15518 | get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9; | |
15519 | ||
15520 | +#ifdef CONFIG_PAX_KERNEXEC | |
15521 | + pax_close_kernel(cr0); | |
15522 | +#endif | |
15523 | + | |
15524 | syscall_init(); /* This sets MSR_*STAR and related */ | |
15525 | load_TR_desc(); /* This does ltr */ | |
15526 | load_LDT(¤t->active_mm->context); /* This does lldt */ | |
de855c5d AM |
15527 | diff -urNp linux-2.6.29.6/arch/x86/vdso/Makefile linux-2.6.29.6/arch/x86/vdso/Makefile |
15528 | --- linux-2.6.29.6/arch/x86/vdso/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
15529 | +++ linux-2.6.29.6/arch/x86/vdso/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
15530 | @@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@ | |
15531 | $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ | |
15532 | -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) | |
15533 | ||
15534 | -VDSO_LDFLAGS = -fPIC -shared $(call ld-option, -Wl$(comma)--hash-style=sysv) | |
15535 | +VDSO_LDFLAGS = -fPIC -shared --no-undefined $(call ld-option, -Wl$(comma)--hash-style=sysv) | |
15536 | ||
15537 | # | |
15538 | # Install the unstripped copy of vdso*.so listed in $(vdso-install-y). | |
15539 | diff -urNp linux-2.6.29.6/arch/x86/vdso/vclock_gettime.c linux-2.6.29.6/arch/x86/vdso/vclock_gettime.c | |
15540 | --- linux-2.6.29.6/arch/x86/vdso/vclock_gettime.c 2009-07-02 19:41:20.000000000 -0400 | |
15541 | +++ linux-2.6.29.6/arch/x86/vdso/vclock_gettime.c 2009-07-09 22:13:39.000000000 -0400 | |
15542 | @@ -26,20 +26,43 @@ | |
15543 | ||
15544 | #define gtod vdso_vsyscall_gtod_data | |
15545 | ||
15546 | +notrace noinline long __vdso_fallback_time(long *t) | |
15547 | +{ | |
15548 | + long secs; | |
15549 | + asm volatile("syscall" | |
15550 | + : "=a" (secs) | |
15551 | + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory"); | |
15552 | + return secs; | |
15553 | +} | |
15554 | + | |
15555 | notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) | |
15556 | { | |
15557 | long ret; | |
15558 | asm("syscall" : "=a" (ret) : | |
15559 | - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory"); | |
15560 | + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory"); | |
15561 | return ret; | |
15562 | } | |
15563 | ||
15564 | +notrace static inline cycle_t __vdso_vread_hpet(void) | |
15565 | +{ | |
15566 | + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0); | |
15567 | +} | |
15568 | + | |
15569 | +notrace static inline cycle_t __vdso_vread_tsc(void) | |
15570 | +{ | |
15571 | + cycle_t ret = (cycle_t)vget_cycles(); | |
15572 | + | |
15573 | + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last; | |
15574 | +} | |
15575 | + | |
15576 | notrace static inline long vgetns(void) | |
15577 | { | |
15578 | long v; | |
15579 | - cycles_t (*vread)(void); | |
15580 | - vread = gtod->clock.vread; | |
15581 | - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask; | |
15582 | + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]) | |
15583 | + v = __vdso_vread_tsc(); | |
15584 | + else | |
15585 | + v = __vdso_vread_hpet(); | |
15586 | + v = (v - gtod->clock.cycle_last) & gtod->clock.mask; | |
15587 | return (v * gtod->clock.mult) >> gtod->clock.shift; | |
15588 | } | |
15589 | ||
15590 | @@ -88,7 +111,9 @@ notrace static noinline int do_monotonic | |
15591 | ||
15592 | notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) | |
15593 | { | |
15594 | - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) | |
15595 | + if (likely(gtod->sysctl_enabled && | |
15596 | + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) || | |
15597 | + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])))) | |
15598 | switch (clock) { | |
15599 | case CLOCK_REALTIME: | |
15600 | return do_realtime(ts); | |
15601 | @@ -100,10 +125,20 @@ notrace int __vdso_clock_gettime(clockid | |
15602 | int clock_gettime(clockid_t, struct timespec *) | |
15603 | __attribute__((weak, alias("__vdso_clock_gettime"))); | |
15604 | ||
15605 | -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) | |
15606 | +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz) | |
15607 | { | |
15608 | long ret; | |
15609 | - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) { | |
15610 | + asm("syscall" : "=a" (ret) : | |
15611 | + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory"); | |
15612 | + return ret; | |
15613 | +} | |
15614 | + | |
15615 | +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) | |
15616 | +{ | |
15617 | + if (likely(gtod->sysctl_enabled && | |
15618 | + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) || | |
15619 | + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])))) | |
15620 | + { | |
15621 | BUILD_BUG_ON(offsetof(struct timeval, tv_usec) != | |
15622 | offsetof(struct timespec, tv_nsec) || | |
15623 | sizeof(*tv) != sizeof(struct timespec)); | |
15624 | @@ -116,9 +151,7 @@ notrace int __vdso_gettimeofday(struct t | |
15625 | } | |
15626 | return 0; | |
15627 | } | |
15628 | - asm("syscall" : "=a" (ret) : | |
15629 | - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory"); | |
15630 | - return ret; | |
15631 | + return __vdso_fallback_gettimeofday(tv, tz); | |
15632 | } | |
15633 | int gettimeofday(struct timeval *, struct timezone *) | |
15634 | __attribute__((weak, alias("__vdso_gettimeofday"))); | |
15635 | diff -urNp linux-2.6.29.6/arch/x86/vdso/vdso32-setup.c linux-2.6.29.6/arch/x86/vdso/vdso32-setup.c | |
15636 | --- linux-2.6.29.6/arch/x86/vdso/vdso32-setup.c 2009-07-02 19:41:20.000000000 -0400 | |
15637 | +++ linux-2.6.29.6/arch/x86/vdso/vdso32-setup.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15638 | @@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m |
15639 | void enable_sep_cpu(void) | |
15640 | { | |
15641 | int cpu = get_cpu(); | |
15642 | - struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
15643 | + struct tss_struct *tss = init_tss + cpu; | |
15644 | ||
15645 | if (!boot_cpu_has(X86_FEATURE_SEP)) { | |
15646 | put_cpu(); | |
15647 | @@ -249,7 +249,7 @@ static int __init gate_vma_init(void) | |
15648 | gate_vma.vm_start = FIXADDR_USER_START; | |
15649 | gate_vma.vm_end = FIXADDR_USER_END; | |
15650 | gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC; | |
15651 | - gate_vma.vm_page_prot = __P101; | |
15652 | + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags); | |
15653 | /* | |
15654 | * Make sure the vDSO gets into every core dump. | |
15655 | * Dumping its contents makes post-mortem fully interpretable later | |
15656 | @@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l | |
15657 | if (compat) | |
15658 | addr = VDSO_HIGH_BASE; | |
15659 | else { | |
15660 | - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0); | |
15661 | + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE); | |
15662 | if (IS_ERR_VALUE(addr)) { | |
15663 | ret = addr; | |
15664 | goto up_fail; | |
15665 | @@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l | |
15666 | goto up_fail; | |
15667 | } | |
15668 | ||
15669 | - current->mm->context.vdso = (void *)addr; | |
15670 | + current->mm->context.vdso = addr; | |
15671 | current_thread_info()->sysenter_return = | |
15672 | VDSO32_SYMBOL(addr, SYSENTER_RETURN); | |
15673 | ||
15674 | @@ -384,7 +384,7 @@ static ctl_table abi_table2[] = { | |
15675 | .mode = 0644, | |
15676 | .proc_handler = proc_dointvec | |
15677 | }, | |
15678 | - {} | |
15679 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
15680 | }; | |
15681 | ||
15682 | static ctl_table abi_root_table2[] = { | |
15683 | @@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = { | |
15684 | .mode = 0555, | |
15685 | .child = abi_table2 | |
15686 | }, | |
15687 | - {} | |
15688 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
15689 | }; | |
15690 | ||
15691 | static __init int ia32_binfmt_init(void) | |
15692 | @@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init); | |
15693 | ||
15694 | const char *arch_vma_name(struct vm_area_struct *vma) | |
15695 | { | |
15696 | - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) | |
15697 | + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso) | |
15698 | return "[vdso]"; | |
15699 | + | |
15700 | +#ifdef CONFIG_PAX_SEGMEXEC | |
15701 | + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso) | |
15702 | + return "[vdso]"; | |
15703 | +#endif | |
15704 | + | |
15705 | return NULL; | |
15706 | } | |
15707 | ||
15708 | @@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru | |
15709 | struct mm_struct *mm = tsk->mm; | |
15710 | ||
15711 | /* Check to see if this task was created in compat vdso mode */ | |
15712 | - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE) | |
15713 | + if (mm && mm->context.vdso == VDSO_HIGH_BASE) | |
15714 | return &gate_vma; | |
15715 | return NULL; | |
15716 | } | |
de855c5d AM |
15717 | diff -urNp linux-2.6.29.6/arch/x86/vdso/vdso.lds.S linux-2.6.29.6/arch/x86/vdso/vdso.lds.S |
15718 | --- linux-2.6.29.6/arch/x86/vdso/vdso.lds.S 2009-07-02 19:41:20.000000000 -0400 | |
15719 | +++ linux-2.6.29.6/arch/x86/vdso/vdso.lds.S 2009-07-09 22:13:39.000000000 -0400 | |
15720 | @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK; | |
15721 | #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x; | |
15722 | #include "vextern.h" | |
15723 | #undef VEXTERN | |
15724 | + | |
15725 | +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x; | |
15726 | +VEXTERN(fallback_gettimeofday) | |
15727 | +VEXTERN(fallback_time) | |
15728 | +VEXTERN(getcpu) | |
15729 | +#undef VEXTERN | |
15730 | diff -urNp linux-2.6.29.6/arch/x86/vdso/vextern.h linux-2.6.29.6/arch/x86/vdso/vextern.h | |
15731 | --- linux-2.6.29.6/arch/x86/vdso/vextern.h 2009-07-02 19:41:20.000000000 -0400 | |
15732 | +++ linux-2.6.29.6/arch/x86/vdso/vextern.h 2009-07-09 22:13:39.000000000 -0400 | |
15733 | @@ -11,6 +11,5 @@ | |
15734 | put into vextern.h and be referenced as a pointer with vdso prefix. | |
15735 | The main kernel later fills in the values. */ | |
15736 | ||
15737 | -VEXTERN(jiffies) | |
15738 | VEXTERN(vgetcpu_mode) | |
15739 | VEXTERN(vsyscall_gtod_data) | |
15740 | diff -urNp linux-2.6.29.6/arch/x86/vdso/vma.c linux-2.6.29.6/arch/x86/vdso/vma.c | |
15741 | --- linux-2.6.29.6/arch/x86/vdso/vma.c 2009-07-02 19:41:20.000000000 -0400 | |
15742 | +++ linux-2.6.29.6/arch/x86/vdso/vma.c 2009-07-09 22:13:39.000000000 -0400 | |
15743 | @@ -8,6 +8,7 @@ | |
15744 | #include <linux/sched.h> | |
15745 | #include <linux/init.h> | |
15746 | #include <linux/random.h> | |
15747 | +#include <linux/elf.h> | |
15748 | #include <asm/vsyscall.h> | |
15749 | #include <asm/vgtod.h> | |
15750 | #include <asm/proto.h> | |
15751 | @@ -56,7 +57,7 @@ static int __init init_vdso_vars(void) | |
15752 | if (!vbase) | |
15753 | goto oom; | |
15754 | ||
15755 | - if (memcmp(vbase, "\177ELF", 4)) { | |
15756 | + if (memcmp(vbase, ELFMAG, SELFMAG)) { | |
15757 | printk("VDSO: I'm broken; not ELF\n"); | |
15758 | vdso_enabled = 0; | |
15759 | } | |
15760 | @@ -65,6 +66,7 @@ static int __init init_vdso_vars(void) | |
15761 | *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x; | |
15762 | #include "vextern.h" | |
15763 | #undef VEXTERN | |
15764 | + vunmap(vbase); | |
15765 | return 0; | |
15766 | ||
15767 | oom: | |
15768 | @@ -123,7 +125,7 @@ int arch_setup_additional_pages(struct l | |
2380c486 JR |
15769 | if (ret) |
15770 | goto up_fail; | |
15771 | ||
15772 | - current->mm->context.vdso = (void *)addr; | |
15773 | + current->mm->context.vdso = addr; | |
15774 | up_fail: | |
15775 | up_write(&mm->mmap_sem); | |
15776 | return ret; | |
de855c5d AM |
15777 | diff -urNp linux-2.6.29.6/arch/x86/xen/enlighten.c linux-2.6.29.6/arch/x86/xen/enlighten.c |
15778 | --- linux-2.6.29.6/arch/x86/xen/enlighten.c 2009-07-02 19:41:20.000000000 -0400 | |
15779 | +++ linux-2.6.29.6/arch/x86/xen/enlighten.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15780 | @@ -319,7 +319,7 @@ static void xen_set_ldt(const void *addr |
15781 | static void xen_load_gdt(const struct desc_ptr *dtr) | |
15782 | { | |
15783 | unsigned long *frames; | |
15784 | - unsigned long va = dtr->address; | |
15785 | + unsigned long va = (unsigned long)dtr->address; | |
15786 | unsigned int size = dtr->size + 1; | |
15787 | unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; | |
15788 | int f; | |
15789 | @@ -334,7 +334,7 @@ static void xen_load_gdt(const struct de | |
15790 | mcs = xen_mc_entry(sizeof(*frames) * pages); | |
15791 | frames = mcs.args; | |
15792 | ||
15793 | - for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) { | |
15794 | + for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) { | |
15795 | frames[f] = virt_to_mfn(va); | |
15796 | make_lowmem_page_readonly((void *)va); | |
15797 | } | |
15798 | @@ -442,7 +442,7 @@ static void xen_write_idt_entry(gate_des | |
15799 | ||
15800 | preempt_disable(); | |
15801 | ||
15802 | - start = __get_cpu_var(idt_desc).address; | |
15803 | + start = (unsigned long)__get_cpu_var(idt_desc).address; | |
15804 | end = start + __get_cpu_var(idt_desc).size + 1; | |
15805 | ||
15806 | xen_mc_flush(); | |
15807 | @@ -1528,6 +1528,8 @@ static __init pgd_t *xen_setup_kernel_pa | |
15808 | convert_pfn_mfn(init_level4_pgt); | |
15809 | convert_pfn_mfn(level3_ident_pgt); | |
15810 | convert_pfn_mfn(level3_kernel_pgt); | |
15811 | + convert_pfn_mfn(level3_vmalloc_pgt); | |
15812 | + convert_pfn_mfn(level3_vmemmap_pgt); | |
15813 | ||
15814 | l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd); | |
15815 | l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud); | |
15816 | @@ -1546,9 +1548,12 @@ static __init pgd_t *xen_setup_kernel_pa | |
15817 | set_page_prot(init_level4_pgt, PAGE_KERNEL_RO); | |
15818 | set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO); | |
15819 | set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO); | |
15820 | + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO); | |
15821 | + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO); | |
15822 | set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO); | |
15823 | set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO); | |
15824 | set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO); | |
15825 | + set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO); | |
15826 | ||
15827 | /* Pin down new L4 */ | |
15828 | pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE, | |
de855c5d AM |
15829 | diff -urNp linux-2.6.29.6/arch/x86/xen/smp.c linux-2.6.29.6/arch/x86/xen/smp.c |
15830 | --- linux-2.6.29.6/arch/x86/xen/smp.c 2009-07-02 19:41:20.000000000 -0400 | |
15831 | +++ linux-2.6.29.6/arch/x86/xen/smp.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15832 | @@ -171,11 +171,6 @@ static void __init xen_smp_prepare_boot_ |
15833 | { | |
15834 | BUG_ON(smp_processor_id() != 0); | |
15835 | native_smp_prepare_boot_cpu(); | |
15836 | - | |
15837 | - /* We've switched to the "real" per-cpu gdt, so make sure the | |
15838 | - old memory can be recycled */ | |
15839 | - make_lowmem_page_readwrite(&per_cpu_var(gdt_page)); | |
15840 | - | |
15841 | xen_setup_vcpu_info_placement(); | |
15842 | } | |
15843 | ||
15844 | @@ -234,8 +229,8 @@ cpu_initialize_context(unsigned int cpu, | |
15845 | gdt = get_cpu_gdt_table(cpu); | |
15846 | ||
15847 | ctxt->flags = VGCF_IN_KERNEL; | |
15848 | - ctxt->user_regs.ds = __USER_DS; | |
15849 | - ctxt->user_regs.es = __USER_DS; | |
15850 | + ctxt->user_regs.ds = __KERNEL_DS; | |
15851 | + ctxt->user_regs.es = __KERNEL_DS; | |
15852 | ctxt->user_regs.ss = __KERNEL_DS; | |
15853 | #ifdef CONFIG_X86_32 | |
15854 | ctxt->user_regs.fs = __KERNEL_PERCPU; | |
de855c5d AM |
15855 | diff -urNp linux-2.6.29.6/arch/xtensa/include/asm/atomic.h linux-2.6.29.6/arch/xtensa/include/asm/atomic.h |
15856 | --- linux-2.6.29.6/arch/xtensa/include/asm/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
15857 | +++ linux-2.6.29.6/arch/xtensa/include/asm/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
15858 | @@ -165,6 +165,9 @@ static inline int atomic_sub_return(int | |
15859 | * Atomically increments @v by 1. | |
15860 | */ | |
15861 | #define atomic_inc(v) atomic_add(1,(v)) | |
15862 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
15863 | +#define atomic_add_unchecked(i, v) atomic_add((i), (v)) | |
15864 | +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v)) | |
15865 | ||
15866 | /** | |
15867 | * atomic_inc - increment atomic variable | |
15868 | diff -urNp linux-2.6.29.6/arch/xtensa/include/asm/kmap_types.h linux-2.6.29.6/arch/xtensa/include/asm/kmap_types.h | |
15869 | --- linux-2.6.29.6/arch/xtensa/include/asm/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
15870 | +++ linux-2.6.29.6/arch/xtensa/include/asm/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15871 | @@ -25,6 +25,7 @@ enum km_type { |
15872 | KM_IRQ1, | |
15873 | KM_SOFTIRQ0, | |
15874 | KM_SOFTIRQ1, | |
15875 | + KM_CLEARPAGE, | |
15876 | KM_TYPE_NR | |
15877 | }; | |
15878 | ||
de855c5d AM |
15879 | diff -urNp linux-2.6.29.6/crypto/lrw.c linux-2.6.29.6/crypto/lrw.c |
15880 | --- linux-2.6.29.6/crypto/lrw.c 2009-07-02 19:41:20.000000000 -0400 | |
15881 | +++ linux-2.6.29.6/crypto/lrw.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15882 | @@ -60,7 +60,7 @@ static int setkey(struct crypto_tfm *par |
15883 | struct priv *ctx = crypto_tfm_ctx(parent); | |
15884 | struct crypto_cipher *child = ctx->child; | |
15885 | int err, i; | |
15886 | - be128 tmp = { 0 }; | |
15887 | + be128 tmp = { 0, 0 }; | |
15888 | int bsize = crypto_cipher_blocksize(child); | |
15889 | ||
15890 | crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); | |
de855c5d AM |
15891 | diff -urNp linux-2.6.29.6/Documentation/dontdiff linux-2.6.29.6/Documentation/dontdiff |
15892 | --- linux-2.6.29.6/Documentation/dontdiff 2009-07-02 19:41:20.000000000 -0400 | |
15893 | +++ linux-2.6.29.6/Documentation/dontdiff 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15894 | @@ -3,6 +3,7 @@ |
15895 | *.bin | |
15896 | *.cpio | |
15897 | *.csp | |
15898 | +*.dbg | |
15899 | *.dsp | |
15900 | *.dvi | |
15901 | *.elf | |
15902 | @@ -49,6 +50,10 @@ | |
15903 | 53c700_d.h | |
15904 | CVS | |
15905 | ChangeSet | |
15906 | +GPATH | |
15907 | +GRTAGS | |
15908 | +GSYMS | |
15909 | +GTAGS | |
15910 | Image | |
15911 | Kerntypes | |
15912 | Module.markers | |
15913 | @@ -62,7 +67,6 @@ aic7*reg_print.c* | |
15914 | aic7*seq.h* | |
15915 | aicasm | |
15916 | aicdb.h* | |
15917 | -asm | |
15918 | asm-offsets.h | |
15919 | asm_offsets.h | |
15920 | autoconf.h* | |
15921 | @@ -77,6 +81,7 @@ btfixupprep | |
15922 | build | |
15923 | bvmlinux | |
15924 | bzImage* | |
15925 | +capflags.c | |
15926 | classlist.h* | |
15927 | comp*.log | |
15928 | compile.h* | |
de855c5d AM |
15929 | @@ -104,6 +109,7 @@ gen_crc32table |
15930 | gen_init_cpio | |
15931 | genksyms | |
15932 | *_gray256.c | |
15933 | +hash | |
15934 | ihex2fw | |
15935 | ikconfig.h* | |
15936 | initramfs_data.cpio | |
15937 | @@ -165,6 +171,7 @@ setup | |
15938 | setup.bin | |
15939 | setup.elf | |
15940 | sImage | |
15941 | +slabinfo | |
15942 | sm_tbl* | |
15943 | split-include | |
15944 | syscalltab.h | |
15945 | @@ -188,12 +195,15 @@ version.h* | |
2380c486 JR |
15946 | vmlinux |
15947 | vmlinux-* | |
15948 | vmlinux.aout | |
15949 | +vmlinux.bin.all | |
15950 | vmlinux.lds | |
15951 | +vmlinux.relocs | |
15952 | vsyscall.lds | |
15953 | vsyscall_32.lds | |
15954 | wanxlfw.inc | |
15955 | uImage | |
15956 | unifdef | |
15957 | +utsrelease.h | |
15958 | wakeup.bin | |
15959 | wakeup.elf | |
15960 | wakeup.lds | |
de855c5d AM |
15961 | diff -urNp linux-2.6.29.6/drivers/acpi/blacklist.c linux-2.6.29.6/drivers/acpi/blacklist.c |
15962 | --- linux-2.6.29.6/drivers/acpi/blacklist.c 2009-07-02 19:41:20.000000000 -0400 | |
15963 | +++ linux-2.6.29.6/drivers/acpi/blacklist.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15964 | @@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b |
15965 | {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal, | |
15966 | "Incorrect _ADR", 1}, | |
15967 | ||
15968 | - {""} | |
15969 | + {"", "", 0, 0, 0, all_versions, 0} | |
15970 | }; | |
15971 | ||
15972 | #if CONFIG_ACPI_BLACKLIST_YEAR | |
de855c5d AM |
15973 | diff -urNp linux-2.6.29.6/drivers/acpi/osl.c linux-2.6.29.6/drivers/acpi/osl.c |
15974 | --- linux-2.6.29.6/drivers/acpi/osl.c 2009-07-02 19:41:20.000000000 -0400 | |
15975 | +++ linux-2.6.29.6/drivers/acpi/osl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15976 | @@ -483,6 +483,8 @@ acpi_os_read_memory(acpi_physical_addres |
15977 | void __iomem *virt_addr; | |
15978 | ||
15979 | virt_addr = ioremap(phys_addr, width); | |
15980 | + if (!virt_addr) | |
15981 | + return AE_NO_MEMORY; | |
15982 | if (!value) | |
15983 | value = &dummy; | |
15984 | ||
15985 | @@ -511,6 +513,8 @@ acpi_os_write_memory(acpi_physical_addre | |
15986 | void __iomem *virt_addr; | |
15987 | ||
15988 | virt_addr = ioremap(phys_addr, width); | |
15989 | + if (!virt_addr) | |
15990 | + return AE_NO_MEMORY; | |
15991 | ||
15992 | switch (width) { | |
15993 | case 8: | |
de855c5d AM |
15994 | diff -urNp linux-2.6.29.6/drivers/acpi/processor_core.c linux-2.6.29.6/drivers/acpi/processor_core.c |
15995 | --- linux-2.6.29.6/drivers/acpi/processor_core.c 2009-07-02 19:41:20.000000000 -0400 | |
15996 | +++ linux-2.6.29.6/drivers/acpi/processor_core.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
15997 | @@ -678,7 +678,7 @@ static int __cpuinit acpi_processor_star |
15998 | return 0; | |
15999 | } | |
16000 | ||
16001 | - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); | |
16002 | + BUG_ON(pr->id >= nr_cpu_ids); | |
16003 | ||
16004 | /* | |
16005 | * Buggy BIOS check | |
de855c5d AM |
16006 | diff -urNp linux-2.6.29.6/drivers/acpi/processor_idle.c linux-2.6.29.6/drivers/acpi/processor_idle.c |
16007 | --- linux-2.6.29.6/drivers/acpi/processor_idle.c 2009-07-02 19:41:20.000000000 -0400 | |
16008 | +++ linux-2.6.29.6/drivers/acpi/processor_idle.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
16009 | @@ -156,7 +156,7 @@ static struct dmi_system_id __cpuinitdat |
16010 | DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), | |
16011 | DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")}, | |
16012 | (void *)2}, | |
16013 | - {}, | |
16014 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}, | |
16015 | }; | |
16016 | ||
16017 | static inline u32 ticks_elapsed(u32 t1, u32 t2) | |
de855c5d AM |
16018 | diff -urNp linux-2.6.29.6/drivers/ata/ahci.c linux-2.6.29.6/drivers/ata/ahci.c |
16019 | --- linux-2.6.29.6/drivers/ata/ahci.c 2009-07-02 19:41:20.000000000 -0400 | |
16020 | +++ linux-2.6.29.6/drivers/ata/ahci.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
16021 | @@ -611,7 +611,7 @@ static const struct pci_device_id ahci_p |
16022 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, | |
16023 | PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci }, | |
16024 | ||
16025 | - { } /* terminate list */ | |
16026 | + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ | |
16027 | }; | |
16028 | ||
16029 | ||
de855c5d AM |
16030 | diff -urNp linux-2.6.29.6/drivers/ata/ata_piix.c linux-2.6.29.6/drivers/ata/ata_piix.c |
16031 | --- linux-2.6.29.6/drivers/ata/ata_piix.c 2009-07-02 19:41:20.000000000 -0400 | |
16032 | +++ linux-2.6.29.6/drivers/ata/ata_piix.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
16033 | @@ -291,7 +291,7 @@ static const struct pci_device_id piix_p |
16034 | { 0x8086, 0x3b2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, | |
16035 | /* SATA Controller IDE (PCH) */ | |
16036 | { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata }, | |
16037 | - { } /* terminate list */ | |
16038 | + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ | |
16039 | }; | |
16040 | ||
16041 | static struct pci_driver piix_pci_driver = { | |
16042 | @@ -595,7 +595,7 @@ static const struct ich_laptop ich_lapto | |
16043 | { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */ | |
16044 | { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ | |
16045 | /* end marker */ | |
16046 | - { 0, } | |
16047 | + { 0, 0, 0 } | |
16048 | }; | |
16049 | ||
16050 | /** | |
16051 | @@ -1054,7 +1054,7 @@ static int piix_broken_suspend(void) | |
16052 | }, | |
16053 | }, | |
16054 | ||
16055 | - { } /* terminate list */ | |
16056 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } /* terminate list */ | |
16057 | }; | |
16058 | static const char *oemstrs[] = { | |
16059 | "Tecra M3,", | |
de855c5d AM |
16060 | diff -urNp linux-2.6.29.6/drivers/ata/libata-core.c linux-2.6.29.6/drivers/ata/libata-core.c |
16061 | --- linux-2.6.29.6/drivers/ata/libata-core.c 2009-07-02 19:41:20.000000000 -0400 | |
16062 | +++ linux-2.6.29.6/drivers/ata/libata-core.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
16063 | @@ -889,7 +889,7 @@ static const struct ata_xfer_ent { |
16064 | { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 }, | |
16065 | { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 }, | |
16066 | { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 }, | |
16067 | - { -1, }, | |
16068 | + { -1, 0, 0 } | |
16069 | }; | |
16070 | ||
16071 | /** | |
16072 | @@ -3105,7 +3105,7 @@ static const struct ata_timing ata_timin | |
16073 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 }, | |
16074 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 }, | |
16075 | ||
16076 | - { 0xFF } | |
16077 | + { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 } | |
16078 | }; | |
16079 | ||
16080 | #define ENOUGH(v, unit) (((v)-1)/(unit)+1) | |
16081 | @@ -4267,7 +4267,7 @@ static const struct ata_blacklist_entry | |
16082 | { "WD My Book", NULL, ATA_HORKAGE_1_5_GBPS, }, | |
16083 | ||
16084 | /* End Marker */ | |
16085 | - { } | |
16086 | + { NULL, NULL, 0 } | |
16087 | }; | |
16088 | ||
16089 | static int strn_pattern_cmp(const char *patt, const char *name, int wildchar) | |
de855c5d AM |
16090 | diff -urNp linux-2.6.29.6/drivers/atm/adummy.c linux-2.6.29.6/drivers/atm/adummy.c |
16091 | --- linux-2.6.29.6/drivers/atm/adummy.c 2009-07-02 19:41:20.000000000 -0400 | |
16092 | +++ linux-2.6.29.6/drivers/atm/adummy.c 2009-07-09 22:13:39.000000000 -0400 | |
16093 | @@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct | |
16094 | vcc->pop(vcc, skb); | |
16095 | else | |
16096 | dev_kfree_skb_any(skb); | |
16097 | - atomic_inc(&vcc->stats->tx); | |
16098 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16099 | ||
16100 | return 0; | |
16101 | } | |
16102 | diff -urNp linux-2.6.29.6/drivers/atm/ambassador.c linux-2.6.29.6/drivers/atm/ambassador.c | |
16103 | --- linux-2.6.29.6/drivers/atm/ambassador.c 2009-07-02 19:41:20.000000000 -0400 | |
16104 | +++ linux-2.6.29.6/drivers/atm/ambassador.c 2009-07-09 22:13:39.000000000 -0400 | |
16105 | @@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, | |
16106 | PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx); | |
16107 | ||
16108 | // VC layer stats | |
16109 | - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx); | |
16110 | + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx); | |
16111 | ||
16112 | // free the descriptor | |
16113 | kfree (tx_descr); | |
16114 | @@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, | |
16115 | dump_skb ("<<<", vc, skb); | |
16116 | ||
16117 | // VC layer stats | |
16118 | - atomic_inc(&atm_vcc->stats->rx); | |
16119 | + atomic_inc_unchecked(&atm_vcc->stats->rx); | |
16120 | __net_timestamp(skb); | |
16121 | // end of our responsability | |
16122 | atm_vcc->push (atm_vcc, skb); | |
16123 | @@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, | |
16124 | } else { | |
16125 | PRINTK (KERN_INFO, "dropped over-size frame"); | |
16126 | // should we count this? | |
16127 | - atomic_inc(&atm_vcc->stats->rx_drop); | |
16128 | + atomic_inc_unchecked(&atm_vcc->stats->rx_drop); | |
16129 | } | |
16130 | ||
16131 | } else { | |
16132 | @@ -1349,7 +1349,7 @@ static int amb_send (struct atm_vcc * at | |
16133 | } | |
16134 | ||
16135 | if (check_area (skb->data, skb->len)) { | |
16136 | - atomic_inc(&atm_vcc->stats->tx_err); | |
16137 | + atomic_inc_unchecked(&atm_vcc->stats->tx_err); | |
16138 | return -ENOMEM; // ? | |
16139 | } | |
16140 | ||
16141 | diff -urNp linux-2.6.29.6/drivers/atm/atmtcp.c linux-2.6.29.6/drivers/atm/atmtcp.c | |
16142 | --- linux-2.6.29.6/drivers/atm/atmtcp.c 2009-07-02 19:41:20.000000000 -0400 | |
16143 | +++ linux-2.6.29.6/drivers/atm/atmtcp.c 2009-07-09 22:13:39.000000000 -0400 | |
16144 | @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc | |
16145 | if (vcc->pop) vcc->pop(vcc,skb); | |
16146 | else dev_kfree_skb(skb); | |
16147 | if (dev_data) return 0; | |
16148 | - atomic_inc(&vcc->stats->tx_err); | |
16149 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16150 | return -ENOLINK; | |
16151 | } | |
16152 | size = skb->len+sizeof(struct atmtcp_hdr); | |
16153 | @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc | |
16154 | if (!new_skb) { | |
16155 | if (vcc->pop) vcc->pop(vcc,skb); | |
16156 | else dev_kfree_skb(skb); | |
16157 | - atomic_inc(&vcc->stats->tx_err); | |
16158 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16159 | return -ENOBUFS; | |
16160 | } | |
16161 | hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr)); | |
16162 | @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc | |
16163 | if (vcc->pop) vcc->pop(vcc,skb); | |
16164 | else dev_kfree_skb(skb); | |
16165 | out_vcc->push(out_vcc,new_skb); | |
16166 | - atomic_inc(&vcc->stats->tx); | |
16167 | - atomic_inc(&out_vcc->stats->rx); | |
16168 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16169 | + atomic_inc_unchecked(&out_vcc->stats->rx); | |
16170 | return 0; | |
16171 | } | |
16172 | ||
16173 | @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc | |
16174 | out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci)); | |
16175 | read_unlock(&vcc_sklist_lock); | |
16176 | if (!out_vcc) { | |
16177 | - atomic_inc(&vcc->stats->tx_err); | |
16178 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16179 | goto done; | |
16180 | } | |
16181 | skb_pull(skb,sizeof(struct atmtcp_hdr)); | |
16182 | @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc | |
16183 | __net_timestamp(new_skb); | |
16184 | skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len); | |
16185 | out_vcc->push(out_vcc,new_skb); | |
16186 | - atomic_inc(&vcc->stats->tx); | |
16187 | - atomic_inc(&out_vcc->stats->rx); | |
16188 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16189 | + atomic_inc_unchecked(&out_vcc->stats->rx); | |
16190 | done: | |
16191 | if (vcc->pop) vcc->pop(vcc,skb); | |
16192 | else dev_kfree_skb(skb); | |
16193 | diff -urNp linux-2.6.29.6/drivers/atm/eni.c linux-2.6.29.6/drivers/atm/eni.c | |
16194 | --- linux-2.6.29.6/drivers/atm/eni.c 2009-07-02 19:41:20.000000000 -0400 | |
16195 | +++ linux-2.6.29.6/drivers/atm/eni.c 2009-07-09 22:13:39.000000000 -0400 | |
16196 | @@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc) | |
16197 | DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n", | |
16198 | vcc->dev->number); | |
16199 | length = 0; | |
16200 | - atomic_inc(&vcc->stats->rx_err); | |
16201 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16202 | } | |
16203 | else { | |
16204 | length = ATM_CELL_SIZE-1; /* no HEC */ | |
16205 | @@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc) | |
16206 | size); | |
16207 | } | |
16208 | eff = length = 0; | |
16209 | - atomic_inc(&vcc->stats->rx_err); | |
16210 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16211 | } | |
16212 | else { | |
16213 | size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2); | |
16214 | @@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc) | |
16215 | "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n", | |
16216 | vcc->dev->number,vcc->vci,length,size << 2,descr); | |
16217 | length = eff = 0; | |
16218 | - atomic_inc(&vcc->stats->rx_err); | |
16219 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16220 | } | |
16221 | } | |
16222 | skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL; | |
16223 | @@ -770,7 +770,7 @@ rx_dequeued++; | |
16224 | vcc->push(vcc,skb); | |
16225 | pushed++; | |
16226 | } | |
16227 | - atomic_inc(&vcc->stats->rx); | |
16228 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16229 | } | |
16230 | wake_up(&eni_dev->rx_wait); | |
16231 | } | |
16232 | @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *d | |
16233 | PCI_DMA_TODEVICE); | |
16234 | if (vcc->pop) vcc->pop(vcc,skb); | |
16235 | else dev_kfree_skb_irq(skb); | |
16236 | - atomic_inc(&vcc->stats->tx); | |
16237 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16238 | wake_up(&eni_dev->tx_wait); | |
16239 | dma_complete++; | |
16240 | } | |
16241 | diff -urNp linux-2.6.29.6/drivers/atm/firestream.c linux-2.6.29.6/drivers/atm/firestream.c | |
16242 | --- linux-2.6.29.6/drivers/atm/firestream.c 2009-07-02 19:41:20.000000000 -0400 | |
16243 | +++ linux-2.6.29.6/drivers/atm/firestream.c 2009-07-09 22:13:39.000000000 -0400 | |
16244 | @@ -748,7 +748,7 @@ static void process_txdone_queue (struct | |
16245 | } | |
16246 | } | |
16247 | ||
16248 | - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx); | |
16249 | + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx); | |
16250 | ||
16251 | fs_dprintk (FS_DEBUG_TXMEM, "i"); | |
16252 | fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb); | |
16253 | @@ -815,7 +815,7 @@ static void process_incoming (struct fs_ | |
16254 | #endif | |
16255 | skb_put (skb, qe->p1 & 0xffff); | |
16256 | ATM_SKB(skb)->vcc = atm_vcc; | |
16257 | - atomic_inc(&atm_vcc->stats->rx); | |
16258 | + atomic_inc_unchecked(&atm_vcc->stats->rx); | |
16259 | __net_timestamp(skb); | |
16260 | fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb); | |
16261 | atm_vcc->push (atm_vcc, skb); | |
16262 | @@ -836,12 +836,12 @@ static void process_incoming (struct fs_ | |
16263 | kfree (pe); | |
16264 | } | |
16265 | if (atm_vcc) | |
16266 | - atomic_inc(&atm_vcc->stats->rx_drop); | |
16267 | + atomic_inc_unchecked(&atm_vcc->stats->rx_drop); | |
16268 | break; | |
16269 | case 0x1f: /* Reassembly abort: no buffers. */ | |
16270 | /* Silently increment error counter. */ | |
16271 | if (atm_vcc) | |
16272 | - atomic_inc(&atm_vcc->stats->rx_drop); | |
16273 | + atomic_inc_unchecked(&atm_vcc->stats->rx_drop); | |
16274 | break; | |
16275 | default: /* Hmm. Haven't written the code to handle the others yet... -- REW */ | |
16276 | printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n", | |
16277 | diff -urNp linux-2.6.29.6/drivers/atm/fore200e.c linux-2.6.29.6/drivers/atm/fore200e.c | |
16278 | --- linux-2.6.29.6/drivers/atm/fore200e.c 2009-07-02 19:41:20.000000000 -0400 | |
16279 | +++ linux-2.6.29.6/drivers/atm/fore200e.c 2009-07-09 22:13:39.000000000 -0400 | |
16280 | @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200 | |
16281 | #endif | |
16282 | /* check error condition */ | |
16283 | if (*entry->status & STATUS_ERROR) | |
16284 | - atomic_inc(&vcc->stats->tx_err); | |
16285 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16286 | else | |
16287 | - atomic_inc(&vcc->stats->tx); | |
16288 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16289 | } | |
16290 | } | |
16291 | ||
16292 | @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore2 | |
16293 | if (skb == NULL) { | |
16294 | DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len); | |
16295 | ||
16296 | - atomic_inc(&vcc->stats->rx_drop); | |
16297 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16298 | return -ENOMEM; | |
16299 | } | |
16300 | ||
16301 | @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore2 | |
16302 | ||
16303 | dev_kfree_skb_any(skb); | |
16304 | ||
16305 | - atomic_inc(&vcc->stats->rx_drop); | |
16306 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16307 | return -ENOMEM; | |
16308 | } | |
16309 | ||
16310 | ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0); | |
16311 | ||
16312 | vcc->push(vcc, skb); | |
16313 | - atomic_inc(&vcc->stats->rx); | |
16314 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16315 | ||
16316 | ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0); | |
16317 | ||
16318 | @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200 | |
16319 | DPRINTK(2, "damaged PDU on %d.%d.%d\n", | |
16320 | fore200e->atm_dev->number, | |
16321 | entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci); | |
16322 | - atomic_inc(&vcc->stats->rx_err); | |
16323 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16324 | } | |
16325 | } | |
16326 | ||
16327 | @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struc | |
16328 | goto retry_here; | |
16329 | } | |
16330 | ||
16331 | - atomic_inc(&vcc->stats->tx_err); | |
16332 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16333 | ||
16334 | fore200e->tx_sat++; | |
16335 | DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n", | |
16336 | diff -urNp linux-2.6.29.6/drivers/atm/he.c linux-2.6.29.6/drivers/atm/he.c | |
16337 | --- linux-2.6.29.6/drivers/atm/he.c 2009-07-02 19:41:20.000000000 -0400 | |
16338 | +++ linux-2.6.29.6/drivers/atm/he.c 2009-07-09 22:13:39.000000000 -0400 | |
16339 | @@ -1728,7 +1728,7 @@ he_service_rbrq(struct he_dev *he_dev, i | |
16340 | ||
16341 | if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) { | |
16342 | hprintk("HBUF_ERR! (cid 0x%x)\n", cid); | |
16343 | - atomic_inc(&vcc->stats->rx_drop); | |
16344 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16345 | goto return_host_buffers; | |
16346 | } | |
16347 | ||
16348 | @@ -1761,7 +1761,7 @@ he_service_rbrq(struct he_dev *he_dev, i | |
16349 | RBRQ_LEN_ERR(he_dev->rbrq_head) | |
16350 | ? "LEN_ERR" : "", | |
16351 | vcc->vpi, vcc->vci); | |
16352 | - atomic_inc(&vcc->stats->rx_err); | |
16353 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16354 | goto return_host_buffers; | |
16355 | } | |
16356 | ||
16357 | @@ -1820,7 +1820,7 @@ he_service_rbrq(struct he_dev *he_dev, i | |
16358 | vcc->push(vcc, skb); | |
16359 | spin_lock(&he_dev->global_lock); | |
16360 | ||
16361 | - atomic_inc(&vcc->stats->rx); | |
16362 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16363 | ||
16364 | return_host_buffers: | |
16365 | ++pdus_assembled; | |
16366 | @@ -2673,7 +2673,7 @@ he_send(struct atm_vcc *vcc, struct sk_b | |
16367 | __enqueue_tpd(he_dev, tpd, cid); | |
16368 | spin_unlock_irqrestore(&he_dev->global_lock, flags); | |
16369 | ||
16370 | - atomic_inc(&vcc->stats->tx); | |
16371 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16372 | ||
16373 | return 0; | |
16374 | } | |
16375 | diff -urNp linux-2.6.29.6/drivers/atm/horizon.c linux-2.6.29.6/drivers/atm/horizon.c | |
16376 | --- linux-2.6.29.6/drivers/atm/horizon.c 2009-07-02 19:41:20.000000000 -0400 | |
16377 | +++ linux-2.6.29.6/drivers/atm/horizon.c 2009-07-09 22:13:39.000000000 -0400 | |
16378 | @@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, | |
16379 | { | |
16380 | struct atm_vcc * vcc = ATM_SKB(skb)->vcc; | |
16381 | // VC layer stats | |
16382 | - atomic_inc(&vcc->stats->rx); | |
16383 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16384 | __net_timestamp(skb); | |
16385 | // end of our responsability | |
16386 | vcc->push (vcc, skb); | |
16387 | @@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const | |
16388 | dev->tx_iovec = NULL; | |
16389 | ||
16390 | // VC layer stats | |
16391 | - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx); | |
16392 | + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx); | |
16393 | ||
16394 | // free the skb | |
16395 | hrz_kfree_skb (skb); | |
16396 | diff -urNp linux-2.6.29.6/drivers/atm/idt77252.c linux-2.6.29.6/drivers/atm/idt77252.c | |
16397 | --- linux-2.6.29.6/drivers/atm/idt77252.c 2009-07-02 19:41:20.000000000 -0400 | |
16398 | +++ linux-2.6.29.6/drivers/atm/idt77252.c 2009-07-09 22:13:39.000000000 -0400 | |
16399 | @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, str | |
16400 | else | |
16401 | dev_kfree_skb(skb); | |
16402 | ||
16403 | - atomic_inc(&vcc->stats->tx); | |
16404 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16405 | } | |
16406 | ||
16407 | atomic_dec(&scq->used); | |
16408 | @@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, st | |
16409 | if ((sb = dev_alloc_skb(64)) == NULL) { | |
16410 | printk("%s: Can't allocate buffers for aal0.\n", | |
16411 | card->name); | |
16412 | - atomic_add(i, &vcc->stats->rx_drop); | |
16413 | + atomic_add_unchecked(i, &vcc->stats->rx_drop); | |
16414 | break; | |
16415 | } | |
16416 | if (!atm_charge(vcc, sb->truesize)) { | |
16417 | RXPRINTK("%s: atm_charge() dropped aal0 packets.\n", | |
16418 | card->name); | |
16419 | - atomic_add(i - 1, &vcc->stats->rx_drop); | |
16420 | + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); | |
16421 | dev_kfree_skb(sb); | |
16422 | break; | |
16423 | } | |
16424 | @@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, st | |
16425 | ATM_SKB(sb)->vcc = vcc; | |
16426 | __net_timestamp(sb); | |
16427 | vcc->push(vcc, sb); | |
16428 | - atomic_inc(&vcc->stats->rx); | |
16429 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16430 | ||
16431 | cell += ATM_CELL_PAYLOAD; | |
16432 | } | |
16433 | @@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, st | |
16434 | "(CDC: %08x)\n", | |
16435 | card->name, len, rpp->len, readl(SAR_REG_CDC)); | |
16436 | recycle_rx_pool_skb(card, rpp); | |
16437 | - atomic_inc(&vcc->stats->rx_err); | |
16438 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16439 | return; | |
16440 | } | |
16441 | if (stat & SAR_RSQE_CRC) { | |
16442 | RXPRINTK("%s: AAL5 CRC error.\n", card->name); | |
16443 | recycle_rx_pool_skb(card, rpp); | |
16444 | - atomic_inc(&vcc->stats->rx_err); | |
16445 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16446 | return; | |
16447 | } | |
16448 | if (skb_queue_len(&rpp->queue) > 1) { | |
16449 | @@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, st | |
16450 | RXPRINTK("%s: Can't alloc RX skb.\n", | |
16451 | card->name); | |
16452 | recycle_rx_pool_skb(card, rpp); | |
16453 | - atomic_inc(&vcc->stats->rx_err); | |
16454 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16455 | return; | |
16456 | } | |
16457 | if (!atm_charge(vcc, skb->truesize)) { | |
16458 | @@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, st | |
16459 | __net_timestamp(skb); | |
16460 | ||
16461 | vcc->push(vcc, skb); | |
16462 | - atomic_inc(&vcc->stats->rx); | |
16463 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16464 | ||
16465 | return; | |
16466 | } | |
16467 | @@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, st | |
16468 | __net_timestamp(skb); | |
16469 | ||
16470 | vcc->push(vcc, skb); | |
16471 | - atomic_inc(&vcc->stats->rx); | |
16472 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16473 | ||
16474 | if (skb->truesize > SAR_FB_SIZE_3) | |
16475 | add_rx_skb(card, 3, SAR_FB_SIZE_3, 1); | |
16476 | @@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car | |
16477 | if (vcc->qos.aal != ATM_AAL0) { | |
16478 | RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n", | |
16479 | card->name, vpi, vci); | |
16480 | - atomic_inc(&vcc->stats->rx_drop); | |
16481 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16482 | goto drop; | |
16483 | } | |
16484 | ||
16485 | if ((sb = dev_alloc_skb(64)) == NULL) { | |
16486 | printk("%s: Can't allocate buffers for AAL0.\n", | |
16487 | card->name); | |
16488 | - atomic_inc(&vcc->stats->rx_err); | |
16489 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16490 | goto drop; | |
16491 | } | |
16492 | ||
16493 | @@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car | |
16494 | ATM_SKB(sb)->vcc = vcc; | |
16495 | __net_timestamp(sb); | |
16496 | vcc->push(vcc, sb); | |
16497 | - atomic_inc(&vcc->stats->rx); | |
16498 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16499 | ||
16500 | drop: | |
16501 | skb_pull(queue, 64); | |
16502 | @@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s | |
16503 | ||
16504 | if (vc == NULL) { | |
16505 | printk("%s: NULL connection in send().\n", card->name); | |
16506 | - atomic_inc(&vcc->stats->tx_err); | |
16507 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16508 | dev_kfree_skb(skb); | |
16509 | return -EINVAL; | |
16510 | } | |
16511 | if (!test_bit(VCF_TX, &vc->flags)) { | |
16512 | printk("%s: Trying to transmit on a non-tx VC.\n", card->name); | |
16513 | - atomic_inc(&vcc->stats->tx_err); | |
16514 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16515 | dev_kfree_skb(skb); | |
16516 | return -EINVAL; | |
16517 | } | |
16518 | @@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s | |
16519 | break; | |
16520 | default: | |
16521 | printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal); | |
16522 | - atomic_inc(&vcc->stats->tx_err); | |
16523 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16524 | dev_kfree_skb(skb); | |
16525 | return -EINVAL; | |
16526 | } | |
16527 | ||
16528 | if (skb_shinfo(skb)->nr_frags != 0) { | |
16529 | printk("%s: No scatter-gather yet.\n", card->name); | |
16530 | - atomic_inc(&vcc->stats->tx_err); | |
16531 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16532 | dev_kfree_skb(skb); | |
16533 | return -EINVAL; | |
16534 | } | |
16535 | @@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s | |
16536 | ||
16537 | err = queue_skb(card, vc, skb, oam); | |
16538 | if (err) { | |
16539 | - atomic_inc(&vcc->stats->tx_err); | |
16540 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16541 | dev_kfree_skb(skb); | |
16542 | return err; | |
16543 | } | |
16544 | @@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v | |
16545 | skb = dev_alloc_skb(64); | |
16546 | if (!skb) { | |
16547 | printk("%s: Out of memory in send_oam().\n", card->name); | |
16548 | - atomic_inc(&vcc->stats->tx_err); | |
16549 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16550 | return -ENOMEM; | |
16551 | } | |
16552 | atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); | |
16553 | diff -urNp linux-2.6.29.6/drivers/atm/iphase.c linux-2.6.29.6/drivers/atm/iphase.c | |
16554 | --- linux-2.6.29.6/drivers/atm/iphase.c 2009-07-02 19:41:20.000000000 -0400 | |
16555 | +++ linux-2.6.29.6/drivers/atm/iphase.c 2009-07-09 22:13:39.000000000 -0400 | |
16556 | @@ -1125,7 +1125,7 @@ static int rx_pkt(struct atm_dev *dev) | |
16557 | status = (u_short) (buf_desc_ptr->desc_mode); | |
16558 | if (status & (RX_CER | RX_PTE | RX_OFL)) | |
16559 | { | |
16560 | - atomic_inc(&vcc->stats->rx_err); | |
16561 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16562 | IF_ERR(printk("IA: bad packet, dropping it");) | |
16563 | if (status & RX_CER) { | |
16564 | IF_ERR(printk(" cause: packet CRC error\n");) | |
16565 | @@ -1148,7 +1148,7 @@ static int rx_pkt(struct atm_dev *dev) | |
16566 | len = dma_addr - buf_addr; | |
16567 | if (len > iadev->rx_buf_sz) { | |
16568 | printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz); | |
16569 | - atomic_inc(&vcc->stats->rx_err); | |
16570 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16571 | goto out_free_desc; | |
16572 | } | |
16573 | ||
16574 | @@ -1298,7 +1298,7 @@ static void rx_dle_intr(struct atm_dev * | |
16575 | ia_vcc = INPH_IA_VCC(vcc); | |
16576 | if (ia_vcc == NULL) | |
16577 | { | |
16578 | - atomic_inc(&vcc->stats->rx_err); | |
16579 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16580 | dev_kfree_skb_any(skb); | |
16581 | atm_return(vcc, atm_guess_pdu2truesize(len)); | |
16582 | goto INCR_DLE; | |
16583 | @@ -1310,7 +1310,7 @@ static void rx_dle_intr(struct atm_dev * | |
16584 | if ((length > iadev->rx_buf_sz) || (length > | |
16585 | (skb->len - sizeof(struct cpcs_trailer)))) | |
16586 | { | |
16587 | - atomic_inc(&vcc->stats->rx_err); | |
16588 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16589 | IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)", | |
16590 | length, skb->len);) | |
16591 | dev_kfree_skb_any(skb); | |
16592 | @@ -1326,7 +1326,7 @@ static void rx_dle_intr(struct atm_dev * | |
16593 | ||
16594 | IF_RX(printk("rx_dle_intr: skb push");) | |
16595 | vcc->push(vcc,skb); | |
16596 | - atomic_inc(&vcc->stats->rx); | |
16597 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16598 | iadev->rx_pkt_cnt++; | |
16599 | } | |
16600 | INCR_DLE: | |
16601 | @@ -2921,7 +2921,7 @@ static int ia_pkt_tx (struct atm_vcc *vc | |
16602 | if ((desc == 0) || (desc > iadev->num_tx_desc)) | |
16603 | { | |
16604 | IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);) | |
16605 | - atomic_inc(&vcc->stats->tx); | |
16606 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16607 | if (vcc->pop) | |
16608 | vcc->pop(vcc, skb); | |
16609 | else | |
16610 | @@ -3026,7 +3026,7 @@ static int ia_pkt_tx (struct atm_vcc *vc | |
16611 | ATM_DESC(skb) = vcc->vci; | |
16612 | skb_queue_tail(&iadev->tx_dma_q, skb); | |
16613 | ||
16614 | - atomic_inc(&vcc->stats->tx); | |
16615 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16616 | iadev->tx_pkt_cnt++; | |
16617 | /* Increment transaction counter */ | |
16618 | writel(2, iadev->dma+IPHASE5575_TX_COUNTER); | |
16619 | diff -urNp linux-2.6.29.6/drivers/atm/lanai.c linux-2.6.29.6/drivers/atm/lanai.c | |
16620 | --- linux-2.6.29.6/drivers/atm/lanai.c 2009-07-02 19:41:20.000000000 -0400 | |
16621 | +++ linux-2.6.29.6/drivers/atm/lanai.c 2009-07-09 22:13:39.000000000 -0400 | |
16622 | @@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct l | |
16623 | vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0); | |
16624 | lanai_endtx(lanai, lvcc); | |
16625 | lanai_free_skb(lvcc->tx.atmvcc, skb); | |
16626 | - atomic_inc(&lvcc->tx.atmvcc->stats->tx); | |
16627 | + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx); | |
16628 | } | |
16629 | ||
16630 | /* Try to fill the buffer - don't call unless there is backlog */ | |
16631 | @@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc | |
16632 | ATM_SKB(skb)->vcc = lvcc->rx.atmvcc; | |
16633 | __net_timestamp(skb); | |
16634 | lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb); | |
16635 | - atomic_inc(&lvcc->rx.atmvcc->stats->rx); | |
16636 | + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx); | |
16637 | out: | |
16638 | lvcc->rx.buf.ptr = end; | |
16639 | cardvcc_write(lvcc, endptr, vcc_rxreadptr); | |
16640 | @@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_d | |
16641 | DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 " | |
16642 | "vcc %d\n", lanai->number, (unsigned int) s, vci); | |
16643 | lanai->stats.service_rxnotaal5++; | |
16644 | - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err); | |
16645 | + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err); | |
16646 | return 0; | |
16647 | } | |
16648 | if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) { | |
16649 | @@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_d | |
16650 | int bytes; | |
16651 | read_unlock(&vcc_sklist_lock); | |
16652 | DPRINTK("got trashed rx pdu on vci %d\n", vci); | |
16653 | - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err); | |
16654 | + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err); | |
16655 | lvcc->stats.x.aal5.service_trash++; | |
16656 | bytes = (SERVICE_GET_END(s) * 16) - | |
16657 | (((unsigned long) lvcc->rx.buf.ptr) - | |
16658 | @@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_d | |
16659 | } | |
16660 | if (s & SERVICE_STREAM) { | |
16661 | read_unlock(&vcc_sklist_lock); | |
16662 | - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err); | |
16663 | + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err); | |
16664 | lvcc->stats.x.aal5.service_stream++; | |
16665 | printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream " | |
16666 | "PDU on VCI %d!\n", lanai->number, vci); | |
16667 | @@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_d | |
16668 | return 0; | |
16669 | } | |
16670 | DPRINTK("got rx crc error on vci %d\n", vci); | |
16671 | - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err); | |
16672 | + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err); | |
16673 | lvcc->stats.x.aal5.service_rxcrc++; | |
16674 | lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4]; | |
16675 | cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr); | |
16676 | diff -urNp linux-2.6.29.6/drivers/atm/nicstar.c linux-2.6.29.6/drivers/atm/nicstar.c | |
16677 | --- linux-2.6.29.6/drivers/atm/nicstar.c 2009-07-02 19:41:20.000000000 -0400 | |
16678 | +++ linux-2.6.29.6/drivers/atm/nicstar.c 2009-07-09 22:13:39.000000000 -0400 | |
16679 | @@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, | |
16680 | if ((vc = (vc_map *) vcc->dev_data) == NULL) | |
16681 | { | |
16682 | printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index); | |
16683 | - atomic_inc(&vcc->stats->tx_err); | |
16684 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16685 | dev_kfree_skb_any(skb); | |
16686 | return -EINVAL; | |
16687 | } | |
16688 | @@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, | |
16689 | if (!vc->tx) | |
16690 | { | |
16691 | printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index); | |
16692 | - atomic_inc(&vcc->stats->tx_err); | |
16693 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16694 | dev_kfree_skb_any(skb); | |
16695 | return -EINVAL; | |
16696 | } | |
16697 | @@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, | |
16698 | if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) | |
16699 | { | |
16700 | printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index); | |
16701 | - atomic_inc(&vcc->stats->tx_err); | |
16702 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16703 | dev_kfree_skb_any(skb); | |
16704 | return -EINVAL; | |
16705 | } | |
16706 | @@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, | |
16707 | if (skb_shinfo(skb)->nr_frags != 0) | |
16708 | { | |
16709 | printk("nicstar%d: No scatter-gather yet.\n", card->index); | |
16710 | - atomic_inc(&vcc->stats->tx_err); | |
16711 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16712 | dev_kfree_skb_any(skb); | |
16713 | return -EINVAL; | |
16714 | } | |
16715 | @@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, | |
16716 | ||
16717 | if (push_scqe(card, vc, scq, &scqe, skb) != 0) | |
16718 | { | |
16719 | - atomic_inc(&vcc->stats->tx_err); | |
16720 | + atomic_inc_unchecked(&vcc->stats->tx_err); | |
16721 | dev_kfree_skb_any(skb); | |
16722 | return -EIO; | |
16723 | } | |
16724 | - atomic_inc(&vcc->stats->tx); | |
16725 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16726 | ||
16727 | return 0; | |
16728 | } | |
16729 | @@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16730 | { | |
16731 | printk("nicstar%d: Can't allocate buffers for aal0.\n", | |
16732 | card->index); | |
16733 | - atomic_add(i,&vcc->stats->rx_drop); | |
16734 | + atomic_add_unchecked(i,&vcc->stats->rx_drop); | |
16735 | break; | |
16736 | } | |
16737 | if (!atm_charge(vcc, sb->truesize)) | |
16738 | { | |
16739 | RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n", | |
16740 | card->index); | |
16741 | - atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */ | |
16742 | + atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */ | |
16743 | dev_kfree_skb_any(sb); | |
16744 | break; | |
16745 | } | |
16746 | @@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16747 | ATM_SKB(sb)->vcc = vcc; | |
16748 | __net_timestamp(sb); | |
16749 | vcc->push(vcc, sb); | |
16750 | - atomic_inc(&vcc->stats->rx); | |
16751 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16752 | cell += ATM_CELL_PAYLOAD; | |
16753 | } | |
16754 | ||
16755 | @@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16756 | if (iovb == NULL) | |
16757 | { | |
16758 | printk("nicstar%d: Out of iovec buffers.\n", card->index); | |
16759 | - atomic_inc(&vcc->stats->rx_drop); | |
16760 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16761 | recycle_rx_buf(card, skb); | |
16762 | return; | |
16763 | } | |
16764 | @@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16765 | else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS) | |
16766 | { | |
16767 | printk("nicstar%d: received too big AAL5 SDU.\n", card->index); | |
16768 | - atomic_inc(&vcc->stats->rx_err); | |
16769 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16770 | recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS); | |
16771 | NS_SKB(iovb)->iovcnt = 0; | |
16772 | iovb->len = 0; | |
16773 | @@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16774 | printk("nicstar%d: Expected a small buffer, and this is not one.\n", | |
16775 | card->index); | |
16776 | which_list(card, skb); | |
16777 | - atomic_inc(&vcc->stats->rx_err); | |
16778 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16779 | recycle_rx_buf(card, skb); | |
16780 | vc->rx_iov = NULL; | |
16781 | recycle_iov_buf(card, iovb); | |
16782 | @@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16783 | printk("nicstar%d: Expected a large buffer, and this is not one.\n", | |
16784 | card->index); | |
16785 | which_list(card, skb); | |
16786 | - atomic_inc(&vcc->stats->rx_err); | |
16787 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16788 | recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, | |
16789 | NS_SKB(iovb)->iovcnt); | |
16790 | vc->rx_iov = NULL; | |
16791 | @@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16792 | printk(" - PDU size mismatch.\n"); | |
16793 | else | |
16794 | printk(".\n"); | |
16795 | - atomic_inc(&vcc->stats->rx_err); | |
16796 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
16797 | recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, | |
16798 | NS_SKB(iovb)->iovcnt); | |
16799 | vc->rx_iov = NULL; | |
16800 | @@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16801 | if (!atm_charge(vcc, skb->truesize)) | |
16802 | { | |
16803 | push_rxbufs(card, skb); | |
16804 | - atomic_inc(&vcc->stats->rx_drop); | |
16805 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16806 | } | |
16807 | else | |
16808 | { | |
16809 | @@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16810 | ATM_SKB(skb)->vcc = vcc; | |
16811 | __net_timestamp(skb); | |
16812 | vcc->push(vcc, skb); | |
16813 | - atomic_inc(&vcc->stats->rx); | |
16814 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16815 | } | |
16816 | } | |
16817 | else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */ | |
16818 | @@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16819 | if (!atm_charge(vcc, sb->truesize)) | |
16820 | { | |
16821 | push_rxbufs(card, sb); | |
16822 | - atomic_inc(&vcc->stats->rx_drop); | |
16823 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16824 | } | |
16825 | else | |
16826 | { | |
16827 | @@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16828 | ATM_SKB(sb)->vcc = vcc; | |
16829 | __net_timestamp(sb); | |
16830 | vcc->push(vcc, sb); | |
16831 | - atomic_inc(&vcc->stats->rx); | |
16832 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16833 | } | |
16834 | ||
16835 | push_rxbufs(card, skb); | |
16836 | @@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16837 | if (!atm_charge(vcc, skb->truesize)) | |
16838 | { | |
16839 | push_rxbufs(card, skb); | |
16840 | - atomic_inc(&vcc->stats->rx_drop); | |
16841 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16842 | } | |
16843 | else | |
16844 | { | |
16845 | @@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16846 | ATM_SKB(skb)->vcc = vcc; | |
16847 | __net_timestamp(skb); | |
16848 | vcc->push(vcc, skb); | |
16849 | - atomic_inc(&vcc->stats->rx); | |
16850 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16851 | } | |
16852 | ||
16853 | push_rxbufs(card, sb); | |
16854 | @@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16855 | if (hb == NULL) | |
16856 | { | |
16857 | printk("nicstar%d: Out of huge buffers.\n", card->index); | |
16858 | - atomic_inc(&vcc->stats->rx_drop); | |
16859 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16860 | recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, | |
16861 | NS_SKB(iovb)->iovcnt); | |
16862 | vc->rx_iov = NULL; | |
16863 | @@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16864 | } | |
16865 | else | |
16866 | dev_kfree_skb_any(hb); | |
16867 | - atomic_inc(&vcc->stats->rx_drop); | |
16868 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
16869 | } | |
16870 | else | |
16871 | { | |
16872 | @@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_ | |
16873 | #endif /* NS_USE_DESTRUCTORS */ | |
16874 | __net_timestamp(hb); | |
16875 | vcc->push(vcc, hb); | |
16876 | - atomic_inc(&vcc->stats->rx); | |
16877 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16878 | } | |
16879 | } | |
16880 | ||
16881 | diff -urNp linux-2.6.29.6/drivers/atm/solos-pci.c linux-2.6.29.6/drivers/atm/solos-pci.c | |
16882 | --- linux-2.6.29.6/drivers/atm/solos-pci.c 2009-07-02 19:41:20.000000000 -0400 | |
16883 | +++ linux-2.6.29.6/drivers/atm/solos-pci.c 2009-07-09 22:13:39.000000000 -0400 | |
16884 | @@ -261,7 +261,7 @@ void solos_bh(unsigned long card_arg) | |
16885 | } | |
16886 | atm_charge(vcc, skb->truesize); | |
16887 | vcc->push(vcc, skb); | |
16888 | - atomic_inc(&vcc->stats->rx); | |
16889 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16890 | break; | |
16891 | ||
16892 | case PKT_COMMAND: | |
16893 | @@ -487,7 +487,7 @@ static int fpga_tx(struct solos_card *ca | |
16894 | vcc = *(void **)skb->cb; | |
16895 | ||
16896 | if (vcc) { | |
16897 | - atomic_inc(&vcc->stats->tx); | |
16898 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16899 | solos_pop(vcc, skb); | |
16900 | } else | |
16901 | dev_kfree_skb_irq(skb); | |
16902 | @@ -517,9 +517,9 @@ static int psend(struct atm_vcc *vcc, st | |
16903 | memcpy(skb2->data, skb->data, skb->len); | |
16904 | skb_put(skb2, skb->len); | |
16905 | vcc->push(vcc, skb2); | |
16906 | - atomic_inc(&vcc->stats->rx); | |
16907 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16908 | } | |
16909 | - atomic_inc(&vcc->stats->tx); | |
16910 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16911 | solos_pop(vcc, skb); | |
16912 | return 0; | |
16913 | } | |
16914 | diff -urNp linux-2.6.29.6/drivers/atm/suni.c linux-2.6.29.6/drivers/atm/suni.c | |
16915 | --- linux-2.6.29.6/drivers/atm/suni.c 2009-07-02 19:41:20.000000000 -0400 | |
16916 | +++ linux-2.6.29.6/drivers/atm/suni.c 2009-07-09 22:13:39.000000000 -0400 | |
16917 | @@ -49,7 +49,7 @@ static DEFINE_SPINLOCK(sunis_lock); | |
16918 | ||
16919 | ||
16920 | #define ADD_LIMITED(s,v) \ | |
16921 | - atomic_add((v),&stats->s); \ | |
16922 | + atomic_add_unchecked((v),&stats->s); \ | |
16923 | if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX); | |
16924 | ||
16925 | ||
16926 | diff -urNp linux-2.6.29.6/drivers/atm/uPD98402.c linux-2.6.29.6/drivers/atm/uPD98402.c | |
16927 | --- linux-2.6.29.6/drivers/atm/uPD98402.c 2009-07-02 19:41:20.000000000 -0400 | |
16928 | +++ linux-2.6.29.6/drivers/atm/uPD98402.c 2009-07-09 22:13:39.000000000 -0400 | |
16929 | @@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *d | |
16930 | struct sonet_stats tmp; | |
16931 | int error = 0; | |
16932 | ||
16933 | - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs); | |
16934 | + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs); | |
16935 | sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp); | |
16936 | if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp)); | |
16937 | if (zero && !error) { | |
16938 | @@ -160,7 +160,7 @@ static int uPD98402_ioctl(struct atm_dev | |
16939 | ||
16940 | ||
16941 | #define ADD_LIMITED(s,v) \ | |
16942 | - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \ | |
16943 | + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \ | |
16944 | if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \ | |
16945 | atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); } | |
16946 | ||
16947 | @@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev | |
16948 | if (reason & uPD98402_INT_PFM) stat_event(dev); | |
16949 | if (reason & uPD98402_INT_PCO) { | |
16950 | (void) GET(PCOCR); /* clear interrupt cause */ | |
16951 | - atomic_add(GET(HECCT), | |
16952 | + atomic_add_unchecked(GET(HECCT), | |
16953 | &PRIV(dev)->sonet_stats.uncorr_hcs); | |
16954 | } | |
16955 | if ((reason & uPD98402_INT_RFO) && | |
16956 | diff -urNp linux-2.6.29.6/drivers/atm/zatm.c linux-2.6.29.6/drivers/atm/zatm.c | |
16957 | --- linux-2.6.29.6/drivers/atm/zatm.c 2009-07-02 19:41:20.000000000 -0400 | |
16958 | +++ linux-2.6.29.6/drivers/atm/zatm.c 2009-07-09 22:13:39.000000000 -0400 | |
16959 | @@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy | |
16960 | } | |
16961 | if (!size) { | |
16962 | dev_kfree_skb_irq(skb); | |
16963 | - if (vcc) atomic_inc(&vcc->stats->rx_err); | |
16964 | + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err); | |
16965 | continue; | |
16966 | } | |
16967 | if (!atm_charge(vcc,skb->truesize)) { | |
16968 | @@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy | |
16969 | skb->len = size; | |
16970 | ATM_SKB(skb)->vcc = vcc; | |
16971 | vcc->push(vcc,skb); | |
16972 | - atomic_inc(&vcc->stats->rx); | |
16973 | + atomic_inc_unchecked(&vcc->stats->rx); | |
16974 | } | |
16975 | zout(pos & 0xffff,MTA(mbx)); | |
16976 | #if 0 /* probably a stupid idea */ | |
16977 | @@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD | |
16978 | skb_queue_head(&zatm_vcc->backlog,skb); | |
16979 | break; | |
16980 | } | |
16981 | - atomic_inc(&vcc->stats->tx); | |
16982 | + atomic_inc_unchecked(&vcc->stats->tx); | |
16983 | wake_up(&zatm_vcc->tx_wait); | |
16984 | } | |
16985 | ||
16986 | diff -urNp linux-2.6.29.6/drivers/char/agp/frontend.c linux-2.6.29.6/drivers/char/agp/frontend.c | |
16987 | --- linux-2.6.29.6/drivers/char/agp/frontend.c 2009-07-02 19:41:20.000000000 -0400 | |
16988 | +++ linux-2.6.29.6/drivers/char/agp/frontend.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
16989 | @@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag |
16990 | if (copy_from_user(&reserve, arg, sizeof(struct agp_region))) | |
16991 | return -EFAULT; | |
16992 | ||
16993 | - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment)) | |
16994 | + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv)) | |
16995 | return -EFAULT; | |
16996 | ||
16997 | client = agp_find_client_by_pid(reserve.pid); | |
de855c5d AM |
16998 | diff -urNp linux-2.6.29.6/drivers/char/agp/intel-agp.c linux-2.6.29.6/drivers/char/agp/intel-agp.c |
16999 | --- linux-2.6.29.6/drivers/char/agp/intel-agp.c 2009-07-02 19:41:20.000000000 -0400 | |
17000 | +++ linux-2.6.29.6/drivers/char/agp/intel-agp.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17001 | @@ -2369,7 +2369,7 @@ static struct pci_device_id agp_intel_pc |
17002 | ID(PCI_DEVICE_ID_INTEL_Q45_HB), | |
17003 | ID(PCI_DEVICE_ID_INTEL_G45_HB), | |
17004 | ID(PCI_DEVICE_ID_INTEL_G41_HB), | |
17005 | - { } | |
17006 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17007 | }; | |
17008 | ||
17009 | MODULE_DEVICE_TABLE(pci, agp_intel_pci_table); | |
de855c5d AM |
17010 | diff -urNp linux-2.6.29.6/drivers/char/hpet.c linux-2.6.29.6/drivers/char/hpet.c |
17011 | --- linux-2.6.29.6/drivers/char/hpet.c 2009-07-02 19:41:20.000000000 -0400 | |
17012 | +++ linux-2.6.29.6/drivers/char/hpet.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17013 | @@ -975,7 +975,7 @@ static struct acpi_driver hpet_acpi_driv |
17014 | }, | |
17015 | }; | |
17016 | ||
17017 | -static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops }; | |
17018 | +static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL }; | |
17019 | ||
17020 | static int __init hpet_init(void) | |
17021 | { | |
de855c5d AM |
17022 | diff -urNp linux-2.6.29.6/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.29.6/drivers/char/ipmi/ipmi_msghandler.c |
17023 | --- linux-2.6.29.6/drivers/char/ipmi/ipmi_msghandler.c 2009-07-02 19:41:20.000000000 -0400 | |
17024 | +++ linux-2.6.29.6/drivers/char/ipmi/ipmi_msghandler.c 2009-07-09 22:13:39.000000000 -0400 | |
17025 | @@ -408,7 +408,7 @@ struct ipmi_smi { | |
17026 | struct proc_dir_entry *proc_dir; | |
17027 | char proc_dir_name[10]; | |
17028 | ||
17029 | - atomic_t stats[IPMI_NUM_STATS]; | |
17030 | + atomic_unchecked_t stats[IPMI_NUM_STATS]; | |
17031 | ||
17032 | /* | |
17033 | * run_to_completion duplicate of smb_info, smi_info | |
17034 | @@ -441,7 +441,7 @@ static DEFINE_MUTEX(smi_watchers_mutex); | |
17035 | ||
17036 | ||
17037 | #define ipmi_inc_stat(intf, stat) \ | |
17038 | - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) | |
17039 | + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]) | |
17040 | #define ipmi_get_stat(intf, stat) \ | |
17041 | ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) | |
17042 | ||
17043 | diff -urNp linux-2.6.29.6/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.29.6/drivers/char/ipmi/ipmi_si_intf.c | |
17044 | --- linux-2.6.29.6/drivers/char/ipmi/ipmi_si_intf.c 2009-07-02 19:41:20.000000000 -0400 | |
17045 | +++ linux-2.6.29.6/drivers/char/ipmi/ipmi_si_intf.c 2009-07-09 22:13:39.000000000 -0400 | |
17046 | @@ -288,7 +288,7 @@ struct smi_info { | |
17047 | }; | |
17048 | ||
17049 | #define smi_inc_stat(smi, stat) \ | |
17050 | - atomic_inc(&(smi)->stats[SI_STAT_ ## stat]) | |
17051 | + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat]) | |
17052 | #define smi_get_stat(smi, stat) \ | |
17053 | ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) | |
17054 | ||
17055 | diff -urNp linux-2.6.29.6/drivers/char/keyboard.c linux-2.6.29.6/drivers/char/keyboard.c | |
17056 | --- linux-2.6.29.6/drivers/char/keyboard.c 2009-07-02 19:41:20.000000000 -0400 | |
17057 | +++ linux-2.6.29.6/drivers/char/keyboard.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17058 | @@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u |
17059 | kbd->kbdmode == VC_MEDIUMRAW) && | |
17060 | value != KVAL(K_SAK)) | |
17061 | return; /* SAK is allowed even in raw mode */ | |
17062 | + | |
17063 | +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP) | |
17064 | + { | |
17065 | + void *func = fn_handler[value]; | |
17066 | + if (func == fn_show_state || func == fn_show_ptregs || | |
17067 | + func == fn_show_mem) | |
17068 | + return; | |
17069 | + } | |
17070 | +#endif | |
17071 | + | |
17072 | fn_handler[value](vc); | |
17073 | } | |
17074 | ||
17075 | @@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_ | |
17076 | .evbit = { BIT_MASK(EV_SND) }, | |
17077 | }, | |
17078 | ||
17079 | - { }, /* Terminating entry */ | |
17080 | + { 0 }, /* Terminating entry */ | |
17081 | }; | |
17082 | ||
17083 | MODULE_DEVICE_TABLE(input, kbd_ids); | |
de855c5d AM |
17084 | diff -urNp linux-2.6.29.6/drivers/char/mem.c linux-2.6.29.6/drivers/char/mem.c |
17085 | --- linux-2.6.29.6/drivers/char/mem.c 2009-07-02 19:41:20.000000000 -0400 | |
17086 | +++ linux-2.6.29.6/drivers/char/mem.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17087 | @@ -18,6 +18,7 @@ |
17088 | #include <linux/raw.h> | |
17089 | #include <linux/tty.h> | |
17090 | #include <linux/capability.h> | |
17091 | +#include <linux/security.h> | |
17092 | #include <linux/ptrace.h> | |
17093 | #include <linux/device.h> | |
17094 | #include <linux/highmem.h> | |
17095 | @@ -35,6 +36,10 @@ | |
17096 | # include <linux/efi.h> | |
17097 | #endif | |
17098 | ||
de855c5d | 17099 | +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC) |
2380c486 JR |
17100 | +extern struct file_operations grsec_fops; |
17101 | +#endif | |
17102 | + | |
17103 | /* | |
17104 | * Architectures vary in how they handle caching for addresses | |
17105 | * outside of main memory. | |
17106 | @@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f | |
17107 | if (!valid_phys_addr_range(p, count)) | |
17108 | return -EFAULT; | |
17109 | ||
17110 | +#ifdef CONFIG_GRKERNSEC_KMEM | |
17111 | + gr_handle_mem_write(); | |
17112 | + return -EPERM; | |
17113 | +#endif | |
17114 | + | |
17115 | written = 0; | |
17116 | ||
17117 | #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED | |
17118 | @@ -350,6 +360,11 @@ static int mmap_mem(struct file * file, | |
17119 | &vma->vm_page_prot)) | |
17120 | return -EINVAL; | |
17121 | ||
17122 | +#ifdef CONFIG_GRKERNSEC_KMEM | |
17123 | + if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma)) | |
17124 | + return -EPERM; | |
17125 | +#endif | |
17126 | + | |
17127 | vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, | |
17128 | size, | |
17129 | vma->vm_page_prot); | |
17130 | @@ -585,6 +600,11 @@ static ssize_t write_kmem(struct file * | |
17131 | ssize_t written; | |
17132 | char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ | |
17133 | ||
17134 | +#ifdef CONFIG_GRKERNSEC_KMEM | |
17135 | + gr_handle_kmem_write(); | |
17136 | + return -EPERM; | |
17137 | +#endif | |
17138 | + | |
17139 | if (p < (unsigned long) high_memory) { | |
17140 | ||
17141 | wrote = count; | |
17142 | @@ -788,6 +808,16 @@ static loff_t memory_lseek(struct file * | |
17143 | ||
17144 | static int open_port(struct inode * inode, struct file * filp) | |
17145 | { | |
17146 | +#ifdef CONFIG_GRKERNSEC_KMEM | |
17147 | + gr_handle_open_port(); | |
17148 | + return -EPERM; | |
17149 | +#endif | |
17150 | + | |
17151 | + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; | |
17152 | +} | |
17153 | + | |
17154 | +static int open_mem(struct inode * inode, struct file * filp) | |
17155 | +{ | |
17156 | return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; | |
17157 | } | |
17158 | ||
17159 | @@ -795,7 +825,6 @@ static int open_port(struct inode * inod | |
17160 | #define full_lseek null_lseek | |
17161 | #define write_zero write_null | |
17162 | #define read_full read_zero | |
17163 | -#define open_mem open_port | |
17164 | #define open_kmem open_mem | |
17165 | #define open_oldmem open_mem | |
17166 | ||
17167 | @@ -935,6 +964,11 @@ static int memory_open(struct inode * in | |
17168 | filp->f_op = &oldmem_fops; | |
17169 | break; | |
17170 | #endif | |
de855c5d | 17171 | +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC) |
2380c486 JR |
17172 | + case 13: |
17173 | + filp->f_op = &grsec_fops; | |
17174 | + break; | |
17175 | +#endif | |
17176 | default: | |
17177 | unlock_kernel(); | |
17178 | return -ENXIO; | |
17179 | @@ -971,6 +1005,9 @@ static const struct { | |
17180 | #ifdef CONFIG_CRASH_DUMP | |
17181 | {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops}, | |
17182 | #endif | |
de855c5d | 17183 | +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC) |
2380c486 JR |
17184 | + {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops}, |
17185 | +#endif | |
17186 | }; | |
17187 | ||
17188 | static struct class *mem_class; | |
de855c5d AM |
17189 | diff -urNp linux-2.6.29.6/drivers/char/nvram.c linux-2.6.29.6/drivers/char/nvram.c |
17190 | --- linux-2.6.29.6/drivers/char/nvram.c 2009-07-02 19:41:20.000000000 -0400 | |
17191 | +++ linux-2.6.29.6/drivers/char/nvram.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17192 | @@ -429,7 +429,10 @@ static const struct file_operations nvra |
17193 | static struct miscdevice nvram_dev = { | |
17194 | NVRAM_MINOR, | |
17195 | "nvram", | |
17196 | - &nvram_fops | |
17197 | + &nvram_fops, | |
17198 | + {NULL, NULL}, | |
17199 | + NULL, | |
17200 | + NULL | |
17201 | }; | |
17202 | ||
17203 | static int __init nvram_init(void) | |
de855c5d AM |
17204 | diff -urNp linux-2.6.29.6/drivers/char/random.c linux-2.6.29.6/drivers/char/random.c |
17205 | --- linux-2.6.29.6/drivers/char/random.c 2009-07-02 19:41:20.000000000 -0400 | |
17206 | +++ linux-2.6.29.6/drivers/char/random.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17207 | @@ -249,8 +249,13 @@ |
17208 | /* | |
17209 | * Configuration information | |
17210 | */ | |
17211 | +#ifdef CONFIG_GRKERNSEC_RANDNET | |
17212 | +#define INPUT_POOL_WORDS 512 | |
17213 | +#define OUTPUT_POOL_WORDS 128 | |
17214 | +#else | |
17215 | #define INPUT_POOL_WORDS 128 | |
17216 | #define OUTPUT_POOL_WORDS 32 | |
17217 | +#endif | |
17218 | #define SEC_XFER_SIZE 512 | |
17219 | ||
17220 | /* | |
17221 | @@ -287,10 +292,17 @@ static struct poolinfo { | |
17222 | int poolwords; | |
17223 | int tap1, tap2, tap3, tap4, tap5; | |
17224 | } poolinfo_table[] = { | |
17225 | +#ifdef CONFIG_GRKERNSEC_RANDNET | |
17226 | + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */ | |
17227 | + { 512, 411, 308, 208, 104, 1 }, | |
17228 | + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */ | |
17229 | + { 128, 103, 76, 51, 25, 1 }, | |
17230 | +#else | |
17231 | /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */ | |
17232 | { 128, 103, 76, 51, 25, 1 }, | |
17233 | /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */ | |
17234 | { 32, 26, 20, 14, 7, 1 }, | |
17235 | +#endif | |
17236 | #if 0 | |
17237 | /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */ | |
17238 | { 2048, 1638, 1231, 819, 411, 1 }, | |
17239 | @@ -1200,7 +1212,7 @@ EXPORT_SYMBOL(generate_random_uuid); | |
17240 | #include <linux/sysctl.h> | |
17241 | ||
17242 | static int min_read_thresh = 8, min_write_thresh; | |
17243 | -static int max_read_thresh = INPUT_POOL_WORDS * 32; | |
17244 | +static int max_read_thresh = OUTPUT_POOL_WORDS * 32; | |
17245 | static int max_write_thresh = INPUT_POOL_WORDS * 32; | |
17246 | static char sysctl_bootid[16]; | |
17247 | ||
de855c5d AM |
17248 | diff -urNp linux-2.6.29.6/drivers/char/tty_ldisc.c linux-2.6.29.6/drivers/char/tty_ldisc.c |
17249 | --- linux-2.6.29.6/drivers/char/tty_ldisc.c 2009-07-02 19:41:20.000000000 -0400 | |
17250 | +++ linux-2.6.29.6/drivers/char/tty_ldisc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17251 | @@ -74,7 +74,7 @@ int tty_register_ldisc(int disc, struct |
17252 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17253 | tty_ldiscs[disc] = new_ldisc; | |
17254 | new_ldisc->num = disc; | |
17255 | - new_ldisc->refcount = 0; | |
17256 | + atomic_set(&new_ldisc->refcount, 0); | |
17257 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17258 | ||
17259 | return ret; | |
17260 | @@ -102,7 +102,7 @@ int tty_unregister_ldisc(int disc) | |
17261 | return -EINVAL; | |
17262 | ||
17263 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17264 | - if (tty_ldiscs[disc]->refcount) | |
17265 | + if (atomic_read(&tty_ldiscs[disc]->refcount)) | |
17266 | ret = -EBUSY; | |
17267 | else | |
17268 | tty_ldiscs[disc] = NULL; | |
17269 | @@ -139,7 +139,7 @@ static int tty_ldisc_try_get(int disc, s | |
17270 | err = -EAGAIN; | |
17271 | else { | |
17272 | /* lock it */ | |
17273 | - ldops->refcount++; | |
17274 | + atomic_inc(&ldops->refcount); | |
17275 | ld->ops = ldops; | |
17276 | err = 0; | |
17277 | } | |
17278 | @@ -196,8 +196,8 @@ static void tty_ldisc_put(struct tty_ldi | |
17279 | ||
17280 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17281 | ld = tty_ldiscs[disc]; | |
17282 | - BUG_ON(ld->refcount == 0); | |
17283 | - ld->refcount--; | |
17284 | + BUG_ON(atomic_read(&ld->refcount) == 0); | |
17285 | + atomic_dec(&ld->refcount); | |
17286 | module_put(ld->owner); | |
17287 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17288 | } | |
17289 | @@ -264,7 +264,7 @@ const struct file_operations tty_ldiscs_ | |
17290 | ||
17291 | static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) | |
17292 | { | |
17293 | - ld->refcount = 0; | |
17294 | + atomic_set(&ld->refcount, 0); | |
17295 | tty->ldisc = *ld; | |
17296 | } | |
17297 | ||
17298 | @@ -289,7 +289,7 @@ static int tty_ldisc_try(struct tty_stru | |
17299 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17300 | ld = &tty->ldisc; | |
17301 | if (test_bit(TTY_LDISC, &tty->flags)) { | |
17302 | - ld->refcount++; | |
17303 | + atomic_inc(&ld->refcount); | |
17304 | ret = 1; | |
17305 | } | |
17306 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17307 | @@ -316,7 +316,7 @@ struct tty_ldisc *tty_ldisc_ref_wait(str | |
17308 | { | |
17309 | /* wait_event is a macro */ | |
17310 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); | |
17311 | - WARN_ON(tty->ldisc.refcount == 0); | |
17312 | + WARN_ON(atomic_read(&tty->ldisc.refcount) == 0); | |
17313 | return &tty->ldisc; | |
17314 | } | |
17315 | ||
17316 | @@ -359,11 +359,9 @@ void tty_ldisc_deref(struct tty_ldisc *l | |
17317 | BUG_ON(ld == NULL); | |
17318 | ||
17319 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17320 | - if (ld->refcount == 0) | |
17321 | + if (!atomic_add_unless(&ld->refcount, -1, 0)) | |
17322 | printk(KERN_ERR "tty_ldisc_deref: no references.\n"); | |
17323 | - else | |
17324 | - ld->refcount--; | |
17325 | - if (ld->refcount == 0) | |
17326 | + if (atomic_read(&ld->refcount) == 0) | |
17327 | wake_up(&tty_ldisc_wait); | |
17328 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17329 | } | |
17330 | @@ -507,8 +505,8 @@ restart: | |
17331 | clear_bit(TTY_LDISC, &o_tty->flags); | |
17332 | ||
17333 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17334 | - if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { | |
17335 | - if (tty->ldisc.refcount) { | |
17336 | + if (atomic_read(&tty->ldisc.refcount) || (o_tty && atomic_read(&o_tty->ldisc.refcount))) { | |
17337 | + if (atomic_read(&tty->ldisc.refcount)) { | |
17338 | /* Free the new ldisc we grabbed. Must drop the lock | |
17339 | first. */ | |
17340 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17341 | @@ -520,14 +518,14 @@ restart: | |
17342 | * and retries if we made tty_ldisc_wait() smarter. | |
17343 | * That is up for discussion. | |
17344 | */ | |
17345 | - if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) | |
17346 | + if (wait_event_interruptible(tty_ldisc_wait, atomic_read(&tty->ldisc.refcount) == 0) < 0) | |
17347 | return -ERESTARTSYS; | |
17348 | goto restart; | |
17349 | } | |
17350 | - if (o_tty && o_tty->ldisc.refcount) { | |
17351 | + if (o_tty && atomic_read(&o_tty->ldisc.refcount)) { | |
17352 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17353 | tty_ldisc_put(o_tty->ldisc.ops); | |
17354 | - if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0) | |
17355 | + if (wait_event_interruptible(tty_ldisc_wait, atomic_read(&o_tty->ldisc.refcount) == 0) < 0) | |
17356 | return -ERESTARTSYS; | |
17357 | goto restart; | |
17358 | } | |
17359 | @@ -670,9 +668,9 @@ void tty_ldisc_release(struct tty_struct | |
17360 | * side is zero. | |
17361 | */ | |
17362 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17363 | - while (tty->ldisc.refcount) { | |
17364 | + while (atomic_read(&tty->ldisc.refcount)) { | |
17365 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
17366 | - wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); | |
17367 | + wait_event(tty_ldisc_wait, atomic_read(&tty->ldisc.refcount) == 0); | |
17368 | spin_lock_irqsave(&tty_ldisc_lock, flags); | |
17369 | } | |
17370 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | |
de855c5d AM |
17371 | diff -urNp linux-2.6.29.6/drivers/char/vt_ioctl.c linux-2.6.29.6/drivers/char/vt_ioctl.c |
17372 | --- linux-2.6.29.6/drivers/char/vt_ioctl.c 2009-07-02 19:41:20.000000000 -0400 | |
17373 | +++ linux-2.6.29.6/drivers/char/vt_ioctl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17374 | @@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __ |
17375 | case KDSKBENT: | |
17376 | if (!perm) | |
17377 | return -EPERM; | |
17378 | + | |
17379 | +#ifdef CONFIG_GRKERNSEC | |
17380 | + if (!capable(CAP_SYS_TTY_CONFIG)) | |
17381 | + return -EPERM; | |
17382 | +#endif | |
17383 | + | |
17384 | if (!i && v == K_NOSUCHMAP) { | |
17385 | /* deallocate map */ | |
17386 | key_map = key_maps[s]; | |
17387 | @@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry | |
17388 | goto reterr; | |
17389 | } | |
17390 | ||
17391 | +#ifdef CONFIG_GRKERNSEC | |
17392 | + if (!capable(CAP_SYS_TTY_CONFIG)) { | |
17393 | + ret = -EPERM; | |
17394 | + goto reterr; | |
17395 | + } | |
17396 | +#endif | |
17397 | + | |
17398 | q = func_table[i]; | |
17399 | first_free = funcbufptr + (funcbufsize - funcbufleft); | |
17400 | for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) | |
de855c5d AM |
17401 | diff -urNp linux-2.6.29.6/drivers/edac/edac_core.h linux-2.6.29.6/drivers/edac/edac_core.h |
17402 | --- linux-2.6.29.6/drivers/edac/edac_core.h 2009-07-02 19:41:20.000000000 -0400 | |
17403 | +++ linux-2.6.29.6/drivers/edac/edac_core.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17404 | @@ -85,11 +85,11 @@ extern int edac_debug_level; |
17405 | ||
17406 | #else /* !CONFIG_EDAC_DEBUG */ | |
17407 | ||
17408 | -#define debugf0( ... ) | |
17409 | -#define debugf1( ... ) | |
17410 | -#define debugf2( ... ) | |
17411 | -#define debugf3( ... ) | |
17412 | -#define debugf4( ... ) | |
17413 | +#define debugf0( ... ) do {} while (0) | |
17414 | +#define debugf1( ... ) do {} while (0) | |
17415 | +#define debugf2( ... ) do {} while (0) | |
17416 | +#define debugf3( ... ) do {} while (0) | |
17417 | +#define debugf4( ... ) do {} while (0) | |
17418 | ||
17419 | #endif /* !CONFIG_EDAC_DEBUG */ | |
17420 | ||
de855c5d AM |
17421 | diff -urNp linux-2.6.29.6/drivers/firmware/dmi_scan.c linux-2.6.29.6/drivers/firmware/dmi_scan.c |
17422 | --- linux-2.6.29.6/drivers/firmware/dmi_scan.c 2009-07-02 19:41:20.000000000 -0400 | |
17423 | +++ linux-2.6.29.6/drivers/firmware/dmi_scan.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17424 | @@ -389,11 +389,6 @@ void __init dmi_scan_machine(void) |
17425 | } | |
17426 | } | |
17427 | else { | |
17428 | - /* | |
17429 | - * no iounmap() for that ioremap(); it would be a no-op, but | |
17430 | - * it's so early in setup that sucker gets confused into doing | |
17431 | - * what it shouldn't if we actually call it. | |
17432 | - */ | |
17433 | p = dmi_ioremap(0xF0000, 0x10000); | |
17434 | if (p == NULL) | |
17435 | goto error; | |
de855c5d AM |
17436 | diff -urNp linux-2.6.29.6/drivers/gpu/drm/drm_drv.c linux-2.6.29.6/drivers/gpu/drm/drm_drv.c |
17437 | --- linux-2.6.29.6/drivers/gpu/drm/drm_drv.c 2009-07-02 19:41:20.000000000 -0400 | |
17438 | +++ linux-2.6.29.6/drivers/gpu/drm/drm_drv.c 2009-07-09 22:13:39.000000000 -0400 | |
17439 | @@ -461,7 +461,7 @@ int drm_ioctl(struct inode *inode, struc | |
17440 | char *kdata = NULL; | |
17441 | ||
17442 | atomic_inc(&dev->ioctl_count); | |
17443 | - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]); | |
17444 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]); | |
17445 | ++file_priv->ioctl_count; | |
17446 | ||
17447 | DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n", | |
17448 | diff -urNp linux-2.6.29.6/drivers/gpu/drm/drm_fops.c linux-2.6.29.6/drivers/gpu/drm/drm_fops.c | |
17449 | --- linux-2.6.29.6/drivers/gpu/drm/drm_fops.c 2009-07-02 19:41:20.000000000 -0400 | |
17450 | +++ linux-2.6.29.6/drivers/gpu/drm/drm_fops.c 2009-07-09 22:13:39.000000000 -0400 | |
17451 | @@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct | |
17452 | ||
17453 | retcode = drm_open_helper(inode, filp, dev); | |
17454 | if (!retcode) { | |
17455 | - atomic_inc(&dev->counts[_DRM_STAT_OPENS]); | |
17456 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]); | |
17457 | spin_lock(&dev->count_lock); | |
17458 | - if (!dev->open_count++) { | |
17459 | + if (atomic_inc_return(&dev->open_count) == 1) { | |
17460 | spin_unlock(&dev->count_lock); | |
17461 | retcode = drm_setup(dev); | |
17462 | goto out; | |
17463 | @@ -436,7 +436,7 @@ int drm_release(struct inode *inode, str | |
17464 | ||
17465 | lock_kernel(); | |
17466 | ||
17467 | - DRM_DEBUG("open_count = %d\n", dev->open_count); | |
17468 | + DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count)); | |
17469 | ||
17470 | if (dev->driver->preclose) | |
17471 | dev->driver->preclose(dev, file_priv); | |
17472 | @@ -448,7 +448,7 @@ int drm_release(struct inode *inode, str | |
17473 | DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n", | |
17474 | task_pid_nr(current), | |
17475 | (long)old_encode_dev(file_priv->minor->device), | |
17476 | - dev->open_count); | |
17477 | + atomic_read(&dev->open_count)); | |
17478 | ||
17479 | /* if the master has gone away we can't do anything with the lock */ | |
17480 | if (file_priv->minor->master) | |
17481 | @@ -525,9 +525,9 @@ int drm_release(struct inode *inode, str | |
17482 | * End inline drm_release | |
17483 | */ | |
17484 | ||
17485 | - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]); | |
17486 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]); | |
17487 | spin_lock(&dev->count_lock); | |
17488 | - if (!--dev->open_count) { | |
17489 | + if (atomic_dec_and_test(&dev->open_count)) { | |
17490 | if (atomic_read(&dev->ioctl_count)) { | |
17491 | DRM_ERROR("Device busy: %d\n", | |
17492 | atomic_read(&dev->ioctl_count)); | |
17493 | diff -urNp linux-2.6.29.6/drivers/gpu/drm/drm_lock.c linux-2.6.29.6/drivers/gpu/drm/drm_lock.c | |
17494 | --- linux-2.6.29.6/drivers/gpu/drm/drm_lock.c 2009-07-02 19:41:20.000000000 -0400 | |
17495 | +++ linux-2.6.29.6/drivers/gpu/drm/drm_lock.c 2009-07-09 22:13:39.000000000 -0400 | |
17496 | @@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, voi | |
17497 | if (drm_lock_take(&master->lock, lock->context)) { | |
17498 | master->lock.file_priv = file_priv; | |
17499 | master->lock.lock_time = jiffies; | |
17500 | - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]); | |
17501 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]); | |
17502 | break; /* Got lock */ | |
17503 | } | |
17504 | ||
17505 | @@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, v | |
17506 | return -EINVAL; | |
17507 | } | |
17508 | ||
17509 | - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]); | |
17510 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]); | |
17511 | ||
17512 | /* kernel_context_switch isn't used by any of the x86 drm | |
17513 | * modules but is required by the Sparc driver. | |
17514 | diff -urNp linux-2.6.29.6/drivers/gpu/drm/i810/i810_dma.c linux-2.6.29.6/drivers/gpu/drm/i810/i810_dma.c | |
17515 | --- linux-2.6.29.6/drivers/gpu/drm/i810/i810_dma.c 2009-07-02 19:41:20.000000000 -0400 | |
17516 | +++ linux-2.6.29.6/drivers/gpu/drm/i810/i810_dma.c 2009-07-09 22:13:39.000000000 -0400 | |
17517 | @@ -954,8 +954,8 @@ static int i810_dma_vertex(struct drm_de | |
17518 | dma->buflist[vertex->idx], | |
17519 | vertex->discard, vertex->used); | |
17520 | ||
17521 | - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]); | |
17522 | - atomic_inc(&dev->counts[_DRM_STAT_DMA]); | |
17523 | + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]); | |
17524 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]); | |
17525 | sarea_priv->last_enqueue = dev_priv->counter - 1; | |
17526 | sarea_priv->last_dispatch = (int)hw_status[5]; | |
17527 | ||
17528 | @@ -1117,8 +1117,8 @@ static int i810_dma_mc(struct drm_device | |
17529 | i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used, | |
17530 | mc->last_render); | |
17531 | ||
17532 | - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]); | |
17533 | - atomic_inc(&dev->counts[_DRM_STAT_DMA]); | |
17534 | + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]); | |
17535 | + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]); | |
17536 | sarea_priv->last_enqueue = dev_priv->counter - 1; | |
17537 | sarea_priv->last_dispatch = (int)hw_status[5]; | |
17538 | ||
17539 | diff -urNp linux-2.6.29.6/drivers/hwmon/fscpos.c linux-2.6.29.6/drivers/hwmon/fscpos.c | |
17540 | --- linux-2.6.29.6/drivers/hwmon/fscpos.c 2009-07-02 19:41:20.000000000 -0400 | |
17541 | +++ linux-2.6.29.6/drivers/hwmon/fscpos.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17542 | @@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client |
17543 | unsigned long v = simple_strtoul(buf, NULL, 10); | |
17544 | ||
17545 | /* Range: 0..255 */ | |
17546 | - if (v < 0) v = 0; | |
17547 | if (v > 255) v = 255; | |
17548 | ||
17549 | mutex_lock(&data->update_lock); | |
de855c5d AM |
17550 | diff -urNp linux-2.6.29.6/drivers/hwmon/k8temp.c linux-2.6.29.6/drivers/hwmon/k8temp.c |
17551 | --- linux-2.6.29.6/drivers/hwmon/k8temp.c 2009-07-02 19:41:20.000000000 -0400 | |
17552 | +++ linux-2.6.29.6/drivers/hwmon/k8temp.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17553 | @@ -138,7 +138,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n |
17554 | ||
17555 | static struct pci_device_id k8temp_ids[] = { | |
17556 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, | |
17557 | - { 0 }, | |
17558 | + { 0, 0, 0, 0, 0, 0, 0 }, | |
17559 | }; | |
17560 | ||
17561 | MODULE_DEVICE_TABLE(pci, k8temp_ids); | |
de855c5d AM |
17562 | diff -urNp linux-2.6.29.6/drivers/hwmon/sis5595.c linux-2.6.29.6/drivers/hwmon/sis5595.c |
17563 | --- linux-2.6.29.6/drivers/hwmon/sis5595.c 2009-07-02 19:41:20.000000000 -0400 | |
17564 | +++ linux-2.6.29.6/drivers/hwmon/sis5595.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17565 | @@ -699,7 +699,7 @@ static struct sis5595_data *sis5595_upda |
17566 | ||
17567 | static struct pci_device_id sis5595_pci_ids[] = { | |
17568 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, | |
17569 | - { 0, } | |
17570 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17571 | }; | |
17572 | ||
17573 | MODULE_DEVICE_TABLE(pci, sis5595_pci_ids); | |
de855c5d AM |
17574 | diff -urNp linux-2.6.29.6/drivers/hwmon/via686a.c linux-2.6.29.6/drivers/hwmon/via686a.c |
17575 | --- linux-2.6.29.6/drivers/hwmon/via686a.c 2009-07-02 19:41:20.000000000 -0400 | |
17576 | +++ linux-2.6.29.6/drivers/hwmon/via686a.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17577 | @@ -769,7 +769,7 @@ static struct via686a_data *via686a_upda |
17578 | ||
17579 | static struct pci_device_id via686a_pci_ids[] = { | |
17580 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, | |
17581 | - { 0, } | |
17582 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17583 | }; | |
17584 | ||
17585 | MODULE_DEVICE_TABLE(pci, via686a_pci_ids); | |
de855c5d AM |
17586 | diff -urNp linux-2.6.29.6/drivers/hwmon/vt8231.c linux-2.6.29.6/drivers/hwmon/vt8231.c |
17587 | --- linux-2.6.29.6/drivers/hwmon/vt8231.c 2009-07-02 19:41:20.000000000 -0400 | |
17588 | +++ linux-2.6.29.6/drivers/hwmon/vt8231.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17589 | @@ -699,7 +699,7 @@ static struct platform_driver vt8231_dri |
17590 | ||
17591 | static struct pci_device_id vt8231_pci_ids[] = { | |
17592 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, | |
17593 | - { 0, } | |
17594 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17595 | }; | |
17596 | ||
17597 | MODULE_DEVICE_TABLE(pci, vt8231_pci_ids); | |
de855c5d AM |
17598 | diff -urNp linux-2.6.29.6/drivers/hwmon/w83791d.c linux-2.6.29.6/drivers/hwmon/w83791d.c |
17599 | --- linux-2.6.29.6/drivers/hwmon/w83791d.c 2009-07-02 19:41:20.000000000 -0400 | |
17600 | +++ linux-2.6.29.6/drivers/hwmon/w83791d.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17601 | @@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_cli |
17602 | struct i2c_board_info *info); | |
17603 | static int w83791d_remove(struct i2c_client *client); | |
17604 | ||
17605 | -static int w83791d_read(struct i2c_client *client, u8 register); | |
17606 | -static int w83791d_write(struct i2c_client *client, u8 register, u8 value); | |
17607 | +static int w83791d_read(struct i2c_client *client, u8 reg); | |
17608 | +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value); | |
17609 | static struct w83791d_data *w83791d_update_device(struct device *dev); | |
17610 | ||
17611 | #ifdef DEBUG | |
de855c5d AM |
17612 | diff -urNp linux-2.6.29.6/drivers/i2c/busses/i2c-i801.c linux-2.6.29.6/drivers/i2c/busses/i2c-i801.c |
17613 | --- linux-2.6.29.6/drivers/i2c/busses/i2c-i801.c 2009-07-02 19:41:20.000000000 -0400 | |
17614 | +++ linux-2.6.29.6/drivers/i2c/busses/i2c-i801.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17615 | @@ -577,7 +577,7 @@ static struct pci_device_id i801_ids[] = |
17616 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) }, | |
17617 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, | |
17618 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH_SMBUS) }, | |
17619 | - { 0, } | |
17620 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17621 | }; | |
17622 | ||
17623 | MODULE_DEVICE_TABLE (pci, i801_ids); | |
de855c5d AM |
17624 | diff -urNp linux-2.6.29.6/drivers/i2c/busses/i2c-piix4.c linux-2.6.29.6/drivers/i2c/busses/i2c-piix4.c |
17625 | --- linux-2.6.29.6/drivers/i2c/busses/i2c-piix4.c 2009-07-02 19:41:20.000000000 -0400 | |
17626 | +++ linux-2.6.29.6/drivers/i2c/busses/i2c-piix4.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17627 | @@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat |
17628 | .ident = "IBM", | |
17629 | .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, | |
17630 | }, | |
17631 | - { }, | |
17632 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }, | |
17633 | }; | |
17634 | ||
17635 | static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, | |
17636 | @@ -423,7 +423,7 @@ static struct pci_device_id piix4_ids[] | |
17637 | PCI_DEVICE_ID_SERVERWORKS_CSB6) }, | |
17638 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, | |
17639 | PCI_DEVICE_ID_SERVERWORKS_HT1000SB) }, | |
17640 | - { 0, } | |
17641 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17642 | }; | |
17643 | ||
17644 | MODULE_DEVICE_TABLE (pci, piix4_ids); | |
de855c5d AM |
17645 | diff -urNp linux-2.6.29.6/drivers/i2c/busses/i2c-sis630.c linux-2.6.29.6/drivers/i2c/busses/i2c-sis630.c |
17646 | --- linux-2.6.29.6/drivers/i2c/busses/i2c-sis630.c 2009-07-02 19:41:20.000000000 -0400 | |
17647 | +++ linux-2.6.29.6/drivers/i2c/busses/i2c-sis630.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17648 | @@ -471,7 +471,7 @@ static struct i2c_adapter sis630_adapter |
17649 | static struct pci_device_id sis630_ids[] __devinitdata = { | |
17650 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, | |
17651 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, | |
17652 | - { 0, } | |
17653 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17654 | }; | |
17655 | ||
17656 | MODULE_DEVICE_TABLE (pci, sis630_ids); | |
de855c5d AM |
17657 | diff -urNp linux-2.6.29.6/drivers/i2c/busses/i2c-sis96x.c linux-2.6.29.6/drivers/i2c/busses/i2c-sis96x.c |
17658 | --- linux-2.6.29.6/drivers/i2c/busses/i2c-sis96x.c 2009-07-02 19:41:20.000000000 -0400 | |
17659 | +++ linux-2.6.29.6/drivers/i2c/busses/i2c-sis96x.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17660 | @@ -247,7 +247,7 @@ static struct i2c_adapter sis96x_adapter |
17661 | ||
17662 | static struct pci_device_id sis96x_ids[] = { | |
17663 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, | |
17664 | - { 0, } | |
17665 | + { 0, 0, 0, 0, 0, 0, 0 } | |
17666 | }; | |
17667 | ||
17668 | MODULE_DEVICE_TABLE (pci, sis96x_ids); | |
de855c5d AM |
17669 | diff -urNp linux-2.6.29.6/drivers/ieee1394/dv1394.c linux-2.6.29.6/drivers/ieee1394/dv1394.c |
17670 | --- linux-2.6.29.6/drivers/ieee1394/dv1394.c 2009-07-02 19:41:20.000000000 -0400 | |
17671 | +++ linux-2.6.29.6/drivers/ieee1394/dv1394.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17672 | @@ -739,7 +739,7 @@ static void frame_prepare(struct video_c |
17673 | based upon DIF section and sequence | |
17674 | */ | |
17675 | ||
17676 | -static void inline | |
17677 | +static inline void | |
17678 | frame_put_packet (struct frame *f, struct packet *p) | |
17679 | { | |
17680 | int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */ | |
17681 | @@ -2181,7 +2181,7 @@ static struct ieee1394_device_id dv1394_ | |
17682 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | |
17683 | .version = AVC_SW_VERSION_ENTRY & 0xffffff | |
17684 | }, | |
17685 | - { } | |
17686 | + { 0, 0, 0, 0, 0, 0 } | |
17687 | }; | |
17688 | ||
17689 | MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table); | |
de855c5d AM |
17690 | diff -urNp linux-2.6.29.6/drivers/ieee1394/eth1394.c linux-2.6.29.6/drivers/ieee1394/eth1394.c |
17691 | --- linux-2.6.29.6/drivers/ieee1394/eth1394.c 2009-07-02 19:41:20.000000000 -0400 | |
17692 | +++ linux-2.6.29.6/drivers/ieee1394/eth1394.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17693 | @@ -445,7 +445,7 @@ static struct ieee1394_device_id eth1394 |
17694 | .specifier_id = ETHER1394_GASP_SPECIFIER_ID, | |
17695 | .version = ETHER1394_GASP_VERSION, | |
17696 | }, | |
17697 | - {} | |
17698 | + { 0, 0, 0, 0, 0, 0 } | |
17699 | }; | |
17700 | ||
17701 | MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table); | |
de855c5d AM |
17702 | diff -urNp linux-2.6.29.6/drivers/ieee1394/hosts.c linux-2.6.29.6/drivers/ieee1394/hosts.c |
17703 | --- linux-2.6.29.6/drivers/ieee1394/hosts.c 2009-07-02 19:41:20.000000000 -0400 | |
17704 | +++ linux-2.6.29.6/drivers/ieee1394/hosts.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17705 | @@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso |
17706 | } | |
17707 | ||
17708 | static struct hpsb_host_driver dummy_driver = { | |
17709 | + .name = "dummy", | |
17710 | .transmit_packet = dummy_transmit_packet, | |
17711 | .devctl = dummy_devctl, | |
17712 | .isoctl = dummy_isoctl | |
de855c5d AM |
17713 | diff -urNp linux-2.6.29.6/drivers/ieee1394/ohci1394.c linux-2.6.29.6/drivers/ieee1394/ohci1394.c |
17714 | --- linux-2.6.29.6/drivers/ieee1394/ohci1394.c 2009-07-02 19:41:20.000000000 -0400 | |
17715 | +++ linux-2.6.29.6/drivers/ieee1394/ohci1394.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17716 | @@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_ |
17717 | printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args) | |
17718 | ||
17719 | /* Module Parameters */ | |
17720 | -static int phys_dma = 1; | |
17721 | +static int phys_dma; | |
17722 | module_param(phys_dma, int, 0444); | |
17723 | -MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1)."); | |
17724 | +MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0)."); | |
17725 | ||
17726 | static void dma_trm_tasklet(unsigned long data); | |
17727 | static void dma_trm_reset(struct dma_trm_ctx *d); | |
17728 | @@ -3449,7 +3449,7 @@ static struct pci_device_id ohci1394_pci | |
17729 | .subvendor = PCI_ANY_ID, | |
17730 | .subdevice = PCI_ANY_ID, | |
17731 | }, | |
17732 | - { 0, }, | |
17733 | + { 0, 0, 0, 0, 0, 0, 0 }, | |
17734 | }; | |
17735 | ||
17736 | MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl); | |
de855c5d AM |
17737 | diff -urNp linux-2.6.29.6/drivers/ieee1394/raw1394.c linux-2.6.29.6/drivers/ieee1394/raw1394.c |
17738 | --- linux-2.6.29.6/drivers/ieee1394/raw1394.c 2009-07-02 19:41:20.000000000 -0400 | |
17739 | +++ linux-2.6.29.6/drivers/ieee1394/raw1394.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17740 | @@ -2995,7 +2995,7 @@ static struct ieee1394_device_id raw1394 |
17741 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, | |
17742 | .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff, | |
17743 | .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff}, | |
17744 | - {} | |
17745 | + { 0, 0, 0, 0, 0, 0 } | |
17746 | }; | |
17747 | ||
17748 | MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table); | |
de855c5d AM |
17749 | diff -urNp linux-2.6.29.6/drivers/ieee1394/sbp2.c linux-2.6.29.6/drivers/ieee1394/sbp2.c |
17750 | --- linux-2.6.29.6/drivers/ieee1394/sbp2.c 2009-07-02 19:41:20.000000000 -0400 | |
17751 | +++ linux-2.6.29.6/drivers/ieee1394/sbp2.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17752 | @@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id |
17753 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, | |
17754 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, | |
17755 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff}, | |
17756 | - {} | |
17757 | + { 0, 0, 0, 0, 0, 0 } | |
17758 | }; | |
17759 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); | |
17760 | ||
17761 | @@ -2112,7 +2112,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot | |
17762 | MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME); | |
17763 | MODULE_LICENSE("GPL"); | |
17764 | ||
17765 | -static int sbp2_module_init(void) | |
17766 | +static int __init sbp2_module_init(void) | |
17767 | { | |
17768 | int ret; | |
17769 | ||
de855c5d AM |
17770 | diff -urNp linux-2.6.29.6/drivers/ieee1394/video1394.c linux-2.6.29.6/drivers/ieee1394/video1394.c |
17771 | --- linux-2.6.29.6/drivers/ieee1394/video1394.c 2009-07-02 19:41:20.000000000 -0400 | |
17772 | +++ linux-2.6.29.6/drivers/ieee1394/video1394.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17773 | @@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13 |
17774 | .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff, | |
17775 | .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff | |
17776 | }, | |
17777 | - { } | |
17778 | + { 0, 0, 0, 0, 0, 0 } | |
17779 | }; | |
17780 | ||
17781 | MODULE_DEVICE_TABLE(ieee1394, video1394_id_table); | |
de855c5d AM |
17782 | diff -urNp linux-2.6.29.6/drivers/input/keyboard/atkbd.c linux-2.6.29.6/drivers/input/keyboard/atkbd.c |
17783 | --- linux-2.6.29.6/drivers/input/keyboard/atkbd.c 2009-07-02 19:41:20.000000000 -0400 | |
17784 | +++ linux-2.6.29.6/drivers/input/keyboard/atkbd.c 2009-07-09 22:13:39.000000000 -0400 | |
17785 | @@ -1166,7 +1166,7 @@ static struct serio_device_id atkbd_seri | |
2380c486 JR |
17786 | .id = SERIO_ANY, |
17787 | .extra = SERIO_ANY, | |
17788 | }, | |
17789 | - { 0 } | |
17790 | + { 0, 0, 0, 0 } | |
17791 | }; | |
17792 | ||
17793 | MODULE_DEVICE_TABLE(serio, atkbd_serio_ids); | |
de855c5d AM |
17794 | diff -urNp linux-2.6.29.6/drivers/input/mouse/lifebook.c linux-2.6.29.6/drivers/input/mouse/lifebook.c |
17795 | --- linux-2.6.29.6/drivers/input/mouse/lifebook.c 2009-07-02 19:41:20.000000000 -0400 | |
17796 | +++ linux-2.6.29.6/drivers/input/mouse/lifebook.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17797 | @@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo |
17798 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"), | |
17799 | }, | |
17800 | }, | |
17801 | - { } | |
17802 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL} | |
17803 | }; | |
17804 | ||
17805 | static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse) | |
de855c5d AM |
17806 | diff -urNp linux-2.6.29.6/drivers/input/mouse/psmouse-base.c linux-2.6.29.6/drivers/input/mouse/psmouse-base.c |
17807 | --- linux-2.6.29.6/drivers/input/mouse/psmouse-base.c 2009-07-02 19:41:20.000000000 -0400 | |
17808 | +++ linux-2.6.29.6/drivers/input/mouse/psmouse-base.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17809 | @@ -1378,7 +1378,7 @@ static struct serio_device_id psmouse_se |
17810 | .id = SERIO_ANY, | |
17811 | .extra = SERIO_ANY, | |
17812 | }, | |
17813 | - { 0 } | |
17814 | + { 0, 0, 0, 0 } | |
17815 | }; | |
17816 | ||
17817 | MODULE_DEVICE_TABLE(serio, psmouse_serio_ids); | |
de855c5d AM |
17818 | diff -urNp linux-2.6.29.6/drivers/input/mouse/synaptics.c linux-2.6.29.6/drivers/input/mouse/synaptics.c |
17819 | --- linux-2.6.29.6/drivers/input/mouse/synaptics.c 2009-07-02 19:41:20.000000000 -0400 | |
17820 | +++ linux-2.6.29.6/drivers/input/mouse/synaptics.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17821 | @@ -412,7 +412,7 @@ static void synaptics_process_packet(str |
17822 | break; | |
17823 | case 2: | |
17824 | if (SYN_MODEL_PEN(priv->model_id)) | |
17825 | - ; /* Nothing, treat a pen as a single finger */ | |
17826 | + break; /* Nothing, treat a pen as a single finger */ | |
17827 | break; | |
17828 | case 4 ... 15: | |
17829 | if (SYN_CAP_PALMDETECT(priv->capabilities)) | |
17830 | @@ -625,7 +625,7 @@ static const struct dmi_system_id toshib | |
17831 | DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"), | |
17832 | }, | |
17833 | }, | |
17834 | - { } | |
17835 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
17836 | }; | |
17837 | #endif | |
17838 | ||
de855c5d AM |
17839 | diff -urNp linux-2.6.29.6/drivers/input/mousedev.c linux-2.6.29.6/drivers/input/mousedev.c |
17840 | --- linux-2.6.29.6/drivers/input/mousedev.c 2009-07-02 19:41:20.000000000 -0400 | |
17841 | +++ linux-2.6.29.6/drivers/input/mousedev.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17842 | @@ -1062,7 +1062,7 @@ static struct input_handler mousedev_han |
17843 | ||
17844 | #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX | |
17845 | static struct miscdevice psaux_mouse = { | |
17846 | - PSMOUSE_MINOR, "psaux", &mousedev_fops | |
17847 | + PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL | |
17848 | }; | |
17849 | static int psaux_registered; | |
17850 | #endif | |
de855c5d AM |
17851 | diff -urNp linux-2.6.29.6/drivers/input/serio/i8042-x86ia64io.h linux-2.6.29.6/drivers/input/serio/i8042-x86ia64io.h |
17852 | --- linux-2.6.29.6/drivers/input/serio/i8042-x86ia64io.h 2009-07-02 19:41:20.000000000 -0400 | |
17853 | +++ linux-2.6.29.6/drivers/input/serio/i8042-x86ia64io.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17854 | @@ -151,7 +151,7 @@ static struct dmi_system_id __initdata i |
17855 | DMI_MATCH(DMI_PRODUCT_VERSION, "01"), | |
17856 | }, | |
17857 | }, | |
17858 | - { } | |
17859 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
17860 | }; | |
17861 | ||
17862 | /* | |
17863 | @@ -366,7 +366,7 @@ static struct dmi_system_id __initdata i | |
17864 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro1510"), | |
17865 | }, | |
17866 | }, | |
17867 | - { } | |
17868 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
17869 | }; | |
17870 | ||
17871 | #ifdef CONFIG_PNP | |
17872 | @@ -378,7 +378,7 @@ static struct dmi_system_id __initdata i | |
17873 | DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), | |
17874 | }, | |
17875 | }, | |
17876 | - { } | |
17877 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
17878 | }; | |
17879 | #endif | |
17880 | ||
17881 | @@ -445,7 +445,7 @@ static struct dmi_system_id __initdata i | |
17882 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"), | |
17883 | }, | |
17884 | }, | |
17885 | - { } | |
17886 | + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } | |
17887 | }; | |
17888 | ||
17889 | #endif /* CONFIG_X86 */ | |
de855c5d AM |
17890 | diff -urNp linux-2.6.29.6/drivers/input/serio/serio_raw.c linux-2.6.29.6/drivers/input/serio/serio_raw.c |
17891 | --- linux-2.6.29.6/drivers/input/serio/serio_raw.c 2009-07-02 19:41:20.000000000 -0400 | |
17892 | +++ linux-2.6.29.6/drivers/input/serio/serio_raw.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17893 | @@ -378,7 +378,7 @@ static struct serio_device_id serio_raw_ |
17894 | .id = SERIO_ANY, | |
17895 | .extra = SERIO_ANY, | |
17896 | }, | |
17897 | - { 0 } | |
17898 | + { 0, 0, 0, 0 } | |
17899 | }; | |
17900 | ||
17901 | MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids); | |
de855c5d AM |
17902 | diff -urNp linux-2.6.29.6/drivers/lguest/core.c linux-2.6.29.6/drivers/lguest/core.c |
17903 | --- linux-2.6.29.6/drivers/lguest/core.c 2009-07-02 19:41:20.000000000 -0400 | |
17904 | +++ linux-2.6.29.6/drivers/lguest/core.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17905 | @@ -80,9 +80,17 @@ static __init int map_switcher(void) |
17906 | * (SWITCHER_ADDR). We might not get it in theory, but in practice | |
17907 | * it's worked so far. The end address needs +1 because __get_vm_area | |
17908 | * allocates an extra guard page, so we need space for that. */ | |
17909 | + | |
17910 | +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
17911 | + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE, | |
17912 | + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR | |
17913 | + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE); | |
17914 | +#else | |
17915 | switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE, | |
17916 | VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR | |
17917 | + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE); | |
17918 | +#endif | |
17919 | + | |
17920 | if (!switcher_vma) { | |
17921 | err = -ENOMEM; | |
17922 | printk("lguest: could not map switcher pages high\n"); | |
de855c5d AM |
17923 | diff -urNp linux-2.6.29.6/drivers/md/bitmap.c linux-2.6.29.6/drivers/md/bitmap.c |
17924 | --- linux-2.6.29.6/drivers/md/bitmap.c 2009-07-02 19:41:20.000000000 -0400 | |
17925 | +++ linux-2.6.29.6/drivers/md/bitmap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17926 | @@ -57,7 +57,7 @@ |
17927 | # if DEBUG > 0 | |
17928 | # define PRINTK(x...) printk(KERN_DEBUG x) | |
17929 | # else | |
17930 | -# define PRINTK(x...) | |
17931 | +# define PRINTK(x...) do {} while (0) | |
17932 | # endif | |
17933 | #endif | |
17934 | ||
de855c5d AM |
17935 | diff -urNp linux-2.6.29.6/drivers/md/md.c linux-2.6.29.6/drivers/md/md.c |
17936 | --- linux-2.6.29.6/drivers/md/md.c 2009-07-02 19:41:20.000000000 -0400 | |
17937 | +++ linux-2.6.29.6/drivers/md/md.c 2009-07-09 22:13:39.000000000 -0400 | |
17938 | @@ -5637,7 +5637,7 @@ static int md_seq_show(struct seq_file * | |
2380c486 JR |
17939 | chunk_kb ? "KB" : "B"); |
17940 | if (bitmap->file) { | |
17941 | seq_printf(seq, ", file: "); | |
17942 | - seq_path(seq, &bitmap->file->f_path, " \t\n"); | |
17943 | + seq_path(seq, &bitmap->file->f_path, " \t\n\\"); | |
17944 | } | |
17945 | ||
17946 | seq_printf(seq, "\n"); | |
de855c5d AM |
17947 | diff -urNp linux-2.6.29.6/drivers/mtd/devices/doc2000.c linux-2.6.29.6/drivers/mtd/devices/doc2000.c |
17948 | --- linux-2.6.29.6/drivers/mtd/devices/doc2000.c 2009-07-02 19:41:20.000000000 -0400 | |
17949 | +++ linux-2.6.29.6/drivers/mtd/devices/doc2000.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17950 | @@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt |
17951 | ||
17952 | /* The ECC will not be calculated correctly if less than 512 is written */ | |
17953 | /* DBB- | |
17954 | - if (len != 0x200 && eccbuf) | |
17955 | + if (len != 0x200) | |
17956 | printk(KERN_WARNING | |
17957 | "ECC needs a full sector write (adr: %lx size %lx)\n", | |
17958 | (long) to, (long) len); | |
de855c5d AM |
17959 | diff -urNp linux-2.6.29.6/drivers/mtd/devices/doc2001.c linux-2.6.29.6/drivers/mtd/devices/doc2001.c |
17960 | --- linux-2.6.29.6/drivers/mtd/devices/doc2001.c 2009-07-02 19:41:20.000000000 -0400 | |
17961 | +++ linux-2.6.29.6/drivers/mtd/devices/doc2001.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17962 | @@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt |
17963 | /* Don't allow read past end of device */ | |
17964 | if (from >= this->totlen) | |
17965 | return -EINVAL; | |
17966 | + if (!len) | |
17967 | + return -EINVAL; | |
17968 | ||
17969 | /* Don't allow a single read to cross a 512-byte block boundary */ | |
17970 | if (from + len > ((from | 0x1ff) + 1)) | |
de855c5d AM |
17971 | diff -urNp linux-2.6.29.6/drivers/mtd/ubi/build.c linux-2.6.29.6/drivers/mtd/ubi/build.c |
17972 | --- linux-2.6.29.6/drivers/mtd/ubi/build.c 2009-07-02 19:41:20.000000000 -0400 | |
17973 | +++ linux-2.6.29.6/drivers/mtd/ubi/build.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17974 | @@ -1112,7 +1112,7 @@ static int __init bytes_str_to_int(const |
17975 | unsigned long result; | |
17976 | ||
17977 | result = simple_strtoul(str, &endp, 0); | |
17978 | - if (str == endp || result < 0) { | |
17979 | + if (str == endp) { | |
17980 | printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n", | |
17981 | str); | |
17982 | return -EINVAL; | |
de855c5d AM |
17983 | diff -urNp linux-2.6.29.6/drivers/net/irda/vlsi_ir.c linux-2.6.29.6/drivers/net/irda/vlsi_ir.c |
17984 | --- linux-2.6.29.6/drivers/net/irda/vlsi_ir.c 2009-07-02 19:41:20.000000000 -0400 | |
17985 | +++ linux-2.6.29.6/drivers/net/irda/vlsi_ir.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
17986 | @@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s |
17987 | /* no race - tx-ring already empty */ | |
17988 | vlsi_set_baud(idev, iobase); | |
17989 | netif_wake_queue(ndev); | |
17990 | - } | |
17991 | - else | |
17992 | - ; | |
17993 | + } else { | |
17994 | /* keep the speed change pending like it would | |
17995 | * for any len>0 packet. tx completion interrupt | |
17996 | * will apply it when the tx ring becomes empty. | |
17997 | */ | |
17998 | + } | |
17999 | spin_unlock_irqrestore(&idev->lock, flags); | |
18000 | dev_kfree_skb_any(skb); | |
18001 | return 0; | |
de855c5d AM |
18002 | diff -urNp linux-2.6.29.6/drivers/net/pcnet32.c linux-2.6.29.6/drivers/net/pcnet32.c |
18003 | --- linux-2.6.29.6/drivers/net/pcnet32.c 2009-07-02 19:41:20.000000000 -0400 | |
18004 | +++ linux-2.6.29.6/drivers/net/pcnet32.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18005 | @@ -78,7 +78,7 @@ static int cards_found; |
18006 | /* | |
18007 | * VLB I/O addresses | |
18008 | */ | |
18009 | -static unsigned int pcnet32_portlist[] __initdata = | |
18010 | +static unsigned int pcnet32_portlist[] __devinitdata = | |
18011 | { 0x300, 0x320, 0x340, 0x360, 0 }; | |
18012 | ||
18013 | static int pcnet32_debug = 0; | |
de855c5d AM |
18014 | diff -urNp linux-2.6.29.6/drivers/net/tg3.h linux-2.6.29.6/drivers/net/tg3.h |
18015 | --- linux-2.6.29.6/drivers/net/tg3.h 2009-07-02 19:41:20.000000000 -0400 | |
18016 | +++ linux-2.6.29.6/drivers/net/tg3.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18017 | @@ -89,6 +89,7 @@ |
18018 | #define CHIPREV_ID_5750_A0 0x4000 | |
18019 | #define CHIPREV_ID_5750_A1 0x4001 | |
18020 | #define CHIPREV_ID_5750_A3 0x4003 | |
18021 | +#define CHIPREV_ID_5750_C1 0x4201 | |
18022 | #define CHIPREV_ID_5750_C2 0x4202 | |
18023 | #define CHIPREV_ID_5752_A0_HW 0x5000 | |
18024 | #define CHIPREV_ID_5752_A0 0x6000 | |
de855c5d AM |
18025 | diff -urNp linux-2.6.29.6/drivers/oprofile/buffer_sync.c linux-2.6.29.6/drivers/oprofile/buffer_sync.c |
18026 | --- linux-2.6.29.6/drivers/oprofile/buffer_sync.c 2009-07-02 19:41:20.000000000 -0400 | |
18027 | +++ linux-2.6.29.6/drivers/oprofile/buffer_sync.c 2009-07-09 22:13:39.000000000 -0400 | |
18028 | @@ -335,7 +335,7 @@ static void add_data(struct op_entry *en | |
18029 | if (cookie == NO_COOKIE) | |
18030 | offset = pc; | |
18031 | if (cookie == INVALID_COOKIE) { | |
18032 | - atomic_inc(&oprofile_stats.sample_lost_no_mapping); | |
18033 | + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping); | |
18034 | offset = pc; | |
18035 | } | |
18036 | if (cookie != last_cookie) { | |
18037 | @@ -379,14 +379,14 @@ add_sample(struct mm_struct *mm, struct | |
18038 | /* add userspace sample */ | |
18039 | ||
18040 | if (!mm) { | |
18041 | - atomic_inc(&oprofile_stats.sample_lost_no_mm); | |
18042 | + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm); | |
18043 | return 0; | |
18044 | } | |
18045 | ||
18046 | cookie = lookup_dcookie(mm, s->eip, &offset); | |
18047 | ||
18048 | if (cookie == INVALID_COOKIE) { | |
18049 | - atomic_inc(&oprofile_stats.sample_lost_no_mapping); | |
18050 | + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping); | |
18051 | return 0; | |
18052 | } | |
18053 | ||
18054 | @@ -555,7 +555,7 @@ void sync_buffer(int cpu) | |
18055 | /* ignore backtraces if failed to add a sample */ | |
18056 | if (state == sb_bt_start) { | |
18057 | state = sb_bt_ignore; | |
18058 | - atomic_inc(&oprofile_stats.bt_lost_no_mapping); | |
18059 | + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping); | |
18060 | } | |
18061 | } | |
18062 | release_mm(mm); | |
18063 | diff -urNp linux-2.6.29.6/drivers/oprofile/event_buffer.c linux-2.6.29.6/drivers/oprofile/event_buffer.c | |
18064 | --- linux-2.6.29.6/drivers/oprofile/event_buffer.c 2009-07-02 19:41:20.000000000 -0400 | |
18065 | +++ linux-2.6.29.6/drivers/oprofile/event_buffer.c 2009-07-09 22:13:39.000000000 -0400 | |
18066 | @@ -42,7 +42,7 @@ static atomic_t buffer_ready = ATOMIC_IN | |
18067 | void add_event_entry(unsigned long value) | |
18068 | { | |
18069 | if (buffer_pos == buffer_size) { | |
18070 | - atomic_inc(&oprofile_stats.event_lost_overflow); | |
18071 | + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow); | |
18072 | return; | |
18073 | } | |
18074 | ||
18075 | diff -urNp linux-2.6.29.6/drivers/oprofile/oprofilefs.c linux-2.6.29.6/drivers/oprofile/oprofilefs.c | |
18076 | --- linux-2.6.29.6/drivers/oprofile/oprofilefs.c 2009-07-02 19:41:20.000000000 -0400 | |
18077 | +++ linux-2.6.29.6/drivers/oprofile/oprofilefs.c 2009-07-09 22:13:39.000000000 -0400 | |
18078 | @@ -187,7 +187,7 @@ static const struct file_operations atom | |
18079 | ||
18080 | ||
18081 | int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, | |
18082 | - char const *name, atomic_t *val) | |
18083 | + char const *name, atomic_unchecked_t *val) | |
18084 | { | |
18085 | struct dentry *d = __oprofilefs_create_file(sb, root, name, | |
18086 | &atomic_ro_fops, 0444); | |
18087 | diff -urNp linux-2.6.29.6/drivers/oprofile/oprofile_stats.h linux-2.6.29.6/drivers/oprofile/oprofile_stats.h | |
18088 | --- linux-2.6.29.6/drivers/oprofile/oprofile_stats.h 2009-07-02 19:41:20.000000000 -0400 | |
18089 | +++ linux-2.6.29.6/drivers/oprofile/oprofile_stats.h 2009-07-09 22:13:39.000000000 -0400 | |
18090 | @@ -13,10 +13,10 @@ | |
18091 | #include <asm/atomic.h> | |
18092 | ||
18093 | struct oprofile_stat_struct { | |
18094 | - atomic_t sample_lost_no_mm; | |
18095 | - atomic_t sample_lost_no_mapping; | |
18096 | - atomic_t bt_lost_no_mapping; | |
18097 | - atomic_t event_lost_overflow; | |
18098 | + atomic_unchecked_t sample_lost_no_mm; | |
18099 | + atomic_unchecked_t sample_lost_no_mapping; | |
18100 | + atomic_unchecked_t bt_lost_no_mapping; | |
18101 | + atomic_unchecked_t event_lost_overflow; | |
18102 | }; | |
18103 | ||
18104 | extern struct oprofile_stat_struct oprofile_stats; | |
18105 | diff -urNp linux-2.6.29.6/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.29.6/drivers/pci/hotplug/cpqphp_nvram.c | |
18106 | --- linux-2.6.29.6/drivers/pci/hotplug/cpqphp_nvram.c 2009-07-02 19:41:20.000000000 -0400 | |
18107 | +++ linux-2.6.29.6/drivers/pci/hotplug/cpqphp_nvram.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18108 | @@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_ |
18109 | ||
18110 | void compaq_nvram_init (void __iomem *rom_start) | |
18111 | { | |
18112 | + | |
18113 | +#ifndef CONFIG_PAX_KERNEXEC | |
18114 | if (rom_start) { | |
18115 | compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR); | |
18116 | } | |
18117 | +#endif | |
18118 | + | |
18119 | dbg("int15 entry = %p\n", compaq_int15_entry_point); | |
18120 | ||
18121 | /* initialize our int15 lock */ | |
de855c5d AM |
18122 | diff -urNp linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv.c linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv.c |
18123 | --- linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv.c 2009-07-02 19:41:20.000000000 -0400 | |
18124 | +++ linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18125 | @@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i |
18126 | .port_type = PCIE_RC_PORT, | |
18127 | .service_type = PCIE_PORT_SERVICE_AER, | |
18128 | }, | |
18129 | - { /* end: all zeroes */ } | |
18130 | + { 0, 0, 0, 0, 0, 0, 0, 0, 0 } | |
18131 | }; | |
18132 | ||
18133 | static struct pci_error_handlers aer_error_handlers = { | |
de855c5d AM |
18134 | diff -urNp linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv_core.c |
18135 | --- linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv_core.c 2009-07-02 19:41:20.000000000 -0400 | |
18136 | +++ linux-2.6.29.6/drivers/pci/pcie/aer/aerdrv_core.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18137 | @@ -670,7 +670,7 @@ static void aer_isr_one_error(struct pci |
18138 | struct aer_err_source *e_src) | |
18139 | { | |
18140 | struct device *s_device; | |
18141 | - struct aer_err_info e_info = {0, 0, 0,}; | |
18142 | + struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}}; | |
18143 | int i; | |
18144 | u16 id; | |
18145 | ||
de855c5d AM |
18146 | diff -urNp linux-2.6.29.6/drivers/pci/pcie/portdrv_pci.c linux-2.6.29.6/drivers/pci/pcie/portdrv_pci.c |
18147 | --- linux-2.6.29.6/drivers/pci/pcie/portdrv_pci.c 2009-07-02 19:41:20.000000000 -0400 | |
18148 | +++ linux-2.6.29.6/drivers/pci/pcie/portdrv_pci.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18149 | @@ -260,7 +260,7 @@ static void pcie_portdrv_err_resume(stru |
18150 | static const struct pci_device_id port_pci_ids[] = { { | |
18151 | /* handle any PCI-Express port */ | |
18152 | PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0), | |
18153 | - }, { /* end: all zeroes */ } | |
18154 | + }, { 0, 0, 0, 0, 0, 0, 0 } | |
18155 | }; | |
18156 | MODULE_DEVICE_TABLE(pci, port_pci_ids); | |
18157 | ||
de855c5d AM |
18158 | diff -urNp linux-2.6.29.6/drivers/pci/proc.c linux-2.6.29.6/drivers/pci/proc.c |
18159 | --- linux-2.6.29.6/drivers/pci/proc.c 2009-07-02 19:41:20.000000000 -0400 | |
18160 | +++ linux-2.6.29.6/drivers/pci/proc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18161 | @@ -480,7 +480,16 @@ static const struct file_operations proc |
18162 | static int __init pci_proc_init(void) | |
18163 | { | |
18164 | struct pci_dev *dev = NULL; | |
18165 | + | |
18166 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
18167 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
18168 | + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL); | |
18169 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
18170 | + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL); | |
18171 | +#endif | |
18172 | +#else | |
18173 | proc_bus_pci_dir = proc_mkdir("bus/pci", NULL); | |
18174 | +#endif | |
18175 | proc_create("devices", 0, proc_bus_pci_dir, | |
18176 | &proc_bus_pci_dev_operations); | |
18177 | proc_initialized = 1; | |
de855c5d AM |
18178 | diff -urNp linux-2.6.29.6/drivers/pcmcia/ti113x.h linux-2.6.29.6/drivers/pcmcia/ti113x.h |
18179 | --- linux-2.6.29.6/drivers/pcmcia/ti113x.h 2009-07-02 19:41:20.000000000 -0400 | |
18180 | +++ linux-2.6.29.6/drivers/pcmcia/ti113x.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18181 | @@ -903,7 +903,7 @@ static struct pci_device_id ene_tune_tbl |
18182 | DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID, | |
18183 | ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE), | |
18184 | ||
18185 | - {} | |
18186 | + { 0, 0, 0, 0, 0, 0, 0 } | |
18187 | }; | |
18188 | ||
18189 | static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus) | |
de855c5d AM |
18190 | diff -urNp linux-2.6.29.6/drivers/pcmcia/yenta_socket.c linux-2.6.29.6/drivers/pcmcia/yenta_socket.c |
18191 | --- linux-2.6.29.6/drivers/pcmcia/yenta_socket.c 2009-07-02 19:41:20.000000000 -0400 | |
18192 | +++ linux-2.6.29.6/drivers/pcmcia/yenta_socket.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18193 | @@ -1366,7 +1366,7 @@ static struct pci_device_id yenta_table |
18194 | ||
18195 | /* match any cardbus bridge */ | |
18196 | CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT), | |
18197 | - { /* all zeroes */ } | |
18198 | + { 0, 0, 0, 0, 0, 0, 0 } | |
18199 | }; | |
18200 | MODULE_DEVICE_TABLE(pci, yenta_table); | |
18201 | ||
de855c5d AM |
18202 | diff -urNp linux-2.6.29.6/drivers/pnp/pnpbios/bioscalls.c linux-2.6.29.6/drivers/pnp/pnpbios/bioscalls.c |
18203 | --- linux-2.6.29.6/drivers/pnp/pnpbios/bioscalls.c 2009-07-02 19:41:20.000000000 -0400 | |
18204 | +++ linux-2.6.29.6/drivers/pnp/pnpbios/bioscalls.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18205 | @@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr |
18206 | set_limit(gdt[(selname) >> 3], size); \ | |
18207 | } while(0) | |
18208 | ||
18209 | -static struct desc_struct bad_bios_desc; | |
18210 | +static struct desc_struct bad_bios_desc __read_only; | |
18211 | ||
18212 | /* | |
18213 | * At some point we want to use this stack frame pointer to unwind | |
18214 | @@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func | |
18215 | struct desc_struct save_desc_40; | |
18216 | int cpu; | |
18217 | ||
18218 | +#ifdef CONFIG_PAX_KERNEXEC | |
18219 | + unsigned long cr0; | |
18220 | +#endif | |
18221 | + | |
18222 | /* | |
18223 | * PnP BIOSes are generally not terribly re-entrant. | |
18224 | * Also, don't rely on them to save everything correctly. | |
18225 | @@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func | |
18226 | ||
18227 | cpu = get_cpu(); | |
18228 | save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8]; | |
18229 | + | |
18230 | +#ifdef CONFIG_PAX_KERNEXEC | |
18231 | + pax_open_kernel(cr0); | |
18232 | +#endif | |
18233 | + | |
18234 | get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc; | |
18235 | ||
18236 | +#ifdef CONFIG_PAX_KERNEXEC | |
18237 | + pax_close_kernel(cr0); | |
18238 | +#endif | |
18239 | + | |
18240 | /* On some boxes IRQ's during PnP BIOS calls are deadly. */ | |
18241 | spin_lock_irqsave(&pnp_bios_lock, flags); | |
18242 | ||
18243 | @@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func | |
18244 | :"memory"); | |
18245 | spin_unlock_irqrestore(&pnp_bios_lock, flags); | |
18246 | ||
18247 | +#ifdef CONFIG_PAX_KERNEXEC | |
18248 | + pax_open_kernel(cr0); | |
18249 | +#endif | |
18250 | + | |
18251 | get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40; | |
18252 | + | |
18253 | +#ifdef CONFIG_PAX_KERNEXEC | |
18254 | + pax_close_kernel(cr0); | |
18255 | +#endif | |
18256 | + | |
18257 | put_cpu(); | |
18258 | ||
18259 | /* If we get here and this is set then the PnP BIOS faulted on us. */ | |
18260 | @@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n | |
18261 | return status; | |
18262 | } | |
18263 | ||
18264 | -void pnpbios_calls_init(union pnp_bios_install_struct *header) | |
18265 | +void __init pnpbios_calls_init(union pnp_bios_install_struct *header) | |
18266 | { | |
18267 | int i; | |
18268 | ||
18269 | +#ifdef CONFIG_PAX_KERNEXEC | |
18270 | + unsigned long cr0; | |
18271 | +#endif | |
18272 | + | |
18273 | spin_lock_init(&pnp_bios_lock); | |
18274 | pnp_bios_callpoint.offset = header->fields.pm16offset; | |
18275 | pnp_bios_callpoint.segment = PNP_CS16; | |
18276 | ||
18277 | +#ifdef CONFIG_PAX_KERNEXEC | |
18278 | + pax_open_kernel(cr0); | |
18279 | +#endif | |
18280 | + | |
18281 | bad_bios_desc.a = 0; | |
18282 | - bad_bios_desc.b = 0x00409200; | |
18283 | + bad_bios_desc.b = 0x00409300; | |
18284 | ||
18285 | set_base(bad_bios_desc, __va((unsigned long)0x40 << 4)); | |
18286 | _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4)); | |
18287 | @@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i | |
18288 | set_base(gdt[GDT_ENTRY_PNPBIOS_DS], | |
18289 | __va(header->fields.pm16dseg)); | |
18290 | } | |
18291 | + | |
18292 | +#ifdef CONFIG_PAX_KERNEXEC | |
18293 | + pax_close_kernel(cr0); | |
18294 | +#endif | |
18295 | + | |
18296 | } | |
de855c5d AM |
18297 | diff -urNp linux-2.6.29.6/drivers/pnp/quirks.c linux-2.6.29.6/drivers/pnp/quirks.c |
18298 | --- linux-2.6.29.6/drivers/pnp/quirks.c 2009-07-02 19:41:20.000000000 -0400 | |
18299 | +++ linux-2.6.29.6/drivers/pnp/quirks.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18300 | @@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = { |
18301 | /* PnP resources that might overlap PCI BARs */ | |
18302 | {"PNP0c01", quirk_system_pci_resources}, | |
18303 | {"PNP0c02", quirk_system_pci_resources}, | |
18304 | - {""} | |
18305 | + {"", NULL} | |
18306 | }; | |
18307 | ||
18308 | void pnp_fixup_device(struct pnp_dev *dev) | |
de855c5d AM |
18309 | diff -urNp linux-2.6.29.6/drivers/pnp/resource.c linux-2.6.29.6/drivers/pnp/resource.c |
18310 | --- linux-2.6.29.6/drivers/pnp/resource.c 2009-07-02 19:41:20.000000000 -0400 | |
18311 | +++ linux-2.6.29.6/drivers/pnp/resource.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18312 | @@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s |
18313 | return 1; | |
18314 | ||
18315 | /* check if the resource is valid */ | |
18316 | - if (*irq < 0 || *irq > 15) | |
18317 | + if (*irq > 15) | |
18318 | return 0; | |
18319 | ||
18320 | /* check if the resource is reserved */ | |
18321 | @@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s | |
18322 | return 1; | |
18323 | ||
18324 | /* check if the resource is valid */ | |
18325 | - if (*dma < 0 || *dma == 4 || *dma > 7) | |
18326 | + if (*dma == 4 || *dma > 7) | |
18327 | return 0; | |
18328 | ||
18329 | /* check if the resource is reserved */ | |
de855c5d AM |
18330 | diff -urNp linux-2.6.29.6/drivers/scsi/libfc/fc_exch.c linux-2.6.29.6/drivers/scsi/libfc/fc_exch.c |
18331 | --- linux-2.6.29.6/drivers/scsi/libfc/fc_exch.c 2009-07-02 19:41:20.000000000 -0400 | |
18332 | +++ linux-2.6.29.6/drivers/scsi/libfc/fc_exch.c 2009-07-09 22:13:39.000000000 -0400 | |
18333 | @@ -84,12 +84,12 @@ struct fc_exch_mgr { | |
18334 | * all together if not used XXX | |
18335 | */ | |
18336 | struct { | |
18337 | - atomic_t no_free_exch; | |
18338 | - atomic_t no_free_exch_xid; | |
18339 | - atomic_t xid_not_found; | |
18340 | - atomic_t xid_busy; | |
18341 | - atomic_t seq_not_found; | |
18342 | - atomic_t non_bls_resp; | |
18343 | + atomic_unchecked_t no_free_exch; | |
18344 | + atomic_unchecked_t no_free_exch_xid; | |
18345 | + atomic_unchecked_t xid_not_found; | |
18346 | + atomic_unchecked_t xid_busy; | |
18347 | + atomic_unchecked_t seq_not_found; | |
18348 | + atomic_unchecked_t non_bls_resp; | |
18349 | } stats; | |
18350 | struct fc_exch **exches; /* for exch pointers indexed by xid */ | |
18351 | }; | |
18352 | @@ -534,7 +534,7 @@ struct fc_exch *fc_exch_alloc(struct fc_ | |
18353 | /* allocate memory for exchange */ | |
18354 | ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC); | |
18355 | if (!ep) { | |
18356 | - atomic_inc(&mp->stats.no_free_exch); | |
18357 | + atomic_inc_unchecked(&mp->stats.no_free_exch); | |
18358 | goto out; | |
18359 | } | |
18360 | memset(ep, 0, sizeof(*ep)); | |
18361 | @@ -579,7 +579,7 @@ out: | |
18362 | return ep; | |
18363 | err: | |
18364 | spin_unlock_bh(&mp->em_lock); | |
18365 | - atomic_inc(&mp->stats.no_free_exch_xid); | |
18366 | + atomic_inc_unchecked(&mp->stats.no_free_exch_xid); | |
18367 | mempool_free(ep, mp->ep_pool); | |
18368 | return NULL; | |
18369 | } | |
18370 | @@ -682,7 +682,7 @@ static enum fc_pf_rjt_reason fc_seq_look | |
18371 | xid = ntohs(fh->fh_ox_id); /* we originated exch */ | |
18372 | ep = fc_exch_find(mp, xid); | |
18373 | if (!ep) { | |
18374 | - atomic_inc(&mp->stats.xid_not_found); | |
18375 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18376 | reject = FC_RJT_OX_ID; | |
18377 | goto out; | |
18378 | } | |
18379 | @@ -712,7 +712,7 @@ static enum fc_pf_rjt_reason fc_seq_look | |
18380 | ep = fc_exch_find(mp, xid); | |
18381 | if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) { | |
18382 | if (ep) { | |
18383 | - atomic_inc(&mp->stats.xid_busy); | |
18384 | + atomic_inc_unchecked(&mp->stats.xid_busy); | |
18385 | reject = FC_RJT_RX_ID; | |
18386 | goto rel; | |
18387 | } | |
18388 | @@ -723,7 +723,7 @@ static enum fc_pf_rjt_reason fc_seq_look | |
18389 | } | |
18390 | xid = ep->xid; /* get our XID */ | |
18391 | } else if (!ep) { | |
18392 | - atomic_inc(&mp->stats.xid_not_found); | |
18393 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18394 | reject = FC_RJT_RX_ID; /* XID not found */ | |
18395 | goto out; | |
18396 | } | |
18397 | @@ -744,7 +744,7 @@ static enum fc_pf_rjt_reason fc_seq_look | |
18398 | } else { | |
18399 | sp = &ep->seq; | |
18400 | if (sp->id != fh->fh_seq_id) { | |
18401 | - atomic_inc(&mp->stats.seq_not_found); | |
18402 | + atomic_inc_unchecked(&mp->stats.seq_not_found); | |
18403 | reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */ | |
18404 | goto rel; | |
18405 | } | |
18406 | @@ -1156,18 +1156,18 @@ static void fc_exch_recv_seq_resp(struct | |
18407 | ||
18408 | ep = fc_exch_find(mp, ntohs(fh->fh_ox_id)); | |
18409 | if (!ep) { | |
18410 | - atomic_inc(&mp->stats.xid_not_found); | |
18411 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18412 | goto out; | |
18413 | } | |
18414 | if (ep->rxid == FC_XID_UNKNOWN) | |
18415 | ep->rxid = ntohs(fh->fh_rx_id); | |
18416 | if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) { | |
18417 | - atomic_inc(&mp->stats.xid_not_found); | |
18418 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18419 | goto rel; | |
18420 | } | |
18421 | if (ep->did != ntoh24(fh->fh_s_id) && | |
18422 | ep->did != FC_FID_FLOGI) { | |
18423 | - atomic_inc(&mp->stats.xid_not_found); | |
18424 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18425 | goto rel; | |
18426 | } | |
18427 | sof = fr_sof(fp); | |
18428 | @@ -1178,7 +1178,7 @@ static void fc_exch_recv_seq_resp(struct | |
18429 | } else { | |
18430 | sp = &ep->seq; | |
18431 | if (sp->id != fh->fh_seq_id) { | |
18432 | - atomic_inc(&mp->stats.seq_not_found); | |
18433 | + atomic_inc_unchecked(&mp->stats.seq_not_found); | |
18434 | goto rel; | |
18435 | } | |
18436 | } | |
18437 | @@ -1237,10 +1237,10 @@ static void fc_exch_recv_resp(struct fc_ | |
18438 | ||
18439 | sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */ | |
18440 | if (!sp) { | |
18441 | - atomic_inc(&mp->stats.xid_not_found); | |
18442 | + atomic_inc_unchecked(&mp->stats.xid_not_found); | |
18443 | FC_DEBUG_EXCH("seq lookup failed\n"); | |
18444 | } else { | |
18445 | - atomic_inc(&mp->stats.non_bls_resp); | |
18446 | + atomic_inc_unchecked(&mp->stats.non_bls_resp); | |
18447 | FC_DEBUG_EXCH("non-BLS response to sequence"); | |
18448 | } | |
18449 | fc_frame_free(fp); | |
18450 | diff -urNp linux-2.6.29.6/drivers/scsi/scsi_logging.h linux-2.6.29.6/drivers/scsi/scsi_logging.h | |
18451 | --- linux-2.6.29.6/drivers/scsi/scsi_logging.h 2009-07-02 19:41:20.000000000 -0400 | |
18452 | +++ linux-2.6.29.6/drivers/scsi/scsi_logging.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18453 | @@ -51,7 +51,7 @@ do { \ |
18454 | } while (0); \ | |
18455 | } while (0) | |
18456 | #else | |
18457 | -#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) | |
18458 | +#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0) | |
18459 | #endif /* CONFIG_SCSI_LOGGING */ | |
18460 | ||
18461 | /* | |
de855c5d AM |
18462 | diff -urNp linux-2.6.29.6/drivers/serial/8250_pci.c linux-2.6.29.6/drivers/serial/8250_pci.c |
18463 | --- linux-2.6.29.6/drivers/serial/8250_pci.c 2009-07-02 19:41:20.000000000 -0400 | |
18464 | +++ linux-2.6.29.6/drivers/serial/8250_pci.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18465 | @@ -3162,7 +3162,7 @@ static struct pci_device_id serial_pci_t |
18466 | PCI_ANY_ID, PCI_ANY_ID, | |
18467 | PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, | |
18468 | 0xffff00, pbn_default }, | |
18469 | - { 0, } | |
18470 | + { 0, 0, 0, 0, 0, 0, 0 } | |
18471 | }; | |
18472 | ||
18473 | static struct pci_driver serial_pci_driver = { | |
de855c5d AM |
18474 | diff -urNp linux-2.6.29.6/drivers/usb/atm/usbatm.c linux-2.6.29.6/drivers/usb/atm/usbatm.c |
18475 | --- linux-2.6.29.6/drivers/usb/atm/usbatm.c 2009-07-02 19:41:20.000000000 -0400 | |
18476 | +++ linux-2.6.29.6/drivers/usb/atm/usbatm.c 2009-07-09 22:13:39.000000000 -0400 | |
18477 | @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(stru | |
18478 | if (printk_ratelimit()) | |
18479 | atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", | |
18480 | __func__, vpi, vci); | |
18481 | - atomic_inc(&vcc->stats->rx_err); | |
18482 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
18483 | return; | |
18484 | } | |
18485 | ||
18486 | @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(stru | |
18487 | if (length > ATM_MAX_AAL5_PDU) { | |
18488 | atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n", | |
18489 | __func__, length, vcc); | |
18490 | - atomic_inc(&vcc->stats->rx_err); | |
18491 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
18492 | goto out; | |
18493 | } | |
18494 | ||
18495 | @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(stru | |
18496 | if (sarb->len < pdu_length) { | |
18497 | atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", | |
18498 | __func__, pdu_length, sarb->len, vcc); | |
18499 | - atomic_inc(&vcc->stats->rx_err); | |
18500 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
18501 | goto out; | |
18502 | } | |
18503 | ||
18504 | if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) { | |
18505 | atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", | |
18506 | __func__, vcc); | |
18507 | - atomic_inc(&vcc->stats->rx_err); | |
18508 | + atomic_inc_unchecked(&vcc->stats->rx_err); | |
18509 | goto out; | |
18510 | } | |
18511 | ||
18512 | @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(stru | |
18513 | if (printk_ratelimit()) | |
18514 | atm_err(instance, "%s: no memory for skb (length: %u)!\n", | |
18515 | __func__, length); | |
18516 | - atomic_inc(&vcc->stats->rx_drop); | |
18517 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
18518 | goto out; | |
18519 | } | |
18520 | ||
18521 | @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(stru | |
18522 | ||
18523 | vcc->push(vcc, skb); | |
18524 | ||
18525 | - atomic_inc(&vcc->stats->rx); | |
18526 | + atomic_inc_unchecked(&vcc->stats->rx); | |
18527 | out: | |
18528 | skb_trim(sarb, 0); | |
18529 | } | |
18530 | @@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned l | |
18531 | struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc; | |
18532 | ||
18533 | usbatm_pop(vcc, skb); | |
18534 | - atomic_inc(&vcc->stats->tx); | |
18535 | + atomic_inc_unchecked(&vcc->stats->tx); | |
18536 | ||
18537 | skb = skb_dequeue(&instance->sndqueue); | |
18538 | } | |
18539 | diff -urNp linux-2.6.29.6/drivers/usb/class/cdc-acm.c linux-2.6.29.6/drivers/usb/class/cdc-acm.c | |
18540 | --- linux-2.6.29.6/drivers/usb/class/cdc-acm.c 2009-07-02 19:41:20.000000000 -0400 | |
18541 | +++ linux-2.6.29.6/drivers/usb/class/cdc-acm.c 2009-07-09 22:13:39.000000000 -0400 | |
18542 | @@ -1397,7 +1397,7 @@ static struct usb_device_id acm_ids[] = | |
2380c486 JR |
18543 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
18544 | ||
18545 | /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */ | |
18546 | - { } | |
18547 | + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } | |
18548 | }; | |
18549 | ||
18550 | MODULE_DEVICE_TABLE (usb, acm_ids); | |
de855c5d AM |
18551 | diff -urNp linux-2.6.29.6/drivers/usb/class/usblp.c linux-2.6.29.6/drivers/usb/class/usblp.c |
18552 | --- linux-2.6.29.6/drivers/usb/class/usblp.c 2009-07-02 19:41:20.000000000 -0400 | |
18553 | +++ linux-2.6.29.6/drivers/usb/class/usblp.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18554 | @@ -228,7 +228,7 @@ static const struct quirk_printer_struct |
18555 | { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */ | |
18556 | { 0x04f9, 0x000d, USBLP_QUIRK_BIDIR }, /* Brother Industries, Ltd HL-1440 Laser Printer */ | |
18557 | { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */ | |
18558 | - { 0, 0 } | |
18559 | + { 0, 0, 0 } | |
18560 | }; | |
18561 | ||
18562 | static int usblp_wwait(struct usblp *usblp, int nonblock); | |
18563 | @@ -1403,7 +1403,7 @@ static struct usb_device_id usblp_ids [] | |
18564 | { USB_INTERFACE_INFO(7, 1, 2) }, | |
18565 | { USB_INTERFACE_INFO(7, 1, 3) }, | |
18566 | { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */ | |
18567 | - { } /* Terminating entry */ | |
18568 | + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */ | |
18569 | }; | |
18570 | ||
18571 | MODULE_DEVICE_TABLE (usb, usblp_ids); | |
de855c5d AM |
18572 | diff -urNp linux-2.6.29.6/drivers/usb/core/hub.c linux-2.6.29.6/drivers/usb/core/hub.c |
18573 | --- linux-2.6.29.6/drivers/usb/core/hub.c 2009-07-02 19:41:20.000000000 -0400 | |
18574 | +++ linux-2.6.29.6/drivers/usb/core/hub.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18575 | @@ -3193,7 +3193,7 @@ static struct usb_device_id hub_id_table |
18576 | .bDeviceClass = USB_CLASS_HUB}, | |
18577 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, | |
18578 | .bInterfaceClass = USB_CLASS_HUB}, | |
18579 | - { } /* Terminating entry */ | |
18580 | + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */ | |
18581 | }; | |
18582 | ||
18583 | MODULE_DEVICE_TABLE (usb, hub_id_table); | |
de855c5d AM |
18584 | diff -urNp linux-2.6.29.6/drivers/usb/core/message.c linux-2.6.29.6/drivers/usb/core/message.c |
18585 | --- linux-2.6.29.6/drivers/usb/core/message.c 2009-07-02 19:41:20.000000000 -0400 | |
18586 | +++ linux-2.6.29.6/drivers/usb/core/message.c 2009-07-09 22:13:39.000000000 -0400 | |
18587 | @@ -866,7 +866,8 @@ char *usb_cache_string(struct usb_device | |
18588 | if (buf) { | |
18589 | len = usb_string(udev, index, buf, 256); | |
18590 | if (len > 0) { | |
18591 | - smallbuf = kmalloc(++len, GFP_KERNEL); | |
18592 | + ++len; | |
18593 | + smallbuf = kmalloc(len, GFP_KERNEL); | |
18594 | if (!smallbuf) | |
18595 | return buf; | |
18596 | memcpy(smallbuf, buf, len); | |
18597 | diff -urNp linux-2.6.29.6/drivers/usb/host/ehci-pci.c linux-2.6.29.6/drivers/usb/host/ehci-pci.c | |
18598 | --- linux-2.6.29.6/drivers/usb/host/ehci-pci.c 2009-07-02 19:41:20.000000000 -0400 | |
18599 | +++ linux-2.6.29.6/drivers/usb/host/ehci-pci.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18600 | @@ -418,7 +418,7 @@ static const struct pci_device_id pci_id |
18601 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0), | |
18602 | .driver_data = (unsigned long) &ehci_pci_hc_driver, | |
18603 | }, | |
18604 | - { /* end: all zeroes */ } | |
18605 | + { 0, 0, 0, 0, 0, 0, 0 } | |
18606 | }; | |
18607 | MODULE_DEVICE_TABLE(pci, pci_ids); | |
18608 | ||
de855c5d AM |
18609 | diff -urNp linux-2.6.29.6/drivers/usb/host/uhci-hcd.c linux-2.6.29.6/drivers/usb/host/uhci-hcd.c |
18610 | --- linux-2.6.29.6/drivers/usb/host/uhci-hcd.c 2009-07-02 19:41:20.000000000 -0400 | |
18611 | +++ linux-2.6.29.6/drivers/usb/host/uhci-hcd.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18612 | @@ -927,7 +927,7 @@ static const struct pci_device_id uhci_p |
18613 | /* handle any USB UHCI controller */ | |
18614 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0), | |
18615 | .driver_data = (unsigned long) &uhci_driver, | |
18616 | - }, { /* end: all zeroes */ } | |
18617 | + }, { 0, 0, 0, 0, 0, 0, 0 } | |
18618 | }; | |
18619 | ||
18620 | MODULE_DEVICE_TABLE(pci, uhci_pci_ids); | |
de855c5d AM |
18621 | diff -urNp linux-2.6.29.6/drivers/usb/storage/debug.h linux-2.6.29.6/drivers/usb/storage/debug.h |
18622 | --- linux-2.6.29.6/drivers/usb/storage/debug.h 2009-07-02 19:41:20.000000000 -0400 | |
18623 | +++ linux-2.6.29.6/drivers/usb/storage/debug.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18624 | @@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char |
18625 | #define US_DEBUGPX(x...) printk( x ) | |
18626 | #define US_DEBUG(x) x | |
18627 | #else | |
18628 | -#define US_DEBUGP(x...) | |
18629 | -#define US_DEBUGPX(x...) | |
18630 | -#define US_DEBUG(x) | |
18631 | +#define US_DEBUGP(x...) do {} while (0) | |
18632 | +#define US_DEBUGPX(x...) do {} while (0) | |
18633 | +#define US_DEBUG(x) do {} while (0) | |
18634 | #endif | |
18635 | ||
18636 | #endif | |
de855c5d AM |
18637 | diff -urNp linux-2.6.29.6/drivers/usb/storage/usb.c linux-2.6.29.6/drivers/usb/storage/usb.c |
18638 | --- linux-2.6.29.6/drivers/usb/storage/usb.c 2009-07-02 19:41:20.000000000 -0400 | |
18639 | +++ linux-2.6.29.6/drivers/usb/storage/usb.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18640 | @@ -141,7 +141,7 @@ static struct usb_device_id storage_usb_ |
18641 | #undef COMPLIANT_DEV | |
18642 | #undef USUAL_DEV | |
18643 | /* Terminating entry */ | |
18644 | - { } | |
18645 | + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } | |
18646 | }; | |
18647 | ||
18648 | MODULE_DEVICE_TABLE (usb, storage_usb_ids); | |
18649 | @@ -184,7 +184,7 @@ static struct us_unusual_dev us_unusual_ | |
18650 | # undef USUAL_DEV | |
18651 | ||
18652 | /* Terminating entry */ | |
18653 | - { NULL } | |
18654 | + { NULL, NULL, 0, 0, NULL } | |
18655 | }; | |
18656 | ||
18657 | ||
de855c5d AM |
18658 | diff -urNp linux-2.6.29.6/drivers/uwb/wlp/messages.c linux-2.6.29.6/drivers/uwb/wlp/messages.c |
18659 | --- linux-2.6.29.6/drivers/uwb/wlp/messages.c 2009-07-02 19:41:20.000000000 -0400 | |
18660 | +++ linux-2.6.29.6/drivers/uwb/wlp/messages.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18661 | @@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct |
18662 | size_t len = skb->len; | |
18663 | size_t used; | |
18664 | ssize_t result; | |
18665 | - struct wlp_nonce enonce, rnonce; | |
18666 | + struct wlp_nonce enonce = {{0}}, rnonce = {{0}}; | |
18667 | enum wlp_assc_error assc_err; | |
18668 | char enonce_buf[WLP_WSS_NONCE_STRSIZE]; | |
18669 | char rnonce_buf[WLP_WSS_NONCE_STRSIZE]; | |
de855c5d AM |
18670 | diff -urNp linux-2.6.29.6/drivers/video/fbmem.c linux-2.6.29.6/drivers/video/fbmem.c |
18671 | --- linux-2.6.29.6/drivers/video/fbmem.c 2009-07-02 19:41:20.000000000 -0400 | |
18672 | +++ linux-2.6.29.6/drivers/video/fbmem.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18673 | @@ -393,7 +393,7 @@ static void fb_do_show_logo(struct fb_in |
18674 | image->dx += image->width + 8; | |
18675 | } | |
18676 | } else if (rotate == FB_ROTATE_UD) { | |
18677 | - for (x = 0; x < num && image->dx >= 0; x++) { | |
18678 | + for (x = 0; x < num && (__s32)image->dx >= 0; x++) { | |
18679 | info->fbops->fb_imageblit(info, image); | |
18680 | image->dx -= image->width + 8; | |
18681 | } | |
18682 | @@ -405,7 +405,7 @@ static void fb_do_show_logo(struct fb_in | |
18683 | image->dy += image->height + 8; | |
18684 | } | |
18685 | } else if (rotate == FB_ROTATE_CCW) { | |
18686 | - for (x = 0; x < num && image->dy >= 0; x++) { | |
18687 | + for (x = 0; x < num && (__s32)image->dy >= 0; x++) { | |
18688 | info->fbops->fb_imageblit(info, image); | |
18689 | image->dy -= image->height + 8; | |
18690 | } | |
de855c5d | 18691 | @@ -1098,7 +1098,7 @@ static long do_fb_ioctl(struct fb_info * |
2380c486 JR |
18692 | return -EFAULT; |
18693 | if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) | |
18694 | return -EINVAL; | |
18695 | - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) | |
18696 | + if (con2fb.framebuffer >= FB_MAX) | |
18697 | return -EINVAL; | |
18698 | if (!registered_fb[con2fb.framebuffer]) | |
18699 | request_module("fb%d", con2fb.framebuffer); | |
de855c5d AM |
18700 | diff -urNp linux-2.6.29.6/drivers/video/fbmon.c linux-2.6.29.6/drivers/video/fbmon.c |
18701 | --- linux-2.6.29.6/drivers/video/fbmon.c 2009-07-02 19:41:20.000000000 -0400 | |
18702 | +++ linux-2.6.29.6/drivers/video/fbmon.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18703 | @@ -45,7 +45,7 @@ |
18704 | #ifdef DEBUG | |
18705 | #define DPRINTK(fmt, args...) printk(fmt,## args) | |
18706 | #else | |
18707 | -#define DPRINTK(fmt, args...) | |
18708 | +#define DPRINTK(fmt, args...) do {} while (0) | |
18709 | #endif | |
18710 | ||
18711 | #define FBMON_FIX_HEADER 1 | |
de855c5d AM |
18712 | diff -urNp linux-2.6.29.6/drivers/video/i810/i810_accel.c linux-2.6.29.6/drivers/video/i810/i810_accel.c |
18713 | --- linux-2.6.29.6/drivers/video/i810/i810_accel.c 2009-07-02 19:41:20.000000000 -0400 | |
18714 | +++ linux-2.6.29.6/drivers/video/i810/i810_accel.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18715 | @@ -73,6 +73,7 @@ static inline int wait_for_space(struct |
18716 | } | |
18717 | } | |
18718 | printk("ringbuffer lockup!!!\n"); | |
18719 | + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space); | |
18720 | i810_report_error(mmio); | |
18721 | par->dev_flags |= LOCKUP; | |
18722 | info->pixmap.scan_align = 1; | |
de855c5d AM |
18723 | diff -urNp linux-2.6.29.6/drivers/video/i810/i810_main.c linux-2.6.29.6/drivers/video/i810/i810_main.c |
18724 | --- linux-2.6.29.6/drivers/video/i810/i810_main.c 2009-07-02 19:41:20.000000000 -0400 | |
18725 | +++ linux-2.6.29.6/drivers/video/i810/i810_main.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18726 | @@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t |
18727 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, | |
18728 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, | |
18729 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, | |
18730 | - { 0 }, | |
18731 | + { 0, 0, 0, 0, 0, 0, 0 }, | |
18732 | }; | |
18733 | ||
18734 | static struct pci_driver i810fb_driver = { | |
de855c5d AM |
18735 | diff -urNp linux-2.6.29.6/drivers/video/modedb.c linux-2.6.29.6/drivers/video/modedb.c |
18736 | --- linux-2.6.29.6/drivers/video/modedb.c 2009-07-02 19:41:20.000000000 -0400 | |
18737 | +++ linux-2.6.29.6/drivers/video/modedb.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
18738 | @@ -38,232 +38,232 @@ static const struct fb_videomode modedb[ |
18739 | { | |
18740 | /* 640x400 @ 70 Hz, 31.5 kHz hsync */ | |
18741 | NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, | |
18742 | - 0, FB_VMODE_NONINTERLACED | |
18743 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18744 | }, { | |
18745 | /* 640x480 @ 60 Hz, 31.5 kHz hsync */ | |
18746 | NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, | |
18747 | - 0, FB_VMODE_NONINTERLACED | |
18748 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18749 | }, { | |
18750 | /* 800x600 @ 56 Hz, 35.15 kHz hsync */ | |
18751 | NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, | |
18752 | - 0, FB_VMODE_NONINTERLACED | |
18753 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18754 | }, { | |
18755 | /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */ | |
18756 | NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, | |
18757 | - 0, FB_VMODE_INTERLACED | |
18758 | + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN | |
18759 | }, { | |
18760 | /* 640x400 @ 85 Hz, 37.86 kHz hsync */ | |
18761 | NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3, | |
18762 | - FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18763 | + FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18764 | }, { | |
18765 | /* 640x480 @ 72 Hz, 36.5 kHz hsync */ | |
18766 | NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, | |
18767 | - 0, FB_VMODE_NONINTERLACED | |
18768 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18769 | }, { | |
18770 | /* 640x480 @ 75 Hz, 37.50 kHz hsync */ | |
18771 | NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, | |
18772 | - 0, FB_VMODE_NONINTERLACED | |
18773 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18774 | }, { | |
18775 | /* 800x600 @ 60 Hz, 37.8 kHz hsync */ | |
18776 | NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4, | |
18777 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18778 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18779 | }, { | |
18780 | /* 640x480 @ 85 Hz, 43.27 kHz hsync */ | |
18781 | NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, | |
18782 | - 0, FB_VMODE_NONINTERLACED | |
18783 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18784 | }, { | |
18785 | /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */ | |
18786 | NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, | |
18787 | - 0, FB_VMODE_INTERLACED | |
18788 | + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN | |
18789 | }, { | |
18790 | /* 800x600 @ 72 Hz, 48.0 kHz hsync */ | |
18791 | NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6, | |
18792 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18793 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18794 | }, { | |
18795 | /* 1024x768 @ 60 Hz, 48.4 kHz hsync */ | |
18796 | NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, | |
18797 | - 0, FB_VMODE_NONINTERLACED | |
18798 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18799 | }, { | |
18800 | /* 640x480 @ 100 Hz, 53.01 kHz hsync */ | |
18801 | NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, | |
18802 | - 0, FB_VMODE_NONINTERLACED | |
18803 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18804 | }, { | |
18805 | /* 1152x864 @ 60 Hz, 53.5 kHz hsync */ | |
18806 | NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, | |
18807 | - 0, FB_VMODE_NONINTERLACED | |
18808 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18809 | }, { | |
18810 | /* 800x600 @ 85 Hz, 55.84 kHz hsync */ | |
18811 | NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, | |
18812 | - 0, FB_VMODE_NONINTERLACED | |
18813 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18814 | }, { | |
18815 | /* 1024x768 @ 70 Hz, 56.5 kHz hsync */ | |
18816 | NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, | |
18817 | - 0, FB_VMODE_NONINTERLACED | |
18818 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18819 | }, { | |
18820 | /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */ | |
18821 | NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, | |
18822 | - 0, FB_VMODE_INTERLACED | |
18823 | + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN | |
18824 | }, { | |
18825 | /* 800x600 @ 100 Hz, 64.02 kHz hsync */ | |
18826 | NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, | |
18827 | - 0, FB_VMODE_NONINTERLACED | |
18828 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18829 | }, { | |
18830 | /* 1024x768 @ 76 Hz, 62.5 kHz hsync */ | |
18831 | NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, | |
18832 | - 0, FB_VMODE_NONINTERLACED | |
18833 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18834 | }, { | |
18835 | /* 1152x864 @ 70 Hz, 62.4 kHz hsync */ | |
18836 | NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, | |
18837 | - 0, FB_VMODE_NONINTERLACED | |
18838 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18839 | }, { | |
18840 | /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */ | |
18841 | NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, | |
18842 | - 0, FB_VMODE_NONINTERLACED | |
18843 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18844 | }, { | |
18845 | /* 1400x1050 @ 60Hz, 63.9 kHz hsync */ | |
18846 | NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, | |
18847 | - 0, FB_VMODE_NONINTERLACED | |
18848 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18849 | }, { | |
18850 | /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/ | |
18851 | NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13, | |
18852 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18853 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18854 | }, { | |
18855 | /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/ | |
18856 | NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3, | |
18857 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18858 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18859 | }, { | |
18860 | /* 1024x768 @ 85 Hz, 70.24 kHz hsync */ | |
18861 | NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, | |
18862 | - 0, FB_VMODE_NONINTERLACED | |
18863 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18864 | }, { | |
18865 | /* 1152x864 @ 78 Hz, 70.8 kHz hsync */ | |
18866 | NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, | |
18867 | - 0, FB_VMODE_NONINTERLACED | |
18868 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18869 | }, { | |
18870 | /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */ | |
18871 | NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, | |
18872 | - 0, FB_VMODE_NONINTERLACED | |
18873 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18874 | }, { | |
18875 | /* 1600x1200 @ 60Hz, 75.00 kHz hsync */ | |
18876 | NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3, | |
18877 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18878 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18879 | }, { | |
18880 | /* 1152x864 @ 84 Hz, 76.0 kHz hsync */ | |
18881 | NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, | |
18882 | - 0, FB_VMODE_NONINTERLACED | |
18883 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18884 | }, { | |
18885 | /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */ | |
18886 | NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, | |
18887 | - 0, FB_VMODE_NONINTERLACED | |
18888 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18889 | }, { | |
18890 | /* 1024x768 @ 100Hz, 80.21 kHz hsync */ | |
18891 | NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, | |
18892 | - 0, FB_VMODE_NONINTERLACED | |
18893 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18894 | }, { | |
18895 | /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */ | |
18896 | NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, | |
18897 | - 0, FB_VMODE_NONINTERLACED | |
18898 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18899 | }, { | |
18900 | /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */ | |
18901 | NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, | |
18902 | - 0, FB_VMODE_NONINTERLACED | |
18903 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18904 | }, { | |
18905 | /* 1152x864 @ 100 Hz, 89.62 kHz hsync */ | |
18906 | NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, | |
18907 | - 0, FB_VMODE_NONINTERLACED | |
18908 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18909 | }, { | |
18910 | /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */ | |
18911 | NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3, | |
18912 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18913 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18914 | }, { | |
18915 | /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */ | |
18916 | NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, | |
18917 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18918 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18919 | }, { | |
18920 | /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */ | |
18921 | NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6, | |
18922 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18923 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18924 | }, { | |
18925 | /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */ | |
18926 | NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3, | |
18927 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18928 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18929 | }, { | |
18930 | /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */ | |
18931 | NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, | |
18932 | - 0, FB_VMODE_NONINTERLACED | |
18933 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18934 | }, { | |
18935 | /* 1800x1440 @ 64Hz, 96.15 kHz hsync */ | |
18936 | NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3, | |
18937 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18938 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18939 | }, { | |
18940 | /* 1800x1440 @ 70Hz, 104.52 kHz hsync */ | |
18941 | NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3, | |
18942 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
18943 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18944 | }, { | |
18945 | /* 512x384 @ 78 Hz, 31.50 kHz hsync */ | |
18946 | NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, | |
18947 | - 0, FB_VMODE_NONINTERLACED | |
18948 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18949 | }, { | |
18950 | /* 512x384 @ 85 Hz, 34.38 kHz hsync */ | |
18951 | NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, | |
18952 | - 0, FB_VMODE_NONINTERLACED | |
18953 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
18954 | }, { | |
18955 | /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */ | |
18956 | NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, | |
18957 | - 0, FB_VMODE_DOUBLE | |
18958 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18959 | }, { | |
18960 | /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */ | |
18961 | NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, | |
18962 | - 0, FB_VMODE_DOUBLE | |
18963 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18964 | }, { | |
18965 | /* 320x240 @ 72 Hz, 36.5 kHz hsync */ | |
18966 | NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, | |
18967 | - 0, FB_VMODE_DOUBLE | |
18968 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18969 | }, { | |
18970 | /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */ | |
18971 | NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, | |
18972 | - 0, FB_VMODE_DOUBLE | |
18973 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18974 | }, { | |
18975 | /* 400x300 @ 60 Hz, 37.8 kHz hsync */ | |
18976 | NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, | |
18977 | - 0, FB_VMODE_DOUBLE | |
18978 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18979 | }, { | |
18980 | /* 400x300 @ 72 Hz, 48.0 kHz hsync */ | |
18981 | NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, | |
18982 | - 0, FB_VMODE_DOUBLE | |
18983 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18984 | }, { | |
18985 | /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */ | |
18986 | NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, | |
18987 | - 0, FB_VMODE_DOUBLE | |
18988 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18989 | }, { | |
18990 | /* 480x300 @ 60 Hz, 37.8 kHz hsync */ | |
18991 | NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, | |
18992 | - 0, FB_VMODE_DOUBLE | |
18993 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18994 | }, { | |
18995 | /* 480x300 @ 63 Hz, 39.6 kHz hsync */ | |
18996 | NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, | |
18997 | - 0, FB_VMODE_DOUBLE | |
18998 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
18999 | }, { | |
19000 | /* 480x300 @ 72 Hz, 48.0 kHz hsync */ | |
19001 | NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, | |
19002 | - 0, FB_VMODE_DOUBLE | |
19003 | + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN | |
19004 | }, { | |
19005 | /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */ | |
19006 | NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3, | |
19007 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, | |
19008 | - FB_VMODE_NONINTERLACED | |
19009 | + FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
19010 | }, { | |
19011 | /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */ | |
19012 | NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6, | |
19013 | - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED | |
19014 | + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
19015 | }, { | |
19016 | /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */ | |
19017 | NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, | |
19018 | - 0, FB_VMODE_NONINTERLACED | |
19019 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
19020 | }, { | |
19021 | /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */ | |
19022 | NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, | |
19023 | - 0, FB_VMODE_NONINTERLACED | |
19024 | + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN | |
19025 | }, | |
19026 | }; | |
19027 | ||
de855c5d AM |
19028 | diff -urNp linux-2.6.29.6/drivers/video/uvesafb.c linux-2.6.29.6/drivers/video/uvesafb.c |
19029 | --- linux-2.6.29.6/drivers/video/uvesafb.c 2009-07-02 19:41:20.000000000 -0400 | |
19030 | +++ linux-2.6.29.6/drivers/video/uvesafb.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19031 | @@ -18,6 +18,7 @@ |
19032 | #include <linux/fb.h> | |
19033 | #include <linux/io.h> | |
19034 | #include <linux/mutex.h> | |
19035 | +#include <linux/moduleloader.h> | |
19036 | #include <video/edid.h> | |
19037 | #include <video/uvesafb.h> | |
19038 | #ifdef CONFIG_X86 | |
19039 | @@ -117,7 +118,7 @@ static int uvesafb_helper_start(void) | |
19040 | NULL, | |
19041 | }; | |
19042 | ||
19043 | - return call_usermodehelper(v86d_path, argv, envp, 1); | |
19044 | + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC); | |
19045 | } | |
19046 | ||
19047 | /* | |
19048 | @@ -574,10 +575,34 @@ static int __devinit uvesafb_vbe_getpmi( | |
19049 | if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) { | |
19050 | par->pmi_setpal = par->ypan = 0; | |
19051 | } else { | |
19052 | + | |
19053 | +#ifdef CONFIG_PAX_KERNEXEC | |
19054 | +#ifdef CONFIG_MODULES | |
19055 | + unsigned long cr0; | |
19056 | + | |
19057 | + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx); | |
19058 | +#endif | |
19059 | + if (!par->pmi_code) { | |
19060 | + par->pmi_setpal = par->ypan = 0; | |
19061 | + return 0; | |
19062 | + } | |
19063 | +#endif | |
19064 | + | |
19065 | par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4) | |
19066 | + task->t.regs.edi); | |
19067 | + | |
19068 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19069 | + pax_open_kernel(cr0); | |
19070 | + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx); | |
19071 | + pax_close_kernel(cr0); | |
19072 | + | |
19073 | + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]); | |
19074 | + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]); | |
19075 | +#else | |
19076 | par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1]; | |
19077 | par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2]; | |
19078 | +#endif | |
19079 | + | |
19080 | printk(KERN_INFO "uvesafb: protected mode interface info at " | |
19081 | "%04x:%04x\n", | |
19082 | (u16)task->t.regs.es, (u16)task->t.regs.edi); | |
19083 | @@ -1832,6 +1857,11 @@ out: | |
19084 | if (par->vbe_modes) | |
19085 | kfree(par->vbe_modes); | |
19086 | ||
19087 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19088 | + if (par->pmi_code) | |
19089 | + module_free_exec(NULL, par->pmi_code); | |
19090 | +#endif | |
19091 | + | |
19092 | framebuffer_release(info); | |
19093 | return err; | |
19094 | } | |
19095 | @@ -1858,6 +1888,12 @@ static int uvesafb_remove(struct platfor | |
19096 | kfree(par->vbe_state_orig); | |
19097 | if (par->vbe_state_saved) | |
19098 | kfree(par->vbe_state_saved); | |
19099 | + | |
19100 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19101 | + if (par->pmi_code) | |
19102 | + module_free_exec(NULL, par->pmi_code); | |
19103 | +#endif | |
19104 | + | |
19105 | } | |
19106 | ||
19107 | framebuffer_release(info); | |
de855c5d AM |
19108 | diff -urNp linux-2.6.29.6/drivers/video/vesafb.c linux-2.6.29.6/drivers/video/vesafb.c |
19109 | --- linux-2.6.29.6/drivers/video/vesafb.c 2009-07-02 19:41:20.000000000 -0400 | |
19110 | +++ linux-2.6.29.6/drivers/video/vesafb.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19111 | @@ -9,6 +9,7 @@ |
19112 | */ | |
19113 | ||
19114 | #include <linux/module.h> | |
19115 | +#include <linux/moduleloader.h> | |
19116 | #include <linux/kernel.h> | |
19117 | #include <linux/errno.h> | |
19118 | #include <linux/string.h> | |
19119 | @@ -53,8 +54,8 @@ static int vram_remap __initdata; /* | |
19120 | static int vram_total __initdata; /* Set total amount of memory */ | |
19121 | static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */ | |
19122 | static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */ | |
19123 | -static void (*pmi_start)(void) __read_mostly; | |
19124 | -static void (*pmi_pal) (void) __read_mostly; | |
19125 | +static void (*pmi_start)(void) __read_only; | |
19126 | +static void (*pmi_pal) (void) __read_only; | |
19127 | static int depth __read_mostly; | |
19128 | static int vga_compat __read_mostly; | |
19129 | /* --------------------------------------------------------------------- */ | |
19130 | @@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl | |
19131 | unsigned int size_vmode; | |
19132 | unsigned int size_remap; | |
19133 | unsigned int size_total; | |
19134 | + void *pmi_code = NULL; | |
19135 | ||
19136 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) | |
19137 | return -ENODEV; | |
19138 | @@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl | |
19139 | size_remap = size_total; | |
19140 | vesafb_fix.smem_len = size_remap; | |
19141 | ||
19142 | -#ifndef __i386__ | |
19143 | - screen_info.vesapm_seg = 0; | |
19144 | -#endif | |
19145 | - | |
19146 | if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) { | |
19147 | printk(KERN_WARNING | |
19148 | "vesafb: cannot reserve video memory at 0x%lx\n", | |
19149 | @@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl | |
19150 | printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n", | |
19151 | vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages); | |
19152 | ||
19153 | +#ifdef __i386__ | |
19154 | + | |
19155 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19156 | + pmi_code = module_alloc_exec(screen_info.vesapm_size); | |
19157 | + if (!pmi_code) | |
19158 | +#elif !defined(CONFIG_PAX_KERNEXEC) | |
19159 | + if (0) | |
19160 | +#endif | |
19161 | + | |
19162 | +#endif | |
19163 | + screen_info.vesapm_seg = 0; | |
19164 | + | |
19165 | if (screen_info.vesapm_seg) { | |
19166 | - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n", | |
19167 | - screen_info.vesapm_seg,screen_info.vesapm_off); | |
19168 | + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n", | |
19169 | + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size); | |
19170 | } | |
19171 | ||
19172 | if (screen_info.vesapm_seg < 0xc000) | |
19173 | @@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl | |
19174 | ||
19175 | if (ypan || pmi_setpal) { | |
19176 | unsigned short *pmi_base; | |
19177 | - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); | |
19178 | - pmi_start = (void*)((char*)pmi_base + pmi_base[1]); | |
19179 | - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); | |
19180 | + | |
19181 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19182 | + unsigned long cr0; | |
19183 | +#endif | |
19184 | + | |
19185 | + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); | |
19186 | + | |
19187 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19188 | + pax_open_kernel(cr0); | |
19189 | + memcpy(pmi_code, pmi_base, screen_info.vesapm_size); | |
19190 | +#else | |
19191 | + pmi_code = pmi_base; | |
19192 | +#endif | |
19193 | + | |
19194 | + pmi_start = (void*)((char*)pmi_code + pmi_base[1]); | |
19195 | + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]); | |
19196 | + | |
19197 | +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19198 | + pmi_start = ktva_ktla(pmi_start); | |
19199 | + pmi_pal = ktva_ktla(pmi_pal); | |
19200 | + pax_close_kernel(cr0); | |
19201 | +#endif | |
19202 | + | |
19203 | printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal); | |
19204 | if (pmi_base[3]) { | |
19205 | printk(KERN_INFO "vesafb: pmi: ports = "); | |
19206 | @@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl | |
19207 | info->node, info->fix.id); | |
19208 | return 0; | |
19209 | err: | |
19210 | + | |
19211 | +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC) | |
19212 | + module_free_exec(NULL, pmi_code); | |
19213 | +#endif | |
19214 | + | |
19215 | if (info->screen_base) | |
19216 | iounmap(info->screen_base); | |
19217 | framebuffer_release(info); | |
de855c5d AM |
19218 | diff -urNp linux-2.6.29.6/fs/9p/vfs_inode.c linux-2.6.29.6/fs/9p/vfs_inode.c |
19219 | --- linux-2.6.29.6/fs/9p/vfs_inode.c 2009-07-02 19:41:20.000000000 -0400 | |
19220 | +++ linux-2.6.29.6/fs/9p/vfs_inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19221 | @@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct |
19222 | static void | |
19223 | v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) | |
19224 | { | |
19225 | - char *s = nd_get_link(nd); | |
19226 | + const char *s = nd_get_link(nd); | |
19227 | ||
19228 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, | |
19229 | IS_ERR(s) ? "<error>" : s); | |
de855c5d AM |
19230 | diff -urNp linux-2.6.29.6/fs/aio.c linux-2.6.29.6/fs/aio.c |
19231 | --- linux-2.6.29.6/fs/aio.c 2009-07-02 19:41:20.000000000 -0400 | |
19232 | +++ linux-2.6.29.6/fs/aio.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19233 | @@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx |
19234 | size += sizeof(struct io_event) * nr_events; | |
19235 | nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT; | |
19236 | ||
19237 | - if (nr_pages < 0) | |
19238 | + if (nr_pages <= 0) | |
19239 | return -EINVAL; | |
19240 | ||
19241 | nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event); | |
de855c5d AM |
19242 | diff -urNp linux-2.6.29.6/fs/autofs/root.c linux-2.6.29.6/fs/autofs/root.c |
19243 | --- linux-2.6.29.6/fs/autofs/root.c 2009-07-02 19:41:20.000000000 -0400 | |
19244 | +++ linux-2.6.29.6/fs/autofs/root.c 2009-07-09 22:13:39.000000000 -0400 | |
19245 | @@ -299,7 +299,8 @@ static int autofs_root_symlink(struct in | |
19246 | set_bit(n,sbi->symlink_bitmap); | |
19247 | sl = &sbi->symlink[n]; | |
19248 | sl->len = strlen(symname); | |
19249 | - sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL); | |
19250 | + slsize = sl->len + 1; | |
19251 | + sl->data = kmalloc(slsize, GFP_KERNEL); | |
19252 | if (!sl->data) { | |
19253 | clear_bit(n,sbi->symlink_bitmap); | |
19254 | unlock_kernel(); | |
19255 | diff -urNp linux-2.6.29.6/fs/autofs4/symlink.c linux-2.6.29.6/fs/autofs4/symlink.c | |
19256 | --- linux-2.6.29.6/fs/autofs4/symlink.c 2009-07-02 19:41:20.000000000 -0400 | |
19257 | +++ linux-2.6.29.6/fs/autofs4/symlink.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19258 | @@ -15,7 +15,7 @@ |
19259 | static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) | |
19260 | { | |
19261 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
19262 | - nd_set_link(nd, (char *)ino->u.symlink); | |
19263 | + nd_set_link(nd, ino->u.symlink); | |
19264 | return NULL; | |
19265 | } | |
19266 | ||
de855c5d AM |
19267 | diff -urNp linux-2.6.29.6/fs/befs/linuxvfs.c linux-2.6.29.6/fs/befs/linuxvfs.c |
19268 | --- linux-2.6.29.6/fs/befs/linuxvfs.c 2009-07-02 19:41:20.000000000 -0400 | |
19269 | +++ linux-2.6.29.6/fs/befs/linuxvfs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19270 | @@ -493,7 +493,7 @@ static void befs_put_link(struct dentry |
19271 | { | |
19272 | befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); | |
19273 | if (befs_ino->i_flags & BEFS_LONG_SYMLINK) { | |
19274 | - char *link = nd_get_link(nd); | |
19275 | + const char *link = nd_get_link(nd); | |
19276 | if (!IS_ERR(link)) | |
19277 | kfree(link); | |
19278 | } | |
de855c5d AM |
19279 | diff -urNp linux-2.6.29.6/fs/binfmt_aout.c linux-2.6.29.6/fs/binfmt_aout.c |
19280 | --- linux-2.6.29.6/fs/binfmt_aout.c 2009-07-02 19:41:20.000000000 -0400 | |
19281 | +++ linux-2.6.29.6/fs/binfmt_aout.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19282 | @@ -16,6 +16,7 @@ |
19283 | #include <linux/string.h> | |
19284 | #include <linux/fs.h> | |
19285 | #include <linux/file.h> | |
19286 | +#include <linux/security.h> | |
19287 | #include <linux/stat.h> | |
19288 | #include <linux/fcntl.h> | |
19289 | #include <linux/ptrace.h> | |
19290 | @@ -113,10 +114,12 @@ static int aout_core_dump(long signr, st | |
19291 | ||
19292 | /* If the size of the dump file exceeds the rlimit, then see what would happen | |
19293 | if we wrote the stack, but not the data area. */ | |
19294 | + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1); | |
19295 | if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit) | |
19296 | dump.u_dsize = 0; | |
19297 | ||
19298 | /* Make sure we have enough room to write the stack and data areas. */ | |
19299 | + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1); | |
19300 | if ((dump.u_ssize + 1) * PAGE_SIZE > limit) | |
19301 | dump.u_ssize = 0; | |
19302 | ||
19303 | @@ -249,6 +252,8 @@ static int load_aout_binary(struct linux | |
19304 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | |
19305 | if (rlim >= RLIM_INFINITY) | |
19306 | rlim = ~0; | |
19307 | + | |
19308 | + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1); | |
19309 | if (ex.a_data + ex.a_bss > rlim) | |
19310 | return -ENOMEM; | |
19311 | ||
19312 | @@ -276,6 +281,27 @@ static int load_aout_binary(struct linux | |
19313 | install_exec_creds(bprm); | |
19314 | current->flags &= ~PF_FORKNOEXEC; | |
19315 | ||
19316 | +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
19317 | + current->mm->pax_flags = 0UL; | |
19318 | +#endif | |
19319 | + | |
19320 | +#ifdef CONFIG_PAX_PAGEEXEC | |
19321 | + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) { | |
19322 | + current->mm->pax_flags |= MF_PAX_PAGEEXEC; | |
19323 | + | |
19324 | +#ifdef CONFIG_PAX_EMUTRAMP | |
19325 | + if (N_FLAGS(ex) & F_PAX_EMUTRAMP) | |
19326 | + current->mm->pax_flags |= MF_PAX_EMUTRAMP; | |
19327 | +#endif | |
19328 | + | |
19329 | +#ifdef CONFIG_PAX_MPROTECT | |
19330 | + if (!(N_FLAGS(ex) & F_PAX_MPROTECT)) | |
19331 | + current->mm->pax_flags |= MF_PAX_MPROTECT; | |
19332 | +#endif | |
19333 | + | |
19334 | + } | |
19335 | +#endif | |
19336 | + | |
19337 | if (N_MAGIC(ex) == OMAGIC) { | |
19338 | unsigned long text_addr, map_size; | |
19339 | loff_t pos; | |
19340 | @@ -348,7 +374,7 @@ static int load_aout_binary(struct linux | |
19341 | ||
19342 | down_write(¤t->mm->mmap_sem); | |
19343 | error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data, | |
19344 | - PROT_READ | PROT_WRITE | PROT_EXEC, | |
19345 | + PROT_READ | PROT_WRITE, | |
19346 | MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, | |
19347 | fd_offset + ex.a_text); | |
19348 | up_write(¤t->mm->mmap_sem); | |
de855c5d AM |
19349 | diff -urNp linux-2.6.29.6/fs/binfmt_elf.c linux-2.6.29.6/fs/binfmt_elf.c |
19350 | --- linux-2.6.29.6/fs/binfmt_elf.c 2009-07-02 19:41:20.000000000 -0400 | |
19351 | +++ linux-2.6.29.6/fs/binfmt_elf.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19352 | @@ -42,6 +42,10 @@ |
19353 | #include <asm/param.h> | |
19354 | #include <asm/page.h> | |
19355 | ||
19356 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19357 | +#include <asm/desc.h> | |
19358 | +#endif | |
19359 | + | |
19360 | static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs); | |
19361 | static int load_elf_library(struct file *); | |
19362 | static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *, | |
19363 | @@ -57,6 +61,10 @@ static int elf_core_dump(long signr, str | |
19364 | #define elf_core_dump NULL | |
19365 | #endif | |
19366 | ||
19367 | +#ifdef CONFIG_PAX_MPROTECT | |
19368 | +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags); | |
19369 | +#endif | |
19370 | + | |
19371 | #if ELF_EXEC_PAGESIZE > PAGE_SIZE | |
19372 | #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE | |
19373 | #else | |
19374 | @@ -76,6 +84,11 @@ static struct linux_binfmt elf_format = | |
19375 | .load_binary = load_elf_binary, | |
19376 | .load_shlib = load_elf_library, | |
19377 | .core_dump = elf_core_dump, | |
19378 | + | |
19379 | +#ifdef CONFIG_PAX_MPROTECT | |
19380 | + .handle_mprotect= elf_handle_mprotect, | |
19381 | +#endif | |
19382 | + | |
19383 | .min_coredump = ELF_EXEC_PAGESIZE, | |
19384 | .hasvdso = 1 | |
19385 | }; | |
19386 | @@ -84,6 +97,8 @@ static struct linux_binfmt elf_format = | |
19387 | ||
19388 | static int set_brk(unsigned long start, unsigned long end) | |
19389 | { | |
19390 | + unsigned long e = end; | |
19391 | + | |
19392 | start = ELF_PAGEALIGN(start); | |
19393 | end = ELF_PAGEALIGN(end); | |
19394 | if (end > start) { | |
19395 | @@ -94,7 +109,7 @@ static int set_brk(unsigned long start, | |
19396 | if (BAD_ADDR(addr)) | |
19397 | return addr; | |
19398 | } | |
19399 | - current->mm->start_brk = current->mm->brk = end; | |
19400 | + current->mm->start_brk = current->mm->brk = e; | |
19401 | return 0; | |
19402 | } | |
19403 | ||
de855c5d AM |
19404 | @@ -155,7 +170,7 @@ create_elf_tables(struct linux_binprm *b |
19405 | elf_addr_t __user *u_rand_bytes; | |
19406 | const char *k_platform = ELF_PLATFORM; | |
19407 | const char *k_base_platform = ELF_BASE_PLATFORM; | |
19408 | - unsigned char k_rand_bytes[16]; | |
19409 | + u32 k_rand_bytes[4]; | |
19410 | int items; | |
19411 | elf_addr_t *elf_info; | |
19412 | int ei_index = 0; | |
19413 | @@ -202,6 +217,10 @@ create_elf_tables(struct linux_binprm *b | |
19414 | * Generate 16 random bytes for userspace PRNG seeding. | |
19415 | */ | |
19416 | get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes)); | |
19417 | + srandom32(k_rand_bytes[0] ^ random32()); | |
19418 | + srandom32(k_rand_bytes[1] ^ random32()); | |
19419 | + srandom32(k_rand_bytes[2] ^ random32()); | |
19420 | + srandom32(k_rand_bytes[3] ^ random32()); | |
19421 | u_rand_bytes = (elf_addr_t __user *) | |
19422 | STACK_ALLOC(p, sizeof(k_rand_bytes)); | |
19423 | if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes))) | |
19424 | @@ -392,10 +411,10 @@ static unsigned long load_elf_interp(str | |
2380c486 JR |
19425 | { |
19426 | struct elf_phdr *elf_phdata; | |
19427 | struct elf_phdr *eppnt; | |
19428 | - unsigned long load_addr = 0; | |
19429 | + unsigned long load_addr = 0, pax_task_size = TASK_SIZE; | |
19430 | int load_addr_set = 0; | |
19431 | unsigned long last_bss = 0, elf_bss = 0; | |
19432 | - unsigned long error = ~0UL; | |
19433 | + unsigned long error = -EINVAL; | |
19434 | unsigned long total_size; | |
19435 | int retval, i, size; | |
19436 | ||
de855c5d | 19437 | @@ -441,6 +460,11 @@ static unsigned long load_elf_interp(str |
2380c486 JR |
19438 | goto out_close; |
19439 | } | |
19440 | ||
19441 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19442 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) | |
19443 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
19444 | +#endif | |
19445 | + | |
19446 | eppnt = elf_phdata; | |
19447 | for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) { | |
19448 | if (eppnt->p_type == PT_LOAD) { | |
de855c5d | 19449 | @@ -484,8 +508,8 @@ static unsigned long load_elf_interp(str |
2380c486 JR |
19450 | k = load_addr + eppnt->p_vaddr; |
19451 | if (BAD_ADDR(k) || | |
19452 | eppnt->p_filesz > eppnt->p_memsz || | |
19453 | - eppnt->p_memsz > TASK_SIZE || | |
19454 | - TASK_SIZE - eppnt->p_memsz < k) { | |
19455 | + eppnt->p_memsz > pax_task_size || | |
19456 | + pax_task_size - eppnt->p_memsz < k) { | |
19457 | error = -ENOMEM; | |
19458 | goto out_close; | |
19459 | } | |
de855c5d | 19460 | @@ -539,6 +563,177 @@ out: |
2380c486 JR |
19461 | return error; |
19462 | } | |
19463 | ||
19464 | +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE) | |
19465 | +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata) | |
19466 | +{ | |
19467 | + unsigned long pax_flags = 0UL; | |
19468 | + | |
19469 | +#ifdef CONFIG_PAX_PAGEEXEC | |
19470 | + if (elf_phdata->p_flags & PF_PAGEEXEC) | |
19471 | + pax_flags |= MF_PAX_PAGEEXEC; | |
19472 | +#endif | |
19473 | + | |
19474 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19475 | + if (elf_phdata->p_flags & PF_SEGMEXEC) | |
19476 | + pax_flags |= MF_PAX_SEGMEXEC; | |
19477 | +#endif | |
19478 | + | |
19479 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC) | |
19480 | + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
19481 | + if (nx_enabled) | |
19482 | + pax_flags &= ~MF_PAX_SEGMEXEC; | |
19483 | + else | |
19484 | + pax_flags &= ~MF_PAX_PAGEEXEC; | |
19485 | + } | |
19486 | +#endif | |
19487 | + | |
19488 | +#ifdef CONFIG_PAX_EMUTRAMP | |
19489 | + if (elf_phdata->p_flags & PF_EMUTRAMP) | |
19490 | + pax_flags |= MF_PAX_EMUTRAMP; | |
19491 | +#endif | |
19492 | + | |
19493 | +#ifdef CONFIG_PAX_MPROTECT | |
19494 | + if (elf_phdata->p_flags & PF_MPROTECT) | |
19495 | + pax_flags |= MF_PAX_MPROTECT; | |
19496 | +#endif | |
19497 | + | |
19498 | +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK) | |
19499 | + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP)) | |
19500 | + pax_flags |= MF_PAX_RANDMMAP; | |
19501 | +#endif | |
19502 | + | |
19503 | + return pax_flags; | |
19504 | +} | |
19505 | +#endif | |
19506 | + | |
19507 | +#ifdef CONFIG_PAX_PT_PAX_FLAGS | |
19508 | +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata) | |
19509 | +{ | |
19510 | + unsigned long pax_flags = 0UL; | |
19511 | + | |
19512 | +#ifdef CONFIG_PAX_PAGEEXEC | |
19513 | + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC)) | |
19514 | + pax_flags |= MF_PAX_PAGEEXEC; | |
19515 | +#endif | |
19516 | + | |
19517 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19518 | + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC)) | |
19519 | + pax_flags |= MF_PAX_SEGMEXEC; | |
19520 | +#endif | |
19521 | + | |
19522 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC) | |
19523 | + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
19524 | + if (nx_enabled) | |
19525 | + pax_flags &= ~MF_PAX_SEGMEXEC; | |
19526 | + else | |
19527 | + pax_flags &= ~MF_PAX_PAGEEXEC; | |
19528 | + } | |
19529 | +#endif | |
19530 | + | |
19531 | +#ifdef CONFIG_PAX_EMUTRAMP | |
19532 | + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP)) | |
19533 | + pax_flags |= MF_PAX_EMUTRAMP; | |
19534 | +#endif | |
19535 | + | |
19536 | +#ifdef CONFIG_PAX_MPROTECT | |
19537 | + if (!(elf_phdata->p_flags & PF_NOMPROTECT)) | |
19538 | + pax_flags |= MF_PAX_MPROTECT; | |
19539 | +#endif | |
19540 | + | |
19541 | +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK) | |
19542 | + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP)) | |
19543 | + pax_flags |= MF_PAX_RANDMMAP; | |
19544 | +#endif | |
19545 | + | |
19546 | + return pax_flags; | |
19547 | +} | |
19548 | +#endif | |
19549 | + | |
19550 | +#ifdef CONFIG_PAX_EI_PAX | |
19551 | +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex) | |
19552 | +{ | |
19553 | + unsigned long pax_flags = 0UL; | |
19554 | + | |
19555 | +#ifdef CONFIG_PAX_PAGEEXEC | |
19556 | + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC)) | |
19557 | + pax_flags |= MF_PAX_PAGEEXEC; | |
19558 | +#endif | |
19559 | + | |
19560 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19561 | + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC)) | |
19562 | + pax_flags |= MF_PAX_SEGMEXEC; | |
19563 | +#endif | |
19564 | + | |
19565 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC) | |
19566 | + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
19567 | + if (nx_enabled) | |
19568 | + pax_flags &= ~MF_PAX_SEGMEXEC; | |
19569 | + else | |
19570 | + pax_flags &= ~MF_PAX_PAGEEXEC; | |
19571 | + } | |
19572 | +#endif | |
19573 | + | |
19574 | +#ifdef CONFIG_PAX_EMUTRAMP | |
19575 | + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP)) | |
19576 | + pax_flags |= MF_PAX_EMUTRAMP; | |
19577 | +#endif | |
19578 | + | |
19579 | +#ifdef CONFIG_PAX_MPROTECT | |
19580 | + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT)) | |
19581 | + pax_flags |= MF_PAX_MPROTECT; | |
19582 | +#endif | |
19583 | + | |
19584 | +#ifdef CONFIG_PAX_ASLR | |
19585 | + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP)) | |
19586 | + pax_flags |= MF_PAX_RANDMMAP; | |
19587 | +#endif | |
19588 | + | |
19589 | + return pax_flags; | |
19590 | +} | |
19591 | +#endif | |
19592 | + | |
19593 | +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) | |
19594 | +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata) | |
19595 | +{ | |
19596 | + unsigned long pax_flags = 0UL; | |
19597 | + | |
19598 | +#ifdef CONFIG_PAX_PT_PAX_FLAGS | |
19599 | + unsigned long i; | |
19600 | +#endif | |
19601 | + | |
19602 | +#ifdef CONFIG_PAX_EI_PAX | |
19603 | + pax_flags = pax_parse_ei_pax(elf_ex); | |
19604 | +#endif | |
19605 | + | |
19606 | +#ifdef CONFIG_PAX_PT_PAX_FLAGS | |
19607 | + for (i = 0UL; i < elf_ex->e_phnum; i++) | |
19608 | + if (elf_phdata[i].p_type == PT_PAX_FLAGS) { | |
19609 | + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) || | |
19610 | + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) || | |
19611 | + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) || | |
19612 | + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) || | |
19613 | + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP))) | |
19614 | + return -EINVAL; | |
19615 | + | |
19616 | +#ifdef CONFIG_PAX_SOFTMODE | |
19617 | + if (pax_softmode) | |
19618 | + pax_flags = pax_parse_softmode(&elf_phdata[i]); | |
19619 | + else | |
19620 | +#endif | |
19621 | + | |
19622 | + pax_flags = pax_parse_hardmode(&elf_phdata[i]); | |
19623 | + break; | |
19624 | + } | |
19625 | +#endif | |
19626 | + | |
19627 | + if (0 > pax_check_flags(&pax_flags)) | |
19628 | + return -EINVAL; | |
19629 | + | |
19630 | + current->mm->pax_flags = pax_flags; | |
19631 | + return 0; | |
19632 | +} | |
19633 | +#endif | |
19634 | + | |
19635 | /* | |
19636 | * These are the functions used to load ELF style executables and shared | |
19637 | * libraries. There is no binary dependent code anywhere else. | |
de855c5d | 19638 | @@ -555,6 +750,11 @@ static unsigned long randomize_stack_top |
2380c486 JR |
19639 | { |
19640 | unsigned int random_variable = 0; | |
19641 | ||
19642 | +#ifdef CONFIG_PAX_RANDUSTACK | |
19643 | + if (randomize_va_space) | |
19644 | + return stack_top - current->mm->delta_stack; | |
19645 | +#endif | |
19646 | + | |
19647 | if ((current->flags & PF_RANDOMIZE) && | |
19648 | !(current->personality & ADDR_NO_RANDOMIZE)) { | |
19649 | random_variable = get_random_int() & STACK_RND_MASK; | |
de855c5d | 19650 | @@ -573,7 +773,7 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19651 | unsigned long load_addr = 0, load_bias = 0; |
19652 | int load_addr_set = 0; | |
19653 | char * elf_interpreter = NULL; | |
19654 | - unsigned long error; | |
19655 | + unsigned long error = 0; | |
19656 | struct elf_phdr *elf_ppnt, *elf_phdata; | |
19657 | unsigned long elf_bss, elf_brk; | |
19658 | int elf_exec_fileno; | |
de855c5d | 19659 | @@ -584,11 +784,11 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19660 | unsigned long start_code, end_code, start_data, end_data; |
19661 | unsigned long reloc_func_desc = 0; | |
19662 | int executable_stack = EXSTACK_DEFAULT; | |
19663 | - unsigned long def_flags = 0; | |
19664 | struct { | |
19665 | struct elfhdr elf_ex; | |
19666 | struct elfhdr interp_elf_ex; | |
19667 | } *loc; | |
19668 | + unsigned long pax_task_size = TASK_SIZE; | |
19669 | ||
19670 | loc = kmalloc(sizeof(*loc), GFP_KERNEL); | |
19671 | if (!loc) { | |
de855c5d | 19672 | @@ -756,11 +956,80 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19673 | |
19674 | /* OK, This is the point of no return */ | |
19675 | current->flags &= ~PF_FORKNOEXEC; | |
19676 | - current->mm->def_flags = def_flags; | |
19677 | + | |
19678 | +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
19679 | + current->mm->pax_flags = 0UL; | |
19680 | +#endif | |
19681 | + | |
19682 | +#ifdef CONFIG_PAX_DLRESOLVE | |
19683 | + current->mm->call_dl_resolve = 0UL; | |
19684 | +#endif | |
19685 | + | |
19686 | +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT) | |
19687 | + current->mm->call_syscall = 0UL; | |
19688 | +#endif | |
19689 | + | |
19690 | +#ifdef CONFIG_PAX_ASLR | |
19691 | + current->mm->delta_mmap = 0UL; | |
19692 | + current->mm->delta_stack = 0UL; | |
19693 | +#endif | |
19694 | + | |
19695 | + current->mm->def_flags = 0; | |
19696 | + | |
19697 | +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) | |
19698 | + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) { | |
19699 | + send_sig(SIGKILL, current, 0); | |
19700 | + goto out_free_dentry; | |
19701 | + } | |
19702 | +#endif | |
19703 | + | |
19704 | +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS | |
19705 | + pax_set_initial_flags(bprm); | |
19706 | +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS) | |
19707 | + if (pax_set_initial_flags_func) | |
19708 | + (pax_set_initial_flags_func)(bprm); | |
19709 | +#endif | |
19710 | + | |
19711 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
19712 | + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) { | |
19713 | + current->mm->context.user_cs_limit = PAGE_SIZE; | |
19714 | + current->mm->def_flags |= VM_PAGEEXEC; | |
19715 | + } | |
19716 | +#endif | |
19717 | + | |
19718 | +#ifdef CONFIG_PAX_SEGMEXEC | |
19719 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) { | |
19720 | + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE; | |
19721 | + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE; | |
19722 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
19723 | + } | |
19724 | +#endif | |
19725 | + | |
19726 | +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC) | |
19727 | + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
19728 | + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu()); | |
19729 | + put_cpu_no_resched(); | |
19730 | + } | |
19731 | +#endif | |
19732 | + | |
19733 | +#ifdef CONFIG_PAX_ASLR | |
19734 | + if (current->mm->pax_flags & MF_PAX_RANDMMAP) { | |
19735 | + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT; | |
19736 | + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT; | |
19737 | + } | |
19738 | +#endif | |
19739 | ||
19740 | /* Do this immediately, since STACK_TOP as used in setup_arg_pages | |
19741 | may depend on the personality. */ | |
19742 | SET_PERSONALITY(loc->elf_ex); | |
19743 | + | |
19744 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
19745 | + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
19746 | + executable_stack = EXSTACK_DISABLE_X; | |
19747 | + current->personality &= ~READ_IMPLIES_EXEC; | |
19748 | + } else | |
19749 | +#endif | |
19750 | + | |
19751 | if (elf_read_implies_exec(loc->elf_ex, executable_stack)) | |
19752 | current->personality |= READ_IMPLIES_EXEC; | |
19753 | ||
de855c5d | 19754 | @@ -841,6 +1110,20 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19755 | #else |
19756 | load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr); | |
19757 | #endif | |
19758 | + | |
19759 | +#ifdef CONFIG_PAX_RANDMMAP | |
19760 | + /* PaX: randomize base address at the default exe base if requested */ | |
19761 | + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) { | |
19762 | +#ifdef CONFIG_SPARC64 | |
19763 | + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1); | |
19764 | +#else | |
19765 | + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT; | |
19766 | +#endif | |
19767 | + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias); | |
19768 | + elf_flags |= MAP_FIXED; | |
19769 | + } | |
19770 | +#endif | |
19771 | + | |
19772 | } | |
19773 | ||
19774 | error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, | |
de855c5d | 19775 | @@ -873,9 +1156,9 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19776 | * allowed task size. Note that p_filesz must always be |
19777 | * <= p_memsz so it is only necessary to check p_memsz. | |
19778 | */ | |
19779 | - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz || | |
19780 | - elf_ppnt->p_memsz > TASK_SIZE || | |
19781 | - TASK_SIZE - elf_ppnt->p_memsz < k) { | |
19782 | + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz || | |
19783 | + elf_ppnt->p_memsz > pax_task_size || | |
19784 | + pax_task_size - elf_ppnt->p_memsz < k) { | |
19785 | /* set_brk can never work. Avoid overflows. */ | |
19786 | send_sig(SIGKILL, current, 0); | |
19787 | retval = -EINVAL; | |
de855c5d | 19788 | @@ -903,6 +1186,11 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19789 | start_data += load_bias; |
19790 | end_data += load_bias; | |
19791 | ||
19792 | +#ifdef CONFIG_PAX_RANDMMAP | |
19793 | + if (current->mm->pax_flags & MF_PAX_RANDMMAP) | |
19794 | + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4); | |
19795 | +#endif | |
19796 | + | |
19797 | /* Calling set_brk effectively mmaps the pages that we need | |
19798 | * for the bss and break sections. We must do this before | |
19799 | * mapping in the interpreter, to make sure it doesn't wind | |
de855c5d | 19800 | @@ -914,9 +1202,11 @@ static int load_elf_binary(struct linux_ |
2380c486 JR |
19801 | goto out_free_dentry; |
19802 | } | |
19803 | if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) { | |
19804 | - send_sig(SIGSEGV, current, 0); | |
19805 | - retval = -EFAULT; /* Nobody gets to see this, but.. */ | |
19806 | - goto out_free_dentry; | |
19807 | + /* | |
19808 | + * This bss-zeroing can fail if the ELF | |
19809 | + * file specifies odd protections. So | |
19810 | + * we don't check the return value | |
19811 | + */ | |
19812 | } | |
19813 | ||
19814 | if (elf_interpreter) { | |
de855c5d | 19815 | @@ -1153,8 +1443,10 @@ static int dump_seek(struct file *file, |
2380c486 JR |
19816 | unsigned long n = off; |
19817 | if (n > PAGE_SIZE) | |
19818 | n = PAGE_SIZE; | |
19819 | - if (!dump_write(file, buf, n)) | |
19820 | + if (!dump_write(file, buf, n)) { | |
19821 | + free_page((unsigned long)buf); | |
19822 | return 0; | |
19823 | + } | |
19824 | off -= n; | |
19825 | } | |
19826 | free_page((unsigned long)buf); | |
de855c5d | 19827 | @@ -1166,7 +1458,7 @@ static int dump_seek(struct file *file, |
2380c486 JR |
19828 | * Decide what to dump of a segment, part, all or none. |
19829 | */ | |
19830 | static unsigned long vma_dump_size(struct vm_area_struct *vma, | |
19831 | - unsigned long mm_flags) | |
19832 | + unsigned long mm_flags, long signr) | |
19833 | { | |
19834 | #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type)) | |
19835 | ||
de855c5d | 19836 | @@ -1200,7 +1492,7 @@ static unsigned long vma_dump_size(struc |
2380c486 JR |
19837 | if (vma->vm_file == NULL) |
19838 | return 0; | |
19839 | ||
19840 | - if (FILTER(MAPPED_PRIVATE)) | |
19841 | + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE)) | |
19842 | goto whole; | |
19843 | ||
19844 | /* | |
de855c5d | 19845 | @@ -1296,8 +1588,11 @@ static int writenote(struct memelfnote * |
2380c486 JR |
19846 | #undef DUMP_WRITE |
19847 | ||
19848 | #define DUMP_WRITE(addr, nr) \ | |
19849 | + do { \ | |
19850 | + gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \ | |
19851 | if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \ | |
19852 | - goto end_coredump; | |
19853 | + goto end_coredump; \ | |
19854 | + } while (0); | |
19855 | #define DUMP_SEEK(off) \ | |
19856 | if (!dump_seek(file, (off))) \ | |
19857 | goto end_coredump; | |
de855c5d | 19858 | @@ -2002,7 +2297,7 @@ static int elf_core_dump(long signr, str |
2380c486 JR |
19859 | phdr.p_offset = offset; |
19860 | phdr.p_vaddr = vma->vm_start; | |
19861 | phdr.p_paddr = 0; | |
19862 | - phdr.p_filesz = vma_dump_size(vma, mm_flags); | |
19863 | + phdr.p_filesz = vma_dump_size(vma, mm_flags, signr); | |
19864 | phdr.p_memsz = vma->vm_end - vma->vm_start; | |
19865 | offset += phdr.p_filesz; | |
19866 | phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0; | |
de855c5d | 19867 | @@ -2034,7 +2329,7 @@ static int elf_core_dump(long signr, str |
2380c486 JR |
19868 | unsigned long addr; |
19869 | unsigned long end; | |
19870 | ||
19871 | - end = vma->vm_start + vma_dump_size(vma, mm_flags); | |
19872 | + end = vma->vm_start + vma_dump_size(vma, mm_flags, signr); | |
19873 | ||
19874 | for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) { | |
19875 | struct page *page; | |
de855c5d | 19876 | @@ -2054,6 +2349,7 @@ static int elf_core_dump(long signr, str |
2380c486 JR |
19877 | flush_cache_page(tmp_vma, addr, |
19878 | page_to_pfn(page)); | |
19879 | kaddr = kmap(page); | |
19880 | + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1); | |
19881 | if ((size += PAGE_SIZE) > limit || | |
19882 | !dump_write(file, kaddr, | |
19883 | PAGE_SIZE)) { | |
de855c5d | 19884 | @@ -2084,6 +2380,99 @@ out: |
2380c486 JR |
19885 | |
19886 | #endif /* USE_ELF_CORE_DUMP */ | |
19887 | ||
19888 | +#ifdef CONFIG_PAX_MPROTECT | |
19889 | +/* PaX: non-PIC ELF libraries need relocations on their executable segments | |
19890 | + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly | |
19891 | + * we'll remove VM_MAYWRITE for good on RELRO segments. | |
19892 | + * | |
19893 | + * The checks favour ld-linux.so behaviour which operates on a per ELF segment | |
19894 | + * basis because we want to allow the common case and not the special ones. | |
19895 | + */ | |
19896 | +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags) | |
19897 | +{ | |
19898 | + struct elfhdr elf_h; | |
19899 | + struct elf_phdr elf_p; | |
19900 | + unsigned long i; | |
19901 | + unsigned long oldflags; | |
19902 | + bool is_textrel_rw, is_textrel_rx, is_relro; | |
19903 | + | |
19904 | + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT)) | |
19905 | + return; | |
19906 | + | |
19907 | + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ); | |
19908 | + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ; | |
19909 | + | |
19910 | +#ifdef CONFIG_PAX_NOELFRELOCS | |
19911 | + is_textrel_rw = false; | |
19912 | + is_textrel_rx = false; | |
19913 | +#else | |
19914 | + /* possible TEXTREL */ | |
19915 | + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ); | |
19916 | + is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ); | |
19917 | +#endif | |
19918 | + | |
19919 | + /* possible RELRO */ | |
19920 | + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ); | |
19921 | + | |
19922 | + if (!is_textrel_rw && !is_textrel_rx && !is_relro) | |
19923 | + return; | |
19924 | + | |
19925 | + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) || | |
19926 | + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) || | |
19927 | + | |
19928 | +#ifdef CONFIG_PAX_ETEXECRELOCS | |
19929 | + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) || | |
19930 | +#else | |
19931 | + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) || | |
19932 | +#endif | |
19933 | + | |
19934 | + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) || | |
19935 | + !elf_check_arch(&elf_h) || | |
19936 | + elf_h.e_phentsize != sizeof(struct elf_phdr) || | |
19937 | + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr)) | |
19938 | + return; | |
19939 | + | |
19940 | + for (i = 0UL; i < elf_h.e_phnum; i++) { | |
19941 | + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p))) | |
19942 | + return; | |
19943 | + switch (elf_p.p_type) { | |
19944 | + case PT_DYNAMIC: { | |
19945 | + elf_addr_t dyn_offset = 0UL; | |
19946 | + elf_dyn dyn; | |
19947 | + | |
19948 | + if (!is_textrel_rw && !is_textrel_rx) | |
19949 | + continue; | |
19950 | + dyn_offset = elf_p.p_offset; | |
19951 | + i = 0UL; | |
19952 | + do { | |
19953 | + if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn))) | |
19954 | + return; | |
19955 | + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) { | |
19956 | + gr_log_textrel(vma); | |
19957 | + if (is_textrel_rw) | |
19958 | + vma->vm_flags |= VM_MAYWRITE; | |
19959 | + else | |
19960 | + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */ | |
19961 | + vma->vm_flags &= ~VM_MAYWRITE; | |
19962 | + return; | |
19963 | + } | |
19964 | + i++; | |
19965 | + } while (dyn.d_tag != DT_NULL); | |
19966 | + return; | |
19967 | + } | |
19968 | + | |
19969 | + case PT_GNU_RELRO: | |
19970 | + if (!is_relro) | |
19971 | + continue; | |
19972 | + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) { | |
19973 | + vma->vm_flags &= ~VM_MAYWRITE; | |
19974 | + } | |
19975 | + return; | |
19976 | + } | |
19977 | + } | |
19978 | +} | |
19979 | +#endif | |
19980 | + | |
19981 | static int __init init_elf_binfmt(void) | |
19982 | { | |
19983 | return register_binfmt(&elf_format); | |
de855c5d AM |
19984 | diff -urNp linux-2.6.29.6/fs/binfmt_flat.c linux-2.6.29.6/fs/binfmt_flat.c |
19985 | --- linux-2.6.29.6/fs/binfmt_flat.c 2009-07-02 19:41:20.000000000 -0400 | |
19986 | +++ linux-2.6.29.6/fs/binfmt_flat.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
19987 | @@ -554,7 +554,9 @@ static int load_flat_file(struct linux_b |
19988 | realdatastart = (unsigned long) -ENOMEM; | |
19989 | printk("Unable to allocate RAM for process data, errno %d\n", | |
19990 | (int)-realdatastart); | |
19991 | + down_write(¤t->mm->mmap_sem); | |
19992 | do_munmap(current->mm, textpos, text_len); | |
19993 | + up_write(¤t->mm->mmap_sem); | |
19994 | ret = realdatastart; | |
19995 | goto err; | |
19996 | } | |
19997 | @@ -576,8 +578,10 @@ static int load_flat_file(struct linux_b | |
19998 | } | |
19999 | if (result >= (unsigned long)-4096) { | |
20000 | printk("Unable to read data+bss, errno %d\n", (int)-result); | |
20001 | + down_write(¤t->mm->mmap_sem); | |
20002 | do_munmap(current->mm, textpos, text_len); | |
20003 | do_munmap(current->mm, realdatastart, data_len + extra); | |
20004 | + up_write(¤t->mm->mmap_sem); | |
20005 | ret = result; | |
20006 | goto err; | |
20007 | } | |
20008 | @@ -643,8 +647,10 @@ static int load_flat_file(struct linux_b | |
20009 | } | |
20010 | if (result >= (unsigned long)-4096) { | |
20011 | printk("Unable to read code+data+bss, errno %d\n",(int)-result); | |
20012 | + down_write(¤t->mm->mmap_sem); | |
20013 | do_munmap(current->mm, textpos, text_len + data_len + extra + | |
20014 | MAX_SHARED_LIBS * sizeof(unsigned long)); | |
20015 | + up_write(¤t->mm->mmap_sem); | |
20016 | ret = result; | |
20017 | goto err; | |
20018 | } | |
de855c5d AM |
20019 | diff -urNp linux-2.6.29.6/fs/binfmt_misc.c linux-2.6.29.6/fs/binfmt_misc.c |
20020 | --- linux-2.6.29.6/fs/binfmt_misc.c 2009-07-02 19:41:20.000000000 -0400 | |
20021 | +++ linux-2.6.29.6/fs/binfmt_misc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20022 | @@ -693,7 +693,7 @@ static int bm_fill_super(struct super_bl |
20023 | static struct tree_descr bm_files[] = { | |
20024 | [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO}, | |
20025 | [3] = {"register", &bm_register_operations, S_IWUSR}, | |
20026 | - /* last one */ {""} | |
20027 | + /* last one */ {"", NULL, 0} | |
20028 | }; | |
20029 | int err = simple_fill_super(sb, 0x42494e4d, bm_files); | |
20030 | if (!err) | |
de855c5d AM |
20031 | diff -urNp linux-2.6.29.6/fs/bio.c linux-2.6.29.6/fs/bio.c |
20032 | --- linux-2.6.29.6/fs/bio.c 2009-07-02 19:41:20.000000000 -0400 | |
20033 | +++ linux-2.6.29.6/fs/bio.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20034 | @@ -710,7 +710,7 @@ static int __bio_copy_iov(struct bio *bi |
20035 | ||
20036 | while (bv_len && iov_idx < iov_count) { | |
20037 | unsigned int bytes; | |
20038 | - char *iov_addr; | |
20039 | + char __user *iov_addr; | |
20040 | ||
20041 | bytes = min_t(unsigned int, | |
20042 | iov[iov_idx].iov_len - iov_off, bv_len); | |
de855c5d AM |
20043 | diff -urNp linux-2.6.29.6/fs/buffer.c linux-2.6.29.6/fs/buffer.c |
20044 | --- linux-2.6.29.6/fs/buffer.c 2009-07-02 19:41:20.000000000 -0400 | |
20045 | +++ linux-2.6.29.6/fs/buffer.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20046 | @@ -25,6 +25,7 @@ |
20047 | #include <linux/percpu.h> | |
20048 | #include <linux/slab.h> | |
20049 | #include <linux/capability.h> | |
20050 | +#include <linux/security.h> | |
20051 | #include <linux/blkdev.h> | |
20052 | #include <linux/file.h> | |
20053 | #include <linux/quotaops.h> | |
20054 | @@ -2312,6 +2313,7 @@ int generic_cont_expand_simple(struct in | |
20055 | ||
20056 | err = -EFBIG; | |
20057 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; | |
20058 | + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1); | |
20059 | if (limit != RLIM_INFINITY && size > (loff_t)limit) { | |
20060 | send_sig(SIGXFSZ, current, 0); | |
20061 | goto out; | |
de855c5d AM |
20062 | diff -urNp linux-2.6.29.6/fs/cifs/cifs_uniupr.h linux-2.6.29.6/fs/cifs/cifs_uniupr.h |
20063 | --- linux-2.6.29.6/fs/cifs/cifs_uniupr.h 2009-07-02 19:41:20.000000000 -0400 | |
20064 | +++ linux-2.6.29.6/fs/cifs/cifs_uniupr.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20065 | @@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa |
20066 | {0x0490, 0x04cc, UniCaseRangeU0490}, | |
20067 | {0x1e00, 0x1ffc, UniCaseRangeU1e00}, | |
20068 | {0xff40, 0xff5a, UniCaseRangeUff40}, | |
20069 | - {0} | |
20070 | + {0, 0, NULL} | |
20071 | }; | |
20072 | #endif | |
20073 | ||
de855c5d AM |
20074 | diff -urNp linux-2.6.29.6/fs/cifs/link.c linux-2.6.29.6/fs/cifs/link.c |
20075 | --- linux-2.6.29.6/fs/cifs/link.c 2009-07-02 19:41:20.000000000 -0400 | |
20076 | +++ linux-2.6.29.6/fs/cifs/link.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20077 | @@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c |
20078 | ||
20079 | void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie) | |
20080 | { | |
20081 | - char *p = nd_get_link(nd); | |
20082 | + const char *p = nd_get_link(nd); | |
20083 | if (!IS_ERR(p)) | |
20084 | kfree(p); | |
20085 | } | |
de855c5d AM |
20086 | diff -urNp linux-2.6.29.6/fs/compat.c linux-2.6.29.6/fs/compat.c |
20087 | --- linux-2.6.29.6/fs/compat.c 2009-07-02 19:41:20.000000000 -0400 | |
20088 | +++ linux-2.6.29.6/fs/compat.c 2009-07-09 22:13:39.000000000 -0400 | |
20089 | @@ -1338,14 +1338,12 @@ static int compat_copy_strings(int argc, | |
2380c486 JR |
20090 | if (!kmapped_page || kpos != (pos & PAGE_MASK)) { |
20091 | struct page *page; | |
20092 | ||
20093 | -#ifdef CONFIG_STACK_GROWSUP | |
20094 | ret = expand_stack_downwards(bprm->vma, pos); | |
20095 | if (ret < 0) { | |
20096 | /* We've exceed the stack rlimit. */ | |
20097 | ret = -E2BIG; | |
20098 | goto out; | |
20099 | } | |
20100 | -#endif | |
20101 | ret = get_user_pages(current, bprm->mm, pos, | |
20102 | 1, 1, 1, &page, NULL); | |
20103 | if (ret <= 0) { | |
de855c5d | 20104 | @@ -1391,6 +1389,11 @@ int compat_do_execve(char * filename, |
2380c486 JR |
20105 | compat_uptr_t __user *envp, |
20106 | struct pt_regs * regs) | |
20107 | { | |
20108 | +#ifdef CONFIG_GRKERNSEC | |
20109 | + struct file *old_exec_file; | |
20110 | + struct acl_subject_label *old_acl; | |
20111 | + struct rlimit old_rlim[RLIM_NLIMITS]; | |
20112 | +#endif | |
20113 | struct linux_binprm *bprm; | |
20114 | struct file *file; | |
de855c5d AM |
20115 | struct files_struct *displaced; |
20116 | @@ -1431,6 +1434,14 @@ int compat_do_execve(char * filename, | |
2380c486 JR |
20117 | bprm->filename = filename; |
20118 | bprm->interp = filename; | |
20119 | ||
20120 | + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(¤t->cred->user->processes), 1); | |
20121 | + retval = -EAGAIN; | |
20122 | + if (gr_handle_nproc()) | |
20123 | + goto out_file; | |
20124 | + retval = -EACCES; | |
20125 | + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) | |
20126 | + goto out_file; | |
20127 | + | |
20128 | retval = bprm_mm_init(bprm); | |
20129 | if (retval) | |
20130 | goto out_file; | |
de855c5d | 20131 | @@ -1460,9 +1471,40 @@ int compat_do_execve(char * filename, |
2380c486 JR |
20132 | if (retval < 0) |
20133 | goto out; | |
20134 | ||
20135 | + if (!gr_tpe_allow(file)) { | |
20136 | + retval = -EACCES; | |
20137 | + goto out; | |
20138 | + } | |
20139 | + | |
20140 | + if (gr_check_crash_exec(file)) { | |
20141 | + retval = -EACCES; | |
20142 | + goto out; | |
20143 | + } | |
20144 | + | |
20145 | + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt); | |
20146 | + | |
20147 | + gr_handle_exec_args(bprm, (char __user * __user *)argv); | |
20148 | + | |
20149 | +#ifdef CONFIG_GRKERNSEC | |
20150 | + old_acl = current->acl; | |
20151 | + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim)); | |
20152 | + old_exec_file = current->exec_file; | |
20153 | + get_file(file); | |
20154 | + current->exec_file = file; | |
20155 | +#endif | |
20156 | + | |
de855c5d AM |
20157 | + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt, |
20158 | + bprm->unsafe & LSM_UNSAFE_SHARE); | |
2380c486 JR |
20159 | + if (retval < 0) |
20160 | + goto out_fail; | |
20161 | + | |
20162 | retval = search_binary_handler(bprm, regs); | |
20163 | if (retval < 0) | |
20164 | - goto out; | |
20165 | + goto out_fail; | |
20166 | +#ifdef CONFIG_GRKERNSEC | |
20167 | + if (old_exec_file) | |
20168 | + fput(old_exec_file); | |
20169 | +#endif | |
20170 | ||
20171 | /* execve succeeded */ | |
de855c5d AM |
20172 | current->fs->in_exec = 0; |
20173 | @@ -1473,6 +1515,14 @@ int compat_do_execve(char * filename, | |
20174 | put_files_struct(displaced); | |
2380c486 JR |
20175 | return retval; |
20176 | ||
20177 | +out_fail: | |
20178 | +#ifdef CONFIG_GRKERNSEC | |
20179 | + current->acl = old_acl; | |
20180 | + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim)); | |
20181 | + fput(current->exec_file); | |
20182 | + current->exec_file = old_exec_file; | |
20183 | +#endif | |
20184 | + | |
20185 | out: | |
20186 | if (bprm->mm) | |
20187 | mmput(bprm->mm); | |
de855c5d AM |
20188 | diff -urNp linux-2.6.29.6/fs/compat_ioctl.c linux-2.6.29.6/fs/compat_ioctl.c |
20189 | --- linux-2.6.29.6/fs/compat_ioctl.c 2009-07-02 19:41:20.000000000 -0400 | |
20190 | +++ linux-2.6.29.6/fs/compat_ioctl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20191 | @@ -1832,15 +1832,15 @@ struct ioctl_trans { |
20192 | }; | |
20193 | ||
20194 | #define HANDLE_IOCTL(cmd,handler) \ | |
20195 | - { (cmd), (ioctl_trans_handler_t)(handler) }, | |
20196 | + { (cmd), (ioctl_trans_handler_t)(handler), NULL }, | |
20197 | ||
20198 | /* pointer to compatible structure or no argument */ | |
20199 | #define COMPATIBLE_IOCTL(cmd) \ | |
20200 | - { (cmd), do_ioctl32_pointer }, | |
20201 | + { (cmd), do_ioctl32_pointer, NULL }, | |
20202 | ||
20203 | /* argument is an unsigned long integer, not a pointer */ | |
20204 | #define ULONG_IOCTL(cmd) \ | |
20205 | - { (cmd), (ioctl_trans_handler_t)sys_ioctl }, | |
20206 | + { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL }, | |
20207 | ||
20208 | /* ioctl should not be warned about even if it's not implemented. | |
20209 | Valid reasons to use this: | |
de855c5d AM |
20210 | diff -urNp linux-2.6.29.6/fs/debugfs/inode.c linux-2.6.29.6/fs/debugfs/inode.c |
20211 | --- linux-2.6.29.6/fs/debugfs/inode.c 2009-07-02 19:41:20.000000000 -0400 | |
20212 | +++ linux-2.6.29.6/fs/debugfs/inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20213 | @@ -117,7 +117,7 @@ static inline int debugfs_positive(struc |
20214 | ||
20215 | static int debug_fill_super(struct super_block *sb, void *data, int silent) | |
20216 | { | |
20217 | - static struct tree_descr debug_files[] = {{""}}; | |
20218 | + static struct tree_descr debug_files[] = {{"", NULL, 0}}; | |
20219 | ||
20220 | return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); | |
20221 | } | |
de855c5d AM |
20222 | diff -urNp linux-2.6.29.6/fs/exec.c linux-2.6.29.6/fs/exec.c |
20223 | --- linux-2.6.29.6/fs/exec.c 2009-07-02 19:41:20.000000000 -0400 | |
20224 | +++ linux-2.6.29.6/fs/exec.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20225 | @@ -52,12 +52,24 @@ |
20226 | #include <linux/tracehook.h> | |
20227 | #include <linux/kmod.h> | |
20228 | #include <linux/fsnotify.h> | |
20229 | +#include <linux/random.h> | |
20230 | +#include <linux/seq_file.h> | |
20231 | + | |
20232 | +#ifdef CONFIG_PAX_REFCOUNT | |
20233 | +#include <linux/kallsyms.h> | |
20234 | +#include <linux/kdebug.h> | |
20235 | +#endif | |
20236 | ||
20237 | #include <asm/uaccess.h> | |
20238 | #include <asm/mmu_context.h> | |
20239 | #include <asm/tlb.h> | |
20240 | #include "internal.h" | |
20241 | ||
20242 | +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS | |
20243 | +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm); | |
20244 | +EXPORT_SYMBOL(pax_set_initial_flags_func); | |
20245 | +#endif | |
20246 | + | |
20247 | int core_uses_pid; | |
20248 | char core_pattern[CORENAME_MAX_SIZE] = "core"; | |
20249 | int suid_dumpable = 0; | |
20250 | @@ -169,18 +181,10 @@ static struct page *get_arg_page(struct | |
20251 | int write) | |
20252 | { | |
20253 | struct page *page; | |
20254 | - int ret; | |
20255 | ||
20256 | -#ifdef CONFIG_STACK_GROWSUP | |
20257 | - if (write) { | |
20258 | - ret = expand_stack_downwards(bprm->vma, pos); | |
20259 | - if (ret < 0) | |
20260 | - return NULL; | |
20261 | - } | |
20262 | -#endif | |
20263 | - ret = get_user_pages(current, bprm->mm, pos, | |
20264 | - 1, write, 1, &page, NULL); | |
20265 | - if (ret <= 0) | |
20266 | + if (0 > expand_stack_downwards(bprm->vma, pos)) | |
20267 | + return NULL; | |
20268 | + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL)) | |
20269 | return NULL; | |
20270 | ||
20271 | if (write) { | |
20272 | @@ -252,6 +256,11 @@ static int __bprm_mm_init(struct linux_b | |
20273 | vma->vm_end = STACK_TOP_MAX; | |
20274 | vma->vm_start = vma->vm_end - PAGE_SIZE; | |
20275 | vma->vm_flags = VM_STACK_FLAGS; | |
20276 | + | |
20277 | +#ifdef CONFIG_PAX_SEGMEXEC | |
20278 | + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC); | |
20279 | +#endif | |
20280 | + | |
20281 | vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
20282 | err = insert_vm_struct(mm, vma); | |
20283 | if (err) | |
20284 | @@ -260,6 +269,12 @@ static int __bprm_mm_init(struct linux_b | |
20285 | mm->stack_vm = mm->total_vm = 1; | |
20286 | up_write(&mm->mmap_sem); | |
20287 | bprm->p = vma->vm_end - sizeof(void *); | |
20288 | + | |
20289 | +#ifdef CONFIG_PAX_RANDUSTACK | |
20290 | + if (randomize_va_space) | |
20291 | + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK; | |
20292 | +#endif | |
20293 | + | |
20294 | return 0; | |
20295 | err: | |
20296 | up_write(&mm->mmap_sem); | |
20297 | @@ -520,6 +535,10 @@ static int shift_arg_pages(struct vm_are | |
20298 | if (vma != find_vma(mm, new_start)) | |
20299 | return -EFAULT; | |
20300 | ||
20301 | +#ifdef CONFIG_PAX_SEGMEXEC | |
20302 | + BUG_ON(pax_find_mirror_vma(vma)); | |
20303 | +#endif | |
20304 | + | |
20305 | /* | |
20306 | * cover the whole range: [new_start, old_end) | |
20307 | */ | |
20308 | @@ -608,6 +627,14 @@ int setup_arg_pages(struct linux_binprm | |
20309 | bprm->exec -= stack_shift; | |
20310 | ||
20311 | down_write(&mm->mmap_sem); | |
20312 | + | |
20313 | + /* Move stack pages down in memory. */ | |
20314 | + if (stack_shift) { | |
20315 | + ret = shift_arg_pages(vma, stack_shift); | |
20316 | + if (ret) | |
20317 | + goto out_unlock; | |
20318 | + } | |
20319 | + | |
20320 | vm_flags = VM_STACK_FLAGS; | |
20321 | ||
20322 | /* | |
20323 | @@ -621,21 +648,24 @@ int setup_arg_pages(struct linux_binprm | |
20324 | vm_flags &= ~VM_EXEC; | |
20325 | vm_flags |= mm->def_flags; | |
20326 | ||
20327 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
20328 | + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
20329 | + vm_flags &= ~VM_EXEC; | |
20330 | + | |
20331 | +#ifdef CONFIG_PAX_MPROTECT | |
20332 | + if (mm->pax_flags & MF_PAX_MPROTECT) | |
20333 | + vm_flags &= ~VM_MAYEXEC; | |
20334 | +#endif | |
20335 | + | |
20336 | + } | |
20337 | +#endif | |
20338 | + | |
20339 | ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end, | |
20340 | vm_flags); | |
20341 | if (ret) | |
20342 | goto out_unlock; | |
20343 | BUG_ON(prev != vma); | |
20344 | ||
20345 | - /* Move stack pages down in memory. */ | |
20346 | - if (stack_shift) { | |
20347 | - ret = shift_arg_pages(vma, stack_shift); | |
20348 | - if (ret) { | |
20349 | - up_write(&mm->mmap_sem); | |
20350 | - return ret; | |
20351 | - } | |
20352 | - } | |
20353 | - | |
20354 | #ifdef CONFIG_STACK_GROWSUP | |
20355 | stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE; | |
20356 | #else | |
20357 | @@ -647,7 +677,7 @@ int setup_arg_pages(struct linux_binprm | |
20358 | ||
20359 | out_unlock: | |
20360 | up_write(&mm->mmap_sem); | |
20361 | - return 0; | |
20362 | + return ret; | |
20363 | } | |
20364 | EXPORT_SYMBOL(setup_arg_pages); | |
20365 | ||
de855c5d AM |
20366 | @@ -1066,7 +1096,7 @@ int check_unsafe_exec(struct linux_binpr |
20367 | } | |
20368 | rcu_read_unlock(); | |
20369 | ||
20370 | - if (p->fs->users > n_fs) { | |
20371 | + if (atomic_read(&p->fs->users) > n_fs) { | |
20372 | bprm->unsafe |= LSM_UNSAFE_SHARE; | |
20373 | } else { | |
20374 | res = -EAGAIN; | |
20375 | @@ -1270,6 +1300,11 @@ int do_execve(char * filename, | |
2380c486 JR |
20376 | char __user *__user *envp, |
20377 | struct pt_regs * regs) | |
20378 | { | |
20379 | +#ifdef CONFIG_GRKERNSEC | |
20380 | + struct file *old_exec_file; | |
20381 | + struct acl_subject_label *old_acl; | |
20382 | + struct rlimit old_rlim[RLIM_NLIMITS]; | |
20383 | +#endif | |
20384 | struct linux_binprm *bprm; | |
20385 | struct file *file; | |
20386 | struct files_struct *displaced; | |
de855c5d AM |
20387 | @@ -1310,6 +1345,18 @@ int do_execve(char * filename, |
20388 | bprm->filename = filename; | |
20389 | bprm->interp = filename; | |
2380c486 JR |
20390 | |
20391 | + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(¤t->cred->user->processes), 1); | |
20392 | + | |
20393 | + if (gr_handle_nproc()) { | |
de855c5d AM |
20394 | + retval = -EAGAIN; |
20395 | + goto out_file; | |
2380c486 JR |
20396 | + } |
20397 | + | |
20398 | + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) { | |
de855c5d AM |
20399 | + retval = -EACCES; |
20400 | + goto out_file; | |
2380c486 JR |
20401 | + } |
20402 | + | |
de855c5d AM |
20403 | retval = bprm_mm_init(bprm); |
20404 | if (retval) | |
20405 | goto out_file; | |
20406 | @@ -1339,10 +1386,41 @@ int do_execve(char * filename, | |
2380c486 JR |
20407 | if (retval < 0) |
20408 | goto out; | |
20409 | ||
20410 | + if (!gr_tpe_allow(file)) { | |
20411 | + retval = -EACCES; | |
20412 | + goto out; | |
20413 | + } | |
20414 | + | |
20415 | + if (gr_check_crash_exec(file)) { | |
20416 | + retval = -EACCES; | |
20417 | + goto out; | |
20418 | + } | |
20419 | + | |
20420 | + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt); | |
20421 | + | |
20422 | + gr_handle_exec_args(bprm, argv); | |
20423 | + | |
20424 | +#ifdef CONFIG_GRKERNSEC | |
20425 | + old_acl = current->acl; | |
20426 | + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim)); | |
20427 | + old_exec_file = current->exec_file; | |
20428 | + get_file(file); | |
20429 | + current->exec_file = file; | |
20430 | +#endif | |
20431 | + | |
de855c5d AM |
20432 | + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt, |
20433 | + bprm->unsafe & LSM_UNSAFE_SHARE); | |
2380c486 JR |
20434 | + if (retval < 0) |
20435 | + goto out_fail; | |
20436 | + | |
20437 | current->flags &= ~PF_KTHREAD; | |
20438 | retval = search_binary_handler(bprm,regs); | |
20439 | if (retval < 0) | |
20440 | - goto out; | |
20441 | + goto out_fail; | |
20442 | +#ifdef CONFIG_GRKERNSEC | |
20443 | + if (old_exec_file) | |
20444 | + fput(old_exec_file); | |
20445 | +#endif | |
20446 | ||
20447 | /* execve succeeded */ | |
de855c5d AM |
20448 | current->fs->in_exec = 0; |
20449 | @@ -1353,6 +1431,14 @@ int do_execve(char * filename, | |
2380c486 JR |
20450 | put_files_struct(displaced); |
20451 | return retval; | |
20452 | ||
20453 | +out_fail: | |
20454 | +#ifdef CONFIG_GRKERNSEC | |
20455 | + current->acl = old_acl; | |
20456 | + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim)); | |
20457 | + fput(current->exec_file); | |
20458 | + current->exec_file = old_exec_file; | |
20459 | +#endif | |
20460 | + | |
20461 | out: | |
20462 | if (bprm->mm) | |
20463 | mmput (bprm->mm); | |
de855c5d | 20464 | @@ -1520,6 +1606,164 @@ out: |
2380c486 JR |
20465 | return ispipe; |
20466 | } | |
20467 | ||
20468 | +int pax_check_flags(unsigned long *flags) | |
20469 | +{ | |
20470 | + int retval = 0; | |
20471 | + | |
20472 | +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC) | |
20473 | + if (*flags & MF_PAX_SEGMEXEC) | |
20474 | + { | |
20475 | + *flags &= ~MF_PAX_SEGMEXEC; | |
20476 | + retval = -EINVAL; | |
20477 | + } | |
20478 | +#endif | |
20479 | + | |
20480 | + if ((*flags & MF_PAX_PAGEEXEC) | |
20481 | + | |
20482 | +#ifdef CONFIG_PAX_PAGEEXEC | |
20483 | + && (*flags & MF_PAX_SEGMEXEC) | |
20484 | +#endif | |
20485 | + | |
20486 | + ) | |
20487 | + { | |
20488 | + *flags &= ~MF_PAX_PAGEEXEC; | |
20489 | + retval = -EINVAL; | |
20490 | + } | |
20491 | + | |
20492 | + if ((*flags & MF_PAX_MPROTECT) | |
20493 | + | |
20494 | +#ifdef CONFIG_PAX_MPROTECT | |
20495 | + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) | |
20496 | +#endif | |
20497 | + | |
20498 | + ) | |
20499 | + { | |
20500 | + *flags &= ~MF_PAX_MPROTECT; | |
20501 | + retval = -EINVAL; | |
20502 | + } | |
20503 | + | |
20504 | + if ((*flags & MF_PAX_EMUTRAMP) | |
20505 | + | |
20506 | +#ifdef CONFIG_PAX_EMUTRAMP | |
20507 | + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) | |
20508 | +#endif | |
20509 | + | |
20510 | + ) | |
20511 | + { | |
20512 | + *flags &= ~MF_PAX_EMUTRAMP; | |
20513 | + retval = -EINVAL; | |
20514 | + } | |
20515 | + | |
20516 | + return retval; | |
20517 | +} | |
20518 | + | |
20519 | +EXPORT_SYMBOL(pax_check_flags); | |
20520 | + | |
20521 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
20522 | +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp) | |
20523 | +{ | |
20524 | + struct task_struct *tsk = current; | |
20525 | + struct mm_struct *mm = current->mm; | |
20526 | + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL); | |
20527 | + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL); | |
20528 | + char *path_exec = NULL; | |
20529 | + char *path_fault = NULL; | |
20530 | + unsigned long start = 0UL, end = 0UL, offset = 0UL; | |
20531 | + | |
20532 | + if (buffer_exec && buffer_fault) { | |
20533 | + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL; | |
20534 | + | |
20535 | + down_read(&mm->mmap_sem); | |
20536 | + vma = mm->mmap; | |
20537 | + while (vma && (!vma_exec || !vma_fault)) { | |
20538 | + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) | |
20539 | + vma_exec = vma; | |
20540 | + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end) | |
20541 | + vma_fault = vma; | |
20542 | + vma = vma->vm_next; | |
20543 | + } | |
20544 | + if (vma_exec) { | |
20545 | + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE); | |
20546 | + if (IS_ERR(path_exec)) | |
20547 | + path_exec = "<path too long>"; | |
20548 | + else { | |
de855c5d AM |
20549 | + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\"); |
20550 | + if (path_exec) { | |
20551 | + *path_exec = 0; | |
20552 | + path_exec = buffer_exec; | |
20553 | + } else | |
20554 | + path_exec = "<path too long>"; | |
2380c486 JR |
20555 | + } |
20556 | + } | |
20557 | + if (vma_fault) { | |
20558 | + start = vma_fault->vm_start; | |
20559 | + end = vma_fault->vm_end; | |
20560 | + offset = vma_fault->vm_pgoff << PAGE_SHIFT; | |
20561 | + if (vma_fault->vm_file) { | |
20562 | + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE); | |
20563 | + if (IS_ERR(path_fault)) | |
20564 | + path_fault = "<path too long>"; | |
20565 | + else { | |
de855c5d AM |
20566 | + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\"); |
20567 | + if (path_fault) { | |
20568 | + *path_fault = 0; | |
20569 | + path_fault = buffer_fault; | |
20570 | + } else | |
20571 | + path_fault = "<path too long>"; | |
2380c486 JR |
20572 | + } |
20573 | + } else | |
20574 | + path_fault = "<anonymous mapping>"; | |
20575 | + } | |
20576 | + up_read(&mm->mmap_sem); | |
20577 | + } | |
20578 | + if (tsk->signal->curr_ip) | |
20579 | + printk(KERN_ERR "PAX: From %u.%u.%u.%u: execution attempt in: %s, %08lx-%08lx %08lx\n", NIPQUAD(tsk->signal->curr_ip), path_fault, start, end, offset); | |
20580 | + else | |
20581 | + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset); | |
20582 | + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, " | |
20583 | + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk), | |
20584 | + task_uid(tsk), task_euid(tsk), pc, sp); | |
20585 | + free_page((unsigned long)buffer_exec); | |
20586 | + free_page((unsigned long)buffer_fault); | |
20587 | + pax_report_insns(pc, sp); | |
20588 | + do_coredump(SIGKILL, SIGKILL, regs); | |
20589 | +} | |
20590 | +#endif | |
20591 | + | |
20592 | +#ifdef CONFIG_PAX_REFCOUNT | |
20593 | +void pax_report_refcount_overflow(struct pt_regs *regs) | |
20594 | +{ | |
20595 | + if (current->signal->curr_ip) | |
20596 | + printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", | |
20597 | + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current_uid(), current_euid()); | |
20598 | + else | |
20599 | + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", | |
20600 | + current->comm, task_pid_nr(current), current_uid(), current_euid()); | |
20601 | + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs)); | |
20602 | + show_registers(regs); | |
20603 | + force_sig_specific(SIGKILL, current); | |
20604 | +} | |
20605 | +#endif | |
de855c5d AM |
20606 | + |
20607 | +#ifdef CONFIG_PAX_USERCOPY | |
20608 | +void pax_report_leak_to_user(const void *ptr, unsigned long len) | |
20609 | +{ | |
20610 | + if (current->signal->curr_ip) | |
20611 | + printk(KERN_ERR "PAX: From %u.%u.%u.%u: kernel memory leak attempt detected from %p (%lu bytes)\n", NIPQUAD(current->signal->curr_ip), ptr, len); | |
20612 | + else | |
20613 | + printk(KERN_ERR "PAX: kernel memory leak attempt detected from %p (%lu bytes)\n", ptr, len); | |
20614 | + dump_stack(); | |
20615 | + do_group_exit(SIGKILL); | |
20616 | +} | |
20617 | + | |
20618 | +void pax_report_overflow_from_user(const void *ptr, unsigned long len) | |
20619 | +{ | |
20620 | + printk(KERN_ERR "PAX: kernel memory overflow attempt detected to %p (%lu bytes)\n", ptr, len); | |
20621 | + dump_stack(); | |
20622 | + do_group_exit(SIGKILL); | |
20623 | +} | |
20624 | +#endif | |
2380c486 JR |
20625 | + |
20626 | static int zap_process(struct task_struct *start) | |
20627 | { | |
20628 | struct task_struct *t; | |
de855c5d | 20629 | @@ -1779,6 +2023,10 @@ void do_coredump(long signr, int exit_co |
2380c486 JR |
20630 | */ |
20631 | clear_thread_flag(TIF_SIGPENDING); | |
20632 | ||
20633 | + if (signr == SIGKILL || signr == SIGILL) | |
20634 | + gr_handle_brute_attach(current); | |
20635 | + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1); | |
20636 | + | |
20637 | /* | |
20638 | * lock_kernel() because format_corename() is controlled by sysctl, which | |
20639 | * uses lock_kernel() | |
de855c5d AM |
20640 | diff -urNp linux-2.6.29.6/fs/ext2/balloc.c linux-2.6.29.6/fs/ext2/balloc.c |
20641 | --- linux-2.6.29.6/fs/ext2/balloc.c 2009-07-02 19:41:20.000000000 -0400 | |
20642 | +++ linux-2.6.29.6/fs/ext2/balloc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20643 | @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e |
20644 | ||
20645 | free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter); | |
20646 | root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count); | |
20647 | - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) && | |
20648 | + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) && | |
20649 | sbi->s_resuid != current_fsuid() && | |
20650 | (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) { | |
20651 | return 0; | |
de855c5d AM |
20652 | diff -urNp linux-2.6.29.6/fs/ext3/balloc.c linux-2.6.29.6/fs/ext3/balloc.c |
20653 | --- linux-2.6.29.6/fs/ext3/balloc.c 2009-07-02 19:41:20.000000000 -0400 | |
20654 | +++ linux-2.6.29.6/fs/ext3/balloc.c 2009-07-09 22:13:39.000000000 -0400 | |
20655 | @@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e | |
2380c486 | 20656 | |
de855c5d AM |
20657 | free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter); |
20658 | root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count); | |
20659 | - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) && | |
20660 | + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) && | |
20661 | sbi->s_resuid != current_fsuid() && | |
20662 | (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) { | |
20663 | return 0; | |
20664 | diff -urNp linux-2.6.29.6/fs/ext3/namei.c linux-2.6.29.6/fs/ext3/namei.c | |
20665 | --- linux-2.6.29.6/fs/ext3/namei.c 2009-07-02 19:41:20.000000000 -0400 | |
20666 | +++ linux-2.6.29.6/fs/ext3/namei.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20667 | @@ -1159,7 +1159,7 @@ static struct ext3_dir_entry_2 *do_split |
20668 | char *data1 = (*bh)->b_data, *data2; | |
20669 | unsigned split, move, size; | |
20670 | struct ext3_dir_entry_2 *de = NULL, *de2; | |
20671 | - int err = 0, i; | |
20672 | + int i, err = 0; | |
20673 | ||
20674 | bh2 = ext3_append (handle, dir, &newblock, &err); | |
20675 | if (!(bh2)) { | |
de855c5d AM |
20676 | diff -urNp linux-2.6.29.6/fs/ext3/xattr.c linux-2.6.29.6/fs/ext3/xattr.c |
20677 | --- linux-2.6.29.6/fs/ext3/xattr.c 2009-07-02 19:41:20.000000000 -0400 | |
20678 | +++ linux-2.6.29.6/fs/ext3/xattr.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20679 | @@ -89,8 +89,8 @@ |
20680 | printk("\n"); \ | |
20681 | } while (0) | |
20682 | #else | |
20683 | -# define ea_idebug(f...) | |
20684 | -# define ea_bdebug(f...) | |
20685 | +# define ea_idebug(f...) do {} while (0) | |
20686 | +# define ea_bdebug(f...) do {} while (0) | |
20687 | #endif | |
20688 | ||
20689 | static void ext3_xattr_cache_insert(struct buffer_head *); | |
de855c5d AM |
20690 | diff -urNp linux-2.6.29.6/fs/ext4/balloc.c linux-2.6.29.6/fs/ext4/balloc.c |
20691 | --- linux-2.6.29.6/fs/ext4/balloc.c 2009-07-02 19:41:20.000000000 -0400 | |
20692 | +++ linux-2.6.29.6/fs/ext4/balloc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20693 | @@ -577,7 +577,7 @@ int ext4_has_free_blocks(struct ext4_sb_ |
20694 | /* Hm, nope. Are (enough) root reserved blocks available? */ | |
20695 | if (sbi->s_resuid == current_fsuid() || | |
20696 | ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) || | |
20697 | - capable(CAP_SYS_RESOURCE)) { | |
20698 | + capable_nolog(CAP_SYS_RESOURCE)) { | |
20699 | if (free_blocks >= (nblocks + dirty_blocks)) | |
20700 | return 1; | |
20701 | } | |
de855c5d AM |
20702 | diff -urNp linux-2.6.29.6/fs/ext4/namei.c linux-2.6.29.6/fs/ext4/namei.c |
20703 | --- linux-2.6.29.6/fs/ext4/namei.c 2009-07-02 19:41:20.000000000 -0400 | |
20704 | +++ linux-2.6.29.6/fs/ext4/namei.c 2009-07-09 22:13:39.000000000 -0400 | |
20705 | @@ -1177,7 +1177,7 @@ static struct ext4_dir_entry_2 *do_split | |
2380c486 JR |
20706 | char *data1 = (*bh)->b_data, *data2; |
20707 | unsigned split, move, size; | |
20708 | struct ext4_dir_entry_2 *de = NULL, *de2; | |
20709 | - int err = 0, i; | |
20710 | + int i, err = 0; | |
20711 | ||
20712 | bh2 = ext4_append (handle, dir, &newblock, &err); | |
20713 | if (!(bh2)) { | |
de855c5d AM |
20714 | diff -urNp linux-2.6.29.6/fs/fcntl.c linux-2.6.29.6/fs/fcntl.c |
20715 | --- linux-2.6.29.6/fs/fcntl.c 2009-07-02 19:41:20.000000000 -0400 | |
20716 | +++ linux-2.6.29.6/fs/fcntl.c 2009-07-09 22:13:39.000000000 -0400 | |
20717 | @@ -269,6 +269,7 @@ static long do_fcntl(int fd, unsigned in | |
2380c486 JR |
20718 | switch (cmd) { |
20719 | case F_DUPFD: | |
20720 | case F_DUPFD_CLOEXEC: | |
20721 | + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0); | |
20722 | if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | |
20723 | break; | |
20724 | err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0); | |
de855c5d | 20725 | @@ -419,7 +420,8 @@ static inline int sigio_perm(struct task |
2380c486 JR |
20726 | ret = ((fown->euid == 0 || |
20727 | fown->euid == cred->suid || fown->euid == cred->uid || | |
20728 | fown->uid == cred->suid || fown->uid == cred->uid) && | |
20729 | - !security_file_send_sigiotask(p, fown, sig)); | |
20730 | + !security_file_send_sigiotask(p, fown, sig) && | |
20731 | + !gr_check_protected_task(p) && !gr_pid_is_chrooted(p)); | |
20732 | rcu_read_unlock(); | |
20733 | return ret; | |
20734 | } | |
de855c5d AM |
20735 | diff -urNp linux-2.6.29.6/fs/file.c linux-2.6.29.6/fs/file.c |
20736 | --- linux-2.6.29.6/fs/file.c 2009-07-02 19:41:20.000000000 -0400 | |
20737 | +++ linux-2.6.29.6/fs/file.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20738 | @@ -13,6 +13,7 @@ |
20739 | #include <linux/slab.h> | |
20740 | #include <linux/vmalloc.h> | |
20741 | #include <linux/file.h> | |
20742 | +#include <linux/security.h> | |
20743 | #include <linux/fdtable.h> | |
20744 | #include <linux/bitops.h> | |
20745 | #include <linux/interrupt.h> | |
20746 | @@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi | |
20747 | * N.B. For clone tasks sharing a files structure, this test | |
20748 | * will limit the total number of files that can be opened. | |
20749 | */ | |
20750 | + | |
20751 | + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0); | |
20752 | if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | |
20753 | return -EMFILE; | |
20754 | ||
de855c5d AM |
20755 | diff -urNp linux-2.6.29.6/fs/fs_struct.c linux-2.6.29.6/fs/fs_struct.c |
20756 | --- linux-2.6.29.6/fs/fs_struct.c 2009-07-02 19:41:20.000000000 -0400 | |
20757 | +++ linux-2.6.29.6/fs/fs_struct.c 2009-07-09 22:13:39.000000000 -0400 | |
20758 | @@ -88,7 +88,7 @@ void exit_fs(struct task_struct *tsk) | |
20759 | task_lock(tsk); | |
20760 | write_lock(&fs->lock); | |
20761 | tsk->fs = NULL; | |
20762 | - kill = !--fs->users; | |
20763 | + kill = !atomic_dec_return(&fs->users); | |
20764 | write_unlock(&fs->lock); | |
20765 | task_unlock(tsk); | |
20766 | if (kill) | |
20767 | @@ -101,7 +101,7 @@ struct fs_struct *copy_fs_struct(struct | |
20768 | struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL); | |
20769 | /* We don't need to lock fs - think why ;-) */ | |
20770 | if (fs) { | |
20771 | - fs->users = 1; | |
20772 | + atomic_set(&fs->users, 1); | |
20773 | fs->in_exec = 0; | |
20774 | rwlock_init(&fs->lock); | |
20775 | fs->umask = old->umask; | |
20776 | @@ -126,7 +126,7 @@ int unshare_fs_struct(void) | |
20777 | ||
20778 | task_lock(current); | |
20779 | write_lock(&fs->lock); | |
20780 | - kill = !--fs->users; | |
20781 | + kill = !atomic_dec_return(&fs->users); | |
20782 | current->fs = new_fs; | |
20783 | write_unlock(&fs->lock); | |
20784 | task_unlock(current); | |
20785 | @@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct); | |
20786 | ||
20787 | /* to be mentioned only in INIT_TASK */ | |
20788 | struct fs_struct init_fs = { | |
20789 | - .users = 1, | |
20790 | + .users = ATOMIC_INIT(1), | |
20791 | .lock = __RW_LOCK_UNLOCKED(init_fs.lock), | |
20792 | .umask = 0022, | |
20793 | }; | |
20794 | @@ -155,12 +155,12 @@ void daemonize_fs_struct(void) | |
20795 | task_lock(current); | |
20796 | ||
20797 | write_lock(&init_fs.lock); | |
20798 | - init_fs.users++; | |
20799 | + atomic_inc(&init_fs.users); | |
20800 | write_unlock(&init_fs.lock); | |
20801 | ||
20802 | write_lock(&fs->lock); | |
20803 | current->fs = &init_fs; | |
20804 | - kill = !--fs->users; | |
20805 | + kill = !atomic_dec_return(&fs->users); | |
20806 | write_unlock(&fs->lock); | |
20807 | ||
20808 | task_unlock(current); | |
20809 | diff -urNp linux-2.6.29.6/fs/fuse/control.c linux-2.6.29.6/fs/fuse/control.c | |
20810 | --- linux-2.6.29.6/fs/fuse/control.c 2009-07-02 19:41:20.000000000 -0400 | |
20811 | +++ linux-2.6.29.6/fs/fuse/control.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20812 | @@ -161,7 +161,7 @@ void fuse_ctl_remove_conn(struct fuse_co |
20813 | ||
20814 | static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent) | |
20815 | { | |
20816 | - struct tree_descr empty_descr = {""}; | |
20817 | + struct tree_descr empty_descr = {"", NULL, 0}; | |
20818 | struct fuse_conn *fc; | |
20819 | int err; | |
20820 | ||
de855c5d AM |
20821 | diff -urNp linux-2.6.29.6/fs/fuse/dir.c linux-2.6.29.6/fs/fuse/dir.c |
20822 | --- linux-2.6.29.6/fs/fuse/dir.c 2009-07-02 19:41:20.000000000 -0400 | |
20823 | +++ linux-2.6.29.6/fs/fuse/dir.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20824 | @@ -1081,7 +1081,7 @@ static char *read_link(struct dentry *de |
20825 | return link; | |
20826 | } | |
20827 | ||
20828 | -static void free_link(char *link) | |
20829 | +static void free_link(const char *link) | |
20830 | { | |
20831 | if (!IS_ERR(link)) | |
20832 | free_page((unsigned long) link); | |
de855c5d AM |
20833 | diff -urNp linux-2.6.29.6/fs/hfs/inode.c linux-2.6.29.6/fs/hfs/inode.c |
20834 | --- linux-2.6.29.6/fs/hfs/inode.c 2009-07-02 19:41:20.000000000 -0400 | |
20835 | +++ linux-2.6.29.6/fs/hfs/inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20836 | @@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode, |
20837 | ||
20838 | if (S_ISDIR(main_inode->i_mode)) { | |
20839 | if (fd.entrylength < sizeof(struct hfs_cat_dir)) | |
20840 | - /* panic? */; | |
20841 | + {/* panic? */} | |
20842 | hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, | |
20843 | sizeof(struct hfs_cat_dir)); | |
20844 | if (rec.type != HFS_CDR_DIR || | |
20845 | @@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode, | |
20846 | sizeof(struct hfs_cat_file)); | |
20847 | } else { | |
20848 | if (fd.entrylength < sizeof(struct hfs_cat_file)) | |
20849 | - /* panic? */; | |
20850 | + {/* panic? */} | |
20851 | hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, | |
20852 | sizeof(struct hfs_cat_file)); | |
20853 | if (rec.type != HFS_CDR_FIL || | |
de855c5d AM |
20854 | diff -urNp linux-2.6.29.6/fs/hfsplus/inode.c linux-2.6.29.6/fs/hfsplus/inode.c |
20855 | --- linux-2.6.29.6/fs/hfsplus/inode.c 2009-07-02 19:41:20.000000000 -0400 | |
20856 | +++ linux-2.6.29.6/fs/hfsplus/inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20857 | @@ -406,7 +406,7 @@ int hfsplus_cat_read_inode(struct inode |
20858 | struct hfsplus_cat_folder *folder = &entry.folder; | |
20859 | ||
20860 | if (fd->entrylength < sizeof(struct hfsplus_cat_folder)) | |
20861 | - /* panic? */; | |
20862 | + {/* panic? */} | |
20863 | hfs_bnode_read(fd->bnode, &entry, fd->entryoffset, | |
20864 | sizeof(struct hfsplus_cat_folder)); | |
20865 | hfsplus_get_perms(inode, &folder->permissions, 1); | |
20866 | @@ -423,7 +423,7 @@ int hfsplus_cat_read_inode(struct inode | |
20867 | struct hfsplus_cat_file *file = &entry.file; | |
20868 | ||
20869 | if (fd->entrylength < sizeof(struct hfsplus_cat_file)) | |
20870 | - /* panic? */; | |
20871 | + {/* panic? */} | |
20872 | hfs_bnode_read(fd->bnode, &entry, fd->entryoffset, | |
20873 | sizeof(struct hfsplus_cat_file)); | |
20874 | ||
20875 | @@ -479,7 +479,7 @@ int hfsplus_cat_write_inode(struct inode | |
20876 | struct hfsplus_cat_folder *folder = &entry.folder; | |
20877 | ||
20878 | if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) | |
20879 | - /* panic? */; | |
20880 | + {/* panic? */} | |
20881 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, | |
20882 | sizeof(struct hfsplus_cat_folder)); | |
20883 | /* simple node checks? */ | |
20884 | @@ -501,7 +501,7 @@ int hfsplus_cat_write_inode(struct inode | |
20885 | struct hfsplus_cat_file *file = &entry.file; | |
20886 | ||
20887 | if (fd.entrylength < sizeof(struct hfsplus_cat_file)) | |
20888 | - /* panic? */; | |
20889 | + {/* panic? */} | |
20890 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, | |
20891 | sizeof(struct hfsplus_cat_file)); | |
20892 | hfsplus_inode_write_fork(inode, &file->data_fork); | |
de855c5d AM |
20893 | diff -urNp linux-2.6.29.6/fs/jffs2/debug.h linux-2.6.29.6/fs/jffs2/debug.h |
20894 | --- linux-2.6.29.6/fs/jffs2/debug.h 2009-07-02 19:41:20.000000000 -0400 | |
20895 | +++ linux-2.6.29.6/fs/jffs2/debug.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
20896 | @@ -52,13 +52,13 @@ |
20897 | #if CONFIG_JFFS2_FS_DEBUG > 0 | |
20898 | #define D1(x) x | |
20899 | #else | |
20900 | -#define D1(x) | |
20901 | +#define D1(x) do {} while (0); | |
20902 | #endif | |
20903 | ||
20904 | #if CONFIG_JFFS2_FS_DEBUG > 1 | |
20905 | #define D2(x) x | |
20906 | #else | |
20907 | -#define D2(x) | |
20908 | +#define D2(x) do {} while (0); | |
20909 | #endif | |
20910 | ||
20911 | /* The prefixes of JFFS2 messages */ | |
20912 | @@ -114,73 +114,73 @@ | |
20913 | #ifdef JFFS2_DBG_READINODE_MESSAGES | |
20914 | #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20915 | #else | |
20916 | -#define dbg_readinode(fmt, ...) | |
20917 | +#define dbg_readinode(fmt, ...) do {} while (0) | |
20918 | #endif | |
20919 | #ifdef JFFS2_DBG_READINODE2_MESSAGES | |
20920 | #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20921 | #else | |
20922 | -#define dbg_readinode2(fmt, ...) | |
20923 | +#define dbg_readinode2(fmt, ...) do {} while (0) | |
20924 | #endif | |
20925 | ||
20926 | /* Fragtree build debugging messages */ | |
20927 | #ifdef JFFS2_DBG_FRAGTREE_MESSAGES | |
20928 | #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20929 | #else | |
20930 | -#define dbg_fragtree(fmt, ...) | |
20931 | +#define dbg_fragtree(fmt, ...) do {} while (0) | |
20932 | #endif | |
20933 | #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES | |
20934 | #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20935 | #else | |
20936 | -#define dbg_fragtree2(fmt, ...) | |
20937 | +#define dbg_fragtree2(fmt, ...) do {} while (0) | |
20938 | #endif | |
20939 | ||
20940 | /* Directory entry list manilulation debugging messages */ | |
20941 | #ifdef JFFS2_DBG_DENTLIST_MESSAGES | |
20942 | #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20943 | #else | |
20944 | -#define dbg_dentlist(fmt, ...) | |
20945 | +#define dbg_dentlist(fmt, ...) do {} while (0) | |
20946 | #endif | |
20947 | ||
20948 | /* Print the messages about manipulating node_refs */ | |
20949 | #ifdef JFFS2_DBG_NODEREF_MESSAGES | |
20950 | #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20951 | #else | |
20952 | -#define dbg_noderef(fmt, ...) | |
20953 | +#define dbg_noderef(fmt, ...) do {} while (0) | |
20954 | #endif | |
20955 | ||
20956 | /* Manipulations with the list of inodes (JFFS2 inocache) */ | |
20957 | #ifdef JFFS2_DBG_INOCACHE_MESSAGES | |
20958 | #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20959 | #else | |
20960 | -#define dbg_inocache(fmt, ...) | |
20961 | +#define dbg_inocache(fmt, ...) do {} while (0) | |
20962 | #endif | |
20963 | ||
20964 | /* Summary debugging messages */ | |
20965 | #ifdef JFFS2_DBG_SUMMARY_MESSAGES | |
20966 | #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20967 | #else | |
20968 | -#define dbg_summary(fmt, ...) | |
20969 | +#define dbg_summary(fmt, ...) do {} while (0) | |
20970 | #endif | |
20971 | ||
20972 | /* File system build messages */ | |
20973 | #ifdef JFFS2_DBG_FSBUILD_MESSAGES | |
20974 | #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20975 | #else | |
20976 | -#define dbg_fsbuild(fmt, ...) | |
20977 | +#define dbg_fsbuild(fmt, ...) do {} while (0) | |
20978 | #endif | |
20979 | ||
20980 | /* Watch the object allocations */ | |
20981 | #ifdef JFFS2_DBG_MEMALLOC_MESSAGES | |
20982 | #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20983 | #else | |
20984 | -#define dbg_memalloc(fmt, ...) | |
20985 | +#define dbg_memalloc(fmt, ...) do {} while (0) | |
20986 | #endif | |
20987 | ||
20988 | /* Watch the XATTR subsystem */ | |
20989 | #ifdef JFFS2_DBG_XATTR_MESSAGES | |
20990 | #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__) | |
20991 | #else | |
20992 | -#define dbg_xattr(fmt, ...) | |
20993 | +#define dbg_xattr(fmt, ...) do {} while (0) | |
20994 | #endif | |
20995 | ||
20996 | /* "Sanity" checks */ | |
de855c5d AM |
20997 | diff -urNp linux-2.6.29.6/fs/jffs2/erase.c linux-2.6.29.6/fs/jffs2/erase.c |
20998 | --- linux-2.6.29.6/fs/jffs2/erase.c 2009-07-02 19:41:20.000000000 -0400 | |
20999 | +++ linux-2.6.29.6/fs/jffs2/erase.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21000 | @@ -432,7 +432,8 @@ static void jffs2_mark_erased_block(stru |
21001 | struct jffs2_unknown_node marker = { | |
21002 | .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK), | |
21003 | .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER), | |
21004 | - .totlen = cpu_to_je32(c->cleanmarker_size) | |
21005 | + .totlen = cpu_to_je32(c->cleanmarker_size), | |
21006 | + .hdr_crc = cpu_to_je32(0) | |
21007 | }; | |
21008 | ||
21009 | jffs2_prealloc_raw_node_refs(c, jeb, 1); | |
de855c5d AM |
21010 | diff -urNp linux-2.6.29.6/fs/jffs2/summary.h linux-2.6.29.6/fs/jffs2/summary.h |
21011 | --- linux-2.6.29.6/fs/jffs2/summary.h 2009-07-02 19:41:20.000000000 -0400 | |
21012 | +++ linux-2.6.29.6/fs/jffs2/summary.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21013 | @@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_ |
21014 | ||
21015 | #define jffs2_sum_active() (0) | |
21016 | #define jffs2_sum_init(a) (0) | |
21017 | -#define jffs2_sum_exit(a) | |
21018 | -#define jffs2_sum_disable_collecting(a) | |
21019 | +#define jffs2_sum_exit(a) do {} while (0) | |
21020 | +#define jffs2_sum_disable_collecting(a) do {} while (0) | |
21021 | #define jffs2_sum_is_disabled(a) (0) | |
21022 | -#define jffs2_sum_reset_collected(a) | |
21023 | +#define jffs2_sum_reset_collected(a) do {} while (0) | |
21024 | #define jffs2_sum_add_kvec(a,b,c,d) (0) | |
21025 | -#define jffs2_sum_move_collected(a,b) | |
21026 | +#define jffs2_sum_move_collected(a,b) do {} while (0) | |
21027 | #define jffs2_sum_write_sumnode(a) (0) | |
21028 | -#define jffs2_sum_add_padding_mem(a,b) | |
21029 | -#define jffs2_sum_add_inode_mem(a,b,c) | |
21030 | -#define jffs2_sum_add_dirent_mem(a,b,c) | |
21031 | -#define jffs2_sum_add_xattr_mem(a,b,c) | |
21032 | -#define jffs2_sum_add_xref_mem(a,b,c) | |
21033 | +#define jffs2_sum_add_padding_mem(a,b) do {} while (0) | |
21034 | +#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0) | |
21035 | +#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0) | |
21036 | +#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0) | |
21037 | +#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0) | |
21038 | #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0) | |
21039 | ||
21040 | #endif /* CONFIG_JFFS2_SUMMARY */ | |
de855c5d AM |
21041 | diff -urNp linux-2.6.29.6/fs/jffs2/wbuf.c linux-2.6.29.6/fs/jffs2/wbuf.c |
21042 | --- linux-2.6.29.6/fs/jffs2/wbuf.c 2009-07-02 19:41:20.000000000 -0400 | |
21043 | +++ linux-2.6.29.6/fs/jffs2/wbuf.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21044 | @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o |
21045 | { | |
21046 | .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK), | |
21047 | .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER), | |
21048 | - .totlen = constant_cpu_to_je32(8) | |
21049 | + .totlen = constant_cpu_to_je32(8), | |
21050 | + .hdr_crc = constant_cpu_to_je32(0) | |
21051 | }; | |
21052 | ||
21053 | /* | |
de855c5d AM |
21054 | diff -urNp linux-2.6.29.6/fs/locks.c linux-2.6.29.6/fs/locks.c |
21055 | --- linux-2.6.29.6/fs/locks.c 2009-07-02 19:41:20.000000000 -0400 | |
21056 | +++ linux-2.6.29.6/fs/locks.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21057 | @@ -2006,16 +2006,16 @@ void locks_remove_flock(struct file *fil |
21058 | return; | |
21059 | ||
21060 | if (filp->f_op && filp->f_op->flock) { | |
21061 | - struct file_lock fl = { | |
21062 | + struct file_lock flock = { | |
21063 | .fl_pid = current->tgid, | |
21064 | .fl_file = filp, | |
21065 | .fl_flags = FL_FLOCK, | |
21066 | .fl_type = F_UNLCK, | |
21067 | .fl_end = OFFSET_MAX, | |
21068 | }; | |
21069 | - filp->f_op->flock(filp, F_SETLKW, &fl); | |
21070 | - if (fl.fl_ops && fl.fl_ops->fl_release_private) | |
21071 | - fl.fl_ops->fl_release_private(&fl); | |
21072 | + filp->f_op->flock(filp, F_SETLKW, &flock); | |
21073 | + if (flock.fl_ops && flock.fl_ops->fl_release_private) | |
21074 | + flock.fl_ops->fl_release_private(&flock); | |
21075 | } | |
21076 | ||
21077 | lock_kernel(); | |
de855c5d AM |
21078 | diff -urNp linux-2.6.29.6/fs/namei.c linux-2.6.29.6/fs/namei.c |
21079 | --- linux-2.6.29.6/fs/namei.c 2009-07-02 19:41:20.000000000 -0400 | |
21080 | +++ linux-2.6.29.6/fs/namei.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21081 | @@ -622,7 +622,7 @@ static __always_inline int __do_follow_l |
21082 | cookie = dentry->d_inode->i_op->follow_link(dentry, nd); | |
21083 | error = PTR_ERR(cookie); | |
21084 | if (!IS_ERR(cookie)) { | |
21085 | - char *s = nd_get_link(nd); | |
21086 | + const char *s = nd_get_link(nd); | |
21087 | error = 0; | |
21088 | if (s) | |
21089 | error = __vfs_follow_link(nd, s); | |
21090 | @@ -653,6 +653,13 @@ static inline int do_follow_link(struct | |
21091 | err = security_inode_follow_link(path->dentry, nd); | |
21092 | if (err) | |
21093 | goto loop; | |
21094 | + | |
21095 | + if (gr_handle_follow_link(path->dentry->d_parent->d_inode, | |
21096 | + path->dentry->d_inode, path->dentry, nd->path.mnt)) { | |
21097 | + err = -EACCES; | |
21098 | + goto loop; | |
21099 | + } | |
21100 | + | |
21101 | current->link_count++; | |
21102 | current->total_link_count++; | |
21103 | nd->depth++; | |
21104 | @@ -996,11 +1003,18 @@ return_reval: | |
21105 | break; | |
21106 | } | |
21107 | return_base: | |
21108 | + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) { | |
21109 | + path_put(&nd->path); | |
21110 | + return -ENOENT; | |
21111 | + } | |
21112 | return 0; | |
21113 | out_dput: | |
21114 | path_put_conditional(&next, nd); | |
21115 | break; | |
21116 | } | |
21117 | + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) | |
21118 | + err = -ENOENT; | |
21119 | + | |
21120 | path_put(&nd->path); | |
21121 | return_err: | |
21122 | return err; | |
21123 | @@ -1571,12 +1585,19 @@ static int __open_namei_create(struct na | |
21124 | int error; | |
21125 | struct dentry *dir = nd->path.dentry; | |
21126 | ||
21127 | + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) { | |
21128 | + error = -EACCES; | |
21129 | + goto out_unlock; | |
21130 | + } | |
21131 | + | |
21132 | if (!IS_POSIXACL(dir->d_inode)) | |
21133 | mode &= ~current->fs->umask; | |
21134 | error = security_path_mknod(&nd->path, path->dentry, mode, 0); | |
21135 | if (error) | |
21136 | goto out_unlock; | |
21137 | error = vfs_create(dir->d_inode, path->dentry, mode, nd); | |
21138 | + if (!error) | |
21139 | + gr_handle_create(path->dentry, nd->path.mnt); | |
21140 | out_unlock: | |
21141 | mutex_unlock(&dir->d_inode->i_mutex); | |
21142 | dput(nd->path.dentry); | |
21143 | @@ -1658,6 +1679,17 @@ struct file *do_filp_open(int dfd, const | |
21144 | &nd, flag); | |
21145 | if (error) | |
21146 | return ERR_PTR(error); | |
21147 | + | |
21148 | + if (gr_handle_rawio(nd.path.dentry->d_inode)) { | |
21149 | + error = -EPERM; | |
21150 | + goto exit; | |
21151 | + } | |
21152 | + | |
21153 | + if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) { | |
21154 | + error = -EACCES; | |
21155 | + goto exit; | |
21156 | + } | |
21157 | + | |
21158 | goto ok; | |
21159 | } | |
21160 | ||
21161 | @@ -1730,6 +1762,20 @@ do_last: | |
21162 | /* | |
21163 | * It already exists. | |
21164 | */ | |
21165 | + | |
21166 | + if (gr_handle_rawio(path.dentry->d_inode)) { | |
21167 | + error = -EPERM; | |
21168 | + goto exit_mutex_unlock; | |
21169 | + } | |
21170 | + if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) { | |
21171 | + error = -EACCES; | |
21172 | + goto exit_mutex_unlock; | |
21173 | + } | |
21174 | + if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) { | |
21175 | + error = -EACCES; | |
21176 | + goto exit_mutex_unlock; | |
21177 | + } | |
21178 | + | |
21179 | mutex_unlock(&dir->d_inode->i_mutex); | |
21180 | audit_inode(pathname, path.dentry); | |
21181 | ||
21182 | @@ -1815,6 +1861,13 @@ do_link: | |
21183 | error = security_inode_follow_link(path.dentry, &nd); | |
21184 | if (error) | |
21185 | goto exit_dput; | |
21186 | + | |
21187 | + if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode, | |
21188 | + path.dentry, nd.path.mnt)) { | |
21189 | + error = -EACCES; | |
21190 | + goto exit_dput; | |
21191 | + } | |
21192 | + | |
21193 | error = __do_follow_link(&path, &nd); | |
21194 | if (error) { | |
21195 | /* Does someone understand code flow here? Or it is only | |
21196 | @@ -1987,6 +2040,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const | |
21197 | error = may_mknod(mode); | |
21198 | if (error) | |
21199 | goto out_dput; | |
21200 | + | |
21201 | + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) { | |
21202 | + error = -EPERM; | |
21203 | + goto out_dput; | |
21204 | + } | |
21205 | + | |
21206 | + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) { | |
21207 | + error = -EACCES; | |
21208 | + goto out_dput; | |
21209 | + } | |
21210 | + | |
21211 | error = mnt_want_write(nd.path.mnt); | |
21212 | if (error) | |
21213 | goto out_dput; | |
21214 | @@ -2007,6 +2071,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const | |
21215 | } | |
21216 | out_drop_write: | |
21217 | mnt_drop_write(nd.path.mnt); | |
21218 | + | |
21219 | + if (!error) | |
21220 | + gr_handle_create(dentry, nd.path.mnt); | |
21221 | out_dput: | |
21222 | dput(dentry); | |
21223 | out_unlock: | |
21224 | @@ -2060,6 +2127,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const | |
21225 | if (IS_ERR(dentry)) | |
21226 | goto out_unlock; | |
21227 | ||
21228 | + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) { | |
21229 | + error = -EACCES; | |
21230 | + goto out_dput; | |
21231 | + } | |
21232 | + | |
21233 | if (!IS_POSIXACL(nd.path.dentry->d_inode)) | |
21234 | mode &= ~current->fs->umask; | |
21235 | error = mnt_want_write(nd.path.mnt); | |
21236 | @@ -2071,6 +2143,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const | |
21237 | error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); | |
21238 | out_drop_write: | |
21239 | mnt_drop_write(nd.path.mnt); | |
21240 | + | |
21241 | + if (!error) | |
21242 | + gr_handle_create(dentry, nd.path.mnt); | |
21243 | + | |
21244 | out_dput: | |
21245 | dput(dentry); | |
21246 | out_unlock: | |
21247 | @@ -2152,6 +2228,8 @@ static long do_rmdir(int dfd, const char | |
21248 | char * name; | |
21249 | struct dentry *dentry; | |
21250 | struct nameidata nd; | |
21251 | + ino_t saved_ino = 0; | |
21252 | + dev_t saved_dev = 0; | |
21253 | ||
21254 | error = user_path_parent(dfd, pathname, &nd, &name); | |
21255 | if (error) | |
21256 | @@ -2176,6 +2254,19 @@ static long do_rmdir(int dfd, const char | |
21257 | error = PTR_ERR(dentry); | |
21258 | if (IS_ERR(dentry)) | |
21259 | goto exit2; | |
21260 | + | |
21261 | + if (dentry->d_inode != NULL) { | |
21262 | + if (dentry->d_inode->i_nlink <= 1) { | |
21263 | + saved_ino = dentry->d_inode->i_ino; | |
21264 | + saved_dev = dentry->d_inode->i_sb->s_dev; | |
21265 | + } | |
21266 | + | |
21267 | + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) { | |
21268 | + error = -EACCES; | |
21269 | + goto exit3; | |
21270 | + } | |
21271 | + } | |
21272 | + | |
21273 | error = mnt_want_write(nd.path.mnt); | |
21274 | if (error) | |
21275 | goto exit3; | |
21276 | @@ -2183,6 +2274,8 @@ static long do_rmdir(int dfd, const char | |
21277 | if (error) | |
21278 | goto exit4; | |
21279 | error = vfs_rmdir(nd.path.dentry->d_inode, dentry); | |
21280 | + if (!error && (saved_dev || saved_ino)) | |
21281 | + gr_handle_delete(saved_ino, saved_dev); | |
21282 | exit4: | |
21283 | mnt_drop_write(nd.path.mnt); | |
21284 | exit3: | |
21285 | @@ -2244,6 +2337,8 @@ static long do_unlinkat(int dfd, const c | |
21286 | struct dentry *dentry; | |
21287 | struct nameidata nd; | |
21288 | struct inode *inode = NULL; | |
21289 | + ino_t saved_ino = 0; | |
21290 | + dev_t saved_dev = 0; | |
21291 | ||
21292 | error = user_path_parent(dfd, pathname, &nd, &name); | |
21293 | if (error) | |
21294 | @@ -2263,8 +2358,19 @@ static long do_unlinkat(int dfd, const c | |
21295 | if (nd.last.name[nd.last.len]) | |
21296 | goto slashes; | |
21297 | inode = dentry->d_inode; | |
21298 | - if (inode) | |
21299 | + if (inode) { | |
21300 | + if (inode->i_nlink <= 1) { | |
21301 | + saved_ino = inode->i_ino; | |
21302 | + saved_dev = inode->i_sb->s_dev; | |
21303 | + } | |
21304 | + | |
21305 | atomic_inc(&inode->i_count); | |
21306 | + | |
21307 | + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) { | |
21308 | + error = -EACCES; | |
21309 | + goto exit2; | |
21310 | + } | |
21311 | + } | |
21312 | error = mnt_want_write(nd.path.mnt); | |
21313 | if (error) | |
21314 | goto exit2; | |
21315 | @@ -2272,6 +2378,8 @@ static long do_unlinkat(int dfd, const c | |
21316 | if (error) | |
21317 | goto exit3; | |
21318 | error = vfs_unlink(nd.path.dentry->d_inode, dentry); | |
21319 | + if (!error && (saved_ino || saved_dev)) | |
21320 | + gr_handle_delete(saved_ino, saved_dev); | |
21321 | exit3: | |
21322 | mnt_drop_write(nd.path.mnt); | |
21323 | exit2: | |
21324 | @@ -2350,6 +2458,11 @@ SYSCALL_DEFINE3(symlinkat, const char __ | |
21325 | if (IS_ERR(dentry)) | |
21326 | goto out_unlock; | |
21327 | ||
21328 | + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) { | |
21329 | + error = -EACCES; | |
21330 | + goto out_dput; | |
21331 | + } | |
21332 | + | |
21333 | error = mnt_want_write(nd.path.mnt); | |
21334 | if (error) | |
21335 | goto out_dput; | |
21336 | @@ -2357,6 +2470,8 @@ SYSCALL_DEFINE3(symlinkat, const char __ | |
21337 | if (error) | |
21338 | goto out_drop_write; | |
21339 | error = vfs_symlink(nd.path.dentry->d_inode, dentry, from); | |
21340 | + if (!error) | |
21341 | + gr_handle_create(dentry, nd.path.mnt); | |
21342 | out_drop_write: | |
21343 | mnt_drop_write(nd.path.mnt); | |
21344 | out_dput: | |
21345 | @@ -2450,6 +2565,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con | |
21346 | error = PTR_ERR(new_dentry); | |
21347 | if (IS_ERR(new_dentry)) | |
21348 | goto out_unlock; | |
21349 | + | |
21350 | + if (gr_handle_hardlink(old_path.dentry, old_path.mnt, | |
21351 | + old_path.dentry->d_inode, | |
21352 | + old_path.dentry->d_inode->i_mode, to)) { | |
21353 | + error = -EACCES; | |
21354 | + goto out_dput; | |
21355 | + } | |
21356 | + | |
21357 | + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt, | |
21358 | + old_path.dentry, old_path.mnt, to)) { | |
21359 | + error = -EACCES; | |
21360 | + goto out_dput; | |
21361 | + } | |
21362 | + | |
21363 | error = mnt_want_write(nd.path.mnt); | |
21364 | if (error) | |
21365 | goto out_dput; | |
21366 | @@ -2457,6 +2586,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con | |
21367 | if (error) | |
21368 | goto out_drop_write; | |
21369 | error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry); | |
21370 | + if (!error) | |
21371 | + gr_handle_create(new_dentry, nd.path.mnt); | |
21372 | out_drop_write: | |
21373 | mnt_drop_write(nd.path.mnt); | |
21374 | out_dput: | |
21375 | @@ -2690,6 +2821,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c | |
21376 | if (new_dentry == trap) | |
21377 | goto exit5; | |
21378 | ||
21379 | + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt, | |
21380 | + old_dentry, old_dir->d_inode, oldnd.path.mnt, | |
21381 | + to); | |
21382 | + if (error) | |
21383 | + goto exit5; | |
21384 | + | |
21385 | error = mnt_want_write(oldnd.path.mnt); | |
21386 | if (error) | |
21387 | goto exit5; | |
21388 | @@ -2699,6 +2836,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c | |
21389 | goto exit6; | |
21390 | error = vfs_rename(old_dir->d_inode, old_dentry, | |
21391 | new_dir->d_inode, new_dentry); | |
21392 | + if (!error) | |
21393 | + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry, | |
21394 | + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0); | |
21395 | exit6: | |
21396 | mnt_drop_write(oldnd.path.mnt); | |
21397 | exit5: | |
de855c5d AM |
21398 | diff -urNp linux-2.6.29.6/fs/namespace.c linux-2.6.29.6/fs/namespace.c |
21399 | --- linux-2.6.29.6/fs/namespace.c 2009-07-02 19:41:20.000000000 -0400 | |
21400 | +++ linux-2.6.29.6/fs/namespace.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21401 | @@ -1096,6 +1096,8 @@ static int do_umount(struct vfsmount *mn |
21402 | lock_kernel(); | |
21403 | retval = do_remount_sb(sb, MS_RDONLY, NULL, 0); | |
21404 | unlock_kernel(); | |
21405 | + | |
21406 | + gr_log_remount(mnt->mnt_devname, retval); | |
21407 | } | |
21408 | up_write(&sb->s_umount); | |
21409 | return retval; | |
21410 | @@ -1119,6 +1121,9 @@ static int do_umount(struct vfsmount *mn | |
21411 | security_sb_umount_busy(mnt); | |
21412 | up_write(&namespace_sem); | |
21413 | release_mounts(&umount_list); | |
21414 | + | |
21415 | + gr_log_unmount(mnt->mnt_devname, retval); | |
21416 | + | |
21417 | return retval; | |
21418 | } | |
21419 | ||
21420 | @@ -1948,6 +1953,11 @@ long do_mount(char *dev_name, char *dir_ | |
21421 | if (retval) | |
21422 | goto dput_out; | |
21423 | ||
21424 | + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) { | |
21425 | + retval = -EPERM; | |
21426 | + goto dput_out; | |
21427 | + } | |
21428 | + | |
21429 | if (flags & MS_REMOUNT) | |
21430 | retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags, | |
21431 | data_page); | |
21432 | @@ -1962,6 +1972,9 @@ long do_mount(char *dev_name, char *dir_ | |
21433 | dev_name, data_page); | |
21434 | dput_out: | |
21435 | path_put(&path); | |
21436 | + | |
21437 | + gr_log_mount(dev_name, dir_name, retval); | |
21438 | + | |
21439 | return retval; | |
21440 | } | |
21441 | ||
21442 | @@ -2073,6 +2086,9 @@ SYSCALL_DEFINE5(mount, char __user *, de | |
21443 | if (retval < 0) | |
21444 | goto out3; | |
21445 | ||
21446 | + if (gr_handle_chroot_pivot()) | |
21447 | + return -EPERM; | |
21448 | + | |
21449 | lock_kernel(); | |
21450 | retval = do_mount((char *)dev_page, dir_page, (char *)type_page, | |
21451 | flags, (void *)data_page); | |
de855c5d AM |
21452 | diff -urNp linux-2.6.29.6/fs/nfs/nfs4proc.c linux-2.6.29.6/fs/nfs/nfs4proc.c |
21453 | --- linux-2.6.29.6/fs/nfs/nfs4proc.c 2009-07-02 19:41:20.000000000 -0400 | |
21454 | +++ linux-2.6.29.6/fs/nfs/nfs4proc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21455 | @@ -763,7 +763,7 @@ static int _nfs4_do_open_reclaim(struct |
21456 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) | |
21457 | { | |
21458 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21459 | - struct nfs4_exception exception = { }; | |
21460 | + struct nfs4_exception exception = {0, 0}; | |
21461 | int err; | |
21462 | do { | |
21463 | err = _nfs4_do_open_reclaim(ctx, state); | |
21464 | @@ -805,7 +805,7 @@ static int _nfs4_open_delegation_recall( | |
21465 | ||
21466 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) | |
21467 | { | |
21468 | - struct nfs4_exception exception = { }; | |
21469 | + struct nfs4_exception exception = {0, 0}; | |
21470 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21471 | int err; | |
21472 | do { | |
21473 | @@ -1099,7 +1099,7 @@ static int _nfs4_open_expired(struct nfs | |
21474 | static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) | |
21475 | { | |
21476 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21477 | - struct nfs4_exception exception = { }; | |
21478 | + struct nfs4_exception exception = {0, 0}; | |
21479 | int err; | |
21480 | ||
21481 | do { | |
21482 | @@ -1197,7 +1197,7 @@ out_err: | |
21483 | ||
21484 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) | |
21485 | { | |
21486 | - struct nfs4_exception exception = { }; | |
21487 | + struct nfs4_exception exception = {0, 0}; | |
21488 | struct nfs4_state *res; | |
21489 | int status; | |
21490 | ||
21491 | @@ -1288,7 +1288,7 @@ static int nfs4_do_setattr(struct inode | |
21492 | struct nfs4_state *state) | |
21493 | { | |
21494 | struct nfs_server *server = NFS_SERVER(inode); | |
21495 | - struct nfs4_exception exception = { }; | |
21496 | + struct nfs4_exception exception = {0, 0}; | |
21497 | int err; | |
21498 | do { | |
21499 | err = nfs4_handle_exception(server, | |
21500 | @@ -1607,7 +1607,7 @@ static int _nfs4_server_capabilities(str | |
21501 | ||
21502 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | |
21503 | { | |
21504 | - struct nfs4_exception exception = { }; | |
21505 | + struct nfs4_exception exception = {0, 0}; | |
21506 | int err; | |
21507 | do { | |
21508 | err = nfs4_handle_exception(server, | |
21509 | @@ -1640,7 +1640,7 @@ static int _nfs4_lookup_root(struct nfs_ | |
21510 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | |
21511 | struct nfs_fsinfo *info) | |
21512 | { | |
21513 | - struct nfs4_exception exception = { }; | |
21514 | + struct nfs4_exception exception = {0, 0}; | |
21515 | int err; | |
21516 | do { | |
21517 | err = nfs4_handle_exception(server, | |
21518 | @@ -1729,7 +1729,7 @@ static int _nfs4_proc_getattr(struct nfs | |
21519 | ||
21520 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | |
21521 | { | |
21522 | - struct nfs4_exception exception = { }; | |
21523 | + struct nfs4_exception exception = {0, 0}; | |
21524 | int err; | |
21525 | do { | |
21526 | err = nfs4_handle_exception(server, | |
21527 | @@ -1817,7 +1817,7 @@ static int nfs4_proc_lookupfh(struct nfs | |
21528 | struct qstr *name, struct nfs_fh *fhandle, | |
21529 | struct nfs_fattr *fattr) | |
21530 | { | |
21531 | - struct nfs4_exception exception = { }; | |
21532 | + struct nfs4_exception exception = {0, 0}; | |
21533 | int err; | |
21534 | do { | |
21535 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); | |
21536 | @@ -1846,7 +1846,7 @@ static int _nfs4_proc_lookup(struct inod | |
21537 | ||
21538 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | |
21539 | { | |
21540 | - struct nfs4_exception exception = { }; | |
21541 | + struct nfs4_exception exception = {0, 0}; | |
21542 | int err; | |
21543 | do { | |
21544 | err = nfs4_handle_exception(NFS_SERVER(dir), | |
21545 | @@ -1910,7 +1910,7 @@ static int _nfs4_proc_access(struct inod | |
21546 | ||
21547 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | |
21548 | { | |
21549 | - struct nfs4_exception exception = { }; | |
21550 | + struct nfs4_exception exception = {0, 0}; | |
21551 | int err; | |
21552 | do { | |
21553 | err = nfs4_handle_exception(NFS_SERVER(inode), | |
21554 | @@ -1965,7 +1965,7 @@ static int _nfs4_proc_readlink(struct in | |
21555 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, | |
21556 | unsigned int pgbase, unsigned int pglen) | |
21557 | { | |
21558 | - struct nfs4_exception exception = { }; | |
21559 | + struct nfs4_exception exception = {0, 0}; | |
21560 | int err; | |
21561 | do { | |
21562 | err = nfs4_handle_exception(NFS_SERVER(inode), | |
21563 | @@ -2063,7 +2063,7 @@ static int _nfs4_proc_remove(struct inod | |
21564 | ||
21565 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) | |
21566 | { | |
21567 | - struct nfs4_exception exception = { }; | |
21568 | + struct nfs4_exception exception = {0, 0}; | |
21569 | int err; | |
21570 | do { | |
21571 | err = nfs4_handle_exception(NFS_SERVER(dir), | |
21572 | @@ -2135,7 +2135,7 @@ static int _nfs4_proc_rename(struct inod | |
21573 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | |
21574 | struct inode *new_dir, struct qstr *new_name) | |
21575 | { | |
21576 | - struct nfs4_exception exception = { }; | |
21577 | + struct nfs4_exception exception = {0, 0}; | |
21578 | int err; | |
21579 | do { | |
21580 | err = nfs4_handle_exception(NFS_SERVER(old_dir), | |
21581 | @@ -2182,7 +2182,7 @@ static int _nfs4_proc_link(struct inode | |
21582 | ||
21583 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | |
21584 | { | |
21585 | - struct nfs4_exception exception = { }; | |
21586 | + struct nfs4_exception exception = {0, 0}; | |
21587 | int err; | |
21588 | do { | |
21589 | err = nfs4_handle_exception(NFS_SERVER(inode), | |
21590 | @@ -2273,7 +2273,7 @@ out: | |
21591 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | |
21592 | struct page *page, unsigned int len, struct iattr *sattr) | |
21593 | { | |
21594 | - struct nfs4_exception exception = { }; | |
21595 | + struct nfs4_exception exception = {0, 0}; | |
21596 | int err; | |
21597 | do { | |
21598 | err = nfs4_handle_exception(NFS_SERVER(dir), | |
21599 | @@ -2304,7 +2304,7 @@ out: | |
21600 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | |
21601 | struct iattr *sattr) | |
21602 | { | |
21603 | - struct nfs4_exception exception = { }; | |
21604 | + struct nfs4_exception exception = {0, 0}; | |
21605 | int err; | |
21606 | do { | |
21607 | err = nfs4_handle_exception(NFS_SERVER(dir), | |
21608 | @@ -2353,7 +2353,7 @@ static int _nfs4_proc_readdir(struct den | |
21609 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | |
21610 | u64 cookie, struct page *page, unsigned int count, int plus) | |
21611 | { | |
21612 | - struct nfs4_exception exception = { }; | |
21613 | + struct nfs4_exception exception = {0, 0}; | |
21614 | int err; | |
21615 | do { | |
21616 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), | |
21617 | @@ -2401,7 +2401,7 @@ out: | |
21618 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | |
21619 | struct iattr *sattr, dev_t rdev) | |
21620 | { | |
21621 | - struct nfs4_exception exception = { }; | |
21622 | + struct nfs4_exception exception = {0, 0}; | |
21623 | int err; | |
21624 | do { | |
21625 | err = nfs4_handle_exception(NFS_SERVER(dir), | |
21626 | @@ -2430,7 +2430,7 @@ static int _nfs4_proc_statfs(struct nfs_ | |
21627 | ||
21628 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) | |
21629 | { | |
21630 | - struct nfs4_exception exception = { }; | |
21631 | + struct nfs4_exception exception = {0, 0}; | |
21632 | int err; | |
21633 | do { | |
21634 | err = nfs4_handle_exception(server, | |
21635 | @@ -2458,7 +2458,7 @@ static int _nfs4_do_fsinfo(struct nfs_se | |
21636 | ||
21637 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | |
21638 | { | |
21639 | - struct nfs4_exception exception = { }; | |
21640 | + struct nfs4_exception exception = {0, 0}; | |
21641 | int err; | |
21642 | ||
21643 | do { | |
21644 | @@ -2501,7 +2501,7 @@ static int _nfs4_proc_pathconf(struct nf | |
21645 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | |
21646 | struct nfs_pathconf *pathconf) | |
21647 | { | |
21648 | - struct nfs4_exception exception = { }; | |
21649 | + struct nfs4_exception exception = {0, 0}; | |
21650 | int err; | |
21651 | ||
21652 | do { | |
21653 | @@ -2788,7 +2788,7 @@ out_free: | |
21654 | ||
21655 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | |
21656 | { | |
21657 | - struct nfs4_exception exception = { }; | |
21658 | + struct nfs4_exception exception = {0, 0}; | |
21659 | ssize_t ret; | |
21660 | do { | |
21661 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); | |
21662 | @@ -2845,7 +2845,7 @@ static int __nfs4_proc_set_acl(struct in | |
21663 | ||
21664 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | |
21665 | { | |
21666 | - struct nfs4_exception exception = { }; | |
21667 | + struct nfs4_exception exception = {0, 0}; | |
21668 | int err; | |
21669 | do { | |
21670 | err = nfs4_handle_exception(NFS_SERVER(inode), | |
21671 | @@ -3068,7 +3068,7 @@ out: | |
21672 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) | |
21673 | { | |
21674 | struct nfs_server *server = NFS_SERVER(inode); | |
21675 | - struct nfs4_exception exception = { }; | |
21676 | + struct nfs4_exception exception = {0, 0}; | |
21677 | int err; | |
21678 | do { | |
21679 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); | |
21680 | @@ -3141,7 +3141,7 @@ out: | |
21681 | ||
21682 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | |
21683 | { | |
21684 | - struct nfs4_exception exception = { }; | |
21685 | + struct nfs4_exception exception = {0, 0}; | |
21686 | int err; | |
21687 | ||
21688 | do { | |
21689 | @@ -3498,7 +3498,7 @@ static int _nfs4_do_setlk(struct nfs4_st | |
21690 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) | |
21691 | { | |
21692 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21693 | - struct nfs4_exception exception = { }; | |
21694 | + struct nfs4_exception exception = {0, 0}; | |
21695 | int err; | |
21696 | ||
21697 | do { | |
21698 | @@ -3516,7 +3516,7 @@ static int nfs4_lock_reclaim(struct nfs4 | |
21699 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) | |
21700 | { | |
21701 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21702 | - struct nfs4_exception exception = { }; | |
21703 | + struct nfs4_exception exception = {0, 0}; | |
21704 | int err; | |
21705 | ||
21706 | err = nfs4_set_lock_state(state, request); | |
21707 | @@ -3571,7 +3571,7 @@ out: | |
21708 | ||
21709 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | |
21710 | { | |
21711 | - struct nfs4_exception exception = { }; | |
21712 | + struct nfs4_exception exception = {0, 0}; | |
21713 | int err; | |
21714 | ||
21715 | do { | |
21716 | @@ -3621,7 +3621,7 @@ nfs4_proc_lock(struct file *filp, int cm | |
21717 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) | |
21718 | { | |
21719 | struct nfs_server *server = NFS_SERVER(state->inode); | |
21720 | - struct nfs4_exception exception = { }; | |
21721 | + struct nfs4_exception exception = {0, 0}; | |
21722 | int err; | |
21723 | ||
21724 | err = nfs4_set_lock_state(state, fl); | |
de855c5d AM |
21725 | diff -urNp linux-2.6.29.6/fs/nfsd/export.c linux-2.6.29.6/fs/nfsd/export.c |
21726 | --- linux-2.6.29.6/fs/nfsd/export.c 2009-07-02 19:41:20.000000000 -0400 | |
21727 | +++ linux-2.6.29.6/fs/nfsd/export.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21728 | @@ -472,7 +472,7 @@ static int secinfo_parse(char **mesg, ch |
21729 | * probably discover the problem when someone fails to | |
21730 | * authenticate. | |
21731 | */ | |
21732 | - if (f->pseudoflavor < 0) | |
21733 | + if ((s32)f->pseudoflavor < 0) | |
21734 | return -EINVAL; | |
21735 | err = get_int(mesg, &f->flags); | |
21736 | if (err) | |
de855c5d AM |
21737 | diff -urNp linux-2.6.29.6/fs/nls/nls_base.c linux-2.6.29.6/fs/nls/nls_base.c |
21738 | --- linux-2.6.29.6/fs/nls/nls_base.c 2009-07-02 19:41:20.000000000 -0400 | |
21739 | +++ linux-2.6.29.6/fs/nls/nls_base.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21740 | @@ -40,7 +40,7 @@ static const struct utf8_table utf8_tabl |
21741 | {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */}, | |
21742 | {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */}, | |
21743 | {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */}, | |
21744 | - {0, /* end of table */} | |
21745 | + {0, 0, 0, 0, 0, /* end of table */} | |
21746 | }; | |
21747 | ||
21748 | int | |
de855c5d AM |
21749 | diff -urNp linux-2.6.29.6/fs/ntfs/file.c linux-2.6.29.6/fs/ntfs/file.c |
21750 | --- linux-2.6.29.6/fs/ntfs/file.c 2009-07-02 19:41:20.000000000 -0400 | |
21751 | +++ linux-2.6.29.6/fs/ntfs/file.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
21752 | @@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_ |
21753 | #endif /* NTFS_RW */ | |
21754 | }; | |
21755 | ||
21756 | -const struct file_operations ntfs_empty_file_ops = {}; | |
21757 | +const struct file_operations ntfs_empty_file_ops; | |
21758 | ||
21759 | -const struct inode_operations ntfs_empty_inode_ops = {}; | |
21760 | +const struct inode_operations ntfs_empty_inode_ops; | |
de855c5d AM |
21761 | diff -urNp linux-2.6.29.6/fs/ocfs2/localalloc.c linux-2.6.29.6/fs/ocfs2/localalloc.c |
21762 | --- linux-2.6.29.6/fs/ocfs2/localalloc.c 2009-07-02 19:41:20.000000000 -0400 | |
21763 | +++ linux-2.6.29.6/fs/ocfs2/localalloc.c 2009-07-09 22:13:39.000000000 -0400 | |
21764 | @@ -1272,7 +1272,7 @@ static int ocfs2_local_alloc_slide_windo | |
21765 | goto bail; | |
21766 | } | |
21767 | ||
21768 | - atomic_inc(&osb->alloc_stats.moves); | |
21769 | + atomic_inc_unchecked(&osb->alloc_stats.moves); | |
21770 | ||
21771 | status = 0; | |
21772 | bail: | |
21773 | diff -urNp linux-2.6.29.6/fs/ocfs2/ocfs2.h linux-2.6.29.6/fs/ocfs2/ocfs2.h | |
21774 | --- linux-2.6.29.6/fs/ocfs2/ocfs2.h 2009-07-02 19:41:20.000000000 -0400 | |
21775 | +++ linux-2.6.29.6/fs/ocfs2/ocfs2.h 2009-07-09 22:13:39.000000000 -0400 | |
21776 | @@ -168,11 +168,11 @@ enum ocfs2_vol_state | |
21777 | ||
21778 | struct ocfs2_alloc_stats | |
21779 | { | |
21780 | - atomic_t moves; | |
21781 | - atomic_t local_data; | |
21782 | - atomic_t bitmap_data; | |
21783 | - atomic_t bg_allocs; | |
21784 | - atomic_t bg_extends; | |
21785 | + atomic_unchecked_t moves; | |
21786 | + atomic_unchecked_t local_data; | |
21787 | + atomic_unchecked_t bitmap_data; | |
21788 | + atomic_unchecked_t bg_allocs; | |
21789 | + atomic_unchecked_t bg_extends; | |
21790 | }; | |
21791 | ||
21792 | enum ocfs2_local_alloc_state | |
21793 | diff -urNp linux-2.6.29.6/fs/ocfs2/suballoc.c linux-2.6.29.6/fs/ocfs2/suballoc.c | |
21794 | --- linux-2.6.29.6/fs/ocfs2/suballoc.c 2009-07-02 19:41:20.000000000 -0400 | |
21795 | +++ linux-2.6.29.6/fs/ocfs2/suballoc.c 2009-07-09 22:13:39.000000000 -0400 | |
21796 | @@ -602,7 +602,7 @@ static int ocfs2_reserve_suballoc_bits(s | |
21797 | mlog_errno(status); | |
21798 | goto bail; | |
21799 | } | |
21800 | - atomic_inc(&osb->alloc_stats.bg_extends); | |
21801 | + atomic_inc_unchecked(&osb->alloc_stats.bg_extends); | |
21802 | ||
21803 | /* You should never ask for this much metadata */ | |
21804 | BUG_ON(bits_wanted > | |
21805 | @@ -1608,7 +1608,7 @@ int ocfs2_claim_metadata(struct ocfs2_su | |
21806 | mlog_errno(status); | |
21807 | goto bail; | |
21808 | } | |
21809 | - atomic_inc(&osb->alloc_stats.bg_allocs); | |
21810 | + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs); | |
21811 | ||
21812 | *blkno_start = bg_blkno + (u64) *suballoc_bit_start; | |
21813 | ac->ac_bits_given += (*num_bits); | |
21814 | @@ -1647,7 +1647,7 @@ int ocfs2_claim_new_inode(struct ocfs2_s | |
21815 | mlog_errno(status); | |
21816 | goto bail; | |
21817 | } | |
21818 | - atomic_inc(&osb->alloc_stats.bg_allocs); | |
21819 | + atomic_inc_unchecked(&osb->alloc_stats.bg_allocs); | |
21820 | ||
21821 | BUG_ON(num_bits != 1); | |
21822 | ||
21823 | @@ -1748,7 +1748,7 @@ int __ocfs2_claim_clusters(struct ocfs2_ | |
21824 | cluster_start, | |
21825 | num_clusters); | |
21826 | if (!status) | |
21827 | - atomic_inc(&osb->alloc_stats.local_data); | |
21828 | + atomic_inc_unchecked(&osb->alloc_stats.local_data); | |
21829 | } else { | |
21830 | if (min_clusters > (osb->bitmap_cpg - 1)) { | |
21831 | /* The only paths asking for contiguousness | |
21832 | @@ -1776,7 +1776,7 @@ int __ocfs2_claim_clusters(struct ocfs2_ | |
21833 | ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode, | |
21834 | bg_blkno, | |
21835 | bg_bit_off); | |
21836 | - atomic_inc(&osb->alloc_stats.bitmap_data); | |
21837 | + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data); | |
21838 | } | |
21839 | } | |
21840 | if (status < 0) { | |
21841 | diff -urNp linux-2.6.29.6/fs/open.c linux-2.6.29.6/fs/open.c | |
21842 | --- linux-2.6.29.6/fs/open.c 2009-07-02 19:41:20.000000000 -0400 | |
21843 | +++ linux-2.6.29.6/fs/open.c 2009-07-09 22:13:39.000000000 -0400 | |
21844 | @@ -205,6 +205,9 @@ int do_truncate(struct dentry *dentry, l | |
2380c486 JR |
21845 | if (length < 0) |
21846 | return -EINVAL; | |
21847 | ||
21848 | + if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt)) | |
21849 | + return -EACCES; | |
21850 | + | |
21851 | newattrs.ia_size = length; | |
21852 | newattrs.ia_valid = ATTR_SIZE | time_attrs; | |
21853 | if (filp) { | |
de855c5d | 21854 | @@ -509,6 +512,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con |
2380c486 JR |
21855 | if (__mnt_is_readonly(path.mnt)) |
21856 | res = -EROFS; | |
21857 | ||
21858 | + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode)) | |
21859 | + res = -EACCES; | |
21860 | + | |
21861 | out_path_release: | |
21862 | path_put(&path); | |
21863 | out: | |
de855c5d | 21864 | @@ -535,6 +541,8 @@ SYSCALL_DEFINE1(chdir, const char __user |
2380c486 JR |
21865 | if (error) |
21866 | goto dput_and_out; | |
21867 | ||
21868 | + gr_log_chdir(path.dentry, path.mnt); | |
21869 | + | |
21870 | set_fs_pwd(current->fs, &path); | |
21871 | ||
21872 | dput_and_out: | |
de855c5d | 21873 | @@ -561,6 +569,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd |
2380c486 JR |
21874 | goto out_putf; |
21875 | ||
21876 | error = inode_permission(inode, MAY_EXEC | MAY_ACCESS); | |
21877 | + | |
21878 | + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt)) | |
21879 | + error = -EPERM; | |
21880 | + | |
21881 | + if (!error) | |
21882 | + gr_log_chdir(file->f_path.dentry, file->f_path.mnt); | |
21883 | + | |
21884 | if (!error) | |
21885 | set_fs_pwd(current->fs, &file->f_path); | |
21886 | out_putf: | |
de855c5d | 21887 | @@ -586,7 +601,18 @@ SYSCALL_DEFINE1(chroot, const char __use |
2380c486 JR |
21888 | if (!capable(CAP_SYS_CHROOT)) |
21889 | goto dput_and_out; | |
21890 | ||
21891 | + if (gr_handle_chroot_chroot(path.dentry, path.mnt)) | |
21892 | + goto dput_and_out; | |
21893 | + | |
21894 | + if (gr_handle_chroot_caps(&path)) { | |
21895 | + error = -ENOMEM; | |
21896 | + goto dput_and_out; | |
21897 | + } | |
21898 | + | |
21899 | set_fs_root(current->fs, &path); | |
21900 | + | |
21901 | + gr_handle_chroot_chdir(&path); | |
21902 | + | |
21903 | error = 0; | |
21904 | dput_and_out: | |
21905 | path_put(&path); | |
de855c5d | 21906 | @@ -614,13 +640,28 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd |
2380c486 JR |
21907 | err = mnt_want_write(file->f_path.mnt); |
21908 | if (err) | |
21909 | goto out_putf; | |
21910 | + | |
21911 | + if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) { | |
21912 | + err = -EACCES; | |
21913 | + goto out_drop_write; | |
21914 | + } | |
21915 | + | |
21916 | mutex_lock(&inode->i_mutex); | |
21917 | if (mode == (mode_t) -1) | |
21918 | mode = inode->i_mode; | |
21919 | + | |
21920 | + if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) { | |
21921 | + err = -EPERM; | |
21922 | + mutex_unlock(&inode->i_mutex); | |
21923 | + goto out_drop_write; | |
21924 | + } | |
21925 | + | |
21926 | newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); | |
21927 | newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; | |
21928 | err = notify_change(dentry, &newattrs); | |
21929 | mutex_unlock(&inode->i_mutex); | |
21930 | + | |
21931 | +out_drop_write: | |
21932 | mnt_drop_write(file->f_path.mnt); | |
21933 | out_putf: | |
21934 | fput(file); | |
de855c5d | 21935 | @@ -643,13 +684,28 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons |
2380c486 JR |
21936 | error = mnt_want_write(path.mnt); |
21937 | if (error) | |
21938 | goto dput_and_out; | |
21939 | + | |
21940 | + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) { | |
21941 | + error = -EACCES; | |
21942 | + goto out_drop_write; | |
21943 | + } | |
21944 | + | |
21945 | mutex_lock(&inode->i_mutex); | |
21946 | if (mode == (mode_t) -1) | |
21947 | mode = inode->i_mode; | |
21948 | + | |
21949 | + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) { | |
21950 | + error = -EACCES; | |
21951 | + mutex_unlock(&inode->i_mutex); | |
21952 | + goto out_drop_write; | |
21953 | + } | |
21954 | + | |
21955 | newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); | |
21956 | newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; | |
21957 | error = notify_change(path.dentry, &newattrs); | |
21958 | mutex_unlock(&inode->i_mutex); | |
21959 | + | |
21960 | +out_drop_write: | |
21961 | mnt_drop_write(path.mnt); | |
21962 | dput_and_out: | |
21963 | path_put(&path); | |
de855c5d | 21964 | @@ -662,12 +718,15 @@ SYSCALL_DEFINE2(chmod, const char __user |
2380c486 JR |
21965 | return sys_fchmodat(AT_FDCWD, filename, mode); |
21966 | } | |
21967 | ||
21968 | -static int chown_common(struct dentry * dentry, uid_t user, gid_t group) | |
21969 | +static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt) | |
21970 | { | |
21971 | struct inode *inode = dentry->d_inode; | |
21972 | int error; | |
21973 | struct iattr newattrs; | |
21974 | ||
21975 | + if (!gr_acl_handle_chown(dentry, mnt)) | |
21976 | + return -EACCES; | |
21977 | + | |
21978 | newattrs.ia_valid = ATTR_CTIME; | |
21979 | if (user != (uid_t) -1) { | |
21980 | newattrs.ia_valid |= ATTR_UID; | |
de855c5d AM |
21981 | @@ -698,7 +757,7 @@ SYSCALL_DEFINE3(chown, const char __user |
21982 | error = mnt_want_write(path.mnt); | |
21983 | if (error) | |
21984 | goto out_release; | |
21985 | - error = chown_common(path.dentry, user, group); | |
21986 | + error = chown_common(path.dentry, user, group, path.mnt); | |
2380c486 JR |
21987 | mnt_drop_write(path.mnt); |
21988 | out_release: | |
21989 | path_put(&path); | |
de855c5d AM |
21990 | @@ -723,7 +782,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons |
21991 | error = mnt_want_write(path.mnt); | |
21992 | if (error) | |
21993 | goto out_release; | |
21994 | - error = chown_common(path.dentry, user, group); | |
21995 | + error = chown_common(path.dentry, user, group, path.mnt); | |
2380c486 JR |
21996 | mnt_drop_write(path.mnt); |
21997 | out_release: | |
21998 | path_put(&path); | |
de855c5d AM |
21999 | @@ -742,7 +801,7 @@ SYSCALL_DEFINE3(lchown, const char __use |
22000 | error = mnt_want_write(path.mnt); | |
22001 | if (error) | |
22002 | goto out_release; | |
22003 | - error = chown_common(path.dentry, user, group); | |
22004 | + error = chown_common(path.dentry, user, group, path.mnt); | |
2380c486 JR |
22005 | mnt_drop_write(path.mnt); |
22006 | out_release: | |
22007 | path_put(&path); | |
de855c5d | 22008 | @@ -765,7 +824,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd |
2380c486 JR |
22009 | goto out_fput; |
22010 | dentry = file->f_path.dentry; | |
22011 | audit_inode(NULL, dentry); | |
22012 | - error = chown_common(dentry, user, group); | |
22013 | + error = chown_common(dentry, user, group, file->f_path.mnt); | |
22014 | mnt_drop_write(file->f_path.mnt); | |
22015 | out_fput: | |
22016 | fput(file); | |
de855c5d AM |
22017 | diff -urNp linux-2.6.29.6/fs/pipe.c linux-2.6.29.6/fs/pipe.c |
22018 | --- linux-2.6.29.6/fs/pipe.c 2009-07-02 19:41:20.000000000 -0400 | |
22019 | +++ linux-2.6.29.6/fs/pipe.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22020 | @@ -848,7 +848,7 @@ void free_pipe_info(struct inode *inode) |
22021 | inode->i_pipe = NULL; | |
22022 | } | |
22023 | ||
22024 | -static struct vfsmount *pipe_mnt __read_mostly; | |
22025 | +struct vfsmount *pipe_mnt __read_mostly; | |
22026 | static int pipefs_delete_dentry(struct dentry *dentry) | |
22027 | { | |
22028 | /* | |
de855c5d AM |
22029 | diff -urNp linux-2.6.29.6/fs/proc/array.c linux-2.6.29.6/fs/proc/array.c |
22030 | --- linux-2.6.29.6/fs/proc/array.c 2009-07-02 19:41:20.000000000 -0400 | |
22031 | +++ linux-2.6.29.6/fs/proc/array.c 2009-07-09 22:13:39.000000000 -0400 | |
22032 | @@ -321,6 +321,21 @@ static inline void task_context_switch_c | |
2380c486 JR |
22033 | p->nivcsw); |
22034 | } | |
22035 | ||
22036 | +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
22037 | +static inline void task_pax(struct seq_file *m, struct task_struct *p) | |
22038 | +{ | |
22039 | + if (p->mm) | |
22040 | + seq_printf(m, "PaX:\t%c%c%c%c%c\n", | |
22041 | + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p', | |
22042 | + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e', | |
22043 | + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm', | |
22044 | + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r', | |
22045 | + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's'); | |
22046 | + else | |
22047 | + seq_printf(m, "PaX:\t-----\n"); | |
22048 | +} | |
22049 | +#endif | |
22050 | + | |
22051 | int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, | |
22052 | struct pid *pid, struct task_struct *task) | |
22053 | { | |
de855c5d | 22054 | @@ -340,9 +355,20 @@ int proc_pid_status(struct seq_file *m, |
2380c486 JR |
22055 | task_show_regs(m, task); |
22056 | #endif | |
22057 | task_context_switch_counts(m, task); | |
22058 | + | |
22059 | +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
22060 | + task_pax(m, task); | |
22061 | +#endif | |
22062 | + | |
22063 | return 0; | |
22064 | } | |
22065 | ||
22066 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22067 | +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \ | |
22068 | + (_mm->pax_flags & MF_PAX_RANDMMAP || \ | |
22069 | + _mm->pax_flags & MF_PAX_SEGMEXEC)) | |
22070 | +#endif | |
22071 | + | |
22072 | static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, | |
22073 | struct pid *pid, struct task_struct *task, int whole) | |
22074 | { | |
de855c5d | 22075 | @@ -439,6 +465,19 @@ static int do_task_stat(struct seq_file |
2380c486 JR |
22076 | gtime = task_gtime(task); |
22077 | } | |
22078 | ||
22079 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22080 | + if (PAX_RAND_FLAGS(mm)) { | |
22081 | + eip = 0; | |
22082 | + esp = 0; | |
22083 | + wchan = 0; | |
22084 | + } | |
22085 | +#endif | |
22086 | +#ifdef CONFIG_GRKERNSEC_HIDESYM | |
22087 | + wchan = 0; | |
22088 | + eip =0; | |
22089 | + esp =0; | |
22090 | +#endif | |
22091 | + | |
22092 | /* scale priority and nice values from timeslices to -20..20 */ | |
22093 | /* to make it look like a "normal" Unix priority/nice value */ | |
22094 | priority = task_prio(task); | |
de855c5d | 22095 | @@ -479,9 +518,15 @@ static int do_task_stat(struct seq_file |
2380c486 JR |
22096 | vsize, |
22097 | mm ? get_mm_rss(mm) : 0, | |
22098 | rsslim, | |
22099 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22100 | + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0), | |
22101 | + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0), | |
de855c5d | 22102 | + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0), |
2380c486 JR |
22103 | +#else |
22104 | mm ? mm->start_code : 0, | |
22105 | mm ? mm->end_code : 0, | |
de855c5d | 22106 | (permitted && mm) ? mm->start_stack : 0, |
2380c486 JR |
22107 | +#endif |
22108 | esp, | |
22109 | eip, | |
22110 | /* The signal information here is obsolete. | |
de855c5d | 22111 | @@ -534,3 +579,10 @@ int proc_pid_statm(struct seq_file *m, s |
2380c486 JR |
22112 | |
22113 | return 0; | |
22114 | } | |
22115 | + | |
22116 | +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR | |
22117 | +int proc_pid_ipaddr(struct task_struct *task, char *buffer) | |
22118 | +{ | |
22119 | + return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip)); | |
22120 | +} | |
22121 | +#endif | |
de855c5d AM |
22122 | diff -urNp linux-2.6.29.6/fs/proc/base.c linux-2.6.29.6/fs/proc/base.c |
22123 | --- linux-2.6.29.6/fs/proc/base.c 2009-07-02 19:41:20.000000000 -0400 | |
22124 | +++ linux-2.6.29.6/fs/proc/base.c 2009-07-09 22:13:39.000000000 -0400 | |
22125 | @@ -212,6 +212,9 @@ static int check_mem_permission(struct t | |
2380c486 JR |
22126 | if (task == current) |
22127 | return 0; | |
22128 | ||
22129 | + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task)) | |
22130 | + return -EPERM; | |
22131 | + | |
22132 | /* | |
22133 | * If current is actively ptrace'ing, and would also be | |
22134 | * permitted to freshly attach with ptrace now, permit it. | |
de855c5d AM |
22135 | @@ -262,6 +265,9 @@ static int proc_pid_cmdline(struct task_ |
22136 | if (!mm->arg_end) | |
22137 | goto out_mm; /* Shh! No looking before we're done */ | |
22138 | ||
22139 | + if (gr_acl_handle_procpidmem(task)) | |
22140 | + goto out_mm; | |
22141 | + | |
22142 | len = mm->arg_end - mm->arg_start; | |
22143 | ||
22144 | if (len > PAGE_SIZE) | |
22145 | @@ -289,12 +295,26 @@ out: | |
2380c486 JR |
22146 | return res; |
22147 | } | |
22148 | ||
22149 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22150 | +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \ | |
22151 | + (_mm->pax_flags & MF_PAX_RANDMMAP || \ | |
22152 | + _mm->pax_flags & MF_PAX_SEGMEXEC)) | |
22153 | +#endif | |
22154 | + | |
22155 | static int proc_pid_auxv(struct task_struct *task, char *buffer) | |
22156 | { | |
22157 | int res = 0; | |
22158 | struct mm_struct *mm = get_task_mm(task); | |
22159 | if (mm) { | |
22160 | unsigned int nwords = 0; | |
22161 | + | |
22162 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22163 | + if (PAX_RAND_FLAGS(mm)) { | |
22164 | + mmput(mm); | |
22165 | + return res; | |
22166 | + } | |
22167 | +#endif | |
22168 | + | |
22169 | do { | |
22170 | nwords += 2; | |
22171 | } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */ | |
de855c5d AM |
22172 | @@ -330,7 +350,7 @@ static int proc_pid_wchan(struct task_st |
22173 | } | |
22174 | #endif /* CONFIG_KALLSYMS */ | |
22175 | ||
22176 | -#ifdef CONFIG_STACKTRACE | |
22177 | +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM) | |
22178 | ||
22179 | #define MAX_STACK_TRACE_DEPTH 64 | |
22180 | ||
22181 | @@ -523,7 +543,7 @@ static int proc_pid_limits(struct task_s | |
2380c486 JR |
22182 | return count; |
22183 | } | |
22184 | ||
22185 | -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK | |
22186 | +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP) | |
22187 | static int proc_pid_syscall(struct task_struct *task, char *buffer) | |
22188 | { | |
22189 | long nr; | |
de855c5d AM |
22190 | @@ -937,6 +957,9 @@ static ssize_t environ_read(struct file |
22191 | if (!task) | |
22192 | goto out_no_task; | |
22193 | ||
22194 | + if (gr_acl_handle_procpidmem(task)) | |
22195 | + goto out; | |
22196 | + | |
22197 | if (!ptrace_may_access(task, PTRACE_MODE_READ)) | |
22198 | goto out; | |
22199 | ||
22200 | @@ -1440,7 +1463,11 @@ static struct inode *proc_pid_make_inode | |
2380c486 JR |
22201 | rcu_read_lock(); |
22202 | cred = __task_cred(task); | |
22203 | inode->i_uid = cred->euid; | |
22204 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP | |
22205 | + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID; | |
22206 | +#else | |
22207 | inode->i_gid = cred->egid; | |
22208 | +#endif | |
22209 | rcu_read_unlock(); | |
22210 | } | |
de855c5d AM |
22211 | security_task_to_inode(task, inode); |
22212 | @@ -1458,6 +1485,9 @@ static int pid_getattr(struct vfsmount * | |
2380c486 JR |
22213 | struct inode *inode = dentry->d_inode; |
22214 | struct task_struct *task; | |
22215 | const struct cred *cred; | |
22216 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22217 | + const struct cred *tmpcred = current_cred(); | |
22218 | +#endif | |
22219 | ||
22220 | generic_fillattr(inode, stat); | |
22221 | ||
de855c5d | 22222 | @@ -1465,12 +1495,34 @@ static int pid_getattr(struct vfsmount * |
2380c486 JR |
22223 | stat->uid = 0; |
22224 | stat->gid = 0; | |
22225 | task = pid_task(proc_pid(inode), PIDTYPE_PID); | |
22226 | + | |
22227 | + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) { | |
22228 | + rcu_read_unlock(); | |
22229 | + return -ENOENT; | |
22230 | + } | |
22231 | + | |
22232 | if (task) { | |
22233 | + cred = __task_cred(task); | |
22234 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22235 | + if (!tmpcred->uid || (tmpcred->uid == cred->uid) | |
22236 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP | |
22237 | + || in_group_p(CONFIG_GRKERNSEC_PROC_GID) | |
22238 | +#endif | |
22239 | + ) | |
22240 | +#endif | |
22241 | if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) || | |
22242 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
22243 | + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) || | |
22244 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22245 | + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) || | |
22246 | +#endif | |
22247 | task_dumpable(task)) { | |
22248 | - cred = __task_cred(task); | |
22249 | stat->uid = cred->euid; | |
22250 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP | |
22251 | + stat->gid = CONFIG_GRKERNSEC_PROC_GID; | |
22252 | +#else | |
22253 | stat->gid = cred->egid; | |
22254 | +#endif | |
22255 | } | |
22256 | } | |
22257 | rcu_read_unlock(); | |
de855c5d | 22258 | @@ -1502,11 +1554,20 @@ static int pid_revalidate(struct dentry |
2380c486 JR |
22259 | |
22260 | if (task) { | |
22261 | if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) || | |
22262 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
22263 | + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) || | |
22264 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22265 | + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) || | |
22266 | +#endif | |
22267 | task_dumpable(task)) { | |
22268 | rcu_read_lock(); | |
22269 | cred = __task_cred(task); | |
22270 | inode->i_uid = cred->euid; | |
22271 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP | |
22272 | + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID; | |
22273 | +#else | |
22274 | inode->i_gid = cred->egid; | |
22275 | +#endif | |
22276 | rcu_read_unlock(); | |
22277 | } else { | |
22278 | inode->i_uid = 0; | |
de855c5d AM |
22279 | @@ -1627,7 +1688,8 @@ static int proc_fd_info(struct inode *in |
22280 | int fd = proc_fd(inode); | |
22281 | ||
22282 | if (task) { | |
22283 | - files = get_files_struct(task); | |
22284 | + if (!gr_acl_handle_procpidmem(task)) | |
22285 | + files = get_files_struct(task); | |
22286 | put_task_struct(task); | |
22287 | } | |
22288 | if (files) { | |
22289 | @@ -1879,12 +1941,22 @@ static const struct file_operations proc | |
2380c486 JR |
22290 | static int proc_fd_permission(struct inode *inode, int mask) |
22291 | { | |
22292 | int rv; | |
22293 | + struct task_struct *task; | |
22294 | ||
22295 | rv = generic_permission(inode, mask, NULL); | |
22296 | - if (rv == 0) | |
22297 | - return 0; | |
22298 | + | |
22299 | if (task_pid(current) == proc_pid(inode)) | |
22300 | rv = 0; | |
22301 | + | |
22302 | + task = get_proc_task(inode); | |
22303 | + if (task == NULL) | |
22304 | + return rv; | |
22305 | + | |
22306 | + if (gr_acl_handle_procpidmem(task)) | |
22307 | + rv = -EACCES; | |
22308 | + | |
22309 | + put_task_struct(task); | |
22310 | + | |
22311 | return rv; | |
22312 | } | |
22313 | ||
de855c5d AM |
22314 | @@ -1993,6 +2065,9 @@ static struct dentry *proc_pident_lookup |
22315 | if (!task) | |
22316 | goto out_no_task; | |
2380c486 JR |
22317 | |
22318 | + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task)) | |
22319 | + goto out; | |
22320 | + | |
22321 | /* | |
22322 | * Yes, it does not scale. And it should not. Don't add | |
22323 | * new entries into /proc/<tgid>/ without very good reasons. | |
de855c5d | 22324 | @@ -2037,6 +2112,9 @@ static int proc_pident_readdir(struct fi |
2380c486 JR |
22325 | if (!task) |
22326 | goto out_no_task; | |
22327 | ||
22328 | + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task)) | |
22329 | + goto out; | |
22330 | + | |
22331 | ret = 0; | |
22332 | i = filp->f_pos; | |
22333 | switch (i) { | |
de855c5d | 22334 | @@ -2397,6 +2475,9 @@ static struct dentry *proc_base_lookup(s |
2380c486 JR |
22335 | if (p > last) |
22336 | goto out; | |
22337 | ||
22338 | + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task)) | |
22339 | + goto out; | |
22340 | + | |
22341 | error = proc_base_instantiate(dir, dentry, task, p); | |
22342 | ||
22343 | out: | |
de855c5d | 22344 | @@ -2483,7 +2564,7 @@ static const struct pid_entry tgid_base_ |
2380c486 JR |
22345 | #ifdef CONFIG_SCHED_DEBUG |
22346 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), | |
22347 | #endif | |
22348 | -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK | |
22349 | +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP) | |
22350 | INF("syscall", S_IRUSR, proc_pid_syscall), | |
22351 | #endif | |
22352 | INF("cmdline", S_IRUGO, proc_pid_cmdline), | |
de855c5d AM |
22353 | @@ -2511,7 +2592,7 @@ static const struct pid_entry tgid_base_ |
22354 | #ifdef CONFIG_KALLSYMS | |
22355 | INF("wchan", S_IRUGO, proc_pid_wchan), | |
22356 | #endif | |
22357 | -#ifdef CONFIG_STACKTRACE | |
22358 | +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM) | |
22359 | ONE("stack", S_IRUSR, proc_pid_stack), | |
22360 | #endif | |
22361 | #ifdef CONFIG_SCHEDSTATS | |
22362 | @@ -2541,6 +2622,9 @@ static const struct pid_entry tgid_base_ | |
22363 | #ifdef CONFIG_TASK_IO_ACCOUNTING | |
22364 | INF("io", S_IRUGO, proc_tgid_io_accounting), | |
22365 | #endif | |
22366 | +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR | |
22367 | + INF("ipaddr", S_IRUSR, proc_pid_ipaddr), | |
22368 | +#endif | |
22369 | }; | |
22370 | ||
22371 | static int proc_tgid_base_readdir(struct file * filp, | |
22372 | @@ -2670,7 +2754,14 @@ static struct dentry *proc_pid_instantia | |
2380c486 JR |
22373 | if (!inode) |
22374 | goto out; | |
22375 | ||
22376 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
22377 | + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR; | |
22378 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22379 | + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID; | |
22380 | + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP; | |
22381 | +#else | |
22382 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; | |
22383 | +#endif | |
22384 | inode->i_op = &proc_tgid_base_inode_operations; | |
22385 | inode->i_fop = &proc_tgid_base_operations; | |
22386 | inode->i_flags|=S_IMMUTABLE; | |
de855c5d | 22387 | @@ -2712,7 +2803,11 @@ struct dentry *proc_pid_lookup(struct in |
2380c486 JR |
22388 | if (!task) |
22389 | goto out; | |
3f74aa08 | 22390 | |
2380c486 JR |
22391 | + if (gr_check_hidden_task(task)) |
22392 | + goto out_put_task; | |
3f74aa08 | 22393 | + |
2380c486 JR |
22394 | result = proc_pid_instantiate(dir, dentry, task, NULL); |
22395 | +out_put_task: | |
22396 | put_task_struct(task); | |
22397 | out: | |
22398 | return result; | |
de855c5d | 22399 | @@ -2777,6 +2872,10 @@ int proc_pid_readdir(struct file * filp, |
2380c486 JR |
22400 | { |
22401 | unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; | |
de855c5d | 22402 | struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode); |
2380c486 JR |
22403 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) |
22404 | + const struct cred *tmpcred = current_cred(); | |
22405 | + const struct cred *itercred; | |
22406 | +#endif | |
22407 | struct tgid_iter iter; | |
22408 | struct pid_namespace *ns; | |
22409 | ||
de855c5d | 22410 | @@ -2795,6 +2894,20 @@ int proc_pid_readdir(struct file * filp, |
2380c486 JR |
22411 | for (iter = next_tgid(ns, iter); |
22412 | iter.task; | |
22413 | iter.tgid += 1, iter = next_tgid(ns, iter)) { | |
22414 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22415 | + itercred = __task_cred(iter.task); | |
22416 | +#endif | |
22417 | + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task) | |
22418 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
de855c5d | 22419 | + || (tmpcred->uid && (itercred->uid != tmpcred->uid) |
2380c486 | 22420 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP |
de855c5d | 22421 | + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID) |
2380c486 | 22422 | +#endif |
de855c5d | 22423 | + ) |
2380c486 | 22424 | +#endif |
de855c5d | 22425 | + ) |
2380c486 JR |
22426 | + continue; |
22427 | + | |
22428 | filp->f_pos = iter.tgid + TGID_OFFSET; | |
de855c5d AM |
22429 | if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) { |
22430 | put_task_struct(iter.task); | |
22431 | @@ -2822,7 +2935,7 @@ static const struct pid_entry tid_base_s | |
22432 | #ifdef CONFIG_SCHED_DEBUG | |
22433 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), | |
2380c486 | 22434 | #endif |
de855c5d AM |
22435 | -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK |
22436 | +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP) | |
22437 | INF("syscall", S_IRUSR, proc_pid_syscall), | |
22438 | #endif | |
22439 | INF("cmdline", S_IRUGO, proc_pid_cmdline), | |
22440 | @@ -2849,7 +2962,7 @@ static const struct pid_entry tid_base_s | |
22441 | #ifdef CONFIG_KALLSYMS | |
22442 | INF("wchan", S_IRUGO, proc_pid_wchan), | |
22443 | #endif | |
22444 | -#ifdef CONFIG_STACKTRACE | |
22445 | +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM) | |
22446 | ONE("stack", S_IRUSR, proc_pid_stack), | |
22447 | #endif | |
22448 | #ifdef CONFIG_SCHEDSTATS | |
22449 | diff -urNp linux-2.6.29.6/fs/proc/cmdline.c linux-2.6.29.6/fs/proc/cmdline.c | |
22450 | --- linux-2.6.29.6/fs/proc/cmdline.c 2009-07-02 19:41:20.000000000 -0400 | |
22451 | +++ linux-2.6.29.6/fs/proc/cmdline.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22452 | @@ -23,7 +23,11 @@ static const struct file_operations cmdl |
22453 | ||
22454 | static int __init proc_cmdline_init(void) | |
22455 | { | |
22456 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
22457 | + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops); | |
22458 | +#else | |
22459 | proc_create("cmdline", 0, NULL, &cmdline_proc_fops); | |
22460 | +#endif | |
22461 | return 0; | |
22462 | } | |
22463 | module_init(proc_cmdline_init); | |
de855c5d AM |
22464 | diff -urNp linux-2.6.29.6/fs/proc/devices.c linux-2.6.29.6/fs/proc/devices.c |
22465 | --- linux-2.6.29.6/fs/proc/devices.c 2009-07-02 19:41:20.000000000 -0400 | |
22466 | +++ linux-2.6.29.6/fs/proc/devices.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22467 | @@ -64,7 +64,11 @@ static const struct file_operations proc |
22468 | ||
22469 | static int __init proc_devices_init(void) | |
22470 | { | |
22471 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
22472 | + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations); | |
22473 | +#else | |
22474 | proc_create("devices", 0, NULL, &proc_devinfo_operations); | |
22475 | +#endif | |
22476 | return 0; | |
22477 | } | |
22478 | module_init(proc_devices_init); | |
de855c5d AM |
22479 | diff -urNp linux-2.6.29.6/fs/proc/inode.c linux-2.6.29.6/fs/proc/inode.c |
22480 | --- linux-2.6.29.6/fs/proc/inode.c 2009-07-02 19:41:20.000000000 -0400 | |
22481 | +++ linux-2.6.29.6/fs/proc/inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22482 | @@ -463,7 +463,11 @@ struct inode *proc_get_inode(struct supe |
22483 | if (de->mode) { | |
22484 | inode->i_mode = de->mode; | |
22485 | inode->i_uid = de->uid; | |
22486 | +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP | |
22487 | + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID; | |
22488 | +#else | |
22489 | inode->i_gid = de->gid; | |
22490 | +#endif | |
22491 | } | |
22492 | if (de->size) | |
22493 | inode->i_size = de->size; | |
de855c5d AM |
22494 | diff -urNp linux-2.6.29.6/fs/proc/internal.h linux-2.6.29.6/fs/proc/internal.h |
22495 | --- linux-2.6.29.6/fs/proc/internal.h 2009-07-02 19:41:20.000000000 -0400 | |
22496 | +++ linux-2.6.29.6/fs/proc/internal.h 2009-07-09 22:13:39.000000000 -0400 | |
22497 | @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi | |
2380c486 | 22498 | struct pid *pid, struct task_struct *task); |
de855c5d | 22499 | extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, |
2380c486 JR |
22500 | struct pid *pid, struct task_struct *task); |
22501 | +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR | |
22502 | +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer); | |
22503 | +#endif | |
2380c486 JR |
22504 | extern loff_t mem_lseek(struct file *file, loff_t offset, int orig); |
22505 | ||
de855c5d AM |
22506 | extern const struct file_operations proc_maps_operations; |
22507 | diff -urNp linux-2.6.29.6/fs/proc/Kconfig linux-2.6.29.6/fs/proc/Kconfig | |
22508 | --- linux-2.6.29.6/fs/proc/Kconfig 2009-07-02 19:41:20.000000000 -0400 | |
22509 | +++ linux-2.6.29.6/fs/proc/Kconfig 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22510 | @@ -30,12 +30,12 @@ config PROC_FS |
22511 | ||
22512 | config PROC_KCORE | |
22513 | bool "/proc/kcore support" if !ARM | |
22514 | - depends on PROC_FS && MMU | |
22515 | + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD | |
22516 | ||
22517 | config PROC_VMCORE | |
22518 | bool "/proc/vmcore support (EXPERIMENTAL)" | |
22519 | - depends on PROC_FS && CRASH_DUMP | |
22520 | - default y | |
22521 | + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC | |
22522 | + default n | |
22523 | help | |
22524 | Exports the dump image of crashed kernel in ELF format. | |
22525 | ||
22526 | @@ -59,8 +59,8 @@ config PROC_SYSCTL | |
22527 | limited in memory. | |
22528 | ||
22529 | config PROC_PAGE_MONITOR | |
22530 | - default y | |
22531 | - depends on PROC_FS && MMU | |
22532 | + default n | |
22533 | + depends on PROC_FS && MMU && !GRKERNSEC | |
22534 | bool "Enable /proc page monitoring" if EMBEDDED | |
22535 | help | |
22536 | Various /proc files exist to monitor process memory utilization: | |
de855c5d AM |
22537 | diff -urNp linux-2.6.29.6/fs/proc/kcore.c linux-2.6.29.6/fs/proc/kcore.c |
22538 | --- linux-2.6.29.6/fs/proc/kcore.c 2009-07-02 19:41:20.000000000 -0400 | |
22539 | +++ linux-2.6.29.6/fs/proc/kcore.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22540 | @@ -404,10 +404,12 @@ read_kcore(struct file *file, char __use |
22541 | ||
22542 | static int __init proc_kcore_init(void) | |
22543 | { | |
22544 | +#if !defined(CONFIG_GRKERNSEC_PROC_ADD) | |
22545 | proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations); | |
22546 | if (proc_root_kcore) | |
22547 | proc_root_kcore->size = | |
22548 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; | |
22549 | +#endif | |
22550 | return 0; | |
22551 | } | |
22552 | module_init(proc_kcore_init); | |
de855c5d AM |
22553 | diff -urNp linux-2.6.29.6/fs/proc/nommu.c linux-2.6.29.6/fs/proc/nommu.c |
22554 | --- linux-2.6.29.6/fs/proc/nommu.c 2009-07-02 19:41:20.000000000 -0400 | |
22555 | +++ linux-2.6.29.6/fs/proc/nommu.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22556 | @@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_ |
22557 | if (len < 1) | |
22558 | len = 1; | |
22559 | seq_printf(m, "%*c", len, ' '); | |
22560 | - seq_path(m, &file->f_path, ""); | |
22561 | + seq_path(m, &file->f_path, "\n\\"); | |
22562 | } | |
22563 | ||
22564 | seq_putc(m, '\n'); | |
de855c5d AM |
22565 | diff -urNp linux-2.6.29.6/fs/proc/proc_net.c linux-2.6.29.6/fs/proc/proc_net.c |
22566 | --- linux-2.6.29.6/fs/proc/proc_net.c 2009-07-02 19:41:20.000000000 -0400 | |
22567 | +++ linux-2.6.29.6/fs/proc/proc_net.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22568 | @@ -104,6 +104,17 @@ static struct net *get_proc_task_net(str |
22569 | struct task_struct *task; | |
22570 | struct nsproxy *ns; | |
22571 | struct net *net = NULL; | |
22572 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22573 | + const struct cred *cred = current_cred(); | |
22574 | +#endif | |
22575 | + | |
22576 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
22577 | + if (cred->fsuid) | |
22578 | + return net; | |
22579 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22580 | + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)) | |
22581 | + return net; | |
22582 | +#endif | |
22583 | ||
22584 | rcu_read_lock(); | |
22585 | task = pid_task(proc_pid(dir), PIDTYPE_PID); | |
de855c5d AM |
22586 | diff -urNp linux-2.6.29.6/fs/proc/proc_sysctl.c linux-2.6.29.6/fs/proc/proc_sysctl.c |
22587 | --- linux-2.6.29.6/fs/proc/proc_sysctl.c 2009-07-02 19:41:20.000000000 -0400 | |
22588 | +++ linux-2.6.29.6/fs/proc/proc_sysctl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22589 | @@ -7,6 +7,8 @@ |
22590 | #include <linux/security.h> | |
22591 | #include "internal.h" | |
22592 | ||
22593 | +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op); | |
22594 | + | |
22595 | static struct dentry_operations proc_sys_dentry_operations; | |
22596 | static const struct file_operations proc_sys_file_operations; | |
22597 | static const struct inode_operations proc_sys_inode_operations; | |
22598 | @@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(st | |
22599 | if (!p) | |
22600 | goto out; | |
22601 | ||
22602 | + if (gr_handle_sysctl(p, MAY_EXEC)) | |
22603 | + goto out; | |
22604 | + | |
22605 | err = ERR_PTR(-ENOMEM); | |
22606 | inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); | |
22607 | if (h) | |
22608 | @@ -228,6 +233,9 @@ static int scan(struct ctl_table_header | |
22609 | if (*pos < file->f_pos) | |
22610 | continue; | |
22611 | ||
22612 | + if (gr_handle_sysctl(table, 0)) | |
22613 | + continue; | |
22614 | + | |
22615 | res = proc_sys_fill_cache(file, dirent, filldir, head, table); | |
22616 | if (res) | |
22617 | return res; | |
22618 | @@ -344,6 +352,9 @@ static int proc_sys_getattr(struct vfsmo | |
22619 | if (IS_ERR(head)) | |
22620 | return PTR_ERR(head); | |
22621 | ||
22622 | + if (table && gr_handle_sysctl(table, MAY_EXEC)) | |
22623 | + return -ENOENT; | |
22624 | + | |
22625 | generic_fillattr(inode, stat); | |
22626 | if (table) | |
22627 | stat->mode = (stat->mode & S_IFMT) | table->mode; | |
de855c5d AM |
22628 | diff -urNp linux-2.6.29.6/fs/proc/root.c linux-2.6.29.6/fs/proc/root.c |
22629 | --- linux-2.6.29.6/fs/proc/root.c 2009-07-02 19:41:20.000000000 -0400 | |
22630 | +++ linux-2.6.29.6/fs/proc/root.c 2009-07-09 23:42:59.000000000 -0400 | |
22631 | @@ -101,6 +101,11 @@ static struct file_system_type proc_fs_t | |
22632 | .kill_sb = proc_kill_sb, | |
22633 | }; | |
22634 | ||
22635 | +#ifdef CONFIG_GRKERNSEC_HIDESYM | |
22636 | +static const struct file_operations __kallsyms_operations = { | |
22637 | +}; | |
22638 | +#endif | |
22639 | + | |
22640 | void __init proc_root_init(void) | |
22641 | { | |
22642 | int err; | |
22643 | @@ -134,8 +139,21 @@ void __init proc_root_init(void) | |
2380c486 JR |
22644 | #ifdef CONFIG_PROC_DEVICETREE |
22645 | proc_device_tree_init(); | |
22646 | #endif | |
22647 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
22648 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
22649 | + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL); | |
22650 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
22651 | + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL); | |
22652 | +#endif | |
22653 | +#else | |
22654 | proc_mkdir("bus", NULL); | |
22655 | +#endif | |
22656 | proc_sys_init(); | |
de855c5d AM |
22657 | + |
22658 | +#ifdef CONFIG_GRKERNSEC_HIDESYM | |
22659 | + /* fake kallsyms to workaround klogd bug */ | |
22660 | + proc_create("kallsyms", 0444, NULL, &__kallsyms_operations); | |
22661 | +#endif | |
2380c486 JR |
22662 | } |
22663 | ||
de855c5d AM |
22664 | static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat |
22665 | diff -urNp linux-2.6.29.6/fs/proc/task_mmu.c linux-2.6.29.6/fs/proc/task_mmu.c | |
22666 | --- linux-2.6.29.6/fs/proc/task_mmu.c 2009-07-02 19:41:20.000000000 -0400 | |
22667 | +++ linux-2.6.29.6/fs/proc/task_mmu.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22668 | @@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct |
22669 | "VmStk:\t%8lu kB\n" | |
22670 | "VmExe:\t%8lu kB\n" | |
22671 | "VmLib:\t%8lu kB\n" | |
22672 | - "VmPTE:\t%8lu kB\n", | |
22673 | - hiwater_vm << (PAGE_SHIFT-10), | |
22674 | + "VmPTE:\t%8lu kB\n" | |
22675 | + | |
22676 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
22677 | + "CsBase:\t%8lx\nCsLim:\t%8lx\n" | |
22678 | +#endif | |
22679 | + | |
22680 | + ,hiwater_vm << (PAGE_SHIFT-10), | |
22681 | (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), | |
22682 | mm->locked_vm << (PAGE_SHIFT-10), | |
22683 | hiwater_rss << (PAGE_SHIFT-10), | |
22684 | total_rss << (PAGE_SHIFT-10), | |
22685 | data << (PAGE_SHIFT-10), | |
22686 | mm->stack_vm << (PAGE_SHIFT-10), text, lib, | |
22687 | - (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10); | |
22688 | + (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10 | |
22689 | + | |
22690 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
22691 | + , mm->context.user_cs_base, mm->context.user_cs_limit | |
22692 | +#endif | |
22693 | + | |
22694 | + ); | |
22695 | } | |
22696 | ||
22697 | unsigned long task_vsize(struct mm_struct *mm) | |
22698 | @@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in | |
22699 | return ret; | |
22700 | } | |
22701 | ||
22702 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22703 | +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \ | |
22704 | + (_mm->pax_flags & MF_PAX_RANDMMAP || \ | |
22705 | + _mm->pax_flags & MF_PAX_SEGMEXEC)) | |
22706 | +#endif | |
22707 | + | |
22708 | static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma) | |
22709 | { | |
22710 | struct mm_struct *mm = vma->vm_mm; | |
22711 | @@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file | |
22712 | } | |
22713 | ||
22714 | seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n", | |
22715 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22716 | + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start, | |
22717 | + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end, | |
22718 | +#else | |
22719 | vma->vm_start, | |
22720 | vma->vm_end, | |
22721 | +#endif | |
22722 | flags & VM_READ ? 'r' : '-', | |
22723 | flags & VM_WRITE ? 'w' : '-', | |
22724 | flags & VM_EXEC ? 'x' : '-', | |
22725 | flags & VM_MAYSHARE ? 's' : 'p', | |
22726 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22727 | + PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT, | |
22728 | +#else | |
22729 | ((loff_t)vma->vm_pgoff) << PAGE_SHIFT, | |
22730 | +#endif | |
22731 | MAJOR(dev), MINOR(dev), ino, &len); | |
22732 | ||
22733 | /* | |
22734 | @@ -229,16 +255,16 @@ static void show_map_vma(struct seq_file | |
22735 | */ | |
22736 | if (file) { | |
22737 | pad_len_spaces(m, len); | |
22738 | - seq_path(m, &file->f_path, "\n"); | |
22739 | + seq_path(m, &file->f_path, "\n\\"); | |
22740 | } else { | |
22741 | const char *name = arch_vma_name(vma); | |
22742 | if (!name) { | |
22743 | if (mm) { | |
22744 | - if (vma->vm_start <= mm->start_brk && | |
22745 | - vma->vm_end >= mm->brk) { | |
22746 | + if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { | |
22747 | name = "[heap]"; | |
22748 | - } else if (vma->vm_start <= mm->start_stack && | |
22749 | - vma->vm_end >= mm->start_stack) { | |
22750 | + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) || | |
22751 | + (vma->vm_start <= mm->start_stack && | |
22752 | + vma->vm_end >= mm->start_stack)) { | |
22753 | name = "[stack]"; | |
22754 | } | |
22755 | } else { | |
22756 | @@ -381,9 +407,16 @@ static int show_smap(struct seq_file *m, | |
22757 | }; | |
22758 | ||
22759 | memset(&mss, 0, sizeof mss); | |
22760 | - mss.vma = vma; | |
22761 | - if (vma->vm_mm && !is_vm_hugetlb_page(vma)) | |
22762 | - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk); | |
22763 | + | |
22764 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22765 | + if (!PAX_RAND_FLAGS(vma->vm_mm)) { | |
22766 | +#endif | |
22767 | + mss.vma = vma; | |
22768 | + if (vma->vm_mm && !is_vm_hugetlb_page(vma)) | |
22769 | + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk); | |
22770 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22771 | + } | |
22772 | +#endif | |
22773 | ||
22774 | show_map_vma(m, vma); | |
22775 | ||
22776 | @@ -399,7 +432,11 @@ static int show_smap(struct seq_file *m, | |
22777 | "Swap: %8lu kB\n" | |
22778 | "KernelPageSize: %8lu kB\n" | |
22779 | "MMUPageSize: %8lu kB\n", | |
22780 | +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP | |
22781 | + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10, | |
22782 | +#else | |
22783 | (vma->vm_end - vma->vm_start) >> 10, | |
22784 | +#endif | |
22785 | mss.resident >> 10, | |
22786 | (unsigned long)(mss.pss >> (10 + PSS_SHIFT)), | |
22787 | mss.shared_clean >> 10, | |
de855c5d AM |
22788 | diff -urNp linux-2.6.29.6/fs/proc/task_nommu.c linux-2.6.29.6/fs/proc/task_nommu.c |
22789 | --- linux-2.6.29.6/fs/proc/task_nommu.c 2009-07-02 19:41:20.000000000 -0400 | |
22790 | +++ linux-2.6.29.6/fs/proc/task_nommu.c 2009-07-09 22:13:39.000000000 -0400 | |
22791 | @@ -49,7 +49,7 @@ void task_mem(struct seq_file *m, struct | |
22792 | else | |
22793 | bytes += kobjsize(mm); | |
22794 | ||
22795 | - if (current->fs && current->fs->users > 1) | |
22796 | + if (current->fs && atomic_read(¤t->fs->users) > 1) | |
22797 | sbytes += kobjsize(current->fs); | |
22798 | else | |
22799 | bytes += kobjsize(current->fs); | |
2380c486 JR |
22800 | @@ -151,7 +151,7 @@ static int nommu_vma_show(struct seq_fil |
22801 | if (len < 1) | |
22802 | len = 1; | |
22803 | seq_printf(m, "%*c", len, ' '); | |
22804 | - seq_path(m, &file->f_path, ""); | |
22805 | + seq_path(m, &file->f_path, "\n\\"); | |
22806 | } | |
22807 | ||
22808 | seq_putc(m, '\n'); | |
de855c5d AM |
22809 | diff -urNp linux-2.6.29.6/fs/readdir.c linux-2.6.29.6/fs/readdir.c |
22810 | --- linux-2.6.29.6/fs/readdir.c 2009-07-02 19:41:20.000000000 -0400 | |
22811 | +++ linux-2.6.29.6/fs/readdir.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22812 | @@ -16,6 +16,7 @@ |
22813 | #include <linux/security.h> | |
22814 | #include <linux/syscalls.h> | |
22815 | #include <linux/unistd.h> | |
22816 | +#include <linux/namei.h> | |
22817 | ||
22818 | #include <asm/uaccess.h> | |
22819 | ||
22820 | @@ -67,6 +68,7 @@ struct old_linux_dirent { | |
22821 | ||
22822 | struct readdir_callback { | |
22823 | struct old_linux_dirent __user * dirent; | |
22824 | + struct file * file; | |
22825 | int result; | |
22826 | }; | |
22827 | ||
22828 | @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons | |
22829 | buf->result = -EOVERFLOW; | |
22830 | return -EOVERFLOW; | |
22831 | } | |
22832 | + | |
22833 | + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino)) | |
22834 | + return 0; | |
22835 | + | |
22836 | buf->result++; | |
22837 | dirent = buf->dirent; | |
22838 | if (!access_ok(VERIFY_WRITE, dirent, | |
22839 | @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in | |
22840 | ||
22841 | buf.result = 0; | |
22842 | buf.dirent = dirent; | |
22843 | + buf.file = file; | |
22844 | ||
22845 | error = vfs_readdir(file, fillonedir, &buf); | |
22846 | if (buf.result) | |
22847 | @@ -142,6 +149,7 @@ struct linux_dirent { | |
22848 | struct getdents_callback { | |
22849 | struct linux_dirent __user * current_dir; | |
22850 | struct linux_dirent __user * previous; | |
22851 | + struct file * file; | |
22852 | int count; | |
22853 | int error; | |
22854 | }; | |
22855 | @@ -162,6 +170,10 @@ static int filldir(void * __buf, const c | |
22856 | buf->error = -EOVERFLOW; | |
22857 | return -EOVERFLOW; | |
22858 | } | |
22859 | + | |
22860 | + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino)) | |
22861 | + return 0; | |
22862 | + | |
22863 | dirent = buf->previous; | |
22864 | if (dirent) { | |
22865 | if (__put_user(offset, &dirent->d_off)) | |
22866 | @@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, | |
22867 | buf.previous = NULL; | |
22868 | buf.count = count; | |
22869 | buf.error = 0; | |
22870 | + buf.file = file; | |
22871 | ||
22872 | error = vfs_readdir(file, filldir, &buf); | |
22873 | if (error >= 0) | |
22874 | @@ -228,6 +241,7 @@ out: | |
22875 | struct getdents_callback64 { | |
22876 | struct linux_dirent64 __user * current_dir; | |
22877 | struct linux_dirent64 __user * previous; | |
22878 | + struct file *file; | |
22879 | int count; | |
22880 | int error; | |
22881 | }; | |
22882 | @@ -242,6 +256,10 @@ static int filldir64(void * __buf, const | |
22883 | buf->error = -EINVAL; /* only used if we fail.. */ | |
22884 | if (reclen > buf->count) | |
22885 | return -EINVAL; | |
22886 | + | |
22887 | + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino)) | |
22888 | + return 0; | |
22889 | + | |
22890 | dirent = buf->previous; | |
22891 | if (dirent) { | |
22892 | if (__put_user(offset, &dirent->d_off)) | |
22893 | @@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int | |
22894 | ||
22895 | buf.current_dir = dirent; | |
22896 | buf.previous = NULL; | |
22897 | + buf.file = file; | |
22898 | buf.count = count; | |
22899 | buf.error = 0; | |
22900 | ||
de855c5d AM |
22901 | diff -urNp linux-2.6.29.6/fs/reiserfs/do_balan.c linux-2.6.29.6/fs/reiserfs/do_balan.c |
22902 | --- linux-2.6.29.6/fs/reiserfs/do_balan.c 2009-07-02 19:41:20.000000000 -0400 | |
22903 | +++ linux-2.6.29.6/fs/reiserfs/do_balan.c 2009-07-09 22:13:39.000000000 -0400 | |
22904 | @@ -2114,7 +2114,7 @@ void do_balance(struct tree_balance *tb, | |
22905 | return; | |
22906 | } | |
22907 | ||
22908 | - atomic_inc(&(fs_generation(tb->tb_sb))); | |
22909 | + atomic_inc_unchecked(&(fs_generation(tb->tb_sb))); | |
22910 | do_balance_starts(tb); | |
22911 | ||
22912 | /* balance leaf returns 0 except if combining L R and S into | |
22913 | diff -urNp linux-2.6.29.6/fs/select.c linux-2.6.29.6/fs/select.c | |
22914 | --- linux-2.6.29.6/fs/select.c 2009-07-02 19:41:20.000000000 -0400 | |
22915 | +++ linux-2.6.29.6/fs/select.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22916 | @@ -19,6 +19,7 @@ |
22917 | #include <linux/module.h> | |
22918 | #include <linux/slab.h> | |
22919 | #include <linux/poll.h> | |
22920 | +#include <linux/security.h> | |
22921 | #include <linux/personality.h> /* for STICKY_TIMEOUTS */ | |
22922 | #include <linux/file.h> | |
22923 | #include <linux/fdtable.h> | |
22924 | @@ -781,6 +782,7 @@ int do_sys_poll(struct pollfd __user *uf | |
22925 | struct poll_list *walk = head; | |
22926 | unsigned long todo = nfds; | |
22927 | ||
22928 | + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1); | |
22929 | if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | |
22930 | return -EINVAL; | |
22931 | ||
de855c5d AM |
22932 | diff -urNp linux-2.6.29.6/fs/seq_file.c linux-2.6.29.6/fs/seq_file.c |
22933 | --- linux-2.6.29.6/fs/seq_file.c 2009-07-02 19:41:20.000000000 -0400 | |
22934 | +++ linux-2.6.29.6/fs/seq_file.c 2009-07-09 22:13:39.000000000 -0400 | |
22935 | @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, | |
22936 | return 0; | |
22937 | } | |
22938 | if (!m->buf) { | |
22939 | - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); | |
22940 | + m->size = PAGE_SIZE; | |
22941 | + m->buf = kmalloc(m->size, GFP_KERNEL); | |
22942 | if (!m->buf) | |
22943 | return -ENOMEM; | |
22944 | } | |
22945 | @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, | |
22946 | Eoverflow: | |
22947 | m->op->stop(m, p); | |
22948 | kfree(m->buf); | |
22949 | - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); | |
22950 | + m->size <<= 1; | |
22951 | + m->buf = kmalloc(m->size, GFP_KERNEL); | |
22952 | return !m->buf ? -ENOMEM : -EAGAIN; | |
22953 | } | |
22954 | ||
22955 | @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char | |
22956 | m->version = file->f_version; | |
22957 | /* grab buffer if we didn't have one */ | |
22958 | if (!m->buf) { | |
22959 | - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); | |
22960 | + m->size = PAGE_SIZE; | |
22961 | + m->buf = kmalloc(m->size, GFP_KERNEL); | |
22962 | if (!m->buf) | |
22963 | goto Enomem; | |
22964 | } | |
22965 | @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char | |
22966 | goto Fill; | |
22967 | m->op->stop(m, p); | |
22968 | kfree(m->buf); | |
22969 | - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); | |
22970 | + m->size <<= 1; | |
22971 | + m->buf = kmalloc(m->size, GFP_KERNEL); | |
22972 | if (!m->buf) | |
22973 | goto Enomem; | |
22974 | m->count = 0; | |
22975 | diff -urNp linux-2.6.29.6/fs/smbfs/symlink.c linux-2.6.29.6/fs/smbfs/symlink.c | |
22976 | --- linux-2.6.29.6/fs/smbfs/symlink.c 2009-07-02 19:41:20.000000000 -0400 | |
22977 | +++ linux-2.6.29.6/fs/smbfs/symlink.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22978 | @@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent |
22979 | ||
22980 | static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p) | |
22981 | { | |
22982 | - char *s = nd_get_link(nd); | |
22983 | + const char *s = nd_get_link(nd); | |
22984 | if (!IS_ERR(s)) | |
22985 | __putname(s); | |
22986 | } | |
de855c5d AM |
22987 | diff -urNp linux-2.6.29.6/fs/sysfs/symlink.c linux-2.6.29.6/fs/sysfs/symlink.c |
22988 | --- linux-2.6.29.6/fs/sysfs/symlink.c 2009-07-02 19:41:20.000000000 -0400 | |
22989 | +++ linux-2.6.29.6/fs/sysfs/symlink.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
22990 | @@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de |
22991 | ||
22992 | static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie) | |
22993 | { | |
22994 | - char *page = nd_get_link(nd); | |
22995 | + const char *page = nd_get_link(nd); | |
22996 | if (!IS_ERR(page)) | |
22997 | free_page((unsigned long)page); | |
22998 | } | |
de855c5d AM |
22999 | diff -urNp linux-2.6.29.6/fs/udf/balloc.c linux-2.6.29.6/fs/udf/balloc.c |
23000 | --- linux-2.6.29.6/fs/udf/balloc.c 2009-07-02 19:41:20.000000000 -0400 | |
23001 | +++ linux-2.6.29.6/fs/udf/balloc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
23002 | @@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc |
23003 | unsigned long overflow; | |
23004 | ||
23005 | mutex_lock(&sbi->s_alloc_mutex); | |
23006 | - if (bloc.logicalBlockNum < 0 || | |
23007 | - (bloc.logicalBlockNum + count) > | |
23008 | - sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | |
23009 | + if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | |
23010 | udf_debug("%d < %d || %d + %d > %d\n", | |
23011 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | |
23012 | sbi->s_partmaps[bloc.partitionReferenceNum]. | |
23013 | @@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st | |
23014 | ||
23015 | mutex_lock(&sbi->s_alloc_mutex); | |
23016 | part_len = sbi->s_partmaps[partition].s_partition_len; | |
23017 | - if (first_block < 0 || first_block >= part_len) | |
23018 | + if (first_block >= part_len) | |
23019 | goto out; | |
23020 | ||
23021 | if (first_block + block_count > part_len) | |
23022 | @@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s | |
23023 | mutex_lock(&sbi->s_alloc_mutex); | |
23024 | ||
23025 | repeat: | |
23026 | - if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) | |
23027 | + if (goal >= sbi->s_partmaps[partition].s_partition_len) | |
23028 | goal = 0; | |
23029 | ||
23030 | nr_groups = bitmap->s_nr_groups; | |
23031 | @@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct | |
23032 | struct udf_inode_info *iinfo; | |
23033 | ||
23034 | mutex_lock(&sbi->s_alloc_mutex); | |
23035 | - if (bloc.logicalBlockNum < 0 || | |
23036 | - (bloc.logicalBlockNum + count) > | |
23037 | - sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | |
23038 | + if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) { | |
23039 | udf_debug("%d < %d || %d + %d > %d\n", | |
23040 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | |
23041 | sbi->s_partmaps[bloc.partitionReferenceNum]. | |
23042 | @@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str | |
23043 | int8_t etype = -1; | |
23044 | struct udf_inode_info *iinfo; | |
23045 | ||
23046 | - if (first_block < 0 || | |
23047 | - first_block >= sbi->s_partmaps[partition].s_partition_len) | |
23048 | + if (first_block >= sbi->s_partmaps[partition].s_partition_len) | |
23049 | return 0; | |
23050 | ||
23051 | iinfo = UDF_I(table); | |
23052 | @@ -750,7 +745,7 @@ static int udf_table_new_block(struct su | |
23053 | return newblock; | |
23054 | ||
23055 | mutex_lock(&sbi->s_alloc_mutex); | |
23056 | - if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len) | |
23057 | + if (goal >= sbi->s_partmaps[partition].s_partition_len) | |
23058 | goal = 0; | |
23059 | ||
23060 | /* We search for the closest matching block to goal. If we find | |
de855c5d AM |
23061 | diff -urNp linux-2.6.29.6/fs/ufs/inode.c linux-2.6.29.6/fs/ufs/inode.c |
23062 | --- linux-2.6.29.6/fs/ufs/inode.c 2009-07-02 19:41:20.000000000 -0400 | |
23063 | +++ linux-2.6.29.6/fs/ufs/inode.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
23064 | @@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod |
23065 | ||
23066 | ||
23067 | UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks); | |
23068 | - if (i_block < 0) { | |
23069 | - ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0"); | |
23070 | - } else if (i_block < direct_blocks) { | |
23071 | + if (i_block < direct_blocks) { | |
23072 | offsets[n++] = i_block; | |
23073 | } else if ((i_block -= direct_blocks) < indirect_blocks) { | |
23074 | offsets[n++] = UFS_IND_BLOCK; | |
23075 | @@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod | |
23076 | lock_kernel(); | |
23077 | ||
23078 | UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment); | |
23079 | - if (fragment < 0) | |
23080 | - goto abort_negative; | |
23081 | if (fragment > | |
23082 | ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb) | |
23083 | << uspi->s_fpbshift)) | |
23084 | @@ -504,10 +500,6 @@ abort: | |
23085 | unlock_kernel(); | |
23086 | return err; | |
23087 | ||
23088 | -abort_negative: | |
23089 | - ufs_warning(sb, "ufs_get_block", "block < 0"); | |
23090 | - goto abort; | |
23091 | - | |
23092 | abort_too_big: | |
23093 | ufs_warning(sb, "ufs_get_block", "block > big"); | |
23094 | goto abort; | |
de855c5d AM |
23095 | diff -urNp linux-2.6.29.6/fs/utimes.c linux-2.6.29.6/fs/utimes.c |
23096 | --- linux-2.6.29.6/fs/utimes.c 2009-07-02 19:41:20.000000000 -0400 | |
23097 | +++ linux-2.6.29.6/fs/utimes.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
23098 | @@ -1,6 +1,7 @@ |
23099 | #include <linux/compiler.h> | |
23100 | #include <linux/file.h> | |
23101 | #include <linux/fs.h> | |
23102 | +#include <linux/security.h> | |
23103 | #include <linux/linkage.h> | |
23104 | #include <linux/mount.h> | |
23105 | #include <linux/namei.h> | |
23106 | @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa | |
23107 | goto mnt_drop_write_and_out; | |
23108 | } | |
23109 | } | |
23110 | + | |
23111 | + if (!gr_acl_handle_utime(path->dentry, path->mnt)) { | |
23112 | + error = -EACCES; | |
23113 | + goto mnt_drop_write_and_out; | |
23114 | + } | |
23115 | + | |
23116 | mutex_lock(&inode->i_mutex); | |
23117 | error = notify_change(path->dentry, &newattrs); | |
23118 | mutex_unlock(&inode->i_mutex); | |
de855c5d AM |
23119 | diff -urNp linux-2.6.29.6/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.6/fs/xfs/linux-2.6/xfs_iops.c |
23120 | --- linux-2.6.29.6/fs/xfs/linux-2.6/xfs_iops.c 2009-07-02 19:41:20.000000000 -0400 | |
23121 | +++ linux-2.6.29.6/fs/xfs/linux-2.6/xfs_iops.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
23122 | @@ -494,7 +494,7 @@ xfs_vn_put_link( |
23123 | struct nameidata *nd, | |
23124 | void *p) | |
23125 | { | |
23126 | - char *s = nd_get_link(nd); | |
23127 | + const char *s = nd_get_link(nd); | |
23128 | ||
23129 | if (!IS_ERR(s)) | |
23130 | kfree(s); | |
de855c5d AM |
23131 | diff -urNp linux-2.6.29.6/fs/xfs/xfs_bmap.c linux-2.6.29.6/fs/xfs/xfs_bmap.c |
23132 | --- linux-2.6.29.6/fs/xfs/xfs_bmap.c 2009-07-02 19:41:20.000000000 -0400 | |
23133 | +++ linux-2.6.29.6/fs/xfs/xfs_bmap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
23134 | @@ -360,7 +360,7 @@ xfs_bmap_validate_ret( |
23135 | int nmap, | |
23136 | int ret_nmap); | |
23137 | #else | |
23138 | -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) | |
23139 | +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0) | |
23140 | #endif /* DEBUG */ | |
23141 | ||
23142 | #if defined(XFS_RW_TRACE) | |
de855c5d AM |
23143 | diff -urNp linux-2.6.29.6/grsecurity/gracl_alloc.c linux-2.6.29.6/grsecurity/gracl_alloc.c |
23144 | --- linux-2.6.29.6/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500 | |
23145 | +++ linux-2.6.29.6/grsecurity/gracl_alloc.c 2009-07-09 22:13:39.000000000 -0400 | |
23146 | @@ -0,0 +1,105 @@ | |
2380c486 JR |
23147 | +#include <linux/kernel.h> |
23148 | +#include <linux/mm.h> | |
23149 | +#include <linux/slab.h> | |
23150 | +#include <linux/vmalloc.h> | |
23151 | +#include <linux/gracl.h> | |
23152 | +#include <linux/grsecurity.h> | |
23153 | + | |
23154 | +static unsigned long alloc_stack_next = 1; | |
23155 | +static unsigned long alloc_stack_size = 1; | |
23156 | +static void **alloc_stack; | |
23157 | + | |
23158 | +static __inline__ int | |
23159 | +alloc_pop(void) | |
23160 | +{ | |
23161 | + if (alloc_stack_next == 1) | |
23162 | + return 0; | |
23163 | + | |
23164 | + kfree(alloc_stack[alloc_stack_next - 2]); | |
23165 | + | |
23166 | + alloc_stack_next--; | |
23167 | + | |
23168 | + return 1; | |
23169 | +} | |
23170 | + | |
de855c5d | 23171 | +static __inline__ int |
2380c486 JR |
23172 | +alloc_push(void *buf) |
23173 | +{ | |
23174 | + if (alloc_stack_next >= alloc_stack_size) | |
de855c5d | 23175 | + return 1; |
2380c486 JR |
23176 | + |
23177 | + alloc_stack[alloc_stack_next - 1] = buf; | |
23178 | + | |
23179 | + alloc_stack_next++; | |
23180 | + | |
de855c5d | 23181 | + return 0; |
2380c486 JR |
23182 | +} |
23183 | + | |
23184 | +void * | |
23185 | +acl_alloc(unsigned long len) | |
23186 | +{ | |
de855c5d | 23187 | + void *ret = NULL; |
2380c486 | 23188 | + |
de855c5d AM |
23189 | + if (!len || len > PAGE_SIZE) |
23190 | + goto out; | |
2380c486 JR |
23191 | + |
23192 | + ret = kmalloc(len, GFP_KERNEL); | |
23193 | + | |
de855c5d AM |
23194 | + if (ret) { |
23195 | + if (alloc_push(ret)) { | |
23196 | + kfree(ret); | |
23197 | + ret = NULL; | |
23198 | + } | |
23199 | + } | |
2380c486 | 23200 | + |
de855c5d | 23201 | +out: |
2380c486 JR |
23202 | + return ret; |
23203 | +} | |
23204 | + | |
de855c5d AM |
23205 | +void * |
23206 | +acl_alloc_num(unsigned long num, unsigned long len) | |
23207 | +{ | |
23208 | + if (!len || (num > (PAGE_SIZE / len))) | |
23209 | + return NULL; | |
23210 | + | |
23211 | + return acl_alloc(num * len); | |
23212 | +} | |
23213 | + | |
2380c486 JR |
23214 | +void |
23215 | +acl_free_all(void) | |
23216 | +{ | |
23217 | + if (gr_acl_is_enabled() || !alloc_stack) | |
23218 | + return; | |
23219 | + | |
23220 | + while (alloc_pop()) ; | |
23221 | + | |
23222 | + if (alloc_stack) { | |
23223 | + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE) | |
23224 | + kfree(alloc_stack); | |
23225 | + else | |
23226 | + vfree(alloc_stack); | |
23227 | + } | |
23228 | + | |
23229 | + alloc_stack = NULL; | |
23230 | + alloc_stack_size = 1; | |
23231 | + alloc_stack_next = 1; | |
23232 | + | |
23233 | + return; | |
23234 | +} | |
23235 | + | |
23236 | +int | |
23237 | +acl_alloc_stack_init(unsigned long size) | |
23238 | +{ | |
23239 | + if ((size * sizeof (void *)) <= PAGE_SIZE) | |
23240 | + alloc_stack = | |
23241 | + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL); | |
23242 | + else | |
23243 | + alloc_stack = (void **) vmalloc(size * sizeof (void *)); | |
23244 | + | |
23245 | + alloc_stack_size = size; | |
23246 | + | |
23247 | + if (!alloc_stack) | |
23248 | + return 0; | |
23249 | + else | |
23250 | + return 1; | |
23251 | +} | |
de855c5d AM |
23252 | diff -urNp linux-2.6.29.6/grsecurity/gracl.c linux-2.6.29.6/grsecurity/gracl.c |
23253 | --- linux-2.6.29.6/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500 | |
23254 | +++ linux-2.6.29.6/grsecurity/gracl.c 2009-07-10 05:42:10.000000000 -0400 | |
23255 | @@ -0,0 +1,3855 @@ | |
2380c486 JR |
23256 | +#include <linux/kernel.h> |
23257 | +#include <linux/module.h> | |
23258 | +#include <linux/sched.h> | |
23259 | +#include <linux/mm.h> | |
23260 | +#include <linux/file.h> | |
23261 | +#include <linux/fs.h> | |
23262 | +#include <linux/namei.h> | |
23263 | +#include <linux/mount.h> | |
23264 | +#include <linux/tty.h> | |
23265 | +#include <linux/proc_fs.h> | |
23266 | +#include <linux/smp_lock.h> | |
23267 | +#include <linux/slab.h> | |
23268 | +#include <linux/vmalloc.h> | |
23269 | +#include <linux/types.h> | |
23270 | +#include <linux/sysctl.h> | |
23271 | +#include <linux/netdevice.h> | |
23272 | +#include <linux/ptrace.h> | |
23273 | +#include <linux/gracl.h> | |
23274 | +#include <linux/gralloc.h> | |
23275 | +#include <linux/grsecurity.h> | |
23276 | +#include <linux/grinternal.h> | |
23277 | +#include <linux/pid_namespace.h> | |
23278 | +#include <linux/fdtable.h> | |
23279 | +#include <linux/percpu.h> | |
23280 | + | |
23281 | +#include <asm/uaccess.h> | |
23282 | +#include <asm/errno.h> | |
23283 | +#include <asm/mman.h> | |
23284 | + | |
23285 | +static struct acl_role_db acl_role_set; | |
23286 | +static struct name_db name_set; | |
23287 | +static struct inodev_db inodev_set; | |
23288 | + | |
23289 | +/* for keeping track of userspace pointers used for subjects, so we | |
23290 | + can share references in the kernel as well | |
23291 | +*/ | |
23292 | + | |
23293 | +static struct dentry *real_root; | |
23294 | +static struct vfsmount *real_root_mnt; | |
23295 | + | |
23296 | +static struct acl_subj_map_db subj_map_set; | |
23297 | + | |
23298 | +static struct acl_role_label *default_role; | |
23299 | + | |
23300 | +static u16 acl_sp_role_value; | |
23301 | + | |
23302 | +extern char *gr_shared_page[4]; | |
23303 | +static DECLARE_MUTEX(gr_dev_sem); | |
23304 | +DEFINE_RWLOCK(gr_inode_lock); | |
23305 | + | |
23306 | +struct gr_arg *gr_usermode; | |
23307 | + | |
23308 | +static unsigned int gr_status = GR_STATUS_INIT; | |
23309 | + | |
23310 | +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum); | |
23311 | +extern void gr_clear_learn_entries(void); | |
23312 | + | |
23313 | +#ifdef CONFIG_GRKERNSEC_RESLOG | |
23314 | +extern void gr_log_resource(const struct task_struct *task, | |
23315 | + const int res, const unsigned long wanted, const int gt); | |
23316 | +#endif | |
23317 | + | |
23318 | +unsigned char *gr_system_salt; | |
23319 | +unsigned char *gr_system_sum; | |
23320 | + | |
23321 | +static struct sprole_pw **acl_special_roles = NULL; | |
23322 | +static __u16 num_sprole_pws = 0; | |
23323 | + | |
23324 | +static struct acl_role_label *kernel_role = NULL; | |
23325 | + | |
23326 | +static unsigned int gr_auth_attempts = 0; | |
23327 | +static unsigned long gr_auth_expires = 0UL; | |
23328 | + | |
23329 | +extern struct vfsmount *sock_mnt; | |
23330 | +extern struct vfsmount *pipe_mnt; | |
23331 | +extern struct vfsmount *shm_mnt; | |
23332 | +static struct acl_object_label *fakefs_obj; | |
23333 | + | |
23334 | +extern int gr_init_uidset(void); | |
23335 | +extern void gr_free_uidset(void); | |
23336 | +extern void gr_remove_uid(uid_t uid); | |
23337 | +extern int gr_find_uid(uid_t uid); | |
23338 | + | |
23339 | +__inline__ int | |
23340 | +gr_acl_is_enabled(void) | |
23341 | +{ | |
23342 | + return (gr_status & GR_READY); | |
23343 | +} | |
23344 | + | |
23345 | +char gr_roletype_to_char(void) | |
23346 | +{ | |
23347 | + switch (current->role->roletype & | |
23348 | + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP | | |
23349 | + GR_ROLE_SPECIAL)) { | |
23350 | + case GR_ROLE_DEFAULT: | |
23351 | + return 'D'; | |
23352 | + case GR_ROLE_USER: | |
23353 | + return 'U'; | |
23354 | + case GR_ROLE_GROUP: | |
23355 | + return 'G'; | |
23356 | + case GR_ROLE_SPECIAL: | |
23357 | + return 'S'; | |
23358 | + } | |
23359 | + | |
23360 | + return 'X'; | |
23361 | +} | |
23362 | + | |
23363 | +__inline__ int | |
23364 | +gr_acl_tpe_check(void) | |
23365 | +{ | |
23366 | + if (unlikely(!(gr_status & GR_READY))) | |
23367 | + return 0; | |
23368 | + if (current->role->roletype & GR_ROLE_TPE) | |
23369 | + return 1; | |
23370 | + else | |
23371 | + return 0; | |
23372 | +} | |
23373 | + | |
23374 | +int | |
23375 | +gr_handle_rawio(const struct inode *inode) | |
23376 | +{ | |
23377 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS | |
23378 | + if (inode && S_ISBLK(inode->i_mode) && | |
23379 | + grsec_enable_chroot_caps && proc_is_chrooted(current) && | |
23380 | + !capable(CAP_SYS_RAWIO)) | |
23381 | + return 1; | |
23382 | +#endif | |
23383 | + return 0; | |
23384 | +} | |
23385 | + | |
23386 | +static int | |
23387 | +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb) | |
23388 | +{ | |
23389 | + int i; | |
23390 | + unsigned long *l1; | |
23391 | + unsigned long *l2; | |
23392 | + unsigned char *c1; | |
23393 | + unsigned char *c2; | |
23394 | + int num_longs; | |
23395 | + | |
23396 | + if (likely(lena != lenb)) | |
23397 | + return 0; | |
23398 | + | |
23399 | + l1 = (unsigned long *)a; | |
23400 | + l2 = (unsigned long *)b; | |
23401 | + | |
23402 | + num_longs = lena / sizeof(unsigned long); | |
23403 | + | |
23404 | + for (i = num_longs; i--; l1++, l2++) { | |
23405 | + if (unlikely(*l1 != *l2)) | |
23406 | + return 0; | |
23407 | + } | |
23408 | + | |
23409 | + c1 = (unsigned char *) l1; | |
23410 | + c2 = (unsigned char *) l2; | |
23411 | + | |
23412 | + i = lena - (num_longs * sizeof(unsigned long)); | |
23413 | + | |
23414 | + for (; i--; c1++, c2++) { | |
23415 | + if (unlikely(*c1 != *c2)) | |
23416 | + return 0; | |
23417 | + } | |
23418 | + | |
23419 | + return 1; | |
23420 | +} | |
23421 | + | |
23422 | +static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt, | |
23423 | + struct dentry *root, struct vfsmount *rootmnt, | |
23424 | + char *buffer, int buflen) | |
23425 | +{ | |
23426 | + char * end = buffer+buflen; | |
23427 | + char * retval; | |
23428 | + int namelen; | |
23429 | + | |
23430 | + *--end = '\0'; | |
23431 | + buflen--; | |
23432 | + | |
23433 | + if (buflen < 1) | |
23434 | + goto Elong; | |
23435 | + /* Get '/' right */ | |
23436 | + retval = end-1; | |
23437 | + *retval = '/'; | |
23438 | + | |
23439 | + for (;;) { | |
23440 | + struct dentry * parent; | |
23441 | + | |
23442 | + if (dentry == root && vfsmnt == rootmnt) | |
23443 | + break; | |
23444 | + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { | |
23445 | + /* Global root? */ | |
23446 | + spin_lock(&vfsmount_lock); | |
23447 | + if (vfsmnt->mnt_parent == vfsmnt) { | |
23448 | + spin_unlock(&vfsmount_lock); | |
23449 | + goto global_root; | |
23450 | + } | |
23451 | + dentry = vfsmnt->mnt_mountpoint; | |
23452 | + vfsmnt = vfsmnt->mnt_parent; | |
23453 | + spin_unlock(&vfsmount_lock); | |
23454 | + continue; | |
23455 | + } | |
23456 | + parent = dentry->d_parent; | |
23457 | + prefetch(parent); | |
23458 | + namelen = dentry->d_name.len; | |
23459 | + buflen -= namelen + 1; | |
23460 | + if (buflen < 0) | |
23461 | + goto Elong; | |
23462 | + end -= namelen; | |
23463 | + memcpy(end, dentry->d_name.name, namelen); | |
23464 | + *--end = '/'; | |
23465 | + retval = end; | |
23466 | + dentry = parent; | |
23467 | + } | |
23468 | + | |
23469 | + return retval; | |
23470 | + | |
23471 | +global_root: | |
23472 | + namelen = dentry->d_name.len; | |
23473 | + buflen -= namelen; | |
23474 | + if (buflen < 0) | |
23475 | + goto Elong; | |
23476 | + retval -= namelen-1; /* hit the slash */ | |
23477 | + memcpy(retval, dentry->d_name.name, namelen); | |
23478 | + return retval; | |
23479 | +Elong: | |
23480 | + return ERR_PTR(-ENAMETOOLONG); | |
23481 | +} | |
23482 | + | |
23483 | +static char * | |
23484 | +gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt, | |
23485 | + struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen) | |
23486 | +{ | |
23487 | + char *retval; | |
23488 | + | |
23489 | + retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen); | |
23490 | + if (unlikely(IS_ERR(retval))) | |
23491 | + retval = strcpy(buf, "<path too long>"); | |
23492 | + else if (unlikely(retval[1] == '/' && retval[2] == '\0')) | |
23493 | + retval[1] = '\0'; | |
23494 | + | |
23495 | + return retval; | |
23496 | +} | |
23497 | + | |
23498 | +static char * | |
23499 | +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt, | |
23500 | + char *buf, int buflen) | |
23501 | +{ | |
23502 | + char *res; | |
23503 | + | |
23504 | + /* we can use real_root, real_root_mnt, because this is only called | |
23505 | + by the RBAC system */ | |
23506 | + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen); | |
23507 | + | |
23508 | + return res; | |
23509 | +} | |
23510 | + | |
23511 | +static char * | |
23512 | +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt, | |
23513 | + char *buf, int buflen) | |
23514 | +{ | |
23515 | + char *res; | |
23516 | + struct dentry *root; | |
23517 | + struct vfsmount *rootmnt; | |
23518 | + struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper; | |
23519 | + | |
23520 | + /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */ | |
23521 | + read_lock(&reaper->fs->lock); | |
23522 | + root = dget(reaper->fs->root.dentry); | |
23523 | + rootmnt = mntget(reaper->fs->root.mnt); | |
23524 | + read_unlock(&reaper->fs->lock); | |
23525 | + | |
23526 | + spin_lock(&dcache_lock); | |
23527 | + res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen); | |
23528 | + spin_unlock(&dcache_lock); | |
23529 | + | |
23530 | + dput(root); | |
23531 | + mntput(rootmnt); | |
23532 | + return res; | |
23533 | +} | |
23534 | + | |
23535 | +static char * | |
23536 | +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt) | |
23537 | +{ | |
23538 | + char *ret; | |
23539 | + spin_lock(&dcache_lock); | |
23540 | + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()), | |
23541 | + PAGE_SIZE); | |
23542 | + spin_unlock(&dcache_lock); | |
23543 | + return ret; | |
23544 | +} | |
23545 | + | |
23546 | +char * | |
23547 | +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt) | |
23548 | +{ | |
23549 | + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()), | |
23550 | + PAGE_SIZE); | |
23551 | +} | |
23552 | + | |
23553 | +char * | |
23554 | +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt) | |
23555 | +{ | |
23556 | + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()), | |
23557 | + PAGE_SIZE); | |
23558 | +} | |
23559 | + | |
23560 | +char * | |
23561 | +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt) | |
23562 | +{ | |
23563 | + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()), | |
23564 | + PAGE_SIZE); | |
23565 | +} | |
23566 | + | |
23567 | +char * | |
23568 | +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt) | |
23569 | +{ | |
23570 | + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()), | |
23571 | + PAGE_SIZE); | |
23572 | +} | |
23573 | + | |
23574 | +char * | |
23575 | +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt) | |
23576 | +{ | |
23577 | + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()), | |
23578 | + PAGE_SIZE); | |
23579 | +} | |
23580 | + | |
23581 | +__inline__ __u32 | |
23582 | +to_gr_audit(const __u32 reqmode) | |
23583 | +{ | |
23584 | + /* masks off auditable permission flags, then shifts them to create | |
23585 | + auditing flags, and adds the special case of append auditing if | |
23586 | + we're requesting write */ | |
23587 | + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0)); | |
23588 | +} | |
23589 | + | |
23590 | +struct acl_subject_label * | |
23591 | +lookup_subject_map(const struct acl_subject_label *userp) | |
23592 | +{ | |
23593 | + unsigned int index = shash(userp, subj_map_set.s_size); | |
23594 | + struct subject_map *match; | |
23595 | + | |
23596 | + match = subj_map_set.s_hash[index]; | |
23597 | + | |
23598 | + while (match && match->user != userp) | |
23599 | + match = match->next; | |
23600 | + | |
23601 | + if (match != NULL) | |
23602 | + return match->kernel; | |
23603 | + else | |
23604 | + return NULL; | |
23605 | +} | |
23606 | + | |
23607 | +static void | |
23608 | +insert_subj_map_entry(struct subject_map *subjmap) | |
23609 | +{ | |
23610 | + unsigned int index = shash(subjmap->user, subj_map_set.s_size); | |
23611 | + struct subject_map **curr; | |
23612 | + | |
23613 | + subjmap->prev = NULL; | |
23614 | + | |
23615 | + curr = &subj_map_set.s_hash[index]; | |
23616 | + if (*curr != NULL) | |
23617 | + (*curr)->prev = subjmap; | |
23618 | + | |
23619 | + subjmap->next = *curr; | |
23620 | + *curr = subjmap; | |
23621 | + | |
23622 | + return; | |
23623 | +} | |
23624 | + | |
23625 | +static struct acl_role_label * | |
23626 | +lookup_acl_role_label(const struct task_struct *task, const uid_t uid, | |
23627 | + const gid_t gid) | |
23628 | +{ | |
23629 | + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size); | |
23630 | + struct acl_role_label *match; | |
23631 | + struct role_allowed_ip *ipp; | |
23632 | + unsigned int x; | |
23633 | + | |
23634 | + match = acl_role_set.r_hash[index]; | |
23635 | + | |
23636 | + while (match) { | |
23637 | + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) { | |
23638 | + for (x = 0; x < match->domain_child_num; x++) { | |
23639 | + if (match->domain_children[x] == uid) | |
23640 | + goto found; | |
23641 | + } | |
23642 | + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER) | |
23643 | + break; | |
23644 | + match = match->next; | |
23645 | + } | |
23646 | +found: | |
23647 | + if (match == NULL) { | |
23648 | + try_group: | |
23649 | + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size); | |
23650 | + match = acl_role_set.r_hash[index]; | |
23651 | + | |
23652 | + while (match) { | |
23653 | + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) { | |
23654 | + for (x = 0; x < match->domain_child_num; x++) { | |
23655 | + if (match->domain_children[x] == gid) | |
23656 | + goto found2; | |
23657 | + } | |
23658 | + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP) | |
23659 | + break; | |
23660 | + match = match->next; | |
23661 | + } | |
23662 | +found2: | |
23663 | + if (match == NULL) | |
23664 | + match = default_role; | |
23665 | + if (match->allowed_ips == NULL) | |
23666 | + return match; | |
23667 | + else { | |
23668 | + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) { | |
23669 | + if (likely | |
23670 | + ((ntohl(task->signal->curr_ip) & ipp->netmask) == | |
23671 | + (ntohl(ipp->addr) & ipp->netmask))) | |
23672 | + return match; | |
23673 | + } | |
23674 | + match = default_role; | |
23675 | + } | |
23676 | + } else if (match->allowed_ips == NULL) { | |
23677 | + return match; | |
23678 | + } else { | |
23679 | + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) { | |
23680 | + if (likely | |
23681 | + ((ntohl(task->signal->curr_ip) & ipp->netmask) == | |
23682 | + (ntohl(ipp->addr) & ipp->netmask))) | |
23683 | + return match; | |
23684 | + } | |
23685 | + goto try_group; | |
23686 | + } | |
23687 | + | |
23688 | + return match; | |
23689 | +} | |
23690 | + | |
23691 | +struct acl_subject_label * | |
23692 | +lookup_acl_subj_label(const ino_t ino, const dev_t dev, | |
23693 | + const struct acl_role_label *role) | |
23694 | +{ | |
23695 | + unsigned int index = fhash(ino, dev, role->subj_hash_size); | |
23696 | + struct acl_subject_label *match; | |
23697 | + | |
23698 | + match = role->subj_hash[index]; | |
23699 | + | |
23700 | + while (match && (match->inode != ino || match->device != dev || | |
23701 | + (match->mode & GR_DELETED))) { | |
23702 | + match = match->next; | |
23703 | + } | |
23704 | + | |
23705 | + if (match && !(match->mode & GR_DELETED)) | |
23706 | + return match; | |
23707 | + else | |
23708 | + return NULL; | |
23709 | +} | |
23710 | + | |
de855c5d AM |
23711 | +struct acl_subject_label * |
23712 | +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, | |
23713 | + const struct acl_role_label *role) | |
23714 | +{ | |
23715 | + unsigned int index = fhash(ino, dev, role->subj_hash_size); | |
23716 | + struct acl_subject_label *match; | |
23717 | + | |
23718 | + match = role->subj_hash[index]; | |
23719 | + | |
23720 | + while (match && (match->inode != ino || match->device != dev || | |
23721 | + !(match->mode & GR_DELETED))) { | |
23722 | + match = match->next; | |
23723 | + } | |
23724 | + | |
23725 | + if (match && (match->mode & GR_DELETED)) | |
23726 | + return match; | |
23727 | + else | |
23728 | + return NULL; | |
23729 | +} | |
23730 | + | |
2380c486 JR |
23731 | +static struct acl_object_label * |
23732 | +lookup_acl_obj_label(const ino_t ino, const dev_t dev, | |
23733 | + const struct acl_subject_label *subj) | |
23734 | +{ | |
23735 | + unsigned int index = fhash(ino, dev, subj->obj_hash_size); | |
23736 | + struct acl_object_label *match; | |
23737 | + | |
23738 | + match = subj->obj_hash[index]; | |
23739 | + | |
23740 | + while (match && (match->inode != ino || match->device != dev || | |
23741 | + (match->mode & GR_DELETED))) { | |
23742 | + match = match->next; | |
23743 | + } | |
23744 | + | |
23745 | + if (match && !(match->mode & GR_DELETED)) | |
23746 | + return match; | |
23747 | + else | |
23748 | + return NULL; | |
23749 | +} | |
23750 | + | |
23751 | +static struct acl_object_label * | |
23752 | +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev, | |
23753 | + const struct acl_subject_label *subj) | |
23754 | +{ | |
23755 | + unsigned int index = fhash(ino, dev, subj->obj_hash_size); | |
23756 | + struct acl_object_label *match; | |
23757 | + | |
23758 | + match = subj->obj_hash[index]; | |
23759 | + | |
23760 | + while (match && (match->inode != ino || match->device != dev || | |
23761 | + !(match->mode & GR_DELETED))) { | |
23762 | + match = match->next; | |
23763 | + } | |
23764 | + | |
23765 | + if (match && (match->mode & GR_DELETED)) | |
23766 | + return match; | |
23767 | + | |
23768 | + match = subj->obj_hash[index]; | |
23769 | + | |
23770 | + while (match && (match->inode != ino || match->device != dev || | |
23771 | + (match->mode & GR_DELETED))) { | |
23772 | + match = match->next; | |
23773 | + } | |
23774 | + | |
23775 | + if (match && !(match->mode & GR_DELETED)) | |
23776 | + return match; | |
23777 | + else | |
23778 | + return NULL; | |
23779 | +} | |
23780 | + | |
23781 | +static struct name_entry * | |
23782 | +lookup_name_entry(const char *name) | |
23783 | +{ | |
23784 | + unsigned int len = strlen(name); | |
23785 | + unsigned int key = full_name_hash(name, len); | |
23786 | + unsigned int index = key % name_set.n_size; | |
23787 | + struct name_entry *match; | |
23788 | + | |
23789 | + match = name_set.n_hash[index]; | |
23790 | + | |
23791 | + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len))) | |
23792 | + match = match->next; | |
23793 | + | |
23794 | + return match; | |
23795 | +} | |
23796 | + | |
23797 | +static struct name_entry * | |
23798 | +lookup_name_entry_create(const char *name) | |
23799 | +{ | |
23800 | + unsigned int len = strlen(name); | |
23801 | + unsigned int key = full_name_hash(name, len); | |
23802 | + unsigned int index = key % name_set.n_size; | |
23803 | + struct name_entry *match; | |
23804 | + | |
23805 | + match = name_set.n_hash[index]; | |
23806 | + | |
23807 | + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) || | |
23808 | + !match->deleted)) | |
23809 | + match = match->next; | |
23810 | + | |
23811 | + if (match && match->deleted) | |
23812 | + return match; | |
23813 | + | |
23814 | + match = name_set.n_hash[index]; | |
23815 | + | |
23816 | + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) || | |
23817 | + match->deleted)) | |
23818 | + match = match->next; | |
23819 | + | |
23820 | + if (match && !match->deleted) | |
23821 | + return match; | |
23822 | + else | |
23823 | + return NULL; | |
23824 | +} | |
23825 | + | |
23826 | +static struct inodev_entry * | |
23827 | +lookup_inodev_entry(const ino_t ino, const dev_t dev) | |
23828 | +{ | |
23829 | + unsigned int index = fhash(ino, dev, inodev_set.i_size); | |
23830 | + struct inodev_entry *match; | |
23831 | + | |
23832 | + match = inodev_set.i_hash[index]; | |
23833 | + | |
23834 | + while (match && (match->nentry->inode != ino || match->nentry->device != dev)) | |
23835 | + match = match->next; | |
23836 | + | |
23837 | + return match; | |
23838 | +} | |
23839 | + | |
23840 | +static void | |
23841 | +insert_inodev_entry(struct inodev_entry *entry) | |
23842 | +{ | |
23843 | + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device, | |
23844 | + inodev_set.i_size); | |
23845 | + struct inodev_entry **curr; | |
23846 | + | |
23847 | + entry->prev = NULL; | |
23848 | + | |
23849 | + curr = &inodev_set.i_hash[index]; | |
23850 | + if (*curr != NULL) | |
23851 | + (*curr)->prev = entry; | |
23852 | + | |
23853 | + entry->next = *curr; | |
23854 | + *curr = entry; | |
23855 | + | |
23856 | + return; | |
23857 | +} | |
23858 | + | |
23859 | +static void | |
23860 | +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid) | |
23861 | +{ | |
23862 | + unsigned int index = | |
23863 | + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size); | |
23864 | + struct acl_role_label **curr; | |
23865 | + | |
23866 | + role->prev = NULL; | |
23867 | + | |
23868 | + curr = &acl_role_set.r_hash[index]; | |
23869 | + if (*curr != NULL) | |
23870 | + (*curr)->prev = role; | |
23871 | + | |
23872 | + role->next = *curr; | |
23873 | + *curr = role; | |
23874 | + | |
23875 | + return; | |
23876 | +} | |
23877 | + | |
23878 | +static void | |
23879 | +insert_acl_role_label(struct acl_role_label *role) | |
23880 | +{ | |
23881 | + int i; | |
23882 | + | |
23883 | + if (role->roletype & GR_ROLE_DOMAIN) { | |
23884 | + for (i = 0; i < role->domain_child_num; i++) | |
23885 | + __insert_acl_role_label(role, role->domain_children[i]); | |
23886 | + } else | |
23887 | + __insert_acl_role_label(role, role->uidgid); | |
23888 | +} | |
23889 | + | |
23890 | +static int | |
23891 | +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted) | |
23892 | +{ | |
23893 | + struct name_entry **curr, *nentry; | |
23894 | + struct inodev_entry *ientry; | |
23895 | + unsigned int len = strlen(name); | |
23896 | + unsigned int key = full_name_hash(name, len); | |
23897 | + unsigned int index = key % name_set.n_size; | |
23898 | + | |
23899 | + curr = &name_set.n_hash[index]; | |
23900 | + | |
23901 | + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len))) | |
23902 | + curr = &((*curr)->next); | |
23903 | + | |
23904 | + if (*curr != NULL) | |
23905 | + return 1; | |
23906 | + | |
23907 | + nentry = acl_alloc(sizeof (struct name_entry)); | |
23908 | + if (nentry == NULL) | |
23909 | + return 0; | |
23910 | + ientry = acl_alloc(sizeof (struct inodev_entry)); | |
23911 | + if (ientry == NULL) | |
23912 | + return 0; | |
23913 | + ientry->nentry = nentry; | |
23914 | + | |
23915 | + nentry->key = key; | |
23916 | + nentry->name = name; | |
23917 | + nentry->inode = inode; | |
23918 | + nentry->device = device; | |
23919 | + nentry->len = len; | |
23920 | + nentry->deleted = deleted; | |
23921 | + | |
23922 | + nentry->prev = NULL; | |
23923 | + curr = &name_set.n_hash[index]; | |
23924 | + if (*curr != NULL) | |
23925 | + (*curr)->prev = nentry; | |
23926 | + nentry->next = *curr; | |
23927 | + *curr = nentry; | |
23928 | + | |
23929 | + /* insert us into the table searchable by inode/dev */ | |
23930 | + insert_inodev_entry(ientry); | |
23931 | + | |
23932 | + return 1; | |
23933 | +} | |
23934 | + | |
23935 | +static void | |
23936 | +insert_acl_obj_label(struct acl_object_label *obj, | |
23937 | + struct acl_subject_label *subj) | |
23938 | +{ | |
23939 | + unsigned int index = | |
23940 | + fhash(obj->inode, obj->device, subj->obj_hash_size); | |
23941 | + struct acl_object_label **curr; | |
23942 | + | |
23943 | + | |
23944 | + obj->prev = NULL; | |
23945 | + | |
23946 | + curr = &subj->obj_hash[index]; | |
23947 | + if (*curr != NULL) | |
23948 | + (*curr)->prev = obj; | |
23949 | + | |
23950 | + obj->next = *curr; | |
23951 | + *curr = obj; | |
23952 | + | |
23953 | + return; | |
23954 | +} | |
23955 | + | |
23956 | +static void | |
23957 | +insert_acl_subj_label(struct acl_subject_label *obj, | |
23958 | + struct acl_role_label *role) | |
23959 | +{ | |
23960 | + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size); | |
23961 | + struct acl_subject_label **curr; | |
23962 | + | |
23963 | + obj->prev = NULL; | |
23964 | + | |
23965 | + curr = &role->subj_hash[index]; | |
23966 | + if (*curr != NULL) | |
23967 | + (*curr)->prev = obj; | |
23968 | + | |
23969 | + obj->next = *curr; | |
23970 | + *curr = obj; | |
23971 | + | |
23972 | + return; | |
23973 | +} | |
23974 | + | |
23975 | +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */ | |
23976 | + | |
23977 | +static void * | |
23978 | +create_table(__u32 * len, int elementsize) | |
23979 | +{ | |
23980 | + unsigned int table_sizes[] = { | |
23981 | + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381, | |
23982 | + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143, | |
de855c5d | 23983 | + 4194301, 8388593, 16777213, 33554393, 67108859 |
2380c486 JR |
23984 | + }; |
23985 | + void *newtable = NULL; | |
23986 | + unsigned int pwr = 0; | |
23987 | + | |
23988 | + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) && | |
23989 | + table_sizes[pwr] <= *len) | |
23990 | + pwr++; | |
23991 | + | |
de855c5d | 23992 | + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize)) |
2380c486 JR |
23993 | + return newtable; |
23994 | + | |
23995 | + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE) | |
23996 | + newtable = | |
23997 | + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL); | |
23998 | + else | |
23999 | + newtable = vmalloc(table_sizes[pwr] * elementsize); | |
24000 | + | |
24001 | + *len = table_sizes[pwr]; | |
24002 | + | |
24003 | + return newtable; | |
24004 | +} | |
24005 | + | |
24006 | +static int | |
24007 | +init_variables(const struct gr_arg *arg) | |
24008 | +{ | |
24009 | + struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper; | |
24010 | + unsigned int stacksize; | |
24011 | + | |
24012 | + subj_map_set.s_size = arg->role_db.num_subjects; | |
24013 | + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children; | |
24014 | + name_set.n_size = arg->role_db.num_objects; | |
24015 | + inodev_set.i_size = arg->role_db.num_objects; | |
24016 | + | |
24017 | + if (!subj_map_set.s_size || !acl_role_set.r_size || | |
24018 | + !name_set.n_size || !inodev_set.i_size) | |
24019 | + return 1; | |
24020 | + | |
24021 | + if (!gr_init_uidset()) | |
24022 | + return 1; | |
24023 | + | |
24024 | + /* set up the stack that holds allocation info */ | |
24025 | + | |
24026 | + stacksize = arg->role_db.num_pointers + 5; | |
24027 | + | |
24028 | + if (!acl_alloc_stack_init(stacksize)) | |
24029 | + return 1; | |
24030 | + | |
24031 | + /* grab reference for the real root dentry and vfsmount */ | |
24032 | + read_lock(&reaper->fs->lock); | |
24033 | + real_root_mnt = mntget(reaper->fs->root.mnt); | |
24034 | + real_root = dget(reaper->fs->root.dentry); | |
24035 | + read_unlock(&reaper->fs->lock); | |
24036 | + | |
24037 | + fakefs_obj = acl_alloc(sizeof(struct acl_object_label)); | |
24038 | + if (fakefs_obj == NULL) | |
24039 | + return 1; | |
24040 | + fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC; | |
24041 | + | |
24042 | + subj_map_set.s_hash = | |
24043 | + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *)); | |
24044 | + acl_role_set.r_hash = | |
24045 | + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *)); | |
24046 | + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *)); | |
24047 | + inodev_set.i_hash = | |
24048 | + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *)); | |
24049 | + | |
24050 | + if (!subj_map_set.s_hash || !acl_role_set.r_hash || | |
24051 | + !name_set.n_hash || !inodev_set.i_hash) | |
24052 | + return 1; | |
24053 | + | |
24054 | + memset(subj_map_set.s_hash, 0, | |
24055 | + sizeof(struct subject_map *) * subj_map_set.s_size); | |
24056 | + memset(acl_role_set.r_hash, 0, | |
24057 | + sizeof (struct acl_role_label *) * acl_role_set.r_size); | |
24058 | + memset(name_set.n_hash, 0, | |
24059 | + sizeof (struct name_entry *) * name_set.n_size); | |
24060 | + memset(inodev_set.i_hash, 0, | |
24061 | + sizeof (struct inodev_entry *) * inodev_set.i_size); | |
24062 | + | |
24063 | + return 0; | |
24064 | +} | |
24065 | + | |
24066 | +/* free information not needed after startup | |
24067 | + currently contains user->kernel pointer mappings for subjects | |
24068 | +*/ | |
24069 | + | |
24070 | +static void | |
24071 | +free_init_variables(void) | |
24072 | +{ | |
24073 | + __u32 i; | |
24074 | + | |
24075 | + if (subj_map_set.s_hash) { | |
24076 | + for (i = 0; i < subj_map_set.s_size; i++) { | |
24077 | + if (subj_map_set.s_hash[i]) { | |
24078 | + kfree(subj_map_set.s_hash[i]); | |
24079 | + subj_map_set.s_hash[i] = NULL; | |
24080 | + } | |
24081 | + } | |
24082 | + | |
24083 | + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <= | |
24084 | + PAGE_SIZE) | |
24085 | + kfree(subj_map_set.s_hash); | |
24086 | + else | |
24087 | + vfree(subj_map_set.s_hash); | |
24088 | + } | |
24089 | + | |
24090 | + return; | |
24091 | +} | |
24092 | + | |
24093 | +static void | |
24094 | +free_variables(void) | |
24095 | +{ | |
24096 | + struct acl_subject_label *s; | |
24097 | + struct acl_role_label *r; | |
24098 | + struct task_struct *task, *task2; | |
24099 | + unsigned int i, x; | |
24100 | + | |
24101 | + gr_clear_learn_entries(); | |
24102 | + | |
24103 | + read_lock(&tasklist_lock); | |
24104 | + do_each_thread(task2, task) { | |
24105 | + task->acl_sp_role = 0; | |
24106 | + task->acl_role_id = 0; | |
24107 | + task->acl = NULL; | |
24108 | + task->role = NULL; | |
24109 | + } while_each_thread(task2, task); | |
24110 | + read_unlock(&tasklist_lock); | |
24111 | + | |
24112 | + /* release the reference to the real root dentry and vfsmount */ | |
24113 | + if (real_root) | |
24114 | + dput(real_root); | |
24115 | + real_root = NULL; | |
24116 | + if (real_root_mnt) | |
24117 | + mntput(real_root_mnt); | |
24118 | + real_root_mnt = NULL; | |
24119 | + | |
24120 | + /* free all object hash tables */ | |
24121 | + | |
24122 | + FOR_EACH_ROLE_START(r, i) | |
24123 | + if (r->subj_hash == NULL) | |
24124 | + break; | |
24125 | + FOR_EACH_SUBJECT_START(r, s, x) | |
24126 | + if (s->obj_hash == NULL) | |
24127 | + break; | |
24128 | + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE) | |
24129 | + kfree(s->obj_hash); | |
24130 | + else | |
24131 | + vfree(s->obj_hash); | |
24132 | + FOR_EACH_SUBJECT_END(s, x) | |
24133 | + FOR_EACH_NESTED_SUBJECT_START(r, s) | |
24134 | + if (s->obj_hash == NULL) | |
24135 | + break; | |
24136 | + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE) | |
24137 | + kfree(s->obj_hash); | |
24138 | + else | |
24139 | + vfree(s->obj_hash); | |
24140 | + FOR_EACH_NESTED_SUBJECT_END(s) | |
24141 | + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE) | |
24142 | + kfree(r->subj_hash); | |
24143 | + else | |
24144 | + vfree(r->subj_hash); | |
24145 | + r->subj_hash = NULL; | |
24146 | + FOR_EACH_ROLE_END(r,i) | |
24147 | + | |
24148 | + acl_free_all(); | |
24149 | + | |
24150 | + if (acl_role_set.r_hash) { | |
24151 | + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <= | |
24152 | + PAGE_SIZE) | |
24153 | + kfree(acl_role_set.r_hash); | |
24154 | + else | |
24155 | + vfree(acl_role_set.r_hash); | |
24156 | + } | |
24157 | + if (name_set.n_hash) { | |
24158 | + if ((name_set.n_size * sizeof (struct name_entry *)) <= | |
24159 | + PAGE_SIZE) | |
24160 | + kfree(name_set.n_hash); | |
24161 | + else | |
24162 | + vfree(name_set.n_hash); | |
24163 | + } | |
24164 | + | |
24165 | + if (inodev_set.i_hash) { | |
24166 | + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <= | |
24167 | + PAGE_SIZE) | |
24168 | + kfree(inodev_set.i_hash); | |
24169 | + else | |
24170 | + vfree(inodev_set.i_hash); | |
24171 | + } | |
24172 | + | |
24173 | + gr_free_uidset(); | |
24174 | + | |
24175 | + memset(&name_set, 0, sizeof (struct name_db)); | |
24176 | + memset(&inodev_set, 0, sizeof (struct inodev_db)); | |
24177 | + memset(&acl_role_set, 0, sizeof (struct acl_role_db)); | |
24178 | + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db)); | |
24179 | + | |
24180 | + default_role = NULL; | |
24181 | + | |
24182 | + return; | |
24183 | +} | |
24184 | + | |
24185 | +static __u32 | |
24186 | +count_user_objs(struct acl_object_label *userp) | |
24187 | +{ | |
24188 | + struct acl_object_label o_tmp; | |
24189 | + __u32 num = 0; | |
24190 | + | |
24191 | + while (userp) { | |
24192 | + if (copy_from_user(&o_tmp, userp, | |
24193 | + sizeof (struct acl_object_label))) | |
24194 | + break; | |
24195 | + | |
24196 | + userp = o_tmp.prev; | |
24197 | + num++; | |
24198 | + } | |
24199 | + | |
24200 | + return num; | |
24201 | +} | |
24202 | + | |
24203 | +static struct acl_subject_label * | |
24204 | +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role); | |
24205 | + | |
24206 | +static int | |
24207 | +copy_user_glob(struct acl_object_label *obj) | |
24208 | +{ | |
24209 | + struct acl_object_label *g_tmp, **guser; | |
24210 | + unsigned int len; | |
24211 | + char *tmp; | |
24212 | + | |
24213 | + if (obj->globbed == NULL) | |
24214 | + return 0; | |
24215 | + | |
24216 | + guser = &obj->globbed; | |
24217 | + while (*guser) { | |
24218 | + g_tmp = (struct acl_object_label *) | |
24219 | + acl_alloc(sizeof (struct acl_object_label)); | |
24220 | + if (g_tmp == NULL) | |
24221 | + return -ENOMEM; | |
24222 | + | |
24223 | + if (copy_from_user(g_tmp, *guser, | |
24224 | + sizeof (struct acl_object_label))) | |
24225 | + return -EFAULT; | |
24226 | + | |
24227 | + len = strnlen_user(g_tmp->filename, PATH_MAX); | |
24228 | + | |
24229 | + if (!len || len >= PATH_MAX) | |
24230 | + return -EINVAL; | |
24231 | + | |
24232 | + if ((tmp = (char *) acl_alloc(len)) == NULL) | |
24233 | + return -ENOMEM; | |
24234 | + | |
24235 | + if (copy_from_user(tmp, g_tmp->filename, len)) | |
24236 | + return -EFAULT; | |
24237 | + | |
24238 | + g_tmp->filename = tmp; | |
24239 | + | |
24240 | + *guser = g_tmp; | |
24241 | + guser = &(g_tmp->next); | |
24242 | + } | |
24243 | + | |
24244 | + return 0; | |
24245 | +} | |
24246 | + | |
24247 | +static int | |
24248 | +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj, | |
24249 | + struct acl_role_label *role) | |
24250 | +{ | |
24251 | + struct acl_object_label *o_tmp; | |
24252 | + unsigned int len; | |
24253 | + int ret; | |
24254 | + char *tmp; | |
24255 | + | |
24256 | + while (userp) { | |
24257 | + if ((o_tmp = (struct acl_object_label *) | |
24258 | + acl_alloc(sizeof (struct acl_object_label))) == NULL) | |
24259 | + return -ENOMEM; | |
24260 | + | |
24261 | + if (copy_from_user(o_tmp, userp, | |
24262 | + sizeof (struct acl_object_label))) | |
24263 | + return -EFAULT; | |
24264 | + | |
24265 | + userp = o_tmp->prev; | |
24266 | + | |
24267 | + len = strnlen_user(o_tmp->filename, PATH_MAX); | |
24268 | + | |
24269 | + if (!len || len >= PATH_MAX) | |
24270 | + return -EINVAL; | |
24271 | + | |
24272 | + if ((tmp = (char *) acl_alloc(len)) == NULL) | |
24273 | + return -ENOMEM; | |
24274 | + | |
24275 | + if (copy_from_user(tmp, o_tmp->filename, len)) | |
24276 | + return -EFAULT; | |
24277 | + | |
24278 | + o_tmp->filename = tmp; | |
24279 | + | |
24280 | + insert_acl_obj_label(o_tmp, subj); | |
24281 | + if (!insert_name_entry(o_tmp->filename, o_tmp->inode, | |
24282 | + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0)) | |
24283 | + return -ENOMEM; | |
24284 | + | |
24285 | + ret = copy_user_glob(o_tmp); | |
24286 | + if (ret) | |
24287 | + return ret; | |
24288 | + | |
24289 | + if (o_tmp->nested) { | |
24290 | + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role); | |
24291 | + if (IS_ERR(o_tmp->nested)) | |
24292 | + return PTR_ERR(o_tmp->nested); | |
24293 | + | |
24294 | + /* insert into nested subject list */ | |
24295 | + o_tmp->nested->next = role->hash->first; | |
24296 | + role->hash->first = o_tmp->nested; | |
24297 | + } | |
24298 | + } | |
24299 | + | |
24300 | + return 0; | |
24301 | +} | |
24302 | + | |
24303 | +static __u32 | |
24304 | +count_user_subjs(struct acl_subject_label *userp) | |
24305 | +{ | |
24306 | + struct acl_subject_label s_tmp; | |
24307 | + __u32 num = 0; | |
24308 | + | |
24309 | + while (userp) { | |
24310 | + if (copy_from_user(&s_tmp, userp, | |
24311 | + sizeof (struct acl_subject_label))) | |
24312 | + break; | |
24313 | + | |
24314 | + userp = s_tmp.prev; | |
24315 | + /* do not count nested subjects against this count, since | |
24316 | + they are not included in the hash table, but are | |
24317 | + attached to objects. We have already counted | |
24318 | + the subjects in userspace for the allocation | |
24319 | + stack | |
24320 | + */ | |
24321 | + if (!(s_tmp.mode & GR_NESTED)) | |
24322 | + num++; | |
24323 | + } | |
24324 | + | |
24325 | + return num; | |
24326 | +} | |
24327 | + | |
24328 | +static int | |
24329 | +copy_user_allowedips(struct acl_role_label *rolep) | |
24330 | +{ | |
24331 | + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast; | |
24332 | + | |
24333 | + ruserip = rolep->allowed_ips; | |
24334 | + | |
24335 | + while (ruserip) { | |
24336 | + rlast = rtmp; | |
24337 | + | |
24338 | + if ((rtmp = (struct role_allowed_ip *) | |
24339 | + acl_alloc(sizeof (struct role_allowed_ip))) == NULL) | |
24340 | + return -ENOMEM; | |
24341 | + | |
24342 | + if (copy_from_user(rtmp, ruserip, | |
24343 | + sizeof (struct role_allowed_ip))) | |
24344 | + return -EFAULT; | |
24345 | + | |
24346 | + ruserip = rtmp->prev; | |
24347 | + | |
24348 | + if (!rlast) { | |
24349 | + rtmp->prev = NULL; | |
24350 | + rolep->allowed_ips = rtmp; | |
24351 | + } else { | |
24352 | + rlast->next = rtmp; | |
24353 | + rtmp->prev = rlast; | |
24354 | + } | |
24355 | + | |
24356 | + if (!ruserip) | |
24357 | + rtmp->next = NULL; | |
24358 | + } | |
24359 | + | |
24360 | + return 0; | |
24361 | +} | |
24362 | + | |
24363 | +static int | |
24364 | +copy_user_transitions(struct acl_role_label *rolep) | |
24365 | +{ | |
24366 | + struct role_transition *rusertp, *rtmp = NULL, *rlast; | |
24367 | + | |
24368 | + unsigned int len; | |
24369 | + char *tmp; | |
24370 | + | |
24371 | + rusertp = rolep->transitions; | |
24372 | + | |
24373 | + while (rusertp) { | |
24374 | + rlast = rtmp; | |
24375 | + | |
24376 | + if ((rtmp = (struct role_transition *) | |
24377 | + acl_alloc(sizeof (struct role_transition))) == NULL) | |
24378 | + return -ENOMEM; | |
24379 | + | |
24380 | + if (copy_from_user(rtmp, rusertp, | |
24381 | + sizeof (struct role_transition))) | |
24382 | + return -EFAULT; | |
24383 | + | |
24384 | + rusertp = rtmp->prev; | |
24385 | + | |
24386 | + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN); | |
24387 | + | |
24388 | + if (!len || len >= GR_SPROLE_LEN) | |
24389 | + return -EINVAL; | |
24390 | + | |
24391 | + if ((tmp = (char *) acl_alloc(len)) == NULL) | |
24392 | + return -ENOMEM; | |
24393 | + | |
24394 | + if (copy_from_user(tmp, rtmp->rolename, len)) | |
24395 | + return -EFAULT; | |
24396 | + | |
24397 | + rtmp->rolename = tmp; | |
24398 | + | |
24399 | + if (!rlast) { | |
24400 | + rtmp->prev = NULL; | |
24401 | + rolep->transitions = rtmp; | |
24402 | + } else { | |
24403 | + rlast->next = rtmp; | |
24404 | + rtmp->prev = rlast; | |
24405 | + } | |
24406 | + | |
24407 | + if (!rusertp) | |
24408 | + rtmp->next = NULL; | |
24409 | + } | |
24410 | + | |
24411 | + return 0; | |
24412 | +} | |
24413 | + | |
24414 | +static struct acl_subject_label * | |
24415 | +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role) | |
24416 | +{ | |
24417 | + struct acl_subject_label *s_tmp = NULL, *s_tmp2; | |
24418 | + unsigned int len; | |
24419 | + char *tmp; | |
24420 | + __u32 num_objs; | |
24421 | + struct acl_ip_label **i_tmp, *i_utmp2; | |
24422 | + struct gr_hash_struct ghash; | |
24423 | + struct subject_map *subjmap; | |
24424 | + unsigned int i_num; | |
24425 | + int err; | |
24426 | + | |
24427 | + s_tmp = lookup_subject_map(userp); | |
24428 | + | |
24429 | + /* we've already copied this subject into the kernel, just return | |
24430 | + the reference to it, and don't copy it over again | |
24431 | + */ | |
24432 | + if (s_tmp) | |
24433 | + return(s_tmp); | |
24434 | + | |
24435 | + if ((s_tmp = (struct acl_subject_label *) | |
24436 | + acl_alloc(sizeof (struct acl_subject_label))) == NULL) | |
24437 | + return ERR_PTR(-ENOMEM); | |
24438 | + | |
24439 | + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL); | |
24440 | + if (subjmap == NULL) | |
24441 | + return ERR_PTR(-ENOMEM); | |
24442 | + | |
24443 | + subjmap->user = userp; | |
24444 | + subjmap->kernel = s_tmp; | |
24445 | + insert_subj_map_entry(subjmap); | |
24446 | + | |
24447 | + if (copy_from_user(s_tmp, userp, | |
24448 | + sizeof (struct acl_subject_label))) | |
24449 | + return ERR_PTR(-EFAULT); | |
24450 | + | |
24451 | + len = strnlen_user(s_tmp->filename, PATH_MAX); | |
24452 | + | |
24453 | + if (!len || len >= PATH_MAX) | |
24454 | + return ERR_PTR(-EINVAL); | |
24455 | + | |
24456 | + if ((tmp = (char *) acl_alloc(len)) == NULL) | |
24457 | + return ERR_PTR(-ENOMEM); | |
24458 | + | |
24459 | + if (copy_from_user(tmp, s_tmp->filename, len)) | |
24460 | + return ERR_PTR(-EFAULT); | |
24461 | + | |
24462 | + s_tmp->filename = tmp; | |
24463 | + | |
24464 | + if (!strcmp(s_tmp->filename, "/")) | |
24465 | + role->root_label = s_tmp; | |
24466 | + | |
24467 | + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct))) | |
24468 | + return ERR_PTR(-EFAULT); | |
24469 | + | |
24470 | + /* copy user and group transition tables */ | |
24471 | + | |
24472 | + if (s_tmp->user_trans_num) { | |
24473 | + uid_t *uidlist; | |
24474 | + | |
de855c5d | 24475 | + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t)); |
2380c486 JR |
24476 | + if (uidlist == NULL) |
24477 | + return ERR_PTR(-ENOMEM); | |
24478 | + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t))) | |
24479 | + return ERR_PTR(-EFAULT); | |
24480 | + | |
24481 | + s_tmp->user_transitions = uidlist; | |
24482 | + } | |
24483 | + | |
24484 | + if (s_tmp->group_trans_num) { | |
24485 | + gid_t *gidlist; | |
24486 | + | |
de855c5d | 24487 | + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t)); |
2380c486 JR |
24488 | + if (gidlist == NULL) |
24489 | + return ERR_PTR(-ENOMEM); | |
24490 | + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t))) | |
24491 | + return ERR_PTR(-EFAULT); | |
24492 | + | |
24493 | + s_tmp->group_transitions = gidlist; | |
24494 | + } | |
24495 | + | |
24496 | + /* set up object hash table */ | |
24497 | + num_objs = count_user_objs(ghash.first); | |
24498 | + | |
24499 | + s_tmp->obj_hash_size = num_objs; | |
24500 | + s_tmp->obj_hash = | |
24501 | + (struct acl_object_label **) | |
24502 | + create_table(&(s_tmp->obj_hash_size), sizeof(void *)); | |
24503 | + | |
24504 | + if (!s_tmp->obj_hash) | |
24505 | + return ERR_PTR(-ENOMEM); | |
24506 | + | |
24507 | + memset(s_tmp->obj_hash, 0, | |
24508 | + s_tmp->obj_hash_size * | |
24509 | + sizeof (struct acl_object_label *)); | |
24510 | + | |
24511 | + /* add in objects */ | |
24512 | + err = copy_user_objs(ghash.first, s_tmp, role); | |
24513 | + | |
24514 | + if (err) | |
24515 | + return ERR_PTR(err); | |
24516 | + | |
24517 | + /* set pointer for parent subject */ | |
24518 | + if (s_tmp->parent_subject) { | |
24519 | + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role); | |
24520 | + | |
24521 | + if (IS_ERR(s_tmp2)) | |
24522 | + return s_tmp2; | |
24523 | + | |
24524 | + s_tmp->parent_subject = s_tmp2; | |
24525 | + } | |
24526 | + | |
24527 | + /* add in ip acls */ | |
24528 | + | |
24529 | + if (!s_tmp->ip_num) { | |
24530 | + s_tmp->ips = NULL; | |
24531 | + goto insert; | |
24532 | + } | |
24533 | + | |
24534 | + i_tmp = | |
de855c5d AM |
24535 | + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num, |
24536 | + sizeof (struct acl_ip_label *)); | |
2380c486 JR |
24537 | + |
24538 | + if (!i_tmp) | |
24539 | + return ERR_PTR(-ENOMEM); | |
24540 | + | |
24541 | + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) { | |
24542 | + *(i_tmp + i_num) = | |
24543 | + (struct acl_ip_label *) | |
24544 | + acl_alloc(sizeof (struct acl_ip_label)); | |
24545 | + if (!*(i_tmp + i_num)) | |
24546 | + return ERR_PTR(-ENOMEM); | |
24547 | + | |
24548 | + if (copy_from_user | |
24549 | + (&i_utmp2, s_tmp->ips + i_num, | |
24550 | + sizeof (struct acl_ip_label *))) | |
24551 | + return ERR_PTR(-EFAULT); | |
24552 | + | |
24553 | + if (copy_from_user | |
24554 | + (*(i_tmp + i_num), i_utmp2, | |
24555 | + sizeof (struct acl_ip_label))) | |
24556 | + return ERR_PTR(-EFAULT); | |
24557 | + | |
24558 | + if ((*(i_tmp + i_num))->iface == NULL) | |
24559 | + continue; | |
24560 | + | |
24561 | + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ); | |
24562 | + if (!len || len >= IFNAMSIZ) | |
24563 | + return ERR_PTR(-EINVAL); | |
24564 | + tmp = acl_alloc(len); | |
24565 | + if (tmp == NULL) | |
24566 | + return ERR_PTR(-ENOMEM); | |
24567 | + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len)) | |
24568 | + return ERR_PTR(-EFAULT); | |
24569 | + (*(i_tmp + i_num))->iface = tmp; | |
24570 | + } | |
24571 | + | |
24572 | + s_tmp->ips = i_tmp; | |
24573 | + | |
24574 | +insert: | |
24575 | + if (!insert_name_entry(s_tmp->filename, s_tmp->inode, | |
24576 | + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0)) | |
24577 | + return ERR_PTR(-ENOMEM); | |
24578 | + | |
24579 | + return s_tmp; | |
24580 | +} | |
24581 | + | |
24582 | +static int | |
24583 | +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role) | |
24584 | +{ | |
24585 | + struct acl_subject_label s_pre; | |
24586 | + struct acl_subject_label * ret; | |
24587 | + int err; | |
24588 | + | |
24589 | + while (userp) { | |
24590 | + if (copy_from_user(&s_pre, userp, | |
24591 | + sizeof (struct acl_subject_label))) | |
24592 | + return -EFAULT; | |
24593 | + | |
24594 | + /* do not add nested subjects here, add | |
24595 | + while parsing objects | |
24596 | + */ | |
24597 | + | |
24598 | + if (s_pre.mode & GR_NESTED) { | |
24599 | + userp = s_pre.prev; | |
24600 | + continue; | |
24601 | + } | |
24602 | + | |
24603 | + ret = do_copy_user_subj(userp, role); | |
24604 | + | |
24605 | + err = PTR_ERR(ret); | |
24606 | + if (IS_ERR(ret)) | |
24607 | + return err; | |
24608 | + | |
24609 | + insert_acl_subj_label(ret, role); | |
24610 | + | |
24611 | + userp = s_pre.prev; | |
24612 | + } | |
24613 | + | |
24614 | + return 0; | |
24615 | +} | |
24616 | + | |
24617 | +static int | |
24618 | +copy_user_acl(struct gr_arg *arg) | |
24619 | +{ | |
24620 | + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2; | |
24621 | + struct sprole_pw *sptmp; | |
24622 | + struct gr_hash_struct *ghash; | |
24623 | + uid_t *domainlist; | |
24624 | + unsigned int r_num; | |
24625 | + unsigned int len; | |
24626 | + char *tmp; | |
24627 | + int err = 0; | |
24628 | + __u16 i; | |
24629 | + __u32 num_subjs; | |
24630 | + | |
24631 | + /* we need a default and kernel role */ | |
24632 | + if (arg->role_db.num_roles < 2) | |
24633 | + return -EINVAL; | |
24634 | + | |
24635 | + /* copy special role authentication info from userspace */ | |
24636 | + | |
24637 | + num_sprole_pws = arg->num_sprole_pws; | |
de855c5d | 24638 | + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *)); |
2380c486 JR |
24639 | + |
24640 | + if (!acl_special_roles) { | |
24641 | + err = -ENOMEM; | |
24642 | + goto cleanup; | |
24643 | + } | |
24644 | + | |
24645 | + for (i = 0; i < num_sprole_pws; i++) { | |
24646 | + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw)); | |
24647 | + if (!sptmp) { | |
24648 | + err = -ENOMEM; | |
24649 | + goto cleanup; | |
24650 | + } | |
24651 | + if (copy_from_user(sptmp, arg->sprole_pws + i, | |
24652 | + sizeof (struct sprole_pw))) { | |
24653 | + err = -EFAULT; | |
24654 | + goto cleanup; | |
24655 | + } | |
24656 | + | |
24657 | + len = | |
24658 | + strnlen_user(sptmp->rolename, GR_SPROLE_LEN); | |
24659 | + | |
24660 | + if (!len || len >= GR_SPROLE_LEN) { | |
24661 | + err = -EINVAL; | |
24662 | + goto cleanup; | |
24663 | + } | |
24664 | + | |
24665 | + if ((tmp = (char *) acl_alloc(len)) == NULL) { | |
24666 | + err = -ENOMEM; | |
24667 | + goto cleanup; | |
24668 | + } | |
24669 | + | |
24670 | + if (copy_from_user(tmp, sptmp->rolename, len)) { | |
24671 | + err = -EFAULT; | |
24672 | + goto cleanup; | |
24673 | + } | |
24674 | + | |
24675 | +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG | |
24676 | + printk(KERN_ALERT "Copying special role %s\n", tmp); | |
24677 | +#endif | |
24678 | + sptmp->rolename = tmp; | |
24679 | + acl_special_roles[i] = sptmp; | |
24680 | + } | |
24681 | + | |
24682 | + r_utmp = (struct acl_role_label **) arg->role_db.r_table; | |
24683 | + | |
24684 | + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) { | |
24685 | + r_tmp = acl_alloc(sizeof (struct acl_role_label)); | |
24686 | + | |
24687 | + if (!r_tmp) { | |
24688 | + err = -ENOMEM; | |
24689 | + goto cleanup; | |
24690 | + } | |
24691 | + | |
24692 | + if (copy_from_user(&r_utmp2, r_utmp + r_num, | |
24693 | + sizeof (struct acl_role_label *))) { | |
24694 | + err = -EFAULT; | |
24695 | + goto cleanup; | |
24696 | + } | |
24697 | + | |
24698 | + if (copy_from_user(r_tmp, r_utmp2, | |
24699 | + sizeof (struct acl_role_label))) { | |
24700 | + err = -EFAULT; | |
24701 | + goto cleanup; | |
24702 | + } | |
24703 | + | |
24704 | + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN); | |
24705 | + | |
24706 | + if (!len || len >= PATH_MAX) { | |
24707 | + err = -EINVAL; | |
24708 | + goto cleanup; | |
24709 | + } | |
24710 | + | |
24711 | + if ((tmp = (char *) acl_alloc(len)) == NULL) { | |
24712 | + err = -ENOMEM; | |
24713 | + goto cleanup; | |
24714 | + } | |
24715 | + if (copy_from_user(tmp, r_tmp->rolename, len)) { | |
24716 | + err = -EFAULT; | |
24717 | + goto cleanup; | |
24718 | + } | |
24719 | + r_tmp->rolename = tmp; | |
24720 | + | |
24721 | + if (!strcmp(r_tmp->rolename, "default") | |
24722 | + && (r_tmp->roletype & GR_ROLE_DEFAULT)) { | |
24723 | + default_role = r_tmp; | |
24724 | + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) { | |
24725 | + kernel_role = r_tmp; | |
24726 | + } | |
24727 | + | |
24728 | + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) { | |
24729 | + err = -ENOMEM; | |
24730 | + goto cleanup; | |
24731 | + } | |
24732 | + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) { | |
24733 | + err = -EFAULT; | |
24734 | + goto cleanup; | |
24735 | + } | |
24736 | + | |
24737 | + r_tmp->hash = ghash; | |
24738 | + | |
24739 | + num_subjs = count_user_subjs(r_tmp->hash->first); | |
24740 | + | |
24741 | + r_tmp->subj_hash_size = num_subjs; | |
24742 | + r_tmp->subj_hash = | |
24743 | + (struct acl_subject_label **) | |
24744 | + create_table(&(r_tmp->subj_hash_size), sizeof(void *)); | |
24745 | + | |
24746 | + if (!r_tmp->subj_hash) { | |
24747 | + err = -ENOMEM; | |
24748 | + goto cleanup; | |
24749 | + } | |
24750 | + | |
24751 | + err = copy_user_allowedips(r_tmp); | |
24752 | + if (err) | |
24753 | + goto cleanup; | |
24754 | + | |
24755 | + /* copy domain info */ | |
24756 | + if (r_tmp->domain_children != NULL) { | |
de855c5d | 24757 | + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t)); |
2380c486 JR |
24758 | + if (domainlist == NULL) { |
24759 | + err = -ENOMEM; | |
24760 | + goto cleanup; | |
24761 | + } | |
24762 | + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) { | |
24763 | + err = -EFAULT; | |
24764 | + goto cleanup; | |
24765 | + } | |
24766 | + r_tmp->domain_children = domainlist; | |
24767 | + } | |
24768 | + | |
24769 | + err = copy_user_transitions(r_tmp); | |
24770 | + if (err) | |
24771 | + goto cleanup; | |
24772 | + | |
24773 | + memset(r_tmp->subj_hash, 0, | |
24774 | + r_tmp->subj_hash_size * | |
24775 | + sizeof (struct acl_subject_label *)); | |
24776 | + | |
24777 | + err = copy_user_subjs(r_tmp->hash->first, r_tmp); | |
24778 | + | |
24779 | + if (err) | |
24780 | + goto cleanup; | |
24781 | + | |
24782 | + /* set nested subject list to null */ | |
24783 | + r_tmp->hash->first = NULL; | |
24784 | + | |
24785 | + insert_acl_role_label(r_tmp); | |
24786 | + } | |
24787 | + | |
24788 | + goto return_err; | |
24789 | + cleanup: | |
24790 | + free_variables(); | |
24791 | + return_err: | |
24792 | + return err; | |
24793 | + | |
24794 | +} | |
24795 | + | |
24796 | +static int | |
24797 | +gracl_init(struct gr_arg *args) | |
24798 | +{ | |
24799 | + int error = 0; | |
24800 | + | |
24801 | + memcpy(gr_system_salt, args->salt, GR_SALT_LEN); | |
24802 | + memcpy(gr_system_sum, args->sum, GR_SHA_LEN); | |
24803 | + | |
24804 | + if (init_variables(args)) { | |
24805 | + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION); | |
24806 | + error = -ENOMEM; | |
24807 | + free_variables(); | |
24808 | + goto out; | |
24809 | + } | |
24810 | + | |
24811 | + error = copy_user_acl(args); | |
24812 | + free_init_variables(); | |
24813 | + if (error) { | |
24814 | + free_variables(); | |
24815 | + goto out; | |
24816 | + } | |
24817 | + | |
24818 | + if ((error = gr_set_acls(0))) { | |
24819 | + free_variables(); | |
24820 | + goto out; | |
24821 | + } | |
24822 | + | |
24823 | + gr_status |= GR_READY; | |
24824 | + out: | |
24825 | + return error; | |
24826 | +} | |
24827 | + | |
24828 | +/* derived from glibc fnmatch() 0: match, 1: no match*/ | |
24829 | + | |
24830 | +static int | |
24831 | +glob_match(const char *p, const char *n) | |
24832 | +{ | |
24833 | + char c; | |
24834 | + | |
24835 | + while ((c = *p++) != '\0') { | |
24836 | + switch (c) { | |
24837 | + case '?': | |
24838 | + if (*n == '\0') | |
24839 | + return 1; | |
24840 | + else if (*n == '/') | |
24841 | + return 1; | |
24842 | + break; | |
24843 | + case '\\': | |
24844 | + if (*n != c) | |
24845 | + return 1; | |
24846 | + break; | |
24847 | + case '*': | |
24848 | + for (c = *p++; c == '?' || c == '*'; c = *p++) { | |
24849 | + if (*n == '/') | |
24850 | + return 1; | |
24851 | + else if (c == '?') { | |
24852 | + if (*n == '\0') | |
24853 | + return 1; | |
24854 | + else | |
24855 | + ++n; | |
24856 | + } | |
24857 | + } | |
24858 | + if (c == '\0') { | |
24859 | + return 0; | |
24860 | + } else { | |
24861 | + const char *endp; | |
24862 | + | |
24863 | + if ((endp = strchr(n, '/')) == NULL) | |
24864 | + endp = n + strlen(n); | |
24865 | + | |
24866 | + if (c == '[') { | |
24867 | + for (--p; n < endp; ++n) | |
24868 | + if (!glob_match(p, n)) | |
24869 | + return 0; | |
24870 | + } else if (c == '/') { | |
24871 | + while (*n != '\0' && *n != '/') | |
24872 | + ++n; | |
24873 | + if (*n == '/' && !glob_match(p, n + 1)) | |
24874 | + return 0; | |
24875 | + } else { | |
24876 | + for (--p; n < endp; ++n) | |
24877 | + if (*n == c && !glob_match(p, n)) | |
24878 | + return 0; | |
24879 | + } | |
24880 | + | |
24881 | + return 1; | |
24882 | + } | |
24883 | + case '[': | |
24884 | + { | |
24885 | + int not; | |
24886 | + char cold; | |
24887 | + | |
24888 | + if (*n == '\0' || *n == '/') | |
24889 | + return 1; | |
24890 | + | |
24891 | + not = (*p == '!' || *p == '^'); | |
24892 | + if (not) | |
24893 | + ++p; | |
24894 | + | |
24895 | + c = *p++; | |
24896 | + for (;;) { | |
24897 | + unsigned char fn = (unsigned char)*n; | |
24898 | + | |
24899 | + if (c == '\0') | |
24900 | + return 1; | |
24901 | + else { | |
24902 | + if (c == fn) | |
24903 | + goto matched; | |
24904 | + cold = c; | |
24905 | + c = *p++; | |
24906 | + | |
24907 | + if (c == '-' && *p != ']') { | |
24908 | + unsigned char cend = *p++; | |
24909 | + | |
24910 | + if (cend == '\0') | |
24911 | + return 1; | |
24912 | + | |
24913 | + if (cold <= fn && fn <= cend) | |
24914 | + goto matched; | |
24915 | + | |
24916 | + c = *p++; | |
24917 | + } | |
24918 | + } | |
24919 | + | |
24920 | + if (c == ']') | |
24921 | + break; | |
24922 | + } | |
24923 | + if (!not) | |
24924 | + return 1; | |
24925 | + break; | |
24926 | + matched: | |
24927 | + while (c != ']') { | |
24928 | + if (c == '\0') | |
24929 | + return 1; | |
24930 | + | |
24931 | + c = *p++; | |
24932 | + } | |
24933 | + if (not) | |
24934 | + return 1; | |
24935 | + } | |
24936 | + break; | |
24937 | + default: | |
24938 | + if (c != *n) | |
24939 | + return 1; | |
24940 | + } | |
24941 | + | |
24942 | + ++n; | |
24943 | + } | |
24944 | + | |
24945 | + if (*n == '\0') | |
24946 | + return 0; | |
24947 | + | |
24948 | + if (*n == '/') | |
24949 | + return 0; | |
24950 | + | |
24951 | + return 1; | |
24952 | +} | |
24953 | + | |
24954 | +static struct acl_object_label * | |
24955 | +chk_glob_label(struct acl_object_label *globbed, | |
24956 | + struct dentry *dentry, struct vfsmount *mnt, char **path) | |
24957 | +{ | |
24958 | + struct acl_object_label *tmp; | |
24959 | + | |
24960 | + if (*path == NULL) | |
24961 | + *path = gr_to_filename_nolock(dentry, mnt); | |
24962 | + | |
24963 | + tmp = globbed; | |
24964 | + | |
24965 | + while (tmp) { | |
24966 | + if (!glob_match(tmp->filename, *path)) | |
24967 | + return tmp; | |
24968 | + tmp = tmp->next; | |
24969 | + } | |
24970 | + | |
24971 | + return NULL; | |
24972 | +} | |
24973 | + | |
24974 | +static struct acl_object_label * | |
24975 | +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt, | |
24976 | + const ino_t curr_ino, const dev_t curr_dev, | |
de855c5d | 24977 | + const struct acl_subject_label *subj, char **path, const int checkglob) |
2380c486 JR |
24978 | +{ |
24979 | + struct acl_subject_label *tmpsubj; | |
24980 | + struct acl_object_label *retval; | |
24981 | + struct acl_object_label *retval2; | |
24982 | + | |
24983 | + tmpsubj = (struct acl_subject_label *) subj; | |
24984 | + read_lock(&gr_inode_lock); | |
24985 | + do { | |
24986 | + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj); | |
24987 | + if (retval) { | |
de855c5d | 24988 | + if (checkglob && retval->globbed) { |
2380c486 JR |
24989 | + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry, |
24990 | + (struct vfsmount *)orig_mnt, path); | |
24991 | + if (retval2) | |
24992 | + retval = retval2; | |
24993 | + } | |
24994 | + break; | |
24995 | + } | |
24996 | + } while ((tmpsubj = tmpsubj->parent_subject)); | |
24997 | + read_unlock(&gr_inode_lock); | |
24998 | + | |
24999 | + return retval; | |
25000 | +} | |
25001 | + | |
25002 | +static __inline__ struct acl_object_label * | |
25003 | +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt, | |
25004 | + const struct dentry *curr_dentry, | |
de855c5d | 25005 | + const struct acl_subject_label *subj, char **path, const int checkglob) |
2380c486 JR |
25006 | +{ |
25007 | + return __full_lookup(orig_dentry, orig_mnt, | |
25008 | + curr_dentry->d_inode->i_ino, | |
de855c5d | 25009 | + curr_dentry->d_inode->i_sb->s_dev, subj, path, checkglob); |
2380c486 JR |
25010 | +} |
25011 | + | |
25012 | +static struct acl_object_label * | |
25013 | +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, | |
de855c5d | 25014 | + const struct acl_subject_label *subj, char *path, const int checkglob) |
2380c486 JR |
25015 | +{ |
25016 | + struct dentry *dentry = (struct dentry *) l_dentry; | |
25017 | + struct vfsmount *mnt = (struct vfsmount *) l_mnt; | |
25018 | + struct acl_object_label *retval; | |
25019 | + | |
25020 | + spin_lock(&dcache_lock); | |
25021 | + | |
25022 | + if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt || | |
25023 | + /* ignore Eric Biederman */ | |
25024 | + IS_PRIVATE(l_dentry->d_inode))) { | |
25025 | + retval = fakefs_obj; | |
25026 | + goto out; | |
25027 | + } | |
25028 | + | |
25029 | + for (;;) { | |
25030 | + if (dentry == real_root && mnt == real_root_mnt) | |
25031 | + break; | |
25032 | + | |
25033 | + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) { | |
25034 | + if (mnt->mnt_parent == mnt) | |
25035 | + break; | |
25036 | + | |
de855c5d | 25037 | + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob); |
2380c486 JR |
25038 | + if (retval != NULL) |
25039 | + goto out; | |
25040 | + | |
25041 | + dentry = mnt->mnt_mountpoint; | |
25042 | + mnt = mnt->mnt_parent; | |
25043 | + continue; | |
25044 | + } | |
25045 | + | |
de855c5d | 25046 | + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob); |
2380c486 JR |
25047 | + if (retval != NULL) |
25048 | + goto out; | |
25049 | + | |
25050 | + dentry = dentry->d_parent; | |
25051 | + } | |
25052 | + | |
de855c5d | 25053 | + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob); |
2380c486 JR |
25054 | + |
25055 | + if (retval == NULL) | |
de855c5d | 25056 | + retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob); |
2380c486 JR |
25057 | +out: |
25058 | + spin_unlock(&dcache_lock); | |
25059 | + return retval; | |
25060 | +} | |
25061 | + | |
25062 | +static __inline__ struct acl_object_label * | |
25063 | +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, | |
25064 | + const struct acl_subject_label *subj) | |
25065 | +{ | |
25066 | + char *path = NULL; | |
de855c5d AM |
25067 | + return __chk_obj_label(l_dentry, l_mnt, subj, path, 1); |
25068 | +} | |
25069 | + | |
25070 | +static __inline__ struct acl_object_label * | |
25071 | +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt, | |
25072 | + const struct acl_subject_label *subj) | |
25073 | +{ | |
25074 | + char *path = NULL; | |
25075 | + return __chk_obj_label(l_dentry, l_mnt, subj, path, 0); | |
2380c486 JR |
25076 | +} |
25077 | + | |
25078 | +static __inline__ struct acl_object_label * | |
25079 | +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, | |
25080 | + const struct acl_subject_label *subj, char *path) | |
25081 | +{ | |
de855c5d | 25082 | + return __chk_obj_label(l_dentry, l_mnt, subj, path, 1); |
2380c486 JR |
25083 | +} |
25084 | + | |
25085 | +static struct acl_subject_label * | |
25086 | +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, | |
25087 | + const struct acl_role_label *role) | |
25088 | +{ | |
25089 | + struct dentry *dentry = (struct dentry *) l_dentry; | |
25090 | + struct vfsmount *mnt = (struct vfsmount *) l_mnt; | |
25091 | + struct acl_subject_label *retval; | |
25092 | + | |
25093 | + spin_lock(&dcache_lock); | |
25094 | + | |
25095 | + for (;;) { | |
25096 | + if (dentry == real_root && mnt == real_root_mnt) | |
25097 | + break; | |
25098 | + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) { | |
25099 | + if (mnt->mnt_parent == mnt) | |
25100 | + break; | |
25101 | + | |
25102 | + read_lock(&gr_inode_lock); | |
25103 | + retval = | |
25104 | + lookup_acl_subj_label(dentry->d_inode->i_ino, | |
25105 | + dentry->d_inode->i_sb->s_dev, role); | |
25106 | + read_unlock(&gr_inode_lock); | |
25107 | + if (retval != NULL) | |
25108 | + goto out; | |
25109 | + | |
25110 | + dentry = mnt->mnt_mountpoint; | |
25111 | + mnt = mnt->mnt_parent; | |
25112 | + continue; | |
25113 | + } | |
25114 | + | |
25115 | + read_lock(&gr_inode_lock); | |
25116 | + retval = lookup_acl_subj_label(dentry->d_inode->i_ino, | |
25117 | + dentry->d_inode->i_sb->s_dev, role); | |
25118 | + read_unlock(&gr_inode_lock); | |
25119 | + if (retval != NULL) | |
25120 | + goto out; | |
25121 | + | |
25122 | + dentry = dentry->d_parent; | |
25123 | + } | |
25124 | + | |
25125 | + read_lock(&gr_inode_lock); | |
25126 | + retval = lookup_acl_subj_label(dentry->d_inode->i_ino, | |
25127 | + dentry->d_inode->i_sb->s_dev, role); | |
25128 | + read_unlock(&gr_inode_lock); | |
25129 | + | |
25130 | + if (unlikely(retval == NULL)) { | |
25131 | + read_lock(&gr_inode_lock); | |
25132 | + retval = lookup_acl_subj_label(real_root->d_inode->i_ino, | |
25133 | + real_root->d_inode->i_sb->s_dev, role); | |
25134 | + read_unlock(&gr_inode_lock); | |
25135 | + } | |
25136 | +out: | |
25137 | + spin_unlock(&dcache_lock); | |
25138 | + | |
25139 | + return retval; | |
25140 | +} | |
25141 | + | |
25142 | +static void | |
25143 | +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode) | |
25144 | +{ | |
25145 | + struct task_struct *task = current; | |
25146 | + const struct cred *cred = current_cred(); | |
25147 | + | |
25148 | + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype, | |
25149 | + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry, | |
25150 | + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename, | |
de855c5d | 25151 | + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip)); |
2380c486 JR |
25152 | + |
25153 | + return; | |
25154 | +} | |
25155 | + | |
25156 | +static void | |
25157 | +gr_log_learn_sysctl(const char *path, const __u32 mode) | |
25158 | +{ | |
25159 | + struct task_struct *task = current; | |
25160 | + const struct cred *cred = current_cred(); | |
25161 | + | |
25162 | + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype, | |
25163 | + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry, | |
25164 | + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename, | |
de855c5d | 25165 | + 1UL, 1UL, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip)); |
2380c486 JR |
25166 | + |
25167 | + return; | |
25168 | +} | |
25169 | + | |
25170 | +static void | |
25171 | +gr_log_learn_id_change(const char type, const unsigned int real, | |
25172 | + const unsigned int effective, const unsigned int fs) | |
25173 | +{ | |
25174 | + struct task_struct *task = current; | |
25175 | + const struct cred *cred = current_cred(); | |
25176 | + | |
25177 | + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype, | |
25178 | + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry, | |
25179 | + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename, | |
25180 | + type, real, effective, fs, NIPQUAD(task->signal->curr_ip)); | |
25181 | + | |
25182 | + return; | |
25183 | +} | |
25184 | + | |
25185 | +__u32 | |
25186 | +gr_check_link(const struct dentry * new_dentry, | |
25187 | + const struct dentry * parent_dentry, | |
25188 | + const struct vfsmount * parent_mnt, | |
25189 | + const struct dentry * old_dentry, const struct vfsmount * old_mnt) | |
25190 | +{ | |
25191 | + struct acl_object_label *obj; | |
25192 | + __u32 oldmode, newmode; | |
25193 | + __u32 needmode; | |
25194 | + | |
25195 | + if (unlikely(!(gr_status & GR_READY))) | |
25196 | + return (GR_CREATE | GR_LINK); | |
25197 | + | |
25198 | + obj = chk_obj_label(old_dentry, old_mnt, current->acl); | |
25199 | + oldmode = obj->mode; | |
25200 | + | |
25201 | + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) | |
25202 | + oldmode |= (GR_CREATE | GR_LINK); | |
25203 | + | |
25204 | + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS; | |
25205 | + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID)) | |
25206 | + needmode |= GR_SETID | GR_AUDIT_SETID; | |
25207 | + | |
25208 | + newmode = | |
25209 | + gr_check_create(new_dentry, parent_dentry, parent_mnt, | |
25210 | + oldmode | needmode); | |
25211 | + | |
25212 | + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | | |
25213 | + GR_SETID | GR_READ | GR_FIND | GR_DELETE | | |
25214 | + GR_INHERIT | GR_AUDIT_INHERIT); | |
25215 | + | |
25216 | + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID)) | |
25217 | + goto bad; | |
25218 | + | |
25219 | + if ((oldmode & needmode) != needmode) | |
25220 | + goto bad; | |
25221 | + | |
25222 | + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS); | |
25223 | + if ((newmode & needmode) != needmode) | |
25224 | + goto bad; | |
25225 | + | |
25226 | + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK)) | |
25227 | + return newmode; | |
25228 | +bad: | |
25229 | + needmode = oldmode; | |
25230 | + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID)) | |
25231 | + needmode |= GR_SETID; | |
25232 | + | |
25233 | + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) { | |
25234 | + gr_log_learn(old_dentry, old_mnt, needmode); | |
25235 | + return (GR_CREATE | GR_LINK); | |
25236 | + } else if (newmode & GR_SUPPRESS) | |
25237 | + return GR_SUPPRESS; | |
25238 | + else | |
25239 | + return 0; | |
25240 | +} | |
25241 | + | |
25242 | +__u32 | |
25243 | +gr_search_file(const struct dentry * dentry, const __u32 mode, | |
25244 | + const struct vfsmount * mnt) | |
25245 | +{ | |
25246 | + __u32 retval = mode; | |
25247 | + struct acl_subject_label *curracl; | |
25248 | + struct acl_object_label *currobj; | |
25249 | + | |
25250 | + if (unlikely(!(gr_status & GR_READY))) | |
25251 | + return (mode & ~GR_AUDITS); | |
25252 | + | |
25253 | + curracl = current->acl; | |
25254 | + | |
25255 | + currobj = chk_obj_label(dentry, mnt, curracl); | |
25256 | + retval = currobj->mode & mode; | |
25257 | + | |
25258 | + if (unlikely | |
25259 | + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE) | |
25260 | + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) { | |
25261 | + __u32 new_mode = mode; | |
25262 | + | |
25263 | + new_mode &= ~(GR_AUDITS | GR_SUPPRESS); | |
25264 | + | |
25265 | + retval = new_mode; | |
25266 | + | |
25267 | + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN) | |
25268 | + new_mode |= GR_INHERIT; | |
25269 | + | |
25270 | + if (!(mode & GR_NOLEARN)) | |
25271 | + gr_log_learn(dentry, mnt, new_mode); | |
25272 | + } | |
25273 | + | |
25274 | + return retval; | |
25275 | +} | |
25276 | + | |
25277 | +__u32 | |
25278 | +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent, | |
25279 | + const struct vfsmount * mnt, const __u32 mode) | |
25280 | +{ | |
25281 | + struct name_entry *match; | |
25282 | + struct acl_object_label *matchpo; | |
25283 | + struct acl_subject_label *curracl; | |
25284 | + char *path; | |
25285 | + __u32 retval; | |
25286 | + | |
25287 | + if (unlikely(!(gr_status & GR_READY))) | |
25288 | + return (mode & ~GR_AUDITS); | |
25289 | + | |
25290 | + preempt_disable(); | |
25291 | + path = gr_to_filename_rbac(new_dentry, mnt); | |
25292 | + match = lookup_name_entry_create(path); | |
25293 | + | |
25294 | + if (!match) | |
25295 | + goto check_parent; | |
25296 | + | |
25297 | + curracl = current->acl; | |
25298 | + | |
25299 | + read_lock(&gr_inode_lock); | |
25300 | + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl); | |
25301 | + read_unlock(&gr_inode_lock); | |
25302 | + | |
25303 | + if (matchpo) { | |
25304 | + if ((matchpo->mode & mode) != | |
25305 | + (mode & ~(GR_AUDITS | GR_SUPPRESS)) | |
25306 | + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) { | |
25307 | + __u32 new_mode = mode; | |
25308 | + | |
25309 | + new_mode &= ~(GR_AUDITS | GR_SUPPRESS); | |
25310 | + | |
25311 | + gr_log_learn(new_dentry, mnt, new_mode); | |
25312 | + | |
25313 | + preempt_enable(); | |
25314 | + return new_mode; | |
25315 | + } | |
25316 | + preempt_enable(); | |
25317 | + return (matchpo->mode & mode); | |
25318 | + } | |
25319 | + | |
25320 | + check_parent: | |
25321 | + curracl = current->acl; | |
25322 | + | |
25323 | + matchpo = chk_obj_create_label(parent, mnt, curracl, path); | |
25324 | + retval = matchpo->mode & mode; | |
25325 | + | |
25326 | + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))) | |
25327 | + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) { | |
25328 | + __u32 new_mode = mode; | |
25329 | + | |
25330 | + new_mode &= ~(GR_AUDITS | GR_SUPPRESS); | |
25331 | + | |
25332 | + gr_log_learn(new_dentry, mnt, new_mode); | |
25333 | + preempt_enable(); | |
25334 | + return new_mode; | |
25335 | + } | |
25336 | + | |
25337 | + preempt_enable(); | |
25338 | + return retval; | |
25339 | +} | |
25340 | + | |
25341 | +int | |
25342 | +gr_check_hidden_task(const struct task_struct *task) | |
25343 | +{ | |
25344 | + if (unlikely(!(gr_status & GR_READY))) | |
25345 | + return 0; | |
25346 | + | |
25347 | + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW)) | |
25348 | + return 1; | |
25349 | + | |
25350 | + return 0; | |
25351 | +} | |
25352 | + | |
25353 | +int | |
25354 | +gr_check_protected_task(const struct task_struct *task) | |
25355 | +{ | |
25356 | + if (unlikely(!(gr_status & GR_READY) || !task)) | |
25357 | + return 0; | |
25358 | + | |
25359 | + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) && | |
25360 | + task->acl != current->acl) | |
25361 | + return 1; | |
25362 | + | |
25363 | + return 0; | |
25364 | +} | |
25365 | + | |
25366 | +void | |
25367 | +gr_copy_label(struct task_struct *tsk) | |
25368 | +{ | |
25369 | + tsk->signal->used_accept = 0; | |
25370 | + tsk->acl_sp_role = 0; | |
25371 | + tsk->acl_role_id = current->acl_role_id; | |
25372 | + tsk->acl = current->acl; | |
25373 | + tsk->role = current->role; | |
25374 | + tsk->signal->curr_ip = current->signal->curr_ip; | |
25375 | + if (current->exec_file) | |
25376 | + get_file(current->exec_file); | |
25377 | + tsk->exec_file = current->exec_file; | |
25378 | + tsk->is_writable = current->is_writable; | |
25379 | + if (unlikely(current->signal->used_accept)) | |
25380 | + current->signal->curr_ip = 0; | |
25381 | + | |
25382 | + return; | |
25383 | +} | |
25384 | + | |
25385 | +static void | |
25386 | +gr_set_proc_res(struct task_struct *task) | |
25387 | +{ | |
25388 | + struct acl_subject_label *proc; | |
25389 | + unsigned short i; | |
25390 | + | |
25391 | + proc = task->acl; | |
25392 | + | |
25393 | + if (proc->mode & (GR_LEARN | GR_INHERITLEARN)) | |
25394 | + return; | |
25395 | + | |
25396 | + for (i = 0; i < RLIM_NLIMITS; i++) { | |
25397 | + if (!(proc->resmask & (1 << i))) | |
25398 | + continue; | |
25399 | + | |
25400 | + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur; | |
25401 | + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max; | |
25402 | + } | |
25403 | + | |
25404 | + return; | |
25405 | +} | |
25406 | + | |
25407 | +int | |
25408 | +gr_check_user_change(int real, int effective, int fs) | |
25409 | +{ | |
25410 | + unsigned int i; | |
25411 | + __u16 num; | |
25412 | + uid_t *uidlist; | |
25413 | + int curuid; | |
25414 | + int realok = 0; | |
25415 | + int effectiveok = 0; | |
25416 | + int fsok = 0; | |
25417 | + | |
25418 | + if (unlikely(!(gr_status & GR_READY))) | |
25419 | + return 0; | |
25420 | + | |
25421 | + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) | |
25422 | + gr_log_learn_id_change('u', real, effective, fs); | |
25423 | + | |
25424 | + num = current->acl->user_trans_num; | |
25425 | + uidlist = current->acl->user_transitions; | |
25426 | + | |
25427 | + if (uidlist == NULL) | |
25428 | + return 0; | |
25429 | + | |
25430 | + if (real == -1) | |
25431 | + realok = 1; | |
25432 | + if (effective == -1) | |
25433 | + effectiveok = 1; | |
25434 | + if (fs == -1) | |
25435 | + fsok = 1; | |
25436 | + | |
25437 | + if (current->acl->user_trans_type & GR_ID_ALLOW) { | |
25438 | + for (i = 0; i < num; i++) { | |
25439 | + curuid = (int)uidlist[i]; | |
25440 | + if (real == curuid) | |
25441 | + realok = 1; | |
25442 | + if (effective == curuid) | |
25443 | + effectiveok = 1; | |
25444 | + if (fs == curuid) | |
25445 | + fsok = 1; | |
25446 | + } | |
25447 | + } else if (current->acl->user_trans_type & GR_ID_DENY) { | |
25448 | + for (i = 0; i < num; i++) { | |
25449 | + curuid = (int)uidlist[i]; | |
25450 | + if (real == curuid) | |
25451 | + break; | |
25452 | + if (effective == curuid) | |
25453 | + break; | |
25454 | + if (fs == curuid) | |
25455 | + break; | |
25456 | + } | |
25457 | + /* not in deny list */ | |
25458 | + if (i == num) { | |
25459 | + realok = 1; | |
25460 | + effectiveok = 1; | |
25461 | + fsok = 1; | |
25462 | + } | |
25463 | + } | |
25464 | + | |
25465 | + if (realok && effectiveok && fsok) | |
25466 | + return 0; | |
25467 | + else { | |
25468 | + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real); | |
25469 | + return 1; | |
25470 | + } | |
25471 | +} | |
25472 | + | |
25473 | +int | |
25474 | +gr_check_group_change(int real, int effective, int fs) | |
25475 | +{ | |
25476 | + unsigned int i; | |
25477 | + __u16 num; | |
25478 | + gid_t *gidlist; | |
25479 | + int curgid; | |
25480 | + int realok = 0; | |
25481 | + int effectiveok = 0; | |
25482 | + int fsok = 0; | |
25483 | + | |
25484 | + if (unlikely(!(gr_status & GR_READY))) | |
25485 | + return 0; | |
25486 | + | |
25487 | + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) | |
25488 | + gr_log_learn_id_change('g', real, effective, fs); | |
25489 | + | |
25490 | + num = current->acl->group_trans_num; | |
25491 | + gidlist = current->acl->group_transitions; | |
25492 | + | |
25493 | + if (gidlist == NULL) | |
25494 | + return 0; | |
25495 | + | |
25496 | + if (real == -1) | |
25497 | + realok = 1; | |
25498 | + if (effective == -1) | |
25499 | + effectiveok = 1; | |
25500 | + if (fs == -1) | |
25501 | + fsok = 1; | |
25502 | + | |
25503 | + if (current->acl->group_trans_type & GR_ID_ALLOW) { | |
25504 | + for (i = 0; i < num; i++) { | |
25505 | + curgid = (int)gidlist[i]; | |
25506 | + if (real == curgid) | |
25507 | + realok = 1; | |
25508 | + if (effective == curgid) | |
25509 | + effectiveok = 1; | |
25510 | + if (fs == curgid) | |
25511 | + fsok = 1; | |
25512 | + } | |
25513 | + } else if (current->acl->group_trans_type & GR_ID_DENY) { | |
25514 | + for (i = 0; i < num; i++) { | |
25515 | + curgid = (int)gidlist[i]; | |
25516 | + if (real == curgid) | |
25517 | + break; | |
25518 | + if (effective == curgid) | |
25519 | + break; | |
25520 | + if (fs == curgid) | |
25521 | + break; | |
25522 | + } | |
25523 | + /* not in deny list */ | |
25524 | + if (i == num) { | |
25525 | + realok = 1; | |
25526 | + effectiveok = 1; | |
25527 | + fsok = 1; | |
25528 | + } | |
25529 | + } | |
25530 | + | |
25531 | + if (realok && effectiveok && fsok) | |
25532 | + return 0; | |
25533 | + else { | |
25534 | + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real); | |
25535 | + return 1; | |
25536 | + } | |
25537 | +} | |
25538 | + | |
25539 | +void | |
25540 | +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid) | |
25541 | +{ | |
25542 | + struct acl_role_label *role = task->role; | |
25543 | + struct acl_subject_label *subj = NULL; | |
25544 | + struct acl_object_label *obj; | |
25545 | + struct file *filp; | |
25546 | + | |
25547 | + if (unlikely(!(gr_status & GR_READY))) | |
25548 | + return; | |
25549 | + | |
25550 | + filp = task->exec_file; | |
25551 | + | |
25552 | + /* kernel process, we'll give them the kernel role */ | |
25553 | + if (unlikely(!filp)) { | |
25554 | + task->role = kernel_role; | |
25555 | + task->acl = kernel_role->root_label; | |
25556 | + return; | |
25557 | + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) | |
25558 | + role = lookup_acl_role_label(task, uid, gid); | |
25559 | + | |
25560 | + /* perform subject lookup in possibly new role | |
25561 | + we can use this result below in the case where role == task->role | |
25562 | + */ | |
25563 | + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role); | |
25564 | + | |
25565 | + /* if we changed uid/gid, but result in the same role | |
25566 | + and are using inheritance, don't lose the inherited subject | |
25567 | + if current subject is other than what normal lookup | |
25568 | + would result in, we arrived via inheritance, don't | |
25569 | + lose subject | |
25570 | + */ | |
25571 | + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) && | |
25572 | + (subj == task->acl))) | |
25573 | + task->acl = subj; | |
25574 | + | |
25575 | + task->role = role; | |
25576 | + | |
25577 | + task->is_writable = 0; | |
25578 | + | |
25579 | + /* ignore additional mmap checks for processes that are writable | |
25580 | + by the default ACL */ | |
25581 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label); | |
25582 | + if (unlikely(obj->mode & GR_WRITE)) | |
25583 | + task->is_writable = 1; | |
25584 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label); | |
25585 | + if (unlikely(obj->mode & GR_WRITE)) | |
25586 | + task->is_writable = 1; | |
25587 | + | |
25588 | +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG | |
25589 | + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename); | |
25590 | +#endif | |
25591 | + | |
25592 | + gr_set_proc_res(task); | |
25593 | + | |
25594 | + return; | |
25595 | +} | |
25596 | + | |
25597 | +int | |
de855c5d AM |
25598 | +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt, |
25599 | + const int unsafe_share) | |
2380c486 JR |
25600 | +{ |
25601 | + struct task_struct *task = current; | |
25602 | + struct acl_subject_label *newacl; | |
25603 | + struct acl_object_label *obj; | |
25604 | + __u32 retmode; | |
25605 | + | |
25606 | + if (unlikely(!(gr_status & GR_READY))) | |
25607 | + return 0; | |
25608 | + | |
25609 | + newacl = chk_subj_label(dentry, mnt, task->role); | |
25610 | + | |
25611 | + task_lock(task); | |
25612 | + if (((task->ptrace & PT_PTRACED) && !(task->acl->mode & | |
25613 | + GR_POVERRIDE) && (task->acl != newacl) && | |
25614 | + !(task->role->roletype & GR_ROLE_GOD) && | |
25615 | + !gr_search_file(dentry, GR_PTRACERD, mnt) && | |
de855c5d AM |
25616 | + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) |
25617 | + || unsafe_share) { | |
2380c486 JR |
25618 | + task_unlock(task); |
25619 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt); | |
25620 | + return -EACCES; | |
25621 | + } | |
25622 | + task_unlock(task); | |
25623 | + | |
25624 | + obj = chk_obj_label(dentry, mnt, task->acl); | |
25625 | + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT); | |
25626 | + | |
25627 | + if (!(task->acl->mode & GR_INHERITLEARN) && | |
25628 | + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) { | |
25629 | + if (obj->nested) | |
25630 | + task->acl = obj->nested; | |
25631 | + else | |
25632 | + task->acl = newacl; | |
25633 | + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT) | |
25634 | + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt); | |
25635 | + | |
25636 | + task->is_writable = 0; | |
25637 | + | |
25638 | + /* ignore additional mmap checks for processes that are writable | |
25639 | + by the default ACL */ | |
25640 | + obj = chk_obj_label(dentry, mnt, default_role->root_label); | |
25641 | + if (unlikely(obj->mode & GR_WRITE)) | |
25642 | + task->is_writable = 1; | |
25643 | + obj = chk_obj_label(dentry, mnt, task->role->root_label); | |
25644 | + if (unlikely(obj->mode & GR_WRITE)) | |
25645 | + task->is_writable = 1; | |
25646 | + | |
25647 | + gr_set_proc_res(task); | |
25648 | + | |
25649 | +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG | |
25650 | + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename); | |
25651 | +#endif | |
25652 | + return 0; | |
25653 | +} | |
25654 | + | |
25655 | +/* always called with valid inodev ptr */ | |
25656 | +static void | |
25657 | +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev) | |
25658 | +{ | |
25659 | + struct acl_object_label *matchpo; | |
25660 | + struct acl_subject_label *matchps; | |
25661 | + struct acl_subject_label *subj; | |
25662 | + struct acl_role_label *role; | |
25663 | + unsigned int i, x; | |
25664 | + | |
25665 | + FOR_EACH_ROLE_START(role, i) | |
25666 | + FOR_EACH_SUBJECT_START(role, subj, x) | |
25667 | + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL) | |
25668 | + matchpo->mode |= GR_DELETED; | |
25669 | + FOR_EACH_SUBJECT_END(subj,x) | |
25670 | + FOR_EACH_NESTED_SUBJECT_START(role, subj) | |
25671 | + if (subj->inode == ino && subj->device == dev) | |
25672 | + subj->mode |= GR_DELETED; | |
25673 | + FOR_EACH_NESTED_SUBJECT_END(subj) | |
25674 | + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL) | |
25675 | + matchps->mode |= GR_DELETED; | |
25676 | + FOR_EACH_ROLE_END(role,i) | |
25677 | + | |
25678 | + inodev->nentry->deleted = 1; | |
25679 | + | |
25680 | + return; | |
25681 | +} | |
25682 | + | |
25683 | +void | |
25684 | +gr_handle_delete(const ino_t ino, const dev_t dev) | |
25685 | +{ | |
25686 | + struct inodev_entry *inodev; | |
25687 | + | |
25688 | + if (unlikely(!(gr_status & GR_READY))) | |
25689 | + return; | |
25690 | + | |
25691 | + write_lock(&gr_inode_lock); | |
25692 | + inodev = lookup_inodev_entry(ino, dev); | |
25693 | + if (inodev != NULL) | |
25694 | + do_handle_delete(inodev, ino, dev); | |
25695 | + write_unlock(&gr_inode_lock); | |
25696 | + | |
25697 | + return; | |
25698 | +} | |
25699 | + | |
25700 | +static void | |
25701 | +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice, | |
25702 | + const ino_t newinode, const dev_t newdevice, | |
25703 | + struct acl_subject_label *subj) | |
25704 | +{ | |
25705 | + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size); | |
25706 | + struct acl_object_label *match; | |
25707 | + | |
25708 | + match = subj->obj_hash[index]; | |
25709 | + | |
25710 | + while (match && (match->inode != oldinode || | |
25711 | + match->device != olddevice || | |
25712 | + !(match->mode & GR_DELETED))) | |
25713 | + match = match->next; | |
25714 | + | |
25715 | + if (match && (match->inode == oldinode) | |
25716 | + && (match->device == olddevice) | |
25717 | + && (match->mode & GR_DELETED)) { | |
25718 | + if (match->prev == NULL) { | |
25719 | + subj->obj_hash[index] = match->next; | |
25720 | + if (match->next != NULL) | |
25721 | + match->next->prev = NULL; | |
25722 | + } else { | |
25723 | + match->prev->next = match->next; | |
25724 | + if (match->next != NULL) | |
25725 | + match->next->prev = match->prev; | |
25726 | + } | |
25727 | + match->prev = NULL; | |
25728 | + match->next = NULL; | |
25729 | + match->inode = newinode; | |
25730 | + match->device = newdevice; | |
25731 | + match->mode &= ~GR_DELETED; | |
25732 | + | |
25733 | + insert_acl_obj_label(match, subj); | |
25734 | + } | |
25735 | + | |
25736 | + return; | |
25737 | +} | |
25738 | + | |
25739 | +static void | |
25740 | +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice, | |
25741 | + const ino_t newinode, const dev_t newdevice, | |
25742 | + struct acl_role_label *role) | |
25743 | +{ | |
25744 | + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size); | |
25745 | + struct acl_subject_label *match; | |
25746 | + | |
25747 | + match = role->subj_hash[index]; | |
25748 | + | |
25749 | + while (match && (match->inode != oldinode || | |
25750 | + match->device != olddevice || | |
25751 | + !(match->mode & GR_DELETED))) | |
25752 | + match = match->next; | |
25753 | + | |
25754 | + if (match && (match->inode == oldinode) | |
25755 | + && (match->device == olddevice) | |
25756 | + && (match->mode & GR_DELETED)) { | |
25757 | + if (match->prev == NULL) { | |
25758 | + role->subj_hash[index] = match->next; | |
25759 | + if (match->next != NULL) | |
25760 | + match->next->prev = NULL; | |
25761 | + } else { | |
25762 | + match->prev->next = match->next; | |
25763 | + if (match->next != NULL) | |
25764 | + match->next->prev = match->prev; | |
25765 | + } | |
25766 | + match->prev = NULL; | |
25767 | + match->next = NULL; | |
25768 | + match->inode = newinode; | |
25769 | + match->device = newdevice; | |
25770 | + match->mode &= ~GR_DELETED; | |
25771 | + | |
25772 | + insert_acl_subj_label(match, role); | |
25773 | + } | |
25774 | + | |
25775 | + return; | |
25776 | +} | |
25777 | + | |
25778 | +static void | |
25779 | +update_inodev_entry(const ino_t oldinode, const dev_t olddevice, | |
25780 | + const ino_t newinode, const dev_t newdevice) | |
25781 | +{ | |
25782 | + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size); | |
25783 | + struct inodev_entry *match; | |
25784 | + | |
25785 | + match = inodev_set.i_hash[index]; | |
25786 | + | |
25787 | + while (match && (match->nentry->inode != oldinode || | |
25788 | + match->nentry->device != olddevice || !match->nentry->deleted)) | |
25789 | + match = match->next; | |
25790 | + | |
25791 | + if (match && (match->nentry->inode == oldinode) | |
25792 | + && (match->nentry->device == olddevice) && | |
25793 | + match->nentry->deleted) { | |
25794 | + if (match->prev == NULL) { | |
25795 | + inodev_set.i_hash[index] = match->next; | |
25796 | + if (match->next != NULL) | |
25797 | + match->next->prev = NULL; | |
25798 | + } else { | |
25799 | + match->prev->next = match->next; | |
25800 | + if (match->next != NULL) | |
25801 | + match->next->prev = match->prev; | |
25802 | + } | |
25803 | + match->prev = NULL; | |
25804 | + match->next = NULL; | |
25805 | + match->nentry->inode = newinode; | |
25806 | + match->nentry->device = newdevice; | |
25807 | + match->nentry->deleted = 0; | |
25808 | + | |
25809 | + insert_inodev_entry(match); | |
25810 | + } | |
25811 | + | |
25812 | + return; | |
25813 | +} | |
25814 | + | |
25815 | +static void | |
25816 | +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry, | |
25817 | + const struct vfsmount *mnt) | |
25818 | +{ | |
25819 | + struct acl_subject_label *subj; | |
25820 | + struct acl_role_label *role; | |
25821 | + unsigned int i, x; | |
25822 | + | |
25823 | + FOR_EACH_ROLE_START(role, i) | |
25824 | + update_acl_subj_label(matchn->inode, matchn->device, | |
25825 | + dentry->d_inode->i_ino, | |
25826 | + dentry->d_inode->i_sb->s_dev, role); | |
25827 | + | |
25828 | + FOR_EACH_NESTED_SUBJECT_START(role, subj) | |
25829 | + if ((subj->inode == dentry->d_inode->i_ino) && | |
25830 | + (subj->device == dentry->d_inode->i_sb->s_dev)) { | |
25831 | + subj->inode = dentry->d_inode->i_ino; | |
25832 | + subj->device = dentry->d_inode->i_sb->s_dev; | |
25833 | + } | |
25834 | + FOR_EACH_NESTED_SUBJECT_END(subj) | |
25835 | + FOR_EACH_SUBJECT_START(role, subj, x) | |
25836 | + update_acl_obj_label(matchn->inode, matchn->device, | |
25837 | + dentry->d_inode->i_ino, | |
25838 | + dentry->d_inode->i_sb->s_dev, subj); | |
25839 | + FOR_EACH_SUBJECT_END(subj,x) | |
25840 | + FOR_EACH_ROLE_END(role,i) | |
25841 | + | |
25842 | + update_inodev_entry(matchn->inode, matchn->device, | |
25843 | + dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev); | |
25844 | + | |
25845 | + return; | |
25846 | +} | |
25847 | + | |
25848 | +void | |
25849 | +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt) | |
25850 | +{ | |
25851 | + struct name_entry *matchn; | |
25852 | + | |
25853 | + if (unlikely(!(gr_status & GR_READY))) | |
25854 | + return; | |
25855 | + | |
25856 | + preempt_disable(); | |
25857 | + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt)); | |
25858 | + | |
25859 | + if (unlikely((unsigned long)matchn)) { | |
25860 | + write_lock(&gr_inode_lock); | |
25861 | + do_handle_create(matchn, dentry, mnt); | |
25862 | + write_unlock(&gr_inode_lock); | |
25863 | + } | |
25864 | + preempt_enable(); | |
25865 | + | |
25866 | + return; | |
25867 | +} | |
25868 | + | |
25869 | +void | |
25870 | +gr_handle_rename(struct inode *old_dir, struct inode *new_dir, | |
25871 | + struct dentry *old_dentry, | |
25872 | + struct dentry *new_dentry, | |
25873 | + struct vfsmount *mnt, const __u8 replace) | |
25874 | +{ | |
25875 | + struct name_entry *matchn; | |
25876 | + struct inodev_entry *inodev; | |
25877 | + | |
25878 | + /* vfs_rename swaps the name and parent link for old_dentry and | |
25879 | + new_dentry | |
25880 | + at this point, old_dentry has the new name, parent link, and inode | |
25881 | + for the renamed file | |
25882 | + if a file is being replaced by a rename, new_dentry has the inode | |
25883 | + and name for the replaced file | |
25884 | + */ | |
25885 | + | |
25886 | + if (unlikely(!(gr_status & GR_READY))) | |
25887 | + return; | |
25888 | + | |
25889 | + preempt_disable(); | |
25890 | + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt)); | |
25891 | + | |
25892 | + /* we wouldn't have to check d_inode if it weren't for | |
25893 | + NFS silly-renaming | |
25894 | + */ | |
25895 | + | |
25896 | + write_lock(&gr_inode_lock); | |
25897 | + if (unlikely(replace && new_dentry->d_inode)) { | |
25898 | + inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino, | |
25899 | + new_dentry->d_inode->i_sb->s_dev); | |
25900 | + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1)) | |
25901 | + do_handle_delete(inodev, new_dentry->d_inode->i_ino, | |
25902 | + new_dentry->d_inode->i_sb->s_dev); | |
25903 | + } | |
25904 | + | |
25905 | + inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino, | |
25906 | + old_dentry->d_inode->i_sb->s_dev); | |
25907 | + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1)) | |
25908 | + do_handle_delete(inodev, old_dentry->d_inode->i_ino, | |
25909 | + old_dentry->d_inode->i_sb->s_dev); | |
25910 | + | |
25911 | + if (unlikely((unsigned long)matchn)) | |
25912 | + do_handle_create(matchn, old_dentry, mnt); | |
25913 | + | |
25914 | + write_unlock(&gr_inode_lock); | |
25915 | + preempt_enable(); | |
25916 | + | |
25917 | + return; | |
25918 | +} | |
25919 | + | |
25920 | +static int | |
25921 | +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt, | |
25922 | + unsigned char **sum) | |
25923 | +{ | |
25924 | + struct acl_role_label *r; | |
25925 | + struct role_allowed_ip *ipp; | |
25926 | + struct role_transition *trans; | |
25927 | + unsigned int i; | |
25928 | + int found = 0; | |
25929 | + | |
25930 | + /* check transition table */ | |
25931 | + | |
25932 | + for (trans = current->role->transitions; trans; trans = trans->next) { | |
25933 | + if (!strcmp(rolename, trans->rolename)) { | |
25934 | + found = 1; | |
25935 | + break; | |
25936 | + } | |
25937 | + } | |
25938 | + | |
25939 | + if (!found) | |
25940 | + return 0; | |
25941 | + | |
25942 | + /* handle special roles that do not require authentication | |
25943 | + and check ip */ | |
25944 | + | |
25945 | + FOR_EACH_ROLE_START(r, i) | |
25946 | + if (!strcmp(rolename, r->rolename) && | |
25947 | + (r->roletype & GR_ROLE_SPECIAL)) { | |
25948 | + found = 0; | |
25949 | + if (r->allowed_ips != NULL) { | |
25950 | + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) { | |
25951 | + if ((ntohl(current->signal->curr_ip) & ipp->netmask) == | |
25952 | + (ntohl(ipp->addr) & ipp->netmask)) | |
25953 | + found = 1; | |
25954 | + } | |
25955 | + } else | |
25956 | + found = 2; | |
25957 | + if (!found) | |
25958 | + return 0; | |
25959 | + | |
25960 | + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) || | |
25961 | + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) { | |
25962 | + *salt = NULL; | |
25963 | + *sum = NULL; | |
25964 | + return 1; | |
25965 | + } | |
25966 | + } | |
25967 | + FOR_EACH_ROLE_END(r,i) | |
25968 | + | |
25969 | + for (i = 0; i < num_sprole_pws; i++) { | |
25970 | + if (!strcmp(rolename, acl_special_roles[i]->rolename)) { | |
25971 | + *salt = acl_special_roles[i]->salt; | |
25972 | + *sum = acl_special_roles[i]->sum; | |
25973 | + return 1; | |
25974 | + } | |
25975 | + } | |
25976 | + | |
25977 | + return 0; | |
25978 | +} | |
25979 | + | |
25980 | +static void | |
25981 | +assign_special_role(char *rolename) | |
25982 | +{ | |
25983 | + struct acl_object_label *obj; | |
25984 | + struct acl_role_label *r; | |
25985 | + struct acl_role_label *assigned = NULL; | |
25986 | + struct task_struct *tsk; | |
25987 | + struct file *filp; | |
25988 | + unsigned int i; | |
25989 | + | |
25990 | + FOR_EACH_ROLE_START(r, i) | |
25991 | + if (!strcmp(rolename, r->rolename) && | |
25992 | + (r->roletype & GR_ROLE_SPECIAL)) | |
25993 | + assigned = r; | |
25994 | + FOR_EACH_ROLE_END(r,i) | |
25995 | + | |
25996 | + if (!assigned) | |
25997 | + return; | |
25998 | + | |
25999 | + read_lock(&tasklist_lock); | |
26000 | + read_lock(&grsec_exec_file_lock); | |
26001 | + | |
26002 | + tsk = current->parent; | |
26003 | + if (tsk == NULL) | |
26004 | + goto out_unlock; | |
26005 | + | |
26006 | + filp = tsk->exec_file; | |
26007 | + if (filp == NULL) | |
26008 | + goto out_unlock; | |
26009 | + | |
26010 | + tsk->is_writable = 0; | |
26011 | + | |
26012 | + tsk->acl_sp_role = 1; | |
26013 | + tsk->acl_role_id = ++acl_sp_role_value; | |
26014 | + tsk->role = assigned; | |
26015 | + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role); | |
26016 | + | |
26017 | + /* ignore additional mmap checks for processes that are writable | |
26018 | + by the default ACL */ | |
26019 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label); | |
26020 | + if (unlikely(obj->mode & GR_WRITE)) | |
26021 | + tsk->is_writable = 1; | |
26022 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label); | |
26023 | + if (unlikely(obj->mode & GR_WRITE)) | |
26024 | + tsk->is_writable = 1; | |
26025 | + | |
26026 | +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG | |
26027 | + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid); | |
26028 | +#endif | |
26029 | + | |
26030 | +out_unlock: | |
26031 | + read_unlock(&grsec_exec_file_lock); | |
26032 | + read_unlock(&tasklist_lock); | |
26033 | + return; | |
26034 | +} | |
26035 | + | |
26036 | +int gr_check_secure_terminal(struct task_struct *task) | |
26037 | +{ | |
26038 | + struct task_struct *p, *p2, *p3; | |
26039 | + struct files_struct *files; | |
26040 | + struct fdtable *fdt; | |
26041 | + struct file *our_file = NULL, *file; | |
26042 | + int i; | |
26043 | + | |
26044 | + if (task->signal->tty == NULL) | |
26045 | + return 1; | |
26046 | + | |
26047 | + files = get_files_struct(task); | |
26048 | + if (files != NULL) { | |
26049 | + rcu_read_lock(); | |
26050 | + fdt = files_fdtable(files); | |
26051 | + for (i=0; i < fdt->max_fds; i++) { | |
26052 | + file = fcheck_files(files, i); | |
26053 | + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) { | |
26054 | + get_file(file); | |
26055 | + our_file = file; | |
26056 | + } | |
26057 | + } | |
26058 | + rcu_read_unlock(); | |
26059 | + put_files_struct(files); | |
26060 | + } | |
26061 | + | |
26062 | + if (our_file == NULL) | |
26063 | + return 1; | |
26064 | + | |
26065 | + read_lock(&tasklist_lock); | |
26066 | + do_each_thread(p2, p) { | |
26067 | + files = get_files_struct(p); | |
26068 | + if (files == NULL || | |
26069 | + (p->signal && p->signal->tty == task->signal->tty)) { | |
26070 | + if (files != NULL) | |
26071 | + put_files_struct(files); | |
26072 | + continue; | |
26073 | + } | |
26074 | + rcu_read_lock(); | |
26075 | + fdt = files_fdtable(files); | |
26076 | + for (i=0; i < fdt->max_fds; i++) { | |
26077 | + file = fcheck_files(files, i); | |
26078 | + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) && | |
26079 | + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) { | |
26080 | + p3 = task; | |
26081 | + while (p3->pid > 0) { | |
26082 | + if (p3 == p) | |
26083 | + break; | |
26084 | + p3 = p3->parent; | |
26085 | + } | |
26086 | + if (p3 == p) | |
26087 | + break; | |
26088 | + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p); | |
26089 | + gr_handle_alertkill(p); | |
26090 | + rcu_read_unlock(); | |
26091 | + put_files_struct(files); | |
26092 | + read_unlock(&tasklist_lock); | |
26093 | + fput(our_file); | |
26094 | + return 0; | |
26095 | + } | |
26096 | + } | |
26097 | + rcu_read_unlock(); | |
26098 | + put_files_struct(files); | |
26099 | + } while_each_thread(p2, p); | |
26100 | + read_unlock(&tasklist_lock); | |
26101 | + | |
26102 | + fput(our_file); | |
26103 | + return 1; | |
26104 | +} | |
26105 | + | |
26106 | +ssize_t | |
26107 | +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos) | |
26108 | +{ | |
26109 | + struct gr_arg_wrapper uwrap; | |
26110 | + unsigned char *sprole_salt; | |
26111 | + unsigned char *sprole_sum; | |
26112 | + int error = sizeof (struct gr_arg_wrapper); | |
26113 | + int error2 = 0; | |
26114 | + | |
26115 | + down(&gr_dev_sem); | |
26116 | + | |
26117 | + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) { | |
26118 | + error = -EPERM; | |
26119 | + goto out; | |
26120 | + } | |
26121 | + | |
26122 | + if (count != sizeof (struct gr_arg_wrapper)) { | |
26123 | + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper)); | |
26124 | + error = -EINVAL; | |
26125 | + goto out; | |
26126 | + } | |
26127 | + | |
26128 | + | |
26129 | + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) { | |
26130 | + gr_auth_expires = 0; | |
26131 | + gr_auth_attempts = 0; | |
26132 | + } | |
26133 | + | |
26134 | + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) { | |
26135 | + error = -EFAULT; | |
26136 | + goto out; | |
26137 | + } | |
26138 | + | |
26139 | + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) { | |
26140 | + error = -EINVAL; | |
26141 | + goto out; | |
26142 | + } | |
26143 | + | |
26144 | + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) { | |
26145 | + error = -EFAULT; | |
26146 | + goto out; | |
26147 | + } | |
26148 | + | |
26149 | + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM && | |
26150 | + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES && | |
26151 | + time_after(gr_auth_expires, get_seconds())) { | |
26152 | + error = -EBUSY; | |
26153 | + goto out; | |
26154 | + } | |
26155 | + | |
26156 | + /* if non-root trying to do anything other than use a special role, | |
26157 | + do not attempt authentication, do not count towards authentication | |
26158 | + locking | |
26159 | + */ | |
26160 | + | |
26161 | + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS && | |
26162 | + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM && | |
26163 | + current_uid()) { | |
26164 | + error = -EPERM; | |
26165 | + goto out; | |
26166 | + } | |
26167 | + | |
26168 | + /* ensure pw and special role name are null terminated */ | |
26169 | + | |
26170 | + gr_usermode->pw[GR_PW_LEN - 1] = '\0'; | |
26171 | + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0'; | |
26172 | + | |
26173 | + /* Okay. | |
26174 | + * We have our enough of the argument structure..(we have yet | |
26175 | + * to copy_from_user the tables themselves) . Copy the tables | |
26176 | + * only if we need them, i.e. for loading operations. */ | |
26177 | + | |
26178 | + switch (gr_usermode->mode) { | |
26179 | + case GR_STATUS: | |
26180 | + if (gr_status & GR_READY) { | |
26181 | + error = 1; | |
26182 | + if (!gr_check_secure_terminal(current)) | |
26183 | + error = 3; | |
26184 | + } else | |
26185 | + error = 2; | |
26186 | + goto out; | |
26187 | + case GR_SHUTDOWN: | |
26188 | + if ((gr_status & GR_READY) | |
26189 | + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) { | |
26190 | + gr_status &= ~GR_READY; | |
26191 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG); | |
26192 | + free_variables(); | |
26193 | + memset(gr_usermode, 0, sizeof (struct gr_arg)); | |
26194 | + memset(gr_system_salt, 0, GR_SALT_LEN); | |
26195 | + memset(gr_system_sum, 0, GR_SHA_LEN); | |
26196 | + } else if (gr_status & GR_READY) { | |
26197 | + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG); | |
26198 | + error = -EPERM; | |
26199 | + } else { | |
26200 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG); | |
26201 | + error = -EAGAIN; | |
26202 | + } | |
26203 | + break; | |
26204 | + case GR_ENABLE: | |
26205 | + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode))) | |
26206 | + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION); | |
26207 | + else { | |
26208 | + if (gr_status & GR_READY) | |
26209 | + error = -EAGAIN; | |
26210 | + else | |
26211 | + error = error2; | |
26212 | + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION); | |
26213 | + } | |
26214 | + break; | |
26215 | + case GR_RELOAD: | |
26216 | + if (!(gr_status & GR_READY)) { | |
26217 | + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION); | |
26218 | + error = -EAGAIN; | |
26219 | + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) { | |
26220 | + lock_kernel(); | |
26221 | + gr_status &= ~GR_READY; | |
26222 | + free_variables(); | |
26223 | + if (!(error2 = gracl_init(gr_usermode))) { | |
26224 | + unlock_kernel(); | |
26225 | + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION); | |
26226 | + } else { | |
26227 | + unlock_kernel(); | |
26228 | + error = error2; | |
26229 | + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION); | |
26230 | + } | |
26231 | + } else { | |
26232 | + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION); | |
26233 | + error = -EPERM; | |
26234 | + } | |
26235 | + break; | |
26236 | + case GR_SEGVMOD: | |
26237 | + if (unlikely(!(gr_status & GR_READY))) { | |
26238 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG); | |
26239 | + error = -EAGAIN; | |
26240 | + break; | |
26241 | + } | |
26242 | + | |
26243 | + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) { | |
26244 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG); | |
26245 | + if (gr_usermode->segv_device && gr_usermode->segv_inode) { | |
26246 | + struct acl_subject_label *segvacl; | |
26247 | + segvacl = | |
26248 | + lookup_acl_subj_label(gr_usermode->segv_inode, | |
26249 | + gr_usermode->segv_device, | |
26250 | + current->role); | |
26251 | + if (segvacl) { | |
26252 | + segvacl->crashes = 0; | |
26253 | + segvacl->expires = 0; | |
26254 | + } | |
26255 | + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) { | |
26256 | + gr_remove_uid(gr_usermode->segv_uid); | |
26257 | + } | |
26258 | + } else { | |
26259 | + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG); | |
26260 | + error = -EPERM; | |
26261 | + } | |
26262 | + break; | |
26263 | + case GR_SPROLE: | |
26264 | + case GR_SPROLEPAM: | |
26265 | + if (unlikely(!(gr_status & GR_READY))) { | |
26266 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG); | |
26267 | + error = -EAGAIN; | |
26268 | + break; | |
26269 | + } | |
26270 | + | |
26271 | + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) { | |
26272 | + current->role->expires = 0; | |
26273 | + current->role->auth_attempts = 0; | |
26274 | + } | |
26275 | + | |
26276 | + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES && | |
26277 | + time_after(current->role->expires, get_seconds())) { | |
26278 | + error = -EBUSY; | |
26279 | + goto out; | |
26280 | + } | |
26281 | + | |
26282 | + if (lookup_special_role_auth | |
26283 | + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum) | |
26284 | + && ((!sprole_salt && !sprole_sum) | |
26285 | + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) { | |
26286 | + char *p = ""; | |
26287 | + assign_special_role(gr_usermode->sp_role); | |
26288 | + read_lock(&tasklist_lock); | |
26289 | + if (current->parent) | |
26290 | + p = current->parent->role->rolename; | |
26291 | + read_unlock(&tasklist_lock); | |
26292 | + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG, | |
26293 | + p, acl_sp_role_value); | |
26294 | + } else { | |
26295 | + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role); | |
26296 | + error = -EPERM; | |
26297 | + if(!(current->role->auth_attempts++)) | |
26298 | + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT; | |
26299 | + | |
26300 | + goto out; | |
26301 | + } | |
26302 | + break; | |
26303 | + case GR_UNSPROLE: | |
26304 | + if (unlikely(!(gr_status & GR_READY))) { | |
26305 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG); | |
26306 | + error = -EAGAIN; | |
26307 | + break; | |
26308 | + } | |
26309 | + | |
26310 | + if (current->role->roletype & GR_ROLE_SPECIAL) { | |
26311 | + char *p = ""; | |
26312 | + int i = 0; | |
26313 | + | |
26314 | + read_lock(&tasklist_lock); | |
26315 | + if (current->parent) { | |
26316 | + p = current->parent->role->rolename; | |
26317 | + i = current->parent->acl_role_id; | |
26318 | + } | |
26319 | + read_unlock(&tasklist_lock); | |
26320 | + | |
26321 | + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i); | |
26322 | + gr_set_acls(1); | |
26323 | + } else { | |
26324 | + gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename); | |
26325 | + error = -EPERM; | |
26326 | + goto out; | |
26327 | + } | |
26328 | + break; | |
26329 | + default: | |
26330 | + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode); | |
26331 | + error = -EINVAL; | |
26332 | + break; | |
26333 | + } | |
26334 | + | |
26335 | + if (error != -EPERM) | |
26336 | + goto out; | |
26337 | + | |
26338 | + if(!(gr_auth_attempts++)) | |
26339 | + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT; | |
26340 | + | |
26341 | + out: | |
26342 | + up(&gr_dev_sem); | |
26343 | + return error; | |
26344 | +} | |
26345 | + | |
26346 | +int | |
26347 | +gr_set_acls(const int type) | |
26348 | +{ | |
26349 | + struct acl_object_label *obj; | |
26350 | + struct task_struct *task, *task2; | |
26351 | + struct file *filp; | |
26352 | + struct acl_role_label *role = current->role; | |
26353 | + __u16 acl_role_id = current->acl_role_id; | |
26354 | + const struct cred *cred; | |
de855c5d AM |
26355 | + char *tmpname; |
26356 | + struct name_entry *nmatch; | |
26357 | + struct acl_subject_label *tmpsubj; | |
2380c486 JR |
26358 | + |
26359 | + read_lock(&tasklist_lock); | |
26360 | + read_lock(&grsec_exec_file_lock); | |
26361 | + do_each_thread(task2, task) { | |
26362 | + /* check to see if we're called from the exit handler, | |
26363 | + if so, only replace ACLs that have inherited the admin | |
26364 | + ACL */ | |
26365 | + | |
26366 | + if (type && (task->role != role || | |
26367 | + task->acl_role_id != acl_role_id)) | |
26368 | + continue; | |
26369 | + | |
26370 | + task->acl_role_id = 0; | |
26371 | + task->acl_sp_role = 0; | |
26372 | + | |
26373 | + if ((filp = task->exec_file)) { | |
26374 | + cred = __task_cred(task); | |
26375 | + task->role = lookup_acl_role_label(task, cred->uid, cred->gid); | |
26376 | + | |
de855c5d AM |
26377 | + /* the following is to apply the correct subject |
26378 | + on binaries running when the RBAC system | |
26379 | + is enabled, when the binaries have been | |
26380 | + replaced or deleted since their execution | |
26381 | + ----- | |
26382 | + when the RBAC system starts, the inode/dev | |
26383 | + from exec_file will be one the RBAC system | |
26384 | + is unaware of. It only knows the inode/dev | |
26385 | + of the present file on disk, or the absence | |
26386 | + of it. | |
26387 | + */ | |
26388 | + preempt_disable(); | |
26389 | + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt); | |
26390 | + | |
26391 | + nmatch = lookup_name_entry(tmpname); | |
26392 | + preempt_enable(); | |
26393 | + tmpsubj = NULL; | |
26394 | + if (nmatch) { | |
26395 | + if (nmatch->deleted) | |
26396 | + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role); | |
26397 | + else | |
26398 | + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role); | |
26399 | + if (tmpsubj != NULL) | |
26400 | + task->acl = tmpsubj; | |
26401 | + } | |
26402 | + if (tmpsubj == NULL) | |
26403 | + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, | |
26404 | + task->role); | |
2380c486 JR |
26405 | + if (task->acl) { |
26406 | + struct acl_subject_label *curr; | |
26407 | + curr = task->acl; | |
26408 | + | |
26409 | + task->is_writable = 0; | |
26410 | + /* ignore additional mmap checks for processes that are writable | |
26411 | + by the default ACL */ | |
26412 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label); | |
26413 | + if (unlikely(obj->mode & GR_WRITE)) | |
26414 | + task->is_writable = 1; | |
26415 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label); | |
26416 | + if (unlikely(obj->mode & GR_WRITE)) | |
26417 | + task->is_writable = 1; | |
26418 | + | |
26419 | + gr_set_proc_res(task); | |
26420 | + | |
26421 | +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG | |
26422 | + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename); | |
26423 | +#endif | |
26424 | + } else { | |
26425 | + read_unlock(&grsec_exec_file_lock); | |
26426 | + read_unlock(&tasklist_lock); | |
26427 | + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid); | |
26428 | + return 1; | |
26429 | + } | |
26430 | + } else { | |
26431 | + // it's a kernel process | |
26432 | + task->role = kernel_role; | |
26433 | + task->acl = kernel_role->root_label; | |
26434 | +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN | |
26435 | + task->acl->mode &= ~GR_PROCFIND; | |
26436 | +#endif | |
26437 | + } | |
26438 | + } while_each_thread(task2, task); | |
26439 | + read_unlock(&grsec_exec_file_lock); | |
26440 | + read_unlock(&tasklist_lock); | |
26441 | + return 0; | |
26442 | +} | |
26443 | + | |
26444 | +void | |
26445 | +gr_learn_resource(const struct task_struct *task, | |
26446 | + const int res, const unsigned long wanted, const int gt) | |
26447 | +{ | |
26448 | + struct acl_subject_label *acl; | |
de855c5d | 26449 | + const struct cred *cred; |
2380c486 JR |
26450 | + |
26451 | + if (unlikely((gr_status & GR_READY) && | |
26452 | + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) | |
26453 | + goto skip_reslog; | |
26454 | + | |
26455 | +#ifdef CONFIG_GRKERNSEC_RESLOG | |
26456 | + gr_log_resource(task, res, wanted, gt); | |
26457 | +#endif | |
26458 | + skip_reslog: | |
26459 | + | |
26460 | + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS)) | |
26461 | + return; | |
26462 | + | |
26463 | + acl = task->acl; | |
26464 | + | |
26465 | + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) || | |
26466 | + !(acl->resmask & (1 << (unsigned short) res)))) | |
26467 | + return; | |
26468 | + | |
26469 | + if (wanted >= acl->res[res].rlim_cur) { | |
26470 | + unsigned long res_add; | |
26471 | + | |
26472 | + res_add = wanted; | |
26473 | + switch (res) { | |
26474 | + case RLIMIT_CPU: | |
26475 | + res_add += GR_RLIM_CPU_BUMP; | |
26476 | + break; | |
26477 | + case RLIMIT_FSIZE: | |
26478 | + res_add += GR_RLIM_FSIZE_BUMP; | |
26479 | + break; | |
26480 | + case RLIMIT_DATA: | |
26481 | + res_add += GR_RLIM_DATA_BUMP; | |
26482 | + break; | |
26483 | + case RLIMIT_STACK: | |
26484 | + res_add += GR_RLIM_STACK_BUMP; | |
26485 | + break; | |
26486 | + case RLIMIT_CORE: | |
26487 | + res_add += GR_RLIM_CORE_BUMP; | |
26488 | + break; | |
26489 | + case RLIMIT_RSS: | |
26490 | + res_add += GR_RLIM_RSS_BUMP; | |
26491 | + break; | |
26492 | + case RLIMIT_NPROC: | |
26493 | + res_add += GR_RLIM_NPROC_BUMP; | |
26494 | + break; | |
26495 | + case RLIMIT_NOFILE: | |
26496 | + res_add += GR_RLIM_NOFILE_BUMP; | |
26497 | + break; | |
26498 | + case RLIMIT_MEMLOCK: | |
26499 | + res_add += GR_RLIM_MEMLOCK_BUMP; | |
26500 | + break; | |
26501 | + case RLIMIT_AS: | |
26502 | + res_add += GR_RLIM_AS_BUMP; | |
26503 | + break; | |
26504 | + case RLIMIT_LOCKS: | |
26505 | + res_add += GR_RLIM_LOCKS_BUMP; | |
26506 | + break; | |
26507 | + case RLIMIT_SIGPENDING: | |
26508 | + res_add += GR_RLIM_SIGPENDING_BUMP; | |
26509 | + break; | |
26510 | + case RLIMIT_MSGQUEUE: | |
26511 | + res_add += GR_RLIM_MSGQUEUE_BUMP; | |
26512 | + break; | |
26513 | + case RLIMIT_NICE: | |
26514 | + res_add += GR_RLIM_NICE_BUMP; | |
26515 | + break; | |
26516 | + case RLIMIT_RTPRIO: | |
26517 | + res_add += GR_RLIM_RTPRIO_BUMP; | |
26518 | + break; | |
26519 | + case RLIMIT_RTTIME: | |
26520 | + res_add += GR_RLIM_RTTIME_BUMP; | |
26521 | + break; | |
26522 | + } | |
26523 | + | |
26524 | + acl->res[res].rlim_cur = res_add; | |
26525 | + | |
26526 | + if (wanted > acl->res[res].rlim_max) | |
26527 | + acl->res[res].rlim_max = res_add; | |
26528 | + | |
de855c5d AM |
26529 | + /* only log the subject filename, since resource logging is supported for |
26530 | + single-subject learning only */ | |
26531 | + cred = __task_cred(task); | |
2380c486 | 26532 | + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, |
de855c5d AM |
26533 | + task->role->roletype, cred->uid, cred->gid, acl->filename, |
26534 | + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max, | |
26535 | + "", (unsigned long) res, NIPQUAD(task->signal->curr_ip)); | |
2380c486 JR |
26536 | + } |
26537 | + | |
26538 | + return; | |
26539 | +} | |
26540 | + | |
de855c5d | 26541 | +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)) |
2380c486 JR |
26542 | +void |
26543 | +pax_set_initial_flags(struct linux_binprm *bprm) | |
26544 | +{ | |
26545 | + struct task_struct *task = current; | |
26546 | + struct acl_subject_label *proc; | |
26547 | + unsigned long flags; | |
26548 | + | |
26549 | + if (unlikely(!(gr_status & GR_READY))) | |
26550 | + return; | |
26551 | + | |
26552 | + flags = pax_get_flags(task); | |
26553 | + | |
26554 | + proc = task->acl; | |
26555 | + | |
26556 | + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC) | |
26557 | + flags &= ~MF_PAX_PAGEEXEC; | |
26558 | + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC) | |
26559 | + flags &= ~MF_PAX_SEGMEXEC; | |
26560 | + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP) | |
26561 | + flags &= ~MF_PAX_RANDMMAP; | |
26562 | + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP) | |
26563 | + flags &= ~MF_PAX_EMUTRAMP; | |
26564 | + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT) | |
26565 | + flags &= ~MF_PAX_MPROTECT; | |
26566 | + | |
26567 | + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC) | |
26568 | + flags |= MF_PAX_PAGEEXEC; | |
26569 | + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC) | |
26570 | + flags |= MF_PAX_SEGMEXEC; | |
26571 | + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP) | |
26572 | + flags |= MF_PAX_RANDMMAP; | |
26573 | + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP) | |
26574 | + flags |= MF_PAX_EMUTRAMP; | |
26575 | + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT) | |
26576 | + flags |= MF_PAX_MPROTECT; | |
26577 | + | |
26578 | + pax_set_flags(task, flags); | |
26579 | + | |
26580 | + return; | |
26581 | +} | |
26582 | +#endif | |
26583 | + | |
26584 | +#ifdef CONFIG_SYSCTL | |
26585 | +/* Eric Biederman likes breaking userland ABI and every inode-based security | |
26586 | + system to save 35kb of memory */ | |
26587 | + | |
26588 | +/* we modify the passed in filename, but adjust it back before returning */ | |
26589 | +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len) | |
26590 | +{ | |
26591 | + struct name_entry *nmatch; | |
26592 | + char *p, *lastp = NULL; | |
26593 | + struct acl_object_label *obj = NULL, *tmp; | |
26594 | + struct acl_subject_label *tmpsubj; | |
26595 | + char c = '\0'; | |
26596 | + | |
26597 | + read_lock(&gr_inode_lock); | |
26598 | + | |
26599 | + p = name + len - 1; | |
26600 | + do { | |
26601 | + nmatch = lookup_name_entry(name); | |
26602 | + if (lastp != NULL) | |
26603 | + *lastp = c; | |
26604 | + | |
26605 | + if (nmatch == NULL) | |
26606 | + goto next_component; | |
26607 | + tmpsubj = current->acl; | |
26608 | + do { | |
26609 | + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj); | |
26610 | + if (obj != NULL) { | |
26611 | + tmp = obj->globbed; | |
26612 | + while (tmp) { | |
26613 | + if (!glob_match(tmp->filename, name)) { | |
26614 | + obj = tmp; | |
26615 | + goto found_obj; | |
26616 | + } | |
26617 | + tmp = tmp->next; | |
26618 | + } | |
26619 | + goto found_obj; | |
26620 | + } | |
26621 | + } while ((tmpsubj = tmpsubj->parent_subject)); | |
26622 | +next_component: | |
26623 | + /* end case */ | |
26624 | + if (p == name) | |
26625 | + break; | |
26626 | + | |
26627 | + while (*p != '/') | |
26628 | + p--; | |
26629 | + if (p == name) | |
26630 | + lastp = p + 1; | |
26631 | + else { | |
26632 | + lastp = p; | |
26633 | + p--; | |
26634 | + } | |
26635 | + c = *lastp; | |
26636 | + *lastp = '\0'; | |
26637 | + } while (1); | |
26638 | +found_obj: | |
26639 | + read_unlock(&gr_inode_lock); | |
26640 | + /* obj returned will always be non-null */ | |
26641 | + return obj; | |
26642 | +} | |
26643 | + | |
26644 | +/* returns 0 when allowing, non-zero on error | |
26645 | + op of 0 is used for readdir, so we don't log the names of hidden files | |
26646 | +*/ | |
26647 | +__u32 | |
26648 | +gr_handle_sysctl(const struct ctl_table *table, const int op) | |
26649 | +{ | |
26650 | + ctl_table *tmp; | |
26651 | + const char *proc_sys = "/proc/sys"; | |
26652 | + char *path; | |
26653 | + struct acl_object_label *obj; | |
26654 | + unsigned short len = 0, pos = 0, depth = 0, i; | |
26655 | + __u32 err = 0; | |
26656 | + __u32 mode = 0; | |
26657 | + | |
26658 | + if (unlikely(!(gr_status & GR_READY))) | |
26659 | + return 0; | |
26660 | + | |
26661 | + /* for now, ignore operations on non-sysctl entries if it's not a | |
26662 | + readdir*/ | |
26663 | + if (table->child != NULL && op != 0) | |
26664 | + return 0; | |
26665 | + | |
26666 | + mode |= GR_FIND; | |
26667 | + /* it's only a read if it's an entry, read on dirs is for readdir */ | |
26668 | + if (op & MAY_READ) | |
26669 | + mode |= GR_READ; | |
26670 | + if (op & MAY_WRITE) | |
26671 | + mode |= GR_WRITE; | |
26672 | + | |
26673 | + preempt_disable(); | |
26674 | + | |
26675 | + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id()); | |
26676 | + | |
26677 | + /* it's only a read/write if it's an actual entry, not a dir | |
26678 | + (which are opened for readdir) | |
26679 | + */ | |
26680 | + | |
26681 | + /* convert the requested sysctl entry into a pathname */ | |
26682 | + | |
26683 | + for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) { | |
26684 | + len += strlen(tmp->procname); | |
26685 | + len++; | |
26686 | + depth++; | |
26687 | + } | |
26688 | + | |
26689 | + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) { | |
26690 | + /* deny */ | |
26691 | + goto out; | |
26692 | + } | |
26693 | + | |
26694 | + memset(path, 0, PAGE_SIZE); | |
26695 | + | |
26696 | + memcpy(path, proc_sys, strlen(proc_sys)); | |
26697 | + | |
26698 | + pos += strlen(proc_sys); | |
26699 | + | |
26700 | + for (; depth > 0; depth--) { | |
26701 | + path[pos] = '/'; | |
26702 | + pos++; | |
26703 | + for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) { | |
26704 | + if (depth == i) { | |
26705 | + memcpy(path + pos, tmp->procname, | |
26706 | + strlen(tmp->procname)); | |
26707 | + pos += strlen(tmp->procname); | |
26708 | + } | |
26709 | + i++; | |
26710 | + } | |
26711 | + } | |
26712 | + | |
26713 | + obj = gr_lookup_by_name(path, pos); | |
26714 | + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS); | |
26715 | + | |
26716 | + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) && | |
26717 | + ((err & mode) != mode))) { | |
26718 | + __u32 new_mode = mode; | |
26719 | + | |
26720 | + new_mode &= ~(GR_AUDITS | GR_SUPPRESS); | |
26721 | + | |
26722 | + err = 0; | |
26723 | + gr_log_learn_sysctl(path, new_mode); | |
26724 | + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) { | |
26725 | + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path); | |
26726 | + err = -ENOENT; | |
26727 | + } else if (!(err & GR_FIND)) { | |
26728 | + err = -ENOENT; | |
26729 | + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) { | |
26730 | + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied", | |
26731 | + path, (mode & GR_READ) ? " reading" : "", | |
26732 | + (mode & GR_WRITE) ? " writing" : ""); | |
26733 | + err = -EACCES; | |
26734 | + } else if ((err & mode) != mode) { | |
26735 | + err = -EACCES; | |
26736 | + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) { | |
26737 | + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful", | |
26738 | + path, (mode & GR_READ) ? " reading" : "", | |
26739 | + (mode & GR_WRITE) ? " writing" : ""); | |
26740 | + err = 0; | |
26741 | + } else | |
26742 | + err = 0; | |
26743 | + | |
26744 | + out: | |
26745 | + preempt_enable(); | |
26746 | + | |
26747 | + return err; | |
26748 | +} | |
26749 | +#endif | |
26750 | + | |
26751 | +int | |
26752 | +gr_handle_proc_ptrace(struct task_struct *task) | |
26753 | +{ | |
26754 | + struct file *filp; | |
26755 | + struct task_struct *tmp = task; | |
26756 | + struct task_struct *curtemp = current; | |
26757 | + __u32 retmode; | |
26758 | + | |
26759 | + if (unlikely(!(gr_status & GR_READY))) | |
26760 | + return 0; | |
26761 | + | |
26762 | + read_lock(&tasklist_lock); | |
26763 | + read_lock(&grsec_exec_file_lock); | |
26764 | + filp = task->exec_file; | |
26765 | + | |
26766 | + while (tmp->pid > 0) { | |
26767 | + if (tmp == curtemp) | |
26768 | + break; | |
26769 | + tmp = tmp->parent; | |
26770 | + } | |
26771 | + | |
26772 | + if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) { | |
26773 | + read_unlock(&grsec_exec_file_lock); | |
26774 | + read_unlock(&tasklist_lock); | |
26775 | + return 1; | |
26776 | + } | |
26777 | + | |
26778 | + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt); | |
26779 | + read_unlock(&grsec_exec_file_lock); | |
26780 | + read_unlock(&tasklist_lock); | |
26781 | + | |
26782 | + if (retmode & GR_NOPTRACE) | |
26783 | + return 1; | |
26784 | + | |
26785 | + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD) | |
26786 | + && (current->acl != task->acl || (current->acl != current->role->root_label | |
26787 | + && current->pid != task->pid))) | |
26788 | + return 1; | |
26789 | + | |
26790 | + return 0; | |
26791 | +} | |
26792 | + | |
26793 | +int | |
26794 | +gr_handle_ptrace(struct task_struct *task, const long request) | |
26795 | +{ | |
26796 | + struct task_struct *tmp = task; | |
26797 | + struct task_struct *curtemp = current; | |
26798 | + __u32 retmode; | |
26799 | + | |
26800 | + if (unlikely(!(gr_status & GR_READY))) | |
26801 | + return 0; | |
26802 | + | |
26803 | + read_lock(&tasklist_lock); | |
26804 | + while (tmp->pid > 0) { | |
26805 | + if (tmp == curtemp) | |
26806 | + break; | |
26807 | + tmp = tmp->parent; | |
26808 | + } | |
26809 | + | |
26810 | + if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) { | |
26811 | + read_unlock(&tasklist_lock); | |
26812 | + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task); | |
26813 | + return 1; | |
26814 | + } | |
26815 | + read_unlock(&tasklist_lock); | |
26816 | + | |
26817 | + read_lock(&grsec_exec_file_lock); | |
26818 | + if (unlikely(!task->exec_file)) { | |
26819 | + read_unlock(&grsec_exec_file_lock); | |
26820 | + return 0; | |
26821 | + } | |
26822 | + | |
26823 | + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt); | |
26824 | + read_unlock(&grsec_exec_file_lock); | |
26825 | + | |
26826 | + if (retmode & GR_NOPTRACE) { | |
26827 | + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task); | |
26828 | + return 1; | |
26829 | + } | |
26830 | + | |
26831 | + if (retmode & GR_PTRACERD) { | |
26832 | + switch (request) { | |
26833 | + case PTRACE_POKETEXT: | |
26834 | + case PTRACE_POKEDATA: | |
26835 | + case PTRACE_POKEUSR: | |
26836 | +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64) | |
26837 | + case PTRACE_SETREGS: | |
26838 | + case PTRACE_SETFPREGS: | |
26839 | +#endif | |
26840 | +#ifdef CONFIG_X86 | |
26841 | + case PTRACE_SETFPXREGS: | |
26842 | +#endif | |
26843 | +#ifdef CONFIG_ALTIVEC | |
26844 | + case PTRACE_SETVRREGS: | |
26845 | +#endif | |
26846 | + return 1; | |
26847 | + default: | |
26848 | + return 0; | |
26849 | + } | |
26850 | + } else if (!(current->acl->mode & GR_POVERRIDE) && | |
26851 | + !(current->role->roletype & GR_ROLE_GOD) && | |
26852 | + (current->acl != task->acl)) { | |
26853 | + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task); | |
26854 | + return 1; | |
26855 | + } | |
26856 | + | |
26857 | + return 0; | |
26858 | +} | |
26859 | + | |
26860 | +static int is_writable_mmap(const struct file *filp) | |
26861 | +{ | |
26862 | + struct task_struct *task = current; | |
26863 | + struct acl_object_label *obj, *obj2; | |
26864 | + | |
26865 | + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) && | |
26866 | + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) { | |
26867 | + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label); | |
26868 | + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, | |
26869 | + task->role->root_label); | |
26870 | + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) { | |
26871 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt); | |
26872 | + return 1; | |
26873 | + } | |
26874 | + } | |
26875 | + return 0; | |
26876 | +} | |
26877 | + | |
26878 | +int | |
26879 | +gr_acl_handle_mmap(const struct file *file, const unsigned long prot) | |
26880 | +{ | |
26881 | + __u32 mode; | |
26882 | + | |
26883 | + if (unlikely(!file || !(prot & PROT_EXEC))) | |
26884 | + return 1; | |
26885 | + | |
26886 | + if (is_writable_mmap(file)) | |
26887 | + return 0; | |
26888 | + | |
26889 | + mode = | |
26890 | + gr_search_file(file->f_path.dentry, | |
26891 | + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS, | |
26892 | + file->f_path.mnt); | |
26893 | + | |
26894 | + if (!gr_tpe_allow(file)) | |
26895 | + return 0; | |
26896 | + | |
26897 | + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) { | |
26898 | + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt); | |
26899 | + return 0; | |
26900 | + } else if (unlikely(!(mode & GR_EXEC))) { | |
26901 | + return 0; | |
26902 | + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) { | |
26903 | + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt); | |
26904 | + return 1; | |
26905 | + } | |
26906 | + | |
26907 | + return 1; | |
26908 | +} | |
26909 | + | |
26910 | +int | |
26911 | +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot) | |
26912 | +{ | |
26913 | + __u32 mode; | |
26914 | + | |
26915 | + if (unlikely(!file || !(prot & PROT_EXEC))) | |
26916 | + return 1; | |
26917 | + | |
26918 | + if (is_writable_mmap(file)) | |
26919 | + return 0; | |
26920 | + | |
26921 | + mode = | |
26922 | + gr_search_file(file->f_path.dentry, | |
26923 | + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS, | |
26924 | + file->f_path.mnt); | |
26925 | + | |
26926 | + if (!gr_tpe_allow(file)) | |
26927 | + return 0; | |
26928 | + | |
26929 | + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) { | |
26930 | + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt); | |
26931 | + return 0; | |
26932 | + } else if (unlikely(!(mode & GR_EXEC))) { | |
26933 | + return 0; | |
26934 | + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) { | |
26935 | + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt); | |
26936 | + return 1; | |
26937 | + } | |
26938 | + | |
26939 | + return 1; | |
26940 | +} | |
26941 | + | |
26942 | +void | |
26943 | +gr_acl_handle_psacct(struct task_struct *task, const long code) | |
26944 | +{ | |
26945 | + unsigned long runtime; | |
26946 | + unsigned long cputime; | |
26947 | + unsigned int wday, cday; | |
26948 | + __u8 whr, chr; | |
26949 | + __u8 wmin, cmin; | |
26950 | + __u8 wsec, csec; | |
26951 | + struct timespec timeval; | |
26952 | + | |
26953 | + if (unlikely(!(gr_status & GR_READY) || !task->acl || | |
26954 | + !(task->acl->mode & GR_PROCACCT))) | |
26955 | + return; | |
26956 | + | |
26957 | + do_posix_clock_monotonic_gettime(&timeval); | |
26958 | + runtime = timeval.tv_sec - task->start_time.tv_sec; | |
26959 | + wday = runtime / (3600 * 24); | |
26960 | + runtime -= wday * (3600 * 24); | |
26961 | + whr = runtime / 3600; | |
26962 | + runtime -= whr * 3600; | |
26963 | + wmin = runtime / 60; | |
26964 | + runtime -= wmin * 60; | |
26965 | + wsec = runtime; | |
26966 | + | |
26967 | + cputime = (task->utime + task->stime) / HZ; | |
26968 | + cday = cputime / (3600 * 24); | |
26969 | + cputime -= cday * (3600 * 24); | |
26970 | + chr = cputime / 3600; | |
26971 | + cputime -= chr * 3600; | |
26972 | + cmin = cputime / 60; | |
26973 | + cputime -= cmin * 60; | |
26974 | + csec = cputime; | |
26975 | + | |
26976 | + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code); | |
26977 | + | |
26978 | + return; | |
26979 | +} | |
26980 | + | |
26981 | +void gr_set_kernel_label(struct task_struct *task) | |
26982 | +{ | |
26983 | + if (gr_status & GR_READY) { | |
26984 | + task->role = kernel_role; | |
26985 | + task->acl = kernel_role->root_label; | |
26986 | + } | |
26987 | + return; | |
26988 | +} | |
26989 | + | |
de855c5d AM |
26990 | +#ifdef CONFIG_TASKSTATS |
26991 | +int gr_is_taskstats_denied(int pid) | |
26992 | +{ | |
26993 | + struct task_struct *task; | |
26994 | + const struct cred *cred; | |
26995 | + int ret = 0; | |
26996 | + | |
26997 | + /* restrict taskstats viewing to un-chrooted root users | |
26998 | + who have the 'view' subject flag if the RBAC system is enabled | |
26999 | + */ | |
27000 | + | |
27001 | + read_lock(&tasklist_lock); | |
27002 | + task = find_task_by_vpid(pid); | |
27003 | + if (task) { | |
27004 | + task_lock(task); | |
27005 | +#ifdef CONFIG_GRKERNSEC_CHROOT | |
27006 | + if (proc_is_chrooted(task)) | |
27007 | + ret = -EACCES; | |
27008 | +#endif | |
27009 | +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
27010 | + cred = __task_cred(task); | |
27011 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
27012 | + if (cred->uid != 0) | |
27013 | + ret = -EACCES; | |
27014 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
27015 | + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID)) | |
27016 | + ret = -EACCES; | |
27017 | +#endif | |
27018 | +#endif | |
27019 | + if (gr_status & GR_READY) { | |
27020 | + if (!(task->acl->mode & GR_VIEW)) | |
27021 | + ret = -EACCES; | |
27022 | + } | |
27023 | + | |
27024 | + task_unlock(task); | |
27025 | + } else | |
27026 | + ret = -ENOENT; | |
27027 | + | |
27028 | + read_unlock(&tasklist_lock); | |
27029 | + | |
27030 | + return ret; | |
27031 | +} | |
27032 | +#endif | |
27033 | + | |
2380c486 JR |
27034 | +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino) |
27035 | +{ | |
27036 | + struct task_struct *task = current; | |
27037 | + struct dentry *dentry = file->f_path.dentry; | |
27038 | + struct vfsmount *mnt = file->f_path.mnt; | |
27039 | + struct acl_object_label *obj, *tmp; | |
27040 | + struct acl_subject_label *subj; | |
27041 | + unsigned int bufsize; | |
27042 | + int is_not_root; | |
27043 | + char *path; | |
27044 | + | |
27045 | + if (unlikely(!(gr_status & GR_READY))) | |
27046 | + return 1; | |
27047 | + | |
27048 | + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN)) | |
27049 | + return 1; | |
27050 | + | |
27051 | + /* ignore Eric Biederman */ | |
27052 | + if (IS_PRIVATE(dentry->d_inode)) | |
27053 | + return 1; | |
27054 | + | |
27055 | + subj = task->acl; | |
27056 | + do { | |
27057 | + obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj); | |
27058 | + if (obj != NULL) | |
27059 | + return (obj->mode & GR_FIND) ? 1 : 0; | |
27060 | + } while ((subj = subj->parent_subject)); | |
27061 | + | |
de855c5d AM |
27062 | + /* this is purely an optimization since we're looking for an object |
27063 | + for the directory we're doing a readdir on | |
27064 | + if it's possible for any globbed object to match the entry we're | |
27065 | + filling into the directory, then the object we find here will be | |
27066 | + an anchor point with attached globbed objects | |
27067 | + */ | |
27068 | + obj = chk_obj_label_noglob(dentry, mnt, task->acl); | |
2380c486 JR |
27069 | + if (obj->globbed == NULL) |
27070 | + return (obj->mode & GR_FIND) ? 1 : 0; | |
27071 | + | |
27072 | + is_not_root = ((obj->filename[0] == '/') && | |
27073 | + (obj->filename[1] == '\0')) ? 0 : 1; | |
27074 | + bufsize = PAGE_SIZE - namelen - is_not_root; | |
27075 | + | |
27076 | + /* check bufsize > PAGE_SIZE || bufsize == 0 */ | |
27077 | + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1))) | |
27078 | + return 1; | |
27079 | + | |
27080 | + preempt_disable(); | |
27081 | + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()), | |
27082 | + bufsize); | |
27083 | + | |
27084 | + bufsize = strlen(path); | |
27085 | + | |
27086 | + /* if base is "/", don't append an additional slash */ | |
27087 | + if (is_not_root) | |
27088 | + *(path + bufsize) = '/'; | |
27089 | + memcpy(path + bufsize + is_not_root, name, namelen); | |
27090 | + *(path + bufsize + namelen + is_not_root) = '\0'; | |
27091 | + | |
27092 | + tmp = obj->globbed; | |
27093 | + while (tmp) { | |
27094 | + if (!glob_match(tmp->filename, path)) { | |
27095 | + preempt_enable(); | |
27096 | + return (tmp->mode & GR_FIND) ? 1 : 0; | |
27097 | + } | |
27098 | + tmp = tmp->next; | |
27099 | + } | |
27100 | + preempt_enable(); | |
27101 | + return (obj->mode & GR_FIND) ? 1 : 0; | |
27102 | +} | |
27103 | + | |
27104 | +EXPORT_SYMBOL(gr_learn_resource); | |
27105 | +EXPORT_SYMBOL(gr_set_kernel_label); | |
27106 | +#ifdef CONFIG_SECURITY | |
27107 | +EXPORT_SYMBOL(gr_check_user_change); | |
27108 | +EXPORT_SYMBOL(gr_check_group_change); | |
27109 | +#endif | |
27110 | + | |
de855c5d AM |
27111 | diff -urNp linux-2.6.29.6/grsecurity/gracl_cap.c linux-2.6.29.6/grsecurity/gracl_cap.c |
27112 | --- linux-2.6.29.6/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500 | |
27113 | +++ linux-2.6.29.6/grsecurity/gracl_cap.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
27114 | @@ -0,0 +1,131 @@ |
27115 | +#include <linux/kernel.h> | |
27116 | +#include <linux/module.h> | |
27117 | +#include <linux/sched.h> | |
27118 | +#include <linux/gracl.h> | |
27119 | +#include <linux/grsecurity.h> | |
27120 | +#include <linux/grinternal.h> | |
27121 | + | |
27122 | +static const char *captab_log[] = { | |
27123 | + "CAP_CHOWN", | |
27124 | + "CAP_DAC_OVERRIDE", | |
27125 | + "CAP_DAC_READ_SEARCH", | |
27126 | + "CAP_FOWNER", | |
27127 | + "CAP_FSETID", | |
27128 | + "CAP_KILL", | |
27129 | + "CAP_SETGID", | |
27130 | + "CAP_SETUID", | |
27131 | + "CAP_SETPCAP", | |
27132 | + "CAP_LINUX_IMMUTABLE", | |
27133 | + "CAP_NET_BIND_SERVICE", | |
27134 | + "CAP_NET_BROADCAST", | |
27135 | + "CAP_NET_ADMIN", | |
27136 | + "CAP_NET_RAW", | |
27137 | + "CAP_IPC_LOCK", | |
27138 | + "CAP_IPC_OWNER", | |
27139 | + "CAP_SYS_MODULE", | |
27140 | + "CAP_SYS_RAWIO", | |
27141 | + "CAP_SYS_CHROOT", | |
27142 | + "CAP_SYS_PTRACE", | |
27143 | + "CAP_SYS_PACCT", | |
27144 | + "CAP_SYS_ADMIN", | |
27145 | + "CAP_SYS_BOOT", | |
27146 | + "CAP_SYS_NICE", | |
27147 | + "CAP_SYS_RESOURCE", | |
27148 | + "CAP_SYS_TIME", | |
27149 | + "CAP_SYS_TTY_CONFIG", | |
27150 | + "CAP_MKNOD", | |
27151 | + "CAP_LEASE", | |
27152 | + "CAP_AUDIT_WRITE", | |
27153 | + "CAP_AUDIT_CONTROL", | |
27154 | + "CAP_SETFCAP", | |
27155 | + "CAP_MAC_OVERRIDE", | |
27156 | + "CAP_MAC_ADMIN" | |
27157 | +}; | |
27158 | + | |
27159 | +EXPORT_SYMBOL(gr_is_capable); | |
27160 | +EXPORT_SYMBOL(gr_is_capable_nolog); | |
27161 | + | |
27162 | +int | |
27163 | +gr_is_capable(const int cap) | |
27164 | +{ | |
27165 | + struct task_struct *task = current; | |
27166 | + const struct cred *cred = current_cred(); | |
27167 | + struct acl_subject_label *curracl; | |
27168 | + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set; | |
27169 | + | |
27170 | + if (!gr_acl_is_enabled()) | |
27171 | + return 1; | |
27172 | + | |
27173 | + curracl = task->acl; | |
27174 | + | |
27175 | + cap_drop = curracl->cap_lower; | |
27176 | + cap_mask = curracl->cap_mask; | |
27177 | + | |
27178 | + while ((curracl = curracl->parent_subject)) { | |
27179 | + /* if the cap isn't specified in the current computed mask but is specified in the | |
27180 | + current level subject, and is lowered in the current level subject, then add | |
27181 | + it to the set of dropped capabilities | |
27182 | + otherwise, add the current level subject's mask to the current computed mask | |
27183 | + */ | |
27184 | + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) { | |
27185 | + cap_raise(cap_mask, cap); | |
27186 | + if (cap_raised(curracl->cap_lower, cap)) | |
27187 | + cap_raise(cap_drop, cap); | |
27188 | + } | |
27189 | + } | |
27190 | + | |
27191 | + if (!cap_raised(cap_drop, cap)) | |
27192 | + return 1; | |
27193 | + | |
27194 | + curracl = task->acl; | |
27195 | + | |
27196 | + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) | |
27197 | + && cap_raised(cred->cap_effective, cap)) { | |
27198 | + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, | |
27199 | + task->role->roletype, cred->uid, | |
27200 | + cred->gid, task->exec_file ? | |
27201 | + gr_to_filename(task->exec_file->f_path.dentry, | |
27202 | + task->exec_file->f_path.mnt) : curracl->filename, | |
27203 | + curracl->filename, 0UL, | |
27204 | + 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip)); | |
27205 | + return 1; | |
27206 | + } | |
27207 | + | |
27208 | + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap)) | |
27209 | + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]); | |
27210 | + return 0; | |
27211 | +} | |
27212 | + | |
27213 | +int | |
27214 | +gr_is_capable_nolog(const int cap) | |
27215 | +{ | |
27216 | + struct acl_subject_label *curracl; | |
27217 | + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set; | |
27218 | + | |
27219 | + if (!gr_acl_is_enabled()) | |
27220 | + return 1; | |
27221 | + | |
27222 | + curracl = current->acl; | |
27223 | + | |
27224 | + cap_drop = curracl->cap_lower; | |
27225 | + cap_mask = curracl->cap_mask; | |
27226 | + | |
27227 | + while ((curracl = curracl->parent_subject)) { | |
27228 | + /* if the cap isn't specified in the current computed mask but is specified in the | |
27229 | + current level subject, and is lowered in the current level subject, then add | |
27230 | + it to the set of dropped capabilities | |
27231 | + otherwise, add the current level subject's mask to the current computed mask | |
27232 | + */ | |
27233 | + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) { | |
27234 | + cap_raise(cap_mask, cap); | |
27235 | + if (cap_raised(curracl->cap_lower, cap)) | |
27236 | + cap_raise(cap_drop, cap); | |
27237 | + } | |
27238 | + } | |
27239 | + | |
27240 | + if (!cap_raised(cap_drop, cap)) | |
27241 | + return 1; | |
27242 | + | |
27243 | + return 0; | |
27244 | +} | |
27245 | + | |
de855c5d AM |
27246 | diff -urNp linux-2.6.29.6/grsecurity/gracl_fs.c linux-2.6.29.6/grsecurity/gracl_fs.c |
27247 | --- linux-2.6.29.6/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500 | |
27248 | +++ linux-2.6.29.6/grsecurity/gracl_fs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
27249 | @@ -0,0 +1,423 @@ |
27250 | +#include <linux/kernel.h> | |
27251 | +#include <linux/sched.h> | |
27252 | +#include <linux/types.h> | |
27253 | +#include <linux/fs.h> | |
27254 | +#include <linux/file.h> | |
27255 | +#include <linux/stat.h> | |
27256 | +#include <linux/grsecurity.h> | |
27257 | +#include <linux/grinternal.h> | |
27258 | +#include <linux/gracl.h> | |
27259 | + | |
27260 | +__u32 | |
27261 | +gr_acl_handle_hidden_file(const struct dentry * dentry, | |
27262 | + const struct vfsmount * mnt) | |
27263 | +{ | |
27264 | + __u32 mode; | |
27265 | + | |
27266 | + if (unlikely(!dentry->d_inode)) | |
27267 | + return GR_FIND; | |
27268 | + | |
27269 | + mode = | |
27270 | + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt); | |
27271 | + | |
27272 | + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) { | |
27273 | + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt); | |
27274 | + return mode; | |
27275 | + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) { | |
27276 | + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt); | |
27277 | + return 0; | |
27278 | + } else if (unlikely(!(mode & GR_FIND))) | |
27279 | + return 0; | |
27280 | + | |
27281 | + return GR_FIND; | |
27282 | +} | |
27283 | + | |
27284 | +__u32 | |
27285 | +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt, | |
27286 | + const int fmode) | |
27287 | +{ | |
27288 | + __u32 reqmode = GR_FIND; | |
27289 | + __u32 mode; | |
27290 | + | |
27291 | + if (unlikely(!dentry->d_inode)) | |
27292 | + return reqmode; | |
27293 | + | |
27294 | + if (unlikely(fmode & O_APPEND)) | |
27295 | + reqmode |= GR_APPEND; | |
27296 | + else if (unlikely(fmode & FMODE_WRITE)) | |
27297 | + reqmode |= GR_WRITE; | |
27298 | + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY))) | |
27299 | + reqmode |= GR_READ; | |
27300 | + | |
27301 | + mode = | |
27302 | + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, | |
27303 | + mnt); | |
27304 | + | |
27305 | + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) { | |
27306 | + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt, | |
27307 | + reqmode & GR_READ ? " reading" : "", | |
27308 | + reqmode & GR_WRITE ? " writing" : reqmode & | |
27309 | + GR_APPEND ? " appending" : ""); | |
27310 | + return reqmode; | |
27311 | + } else | |
27312 | + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS))) | |
27313 | + { | |
27314 | + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt, | |
27315 | + reqmode & GR_READ ? " reading" : "", | |
27316 | + reqmode & GR_WRITE ? " writing" : reqmode & | |
27317 | + GR_APPEND ? " appending" : ""); | |
27318 | + return 0; | |
27319 | + } else if (unlikely((mode & reqmode) != reqmode)) | |
27320 | + return 0; | |
27321 | + | |
27322 | + return reqmode; | |
27323 | +} | |
27324 | + | |
27325 | +__u32 | |
27326 | +gr_acl_handle_creat(const struct dentry * dentry, | |
27327 | + const struct dentry * p_dentry, | |
27328 | + const struct vfsmount * p_mnt, const int fmode, | |
27329 | + const int imode) | |
27330 | +{ | |
27331 | + __u32 reqmode = GR_WRITE | GR_CREATE; | |
27332 | + __u32 mode; | |
27333 | + | |
27334 | + if (unlikely(fmode & O_APPEND)) | |
27335 | + reqmode |= GR_APPEND; | |
27336 | + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY))) | |
27337 | + reqmode |= GR_READ; | |
27338 | + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID)))) | |
27339 | + reqmode |= GR_SETID; | |
27340 | + | |
27341 | + mode = | |
27342 | + gr_check_create(dentry, p_dentry, p_mnt, | |
27343 | + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS); | |
27344 | + | |
27345 | + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) { | |
27346 | + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt, | |
27347 | + reqmode & GR_READ ? " reading" : "", | |
27348 | + reqmode & GR_WRITE ? " writing" : reqmode & | |
27349 | + GR_APPEND ? " appending" : ""); | |
27350 | + return reqmode; | |
27351 | + } else | |
27352 | + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS))) | |
27353 | + { | |
27354 | + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt, | |
27355 | + reqmode & GR_READ ? " reading" : "", | |
27356 | + reqmode & GR_WRITE ? " writing" : reqmode & | |
27357 | + GR_APPEND ? " appending" : ""); | |
27358 | + return 0; | |
27359 | + } else if (unlikely((mode & reqmode) != reqmode)) | |
27360 | + return 0; | |
27361 | + | |
27362 | + return reqmode; | |
27363 | +} | |
27364 | + | |
27365 | +__u32 | |
27366 | +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt, | |
27367 | + const int fmode) | |
27368 | +{ | |
27369 | + __u32 mode, reqmode = GR_FIND; | |
27370 | + | |
27371 | + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode)) | |
27372 | + reqmode |= GR_EXEC; | |
27373 | + if (fmode & S_IWOTH) | |
27374 | + reqmode |= GR_WRITE; | |
27375 | + if (fmode & S_IROTH) | |
27376 | + reqmode |= GR_READ; | |
27377 | + | |
27378 | + mode = | |
27379 | + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, | |
27380 | + mnt); | |
27381 | + | |
27382 | + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) { | |
27383 | + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt, | |
27384 | + reqmode & GR_READ ? " reading" : "", | |
27385 | + reqmode & GR_WRITE ? " writing" : "", | |
27386 | + reqmode & GR_EXEC ? " executing" : ""); | |
27387 | + return reqmode; | |
27388 | + } else | |
27389 | + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS))) | |
27390 | + { | |
27391 | + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt, | |
27392 | + reqmode & GR_READ ? " reading" : "", | |
27393 | + reqmode & GR_WRITE ? " writing" : "", | |
27394 | + reqmode & GR_EXEC ? " executing" : ""); | |
27395 | + return 0; | |
27396 | + } else if (unlikely((mode & reqmode) != reqmode)) | |
27397 | + return 0; | |
27398 | + | |
27399 | + return reqmode; | |
27400 | +} | |
27401 | + | |
27402 | +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt) | |
27403 | +{ | |
27404 | + __u32 mode; | |
27405 | + | |
27406 | + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt); | |
27407 | + | |
27408 | + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) { | |
27409 | + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt); | |
27410 | + return mode; | |
27411 | + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) { | |
27412 | + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt); | |
27413 | + return 0; | |
27414 | + } else if (unlikely((mode & (reqmode)) != (reqmode))) | |
27415 | + return 0; | |
27416 | + | |
27417 | + return (reqmode); | |
27418 | +} | |
27419 | + | |
27420 | +__u32 | |
27421 | +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt) | |
27422 | +{ | |
27423 | + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG); | |
27424 | +} | |
27425 | + | |
27426 | +__u32 | |
27427 | +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt) | |
27428 | +{ | |
27429 | + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG); | |
27430 | +} | |
27431 | + | |
27432 | +__u32 | |
27433 | +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt) | |
27434 | +{ | |
27435 | + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG); | |
27436 | +} | |
27437 | + | |
27438 | +__u32 | |
27439 | +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt) | |
27440 | +{ | |
27441 | + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG); | |
27442 | +} | |
27443 | + | |
27444 | +__u32 | |
27445 | +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt, | |
27446 | + mode_t mode) | |
27447 | +{ | |
27448 | + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode))) | |
27449 | + return 1; | |
27450 | + | |
27451 | + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) { | |
27452 | + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID, | |
27453 | + GR_FCHMOD_ACL_MSG); | |
27454 | + } else { | |
27455 | + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG); | |
27456 | + } | |
27457 | +} | |
27458 | + | |
27459 | +__u32 | |
27460 | +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt, | |
27461 | + mode_t mode) | |
27462 | +{ | |
27463 | + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) { | |
27464 | + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID, | |
27465 | + GR_CHMOD_ACL_MSG); | |
27466 | + } else { | |
27467 | + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG); | |
27468 | + } | |
27469 | +} | |
27470 | + | |
27471 | +__u32 | |
27472 | +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt) | |
27473 | +{ | |
27474 | + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG); | |
27475 | +} | |
27476 | + | |
27477 | +__u32 | |
27478 | +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt) | |
27479 | +{ | |
27480 | + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG); | |
27481 | +} | |
27482 | + | |
27483 | +__u32 | |
27484 | +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt) | |
27485 | +{ | |
27486 | + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE, | |
27487 | + GR_UNIXCONNECT_ACL_MSG); | |
27488 | +} | |
27489 | + | |
27490 | +/* hardlinks require at minimum create permission, | |
27491 | + any additional privilege required is based on the | |
27492 | + privilege of the file being linked to | |
27493 | +*/ | |
27494 | +__u32 | |
27495 | +gr_acl_handle_link(const struct dentry * new_dentry, | |
27496 | + const struct dentry * parent_dentry, | |
27497 | + const struct vfsmount * parent_mnt, | |
27498 | + const struct dentry * old_dentry, | |
27499 | + const struct vfsmount * old_mnt, const char *to) | |
27500 | +{ | |
27501 | + __u32 mode; | |
27502 | + __u32 needmode = GR_CREATE | GR_LINK; | |
27503 | + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK; | |
27504 | + | |
27505 | + mode = | |
27506 | + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry, | |
27507 | + old_mnt); | |
27508 | + | |
27509 | + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) { | |
27510 | + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to); | |
27511 | + return mode; | |
27512 | + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) { | |
27513 | + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to); | |
27514 | + return 0; | |
27515 | + } else if (unlikely((mode & needmode) != needmode)) | |
27516 | + return 0; | |
27517 | + | |
27518 | + return 1; | |
27519 | +} | |
27520 | + | |
27521 | +__u32 | |
27522 | +gr_acl_handle_symlink(const struct dentry * new_dentry, | |
27523 | + const struct dentry * parent_dentry, | |
27524 | + const struct vfsmount * parent_mnt, const char *from) | |
27525 | +{ | |
27526 | + __u32 needmode = GR_WRITE | GR_CREATE; | |
27527 | + __u32 mode; | |
27528 | + | |
27529 | + mode = | |
27530 | + gr_check_create(new_dentry, parent_dentry, parent_mnt, | |
27531 | + GR_CREATE | GR_AUDIT_CREATE | | |
27532 | + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS); | |
27533 | + | |
27534 | + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) { | |
27535 | + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt); | |
27536 | + return mode; | |
27537 | + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) { | |
27538 | + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt); | |
27539 | + return 0; | |
27540 | + } else if (unlikely((mode & needmode) != needmode)) | |
27541 | + return 0; | |
27542 | + | |
27543 | + return (GR_WRITE | GR_CREATE); | |
27544 | +} | |
27545 | + | |
27546 | +static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt) | |
27547 | +{ | |
27548 | + __u32 mode; | |
27549 | + | |
27550 | + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS); | |
27551 | + | |
27552 | + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) { | |
27553 | + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt); | |
27554 | + return mode; | |
27555 | + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) { | |
27556 | + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt); | |
27557 | + return 0; | |
27558 | + } else if (unlikely((mode & (reqmode)) != (reqmode))) | |
27559 | + return 0; | |
27560 | + | |
27561 | + return (reqmode); | |
27562 | +} | |
27563 | + | |
27564 | +__u32 | |
27565 | +gr_acl_handle_mknod(const struct dentry * new_dentry, | |
27566 | + const struct dentry * parent_dentry, | |
27567 | + const struct vfsmount * parent_mnt, | |
27568 | + const int mode) | |
27569 | +{ | |
27570 | + __u32 reqmode = GR_WRITE | GR_CREATE; | |
27571 | + if (unlikely(mode & (S_ISUID | S_ISGID))) | |
27572 | + reqmode |= GR_SETID; | |
27573 | + | |
27574 | + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt, | |
27575 | + reqmode, GR_MKNOD_ACL_MSG); | |
27576 | +} | |
27577 | + | |
27578 | +__u32 | |
27579 | +gr_acl_handle_mkdir(const struct dentry *new_dentry, | |
27580 | + const struct dentry *parent_dentry, | |
27581 | + const struct vfsmount *parent_mnt) | |
27582 | +{ | |
27583 | + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt, | |
27584 | + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG); | |
27585 | +} | |
27586 | + | |
27587 | +#define RENAME_CHECK_SUCCESS(old, new) \ | |
27588 | + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \ | |
27589 | + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ))) | |
27590 | + | |
27591 | +int | |
27592 | +gr_acl_handle_rename(struct dentry *new_dentry, | |
27593 | + struct dentry *parent_dentry, | |
27594 | + const struct vfsmount *parent_mnt, | |
27595 | + struct dentry *old_dentry, | |
27596 | + struct inode *old_parent_inode, | |
27597 | + struct vfsmount *old_mnt, const char *newname) | |
27598 | +{ | |
27599 | + __u32 comp1, comp2; | |
27600 | + int error = 0; | |
27601 | + | |
27602 | + if (unlikely(!gr_acl_is_enabled())) | |
27603 | + return 0; | |
27604 | + | |
27605 | + if (!new_dentry->d_inode) { | |
27606 | + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt, | |
27607 | + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ | | |
27608 | + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS); | |
27609 | + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE | | |
27610 | + GR_DELETE | GR_AUDIT_DELETE | | |
27611 | + GR_AUDIT_READ | GR_AUDIT_WRITE | | |
27612 | + GR_SUPPRESS, old_mnt); | |
27613 | + } else { | |
27614 | + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE | | |
27615 | + GR_CREATE | GR_DELETE | | |
27616 | + GR_AUDIT_CREATE | GR_AUDIT_DELETE | | |
27617 | + GR_AUDIT_READ | GR_AUDIT_WRITE | | |
27618 | + GR_SUPPRESS, parent_mnt); | |
27619 | + comp2 = | |
27620 | + gr_search_file(old_dentry, | |
27621 | + GR_READ | GR_WRITE | GR_AUDIT_READ | | |
27622 | + GR_DELETE | GR_AUDIT_DELETE | | |
27623 | + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt); | |
27624 | + } | |
27625 | + | |
27626 | + if (RENAME_CHECK_SUCCESS(comp1, comp2) && | |
27627 | + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS))) | |
27628 | + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname); | |
27629 | + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS) | |
27630 | + && !(comp2 & GR_SUPPRESS)) { | |
27631 | + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname); | |
27632 | + error = -EACCES; | |
27633 | + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2))) | |
27634 | + error = -EACCES; | |
27635 | + | |
27636 | + return error; | |
27637 | +} | |
27638 | + | |
27639 | +void | |
27640 | +gr_acl_handle_exit(void) | |
27641 | +{ | |
27642 | + u16 id; | |
27643 | + char *rolename; | |
27644 | + struct file *exec_file; | |
27645 | + | |
27646 | + if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) { | |
27647 | + id = current->acl_role_id; | |
27648 | + rolename = current->role->rolename; | |
27649 | + gr_set_acls(1); | |
27650 | + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id); | |
27651 | + } | |
27652 | + | |
27653 | + write_lock(&grsec_exec_file_lock); | |
27654 | + exec_file = current->exec_file; | |
27655 | + current->exec_file = NULL; | |
27656 | + write_unlock(&grsec_exec_file_lock); | |
27657 | + | |
27658 | + if (exec_file) | |
27659 | + fput(exec_file); | |
27660 | +} | |
27661 | + | |
27662 | +int | |
27663 | +gr_acl_handle_procpidmem(const struct task_struct *task) | |
27664 | +{ | |
27665 | + if (unlikely(!gr_acl_is_enabled())) | |
27666 | + return 0; | |
27667 | + | |
27668 | + if (task != current && task->acl->mode & GR_PROTPROCFD) | |
27669 | + return -EACCES; | |
27670 | + | |
27671 | + return 0; | |
27672 | +} | |
de855c5d AM |
27673 | diff -urNp linux-2.6.29.6/grsecurity/gracl_ip.c linux-2.6.29.6/grsecurity/gracl_ip.c |
27674 | --- linux-2.6.29.6/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500 | |
27675 | +++ linux-2.6.29.6/grsecurity/gracl_ip.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
27676 | @@ -0,0 +1,340 @@ |
27677 | +#include <linux/kernel.h> | |
27678 | +#include <asm/uaccess.h> | |
27679 | +#include <asm/errno.h> | |
27680 | +#include <net/sock.h> | |
27681 | +#include <linux/file.h> | |
27682 | +#include <linux/fs.h> | |
27683 | +#include <linux/net.h> | |
27684 | +#include <linux/in.h> | |
27685 | +#include <linux/skbuff.h> | |
27686 | +#include <linux/ip.h> | |
27687 | +#include <linux/udp.h> | |
27688 | +#include <linux/smp_lock.h> | |
27689 | +#include <linux/types.h> | |
27690 | +#include <linux/sched.h> | |
27691 | +#include <linux/netdevice.h> | |
27692 | +#include <linux/inetdevice.h> | |
27693 | +#include <linux/gracl.h> | |
27694 | +#include <linux/grsecurity.h> | |
27695 | +#include <linux/grinternal.h> | |
27696 | + | |
27697 | +#define GR_BIND 0x01 | |
27698 | +#define GR_CONNECT 0x02 | |
27699 | +#define GR_INVERT 0x04 | |
27700 | +#define GR_BINDOVERRIDE 0x08 | |
27701 | +#define GR_CONNECTOVERRIDE 0x10 | |
27702 | + | |
27703 | +static const char * gr_protocols[256] = { | |
27704 | + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt", | |
27705 | + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet", | |
27706 | + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1", | |
27707 | + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp", | |
27708 | + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++", | |
27709 | + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre", | |
27710 | + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile", | |
27711 | + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63", | |
27712 | + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv", | |
27713 | + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak", | |
27714 | + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf", | |
27715 | + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp", | |
27716 | + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim", | |
27717 | + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip", | |
27718 | + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp", | |
27719 | + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup", | |
27720 | + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135", | |
27721 | + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143", | |
27722 | + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151", | |
27723 | + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159", | |
27724 | + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167", | |
27725 | + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175", | |
27726 | + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183", | |
27727 | + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191", | |
27728 | + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199", | |
27729 | + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207", | |
27730 | + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215", | |
27731 | + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223", | |
27732 | + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231", | |
27733 | + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239", | |
27734 | + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247", | |
27735 | + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255", | |
27736 | + }; | |
27737 | + | |
27738 | +static const char * gr_socktypes[11] = { | |
27739 | + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6", | |
27740 | + "unknown:7", "unknown:8", "unknown:9", "packet" | |
27741 | + }; | |
27742 | + | |
27743 | +const char * | |
27744 | +gr_proto_to_name(unsigned char proto) | |
27745 | +{ | |
27746 | + return gr_protocols[proto]; | |
27747 | +} | |
27748 | + | |
27749 | +const char * | |
27750 | +gr_socktype_to_name(unsigned char type) | |
27751 | +{ | |
27752 | + return gr_socktypes[type]; | |
27753 | +} | |
27754 | + | |
27755 | +int | |
27756 | +gr_search_socket(const int domain, const int type, const int protocol) | |
27757 | +{ | |
27758 | + struct acl_subject_label *curr; | |
27759 | + const struct cred *cred = current_cred(); | |
27760 | + | |
27761 | + if (unlikely(!gr_acl_is_enabled())) | |
27762 | + goto exit; | |
27763 | + | |
27764 | + if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET) | |
27765 | + || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255)) | |
27766 | + goto exit; // let the kernel handle it | |
27767 | + | |
27768 | + curr = current->acl; | |
27769 | + | |
27770 | + if (!curr->ips) | |
27771 | + goto exit; | |
27772 | + | |
27773 | + if ((curr->ip_type & (1 << type)) && | |
27774 | + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32)))) | |
27775 | + goto exit; | |
27776 | + | |
27777 | + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) { | |
27778 | + /* we don't place acls on raw sockets , and sometimes | |
27779 | + dgram/ip sockets are opened for ioctl and not | |
27780 | + bind/connect, so we'll fake a bind learn log */ | |
27781 | + if (type == SOCK_RAW || type == SOCK_PACKET) { | |
27782 | + __u32 fakeip = 0; | |
27783 | + security_learn(GR_IP_LEARN_MSG, current->role->rolename, | |
27784 | + current->role->roletype, cred->uid, | |
27785 | + cred->gid, current->exec_file ? | |
27786 | + gr_to_filename(current->exec_file->f_path.dentry, | |
27787 | + current->exec_file->f_path.mnt) : | |
27788 | + curr->filename, curr->filename, | |
27789 | + NIPQUAD(fakeip), 0, type, | |
27790 | + protocol, GR_CONNECT, | |
27791 | +NIPQUAD(current->signal->curr_ip)); | |
27792 | + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) { | |
27793 | + __u32 fakeip = 0; | |
27794 | + security_learn(GR_IP_LEARN_MSG, current->role->rolename, | |
27795 | + current->role->roletype, cred->uid, | |
27796 | + cred->gid, current->exec_file ? | |
27797 | + gr_to_filename(current->exec_file->f_path.dentry, | |
27798 | + current->exec_file->f_path.mnt) : | |
27799 | + curr->filename, curr->filename, | |
27800 | + NIPQUAD(fakeip), 0, type, | |
27801 | + protocol, GR_BIND, NIPQUAD(current->signal->curr_ip)); | |
27802 | + } | |
27803 | + /* we'll log when they use connect or bind */ | |
27804 | + goto exit; | |
27805 | + } | |
27806 | + | |
27807 | + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet", | |
27808 | + gr_socktype_to_name(type), gr_proto_to_name(protocol)); | |
27809 | + | |
27810 | + return 0; | |
27811 | + exit: | |
27812 | + return 1; | |
27813 | +} | |
27814 | + | |
27815 | +int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask) | |
27816 | +{ | |
27817 | + if ((ip->mode & mode) && | |
27818 | + (ip_port >= ip->low) && | |
27819 | + (ip_port <= ip->high) && | |
27820 | + ((ntohl(ip_addr) & our_netmask) == | |
27821 | + (ntohl(our_addr) & our_netmask)) | |
27822 | + && (ip->proto[protocol / 32] & (1 << (protocol % 32))) | |
27823 | + && (ip->type & (1 << type))) { | |
27824 | + if (ip->mode & GR_INVERT) | |
27825 | + return 2; // specifically denied | |
27826 | + else | |
27827 | + return 1; // allowed | |
27828 | + } | |
27829 | + | |
27830 | + return 0; // not specifically allowed, may continue parsing | |
27831 | +} | |
27832 | + | |
27833 | +static int | |
27834 | +gr_search_connectbind(const int full_mode, struct sock *sk, | |
27835 | + struct sockaddr_in *addr, const int type) | |
27836 | +{ | |
27837 | + char iface[IFNAMSIZ] = {0}; | |
27838 | + struct acl_subject_label *curr; | |
27839 | + struct acl_ip_label *ip; | |
27840 | + struct inet_sock *isk; | |
27841 | + struct net_device *dev; | |
27842 | + struct in_device *idev; | |
27843 | + unsigned long i; | |
27844 | + int ret; | |
27845 | + int mode = full_mode & (GR_BIND | GR_CONNECT); | |
27846 | + __u32 ip_addr = 0; | |
27847 | + __u32 our_addr; | |
27848 | + __u32 our_netmask; | |
27849 | + char *p; | |
27850 | + __u16 ip_port = 0; | |
27851 | + const struct cred *cred = current_cred(); | |
27852 | + | |
27853 | + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET)) | |
27854 | + return 0; | |
27855 | + | |
27856 | + curr = current->acl; | |
27857 | + isk = inet_sk(sk); | |
27858 | + | |
27859 | + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */ | |
27860 | + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) | |
27861 | + addr->sin_addr.s_addr = curr->inaddr_any_override; | |
27862 | + if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) { | |
27863 | + struct sockaddr_in saddr; | |
27864 | + int err; | |
27865 | + | |
27866 | + saddr.sin_family = AF_INET; | |
27867 | + saddr.sin_addr.s_addr = curr->inaddr_any_override; | |
27868 | + saddr.sin_port = isk->sport; | |
27869 | + | |
27870 | + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)); | |
27871 | + if (err) | |
27872 | + return err; | |
27873 | + | |
27874 | + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)); | |
27875 | + if (err) | |
27876 | + return err; | |
27877 | + } | |
27878 | + | |
27879 | + if (!curr->ips) | |
27880 | + return 0; | |
27881 | + | |
27882 | + ip_addr = addr->sin_addr.s_addr; | |
27883 | + ip_port = ntohs(addr->sin_port); | |
27884 | + | |
27885 | + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) { | |
27886 | + security_learn(GR_IP_LEARN_MSG, current->role->rolename, | |
27887 | + current->role->roletype, cred->uid, | |
27888 | + cred->gid, current->exec_file ? | |
27889 | + gr_to_filename(current->exec_file->f_path.dentry, | |
27890 | + current->exec_file->f_path.mnt) : | |
27891 | + curr->filename, curr->filename, | |
27892 | + NIPQUAD(ip_addr), ip_port, type, | |
27893 | + sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip)); | |
27894 | + return 0; | |
27895 | + } | |
27896 | + | |
27897 | + for (i = 0; i < curr->ip_num; i++) { | |
27898 | + ip = *(curr->ips + i); | |
27899 | + if (ip->iface != NULL) { | |
27900 | + strncpy(iface, ip->iface, IFNAMSIZ - 1); | |
27901 | + p = strchr(iface, ':'); | |
27902 | + if (p != NULL) | |
27903 | + *p = '\0'; | |
27904 | + dev = dev_get_by_name(sock_net(sk), iface); | |
27905 | + if (dev == NULL) | |
27906 | + continue; | |
27907 | + idev = in_dev_get(dev); | |
27908 | + if (idev == NULL) { | |
27909 | + dev_put(dev); | |
27910 | + continue; | |
27911 | + } | |
27912 | + rcu_read_lock(); | |
27913 | + for_ifa(idev) { | |
27914 | + if (!strcmp(ip->iface, ifa->ifa_label)) { | |
27915 | + our_addr = ifa->ifa_address; | |
27916 | + our_netmask = 0xffffffff; | |
27917 | + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask); | |
27918 | + if (ret == 1) { | |
27919 | + rcu_read_unlock(); | |
27920 | + in_dev_put(idev); | |
27921 | + dev_put(dev); | |
27922 | + return 0; | |
27923 | + } else if (ret == 2) { | |
27924 | + rcu_read_unlock(); | |
27925 | + in_dev_put(idev); | |
27926 | + dev_put(dev); | |
27927 | + goto denied; | |
27928 | + } | |
27929 | + } | |
27930 | + } endfor_ifa(idev); | |
27931 | + rcu_read_unlock(); | |
27932 | + in_dev_put(idev); | |
27933 | + dev_put(dev); | |
27934 | + } else { | |
27935 | + our_addr = ip->addr; | |
27936 | + our_netmask = ip->netmask; | |
27937 | + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask); | |
27938 | + if (ret == 1) | |
27939 | + return 0; | |
27940 | + else if (ret == 2) | |
27941 | + goto denied; | |
27942 | + } | |
27943 | + } | |
27944 | + | |
27945 | +denied: | |
27946 | + if (mode == GR_BIND) | |
27947 | + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol)); | |
27948 | + else if (mode == GR_CONNECT) | |
27949 | + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol)); | |
27950 | + | |
27951 | + return -EACCES; | |
27952 | +} | |
27953 | + | |
27954 | +int | |
27955 | +gr_search_connect(struct socket *sock, struct sockaddr_in *addr) | |
27956 | +{ | |
27957 | + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type); | |
27958 | +} | |
27959 | + | |
27960 | +int | |
27961 | +gr_search_bind(struct socket *sock, struct sockaddr_in *addr) | |
27962 | +{ | |
27963 | + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type); | |
27964 | +} | |
27965 | + | |
27966 | +int gr_search_listen(struct socket *sock) | |
27967 | +{ | |
27968 | + struct sock *sk = sock->sk; | |
27969 | + struct sockaddr_in addr; | |
27970 | + | |
27971 | + addr.sin_addr.s_addr = inet_sk(sk)->saddr; | |
27972 | + addr.sin_port = inet_sk(sk)->sport; | |
27973 | + | |
27974 | + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type); | |
27975 | +} | |
27976 | + | |
27977 | +int gr_search_accept(struct socket *sock) | |
27978 | +{ | |
27979 | + struct sock *sk = sock->sk; | |
27980 | + struct sockaddr_in addr; | |
27981 | + | |
27982 | + addr.sin_addr.s_addr = inet_sk(sk)->saddr; | |
27983 | + addr.sin_port = inet_sk(sk)->sport; | |
27984 | + | |
27985 | + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type); | |
27986 | +} | |
27987 | + | |
27988 | +int | |
27989 | +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr) | |
27990 | +{ | |
27991 | + if (addr) | |
27992 | + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM); | |
27993 | + else { | |
27994 | + struct sockaddr_in sin; | |
27995 | + const struct inet_sock *inet = inet_sk(sk); | |
27996 | + | |
27997 | + sin.sin_addr.s_addr = inet->daddr; | |
27998 | + sin.sin_port = inet->dport; | |
27999 | + | |
28000 | + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM); | |
28001 | + } | |
28002 | +} | |
28003 | + | |
28004 | +int | |
28005 | +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb) | |
28006 | +{ | |
28007 | + struct sockaddr_in sin; | |
28008 | + | |
28009 | + if (unlikely(skb->len < sizeof (struct udphdr))) | |
28010 | + return 0; // skip this packet | |
28011 | + | |
28012 | + sin.sin_addr.s_addr = ip_hdr(skb)->saddr; | |
28013 | + sin.sin_port = udp_hdr(skb)->source; | |
28014 | + | |
28015 | + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM); | |
28016 | +} | |
de855c5d AM |
28017 | diff -urNp linux-2.6.29.6/grsecurity/gracl_learn.c linux-2.6.29.6/grsecurity/gracl_learn.c |
28018 | --- linux-2.6.29.6/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500 | |
28019 | +++ linux-2.6.29.6/grsecurity/gracl_learn.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
28020 | @@ -0,0 +1,211 @@ |
28021 | +#include <linux/kernel.h> | |
28022 | +#include <linux/mm.h> | |
28023 | +#include <linux/sched.h> | |
28024 | +#include <linux/poll.h> | |
28025 | +#include <linux/smp_lock.h> | |
28026 | +#include <linux/string.h> | |
28027 | +#include <linux/file.h> | |
28028 | +#include <linux/types.h> | |
28029 | +#include <linux/vmalloc.h> | |
28030 | +#include <linux/grinternal.h> | |
28031 | + | |
28032 | +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf, | |
28033 | + size_t count, loff_t *ppos); | |
28034 | +extern int gr_acl_is_enabled(void); | |
28035 | + | |
28036 | +static DECLARE_WAIT_QUEUE_HEAD(learn_wait); | |
28037 | +static int gr_learn_attached; | |
28038 | + | |
28039 | +/* use a 512k buffer */ | |
28040 | +#define LEARN_BUFFER_SIZE (512 * 1024) | |
28041 | + | |
28042 | +static DEFINE_SPINLOCK(gr_learn_lock); | |
28043 | +static DECLARE_MUTEX(gr_learn_user_sem); | |
28044 | + | |
28045 | +/* we need to maintain two buffers, so that the kernel context of grlearn | |
28046 | + uses a semaphore around the userspace copying, and the other kernel contexts | |
28047 | + use a spinlock when copying into the buffer, since they cannot sleep | |
28048 | +*/ | |
28049 | +static char *learn_buffer; | |
28050 | +static char *learn_buffer_user; | |
28051 | +static int learn_buffer_len; | |
28052 | +static int learn_buffer_user_len; | |
28053 | + | |
28054 | +static ssize_t | |
28055 | +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos) | |
28056 | +{ | |
28057 | + DECLARE_WAITQUEUE(wait, current); | |
28058 | + ssize_t retval = 0; | |
28059 | + | |
28060 | + add_wait_queue(&learn_wait, &wait); | |
28061 | + set_current_state(TASK_INTERRUPTIBLE); | |
28062 | + do { | |
28063 | + down(&gr_learn_user_sem); | |
28064 | + spin_lock(&gr_learn_lock); | |
28065 | + if (learn_buffer_len) | |
28066 | + break; | |
28067 | + spin_unlock(&gr_learn_lock); | |
28068 | + up(&gr_learn_user_sem); | |
28069 | + if (file->f_flags & O_NONBLOCK) { | |
28070 | + retval = -EAGAIN; | |
28071 | + goto out; | |
28072 | + } | |
28073 | + if (signal_pending(current)) { | |
28074 | + retval = -ERESTARTSYS; | |
28075 | + goto out; | |
28076 | + } | |
28077 | + | |
28078 | + schedule(); | |
28079 | + } while (1); | |
28080 | + | |
28081 | + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len); | |
28082 | + learn_buffer_user_len = learn_buffer_len; | |
28083 | + retval = learn_buffer_len; | |
28084 | + learn_buffer_len = 0; | |
28085 | + | |
28086 | + spin_unlock(&gr_learn_lock); | |
28087 | + | |
28088 | + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len)) | |
28089 | + retval = -EFAULT; | |
28090 | + | |
28091 | + up(&gr_learn_user_sem); | |
28092 | +out: | |
28093 | + set_current_state(TASK_RUNNING); | |
28094 | + remove_wait_queue(&learn_wait, &wait); | |
28095 | + return retval; | |
28096 | +} | |
28097 | + | |
28098 | +static unsigned int | |
28099 | +poll_learn(struct file * file, poll_table * wait) | |
28100 | +{ | |
28101 | + poll_wait(file, &learn_wait, wait); | |
28102 | + | |
28103 | + if (learn_buffer_len) | |
28104 | + return (POLLIN | POLLRDNORM); | |
28105 | + | |
28106 | + return 0; | |
28107 | +} | |
28108 | + | |
28109 | +void | |
28110 | +gr_clear_learn_entries(void) | |
28111 | +{ | |
28112 | + char *tmp; | |
28113 | + | |
28114 | + down(&gr_learn_user_sem); | |
28115 | + if (learn_buffer != NULL) { | |
28116 | + spin_lock(&gr_learn_lock); | |
28117 | + tmp = learn_buffer; | |
28118 | + learn_buffer = NULL; | |
28119 | + spin_unlock(&gr_learn_lock); | |
28120 | + vfree(learn_buffer); | |
28121 | + } | |
28122 | + if (learn_buffer_user != NULL) { | |
28123 | + vfree(learn_buffer_user); | |
28124 | + learn_buffer_user = NULL; | |
28125 | + } | |
28126 | + learn_buffer_len = 0; | |
28127 | + up(&gr_learn_user_sem); | |
28128 | + | |
28129 | + return; | |
28130 | +} | |
28131 | + | |
28132 | +void | |
28133 | +gr_add_learn_entry(const char *fmt, ...) | |
28134 | +{ | |
28135 | + va_list args; | |
28136 | + unsigned int len; | |
28137 | + | |
28138 | + if (!gr_learn_attached) | |
28139 | + return; | |
28140 | + | |
28141 | + spin_lock(&gr_learn_lock); | |
28142 | + | |
28143 | + /* leave a gap at the end so we know when it's "full" but don't have to | |
28144 | + compute the exact length of the string we're trying to append | |
28145 | + */ | |
28146 | + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) { | |
28147 | + spin_unlock(&gr_learn_lock); | |
28148 | + wake_up_interruptible(&learn_wait); | |
28149 | + return; | |
28150 | + } | |
28151 | + if (learn_buffer == NULL) { | |
28152 | + spin_unlock(&gr_learn_lock); | |
28153 | + return; | |
28154 | + } | |
28155 | + | |
28156 | + va_start(args, fmt); | |
28157 | + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args); | |
28158 | + va_end(args); | |
28159 | + | |
28160 | + learn_buffer_len += len + 1; | |
28161 | + | |
28162 | + spin_unlock(&gr_learn_lock); | |
28163 | + wake_up_interruptible(&learn_wait); | |
28164 | + | |
28165 | + return; | |
28166 | +} | |
28167 | + | |
28168 | +static int | |
28169 | +open_learn(struct inode *inode, struct file *file) | |
28170 | +{ | |
28171 | + if (file->f_mode & FMODE_READ && gr_learn_attached) | |
28172 | + return -EBUSY; | |
28173 | + if (file->f_mode & FMODE_READ) { | |
28174 | + int retval = 0; | |
28175 | + down(&gr_learn_user_sem); | |
28176 | + if (learn_buffer == NULL) | |
28177 | + learn_buffer = vmalloc(LEARN_BUFFER_SIZE); | |
28178 | + if (learn_buffer_user == NULL) | |
28179 | + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE); | |
28180 | + if (learn_buffer == NULL) { | |
28181 | + retval = -ENOMEM; | |
28182 | + goto out_error; | |
28183 | + } | |
28184 | + if (learn_buffer_user == NULL) { | |
28185 | + retval = -ENOMEM; | |
28186 | + goto out_error; | |
28187 | + } | |
28188 | + learn_buffer_len = 0; | |
28189 | + learn_buffer_user_len = 0; | |
28190 | + gr_learn_attached = 1; | |
28191 | +out_error: | |
28192 | + up(&gr_learn_user_sem); | |
28193 | + return retval; | |
28194 | + } | |
28195 | + return 0; | |
28196 | +} | |
28197 | + | |
28198 | +static int | |
28199 | +close_learn(struct inode *inode, struct file *file) | |
28200 | +{ | |
28201 | + char *tmp; | |
28202 | + | |
28203 | + if (file->f_mode & FMODE_READ) { | |
28204 | + down(&gr_learn_user_sem); | |
28205 | + if (learn_buffer != NULL) { | |
28206 | + spin_lock(&gr_learn_lock); | |
28207 | + tmp = learn_buffer; | |
28208 | + learn_buffer = NULL; | |
28209 | + spin_unlock(&gr_learn_lock); | |
28210 | + vfree(tmp); | |
28211 | + } | |
28212 | + if (learn_buffer_user != NULL) { | |
28213 | + vfree(learn_buffer_user); | |
28214 | + learn_buffer_user = NULL; | |
28215 | + } | |
28216 | + learn_buffer_len = 0; | |
28217 | + learn_buffer_user_len = 0; | |
28218 | + gr_learn_attached = 0; | |
28219 | + up(&gr_learn_user_sem); | |
28220 | + } | |
28221 | + | |
28222 | + return 0; | |
28223 | +} | |
28224 | + | |
28225 | +struct file_operations grsec_fops = { | |
28226 | + .read = read_learn, | |
28227 | + .write = write_grsec_handler, | |
28228 | + .open = open_learn, | |
28229 | + .release = close_learn, | |
28230 | + .poll = poll_learn, | |
28231 | +}; | |
de855c5d AM |
28232 | diff -urNp linux-2.6.29.6/grsecurity/gracl_res.c linux-2.6.29.6/grsecurity/gracl_res.c |
28233 | --- linux-2.6.29.6/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500 | |
28234 | +++ linux-2.6.29.6/grsecurity/gracl_res.c 2009-07-09 22:13:39.000000000 -0400 | |
28235 | @@ -0,0 +1,58 @@ | |
2380c486 JR |
28236 | +#include <linux/kernel.h> |
28237 | +#include <linux/sched.h> | |
28238 | +#include <linux/gracl.h> | |
28239 | +#include <linux/grinternal.h> | |
28240 | + | |
28241 | +static const char *restab_log[] = { | |
28242 | + [RLIMIT_CPU] = "RLIMIT_CPU", | |
28243 | + [RLIMIT_FSIZE] = "RLIMIT_FSIZE", | |
28244 | + [RLIMIT_DATA] = "RLIMIT_DATA", | |
28245 | + [RLIMIT_STACK] = "RLIMIT_STACK", | |
28246 | + [RLIMIT_CORE] = "RLIMIT_CORE", | |
28247 | + [RLIMIT_RSS] = "RLIMIT_RSS", | |
28248 | + [RLIMIT_NPROC] = "RLIMIT_NPROC", | |
28249 | + [RLIMIT_NOFILE] = "RLIMIT_NOFILE", | |
28250 | + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK", | |
28251 | + [RLIMIT_AS] = "RLIMIT_AS", | |
28252 | + [RLIMIT_LOCKS] = "RLIMIT_LOCKS", | |
28253 | + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING", | |
28254 | + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE", | |
28255 | + [RLIMIT_NICE] = "RLIMIT_NICE", | |
28256 | + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO", | |
28257 | + [RLIMIT_RTTIME] = "RLIMIT_RTTIME", | |
28258 | + [GR_CRASH_RES] = "RLIMIT_CRASH" | |
28259 | +}; | |
28260 | + | |
28261 | +void | |
28262 | +gr_log_resource(const struct task_struct *task, | |
28263 | + const int res, const unsigned long wanted, const int gt) | |
28264 | +{ | |
28265 | + const struct cred *cred = __task_cred(task); | |
28266 | + | |
28267 | + if (res == RLIMIT_NPROC && | |
28268 | + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) || | |
28269 | + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE))) | |
28270 | + return; | |
28271 | + else if (res == RLIMIT_MEMLOCK && | |
28272 | + cap_raised(cred->cap_effective, CAP_IPC_LOCK)) | |
28273 | + return; | |
28274 | + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE)) | |
28275 | + return; | |
28276 | + | |
28277 | + if (!gr_acl_is_enabled() && !grsec_resource_logging) | |
28278 | + return; | |
28279 | + | |
de855c5d AM |
28280 | + // not yet supported resource |
28281 | + if (!restab_log[res]) | |
28282 | + return; | |
28283 | + | |
2380c486 JR |
28284 | + preempt_disable(); |
28285 | + | |
28286 | + if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) || | |
28287 | + (!gt && wanted >= task->signal->rlim[res].rlim_cur)) && | |
28288 | + task->signal->rlim[res].rlim_cur != RLIM_INFINITY)) | |
28289 | + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur); | |
28290 | + preempt_enable_no_resched(); | |
28291 | + | |
28292 | + return; | |
28293 | +} | |
de855c5d AM |
28294 | diff -urNp linux-2.6.29.6/grsecurity/gracl_segv.c linux-2.6.29.6/grsecurity/gracl_segv.c |
28295 | --- linux-2.6.29.6/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500 | |
28296 | +++ linux-2.6.29.6/grsecurity/gracl_segv.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
28297 | @@ -0,0 +1,307 @@ |
28298 | +#include <linux/kernel.h> | |
28299 | +#include <linux/mm.h> | |
28300 | +#include <asm/uaccess.h> | |
28301 | +#include <asm/errno.h> | |
28302 | +#include <asm/mman.h> | |
28303 | +#include <net/sock.h> | |
28304 | +#include <linux/file.h> | |
28305 | +#include <linux/fs.h> | |
28306 | +#include <linux/net.h> | |
28307 | +#include <linux/in.h> | |
28308 | +#include <linux/smp_lock.h> | |
28309 | +#include <linux/slab.h> | |
28310 | +#include <linux/types.h> | |
28311 | +#include <linux/sched.h> | |
28312 | +#include <linux/timer.h> | |
28313 | +#include <linux/gracl.h> | |
28314 | +#include <linux/grsecurity.h> | |
28315 | +#include <linux/grinternal.h> | |
28316 | + | |
28317 | +static struct crash_uid *uid_set; | |
28318 | +static unsigned short uid_used; | |
28319 | +static DEFINE_SPINLOCK(gr_uid_lock); | |
28320 | +extern rwlock_t gr_inode_lock; | |
28321 | +extern struct acl_subject_label * | |
28322 | + lookup_acl_subj_label(const ino_t inode, const dev_t dev, | |
28323 | + struct acl_role_label *role); | |
28324 | +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t); | |
28325 | + | |
28326 | +int | |
28327 | +gr_init_uidset(void) | |
28328 | +{ | |
28329 | + uid_set = | |
28330 | + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL); | |
28331 | + uid_used = 0; | |
28332 | + | |
28333 | + return uid_set ? 1 : 0; | |
28334 | +} | |
28335 | + | |
28336 | +void | |
28337 | +gr_free_uidset(void) | |
28338 | +{ | |
28339 | + if (uid_set) | |
28340 | + kfree(uid_set); | |
28341 | + | |
28342 | + return; | |
28343 | +} | |
28344 | + | |
28345 | +int | |
28346 | +gr_find_uid(const uid_t uid) | |
28347 | +{ | |
28348 | + struct crash_uid *tmp = uid_set; | |
28349 | + uid_t buid; | |
28350 | + int low = 0, high = uid_used - 1, mid; | |
28351 | + | |
28352 | + while (high >= low) { | |
28353 | + mid = (low + high) >> 1; | |
28354 | + buid = tmp[mid].uid; | |
28355 | + if (buid == uid) | |
28356 | + return mid; | |
28357 | + if (buid > uid) | |
28358 | + high = mid - 1; | |
28359 | + if (buid < uid) | |
28360 | + low = mid + 1; | |
28361 | + } | |
28362 | + | |
28363 | + return -1; | |
28364 | +} | |
28365 | + | |
28366 | +static __inline__ void | |
28367 | +gr_insertsort(void) | |
28368 | +{ | |
28369 | + unsigned short i, j; | |
28370 | + struct crash_uid index; | |
28371 | + | |
28372 | + for (i = 1; i < uid_used; i++) { | |
28373 | + index = uid_set[i]; | |
28374 | + j = i; | |
28375 | + while ((j > 0) && uid_set[j - 1].uid > index.uid) { | |
28376 | + uid_set[j] = uid_set[j - 1]; | |
28377 | + j--; | |
28378 | + } | |
28379 | + uid_set[j] = index; | |
28380 | + } | |
28381 | + | |
28382 | + return; | |
28383 | +} | |
28384 | + | |
28385 | +static __inline__ void | |
28386 | +gr_insert_uid(const uid_t uid, const unsigned long expires) | |
28387 | +{ | |
28388 | + int loc; | |
28389 | + | |
28390 | + if (uid_used == GR_UIDTABLE_MAX) | |
28391 | + return; | |
28392 | + | |
28393 | + loc = gr_find_uid(uid); | |
28394 | + | |
28395 | + if (loc >= 0) { | |
28396 | + uid_set[loc].expires = expires; | |
28397 | + return; | |
28398 | + } | |
28399 | + | |
28400 | + uid_set[uid_used].uid = uid; | |
28401 | + uid_set[uid_used].expires = expires; | |
28402 | + uid_used++; | |
28403 | + | |
28404 | + gr_insertsort(); | |
28405 | + | |
28406 | + return; | |
28407 | +} | |
28408 | + | |
28409 | +void | |
28410 | +gr_remove_uid(const unsigned short loc) | |
28411 | +{ | |
28412 | + unsigned short i; | |
28413 | + | |
28414 | + for (i = loc + 1; i < uid_used; i++) | |
28415 | + uid_set[i - 1] = uid_set[i]; | |
28416 | + | |
28417 | + uid_used--; | |
28418 | + | |
28419 | + return; | |
28420 | +} | |
28421 | + | |
28422 | +int | |
28423 | +gr_check_crash_uid(const uid_t uid) | |
28424 | +{ | |
28425 | + int loc; | |
28426 | + int ret = 0; | |
28427 | + | |
28428 | + if (unlikely(!gr_acl_is_enabled())) | |
28429 | + return 0; | |
28430 | + | |
28431 | + spin_lock(&gr_uid_lock); | |
28432 | + loc = gr_find_uid(uid); | |
28433 | + | |
28434 | + if (loc < 0) | |
28435 | + goto out_unlock; | |
28436 | + | |
28437 | + if (time_before_eq(uid_set[loc].expires, get_seconds())) | |
28438 | + gr_remove_uid(loc); | |
28439 | + else | |
28440 | + ret = 1; | |
28441 | + | |
28442 | +out_unlock: | |
28443 | + spin_unlock(&gr_uid_lock); | |
28444 | + return ret; | |
28445 | +} | |
28446 | + | |
28447 | +static __inline__ int | |
28448 | +proc_is_setxid(const struct cred *cred) | |
28449 | +{ | |
28450 | + if (cred->uid != cred->euid || cred->uid != cred->suid || | |
28451 | + cred->uid != cred->fsuid) | |
28452 | + return 1; | |
28453 | + if (cred->gid != cred->egid || cred->gid != cred->sgid || | |
28454 | + cred->gid != cred->fsgid) | |
28455 | + return 1; | |
28456 | + | |
28457 | + return 0; | |
28458 | +} | |
28459 | +static __inline__ int | |
28460 | +gr_fake_force_sig(int sig, struct task_struct *t) | |
28461 | +{ | |
28462 | + unsigned long int flags; | |
28463 | + int ret, blocked, ignored; | |
28464 | + struct k_sigaction *action; | |
28465 | + | |
28466 | + spin_lock_irqsave(&t->sighand->siglock, flags); | |
28467 | + action = &t->sighand->action[sig-1]; | |
28468 | + ignored = action->sa.sa_handler == SIG_IGN; | |
28469 | + blocked = sigismember(&t->blocked, sig); | |
28470 | + if (blocked || ignored) { | |
28471 | + action->sa.sa_handler = SIG_DFL; | |
28472 | + if (blocked) { | |
28473 | + sigdelset(&t->blocked, sig); | |
28474 | + recalc_sigpending_and_wake(t); | |
28475 | + } | |
28476 | + } | |
28477 | + if (action->sa.sa_handler == SIG_DFL) | |
28478 | + t->signal->flags &= ~SIGNAL_UNKILLABLE; | |
28479 | + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t); | |
28480 | + | |
28481 | + spin_unlock_irqrestore(&t->sighand->siglock, flags); | |
28482 | + | |
28483 | + return ret; | |
28484 | +} | |
28485 | + | |
28486 | +void | |
28487 | +gr_handle_crash(struct task_struct *task, const int sig) | |
28488 | +{ | |
28489 | + struct acl_subject_label *curr; | |
28490 | + struct acl_subject_label *curr2; | |
28491 | + struct task_struct *tsk, *tsk2; | |
28492 | + const struct cred *cred = __task_cred(task); | |
28493 | + const struct cred *cred2; | |
28494 | + | |
28495 | + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL) | |
28496 | + return; | |
28497 | + | |
28498 | + if (unlikely(!gr_acl_is_enabled())) | |
28499 | + return; | |
28500 | + | |
28501 | + curr = task->acl; | |
28502 | + | |
28503 | + if (!(curr->resmask & (1 << GR_CRASH_RES))) | |
28504 | + return; | |
28505 | + | |
28506 | + if (time_before_eq(curr->expires, get_seconds())) { | |
28507 | + curr->expires = 0; | |
28508 | + curr->crashes = 0; | |
28509 | + } | |
28510 | + | |
28511 | + curr->crashes++; | |
28512 | + | |
28513 | + if (!curr->expires) | |
28514 | + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max; | |
28515 | + | |
28516 | + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) && | |
28517 | + time_after(curr->expires, get_seconds())) { | |
28518 | + if (cred->uid && proc_is_setxid(cred)) { | |
28519 | + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max); | |
28520 | + spin_lock(&gr_uid_lock); | |
28521 | + gr_insert_uid(cred->uid, curr->expires); | |
28522 | + spin_unlock(&gr_uid_lock); | |
28523 | + curr->expires = 0; | |
28524 | + curr->crashes = 0; | |
28525 | + read_lock(&tasklist_lock); | |
28526 | + do_each_thread(tsk2, tsk) { | |
28527 | + cred2 = __task_cred(tsk); | |
28528 | + if (tsk != task && cred2->uid == cred->uid) | |
28529 | + gr_fake_force_sig(SIGKILL, tsk); | |
28530 | + } while_each_thread(tsk2, tsk); | |
28531 | + read_unlock(&tasklist_lock); | |
28532 | + } else { | |
28533 | + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max); | |
28534 | + read_lock(&tasklist_lock); | |
28535 | + do_each_thread(tsk2, tsk) { | |
28536 | + if (likely(tsk != task)) { | |
28537 | + curr2 = tsk->acl; | |
28538 | + | |
28539 | + if (curr2->device == curr->device && | |
28540 | + curr2->inode == curr->inode) | |
28541 | + gr_fake_force_sig(SIGKILL, tsk); | |
28542 | + } | |
28543 | + } while_each_thread(tsk2, tsk); | |
28544 | + read_unlock(&tasklist_lock); | |
28545 | + } | |
28546 | + } | |
28547 | + | |
28548 | + return; | |
28549 | +} | |
28550 | + | |
28551 | +int | |
28552 | +gr_check_crash_exec(const struct file *filp) | |
28553 | +{ | |
28554 | + struct acl_subject_label *curr; | |
28555 | + | |
28556 | + if (unlikely(!gr_acl_is_enabled())) | |
28557 | + return 0; | |
28558 | + | |
28559 | + read_lock(&gr_inode_lock); | |
28560 | + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino, | |
28561 | + filp->f_path.dentry->d_inode->i_sb->s_dev, | |
28562 | + current->role); | |
28563 | + read_unlock(&gr_inode_lock); | |
28564 | + | |
28565 | + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) || | |
28566 | + (!curr->crashes && !curr->expires)) | |
28567 | + return 0; | |
28568 | + | |
28569 | + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) && | |
28570 | + time_after(curr->expires, get_seconds())) | |
28571 | + return 1; | |
28572 | + else if (time_before_eq(curr->expires, get_seconds())) { | |
28573 | + curr->crashes = 0; | |
28574 | + curr->expires = 0; | |
28575 | + } | |
28576 | + | |
28577 | + return 0; | |
28578 | +} | |
28579 | + | |
28580 | +void | |
28581 | +gr_handle_alertkill(struct task_struct *task) | |
28582 | +{ | |
28583 | + struct acl_subject_label *curracl; | |
28584 | + __u32 curr_ip; | |
28585 | + struct task_struct *p, *p2; | |
28586 | + | |
28587 | + if (unlikely(!gr_acl_is_enabled())) | |
28588 | + return; | |
28589 | + | |
28590 | + curracl = task->acl; | |
28591 | + curr_ip = task->signal->curr_ip; | |
28592 | + | |
28593 | + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) { | |
28594 | + read_lock(&tasklist_lock); | |
28595 | + do_each_thread(p2, p) { | |
28596 | + if (p->signal->curr_ip == curr_ip) | |
28597 | + gr_fake_force_sig(SIGKILL, p); | |
28598 | + } while_each_thread(p2, p); | |
28599 | + read_unlock(&tasklist_lock); | |
28600 | + } else if (curracl->mode & GR_KILLPROC) | |
28601 | + gr_fake_force_sig(SIGKILL, task); | |
28602 | + | |
28603 | + return; | |
28604 | +} | |
de855c5d AM |
28605 | diff -urNp linux-2.6.29.6/grsecurity/gracl_shm.c linux-2.6.29.6/grsecurity/gracl_shm.c |
28606 | --- linux-2.6.29.6/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500 | |
28607 | +++ linux-2.6.29.6/grsecurity/gracl_shm.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
28608 | @@ -0,0 +1,37 @@ |
28609 | +#include <linux/kernel.h> | |
28610 | +#include <linux/mm.h> | |
28611 | +#include <linux/sched.h> | |
28612 | +#include <linux/file.h> | |
28613 | +#include <linux/ipc.h> | |
28614 | +#include <linux/gracl.h> | |
28615 | +#include <linux/grsecurity.h> | |
28616 | +#include <linux/grinternal.h> | |
28617 | + | |
28618 | +int | |
28619 | +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid, | |
28620 | + const time_t shm_createtime, const uid_t cuid, const int shmid) | |
28621 | +{ | |
28622 | + struct task_struct *task; | |
28623 | + | |
28624 | + if (!gr_acl_is_enabled()) | |
28625 | + return 1; | |
28626 | + | |
28627 | + read_lock(&tasklist_lock); | |
28628 | + | |
28629 | + task = find_task_by_vpid(shm_cprid); | |
28630 | + | |
28631 | + if (unlikely(!task)) | |
28632 | + task = find_task_by_vpid(shm_lapid); | |
28633 | + | |
28634 | + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) || | |
28635 | + (task->pid == shm_lapid)) && | |
28636 | + (task->acl->mode & GR_PROTSHM) && | |
28637 | + (task->acl != current->acl))) { | |
28638 | + read_unlock(&tasklist_lock); | |
28639 | + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid); | |
28640 | + return 0; | |
28641 | + } | |
28642 | + read_unlock(&tasklist_lock); | |
28643 | + | |
28644 | + return 1; | |
28645 | +} | |
de855c5d AM |
28646 | diff -urNp linux-2.6.29.6/grsecurity/grsec_chdir.c linux-2.6.29.6/grsecurity/grsec_chdir.c |
28647 | --- linux-2.6.29.6/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500 | |
28648 | +++ linux-2.6.29.6/grsecurity/grsec_chdir.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
28649 | @@ -0,0 +1,19 @@ |
28650 | +#include <linux/kernel.h> | |
28651 | +#include <linux/sched.h> | |
28652 | +#include <linux/fs.h> | |
28653 | +#include <linux/file.h> | |
28654 | +#include <linux/grsecurity.h> | |
28655 | +#include <linux/grinternal.h> | |
28656 | + | |
28657 | +void | |
28658 | +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt) | |
28659 | +{ | |
28660 | +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR | |
28661 | + if ((grsec_enable_chdir && grsec_enable_group && | |
28662 | + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir && | |
28663 | + !grsec_enable_group)) { | |
28664 | + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt); | |
28665 | + } | |
28666 | +#endif | |
28667 | + return; | |
28668 | +} | |
de855c5d AM |
28669 | diff -urNp linux-2.6.29.6/grsecurity/grsec_chroot.c linux-2.6.29.6/grsecurity/grsec_chroot.c |
28670 | --- linux-2.6.29.6/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500 | |
28671 | +++ linux-2.6.29.6/grsecurity/grsec_chroot.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
28672 | @@ -0,0 +1,350 @@ |
28673 | +#include <linux/kernel.h> | |
28674 | +#include <linux/module.h> | |
28675 | +#include <linux/sched.h> | |
28676 | +#include <linux/file.h> | |
28677 | +#include <linux/fs.h> | |
28678 | +#include <linux/mount.h> | |
28679 | +#include <linux/types.h> | |
28680 | +#include <linux/pid_namespace.h> | |
28681 | +#include <linux/grsecurity.h> | |
28682 | +#include <linux/grinternal.h> | |
28683 | + | |
28684 | +int | |
28685 | +gr_handle_chroot_unix(const pid_t pid) | |
28686 | +{ | |
28687 | +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX | |
28688 | + struct pid *spid = NULL; | |
28689 | + | |
28690 | + if (unlikely(!grsec_enable_chroot_unix)) | |
28691 | + return 1; | |
28692 | + | |
28693 | + if (likely(!proc_is_chrooted(current))) | |
28694 | + return 1; | |
28695 | + | |
28696 | + read_lock(&tasklist_lock); | |
28697 | + | |
28698 | + spid = find_vpid(pid); | |
28699 | + if (spid) { | |
28700 | + struct task_struct *p; | |
28701 | + p = pid_task(spid, PIDTYPE_PID); | |
28702 | + task_lock(p); | |
28703 | + if (unlikely(!have_same_root(current, p))) { | |
28704 | + task_unlock(p); | |
28705 | + read_unlock(&tasklist_lock); | |
28706 | + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG); | |
28707 | + return 0; | |
28708 | + } | |
28709 | + task_unlock(p); | |
28710 | + } | |
28711 | + read_unlock(&tasklist_lock); | |
28712 | +#endif | |
28713 | + return 1; | |
28714 | +} | |
28715 | + | |
28716 | +int | |
28717 | +gr_handle_chroot_nice(void) | |
28718 | +{ | |
28719 | +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE | |
28720 | + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) { | |
28721 | + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG); | |
28722 | + return -EPERM; | |
28723 | + } | |
28724 | +#endif | |
28725 | + return 0; | |
28726 | +} | |
28727 | + | |
28728 | +int | |
28729 | +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval) | |
28730 | +{ | |
28731 | +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE | |
28732 | + if (grsec_enable_chroot_nice && (niceval < task_nice(p)) | |
28733 | + && proc_is_chrooted(current)) { | |
28734 | + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid); | |
28735 | + return -EACCES; | |
28736 | + } | |
28737 | +#endif | |
28738 | + return 0; | |
28739 | +} | |
28740 | + | |
28741 | +int | |
28742 | +gr_handle_chroot_rawio(const struct inode *inode) | |
28743 | +{ | |
28744 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS | |
28745 | + if (grsec_enable_chroot_caps && proc_is_chrooted(current) && | |
28746 | + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO)) | |
28747 | + return 1; | |
28748 | +#endif | |
28749 | + return 0; | |
28750 | +} | |
28751 | + | |
28752 | +int | |
28753 | +gr_pid_is_chrooted(struct task_struct *p) | |
28754 | +{ | |
28755 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK | |
28756 | + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL) | |
28757 | + return 0; | |
28758 | + | |
28759 | + task_lock(p); | |
28760 | + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) || | |
28761 | + !have_same_root(current, p)) { | |
28762 | + task_unlock(p); | |
28763 | + return 1; | |
28764 | + } | |
28765 | + task_unlock(p); | |
28766 | +#endif | |
28767 | + return 0; | |
28768 | +} | |
28769 | + | |
28770 | +EXPORT_SYMBOL(gr_pid_is_chrooted); | |
28771 | + | |
28772 | +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR) | |
28773 | +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt) | |
28774 | +{ | |
28775 | + struct dentry *dentry = (struct dentry *)u_dentry; | |
28776 | + struct vfsmount *mnt = (struct vfsmount *)u_mnt; | |
28777 | + struct dentry *realroot; | |
28778 | + struct vfsmount *realrootmnt; | |
28779 | + struct dentry *currentroot; | |
28780 | + struct vfsmount *currentmnt; | |
28781 | + struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper; | |
28782 | + int ret = 1; | |
28783 | + | |
28784 | + read_lock(&reaper->fs->lock); | |
28785 | + realrootmnt = mntget(reaper->fs->root.mnt); | |
28786 | + realroot = dget(reaper->fs->root.dentry); | |
28787 | + read_unlock(&reaper->fs->lock); | |
28788 | + | |
28789 | + read_lock(¤t->fs->lock); | |
28790 | + currentmnt = mntget(current->fs->root.mnt); | |
28791 | + currentroot = dget(current->fs->root.dentry); | |
28792 | + read_unlock(¤t->fs->lock); | |
28793 | + | |
28794 | + spin_lock(&dcache_lock); | |
28795 | + for (;;) { | |
28796 | + if (unlikely((dentry == realroot && mnt == realrootmnt) | |
28797 | + || (dentry == currentroot && mnt == currentmnt))) | |
28798 | + break; | |
28799 | + if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) { | |
28800 | + if (mnt->mnt_parent == mnt) | |
28801 | + break; | |
28802 | + dentry = mnt->mnt_mountpoint; | |
28803 | + mnt = mnt->mnt_parent; | |
28804 | + continue; | |
28805 | + } | |
28806 | + dentry = dentry->d_parent; | |
28807 | + } | |
28808 | + spin_unlock(&dcache_lock); | |
28809 | + | |
28810 | + dput(currentroot); | |
28811 | + mntput(currentmnt); | |
28812 | + | |
28813 | + /* access is outside of chroot */ | |
28814 | + if (dentry == realroot && mnt == realrootmnt) | |
28815 | + ret = 0; | |
28816 | + | |
28817 | + dput(realroot); | |
28818 | + mntput(realrootmnt); | |
28819 | + return ret; | |
28820 | +} | |
28821 | +#endif | |
28822 | + | |
28823 | +int | |
28824 | +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt) | |
28825 | +{ | |
28826 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR | |
28827 | + if (!grsec_enable_chroot_fchdir) | |
28828 | + return 1; | |
28829 | + | |
28830 | + if (!proc_is_chrooted(current)) | |
28831 | + return 1; | |
28832 | + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) { | |
28833 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt); | |
28834 | + return 0; | |
28835 | + } | |
28836 | +#endif | |
28837 | + return 1; | |
28838 | +} | |
28839 | + | |
28840 | +int | |
28841 | +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid, | |
28842 | + const time_t shm_createtime) | |
28843 | +{ | |
28844 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT | |
28845 | + struct pid *pid = NULL; | |
28846 | + time_t starttime; | |
28847 | + | |
28848 | + if (unlikely(!grsec_enable_chroot_shmat)) | |
28849 | + return 1; | |
28850 | + | |
28851 | + if (likely(!proc_is_chrooted(current))) | |
28852 | + return 1; | |
28853 | + | |
28854 | + read_lock(&tasklist_lock); | |
28855 | + | |
28856 | + pid = find_vpid(shm_cprid); | |
28857 | + if (pid) { | |
28858 | + struct task_struct *p; | |
28859 | + p = pid_task(pid, PIDTYPE_PID); | |
28860 | + task_lock(p); | |
28861 | + starttime = p->start_time.tv_sec; | |
28862 | + if (unlikely(!have_same_root(current, p) && | |
28863 | + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) { | |
28864 | + task_unlock(p); | |
28865 | + read_unlock(&tasklist_lock); | |
28866 | + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG); | |
28867 | + return 0; | |
28868 | + } | |
28869 | + task_unlock(p); | |
28870 | + } else { | |
28871 | + pid = find_vpid(shm_lapid); | |
28872 | + if (pid) { | |
28873 | + struct task_struct *p; | |
28874 | + p = pid_task(pid, PIDTYPE_PID); | |
28875 | + task_lock(p); | |
28876 | + if (unlikely(!have_same_root(current, p))) { | |
28877 | + task_unlock(p); | |
28878 | + read_unlock(&tasklist_lock); | |
28879 | + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG); | |
28880 | + return 0; | |
28881 | + } | |
28882 | + task_unlock(p); | |
28883 | + } | |
28884 | + } | |
28885 | + | |
28886 | + read_unlock(&tasklist_lock); | |
28887 | +#endif | |
28888 | + return 1; | |
28889 | +} | |
28890 | + | |
28891 | +void | |
28892 | +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt) | |
28893 | +{ | |
28894 | +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG | |
28895 | + if (grsec_enable_chroot_execlog && proc_is_chrooted(current)) | |
28896 | + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt); | |
28897 | +#endif | |
28898 | + return; | |
28899 | +} | |
28900 | + | |
28901 | +int | |
28902 | +gr_handle_chroot_mknod(const struct dentry *dentry, | |
28903 | + const struct vfsmount *mnt, const int mode) | |
28904 | +{ | |
28905 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD | |
28906 | + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) && | |
28907 | + proc_is_chrooted(current)) { | |
28908 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt); | |
28909 | + return -EPERM; | |
28910 | + } | |
28911 | +#endif | |
28912 | + return 0; | |
28913 | +} | |
28914 | + | |
28915 | +int | |
28916 | +gr_handle_chroot_mount(const struct dentry *dentry, | |
28917 | + const struct vfsmount *mnt, const char *dev_name) | |
28918 | +{ | |
28919 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT | |
28920 | + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) { | |
28921 | + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt); | |
28922 | + return -EPERM; | |
28923 | + } | |
28924 | +#endif | |
28925 | + return 0; | |
28926 | +} | |
28927 | + | |
28928 | +int | |
28929 | +gr_handle_chroot_pivot(void) | |
28930 | +{ | |
28931 | +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT | |
28932 | + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) { | |
28933 | + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG); | |
28934 | + return -EPERM; | |
28935 | + } | |
28936 | +#endif | |
28937 | + return 0; | |
28938 | +} | |
28939 | + | |
28940 | +int | |
28941 | +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt) | |
28942 | +{ | |
28943 | +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE | |
28944 | + if (grsec_enable_chroot_double && proc_is_chrooted(current) && | |
28945 | + !gr_is_outside_chroot(dentry, mnt)) { | |
28946 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt); | |
28947 | + return -EPERM; | |
28948 | + } | |
28949 | +#endif | |
28950 | + return 0; | |
28951 | +} | |
28952 | + | |
28953 | +int | |
28954 | +gr_handle_chroot_caps(struct path *path) | |
28955 | +{ | |
28956 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS | |
28957 | + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL && | |
28958 | + ((current->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb != | |
28959 | + path->dentry->d_inode->i_sb) || | |
28960 | + (current->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino != | |
28961 | + path->dentry->d_inode->i_ino))) { | |
28962 | + | |
28963 | + kernel_cap_t chroot_caps = GR_CHROOT_CAPS; | |
28964 | + const struct cred *old = current_cred(); | |
28965 | + struct cred *new = prepare_creds(); | |
28966 | + if (new == NULL) | |
28967 | + return 1; | |
28968 | + | |
28969 | + new->cap_permitted = cap_drop(old->cap_permitted, | |
28970 | + chroot_caps); | |
28971 | + new->cap_inheritable = cap_drop(old->cap_inheritable, | |
28972 | + chroot_caps); | |
28973 | + new->cap_effective = cap_drop(old->cap_effective, | |
28974 | + chroot_caps); | |
28975 | + | |
28976 | + commit_creds(new); | |
28977 | + | |
28978 | + return 0; | |
28979 | + } | |
28980 | +#endif | |
28981 | + return 0; | |
28982 | +} | |
28983 | + | |
28984 | +int | |
28985 | +gr_handle_chroot_sysctl(const int op) | |
28986 | +{ | |
28987 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL | |
28988 | + if (grsec_enable_chroot_sysctl && proc_is_chrooted(current) | |
28989 | + && (op & MAY_WRITE)) | |
28990 | + return -EACCES; | |
28991 | +#endif | |
28992 | + return 0; | |
28993 | +} | |
28994 | + | |
28995 | +void | |
28996 | +gr_handle_chroot_chdir(struct path *path) | |
28997 | +{ | |
28998 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR | |
28999 | + if (grsec_enable_chroot_chdir) | |
29000 | + set_fs_pwd(current->fs, path); | |
29001 | +#endif | |
29002 | + return; | |
29003 | +} | |
29004 | + | |
29005 | +int | |
29006 | +gr_handle_chroot_chmod(const struct dentry *dentry, | |
29007 | + const struct vfsmount *mnt, const int mode) | |
29008 | +{ | |
29009 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD | |
29010 | + if (grsec_enable_chroot_chmod && | |
29011 | + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) && | |
29012 | + proc_is_chrooted(current)) { | |
29013 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt); | |
29014 | + return -EPERM; | |
29015 | + } | |
29016 | +#endif | |
29017 | + return 0; | |
29018 | +} | |
29019 | + | |
29020 | +#ifdef CONFIG_SECURITY | |
29021 | +EXPORT_SYMBOL(gr_handle_chroot_caps); | |
29022 | +#endif | |
de855c5d AM |
29023 | diff -urNp linux-2.6.29.6/grsecurity/grsec_disabled.c linux-2.6.29.6/grsecurity/grsec_disabled.c |
29024 | --- linux-2.6.29.6/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500 | |
29025 | +++ linux-2.6.29.6/grsecurity/grsec_disabled.c 2009-07-09 23:09:22.000000000 -0400 | |
29026 | @@ -0,0 +1,426 @@ | |
2380c486 JR |
29027 | +#include <linux/kernel.h> |
29028 | +#include <linux/module.h> | |
29029 | +#include <linux/sched.h> | |
29030 | +#include <linux/file.h> | |
29031 | +#include <linux/fs.h> | |
29032 | +#include <linux/kdev_t.h> | |
29033 | +#include <linux/net.h> | |
29034 | +#include <linux/in.h> | |
29035 | +#include <linux/ip.h> | |
29036 | +#include <linux/skbuff.h> | |
29037 | +#include <linux/sysctl.h> | |
29038 | + | |
29039 | +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS | |
29040 | +void | |
29041 | +pax_set_initial_flags(struct linux_binprm *bprm) | |
29042 | +{ | |
29043 | + return; | |
29044 | +} | |
29045 | +#endif | |
29046 | + | |
29047 | +#ifdef CONFIG_SYSCTL | |
29048 | +__u32 | |
29049 | +gr_handle_sysctl(const struct ctl_table * table, const int op) | |
29050 | +{ | |
29051 | + return 0; | |
29052 | +} | |
29053 | +#endif | |
29054 | + | |
de855c5d AM |
29055 | +#ifdef CONFIG_TASKSTATS |
29056 | +int gr_is_taskstats_denied(int pid) | |
29057 | +{ | |
29058 | + return 0; | |
29059 | +} | |
29060 | +#endif | |
29061 | + | |
2380c486 JR |
29062 | +int |
29063 | +gr_acl_is_enabled(void) | |
29064 | +{ | |
29065 | + return 0; | |
29066 | +} | |
29067 | + | |
29068 | +int | |
29069 | +gr_handle_rawio(const struct inode *inode) | |
29070 | +{ | |
29071 | + return 0; | |
29072 | +} | |
29073 | + | |
29074 | +void | |
29075 | +gr_acl_handle_psacct(struct task_struct *task, const long code) | |
29076 | +{ | |
29077 | + return; | |
29078 | +} | |
29079 | + | |
29080 | +int | |
29081 | +gr_handle_ptrace(struct task_struct *task, const long request) | |
29082 | +{ | |
29083 | + return 0; | |
29084 | +} | |
29085 | + | |
29086 | +int | |
29087 | +gr_handle_proc_ptrace(struct task_struct *task) | |
29088 | +{ | |
29089 | + return 0; | |
29090 | +} | |
29091 | + | |
29092 | +void | |
29093 | +gr_learn_resource(const struct task_struct *task, | |
29094 | + const int res, const unsigned long wanted, const int gt) | |
29095 | +{ | |
29096 | + return; | |
29097 | +} | |
29098 | + | |
29099 | +int | |
29100 | +gr_set_acls(const int type) | |
29101 | +{ | |
29102 | + return 0; | |
29103 | +} | |
29104 | + | |
29105 | +int | |
29106 | +gr_check_hidden_task(const struct task_struct *tsk) | |
29107 | +{ | |
29108 | + return 0; | |
29109 | +} | |
29110 | + | |
29111 | +int | |
29112 | +gr_check_protected_task(const struct task_struct *task) | |
29113 | +{ | |
29114 | + return 0; | |
29115 | +} | |
29116 | + | |
29117 | +void | |
29118 | +gr_copy_label(struct task_struct *tsk) | |
29119 | +{ | |
29120 | + return; | |
29121 | +} | |
29122 | + | |
29123 | +void | |
29124 | +gr_set_pax_flags(struct task_struct *task) | |
29125 | +{ | |
29126 | + return; | |
29127 | +} | |
29128 | + | |
29129 | +int | |
de855c5d AM |
29130 | +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt, |
29131 | + const int unsafe_share) | |
2380c486 JR |
29132 | +{ |
29133 | + return 0; | |
29134 | +} | |
29135 | + | |
29136 | +void | |
29137 | +gr_handle_delete(const ino_t ino, const dev_t dev) | |
29138 | +{ | |
29139 | + return; | |
29140 | +} | |
29141 | + | |
29142 | +void | |
29143 | +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt) | |
29144 | +{ | |
29145 | + return; | |
29146 | +} | |
29147 | + | |
29148 | +void | |
29149 | +gr_handle_crash(struct task_struct *task, const int sig) | |
29150 | +{ | |
29151 | + return; | |
29152 | +} | |
29153 | + | |
29154 | +int | |
29155 | +gr_check_crash_exec(const struct file *filp) | |
29156 | +{ | |
29157 | + return 0; | |
29158 | +} | |
29159 | + | |
29160 | +int | |
29161 | +gr_check_crash_uid(const uid_t uid) | |
29162 | +{ | |
29163 | + return 0; | |
29164 | +} | |
29165 | + | |
29166 | +void | |
29167 | +gr_handle_rename(struct inode *old_dir, struct inode *new_dir, | |
29168 | + struct dentry *old_dentry, | |
29169 | + struct dentry *new_dentry, | |
29170 | + struct vfsmount *mnt, const __u8 replace) | |
29171 | +{ | |
29172 | + return; | |
29173 | +} | |
29174 | + | |
29175 | +int | |
29176 | +gr_search_socket(const int family, const int type, const int protocol) | |
29177 | +{ | |
29178 | + return 1; | |
29179 | +} | |
29180 | + | |
29181 | +int | |
29182 | +gr_search_connectbind(const int mode, const struct socket *sock, | |
29183 | + const struct sockaddr_in *addr) | |
29184 | +{ | |
29185 | + return 0; | |
29186 | +} | |
29187 | + | |
29188 | +int | |
29189 | +gr_is_capable(const int cap) | |
29190 | +{ | |
29191 | + return 1; | |
29192 | +} | |
29193 | + | |
29194 | +int | |
29195 | +gr_is_capable_nolog(const int cap) | |
29196 | +{ | |
29197 | + return 1; | |
29198 | +} | |
29199 | + | |
29200 | +void | |
29201 | +gr_handle_alertkill(struct task_struct *task) | |
29202 | +{ | |
29203 | + return; | |
29204 | +} | |
29205 | + | |
29206 | +__u32 | |
29207 | +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt) | |
29208 | +{ | |
29209 | + return 1; | |
29210 | +} | |
29211 | + | |
29212 | +__u32 | |
29213 | +gr_acl_handle_hidden_file(const struct dentry * dentry, | |
29214 | + const struct vfsmount * mnt) | |
29215 | +{ | |
29216 | + return 1; | |
29217 | +} | |
29218 | + | |
29219 | +__u32 | |
29220 | +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt, | |
29221 | + const int fmode) | |
29222 | +{ | |
29223 | + return 1; | |
29224 | +} | |
29225 | + | |
29226 | +__u32 | |
29227 | +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt) | |
29228 | +{ | |
29229 | + return 1; | |
29230 | +} | |
29231 | + | |
29232 | +__u32 | |
29233 | +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt) | |
29234 | +{ | |
29235 | + return 1; | |
29236 | +} | |
29237 | + | |
29238 | +int | |
29239 | +gr_acl_handle_mmap(const struct file *file, const unsigned long prot, | |
29240 | + unsigned int *vm_flags) | |
29241 | +{ | |
29242 | + return 1; | |
29243 | +} | |
29244 | + | |
29245 | +__u32 | |
29246 | +gr_acl_handle_truncate(const struct dentry * dentry, | |
29247 | + const struct vfsmount * mnt) | |
29248 | +{ | |
29249 | + return 1; | |
29250 | +} | |
29251 | + | |
29252 | +__u32 | |
29253 | +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt) | |
29254 | +{ | |
29255 | + return 1; | |
29256 | +} | |
29257 | + | |
29258 | +__u32 | |
29259 | +gr_acl_handle_access(const struct dentry * dentry, | |
29260 | + const struct vfsmount * mnt, const int fmode) | |
29261 | +{ | |
29262 | + return 1; | |
29263 | +} | |
29264 | + | |
29265 | +__u32 | |
29266 | +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt, | |
29267 | + mode_t mode) | |
29268 | +{ | |
29269 | + return 1; | |
29270 | +} | |
29271 | + | |
29272 | +__u32 | |
29273 | +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt, | |
29274 | + mode_t mode) | |
29275 | +{ | |
29276 | + return 1; | |
29277 | +} | |
29278 | + | |
29279 | +__u32 | |
29280 | +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt) | |
29281 | +{ | |
29282 | + return 1; | |
29283 | +} | |
29284 | + | |
29285 | +void | |
29286 | +grsecurity_init(void) | |
29287 | +{ | |
29288 | + return; | |
29289 | +} | |
29290 | + | |
29291 | +__u32 | |
29292 | +gr_acl_handle_mknod(const struct dentry * new_dentry, | |
29293 | + const struct dentry * parent_dentry, | |
29294 | + const struct vfsmount * parent_mnt, | |
29295 | + const int mode) | |
29296 | +{ | |
29297 | + return 1; | |
29298 | +} | |
29299 | + | |
29300 | +__u32 | |
29301 | +gr_acl_handle_mkdir(const struct dentry * new_dentry, | |
29302 | + const struct dentry * parent_dentry, | |
29303 | + const struct vfsmount * parent_mnt) | |
29304 | +{ | |
29305 | + return 1; | |
29306 | +} | |
29307 | + | |
29308 | +__u32 | |
29309 | +gr_acl_handle_symlink(const struct dentry * new_dentry, | |
29310 | + const struct dentry * parent_dentry, | |
29311 | + const struct vfsmount * parent_mnt, const char *from) | |
29312 | +{ | |
29313 | + return 1; | |
29314 | +} | |
29315 | + | |
29316 | +__u32 | |
29317 | +gr_acl_handle_link(const struct dentry * new_dentry, | |
29318 | + const struct dentry * parent_dentry, | |
29319 | + const struct vfsmount * parent_mnt, | |
29320 | + const struct dentry * old_dentry, | |
29321 | + const struct vfsmount * old_mnt, const char *to) | |
29322 | +{ | |
29323 | + return 1; | |
29324 | +} | |
29325 | + | |
29326 | +int | |
29327 | +gr_acl_handle_rename(const struct dentry *new_dentry, | |
29328 | + const struct dentry *parent_dentry, | |
29329 | + const struct vfsmount *parent_mnt, | |
29330 | + const struct dentry *old_dentry, | |
29331 | + const struct inode *old_parent_inode, | |
29332 | + const struct vfsmount *old_mnt, const char *newname) | |
29333 | +{ | |
29334 | + return 0; | |
29335 | +} | |
29336 | + | |
29337 | +int | |
29338 | +gr_acl_handle_filldir(const struct file *file, const char *name, | |
29339 | + const int namelen, const ino_t ino) | |
29340 | +{ | |
29341 | + return 1; | |
29342 | +} | |
29343 | + | |
29344 | +int | |
29345 | +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid, | |
29346 | + const time_t shm_createtime, const uid_t cuid, const int shmid) | |
29347 | +{ | |
29348 | + return 1; | |
29349 | +} | |
29350 | + | |
29351 | +int | |
29352 | +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr) | |
29353 | +{ | |
29354 | + return 0; | |
29355 | +} | |
29356 | + | |
29357 | +int | |
29358 | +gr_search_accept(const struct socket *sock) | |
29359 | +{ | |
29360 | + return 0; | |
29361 | +} | |
29362 | + | |
29363 | +int | |
29364 | +gr_search_listen(const struct socket *sock) | |
29365 | +{ | |
29366 | + return 0; | |
29367 | +} | |
29368 | + | |
29369 | +int | |
29370 | +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr) | |
29371 | +{ | |
29372 | + return 0; | |
29373 | +} | |
29374 | + | |
29375 | +__u32 | |
29376 | +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt) | |
29377 | +{ | |
29378 | + return 1; | |
29379 | +} | |
29380 | + | |
29381 | +__u32 | |
29382 | +gr_acl_handle_creat(const struct dentry * dentry, | |
29383 | + const struct dentry * p_dentry, | |
29384 | + const struct vfsmount * p_mnt, const int fmode, | |
29385 | + const int imode) | |
29386 | +{ | |
29387 | + return 1; | |
29388 | +} | |
29389 | + | |
29390 | +void | |
29391 | +gr_acl_handle_exit(void) | |
29392 | +{ | |
29393 | + return; | |
29394 | +} | |
29395 | + | |
29396 | +int | |
29397 | +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot) | |
29398 | +{ | |
29399 | + return 1; | |
29400 | +} | |
29401 | + | |
29402 | +void | |
29403 | +gr_set_role_label(const uid_t uid, const gid_t gid) | |
29404 | +{ | |
29405 | + return; | |
29406 | +} | |
29407 | + | |
29408 | +int | |
29409 | +gr_acl_handle_procpidmem(const struct task_struct *task) | |
29410 | +{ | |
29411 | + return 0; | |
29412 | +} | |
29413 | + | |
29414 | +int | |
29415 | +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb) | |
29416 | +{ | |
29417 | + return 0; | |
29418 | +} | |
29419 | + | |
29420 | +int | |
29421 | +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr) | |
29422 | +{ | |
29423 | + return 0; | |
29424 | +} | |
29425 | + | |
29426 | +void | |
29427 | +gr_set_kernel_label(struct task_struct *task) | |
29428 | +{ | |
29429 | + return; | |
29430 | +} | |
29431 | + | |
29432 | +int | |
29433 | +gr_check_user_change(int real, int effective, int fs) | |
29434 | +{ | |
29435 | + return 0; | |
29436 | +} | |
29437 | + | |
29438 | +int | |
29439 | +gr_check_group_change(int real, int effective, int fs) | |
29440 | +{ | |
29441 | + return 0; | |
29442 | +} | |
29443 | + | |
29444 | + | |
29445 | +EXPORT_SYMBOL(gr_is_capable); | |
29446 | +EXPORT_SYMBOL(gr_is_capable_nolog); | |
29447 | +EXPORT_SYMBOL(gr_learn_resource); | |
29448 | +EXPORT_SYMBOL(gr_set_kernel_label); | |
29449 | +#ifdef CONFIG_SECURITY | |
29450 | +EXPORT_SYMBOL(gr_check_user_change); | |
29451 | +EXPORT_SYMBOL(gr_check_group_change); | |
29452 | +#endif | |
de855c5d AM |
29453 | diff -urNp linux-2.6.29.6/grsecurity/grsec_exec.c linux-2.6.29.6/grsecurity/grsec_exec.c |
29454 | --- linux-2.6.29.6/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500 | |
29455 | +++ linux-2.6.29.6/grsecurity/grsec_exec.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29456 | @@ -0,0 +1,89 @@ |
29457 | +#include <linux/kernel.h> | |
29458 | +#include <linux/sched.h> | |
29459 | +#include <linux/file.h> | |
29460 | +#include <linux/binfmts.h> | |
29461 | +#include <linux/smp_lock.h> | |
29462 | +#include <linux/fs.h> | |
29463 | +#include <linux/types.h> | |
29464 | +#include <linux/grdefs.h> | |
29465 | +#include <linux/grinternal.h> | |
29466 | +#include <linux/capability.h> | |
29467 | + | |
29468 | +#include <asm/uaccess.h> | |
29469 | + | |
29470 | +#ifdef CONFIG_GRKERNSEC_EXECLOG | |
29471 | +static char gr_exec_arg_buf[132]; | |
29472 | +static DECLARE_MUTEX(gr_exec_arg_sem); | |
29473 | +#endif | |
29474 | + | |
29475 | +int | |
29476 | +gr_handle_nproc(void) | |
29477 | +{ | |
29478 | +#ifdef CONFIG_GRKERNSEC_EXECVE | |
29479 | + const struct cred *cred = current_cred(); | |
29480 | + if (grsec_enable_execve && cred->user && | |
29481 | + (atomic_read(&cred->user->processes) > | |
29482 | + current->signal->rlim[RLIMIT_NPROC].rlim_cur) && | |
29483 | + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) { | |
29484 | + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG); | |
29485 | + return -EAGAIN; | |
29486 | + } | |
29487 | +#endif | |
29488 | + return 0; | |
29489 | +} | |
29490 | + | |
29491 | +void | |
29492 | +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv) | |
29493 | +{ | |
29494 | +#ifdef CONFIG_GRKERNSEC_EXECLOG | |
29495 | + char *grarg = gr_exec_arg_buf; | |
29496 | + unsigned int i, x, execlen = 0; | |
29497 | + char c; | |
29498 | + | |
29499 | + if (!((grsec_enable_execlog && grsec_enable_group && | |
29500 | + in_group_p(grsec_audit_gid)) | |
29501 | + || (grsec_enable_execlog && !grsec_enable_group))) | |
29502 | + return; | |
29503 | + | |
29504 | + down(&gr_exec_arg_sem); | |
29505 | + memset(grarg, 0, sizeof(gr_exec_arg_buf)); | |
29506 | + | |
29507 | + if (unlikely(argv == NULL)) | |
29508 | + goto log; | |
29509 | + | |
29510 | + for (i = 0; i < bprm->argc && execlen < 128; i++) { | |
29511 | + const char __user *p; | |
29512 | + unsigned int len; | |
29513 | + | |
29514 | + if (copy_from_user(&p, argv + i, sizeof(p))) | |
29515 | + goto log; | |
29516 | + if (!p) | |
29517 | + goto log; | |
29518 | + len = strnlen_user(p, 128 - execlen); | |
29519 | + if (len > 128 - execlen) | |
29520 | + len = 128 - execlen; | |
29521 | + else if (len > 0) | |
29522 | + len--; | |
29523 | + if (copy_from_user(grarg + execlen, p, len)) | |
29524 | + goto log; | |
29525 | + | |
29526 | + /* rewrite unprintable characters */ | |
29527 | + for (x = 0; x < len; x++) { | |
29528 | + c = *(grarg + execlen + x); | |
29529 | + if (c < 32 || c > 126) | |
29530 | + *(grarg + execlen + x) = ' '; | |
29531 | + } | |
29532 | + | |
29533 | + execlen += len; | |
29534 | + *(grarg + execlen) = ' '; | |
29535 | + *(grarg + execlen + 1) = '\0'; | |
29536 | + execlen++; | |
29537 | + } | |
29538 | + | |
29539 | + log: | |
29540 | + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry, | |
29541 | + bprm->file->f_path.mnt, grarg); | |
29542 | + up(&gr_exec_arg_sem); | |
29543 | +#endif | |
29544 | + return; | |
29545 | +} | |
de855c5d AM |
29546 | diff -urNp linux-2.6.29.6/grsecurity/grsec_fifo.c linux-2.6.29.6/grsecurity/grsec_fifo.c |
29547 | --- linux-2.6.29.6/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500 | |
29548 | +++ linux-2.6.29.6/grsecurity/grsec_fifo.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29549 | @@ -0,0 +1,24 @@ |
29550 | +#include <linux/kernel.h> | |
29551 | +#include <linux/sched.h> | |
29552 | +#include <linux/fs.h> | |
29553 | +#include <linux/file.h> | |
29554 | +#include <linux/grinternal.h> | |
29555 | + | |
29556 | +int | |
29557 | +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt, | |
29558 | + const struct dentry *dir, const int flag, const int acc_mode) | |
29559 | +{ | |
29560 | +#ifdef CONFIG_GRKERNSEC_FIFO | |
29561 | + const struct cred *cred = current_cred(); | |
29562 | + | |
29563 | + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) && | |
29564 | + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) && | |
29565 | + (dentry->d_inode->i_uid != dir->d_inode->i_uid) && | |
29566 | + (cred->fsuid != dentry->d_inode->i_uid)) { | |
29567 | + if (!generic_permission(dentry->d_inode, acc_mode, NULL)) | |
29568 | + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid); | |
29569 | + return -EACCES; | |
29570 | + } | |
29571 | +#endif | |
29572 | + return 0; | |
29573 | +} | |
de855c5d AM |
29574 | diff -urNp linux-2.6.29.6/grsecurity/grsec_fork.c linux-2.6.29.6/grsecurity/grsec_fork.c |
29575 | --- linux-2.6.29.6/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500 | |
29576 | +++ linux-2.6.29.6/grsecurity/grsec_fork.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29577 | @@ -0,0 +1,15 @@ |
29578 | +#include <linux/kernel.h> | |
29579 | +#include <linux/sched.h> | |
29580 | +#include <linux/grsecurity.h> | |
29581 | +#include <linux/grinternal.h> | |
29582 | +#include <linux/errno.h> | |
29583 | + | |
29584 | +void | |
29585 | +gr_log_forkfail(const int retval) | |
29586 | +{ | |
29587 | +#ifdef CONFIG_GRKERNSEC_FORKFAIL | |
29588 | + if (grsec_enable_forkfail && retval != -ERESTARTNOINTR) | |
29589 | + gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval); | |
29590 | +#endif | |
29591 | + return; | |
29592 | +} | |
de855c5d AM |
29593 | diff -urNp linux-2.6.29.6/grsecurity/grsec_init.c linux-2.6.29.6/grsecurity/grsec_init.c |
29594 | --- linux-2.6.29.6/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500 | |
29595 | +++ linux-2.6.29.6/grsecurity/grsec_init.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29596 | @@ -0,0 +1,230 @@ |
29597 | +#include <linux/kernel.h> | |
29598 | +#include <linux/sched.h> | |
29599 | +#include <linux/mm.h> | |
29600 | +#include <linux/smp_lock.h> | |
29601 | +#include <linux/gracl.h> | |
29602 | +#include <linux/slab.h> | |
29603 | +#include <linux/vmalloc.h> | |
29604 | +#include <linux/percpu.h> | |
29605 | + | |
29606 | +int grsec_enable_link; | |
29607 | +int grsec_enable_dmesg; | |
29608 | +int grsec_enable_fifo; | |
29609 | +int grsec_enable_execve; | |
29610 | +int grsec_enable_execlog; | |
29611 | +int grsec_enable_signal; | |
29612 | +int grsec_enable_forkfail; | |
29613 | +int grsec_enable_time; | |
29614 | +int grsec_enable_audit_textrel; | |
29615 | +int grsec_enable_group; | |
29616 | +int grsec_audit_gid; | |
29617 | +int grsec_enable_chdir; | |
29618 | +int grsec_enable_audit_ipc; | |
29619 | +int grsec_enable_mount; | |
29620 | +int grsec_enable_chroot_findtask; | |
29621 | +int grsec_enable_chroot_mount; | |
29622 | +int grsec_enable_chroot_shmat; | |
29623 | +int grsec_enable_chroot_fchdir; | |
29624 | +int grsec_enable_chroot_double; | |
29625 | +int grsec_enable_chroot_pivot; | |
29626 | +int grsec_enable_chroot_chdir; | |
29627 | +int grsec_enable_chroot_chmod; | |
29628 | +int grsec_enable_chroot_mknod; | |
29629 | +int grsec_enable_chroot_nice; | |
29630 | +int grsec_enable_chroot_execlog; | |
29631 | +int grsec_enable_chroot_caps; | |
29632 | +int grsec_enable_chroot_sysctl; | |
29633 | +int grsec_enable_chroot_unix; | |
29634 | +int grsec_enable_tpe; | |
29635 | +int grsec_tpe_gid; | |
29636 | +int grsec_enable_tpe_all; | |
29637 | +int grsec_enable_socket_all; | |
29638 | +int grsec_socket_all_gid; | |
29639 | +int grsec_enable_socket_client; | |
29640 | +int grsec_socket_client_gid; | |
29641 | +int grsec_enable_socket_server; | |
29642 | +int grsec_socket_server_gid; | |
29643 | +int grsec_resource_logging; | |
29644 | +int grsec_lock; | |
29645 | + | |
29646 | +DEFINE_SPINLOCK(grsec_alert_lock); | |
29647 | +unsigned long grsec_alert_wtime = 0; | |
29648 | +unsigned long grsec_alert_fyet = 0; | |
29649 | + | |
29650 | +DEFINE_SPINLOCK(grsec_audit_lock); | |
29651 | + | |
29652 | +DEFINE_RWLOCK(grsec_exec_file_lock); | |
29653 | + | |
29654 | +char *gr_shared_page[4]; | |
29655 | + | |
29656 | +char *gr_alert_log_fmt; | |
29657 | +char *gr_audit_log_fmt; | |
29658 | +char *gr_alert_log_buf; | |
29659 | +char *gr_audit_log_buf; | |
29660 | + | |
29661 | +extern struct gr_arg *gr_usermode; | |
29662 | +extern unsigned char *gr_system_salt; | |
29663 | +extern unsigned char *gr_system_sum; | |
29664 | + | |
29665 | +void | |
29666 | +grsecurity_init(void) | |
29667 | +{ | |
29668 | + int j; | |
29669 | + /* create the per-cpu shared pages */ | |
29670 | + | |
29671 | +#ifdef CONFIG_X86 | |
29672 | + memset((char *)(0x41a + PAGE_OFFSET), 0, 36); | |
29673 | +#endif | |
29674 | + | |
29675 | + for (j = 0; j < 4; j++) { | |
29676 | + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE); | |
29677 | + if (gr_shared_page[j] == NULL) { | |
29678 | + panic("Unable to allocate grsecurity shared page"); | |
29679 | + return; | |
29680 | + } | |
29681 | + } | |
29682 | + | |
29683 | + /* allocate log buffers */ | |
29684 | + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL); | |
29685 | + if (!gr_alert_log_fmt) { | |
29686 | + panic("Unable to allocate grsecurity alert log format buffer"); | |
29687 | + return; | |
29688 | + } | |
29689 | + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL); | |
29690 | + if (!gr_audit_log_fmt) { | |
29691 | + panic("Unable to allocate grsecurity audit log format buffer"); | |
29692 | + return; | |
29693 | + } | |
29694 | + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL); | |
29695 | + if (!gr_alert_log_buf) { | |
29696 | + panic("Unable to allocate grsecurity alert log buffer"); | |
29697 | + return; | |
29698 | + } | |
29699 | + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL); | |
29700 | + if (!gr_audit_log_buf) { | |
29701 | + panic("Unable to allocate grsecurity audit log buffer"); | |
29702 | + return; | |
29703 | + } | |
29704 | + | |
29705 | + /* allocate memory for authentication structure */ | |
29706 | + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL); | |
29707 | + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL); | |
29708 | + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL); | |
29709 | + | |
29710 | + if (!gr_usermode || !gr_system_salt || !gr_system_sum) { | |
29711 | + panic("Unable to allocate grsecurity authentication structure"); | |
29712 | + return; | |
29713 | + } | |
29714 | + | |
29715 | +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON) | |
29716 | +#ifndef CONFIG_GRKERNSEC_SYSCTL | |
29717 | + grsec_lock = 1; | |
29718 | +#endif | |
29719 | +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL | |
29720 | + grsec_enable_audit_textrel = 1; | |
29721 | +#endif | |
29722 | +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP | |
29723 | + grsec_enable_group = 1; | |
29724 | + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID; | |
29725 | +#endif | |
29726 | +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR | |
29727 | + grsec_enable_chdir = 1; | |
29728 | +#endif | |
29729 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29730 | + grsec_enable_audit_ipc = 1; | |
29731 | +#endif | |
29732 | +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT | |
29733 | + grsec_enable_mount = 1; | |
29734 | +#endif | |
29735 | +#ifdef CONFIG_GRKERNSEC_LINK | |
29736 | + grsec_enable_link = 1; | |
29737 | +#endif | |
29738 | +#ifdef CONFIG_GRKERNSEC_DMESG | |
29739 | + grsec_enable_dmesg = 1; | |
29740 | +#endif | |
29741 | +#ifdef CONFIG_GRKERNSEC_FIFO | |
29742 | + grsec_enable_fifo = 1; | |
29743 | +#endif | |
29744 | +#ifdef CONFIG_GRKERNSEC_EXECVE | |
29745 | + grsec_enable_execve = 1; | |
29746 | +#endif | |
29747 | +#ifdef CONFIG_GRKERNSEC_EXECLOG | |
29748 | + grsec_enable_execlog = 1; | |
29749 | +#endif | |
29750 | +#ifdef CONFIG_GRKERNSEC_SIGNAL | |
29751 | + grsec_enable_signal = 1; | |
29752 | +#endif | |
29753 | +#ifdef CONFIG_GRKERNSEC_FORKFAIL | |
29754 | + grsec_enable_forkfail = 1; | |
29755 | +#endif | |
29756 | +#ifdef CONFIG_GRKERNSEC_TIME | |
29757 | + grsec_enable_time = 1; | |
29758 | +#endif | |
29759 | +#ifdef CONFIG_GRKERNSEC_RESLOG | |
29760 | + grsec_resource_logging = 1; | |
29761 | +#endif | |
29762 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK | |
29763 | + grsec_enable_chroot_findtask = 1; | |
29764 | +#endif | |
29765 | +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX | |
29766 | + grsec_enable_chroot_unix = 1; | |
29767 | +#endif | |
29768 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT | |
29769 | + grsec_enable_chroot_mount = 1; | |
29770 | +#endif | |
29771 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR | |
29772 | + grsec_enable_chroot_fchdir = 1; | |
29773 | +#endif | |
29774 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT | |
29775 | + grsec_enable_chroot_shmat = 1; | |
29776 | +#endif | |
29777 | +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE | |
29778 | + grsec_enable_chroot_double = 1; | |
29779 | +#endif | |
29780 | +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT | |
29781 | + grsec_enable_chroot_pivot = 1; | |
29782 | +#endif | |
29783 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR | |
29784 | + grsec_enable_chroot_chdir = 1; | |
29785 | +#endif | |
29786 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD | |
29787 | + grsec_enable_chroot_chmod = 1; | |
29788 | +#endif | |
29789 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD | |
29790 | + grsec_enable_chroot_mknod = 1; | |
29791 | +#endif | |
29792 | +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE | |
29793 | + grsec_enable_chroot_nice = 1; | |
29794 | +#endif | |
29795 | +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG | |
29796 | + grsec_enable_chroot_execlog = 1; | |
29797 | +#endif | |
29798 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS | |
29799 | + grsec_enable_chroot_caps = 1; | |
29800 | +#endif | |
29801 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL | |
29802 | + grsec_enable_chroot_sysctl = 1; | |
29803 | +#endif | |
29804 | +#ifdef CONFIG_GRKERNSEC_TPE | |
29805 | + grsec_enable_tpe = 1; | |
29806 | + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID; | |
29807 | +#ifdef CONFIG_GRKERNSEC_TPE_ALL | |
29808 | + grsec_enable_tpe_all = 1; | |
29809 | +#endif | |
29810 | +#endif | |
29811 | +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL | |
29812 | + grsec_enable_socket_all = 1; | |
29813 | + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID; | |
29814 | +#endif | |
29815 | +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT | |
29816 | + grsec_enable_socket_client = 1; | |
29817 | + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID; | |
29818 | +#endif | |
29819 | +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER | |
29820 | + grsec_enable_socket_server = 1; | |
29821 | + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID; | |
29822 | +#endif | |
29823 | +#endif | |
29824 | + | |
29825 | + return; | |
29826 | +} | |
de855c5d AM |
29827 | diff -urNp linux-2.6.29.6/grsecurity/grsec_ipc.c linux-2.6.29.6/grsecurity/grsec_ipc.c |
29828 | --- linux-2.6.29.6/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500 | |
29829 | +++ linux-2.6.29.6/grsecurity/grsec_ipc.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29830 | @@ -0,0 +1,81 @@ |
29831 | +#include <linux/kernel.h> | |
29832 | +#include <linux/sched.h> | |
29833 | +#include <linux/types.h> | |
29834 | +#include <linux/ipc.h> | |
29835 | +#include <linux/grsecurity.h> | |
29836 | +#include <linux/grinternal.h> | |
29837 | + | |
29838 | +void | |
29839 | +gr_log_msgget(const int ret, const int msgflg) | |
29840 | +{ | |
29841 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29842 | + if (((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29843 | + grsec_enable_audit_ipc) || (grsec_enable_audit_ipc && | |
29844 | + !grsec_enable_group)) && (ret >= 0) | |
29845 | + && (msgflg & IPC_CREAT)) | |
29846 | + gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG); | |
29847 | +#endif | |
29848 | + return; | |
29849 | +} | |
29850 | + | |
29851 | +void | |
29852 | +gr_log_msgrm(const uid_t uid, const uid_t cuid) | |
29853 | +{ | |
29854 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29855 | + if ((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29856 | + grsec_enable_audit_ipc) || | |
29857 | + (grsec_enable_audit_ipc && !grsec_enable_group)) | |
29858 | + gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid); | |
29859 | +#endif | |
29860 | + return; | |
29861 | +} | |
29862 | + | |
29863 | +void | |
29864 | +gr_log_semget(const int err, const int semflg) | |
29865 | +{ | |
29866 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29867 | + if (((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29868 | + grsec_enable_audit_ipc) || (grsec_enable_audit_ipc && | |
29869 | + !grsec_enable_group)) && (err >= 0) | |
29870 | + && (semflg & IPC_CREAT)) | |
29871 | + gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG); | |
29872 | +#endif | |
29873 | + return; | |
29874 | +} | |
29875 | + | |
29876 | +void | |
29877 | +gr_log_semrm(const uid_t uid, const uid_t cuid) | |
29878 | +{ | |
29879 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29880 | + if ((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29881 | + grsec_enable_audit_ipc) || | |
29882 | + (grsec_enable_audit_ipc && !grsec_enable_group)) | |
29883 | + gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid); | |
29884 | +#endif | |
29885 | + return; | |
29886 | +} | |
29887 | + | |
29888 | +void | |
29889 | +gr_log_shmget(const int err, const int shmflg, const size_t size) | |
29890 | +{ | |
29891 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29892 | + if (((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29893 | + grsec_enable_audit_ipc) || (grsec_enable_audit_ipc && | |
29894 | + !grsec_enable_group)) && (err >= 0) | |
29895 | + && (shmflg & IPC_CREAT)) | |
29896 | + gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size); | |
29897 | +#endif | |
29898 | + return; | |
29899 | +} | |
29900 | + | |
29901 | +void | |
29902 | +gr_log_shmrm(const uid_t uid, const uid_t cuid) | |
29903 | +{ | |
29904 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
29905 | + if ((grsec_enable_group && in_group_p(grsec_audit_gid) && | |
29906 | + grsec_enable_audit_ipc) || | |
29907 | + (grsec_enable_audit_ipc && !grsec_enable_group)) | |
29908 | + gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid); | |
29909 | +#endif | |
29910 | + return; | |
29911 | +} | |
de855c5d AM |
29912 | diff -urNp linux-2.6.29.6/grsecurity/grsec_link.c linux-2.6.29.6/grsecurity/grsec_link.c |
29913 | --- linux-2.6.29.6/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500 | |
29914 | +++ linux-2.6.29.6/grsecurity/grsec_link.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
29915 | @@ -0,0 +1,43 @@ |
29916 | +#include <linux/kernel.h> | |
29917 | +#include <linux/sched.h> | |
29918 | +#include <linux/fs.h> | |
29919 | +#include <linux/file.h> | |
29920 | +#include <linux/grinternal.h> | |
29921 | + | |
29922 | +int | |
29923 | +gr_handle_follow_link(const struct inode *parent, | |
29924 | + const struct inode *inode, | |
29925 | + const struct dentry *dentry, const struct vfsmount *mnt) | |
29926 | +{ | |
29927 | +#ifdef CONFIG_GRKERNSEC_LINK | |
29928 | + const struct cred *cred = current_cred(); | |
29929 | + | |
29930 | + if (grsec_enable_link && S_ISLNK(inode->i_mode) && | |
29931 | + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) && | |
29932 | + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) { | |
29933 | + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid); | |
29934 | + return -EACCES; | |
29935 | + } | |
29936 | +#endif | |
29937 | + return 0; | |
29938 | +} | |
29939 | + | |
29940 | +int | |
29941 | +gr_handle_hardlink(const struct dentry *dentry, | |
29942 | + const struct vfsmount *mnt, | |
29943 | + struct inode *inode, const int mode, const char *to) | |
29944 | +{ | |
29945 | +#ifdef CONFIG_GRKERNSEC_LINK | |
29946 | + const struct cred *cred = current_cred(); | |
29947 | + | |
29948 | + if (grsec_enable_link && cred->fsuid != inode->i_uid && | |
29949 | + (!S_ISREG(mode) || (mode & S_ISUID) || | |
29950 | + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) || | |
29951 | + (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) && | |
29952 | + !capable(CAP_FOWNER) && cred->uid) { | |
29953 | + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to); | |
29954 | + return -EPERM; | |
29955 | + } | |
29956 | +#endif | |
29957 | + return 0; | |
29958 | +} | |
de855c5d AM |
29959 | diff -urNp linux-2.6.29.6/grsecurity/grsec_log.c linux-2.6.29.6/grsecurity/grsec_log.c |
29960 | --- linux-2.6.29.6/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500 | |
29961 | +++ linux-2.6.29.6/grsecurity/grsec_log.c 2009-07-09 22:13:39.000000000 -0400 | |
29962 | @@ -0,0 +1,288 @@ | |
2380c486 JR |
29963 | +#include <linux/kernel.h> |
29964 | +#include <linux/sched.h> | |
29965 | +#include <linux/file.h> | |
29966 | +#include <linux/tty.h> | |
29967 | +#include <linux/fs.h> | |
29968 | +#include <linux/grinternal.h> | |
29969 | + | |
29970 | +#define BEGIN_LOCKS(x) \ | |
29971 | + read_lock(&tasklist_lock); \ | |
29972 | + read_lock(&grsec_exec_file_lock); \ | |
29973 | + if (x != GR_DO_AUDIT) \ | |
29974 | + spin_lock(&grsec_alert_lock); \ | |
29975 | + else \ | |
29976 | + spin_lock(&grsec_audit_lock) | |
29977 | + | |
29978 | +#define END_LOCKS(x) \ | |
29979 | + if (x != GR_DO_AUDIT) \ | |
29980 | + spin_unlock(&grsec_alert_lock); \ | |
29981 | + else \ | |
29982 | + spin_unlock(&grsec_audit_lock); \ | |
29983 | + read_unlock(&grsec_exec_file_lock); \ | |
29984 | + read_unlock(&tasklist_lock); \ | |
29985 | + if (x == GR_DONT_AUDIT) \ | |
29986 | + gr_handle_alertkill(current) | |
29987 | + | |
29988 | +enum { | |
29989 | + FLOODING, | |
29990 | + NO_FLOODING | |
29991 | +}; | |
29992 | + | |
29993 | +extern char *gr_alert_log_fmt; | |
29994 | +extern char *gr_audit_log_fmt; | |
29995 | +extern char *gr_alert_log_buf; | |
29996 | +extern char *gr_audit_log_buf; | |
29997 | + | |
29998 | +static int gr_log_start(int audit) | |
29999 | +{ | |
30000 | + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT; | |
30001 | + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt; | |
30002 | + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf; | |
30003 | + | |
30004 | + if (audit == GR_DO_AUDIT) | |
30005 | + goto set_fmt; | |
30006 | + | |
30007 | + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) { | |
30008 | + grsec_alert_wtime = jiffies; | |
30009 | + grsec_alert_fyet = 0; | |
30010 | + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) { | |
30011 | + grsec_alert_fyet++; | |
30012 | + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) { | |
30013 | + grsec_alert_wtime = jiffies; | |
30014 | + grsec_alert_fyet++; | |
30015 | + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME); | |
30016 | + return FLOODING; | |
30017 | + } else return FLOODING; | |
30018 | + | |
30019 | +set_fmt: | |
30020 | + memset(buf, 0, PAGE_SIZE); | |
30021 | + if (current->signal->curr_ip && gr_acl_is_enabled()) { | |
30022 | + sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) "); | |
30023 | + snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename); | |
30024 | + } else if (current->signal->curr_ip) { | |
30025 | + sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: "); | |
30026 | + snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip)); | |
30027 | + } else if (gr_acl_is_enabled()) { | |
30028 | + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) "); | |
30029 | + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename); | |
30030 | + } else { | |
30031 | + sprintf(fmt, "%s%s", loglevel, "grsec: "); | |
30032 | + strcpy(buf, fmt); | |
30033 | + } | |
30034 | + | |
30035 | + return NO_FLOODING; | |
30036 | +} | |
30037 | + | |
30038 | +static void gr_log_middle(int audit, const char *msg, va_list ap) | |
de855c5d AM |
30039 | + __attribute__ ((format (printf, 2, 0))); |
30040 | + | |
30041 | +static void gr_log_middle(int audit, const char *msg, va_list ap) | |
2380c486 JR |
30042 | +{ |
30043 | + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf; | |
30044 | + unsigned int len = strlen(buf); | |
30045 | + | |
30046 | + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap); | |
30047 | + | |
30048 | + return; | |
30049 | +} | |
30050 | + | |
30051 | +static void gr_log_middle_varargs(int audit, const char *msg, ...) | |
de855c5d AM |
30052 | + __attribute__ ((format (printf, 2, 3))); |
30053 | + | |
30054 | +static void gr_log_middle_varargs(int audit, const char *msg, ...) | |
2380c486 JR |
30055 | +{ |
30056 | + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf; | |
30057 | + unsigned int len = strlen(buf); | |
30058 | + va_list ap; | |
30059 | + | |
30060 | + va_start(ap, msg); | |
30061 | + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap); | |
30062 | + va_end(ap); | |
30063 | + | |
30064 | + return; | |
30065 | +} | |
30066 | + | |
30067 | +static void gr_log_end(int audit) | |
30068 | +{ | |
30069 | + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf; | |
30070 | + unsigned int len = strlen(buf); | |
30071 | + | |
30072 | + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->parent))); | |
30073 | + printk("%s\n", buf); | |
30074 | + | |
30075 | + return; | |
30076 | +} | |
30077 | + | |
30078 | +void gr_log_varargs(int audit, const char *msg, int argtypes, ...) | |
30079 | +{ | |
30080 | + int logtype; | |
30081 | + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied"; | |
30082 | + char *str1, *str2, *str3; | |
30083 | + int num1, num2; | |
30084 | + unsigned long ulong1, ulong2; | |
30085 | + struct dentry *dentry; | |
30086 | + struct vfsmount *mnt; | |
30087 | + struct file *file; | |
30088 | + struct task_struct *task; | |
30089 | + const struct cred *cred, *pcred; | |
30090 | + va_list ap; | |
30091 | + | |
30092 | + BEGIN_LOCKS(audit); | |
30093 | + logtype = gr_log_start(audit); | |
30094 | + if (logtype == FLOODING) { | |
30095 | + END_LOCKS(audit); | |
30096 | + return; | |
30097 | + } | |
30098 | + va_start(ap, argtypes); | |
30099 | + switch (argtypes) { | |
30100 | + case GR_TTYSNIFF: | |
30101 | + task = va_arg(ap, struct task_struct *); | |
30102 | + gr_log_middle_varargs(audit, msg, NIPQUAD(task->signal->curr_ip), gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid); | |
30103 | + break; | |
30104 | + case GR_SYSCTL_HIDDEN: | |
30105 | + str1 = va_arg(ap, char *); | |
30106 | + gr_log_middle_varargs(audit, msg, result, str1); | |
30107 | + break; | |
30108 | + case GR_RBAC: | |
30109 | + dentry = va_arg(ap, struct dentry *); | |
30110 | + mnt = va_arg(ap, struct vfsmount *); | |
30111 | + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt)); | |
30112 | + break; | |
30113 | + case GR_RBAC_STR: | |
30114 | + dentry = va_arg(ap, struct dentry *); | |
30115 | + mnt = va_arg(ap, struct vfsmount *); | |
30116 | + str1 = va_arg(ap, char *); | |
30117 | + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1); | |
30118 | + break; | |
30119 | + case GR_STR_RBAC: | |
30120 | + str1 = va_arg(ap, char *); | |
30121 | + dentry = va_arg(ap, struct dentry *); | |
30122 | + mnt = va_arg(ap, struct vfsmount *); | |
30123 | + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt)); | |
30124 | + break; | |
30125 | + case GR_RBAC_MODE2: | |
30126 | + dentry = va_arg(ap, struct dentry *); | |
30127 | + mnt = va_arg(ap, struct vfsmount *); | |
30128 | + str1 = va_arg(ap, char *); | |
30129 | + str2 = va_arg(ap, char *); | |
30130 | + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2); | |
30131 | + break; | |
30132 | + case GR_RBAC_MODE3: | |
30133 | + dentry = va_arg(ap, struct dentry *); | |
30134 | + mnt = va_arg(ap, struct vfsmount *); | |
30135 | + str1 = va_arg(ap, char *); | |
30136 | + str2 = va_arg(ap, char *); | |
30137 | + str3 = va_arg(ap, char *); | |
30138 | + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3); | |
30139 | + break; | |
30140 | + case GR_FILENAME: | |
30141 | + dentry = va_arg(ap, struct dentry *); | |
30142 | + mnt = va_arg(ap, struct vfsmount *); | |
30143 | + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt)); | |
30144 | + break; | |
30145 | + case GR_STR_FILENAME: | |
30146 | + str1 = va_arg(ap, char *); | |
30147 | + dentry = va_arg(ap, struct dentry *); | |
30148 | + mnt = va_arg(ap, struct vfsmount *); | |
30149 | + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt)); | |
30150 | + break; | |
30151 | + case GR_FILENAME_STR: | |
30152 | + dentry = va_arg(ap, struct dentry *); | |
30153 | + mnt = va_arg(ap, struct vfsmount *); | |
30154 | + str1 = va_arg(ap, char *); | |
30155 | + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1); | |
30156 | + break; | |
30157 | + case GR_FILENAME_TWO_INT: | |
30158 | + dentry = va_arg(ap, struct dentry *); | |
30159 | + mnt = va_arg(ap, struct vfsmount *); | |
30160 | + num1 = va_arg(ap, int); | |
30161 | + num2 = va_arg(ap, int); | |
30162 | + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2); | |
30163 | + break; | |
30164 | + case GR_FILENAME_TWO_INT_STR: | |
30165 | + dentry = va_arg(ap, struct dentry *); | |
30166 | + mnt = va_arg(ap, struct vfsmount *); | |
30167 | + num1 = va_arg(ap, int); | |
30168 | + num2 = va_arg(ap, int); | |
30169 | + str1 = va_arg(ap, char *); | |
30170 | + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1); | |
30171 | + break; | |
30172 | + case GR_TEXTREL: | |
30173 | + file = va_arg(ap, struct file *); | |
30174 | + ulong1 = va_arg(ap, unsigned long); | |
30175 | + ulong2 = va_arg(ap, unsigned long); | |
30176 | + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2); | |
30177 | + break; | |
30178 | + case GR_PTRACE: | |
30179 | + task = va_arg(ap, struct task_struct *); | |
30180 | + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task->pid); | |
30181 | + break; | |
30182 | + case GR_RESOURCE: | |
30183 | + task = va_arg(ap, struct task_struct *); | |
30184 | + cred = __task_cred(task); | |
30185 | + pcred = __task_cred(task->parent); | |
30186 | + ulong1 = va_arg(ap, unsigned long); | |
30187 | + str1 = va_arg(ap, char *); | |
30188 | + ulong2 = va_arg(ap, unsigned long); | |
30189 | + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid); | |
30190 | + break; | |
30191 | + case GR_CAP: | |
30192 | + task = va_arg(ap, struct task_struct *); | |
30193 | + cred = __task_cred(task); | |
30194 | + pcred = __task_cred(task->parent); | |
30195 | + str1 = va_arg(ap, char *); | |
30196 | + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid); | |
30197 | + break; | |
30198 | + case GR_SIG: | |
30199 | + task = va_arg(ap, struct task_struct *); | |
30200 | + cred = __task_cred(task); | |
30201 | + pcred = __task_cred(task->parent); | |
30202 | + num1 = va_arg(ap, int); | |
30203 | + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid); | |
30204 | + break; | |
30205 | + case GR_CRASH1: | |
30206 | + task = va_arg(ap, struct task_struct *); | |
30207 | + cred = __task_cred(task); | |
30208 | + pcred = __task_cred(task->parent); | |
30209 | + ulong1 = va_arg(ap, unsigned long); | |
30210 | + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1); | |
30211 | + break; | |
30212 | + case GR_CRASH2: | |
30213 | + task = va_arg(ap, struct task_struct *); | |
30214 | + cred = __task_cred(task); | |
30215 | + pcred = __task_cred(task->parent); | |
30216 | + ulong1 = va_arg(ap, unsigned long); | |
30217 | + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1); | |
30218 | + break; | |
30219 | + case GR_PSACCT: | |
30220 | + { | |
30221 | + unsigned int wday, cday; | |
30222 | + __u8 whr, chr; | |
30223 | + __u8 wmin, cmin; | |
30224 | + __u8 wsec, csec; | |
30225 | + char cur_tty[64] = { 0 }; | |
30226 | + char parent_tty[64] = { 0 }; | |
30227 | + | |
30228 | + task = va_arg(ap, struct task_struct *); | |
30229 | + wday = va_arg(ap, unsigned int); | |
30230 | + cday = va_arg(ap, unsigned int); | |
30231 | + whr = va_arg(ap, int); | |
30232 | + chr = va_arg(ap, int); | |
30233 | + wmin = va_arg(ap, int); | |
30234 | + cmin = va_arg(ap, int); | |
30235 | + wsec = va_arg(ap, int); | |
30236 | + csec = va_arg(ap, int); | |
30237 | + ulong1 = va_arg(ap, unsigned long); | |
30238 | + cred = __task_cred(task); | |
30239 | + pcred = __task_cred(task->parent); | |
30240 | + | |
30241 | + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, NIPQUAD(task->signal->curr_ip), tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, NIPQUAD(task->parent->signal->curr_ip), tty_name(task->parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid); | |
30242 | + } | |
30243 | + break; | |
30244 | + default: | |
30245 | + gr_log_middle(audit, msg, ap); | |
30246 | + } | |
30247 | + va_end(ap); | |
30248 | + gr_log_end(audit); | |
30249 | + END_LOCKS(audit); | |
30250 | +} | |
de855c5d AM |
30251 | diff -urNp linux-2.6.29.6/grsecurity/grsec_mem.c linux-2.6.29.6/grsecurity/grsec_mem.c |
30252 | --- linux-2.6.29.6/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500 | |
30253 | +++ linux-2.6.29.6/grsecurity/grsec_mem.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
30254 | @@ -0,0 +1,71 @@ |
30255 | +#include <linux/kernel.h> | |
30256 | +#include <linux/sched.h> | |
30257 | +#include <linux/mm.h> | |
30258 | +#include <linux/mman.h> | |
30259 | +#include <linux/grinternal.h> | |
30260 | + | |
30261 | +void | |
30262 | +gr_handle_ioperm(void) | |
30263 | +{ | |
30264 | + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG); | |
30265 | + return; | |
30266 | +} | |
30267 | + | |
30268 | +void | |
30269 | +gr_handle_iopl(void) | |
30270 | +{ | |
30271 | + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG); | |
30272 | + return; | |
30273 | +} | |
30274 | + | |
30275 | +void | |
30276 | +gr_handle_mem_write(void) | |
30277 | +{ | |
30278 | + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG); | |
30279 | + return; | |
30280 | +} | |
30281 | + | |
30282 | +void | |
30283 | +gr_handle_kmem_write(void) | |
30284 | +{ | |
30285 | + gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG); | |
30286 | + return; | |
30287 | +} | |
30288 | + | |
30289 | +void | |
30290 | +gr_handle_open_port(void) | |
30291 | +{ | |
30292 | + gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG); | |
30293 | + return; | |
30294 | +} | |
30295 | + | |
30296 | +int | |
30297 | +gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma) | |
30298 | +{ | |
30299 | + unsigned long start, end; | |
30300 | + | |
30301 | + start = offset; | |
30302 | + end = start + vma->vm_end - vma->vm_start; | |
30303 | + | |
30304 | + if (start > end) { | |
30305 | + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG); | |
30306 | + return -EPERM; | |
30307 | + } | |
30308 | + | |
30309 | + /* allowed ranges : ISA I/O BIOS */ | |
30310 | + if ((start >= __pa(high_memory)) | |
30311 | +#ifdef CONFIG_X86 | |
30312 | + || (start >= 0x000a0000 && end <= 0x00100000) | |
30313 | + || (start >= 0x00000000 && end <= 0x00001000) | |
30314 | +#endif | |
30315 | + ) | |
30316 | + return 0; | |
30317 | + | |
30318 | + if (vma->vm_flags & VM_WRITE) { | |
30319 | + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG); | |
30320 | + return -EPERM; | |
30321 | + } else | |
30322 | + vma->vm_flags &= ~VM_MAYWRITE; | |
30323 | + | |
30324 | + return 0; | |
30325 | +} | |
de855c5d AM |
30326 | diff -urNp linux-2.6.29.6/grsecurity/grsec_mount.c linux-2.6.29.6/grsecurity/grsec_mount.c |
30327 | --- linux-2.6.29.6/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500 | |
30328 | +++ linux-2.6.29.6/grsecurity/grsec_mount.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
30329 | @@ -0,0 +1,34 @@ |
30330 | +#include <linux/kernel.h> | |
30331 | +#include <linux/sched.h> | |
30332 | +#include <linux/grsecurity.h> | |
30333 | +#include <linux/grinternal.h> | |
30334 | + | |
30335 | +void | |
30336 | +gr_log_remount(const char *devname, const int retval) | |
30337 | +{ | |
30338 | +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT | |
30339 | + if (grsec_enable_mount && (retval >= 0)) | |
30340 | + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none"); | |
30341 | +#endif | |
30342 | + return; | |
30343 | +} | |
30344 | + | |
30345 | +void | |
30346 | +gr_log_unmount(const char *devname, const int retval) | |
30347 | +{ | |
30348 | +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT | |
30349 | + if (grsec_enable_mount && (retval >= 0)) | |
30350 | + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none"); | |
30351 | +#endif | |
30352 | + return; | |
30353 | +} | |
30354 | + | |
30355 | +void | |
30356 | +gr_log_mount(const char *from, const char *to, const int retval) | |
30357 | +{ | |
30358 | +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT | |
30359 | + if (grsec_enable_mount && (retval >= 0)) | |
30360 | + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to); | |
30361 | +#endif | |
30362 | + return; | |
30363 | +} | |
de855c5d AM |
30364 | diff -urNp linux-2.6.29.6/grsecurity/grsec_sig.c linux-2.6.29.6/grsecurity/grsec_sig.c |
30365 | --- linux-2.6.29.6/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500 | |
30366 | +++ linux-2.6.29.6/grsecurity/grsec_sig.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
30367 | @@ -0,0 +1,58 @@ |
30368 | +#include <linux/kernel.h> | |
30369 | +#include <linux/sched.h> | |
30370 | +#include <linux/delay.h> | |
30371 | +#include <linux/grsecurity.h> | |
30372 | +#include <linux/grinternal.h> | |
30373 | + | |
30374 | +void | |
30375 | +gr_log_signal(const int sig, const struct task_struct *t) | |
30376 | +{ | |
30377 | +#ifdef CONFIG_GRKERNSEC_SIGNAL | |
30378 | + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) || | |
30379 | + (sig == SIGABRT) || (sig == SIGBUS))) { | |
30380 | + if (t->pid == current->pid) { | |
30381 | + gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig); | |
30382 | + } else { | |
30383 | + gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig); | |
30384 | + } | |
30385 | + } | |
30386 | +#endif | |
30387 | + return; | |
30388 | +} | |
30389 | + | |
30390 | +int | |
30391 | +gr_handle_signal(const struct task_struct *p, const int sig) | |
30392 | +{ | |
30393 | +#ifdef CONFIG_GRKERNSEC | |
30394 | + if (current->pid > 1 && gr_check_protected_task(p)) { | |
30395 | + gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig); | |
30396 | + return -EPERM; | |
30397 | + } else if (gr_pid_is_chrooted((struct task_struct *)p)) { | |
30398 | + return -EPERM; | |
30399 | + } | |
30400 | +#endif | |
30401 | + return 0; | |
30402 | +} | |
30403 | + | |
30404 | +void gr_handle_brute_attach(struct task_struct *p) | |
30405 | +{ | |
30406 | +#ifdef CONFIG_GRKERNSEC_BRUTE | |
30407 | + read_lock(&tasklist_lock); | |
30408 | + read_lock(&grsec_exec_file_lock); | |
30409 | + if (p->parent && p->parent->exec_file == p->exec_file) | |
30410 | + p->parent->brute = 1; | |
30411 | + read_unlock(&grsec_exec_file_lock); | |
30412 | + read_unlock(&tasklist_lock); | |
30413 | +#endif | |
30414 | + return; | |
30415 | +} | |
30416 | + | |
30417 | +void gr_handle_brute_check(void) | |
30418 | +{ | |
30419 | +#ifdef CONFIG_GRKERNSEC_BRUTE | |
30420 | + if (current->brute) | |
30421 | + msleep(30 * 1000); | |
30422 | +#endif | |
30423 | + return; | |
30424 | +} | |
30425 | + | |
de855c5d AM |
30426 | diff -urNp linux-2.6.29.6/grsecurity/grsec_sock.c linux-2.6.29.6/grsecurity/grsec_sock.c |
30427 | --- linux-2.6.29.6/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500 | |
30428 | +++ linux-2.6.29.6/grsecurity/grsec_sock.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
30429 | @@ -0,0 +1,269 @@ |
30430 | +#include <linux/kernel.h> | |
30431 | +#include <linux/module.h> | |
30432 | +#include <linux/sched.h> | |
30433 | +#include <linux/file.h> | |
30434 | +#include <linux/net.h> | |
30435 | +#include <linux/in.h> | |
30436 | +#include <linux/ip.h> | |
30437 | +#include <net/sock.h> | |
30438 | +#include <net/inet_sock.h> | |
30439 | +#include <linux/grsecurity.h> | |
30440 | +#include <linux/grinternal.h> | |
30441 | +#include <linux/gracl.h> | |
30442 | + | |
30443 | +kernel_cap_t gr_cap_rtnetlink(struct sock *sock); | |
30444 | +EXPORT_SYMBOL(gr_cap_rtnetlink); | |
30445 | + | |
30446 | +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb); | |
30447 | +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr); | |
30448 | + | |
30449 | +EXPORT_SYMBOL(gr_search_udp_recvmsg); | |
30450 | +EXPORT_SYMBOL(gr_search_udp_sendmsg); | |
30451 | + | |
30452 | +#ifdef CONFIG_UNIX_MODULE | |
30453 | +EXPORT_SYMBOL(gr_acl_handle_unix); | |
30454 | +EXPORT_SYMBOL(gr_acl_handle_mknod); | |
30455 | +EXPORT_SYMBOL(gr_handle_chroot_unix); | |
30456 | +EXPORT_SYMBOL(gr_handle_create); | |
30457 | +#endif | |
30458 | + | |
30459 | +#ifdef CONFIG_GRKERNSEC | |
30460 | +#define gr_conn_table_size 32749 | |
30461 | +struct conn_table_entry { | |
30462 | + struct conn_table_entry *next; | |
30463 | + struct signal_struct *sig; | |
30464 | +}; | |
30465 | + | |
30466 | +struct conn_table_entry *gr_conn_table[gr_conn_table_size]; | |
30467 | +DEFINE_SPINLOCK(gr_conn_table_lock); | |
30468 | + | |
30469 | +extern const char * gr_socktype_to_name(unsigned char type); | |
30470 | +extern const char * gr_proto_to_name(unsigned char proto); | |
30471 | + | |
30472 | +static __inline__ int | |
30473 | +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size) | |
30474 | +{ | |
30475 | + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size); | |
30476 | +} | |
30477 | + | |
30478 | +static __inline__ int | |
30479 | +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr, | |
30480 | + __u16 sport, __u16 dport) | |
30481 | +{ | |
30482 | + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr && | |
30483 | + sig->gr_sport == sport && sig->gr_dport == dport)) | |
30484 | + return 1; | |
30485 | + else | |
30486 | + return 0; | |
30487 | +} | |
30488 | + | |
30489 | +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent) | |
30490 | +{ | |
30491 | + struct conn_table_entry **match; | |
30492 | + unsigned int index; | |
30493 | + | |
30494 | + index = conn_hash(sig->gr_saddr, sig->gr_daddr, | |
30495 | + sig->gr_sport, sig->gr_dport, | |
30496 | + gr_conn_table_size); | |
30497 | + | |
30498 | + newent->sig = sig; | |
30499 | + | |
30500 | + match = &gr_conn_table[index]; | |
30501 | + newent->next = *match; | |
30502 | + *match = newent; | |
30503 | + | |
30504 | + return; | |
30505 | +} | |
30506 | + | |
30507 | +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig) | |
30508 | +{ | |
30509 | + struct conn_table_entry *match, *last = NULL; | |
30510 | + unsigned int index; | |
30511 | + | |
30512 | + index = conn_hash(sig->gr_saddr, sig->gr_daddr, | |
30513 | + sig->gr_sport, sig->gr_dport, | |
30514 | + gr_conn_table_size); | |
30515 | + | |
30516 | + match = gr_conn_table[index]; | |
30517 | + while (match && !conn_match(match->sig, | |
30518 | + sig->gr_saddr, sig->gr_daddr, sig->gr_sport, | |
30519 | + sig->gr_dport)) { | |
30520 | + last = match; | |
30521 | + match = match->next; | |
30522 | + } | |
30523 | + | |
30524 | + if (match) { | |
30525 | + if (last) | |
30526 | + last->next = match->next; | |
30527 | + else | |
30528 | + gr_conn_table[index] = NULL; | |
30529 | + kfree(match); | |
30530 | + } | |
30531 | + | |
30532 | + return; | |
30533 | +} | |
30534 | + | |
30535 | +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr, | |
30536 | + __u16 sport, __u16 dport) | |
30537 | +{ | |
30538 | + struct conn_table_entry *match; | |
30539 | + unsigned int index; | |
30540 | + | |
30541 | + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size); | |
30542 | + | |
30543 | + match = gr_conn_table[index]; | |
30544 | + while (match && !conn_match(match->sig, saddr, daddr, sport, dport)) | |
30545 | + match = match->next; | |
30546 | + | |
30547 | + if (match) | |
30548 | + return match->sig; | |
30549 | + else | |
30550 | + return NULL; | |
30551 | +} | |
30552 | + | |
30553 | +#endif | |
30554 | + | |
30555 | +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet) | |
30556 | +{ | |
30557 | +#ifdef CONFIG_GRKERNSEC | |
30558 | + struct signal_struct *sig = task->signal; | |
30559 | + struct conn_table_entry *newent; | |
30560 | + | |
30561 | + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC); | |
30562 | + if (newent == NULL) | |
30563 | + return; | |
30564 | + /* no bh lock needed since we are called with bh disabled */ | |
30565 | + spin_lock(&gr_conn_table_lock); | |
30566 | + gr_del_task_from_ip_table_nolock(sig); | |
30567 | + sig->gr_saddr = inet->rcv_saddr; | |
30568 | + sig->gr_daddr = inet->daddr; | |
30569 | + sig->gr_sport = inet->sport; | |
30570 | + sig->gr_dport = inet->dport; | |
30571 | + gr_add_to_task_ip_table_nolock(sig, newent); | |
30572 | + spin_unlock(&gr_conn_table_lock); | |
30573 | +#endif | |
30574 | + return; | |
30575 | +} | |
30576 | + | |
30577 | +void gr_del_task_from_ip_table(struct task_struct *task) | |
30578 | +{ | |
30579 | +#ifdef CONFIG_GRKERNSEC | |
30580 | + spin_lock_bh(&gr_conn_table_lock); | |
30581 | + gr_del_task_from_ip_table_nolock(task->signal); | |
30582 | + spin_unlock_bh(&gr_conn_table_lock); | |
30583 | +#endif | |
30584 | + return; | |
30585 | +} | |
30586 | + | |
30587 | +void | |
30588 | +gr_attach_curr_ip(const struct sock *sk) | |
30589 | +{ | |
30590 | +#ifdef CONFIG_GRKERNSEC | |
30591 | + struct signal_struct *p, *set; | |
30592 | + const struct inet_sock *inet = inet_sk(sk); | |
30593 | + | |
30594 | + if (unlikely(sk->sk_protocol != IPPROTO_TCP)) | |
30595 | + return; | |
30596 | + | |
30597 | + set = current->signal; | |
30598 | + | |
30599 | + spin_lock_bh(&gr_conn_table_lock); | |
30600 | + p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr, | |
30601 | + inet->dport, inet->sport); | |
30602 | + if (unlikely(p != NULL)) { | |
30603 | + set->curr_ip = p->curr_ip; | |
30604 | + set->used_accept = 1; | |
30605 | + gr_del_task_from_ip_table_nolock(p); | |
30606 | + spin_unlock_bh(&gr_conn_table_lock); | |
30607 | + return; | |
30608 | + } | |
30609 | + spin_unlock_bh(&gr_conn_table_lock); | |
30610 | + | |
30611 | + set->curr_ip = inet->daddr; | |
30612 | + set->used_accept = 1; | |
30613 | +#endif | |
30614 | + return; | |
30615 | +} | |
30616 | + | |
30617 | +int | |
30618 | +gr_handle_sock_all(const int family, const int type, const int protocol) | |
30619 | +{ | |
30620 | +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL | |
30621 | + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) && | |
30622 | + (family != AF_UNIX) && (family != AF_LOCAL)) { | |
30623 | + gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol)); | |
30624 | + return -EACCES; | |
30625 | + } | |
30626 | +#endif | |
30627 | + return 0; | |
30628 | +} | |
30629 | + | |
30630 | +int | |
30631 | +gr_handle_sock_server(const struct sockaddr *sck) | |
30632 | +{ | |
30633 | +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER | |
30634 | + if (grsec_enable_socket_server && | |
30635 | + in_group_p(grsec_socket_server_gid) && | |
30636 | + sck && (sck->sa_family != AF_UNIX) && | |
30637 | + (sck->sa_family != AF_LOCAL)) { | |
30638 | + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG); | |
30639 | + return -EACCES; | |
30640 | + } | |
30641 | +#endif | |
30642 | + return 0; | |
30643 | +} | |
30644 | + | |
30645 | +int | |
30646 | +gr_handle_sock_server_other(const struct sock *sck) | |
30647 | +{ | |
30648 | +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER | |
30649 | + if (grsec_enable_socket_server && | |
30650 | + in_group_p(grsec_socket_server_gid) && | |
30651 | + sck && (sck->sk_family != AF_UNIX) && | |
30652 | + (sck->sk_family != AF_LOCAL)) { | |
30653 | + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG); | |
30654 | + return -EACCES; | |
30655 | + } | |
30656 | +#endif | |
30657 | + return 0; | |
30658 | +} | |
30659 | + | |
30660 | +int | |
30661 | +gr_handle_sock_client(const struct sockaddr *sck) | |
30662 | +{ | |
30663 | +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT | |
30664 | + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) && | |
30665 | + sck && (sck->sa_family != AF_UNIX) && | |
30666 | + (sck->sa_family != AF_LOCAL)) { | |
30667 | + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG); | |
30668 | + return -EACCES; | |
30669 | + } | |
30670 | +#endif | |
30671 | + return 0; | |
30672 | +} | |
30673 | + | |
30674 | +kernel_cap_t | |
30675 | +gr_cap_rtnetlink(struct sock *sock) | |
30676 | +{ | |
30677 | +#ifdef CONFIG_GRKERNSEC | |
30678 | + if (!gr_acl_is_enabled()) | |
30679 | + return current_cap(); | |
30680 | + else if (sock->sk_protocol == NETLINK_ISCSI && | |
30681 | + cap_raised(current_cap(), CAP_SYS_ADMIN) && | |
30682 | + gr_is_capable(CAP_SYS_ADMIN)) | |
30683 | + return current_cap(); | |
30684 | + else if (sock->sk_protocol == NETLINK_AUDIT && | |
30685 | + cap_raised(current_cap(), CAP_AUDIT_WRITE) && | |
30686 | + gr_is_capable(CAP_AUDIT_WRITE) && | |
30687 | + cap_raised(current_cap(), CAP_AUDIT_CONTROL) && | |
30688 | + gr_is_capable(CAP_AUDIT_CONTROL)) | |
30689 | + return current_cap(); | |
30690 | + else if (cap_raised(current_cap(), CAP_NET_ADMIN) && | |
30691 | + gr_is_capable(CAP_NET_ADMIN)) | |
30692 | + return current_cap(); | |
30693 | + else | |
30694 | + return __cap_empty_set; | |
30695 | +#else | |
30696 | + return current_cap(); | |
30697 | +#endif | |
30698 | +} | |
de855c5d AM |
30699 | diff -urNp linux-2.6.29.6/grsecurity/grsec_sysctl.c linux-2.6.29.6/grsecurity/grsec_sysctl.c |
30700 | --- linux-2.6.29.6/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500 | |
30701 | +++ linux-2.6.29.6/grsecurity/grsec_sysctl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
30702 | @@ -0,0 +1,435 @@ |
30703 | +#include <linux/kernel.h> | |
30704 | +#include <linux/sched.h> | |
30705 | +#include <linux/sysctl.h> | |
30706 | +#include <linux/grsecurity.h> | |
30707 | +#include <linux/grinternal.h> | |
30708 | + | |
30709 | +#ifdef CONFIG_GRKERNSEC_MODSTOP | |
30710 | +int grsec_modstop; | |
30711 | +#endif | |
30712 | + | |
30713 | +int | |
30714 | +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op) | |
30715 | +{ | |
30716 | +#ifdef CONFIG_GRKERNSEC_SYSCTL | |
30717 | + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) { | |
30718 | + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name); | |
30719 | + return -EACCES; | |
30720 | + } | |
30721 | +#endif | |
30722 | +#ifdef CONFIG_GRKERNSEC_MODSTOP | |
30723 | + if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") && | |
30724 | + grsec_modstop && (op & MAY_WRITE)) { | |
30725 | + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name); | |
30726 | + return -EACCES; | |
30727 | + } | |
30728 | +#endif | |
30729 | + return 0; | |
30730 | +} | |
30731 | + | |
30732 | +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP) | |
30733 | +ctl_table grsecurity_table[] = { | |
30734 | +#ifdef CONFIG_GRKERNSEC_SYSCTL | |
30735 | +#ifdef CONFIG_GRKERNSEC_LINK | |
30736 | + { | |
30737 | + .ctl_name = CTL_UNNUMBERED, | |
30738 | + .procname = "linking_restrictions", | |
30739 | + .data = &grsec_enable_link, | |
30740 | + .maxlen = sizeof(int), | |
30741 | + .mode = 0600, | |
30742 | + .proc_handler = &proc_dointvec, | |
30743 | + }, | |
30744 | +#endif | |
30745 | +#ifdef CONFIG_GRKERNSEC_FIFO | |
30746 | + { | |
30747 | + .ctl_name = CTL_UNNUMBERED, | |
30748 | + .procname = "fifo_restrictions", | |
30749 | + .data = &grsec_enable_fifo, | |
30750 | + .maxlen = sizeof(int), | |
30751 | + .mode = 0600, | |
30752 | + .proc_handler = &proc_dointvec, | |
30753 | + }, | |
30754 | +#endif | |
30755 | +#ifdef CONFIG_GRKERNSEC_EXECVE | |
30756 | + { | |
30757 | + .ctl_name = CTL_UNNUMBERED, | |
30758 | + .procname = "execve_limiting", | |
30759 | + .data = &grsec_enable_execve, | |
30760 | + .maxlen = sizeof(int), | |
30761 | + .mode = 0600, | |
30762 | + .proc_handler = &proc_dointvec, | |
30763 | + }, | |
30764 | +#endif | |
30765 | +#ifdef CONFIG_GRKERNSEC_EXECLOG | |
30766 | + { | |
30767 | + .ctl_name = CTL_UNNUMBERED, | |
30768 | + .procname = "exec_logging", | |
30769 | + .data = &grsec_enable_execlog, | |
30770 | + .maxlen = sizeof(int), | |
30771 | + .mode = 0600, | |
30772 | + .proc_handler = &proc_dointvec, | |
30773 | + }, | |
30774 | +#endif | |
30775 | +#ifdef CONFIG_GRKERNSEC_SIGNAL | |
30776 | + { | |
30777 | + .ctl_name = CTL_UNNUMBERED, | |
30778 | + .procname = "signal_logging", | |
30779 | + .data = &grsec_enable_signal, | |
30780 | + .maxlen = sizeof(int), | |
30781 | + .mode = 0600, | |
30782 | + .proc_handler = &proc_dointvec, | |
30783 | + }, | |
30784 | +#endif | |
30785 | +#ifdef CONFIG_GRKERNSEC_FORKFAIL | |
30786 | + { | |
30787 | + .ctl_name = CTL_UNNUMBERED, | |
30788 | + .procname = "forkfail_logging", | |
30789 | + .data = &grsec_enable_forkfail, | |
30790 | + .maxlen = sizeof(int), | |
30791 | + .mode = 0600, | |
30792 | + .proc_handler = &proc_dointvec, | |
30793 | + }, | |
30794 | +#endif | |
30795 | +#ifdef CONFIG_GRKERNSEC_TIME | |
30796 | + { | |
30797 | + .ctl_name = CTL_UNNUMBERED, | |
30798 | + .procname = "timechange_logging", | |
30799 | + .data = &grsec_enable_time, | |
30800 | + .maxlen = sizeof(int), | |
30801 | + .mode = 0600, | |
30802 | + .proc_handler = &proc_dointvec, | |
30803 | + }, | |
30804 | +#endif | |
30805 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT | |
30806 | + { | |
30807 | + .ctl_name = CTL_UNNUMBERED, | |
30808 | + .procname = "chroot_deny_shmat", | |
30809 | + .data = &grsec_enable_chroot_shmat, | |
30810 | + .maxlen = sizeof(int), | |
30811 | + .mode = 0600, | |
30812 | + .proc_handler = &proc_dointvec, | |
30813 | + }, | |
30814 | +#endif | |
30815 | +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX | |
30816 | + { | |
30817 | + .ctl_name = CTL_UNNUMBERED, | |
30818 | + .procname = "chroot_deny_unix", | |
30819 | + .data = &grsec_enable_chroot_unix, | |
30820 | + .maxlen = sizeof(int), | |
30821 | + .mode = 0600, | |
30822 | + .proc_handler = &proc_dointvec, | |
30823 | + }, | |
30824 | +#endif | |
30825 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT | |
30826 | + { | |
30827 | + .ctl_name = CTL_UNNUMBERED, | |
30828 | + .procname = "chroot_deny_mount", | |
30829 | + .data = &grsec_enable_chroot_mount, | |
30830 | + .maxlen = sizeof(int), | |
30831 | + .mode = 0600, | |
30832 | + .proc_handler = &proc_dointvec, | |
30833 | + }, | |
30834 | +#endif | |
30835 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR | |
30836 | + { | |
30837 | + .ctl_name = CTL_UNNUMBERED, | |
30838 | + .procname = "chroot_deny_fchdir", | |
30839 | + .data = &grsec_enable_chroot_fchdir, | |
30840 | + .maxlen = sizeof(int), | |
30841 | + .mode = 0600, | |
30842 | + .proc_handler = &proc_dointvec, | |
30843 | + }, | |
30844 | +#endif | |
30845 | +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE | |
30846 | + { | |
30847 | + .ctl_name = CTL_UNNUMBERED, | |
30848 | + .procname = "chroot_deny_chroot", | |
30849 | + .data = &grsec_enable_chroot_double, | |
30850 | + .maxlen = sizeof(int), | |
30851 | + .mode = 0600, | |
30852 | + .proc_handler = &proc_dointvec, | |
30853 | + }, | |
30854 | +#endif | |
30855 | +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT | |
30856 | + { | |
30857 | + .ctl_name = CTL_UNNUMBERED, | |
30858 | + .procname = "chroot_deny_pivot", | |
30859 | + .data = &grsec_enable_chroot_pivot, | |
30860 | + .maxlen = sizeof(int), | |
30861 | + .mode = 0600, | |
30862 | + .proc_handler = &proc_dointvec, | |
30863 | + }, | |
30864 | +#endif | |
30865 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR | |
30866 | + { | |
30867 | + .ctl_name = CTL_UNNUMBERED, | |
30868 | + .procname = "chroot_enforce_chdir", | |
30869 | + .data = &grsec_enable_chroot_chdir, | |
30870 | + .maxlen = sizeof(int), | |
30871 | + .mode = 0600, | |
30872 | + .proc_handler = &proc_dointvec, | |
30873 | + }, | |
30874 | +#endif | |
30875 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD | |
30876 | + { | |
30877 | + .ctl_name = CTL_UNNUMBERED, | |
30878 | + .procname = "chroot_deny_chmod", | |
30879 | + .data = &grsec_enable_chroot_chmod, | |
30880 | + .maxlen = sizeof(int), | |
30881 | + .mode = 0600, | |
30882 | + .proc_handler = &proc_dointvec, | |
30883 | + }, | |
30884 | +#endif | |
30885 | +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD | |
30886 | + { | |
30887 | + .ctl_name = CTL_UNNUMBERED, | |
30888 | + .procname = "chroot_deny_mknod", | |
30889 | + .data = &grsec_enable_chroot_mknod, | |
30890 | + .maxlen = sizeof(int), | |
30891 | + .mode = 0600, | |
30892 | + .proc_handler = &proc_dointvec, | |
30893 | + }, | |
30894 | +#endif | |
30895 | +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE | |
30896 | + { | |
30897 | + .ctl_name = CTL_UNNUMBERED, | |
30898 | + .procname = "chroot_restrict_nice", | |
30899 | + .data = &grsec_enable_chroot_nice, | |
30900 | + .maxlen = sizeof(int), | |
30901 | + .mode = 0600, | |
30902 | + .proc_handler = &proc_dointvec, | |
30903 | + }, | |
30904 | +#endif | |
30905 | +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG | |
30906 | + { | |
30907 | + .ctl_name = CTL_UNNUMBERED, | |
30908 | + .procname = "chroot_execlog", | |
30909 | + .data = &grsec_enable_chroot_execlog, | |
30910 | + .maxlen = sizeof(int), | |
30911 | + .mode = 0600, | |
30912 | + .proc_handler = &proc_dointvec, | |
30913 | + }, | |
30914 | +#endif | |
30915 | +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS | |
30916 | + { | |
30917 | + .ctl_name = CTL_UNNUMBERED, | |
30918 | + .procname = "chroot_caps", | |
30919 | + .data = &grsec_enable_chroot_caps, | |
30920 | + .maxlen = sizeof(int), | |
30921 | + .mode = 0600, | |
30922 | + .proc_handler = &proc_dointvec, | |
30923 | + }, | |
30924 | +#endif | |
30925 | +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL | |
30926 | + { | |
30927 | + .ctl_name = CTL_UNNUMBERED, | |
30928 | + .procname = "chroot_deny_sysctl", | |
30929 | + .data = &grsec_enable_chroot_sysctl, | |
30930 | + .maxlen = sizeof(int), | |
30931 | + .mode = 0600, | |
30932 | + .proc_handler = &proc_dointvec, | |
30933 | + }, | |
30934 | +#endif | |
30935 | +#ifdef CONFIG_GRKERNSEC_TPE | |
30936 | + { | |
30937 | + .ctl_name = CTL_UNNUMBERED, | |
30938 | + .procname = "tpe", | |
30939 | + .data = &grsec_enable_tpe, | |
30940 | + .maxlen = sizeof(int), | |
30941 | + .mode = 0600, | |
30942 | + .proc_handler = &proc_dointvec, | |
30943 | + }, | |
30944 | + { | |
30945 | + .ctl_name = CTL_UNNUMBERED, | |
30946 | + .procname = "tpe_gid", | |
30947 | + .data = &grsec_tpe_gid, | |
30948 | + .maxlen = sizeof(int), | |
30949 | + .mode = 0600, | |
30950 | + .proc_handler = &proc_dointvec, | |
30951 | + }, | |
30952 | +#endif | |
30953 | +#ifdef CONFIG_GRKERNSEC_TPE_ALL | |
30954 | + { | |
30955 | + .ctl_name = CTL_UNNUMBERED, | |
30956 | + .procname = "tpe_restrict_all", | |
30957 | + .data = &grsec_enable_tpe_all, | |
30958 | + .maxlen = sizeof(int), | |
30959 | + .mode = 0600, | |
30960 | + .proc_handler = &proc_dointvec, | |
30961 | + }, | |
30962 | +#endif | |
30963 | +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL | |
30964 | + { | |
30965 | + .ctl_name = CTL_UNNUMBERED, | |
30966 | + .procname = "socket_all", | |
30967 | + .data = &grsec_enable_socket_all, | |
30968 | + .maxlen = sizeof(int), | |
30969 | + .mode = 0600, | |
30970 | + .proc_handler = &proc_dointvec, | |
30971 | + }, | |
30972 | + { | |
30973 | + .ctl_name = CTL_UNNUMBERED, | |
30974 | + .procname = "socket_all_gid", | |
30975 | + .data = &grsec_socket_all_gid, | |
30976 | + .maxlen = sizeof(int), | |
30977 | + .mode = 0600, | |
30978 | + .proc_handler = &proc_dointvec, | |
30979 | + }, | |
30980 | +#endif | |
30981 | +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT | |
30982 | + { | |
30983 | + .ctl_name = CTL_UNNUMBERED, | |
30984 | + .procname = "socket_client", | |
30985 | + .data = &grsec_enable_socket_client, | |
30986 | + .maxlen = sizeof(int), | |
30987 | + .mode = 0600, | |
30988 | + .proc_handler = &proc_dointvec, | |
30989 | + }, | |
30990 | + { | |
30991 | + .ctl_name = CTL_UNNUMBERED, | |
30992 | + .procname = "socket_client_gid", | |
30993 | + .data = &grsec_socket_client_gid, | |
30994 | + .maxlen = sizeof(int), | |
30995 | + .mode = 0600, | |
30996 | + .proc_handler = &proc_dointvec, | |
30997 | + }, | |
30998 | +#endif | |
30999 | +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER | |
31000 | + { | |
31001 | + .ctl_name = CTL_UNNUMBERED, | |
31002 | + .procname = "socket_server", | |
31003 | + .data = &grsec_enable_socket_server, | |
31004 | + .maxlen = sizeof(int), | |
31005 | + .mode = 0600, | |
31006 | + .proc_handler = &proc_dointvec, | |
31007 | + }, | |
31008 | + { | |
31009 | + .ctl_name = CTL_UNNUMBERED, | |
31010 | + .procname = "socket_server_gid", | |
31011 | + .data = &grsec_socket_server_gid, | |
31012 | + .maxlen = sizeof(int), | |
31013 | + .mode = 0600, | |
31014 | + .proc_handler = &proc_dointvec, | |
31015 | + }, | |
31016 | +#endif | |
31017 | +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP | |
31018 | + { | |
31019 | + .ctl_name = CTL_UNNUMBERED, | |
31020 | + .procname = "audit_group", | |
31021 | + .data = &grsec_enable_group, | |
31022 | + .maxlen = sizeof(int), | |
31023 | + .mode = 0600, | |
31024 | + .proc_handler = &proc_dointvec, | |
31025 | + }, | |
31026 | + { | |
31027 | + .ctl_name = CTL_UNNUMBERED, | |
31028 | + .procname = "audit_gid", | |
31029 | + .data = &grsec_audit_gid, | |
31030 | + .maxlen = sizeof(int), | |
31031 | + .mode = 0600, | |
31032 | + .proc_handler = &proc_dointvec, | |
31033 | + }, | |
31034 | +#endif | |
31035 | +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR | |
31036 | + { | |
31037 | + .ctl_name = CTL_UNNUMBERED, | |
31038 | + .procname = "audit_chdir", | |
31039 | + .data = &grsec_enable_chdir, | |
31040 | + .maxlen = sizeof(int), | |
31041 | + .mode = 0600, | |
31042 | + .proc_handler = &proc_dointvec, | |
31043 | + }, | |
31044 | +#endif | |
31045 | +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT | |
31046 | + { | |
31047 | + .ctl_name = CTL_UNNUMBERED, | |
31048 | + .procname = "audit_mount", | |
31049 | + .data = &grsec_enable_mount, | |
31050 | + .maxlen = sizeof(int), | |
31051 | + .mode = 0600, | |
31052 | + .proc_handler = &proc_dointvec, | |
31053 | + }, | |
31054 | +#endif | |
31055 | +#ifdef CONFIG_GRKERNSEC_AUDIT_IPC | |
31056 | + { | |
31057 | + .ctl_name = CTL_UNNUMBERED, | |
31058 | + .procname = "audit_ipc", | |
31059 | + .data = &grsec_enable_audit_ipc, | |
31060 | + .maxlen = sizeof(int), | |
31061 | + .mode = 0600, | |
31062 | + .proc_handler = &proc_dointvec, | |
31063 | + }, | |
31064 | +#endif | |
31065 | +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL | |
31066 | + { | |
31067 | + .ctl_name = CTL_UNNUMBERED, | |
31068 | + .procname = "audit_textrel", | |
31069 | + .data = &grsec_enable_audit_textrel, | |
31070 | + .maxlen = sizeof(int), | |
31071 | + .mode = 0600, | |
31072 | + .proc_handler = &proc_dointvec, | |
31073 | + }, | |
31074 | +#endif | |
31075 | +#ifdef CONFIG_GRKERNSEC_DMESG | |
31076 | + { | |
31077 | + .ctl_name = CTL_UNNUMBERED, | |
31078 | + .procname = "dmesg", | |
31079 | + .data = &grsec_enable_dmesg, | |
31080 | + .maxlen = sizeof(int), | |
31081 | + .mode = 0600, | |
31082 | + .proc_handler = &proc_dointvec, | |
31083 | + }, | |
31084 | +#endif | |
31085 | +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK | |
31086 | + { | |
31087 | + .ctl_name = CTL_UNNUMBERED, | |
31088 | + .procname = "chroot_findtask", | |
31089 | + .data = &grsec_enable_chroot_findtask, | |
31090 | + .maxlen = sizeof(int), | |
31091 | + .mode = 0600, | |
31092 | + .proc_handler = &proc_dointvec, | |
31093 | + }, | |
31094 | +#endif | |
31095 | +#ifdef CONFIG_GRKERNSEC_RESLOG | |
31096 | + { | |
31097 | + .ctl_name = CTL_UNNUMBERED, | |
31098 | + .procname = "resource_logging", | |
31099 | + .data = &grsec_resource_logging, | |
31100 | + .maxlen = sizeof(int), | |
31101 | + .mode = 0600, | |
31102 | + .proc_handler = &proc_dointvec, | |
31103 | + }, | |
31104 | +#endif | |
31105 | + { | |
31106 | + .ctl_name = CTL_UNNUMBERED, | |
31107 | + .procname = "grsec_lock", | |
31108 | + .data = &grsec_lock, | |
31109 | + .maxlen = sizeof(int), | |
31110 | + .mode = 0600, | |
31111 | + .proc_handler = &proc_dointvec, | |
31112 | + }, | |
31113 | +#endif | |
31114 | +#ifdef CONFIG_GRKERNSEC_MODSTOP | |
31115 | + { | |
31116 | + .ctl_name = CTL_UNNUMBERED, | |
31117 | + .procname = "disable_modules", | |
31118 | + .data = &grsec_modstop, | |
31119 | + .maxlen = sizeof(int), | |
31120 | + .mode = 0600, | |
31121 | + .proc_handler = &proc_dointvec, | |
31122 | + }, | |
31123 | +#endif | |
31124 | + { .ctl_name = 0 } | |
31125 | +}; | |
31126 | +#endif | |
31127 | + | |
31128 | +int gr_check_modstop(void) | |
31129 | +{ | |
31130 | +#ifdef CONFIG_GRKERNSEC_MODSTOP | |
31131 | + if (grsec_modstop == 1) { | |
31132 | + gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG); | |
31133 | + return 1; | |
31134 | + } | |
31135 | +#endif | |
31136 | + return 0; | |
31137 | +} | |
de855c5d AM |
31138 | diff -urNp linux-2.6.29.6/grsecurity/grsec_textrel.c linux-2.6.29.6/grsecurity/grsec_textrel.c |
31139 | --- linux-2.6.29.6/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500 | |
31140 | +++ linux-2.6.29.6/grsecurity/grsec_textrel.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
31141 | @@ -0,0 +1,16 @@ |
31142 | +#include <linux/kernel.h> | |
31143 | +#include <linux/sched.h> | |
31144 | +#include <linux/mm.h> | |
31145 | +#include <linux/file.h> | |
31146 | +#include <linux/grinternal.h> | |
31147 | +#include <linux/grsecurity.h> | |
31148 | + | |
31149 | +void | |
31150 | +gr_log_textrel(struct vm_area_struct * vma) | |
31151 | +{ | |
31152 | +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL | |
31153 | + if (grsec_enable_audit_textrel) | |
31154 | + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff); | |
31155 | +#endif | |
31156 | + return; | |
31157 | +} | |
de855c5d AM |
31158 | diff -urNp linux-2.6.29.6/grsecurity/grsec_time.c linux-2.6.29.6/grsecurity/grsec_time.c |
31159 | --- linux-2.6.29.6/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500 | |
31160 | +++ linux-2.6.29.6/grsecurity/grsec_time.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
31161 | @@ -0,0 +1,13 @@ |
31162 | +#include <linux/kernel.h> | |
31163 | +#include <linux/sched.h> | |
31164 | +#include <linux/grinternal.h> | |
31165 | + | |
31166 | +void | |
31167 | +gr_log_timechange(void) | |
31168 | +{ | |
31169 | +#ifdef CONFIG_GRKERNSEC_TIME | |
31170 | + if (grsec_enable_time) | |
31171 | + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG); | |
31172 | +#endif | |
31173 | + return; | |
31174 | +} | |
de855c5d AM |
31175 | diff -urNp linux-2.6.29.6/grsecurity/grsec_tpe.c linux-2.6.29.6/grsecurity/grsec_tpe.c |
31176 | --- linux-2.6.29.6/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500 | |
31177 | +++ linux-2.6.29.6/grsecurity/grsec_tpe.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
31178 | @@ -0,0 +1,38 @@ |
31179 | +#include <linux/kernel.h> | |
31180 | +#include <linux/sched.h> | |
31181 | +#include <linux/file.h> | |
31182 | +#include <linux/fs.h> | |
31183 | +#include <linux/grinternal.h> | |
31184 | + | |
31185 | +extern int gr_acl_tpe_check(void); | |
31186 | + | |
31187 | +int | |
31188 | +gr_tpe_allow(const struct file *file) | |
31189 | +{ | |
31190 | +#ifdef CONFIG_GRKERNSEC | |
31191 | + struct inode *inode = file->f_path.dentry->d_parent->d_inode; | |
31192 | + const struct cred *cred = current_cred(); | |
31193 | + | |
31194 | + if (cred->uid && ((grsec_enable_tpe && | |
31195 | +#ifdef CONFIG_GRKERNSEC_TPE_INVERT | |
31196 | + !in_group_p(grsec_tpe_gid) | |
31197 | +#else | |
31198 | + in_group_p(grsec_tpe_gid) | |
31199 | +#endif | |
31200 | + ) || gr_acl_tpe_check()) && | |
31201 | + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) || | |
31202 | + (inode->i_mode & S_IWOTH))))) { | |
31203 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt); | |
31204 | + return 0; | |
31205 | + } | |
31206 | +#ifdef CONFIG_GRKERNSEC_TPE_ALL | |
31207 | + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all && | |
31208 | + ((inode->i_uid && (inode->i_uid != cred->uid)) || | |
31209 | + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) { | |
31210 | + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt); | |
31211 | + return 0; | |
31212 | + } | |
31213 | +#endif | |
31214 | +#endif | |
31215 | + return 1; | |
31216 | +} | |
de855c5d AM |
31217 | diff -urNp linux-2.6.29.6/grsecurity/grsum.c linux-2.6.29.6/grsecurity/grsum.c |
31218 | --- linux-2.6.29.6/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500 | |
31219 | +++ linux-2.6.29.6/grsecurity/grsum.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
31220 | @@ -0,0 +1,59 @@ |
31221 | +#include <linux/err.h> | |
31222 | +#include <linux/kernel.h> | |
31223 | +#include <linux/sched.h> | |
31224 | +#include <linux/mm.h> | |
31225 | +#include <linux/scatterlist.h> | |
31226 | +#include <linux/crypto.h> | |
31227 | +#include <linux/gracl.h> | |
31228 | + | |
31229 | + | |
31230 | +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE) | |
31231 | +#error "crypto and sha256 must be built into the kernel" | |
31232 | +#endif | |
31233 | + | |
31234 | +int | |
31235 | +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum) | |
31236 | +{ | |
31237 | + char *p; | |
31238 | + struct crypto_hash *tfm; | |
31239 | + struct hash_desc desc; | |
31240 | + struct scatterlist sg; | |
31241 | + unsigned char temp_sum[GR_SHA_LEN]; | |
31242 | + volatile int retval = 0; | |
31243 | + volatile int dummy = 0; | |
31244 | + unsigned int i; | |
31245 | + | |
31246 | + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC); | |
31247 | + if (IS_ERR(tfm)) { | |
31248 | + /* should never happen, since sha256 should be built in */ | |
31249 | + return 1; | |
31250 | + } | |
31251 | + | |
31252 | + desc.tfm = tfm; | |
31253 | + desc.flags = 0; | |
31254 | + | |
31255 | + crypto_hash_init(&desc); | |
31256 | + | |
31257 | + p = salt; | |
31258 | + sg_set_buf(&sg, p, GR_SALT_LEN); | |
31259 | + crypto_hash_update(&desc, &sg, sg.length); | |
31260 | + | |
31261 | + p = entry->pw; | |
31262 | + sg_set_buf(&sg, p, strlen(p)); | |
31263 | + | |
31264 | + crypto_hash_update(&desc, &sg, sg.length); | |
31265 | + | |
31266 | + crypto_hash_final(&desc, temp_sum); | |
31267 | + | |
31268 | + memset(entry->pw, 0, GR_PW_LEN); | |
31269 | + | |
31270 | + for (i = 0; i < GR_SHA_LEN; i++) | |
31271 | + if (sum[i] != temp_sum[i]) | |
31272 | + retval = 1; | |
31273 | + else | |
31274 | + dummy = 1; // waste a cycle | |
31275 | + | |
31276 | + crypto_free_hash(tfm); | |
31277 | + | |
31278 | + return retval; | |
31279 | +} | |
de855c5d AM |
31280 | diff -urNp linux-2.6.29.6/grsecurity/Kconfig linux-2.6.29.6/grsecurity/Kconfig |
31281 | --- linux-2.6.29.6/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500 | |
31282 | +++ linux-2.6.29.6/grsecurity/Kconfig 2009-07-10 07:22:18.000000000 -0400 | |
31283 | @@ -0,0 +1,896 @@ | |
2380c486 JR |
31284 | +# |
31285 | +# grecurity configuration | |
31286 | +# | |
31287 | + | |
31288 | +menu "Grsecurity" | |
31289 | + | |
31290 | +config GRKERNSEC | |
31291 | + bool "Grsecurity" | |
31292 | + select CRYPTO | |
31293 | + select CRYPTO_SHA256 | |
31294 | + select SECURITY | |
31295 | + select SECURITY_CAPABILITIES | |
31296 | + help | |
31297 | + If you say Y here, you will be able to configure many features | |
31298 | + that will enhance the security of your system. It is highly | |
31299 | + recommended that you say Y here and read through the help | |
31300 | + for each option so that you fully understand the features and | |
31301 | + can evaluate their usefulness for your machine. | |
31302 | + | |
31303 | +choice | |
31304 | + prompt "Security Level" | |
31305 | + depends on GRKERNSEC | |
31306 | + default GRKERNSEC_CUSTOM | |
31307 | + | |
31308 | +config GRKERNSEC_LOW | |
31309 | + bool "Low" | |
31310 | + select GRKERNSEC_LINK | |
31311 | + select GRKERNSEC_FIFO | |
31312 | + select GRKERNSEC_EXECVE | |
31313 | + select GRKERNSEC_RANDNET | |
31314 | + select GRKERNSEC_DMESG | |
31315 | + select GRKERNSEC_CHROOT | |
31316 | + select GRKERNSEC_CHROOT_CHDIR | |
31317 | + select GRKERNSEC_MODSTOP if (MODULES) | |
31318 | + | |
31319 | + help | |
31320 | + If you choose this option, several of the grsecurity options will | |
31321 | + be enabled that will give you greater protection against a number | |
31322 | + of attacks, while assuring that none of your software will have any | |
31323 | + conflicts with the additional security measures. If you run a lot | |
31324 | + of unusual software, or you are having problems with the higher | |
31325 | + security levels, you should say Y here. With this option, the | |
31326 | + following features are enabled: | |
31327 | + | |
31328 | + - Linking restrictions | |
31329 | + - FIFO restrictions | |
31330 | + - Enforcing RLIMIT_NPROC on execve | |
31331 | + - Restricted dmesg | |
31332 | + - Enforced chdir("/") on chroot | |
31333 | + - Runtime module disabling | |
31334 | + | |
31335 | +config GRKERNSEC_MEDIUM | |
31336 | + bool "Medium" | |
31337 | + select PAX | |
31338 | + select PAX_EI_PAX | |
31339 | + select PAX_PT_PAX_FLAGS | |
31340 | + select PAX_HAVE_ACL_FLAGS | |
31341 | + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR) | |
31342 | + select GRKERNSEC_CHROOT | |
31343 | + select GRKERNSEC_CHROOT_SYSCTL | |
31344 | + select GRKERNSEC_LINK | |
31345 | + select GRKERNSEC_FIFO | |
31346 | + select GRKERNSEC_EXECVE | |
31347 | + select GRKERNSEC_DMESG | |
31348 | + select GRKERNSEC_RANDNET | |
31349 | + select GRKERNSEC_FORKFAIL | |
31350 | + select GRKERNSEC_TIME | |
31351 | + select GRKERNSEC_SIGNAL | |
31352 | + select GRKERNSEC_CHROOT | |
31353 | + select GRKERNSEC_CHROOT_UNIX | |
31354 | + select GRKERNSEC_CHROOT_MOUNT | |
31355 | + select GRKERNSEC_CHROOT_PIVOT | |
31356 | + select GRKERNSEC_CHROOT_DOUBLE | |
31357 | + select GRKERNSEC_CHROOT_CHDIR | |
31358 | + select GRKERNSEC_CHROOT_MKNOD | |
31359 | + select GRKERNSEC_PROC | |
31360 | + select GRKERNSEC_PROC_USERGROUP | |
31361 | + select GRKERNSEC_MODSTOP if (MODULES) | |
31362 | + select PAX_RANDUSTACK | |
31363 | + select PAX_ASLR | |
31364 | + select PAX_RANDMMAP | |
31365 | + select PAX_REFCOUNT if (X86) | |
de855c5d AM |
31366 | + select PAX_USERCOPY if (X86_32 && (SLAB || SLUB)) |
31367 | + select PAX_SECURE_VSYSCALL if (X86_64) | |
2380c486 JR |
31368 | + |
31369 | + help | |
31370 | + If you say Y here, several features in addition to those included | |
31371 | + in the low additional security level will be enabled. These | |
31372 | + features provide even more security to your system, though in rare | |
31373 | + cases they may be incompatible with very old or poorly written | |
31374 | + software. If you enable this option, make sure that your auth | |
31375 | + service (identd) is running as gid 1001. With this option, | |
31376 | + the following features (in addition to those provided in the | |
31377 | + low additional security level) will be enabled: | |
31378 | + | |
31379 | + - Failed fork logging | |
31380 | + - Time change logging | |
31381 | + - Signal logging | |
31382 | + - Deny mounts in chroot | |
31383 | + - Deny double chrooting | |
31384 | + - Deny sysctl writes in chroot | |
31385 | + - Deny mknod in chroot | |
31386 | + - Deny access to abstract AF_UNIX sockets out of chroot | |
31387 | + - Deny pivot_root in chroot | |
31388 | + - Denied writes of /dev/kmem, /dev/mem, and /dev/port | |
31389 | + - /proc restrictions with special GID set to 10 (usually wheel) | |
31390 | + - Address Space Layout Randomization (ASLR) | |
31391 | + - Prevent exploitation of most refcount overflows | |
de855c5d | 31392 | + - Bounds checking of copying between the kernel and userland |
2380c486 JR |
31393 | + |
31394 | +config GRKERNSEC_HIGH | |
31395 | + bool "High" | |
31396 | + select GRKERNSEC_LINK | |
31397 | + select GRKERNSEC_FIFO | |
31398 | + select GRKERNSEC_EXECVE | |
31399 | + select GRKERNSEC_DMESG | |
31400 | + select GRKERNSEC_FORKFAIL | |
31401 | + select GRKERNSEC_TIME | |
31402 | + select GRKERNSEC_SIGNAL | |
31403 | + select GRKERNSEC_CHROOT | |
31404 | + select GRKERNSEC_CHROOT_SHMAT | |
31405 | + select GRKERNSEC_CHROOT_UNIX | |
31406 | + select GRKERNSEC_CHROOT_MOUNT | |
31407 | + select GRKERNSEC_CHROOT_FCHDIR | |
31408 | + select GRKERNSEC_CHROOT_PIVOT | |
31409 | + select GRKERNSEC_CHROOT_DOUBLE | |
31410 | + select GRKERNSEC_CHROOT_CHDIR | |
31411 | + select GRKERNSEC_CHROOT_MKNOD | |
31412 | + select GRKERNSEC_CHROOT_CAPS | |
31413 | + select GRKERNSEC_CHROOT_SYSCTL | |
31414 | + select GRKERNSEC_CHROOT_FINDTASK | |
31415 | + select GRKERNSEC_PROC | |
31416 | + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR) | |
31417 | + select GRKERNSEC_HIDESYM | |
31418 | + select GRKERNSEC_BRUTE | |
31419 | + select GRKERNSEC_PROC_USERGROUP | |
31420 | + select GRKERNSEC_KMEM | |
31421 | + select GRKERNSEC_RESLOG | |
31422 | + select GRKERNSEC_RANDNET | |
31423 | + select GRKERNSEC_PROC_ADD | |
31424 | + select GRKERNSEC_CHROOT_CHMOD | |
31425 | + select GRKERNSEC_CHROOT_NICE | |
31426 | + select GRKERNSEC_AUDIT_MOUNT | |
31427 | + select GRKERNSEC_MODSTOP if (MODULES) | |
31428 | + select PAX | |
31429 | + select PAX_RANDUSTACK | |
31430 | + select PAX_ASLR | |
31431 | + select PAX_RANDMMAP | |
31432 | + select PAX_NOEXEC | |
31433 | + select PAX_MPROTECT | |
31434 | + select PAX_EI_PAX | |
31435 | + select PAX_PT_PAX_FLAGS | |
31436 | + select PAX_HAVE_ACL_FLAGS | |
31437 | + select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK)) | |
31438 | + select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO) | |
31439 | + select PAX_RANDKSTACK if (X86_TSC && !X86_64) | |
31440 | + select PAX_SEGMEXEC if (X86 && !X86_64) | |
31441 | + select PAX_PAGEEXEC if (!X86) | |
31442 | + select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64) | |
31443 | + select PAX_DLRESOLVE if (SPARC32 || SPARC64) | |
31444 | + select PAX_SYSCALL if (PPC32) | |
31445 | + select PAX_EMUTRAMP if (PARISC) | |
31446 | + select PAX_EMUSIGRT if (PARISC) | |
31447 | + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC) | |
31448 | + select PAX_REFCOUNT if (X86) | |
de855c5d AM |
31449 | + select PAX_USERCOPY if (X86_32 && (SLAB || SLUB)) |
31450 | + select PAX_SECURE_VSYSCALL if (X86_64) | |
2380c486 JR |
31451 | + help |
31452 | + If you say Y here, many of the features of grsecurity will be | |
31453 | + enabled, which will protect you against many kinds of attacks | |
31454 | + against your system. The heightened security comes at a cost | |
31455 | + of an increased chance of incompatibilities with rare software | |
31456 | + on your machine. Since this security level enables PaX, you should | |
31457 | + view <http://pax.grsecurity.net> and read about the PaX | |
31458 | + project. While you are there, download chpax and run it on | |
31459 | + binaries that cause problems with PaX. Also remember that | |
31460 | + since the /proc restrictions are enabled, you must run your | |
31461 | + identd as gid 1001. This security level enables the following | |
31462 | + features in addition to those listed in the low and medium | |
31463 | + security levels: | |
31464 | + | |
31465 | + - Additional /proc restrictions | |
31466 | + - Chmod restrictions in chroot | |
31467 | + - No signals, ptrace, or viewing of processes outside of chroot | |
31468 | + - Capability restrictions in chroot | |
31469 | + - Deny fchdir out of chroot | |
31470 | + - Priority restrictions in chroot | |
31471 | + - Segmentation-based implementation of PaX | |
31472 | + - Mprotect restrictions | |
31473 | + - Removal of addresses from /proc/<pid>/[smaps|maps|stat] | |
31474 | + - Kernel stack randomization | |
31475 | + - Mount/unmount/remount logging | |
31476 | + - Kernel symbol hiding | |
31477 | + - Prevention of memory exhaustion-based exploits | |
31478 | +config GRKERNSEC_CUSTOM | |
31479 | + bool "Custom" | |
31480 | + help | |
31481 | + If you say Y here, you will be able to configure every grsecurity | |
31482 | + option, which allows you to enable many more features that aren't | |
31483 | + covered in the basic security levels. These additional features | |
31484 | + include TPE, socket restrictions, and the sysctl system for | |
31485 | + grsecurity. It is advised that you read through the help for | |
31486 | + each option to determine its usefulness in your situation. | |
31487 | + | |
31488 | +endchoice | |
31489 | + | |
31490 | +menu "Address Space Protection" | |
31491 | +depends on GRKERNSEC | |
31492 | + | |
31493 | +config GRKERNSEC_KMEM | |
31494 | + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port" | |
31495 | + help | |
31496 | + If you say Y here, /dev/kmem and /dev/mem won't be allowed to | |
31497 | + be written to via mmap or otherwise to modify the running kernel. | |
31498 | + /dev/port will also not be allowed to be opened. If you have module | |
31499 | + support disabled, enabling this will close up four ways that are | |
31500 | + currently used to insert malicious code into the running kernel. | |
31501 | + Even with all these features enabled, we still highly recommend that | |
31502 | + you use the RBAC system, as it is still possible for an attacker to | |
31503 | + modify the running kernel through privileged I/O granted by ioperm/iopl. | |
31504 | + If you are not using XFree86, you may be able to stop this additional | |
31505 | + case by enabling the 'Disable privileged I/O' option. Though nothing | |
31506 | + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem, | |
31507 | + but only to video memory, which is the only writing we allow in this | |
31508 | + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will | |
31509 | + not be allowed to mprotect it with PROT_WRITE later. | |
31510 | + It is highly recommended that you say Y here if you meet all the | |
31511 | + conditions above. | |
31512 | + | |
31513 | +config GRKERNSEC_IO | |
31514 | + bool "Disable privileged I/O" | |
31515 | + depends on X86 | |
31516 | + select RTC_CLASS | |
31517 | + select RTC_INTF_DEV | |
31518 | + select RTC_DRV_CMOS | |
31519 | + | |
31520 | + help | |
31521 | + If you say Y here, all ioperm and iopl calls will return an error. | |
31522 | + Ioperm and iopl can be used to modify the running kernel. | |
31523 | + Unfortunately, some programs need this access to operate properly, | |
31524 | + the most notable of which are XFree86 and hwclock. hwclock can be | |
31525 | + remedied by having RTC support in the kernel, so real-time | |
31526 | + clock support is enabled if this option is enabled, to ensure | |
31527 | + that hwclock operates correctly. XFree86 still will not | |
31528 | + operate correctly with this option enabled, so DO NOT CHOOSE Y | |
31529 | + IF YOU USE XFree86. If you use XFree86 and you still want to | |
31530 | + protect your kernel against modification, use the RBAC system. | |
31531 | + | |
31532 | +config GRKERNSEC_PROC_MEMMAP | |
31533 | + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]" | |
31534 | + depends on PAX_NOEXEC || PAX_ASLR | |
31535 | + help | |
31536 | + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will | |
31537 | + give no information about the addresses of its mappings if | |
31538 | + PaX features that rely on random addresses are enabled on the task. | |
31539 | + If you use PaX it is greatly recommended that you say Y here as it | |
31540 | + closes up a hole that makes the full ASLR useless for suid | |
31541 | + binaries. | |
31542 | + | |
31543 | +config GRKERNSEC_BRUTE | |
31544 | + bool "Deter exploit bruteforcing" | |
31545 | + help | |
31546 | + If you say Y here, attempts to bruteforce exploits against forking | |
31547 | + daemons such as apache or sshd will be deterred. When a child of a | |
31548 | + forking daemon is killed by PaX or crashes due to an illegal | |
31549 | + instruction, the parent process will be delayed 30 seconds upon every | |
31550 | + subsequent fork until the administrator is able to assess the | |
31551 | + situation and restart the daemon. It is recommended that you also | |
31552 | + enable signal logging in the auditing section so that logs are | |
31553 | + generated when a process performs an illegal instruction. | |
31554 | + | |
31555 | +config GRKERNSEC_MODSTOP | |
31556 | + bool "Runtime module disabling" | |
31557 | + depends on MODULES | |
31558 | + help | |
31559 | + If you say Y here, you will be able to disable the ability to (un)load | |
31560 | + modules at runtime. This feature is useful if you need the ability | |
31561 | + to load kernel modules at boot time, but do not want to allow an | |
31562 | + attacker to load a rootkit kernel module into the system, or to remove | |
31563 | + a loaded kernel module important to system functioning. You should | |
31564 | + enable the /dev/mem protection feature as well, since rootkits can be | |
31565 | + inserted into the kernel via other methods than kernel modules. Since | |
31566 | + an untrusted module could still be loaded by modifying init scripts and | |
31567 | + rebooting the system, it is also recommended that you enable the RBAC | |
31568 | + system. If you enable this option, a sysctl option with name | |
31569 | + "disable_modules" will be created. Setting this option to "1" disables | |
31570 | + module loading. After this option is set, no further writes to it are | |
31571 | + allowed until the system is rebooted. | |
31572 | + | |
31573 | +config GRKERNSEC_HIDESYM | |
31574 | + bool "Hide kernel symbols" | |
31575 | + help | |
31576 | + If you say Y here, getting information on loaded modules, and | |
31577 | + displaying all kernel symbols through a syscall will be restricted | |
31578 | + to users with CAP_SYS_MODULE. This option is only effective | |
31579 | + provided the following conditions are met: | |
31580 | + 1) The kernel using grsecurity is not precompiled by some distribution | |
31581 | + 2) You are using the RBAC system and hiding other files such as your | |
31582 | + kernel image and System.map | |
31583 | + 3) You have the additional /proc restrictions enabled, which removes | |
31584 | + /proc/kcore | |
31585 | + If the above conditions are met, this option will aid to provide a | |
31586 | + useful protection against local and remote kernel exploitation of | |
31587 | + overflows and arbitrary read/write vulnerabilities. | |
31588 | + | |
31589 | +endmenu | |
31590 | +menu "Role Based Access Control Options" | |
31591 | +depends on GRKERNSEC | |
31592 | + | |
de855c5d AM |
31593 | +config GRKERNSEC_NO_RBAC |
31594 | + bool "Disable RBAC system" | |
31595 | + help | |
31596 | + If you say Y here, the /dev/grsec device will be removed from the kernel, | |
31597 | + preventing the RBAC system from being enabled. You should only say Y | |
31598 | + here if you have no intention of using the RBAC system, so as to prevent | |
31599 | + an attacker with root access from misusing the RBAC system to hide files | |
31600 | + and processes when loadable module support and /dev/[k]mem have been | |
31601 | + locked down. | |
31602 | + | |
2380c486 JR |
31603 | +config GRKERNSEC_ACL_HIDEKERN |
31604 | + bool "Hide kernel processes" | |
31605 | + help | |
31606 | + If you say Y here, all kernel threads will be hidden to all | |
31607 | + processes but those whose subject has the "view hidden processes" | |
31608 | + flag. | |
31609 | + | |
31610 | +config GRKERNSEC_ACL_MAXTRIES | |
31611 | + int "Maximum tries before password lockout" | |
31612 | + default 3 | |
31613 | + help | |
31614 | + This option enforces the maximum number of times a user can attempt | |
31615 | + to authorize themselves with the grsecurity RBAC system before being | |
31616 | + denied the ability to attempt authorization again for a specified time. | |
31617 | + The lower the number, the harder it will be to brute-force a password. | |
31618 | + | |
31619 | +config GRKERNSEC_ACL_TIMEOUT | |
31620 | + int "Time to wait after max password tries, in seconds" | |
31621 | + default 30 | |
31622 | + help | |
31623 | + This option specifies the time the user must wait after attempting to | |
31624 | + authorize to the RBAC system with the maximum number of invalid | |
31625 | + passwords. The higher the number, the harder it will be to brute-force | |
31626 | + a password. | |
31627 | + | |
31628 | +endmenu | |
31629 | +menu "Filesystem Protections" | |
31630 | +depends on GRKERNSEC | |
31631 | + | |
31632 | +config GRKERNSEC_PROC | |
31633 | + bool "Proc restrictions" | |
31634 | + help | |
31635 | + If you say Y here, the permissions of the /proc filesystem | |
31636 | + will be altered to enhance system security and privacy. You MUST | |
31637 | + choose either a user only restriction or a user and group restriction. | |
31638 | + Depending upon the option you choose, you can either restrict users to | |
31639 | + see only the processes they themselves run, or choose a group that can | |
31640 | + view all processes and files normally restricted to root if you choose | |
31641 | + the "restrict to user only" option. NOTE: If you're running identd as | |
31642 | + a non-root user, you will have to run it as the group you specify here. | |
31643 | + | |
31644 | +config GRKERNSEC_PROC_USER | |
31645 | + bool "Restrict /proc to user only" | |
31646 | + depends on GRKERNSEC_PROC | |
31647 | + help | |
31648 | + If you say Y here, non-root users will only be able to view their own | |
31649 | + processes, and restricts them from viewing network-related information, | |
31650 | + and viewing kernel symbol and module information. | |
31651 | + | |
31652 | +config GRKERNSEC_PROC_USERGROUP | |
31653 | + bool "Allow special group" | |
31654 | + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER | |
31655 | + help | |
31656 | + If you say Y here, you will be able to select a group that will be | |
31657 | + able to view all processes, network-related information, and | |
31658 | + kernel and symbol information. This option is useful if you want | |
31659 | + to run identd as a non-root user. | |
31660 | + | |
31661 | +config GRKERNSEC_PROC_GID | |
31662 | + int "GID for special group" | |
31663 | + depends on GRKERNSEC_PROC_USERGROUP | |
31664 | + default 1001 | |
31665 | + | |
31666 | +config GRKERNSEC_PROC_ADD | |
31667 | + bool "Additional restrictions" | |
31668 | + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP | |
31669 | + help | |
31670 | + If you say Y here, additional restrictions will be placed on | |
31671 | + /proc that keep normal users from viewing device information and | |
31672 | + slabinfo information that could be useful for exploits. | |
31673 | + | |
31674 | +config GRKERNSEC_LINK | |
31675 | + bool "Linking restrictions" | |
31676 | + help | |
31677 | + If you say Y here, /tmp race exploits will be prevented, since users | |
31678 | + will no longer be able to follow symlinks owned by other users in | |
31679 | + world-writable +t directories (i.e. /tmp), unless the owner of the | |
31680 | + symlink is the owner of the directory. users will also not be | |
31681 | + able to hardlink to files they do not own. If the sysctl option is | |
31682 | + enabled, a sysctl option with name "linking_restrictions" is created. | |
31683 | + | |
31684 | +config GRKERNSEC_FIFO | |
31685 | + bool "FIFO restrictions" | |
31686 | + help | |
31687 | + If you say Y here, users will not be able to write to FIFOs they don't | |
31688 | + own in world-writable +t directories (i.e. /tmp), unless the owner of | |
31689 | + the FIFO is the same owner of the directory it's held in. If the sysctl | |
31690 | + option is enabled, a sysctl option with name "fifo_restrictions" is | |
31691 | + created. | |
31692 | + | |
31693 | +config GRKERNSEC_CHROOT | |
31694 | + bool "Chroot jail restrictions" | |
31695 | + help | |
31696 | + If you say Y here, you will be able to choose several options that will | |
31697 | + make breaking out of a chrooted jail much more difficult. If you | |
31698 | + encounter no software incompatibilities with the following options, it | |
31699 | + is recommended that you enable each one. | |
31700 | + | |
31701 | +config GRKERNSEC_CHROOT_MOUNT | |
31702 | + bool "Deny mounts" | |
31703 | + depends on GRKERNSEC_CHROOT | |
31704 | + help | |
31705 | + If you say Y here, processes inside a chroot will not be able to | |
31706 | + mount or remount filesystems. If the sysctl option is enabled, a | |
31707 | + sysctl option with name "chroot_deny_mount" is created. | |
31708 | + | |
31709 | +config GRKERNSEC_CHROOT_DOUBLE | |
31710 | + bool "Deny double-chroots" | |
31711 | + depends on GRKERNSEC_CHROOT | |
31712 | + help | |
31713 | + If you say Y here, processes inside a chroot will not be able to chroot | |
31714 | + again outside the chroot. This is a widely used method of breaking | |
31715 | + out of a chroot jail and should not be allowed. If the sysctl | |
31716 | + option is enabled, a sysctl option with name | |
31717 | + "chroot_deny_chroot" is created. | |
31718 | + | |
31719 | +config GRKERNSEC_CHROOT_PIVOT | |
31720 | + bool "Deny pivot_root in chroot" | |
31721 | + depends on GRKERNSEC_CHROOT | |
31722 | + help | |
31723 | + If you say Y here, processes inside a chroot will not be able to use | |
31724 | + a function called pivot_root() that was introduced in Linux 2.3.41. It | |
31725 | + works similar to chroot in that it changes the root filesystem. This | |
31726 | + function could be misused in a chrooted process to attempt to break out | |
31727 | + of the chroot, and therefore should not be allowed. If the sysctl | |
31728 | + option is enabled, a sysctl option with name "chroot_deny_pivot" is | |
31729 | + created. | |
31730 | + | |
31731 | +config GRKERNSEC_CHROOT_CHDIR | |
31732 | + bool "Enforce chdir(\"/\") on all chroots" | |
31733 | + depends on GRKERNSEC_CHROOT | |
31734 | + help | |
31735 | + If you say Y here, the current working directory of all newly-chrooted | |
31736 | + applications will be set to the the root directory of the chroot. | |
31737 | + The man page on chroot(2) states: | |
31738 | + Note that this call does not change the current working | |
31739 | + directory, so that `.' can be outside the tree rooted at | |
31740 | + `/'. In particular, the super-user can escape from a | |
31741 | + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'. | |
31742 | + | |
31743 | + It is recommended that you say Y here, since it's not known to break | |
31744 | + any software. If the sysctl option is enabled, a sysctl option with | |
31745 | + name "chroot_enforce_chdir" is created. | |
31746 | + | |
31747 | +config GRKERNSEC_CHROOT_CHMOD | |
31748 | + bool "Deny (f)chmod +s" | |
31749 | + depends on GRKERNSEC_CHROOT | |
31750 | + help | |
31751 | + If you say Y here, processes inside a chroot will not be able to chmod | |
31752 | + or fchmod files to make them have suid or sgid bits. This protects | |
31753 | + against another published method of breaking a chroot. If the sysctl | |
31754 | + option is enabled, a sysctl option with name "chroot_deny_chmod" is | |
31755 | + created. | |
31756 | + | |
31757 | +config GRKERNSEC_CHROOT_FCHDIR | |
31758 | + bool "Deny fchdir out of chroot" | |
31759 | + depends on GRKERNSEC_CHROOT | |
31760 | + help | |
31761 | + If you say Y here, a well-known method of breaking chroots by fchdir'ing | |
31762 | + to a file descriptor of the chrooting process that points to a directory | |
31763 | + outside the filesystem will be stopped. If the sysctl option | |
31764 | + is enabled, a sysctl option with name "chroot_deny_fchdir" is created. | |
31765 | + | |
31766 | +config GRKERNSEC_CHROOT_MKNOD | |
31767 | + bool "Deny mknod" | |
31768 | + depends on GRKERNSEC_CHROOT | |
31769 | + help | |
31770 | + If you say Y here, processes inside a chroot will not be allowed to | |
31771 | + mknod. The problem with using mknod inside a chroot is that it | |
31772 | + would allow an attacker to create a device entry that is the same | |
31773 | + as one on the physical root of your system, which could range from | |
31774 | + anything from the console device to a device for your harddrive (which | |
31775 | + they could then use to wipe the drive or steal data). It is recommended | |
31776 | + that you say Y here, unless you run into software incompatibilities. | |
31777 | + If the sysctl option is enabled, a sysctl option with name | |
31778 | + "chroot_deny_mknod" is created. | |
31779 | + | |
31780 | +config GRKERNSEC_CHROOT_SHMAT | |
31781 | + bool "Deny shmat() out of chroot" | |
31782 | + depends on GRKERNSEC_CHROOT | |
31783 | + help | |
31784 | + If you say Y here, processes inside a chroot will not be able to attach | |
31785 | + to shared memory segments that were created outside of the chroot jail. | |
31786 | + It is recommended that you say Y here. If the sysctl option is enabled, | |
31787 | + a sysctl option with name "chroot_deny_shmat" is created. | |
31788 | + | |
31789 | +config GRKERNSEC_CHROOT_UNIX | |
31790 | + bool "Deny access to abstract AF_UNIX sockets out of chroot" | |
31791 | + depends on GRKERNSEC_CHROOT | |
31792 | + help | |
31793 | + If you say Y here, processes inside a chroot will not be able to | |
31794 | + connect to abstract (meaning not belonging to a filesystem) Unix | |
31795 | + domain sockets that were bound outside of a chroot. It is recommended | |
31796 | + that you say Y here. If the sysctl option is enabled, a sysctl option | |
31797 | + with name "chroot_deny_unix" is created. | |
31798 | + | |
31799 | +config GRKERNSEC_CHROOT_FINDTASK | |
31800 | + bool "Protect outside processes" | |
31801 | + depends on GRKERNSEC_CHROOT | |
31802 | + help | |
31803 | + If you say Y here, processes inside a chroot will not be able to | |
31804 | + kill, send signals with fcntl, ptrace, capget, getpgid, getsid, | |
31805 | + or view any process outside of the chroot. If the sysctl | |
31806 | + option is enabled, a sysctl option with name "chroot_findtask" is | |
31807 | + created. | |
31808 | + | |
31809 | +config GRKERNSEC_CHROOT_NICE | |
31810 | + bool "Restrict priority changes" | |
31811 | + depends on GRKERNSEC_CHROOT | |
31812 | + help | |
31813 | + If you say Y here, processes inside a chroot will not be able to raise | |
31814 | + the priority of processes in the chroot, or alter the priority of | |
31815 | + processes outside the chroot. This provides more security than simply | |
31816 | + removing CAP_SYS_NICE from the process' capability set. If the | |
31817 | + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice" | |
31818 | + is created. | |
31819 | + | |
31820 | +config GRKERNSEC_CHROOT_SYSCTL | |
31821 | + bool "Deny sysctl writes" | |
31822 | + depends on GRKERNSEC_CHROOT | |
31823 | + help | |
31824 | + If you say Y here, an attacker in a chroot will not be able to | |
31825 | + write to sysctl entries, either by sysctl(2) or through a /proc | |
31826 | + interface. It is strongly recommended that you say Y here. If the | |
31827 | + sysctl option is enabled, a sysctl option with name | |
31828 | + "chroot_deny_sysctl" is created. | |
31829 | + | |
31830 | +config GRKERNSEC_CHROOT_CAPS | |
31831 | + bool "Capability restrictions" | |
31832 | + depends on GRKERNSEC_CHROOT | |
31833 | + help | |
31834 | + If you say Y here, the capabilities on all root processes within a | |
31835 | + chroot jail will be lowered to stop module insertion, raw i/o, | |
31836 | + system and net admin tasks, rebooting the system, modifying immutable | |
31837 | + files, modifying IPC owned by another, and changing the system time. | |
31838 | + This is left an option because it can break some apps. Disable this | |
31839 | + if your chrooted apps are having problems performing those kinds of | |
31840 | + tasks. If the sysctl option is enabled, a sysctl option with | |
31841 | + name "chroot_caps" is created. | |
31842 | + | |
31843 | +endmenu | |
31844 | +menu "Kernel Auditing" | |
31845 | +depends on GRKERNSEC | |
31846 | + | |
31847 | +config GRKERNSEC_AUDIT_GROUP | |
31848 | + bool "Single group for auditing" | |
31849 | + help | |
31850 | + If you say Y here, the exec, chdir, (un)mount, and ipc logging features | |
31851 | + will only operate on a group you specify. This option is recommended | |
31852 | + if you only want to watch certain users instead of having a large | |
31853 | + amount of logs from the entire system. If the sysctl option is enabled, | |
31854 | + a sysctl option with name "audit_group" is created. | |
31855 | + | |
31856 | +config GRKERNSEC_AUDIT_GID | |
31857 | + int "GID for auditing" | |
31858 | + depends on GRKERNSEC_AUDIT_GROUP | |
31859 | + default 1007 | |
31860 | + | |
31861 | +config GRKERNSEC_EXECLOG | |
31862 | + bool "Exec logging" | |
31863 | + help | |
31864 | + If you say Y here, all execve() calls will be logged (since the | |
31865 | + other exec*() calls are frontends to execve(), all execution | |
31866 | + will be logged). Useful for shell-servers that like to keep track | |
31867 | + of their users. If the sysctl option is enabled, a sysctl option with | |
31868 | + name "exec_logging" is created. | |
31869 | + WARNING: This option when enabled will produce a LOT of logs, especially | |
31870 | + on an active system. | |
31871 | + | |
31872 | +config GRKERNSEC_RESLOG | |
31873 | + bool "Resource logging" | |
31874 | + help | |
31875 | + If you say Y here, all attempts to overstep resource limits will | |
31876 | + be logged with the resource name, the requested size, and the current | |
31877 | + limit. It is highly recommended that you say Y here. If the sysctl | |
31878 | + option is enabled, a sysctl option with name "resource_logging" is | |
31879 | + created. If the RBAC system is enabled, the sysctl value is ignored. | |
31880 | + | |
31881 | +config GRKERNSEC_CHROOT_EXECLOG | |
31882 | + bool "Log execs within chroot" | |
31883 | + help | |
31884 | + If you say Y here, all executions inside a chroot jail will be logged | |
31885 | + to syslog. This can cause a large amount of logs if certain | |
31886 | + applications (eg. djb's daemontools) are installed on the system, and | |
31887 | + is therefore left as an option. If the sysctl option is enabled, a | |
31888 | + sysctl option with name "chroot_execlog" is created. | |
31889 | + | |
31890 | +config GRKERNSEC_AUDIT_CHDIR | |
31891 | + bool "Chdir logging" | |
31892 | + help | |
31893 | + If you say Y here, all chdir() calls will be logged. If the sysctl | |
31894 | + option is enabled, a sysctl option with name "audit_chdir" is created. | |
31895 | + | |
31896 | +config GRKERNSEC_AUDIT_MOUNT | |
31897 | + bool "(Un)Mount logging" | |
31898 | + help | |
31899 | + If you say Y here, all mounts and unmounts will be logged. If the | |
31900 | + sysctl option is enabled, a sysctl option with name "audit_mount" is | |
31901 | + created. | |
31902 | + | |
31903 | +config GRKERNSEC_AUDIT_IPC | |
31904 | + bool "IPC logging" | |
31905 | + help | |
31906 | + If you say Y here, creation and removal of message queues, semaphores, | |
31907 | + and shared memory will be logged. If the sysctl option is enabled, a | |
31908 | + sysctl option with name "audit_ipc" is created. | |
31909 | + | |
31910 | +config GRKERNSEC_SIGNAL | |
31911 | + bool "Signal logging" | |
31912 | + help | |
31913 | + If you say Y here, certain important signals will be logged, such as | |
31914 | + SIGSEGV, which will as a result inform you of when a error in a program | |
31915 | + occurred, which in some cases could mean a possible exploit attempt. | |
31916 | + If the sysctl option is enabled, a sysctl option with name | |
31917 | + "signal_logging" is created. | |
31918 | + | |
31919 | +config GRKERNSEC_FORKFAIL | |
31920 | + bool "Fork failure logging" | |
31921 | + help | |
31922 | + If you say Y here, all failed fork() attempts will be logged. | |
31923 | + This could suggest a fork bomb, or someone attempting to overstep | |
31924 | + their process limit. If the sysctl option is enabled, a sysctl option | |
31925 | + with name "forkfail_logging" is created. | |
31926 | + | |
31927 | +config GRKERNSEC_TIME | |
31928 | + bool "Time change logging" | |
31929 | + help | |
31930 | + If you say Y here, any changes of the system clock will be logged. | |
31931 | + If the sysctl option is enabled, a sysctl option with name | |
31932 | + "timechange_logging" is created. | |
31933 | + | |
31934 | +config GRKERNSEC_PROC_IPADDR | |
31935 | + bool "/proc/<pid>/ipaddr support" | |
31936 | + help | |
31937 | + If you say Y here, a new entry will be added to each /proc/<pid> | |
31938 | + directory that contains the IP address of the person using the task. | |
31939 | + The IP is carried across local TCP and AF_UNIX stream sockets. | |
31940 | + This information can be useful for IDS/IPSes to perform remote response | |
31941 | + to a local attack. The entry is readable by only the owner of the | |
31942 | + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via | |
31943 | + the RBAC system), and thus does not create privacy concerns. | |
31944 | + | |
31945 | +config GRKERNSEC_AUDIT_TEXTREL | |
31946 | + bool 'ELF text relocations logging (READ HELP)' | |
31947 | + depends on PAX_MPROTECT | |
31948 | + help | |
31949 | + If you say Y here, text relocations will be logged with the filename | |
31950 | + of the offending library or binary. The purpose of the feature is | |
31951 | + to help Linux distribution developers get rid of libraries and | |
31952 | + binaries that need text relocations which hinder the future progress | |
31953 | + of PaX. Only Linux distribution developers should say Y here, and | |
31954 | + never on a production machine, as this option creates an information | |
31955 | + leak that could aid an attacker in defeating the randomization of | |
31956 | + a single memory region. If the sysctl option is enabled, a sysctl | |
31957 | + option with name "audit_textrel" is created. | |
31958 | + | |
31959 | +endmenu | |
31960 | + | |
31961 | +menu "Executable Protections" | |
31962 | +depends on GRKERNSEC | |
31963 | + | |
31964 | +config GRKERNSEC_EXECVE | |
31965 | + bool "Enforce RLIMIT_NPROC on execs" | |
31966 | + help | |
31967 | + If you say Y here, users with a resource limit on processes will | |
31968 | + have the value checked during execve() calls. The current system | |
31969 | + only checks the system limit during fork() calls. If the sysctl option | |
31970 | + is enabled, a sysctl option with name "execve_limiting" is created. | |
31971 | + | |
31972 | +config GRKERNSEC_DMESG | |
31973 | + bool "Dmesg(8) restriction" | |
31974 | + help | |
31975 | + If you say Y here, non-root users will not be able to use dmesg(8) | |
31976 | + to view up to the last 4kb of messages in the kernel's log buffer. | |
31977 | + If the sysctl option is enabled, a sysctl option with name "dmesg" is | |
31978 | + created. | |
31979 | + | |
31980 | +config GRKERNSEC_TPE | |
31981 | + bool "Trusted Path Execution (TPE)" | |
31982 | + help | |
31983 | + If you say Y here, you will be able to choose a gid to add to the | |
31984 | + supplementary groups of users you want to mark as "untrusted." | |
31985 | + These users will not be able to execute any files that are not in | |
31986 | + root-owned directories writable only by root. If the sysctl option | |
31987 | + is enabled, a sysctl option with name "tpe" is created. | |
31988 | + | |
31989 | +config GRKERNSEC_TPE_ALL | |
31990 | + bool "Partially restrict non-root users" | |
31991 | + depends on GRKERNSEC_TPE | |
31992 | + help | |
31993 | + If you say Y here, All non-root users other than the ones in the | |
31994 | + group specified in the main TPE option will only be allowed to | |
31995 | + execute files in directories they own that are not group or | |
31996 | + world-writable, or in directories owned by root and writable only by | |
31997 | + root. If the sysctl option is enabled, a sysctl option with name | |
31998 | + "tpe_restrict_all" is created. | |
31999 | + | |
32000 | +config GRKERNSEC_TPE_INVERT | |
32001 | + bool "Invert GID option" | |
32002 | + depends on GRKERNSEC_TPE | |
32003 | + help | |
32004 | + If you say Y here, the group you specify in the TPE configuration will | |
32005 | + decide what group TPE restrictions will be *disabled* for. This | |
32006 | + option is useful if you want TPE restrictions to be applied to most | |
32007 | + users on the system. | |
32008 | + | |
32009 | +config GRKERNSEC_TPE_GID | |
32010 | + int "GID for untrusted users" | |
32011 | + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT | |
32012 | + default 1005 | |
32013 | + help | |
32014 | + If you have selected the "Invert GID option" above, setting this | |
32015 | + GID determines what group TPE restrictions will be *disabled* for. | |
32016 | + If you have not selected the "Invert GID option" above, setting this | |
32017 | + GID determines what group TPE restrictions will be *enabled* for. | |
32018 | + If the sysctl option is enabled, a sysctl option with name "tpe_gid" | |
32019 | + is created. | |
32020 | + | |
32021 | +config GRKERNSEC_TPE_GID | |
32022 | + int "GID for trusted users" | |
32023 | + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT | |
32024 | + default 1005 | |
32025 | + help | |
32026 | + If you have selected the "Invert GID option" above, setting this | |
32027 | + GID determines what group TPE restrictions will be *disabled* for. | |
32028 | + If you have not selected the "Invert GID option" above, setting this | |
32029 | + GID determines what group TPE restrictions will be *enabled* for. | |
32030 | + If the sysctl option is enabled, a sysctl option with name "tpe_gid" | |
32031 | + is created. | |
32032 | + | |
32033 | +endmenu | |
32034 | +menu "Network Protections" | |
32035 | +depends on GRKERNSEC | |
32036 | + | |
32037 | +config GRKERNSEC_RANDNET | |
32038 | + bool "Larger entropy pools" | |
32039 | + help | |
32040 | + If you say Y here, the entropy pools used for many features of Linux | |
32041 | + and grsecurity will be doubled in size. Since several grsecurity | |
32042 | + features use additional randomness, it is recommended that you say Y | |
32043 | + here. Saying Y here has a similar effect as modifying | |
32044 | + /proc/sys/kernel/random/poolsize. | |
32045 | + | |
de855c5d AM |
32046 | +config GRKERNSEC_BLACKHOLE |
32047 | + bool "TCP/UDP blackhole" | |
32048 | + help | |
32049 | + If you say Y here, neither TCP resets nor ICMP | |
32050 | + destination-unreachable packets will be sent in response to packets | |
32051 | + send to ports for which no associated listening process exists. | |
32052 | + This feature supports both IPV4 and IPV6 and exempts the | |
32053 | + loopback interface from blackholing. Enabling this feature | |
32054 | + makes a host more resilient to DoS attacks and reduces network | |
32055 | + visibility against scanners. | |
32056 | + | |
2380c486 JR |
32057 | +config GRKERNSEC_SOCKET |
32058 | + bool "Socket restrictions" | |
32059 | + help | |
32060 | + If you say Y here, you will be able to choose from several options. | |
32061 | + If you assign a GID on your system and add it to the supplementary | |
32062 | + groups of users you want to restrict socket access to, this patch | |
32063 | + will perform up to three things, based on the option(s) you choose. | |
32064 | + | |
32065 | +config GRKERNSEC_SOCKET_ALL | |
32066 | + bool "Deny any sockets to group" | |
32067 | + depends on GRKERNSEC_SOCKET | |
32068 | + help | |
32069 | + If you say Y here, you will be able to choose a GID of whose users will | |
32070 | + be unable to connect to other hosts from your machine or run server | |
32071 | + applications from your machine. If the sysctl option is enabled, a | |
32072 | + sysctl option with name "socket_all" is created. | |
32073 | + | |
32074 | +config GRKERNSEC_SOCKET_ALL_GID | |
32075 | + int "GID to deny all sockets for" | |
32076 | + depends on GRKERNSEC_SOCKET_ALL | |
32077 | + default 1004 | |
32078 | + help | |
32079 | + Here you can choose the GID to disable socket access for. Remember to | |
32080 | + add the users you want socket access disabled for to the GID | |
32081 | + specified here. If the sysctl option is enabled, a sysctl option | |
32082 | + with name "socket_all_gid" is created. | |
32083 | + | |
32084 | +config GRKERNSEC_SOCKET_CLIENT | |
32085 | + bool "Deny client sockets to group" | |
32086 | + depends on GRKERNSEC_SOCKET | |
32087 | + help | |
32088 | + If you say Y here, you will be able to choose a GID of whose users will | |
32089 | + be unable to connect to other hosts from your machine, but will be | |
32090 | + able to run servers. If this option is enabled, all users in the group | |
32091 | + you specify will have to use passive mode when initiating ftp transfers | |
32092 | + from the shell on your machine. If the sysctl option is enabled, a | |
32093 | + sysctl option with name "socket_client" is created. | |
32094 | + | |
32095 | +config GRKERNSEC_SOCKET_CLIENT_GID | |
32096 | + int "GID to deny client sockets for" | |
32097 | + depends on GRKERNSEC_SOCKET_CLIENT | |
32098 | + default 1003 | |
32099 | + help | |
32100 | + Here you can choose the GID to disable client socket access for. | |
32101 | + Remember to add the users you want client socket access disabled for to | |
32102 | + the GID specified here. If the sysctl option is enabled, a sysctl | |
32103 | + option with name "socket_client_gid" is created. | |
32104 | + | |
32105 | +config GRKERNSEC_SOCKET_SERVER | |
32106 | + bool "Deny server sockets to group" | |
32107 | + depends on GRKERNSEC_SOCKET | |
32108 | + help | |
32109 | + If you say Y here, you will be able to choose a GID of whose users will | |
32110 | + be unable to run server applications from your machine. If the sysctl | |
32111 | + option is enabled, a sysctl option with name "socket_server" is created. | |
32112 | + | |
32113 | +config GRKERNSEC_SOCKET_SERVER_GID | |
32114 | + int "GID to deny server sockets for" | |
32115 | + depends on GRKERNSEC_SOCKET_SERVER | |
32116 | + default 1002 | |
32117 | + help | |
32118 | + Here you can choose the GID to disable server socket access for. | |
32119 | + Remember to add the users you want server socket access disabled for to | |
32120 | + the GID specified here. If the sysctl option is enabled, a sysctl | |
32121 | + option with name "socket_server_gid" is created. | |
32122 | + | |
32123 | +endmenu | |
32124 | +menu "Sysctl support" | |
32125 | +depends on GRKERNSEC && SYSCTL | |
32126 | + | |
32127 | +config GRKERNSEC_SYSCTL | |
32128 | + bool "Sysctl support" | |
32129 | + help | |
32130 | + If you say Y here, you will be able to change the options that | |
32131 | + grsecurity runs with at bootup, without having to recompile your | |
32132 | + kernel. You can echo values to files in /proc/sys/kernel/grsecurity | |
32133 | + to enable (1) or disable (0) various features. All the sysctl entries | |
32134 | + are mutable until the "grsec_lock" entry is set to a non-zero value. | |
32135 | + All features enabled in the kernel configuration are disabled at boot | |
32136 | + if you do not say Y to the "Turn on features by default" option. | |
32137 | + All options should be set at startup, and the grsec_lock entry should | |
32138 | + be set to a non-zero value after all the options are set. | |
32139 | + *THIS IS EXTREMELY IMPORTANT* | |
32140 | + | |
32141 | +config GRKERNSEC_SYSCTL_ON | |
32142 | + bool "Turn on features by default" | |
32143 | + depends on GRKERNSEC_SYSCTL | |
32144 | + help | |
32145 | + If you say Y here, instead of having all features enabled in the | |
32146 | + kernel configuration disabled at boot time, the features will be | |
32147 | + enabled at boot time. It is recommended you say Y here unless | |
32148 | + there is some reason you would want all sysctl-tunable features to | |
32149 | + be disabled by default. As mentioned elsewhere, it is important | |
32150 | + to enable the grsec_lock entry once you have finished modifying | |
32151 | + the sysctl entries. | |
32152 | + | |
32153 | +endmenu | |
32154 | +menu "Logging Options" | |
32155 | +depends on GRKERNSEC | |
32156 | + | |
32157 | +config GRKERNSEC_FLOODTIME | |
32158 | + int "Seconds in between log messages (minimum)" | |
32159 | + default 10 | |
32160 | + help | |
32161 | + This option allows you to enforce the number of seconds between | |
32162 | + grsecurity log messages. The default should be suitable for most | |
32163 | + people, however, if you choose to change it, choose a value small enough | |
32164 | + to allow informative logs to be produced, but large enough to | |
32165 | + prevent flooding. | |
32166 | + | |
32167 | +config GRKERNSEC_FLOODBURST | |
32168 | + int "Number of messages in a burst (maximum)" | |
32169 | + default 4 | |
32170 | + help | |
32171 | + This option allows you to choose the maximum number of messages allowed | |
32172 | + within the flood time interval you chose in a separate option. The | |
32173 | + default should be suitable for most people, however if you find that | |
32174 | + many of your logs are being interpreted as flooding, you may want to | |
32175 | + raise this value. | |
32176 | + | |
32177 | +endmenu | |
32178 | + | |
32179 | +endmenu | |
de855c5d AM |
32180 | diff -urNp linux-2.6.29.6/grsecurity/Makefile linux-2.6.29.6/grsecurity/Makefile |
32181 | --- linux-2.6.29.6/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500 | |
32182 | +++ linux-2.6.29.6/grsecurity/Makefile 2009-07-09 22:13:39.000000000 -0400 | |
32183 | @@ -0,0 +1,21 @@ | |
2380c486 JR |
32184 | +# grsecurity's ACL system was originally written in 2001 by Michael Dalton |
32185 | +# during 2001-2005 it has been completely redesigned by Brad Spengler | |
32186 | +# into an RBAC system | |
32187 | +# | |
32188 | +# All code in this directory and various hooks inserted throughout the kernel | |
de855c5d AM |
32189 | +# are copyright Brad Spengler - Open Source Security, Inc., and released |
32190 | +# under the GPL v2 or higher | |
2380c486 JR |
32191 | + |
32192 | +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \ | |
32193 | + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \ | |
32194 | + grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o | |
32195 | + | |
32196 | +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \ | |
32197 | + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \ | |
32198 | + gracl_learn.o grsec_log.o | |
32199 | +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o | |
32200 | + | |
32201 | +ifndef CONFIG_GRKERNSEC | |
32202 | +obj-y += grsec_disabled.o | |
32203 | +endif | |
32204 | + | |
de855c5d AM |
32205 | diff -urNp linux-2.6.29.6/include/asm-frv/atomic.h linux-2.6.29.6/include/asm-frv/atomic.h |
32206 | --- linux-2.6.29.6/include/asm-frv/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
32207 | +++ linux-2.6.29.6/include/asm-frv/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
32208 | @@ -114,6 +114,10 @@ static inline void atomic_dec(atomic_t * | |
32209 | atomic_sub_return(1, v); | |
32210 | } | |
32211 | ||
32212 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
32213 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
32214 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
32215 | + | |
32216 | #define atomic_dec_return(v) atomic_sub_return(1, (v)) | |
32217 | #define atomic_inc_return(v) atomic_add_return(1, (v)) | |
32218 | ||
32219 | diff -urNp linux-2.6.29.6/include/asm-frv/kmap_types.h linux-2.6.29.6/include/asm-frv/kmap_types.h | |
32220 | --- linux-2.6.29.6/include/asm-frv/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
32221 | +++ linux-2.6.29.6/include/asm-frv/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32222 | @@ -23,6 +23,7 @@ enum km_type { |
32223 | KM_IRQ1, | |
32224 | KM_SOFTIRQ0, | |
32225 | KM_SOFTIRQ1, | |
32226 | + KM_CLEARPAGE, | |
32227 | KM_TYPE_NR | |
32228 | }; | |
32229 | ||
de855c5d AM |
32230 | diff -urNp linux-2.6.29.6/include/asm-generic/futex.h linux-2.6.29.6/include/asm-generic/futex.h |
32231 | --- linux-2.6.29.6/include/asm-generic/futex.h 2009-07-02 19:41:20.000000000 -0400 | |
32232 | +++ linux-2.6.29.6/include/asm-generic/futex.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32233 | @@ -6,7 +6,7 @@ |
32234 | #include <asm/errno.h> | |
32235 | ||
32236 | static inline int | |
32237 | -futex_atomic_op_inuser (int encoded_op, int __user *uaddr) | |
32238 | +futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) | |
32239 | { | |
32240 | int op = (encoded_op >> 28) & 7; | |
32241 | int cmp = (encoded_op >> 24) & 15; | |
32242 | @@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, | |
32243 | } | |
32244 | ||
32245 | static inline int | |
32246 | -futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval) | |
32247 | +futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval) | |
32248 | { | |
32249 | return -ENOSYS; | |
32250 | } | |
de855c5d AM |
32251 | diff -urNp linux-2.6.29.6/include/asm-generic/int-l64.h linux-2.6.29.6/include/asm-generic/int-l64.h |
32252 | --- linux-2.6.29.6/include/asm-generic/int-l64.h 2009-07-02 19:41:20.000000000 -0400 | |
32253 | +++ linux-2.6.29.6/include/asm-generic/int-l64.h 2009-07-09 22:13:39.000000000 -0400 | |
32254 | @@ -44,6 +44,8 @@ typedef unsigned int u32; | |
32255 | typedef signed long s64; | |
32256 | typedef unsigned long u64; | |
32257 | ||
32258 | +typedef unsigned int intoverflow_t __attribute__ ((mode(TI))); | |
32259 | + | |
32260 | #define S8_C(x) x | |
32261 | #define U8_C(x) x ## U | |
32262 | #define S16_C(x) x | |
32263 | diff -urNp linux-2.6.29.6/include/asm-generic/int-ll64.h linux-2.6.29.6/include/asm-generic/int-ll64.h | |
32264 | --- linux-2.6.29.6/include/asm-generic/int-ll64.h 2009-07-02 19:41:20.000000000 -0400 | |
32265 | +++ linux-2.6.29.6/include/asm-generic/int-ll64.h 2009-07-09 22:13:39.000000000 -0400 | |
32266 | @@ -49,6 +49,8 @@ typedef unsigned int u32; | |
32267 | typedef signed long long s64; | |
32268 | typedef unsigned long long u64; | |
32269 | ||
32270 | +typedef unsigned long long intoverflow_t; | |
32271 | + | |
32272 | #define S8_C(x) x | |
32273 | #define U8_C(x) x ## U | |
32274 | #define S16_C(x) x | |
32275 | diff -urNp linux-2.6.29.6/include/asm-generic/vmlinux.lds.h linux-2.6.29.6/include/asm-generic/vmlinux.lds.h | |
32276 | --- linux-2.6.29.6/include/asm-generic/vmlinux.lds.h 2009-07-02 19:41:20.000000000 -0400 | |
32277 | +++ linux-2.6.29.6/include/asm-generic/vmlinux.lds.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32278 | @@ -88,6 +88,7 @@ |
32279 | .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ | |
32280 | VMLINUX_SYMBOL(__start_rodata) = .; \ | |
32281 | *(.rodata) *(.rodata.*) \ | |
32282 | + *(.data.read_only) \ | |
32283 | *(__vermagic) /* Kernel version magic */ \ | |
32284 | *(__markers_strings) /* Markers: strings */ \ | |
32285 | *(__tracepoints_strings)/* Tracepoints: strings */ \ | |
de855c5d AM |
32286 | diff -urNp linux-2.6.29.6/include/asm-m32r/atomic.h linux-2.6.29.6/include/asm-m32r/atomic.h |
32287 | --- linux-2.6.29.6/include/asm-m32r/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
32288 | +++ linux-2.6.29.6/include/asm-m32r/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
32289 | @@ -308,6 +308,10 @@ static __inline__ void atomic_set_mask(u | |
32290 | local_irq_restore(flags); | |
32291 | } | |
32292 | ||
32293 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
32294 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
32295 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
32296 | + | |
32297 | /* Atomic operations are already serializing on m32r */ | |
32298 | #define smp_mb__before_atomic_dec() barrier() | |
32299 | #define smp_mb__after_atomic_dec() barrier() | |
32300 | diff -urNp linux-2.6.29.6/include/asm-m32r/kmap_types.h linux-2.6.29.6/include/asm-m32r/kmap_types.h | |
32301 | --- linux-2.6.29.6/include/asm-m32r/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
32302 | +++ linux-2.6.29.6/include/asm-m32r/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32303 | @@ -21,7 +21,8 @@ D(9) KM_IRQ0, |
32304 | D(10) KM_IRQ1, | |
32305 | D(11) KM_SOFTIRQ0, | |
32306 | D(12) KM_SOFTIRQ1, | |
32307 | -D(13) KM_TYPE_NR | |
32308 | +D(13) KM_CLEARPAGE, | |
32309 | +D(14) KM_TYPE_NR | |
32310 | }; | |
32311 | ||
32312 | #undef D | |
de855c5d AM |
32313 | diff -urNp linux-2.6.29.6/include/asm-mn10300/atomic.h linux-2.6.29.6/include/asm-mn10300/atomic.h |
32314 | --- linux-2.6.29.6/include/asm-mn10300/atomic.h 2009-07-02 19:41:20.000000000 -0400 | |
32315 | +++ linux-2.6.29.6/include/asm-mn10300/atomic.h 2009-07-09 22:13:39.000000000 -0400 | |
32316 | @@ -145,6 +145,10 @@ static inline void atomic_clear_mask(uns | |
32317 | #define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) | |
32318 | #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) | |
32319 | ||
32320 | +#define atomic_inc_unchecked(v) atomic_inc(v) | |
32321 | +#define atomic_add_unchecked(i,v) atomic_add((i),(v)) | |
32322 | +#define atomic_sub_unchecked(i,v) atomic_sub((i),(v)) | |
32323 | + | |
32324 | /* Atomic operations are already serializing on MN10300??? */ | |
32325 | #define smp_mb__before_atomic_dec() barrier() | |
32326 | #define smp_mb__after_atomic_dec() barrier() | |
32327 | diff -urNp linux-2.6.29.6/include/asm-mn10300/kmap_types.h linux-2.6.29.6/include/asm-mn10300/kmap_types.h | |
32328 | --- linux-2.6.29.6/include/asm-mn10300/kmap_types.h 2009-07-02 19:41:20.000000000 -0400 | |
32329 | +++ linux-2.6.29.6/include/asm-mn10300/kmap_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32330 | @@ -25,6 +25,7 @@ enum km_type { |
32331 | KM_IRQ1, | |
32332 | KM_SOFTIRQ0, | |
32333 | KM_SOFTIRQ1, | |
32334 | + KM_CLEARPAGE, | |
32335 | KM_TYPE_NR | |
32336 | }; | |
32337 | ||
de855c5d AM |
32338 | diff -urNp linux-2.6.29.6/include/drm/drm_pciids.h linux-2.6.29.6/include/drm/drm_pciids.h |
32339 | --- linux-2.6.29.6/include/drm/drm_pciids.h 2009-07-02 19:41:20.000000000 -0400 | |
32340 | +++ linux-2.6.29.6/include/drm/drm_pciids.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32341 | @@ -243,7 +243,7 @@ |
32342 | {0x1002, 0x796d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \ | |
32343 | {0x1002, 0x796e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \ | |
32344 | {0x1002, 0x796f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \ | |
32345 | - {0, 0, 0} | |
32346 | + {0, 0, 0, 0, 0, 0} | |
32347 | ||
32348 | #define r128_PCI_IDS \ | |
32349 | {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32350 | @@ -283,14 +283,14 @@ | |
32351 | {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32352 | {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32353 | {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32354 | - {0, 0, 0} | |
32355 | + {0, 0, 0, 0, 0, 0} | |
32356 | ||
32357 | #define mga_PCI_IDS \ | |
32358 | {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \ | |
32359 | {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \ | |
32360 | {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \ | |
32361 | {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \ | |
32362 | - {0, 0, 0} | |
32363 | + {0, 0, 0, 0, 0, 0} | |
32364 | ||
32365 | #define mach64_PCI_IDS \ | |
32366 | {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32367 | @@ -313,7 +313,7 @@ | |
32368 | {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32369 | {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32370 | {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32371 | - {0, 0, 0} | |
32372 | + {0, 0, 0, 0, 0, 0} | |
32373 | ||
32374 | #define sisdrv_PCI_IDS \ | |
32375 | {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32376 | @@ -324,7 +324,7 @@ | |
32377 | {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32378 | {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \ | |
32379 | {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \ | |
32380 | - {0, 0, 0} | |
32381 | + {0, 0, 0, 0, 0, 0} | |
32382 | ||
32383 | #define tdfx_PCI_IDS \ | |
32384 | {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32385 | @@ -333,7 +333,7 @@ | |
32386 | {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32387 | {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32388 | {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32389 | - {0, 0, 0} | |
32390 | + {0, 0, 0, 0, 0, 0} | |
32391 | ||
32392 | #define viadrv_PCI_IDS \ | |
32393 | {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32394 | @@ -345,25 +345,25 @@ | |
32395 | {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32396 | {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \ | |
32397 | {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \ | |
32398 | - {0, 0, 0} | |
32399 | + {0, 0, 0, 0, 0, 0} | |
32400 | ||
32401 | #define i810_PCI_IDS \ | |
32402 | {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32403 | {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32404 | {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32405 | {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32406 | - {0, 0, 0} | |
32407 | + {0, 0, 0, 0, 0, 0} | |
32408 | ||
32409 | #define i830_PCI_IDS \ | |
32410 | {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32411 | {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32412 | {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32413 | {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32414 | - {0, 0, 0} | |
32415 | + {0, 0, 0, 0, 0, 0} | |
32416 | ||
32417 | #define gamma_PCI_IDS \ | |
32418 | {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ | |
32419 | - {0, 0, 0} | |
32420 | + {0, 0, 0, 0, 0, 0} | |
32421 | ||
32422 | #define savage_PCI_IDS \ | |
32423 | {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \ | |
32424 | @@ -389,10 +389,10 @@ | |
32425 | {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \ | |
32426 | {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \ | |
32427 | {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \ | |
32428 | - {0, 0, 0} | |
32429 | + {0, 0, 0, 0, 0, 0} | |
32430 | ||
32431 | #define ffb_PCI_IDS \ | |
32432 | - {0, 0, 0} | |
32433 | + {0, 0, 0, 0, 0, 0} | |
32434 | ||
32435 | #define i915_PCI_IDS \ | |
32436 | {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ | |
de855c5d | 32437 | @@ -419,4 +419,4 @@ |
2380c486 JR |
32438 | {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ |
32439 | {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ | |
de855c5d | 32440 | {0x8086, 0x2e32, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ |
2380c486 JR |
32441 | - {0, 0, 0} |
32442 | + {0, 0, 0, 0, 0, 0} | |
de855c5d AM |
32443 | diff -urNp linux-2.6.29.6/include/drm/drmP.h linux-2.6.29.6/include/drm/drmP.h |
32444 | --- linux-2.6.29.6/include/drm/drmP.h 2009-07-02 19:41:20.000000000 -0400 | |
32445 | +++ linux-2.6.29.6/include/drm/drmP.h 2009-07-09 22:13:39.000000000 -0400 | |
32446 | @@ -825,7 +825,7 @@ struct drm_device { | |
32447 | ||
32448 | /** \name Usage Counters */ | |
32449 | /*@{ */ | |
32450 | - int open_count; /**< Outstanding files open */ | |
32451 | + atomic_t open_count; /**< Outstanding files open */ | |
32452 | atomic_t ioctl_count; /**< Outstanding IOCTLs pending */ | |
32453 | atomic_t vma_count; /**< Outstanding vma areas open */ | |
32454 | int buf_use; /**< Buffers in use -- cannot alloc */ | |
32455 | @@ -836,7 +836,7 @@ struct drm_device { | |
32456 | /*@{ */ | |
32457 | unsigned long counters; | |
32458 | enum drm_stat_type types[15]; | |
32459 | - atomic_t counts[15]; | |
32460 | + atomic_unchecked_t counts[15]; | |
32461 | /*@} */ | |
32462 | ||
32463 | struct list_head filelist; | |
32464 | diff -urNp linux-2.6.29.6/include/linux/a.out.h linux-2.6.29.6/include/linux/a.out.h | |
32465 | --- linux-2.6.29.6/include/linux/a.out.h 2009-07-02 19:41:20.000000000 -0400 | |
32466 | +++ linux-2.6.29.6/include/linux/a.out.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32467 | @@ -39,6 +39,14 @@ enum machine_type { |
32468 | M_MIPS2 = 152 /* MIPS R6000/R4000 binary */ | |
32469 | }; | |
32470 | ||
32471 | +/* Constants for the N_FLAGS field */ | |
32472 | +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */ | |
32473 | +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */ | |
32474 | +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */ | |
32475 | +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */ | |
32476 | +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */ | |
32477 | +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */ | |
32478 | + | |
32479 | #if !defined (N_MAGIC) | |
32480 | #define N_MAGIC(exec) ((exec).a_info & 0xffff) | |
32481 | #endif | |
de855c5d AM |
32482 | diff -urNp linux-2.6.29.6/include/linux/atmdev.h linux-2.6.29.6/include/linux/atmdev.h |
32483 | --- linux-2.6.29.6/include/linux/atmdev.h 2009-07-02 19:41:20.000000000 -0400 | |
32484 | +++ linux-2.6.29.6/include/linux/atmdev.h 2009-07-09 22:13:39.000000000 -0400 | |
32485 | @@ -237,7 +237,7 @@ struct compat_atm_iobuf { | |
32486 | #endif | |
32487 | ||
32488 | struct k_atm_aal_stats { | |
32489 | -#define __HANDLE_ITEM(i) atomic_t i | |
32490 | +#define __HANDLE_ITEM(i) atomic_unchecked_t i | |
32491 | __AAL_STAT_ITEMS | |
32492 | #undef __HANDLE_ITEM | |
32493 | }; | |
32494 | diff -urNp linux-2.6.29.6/include/linux/binfmts.h linux-2.6.29.6/include/linux/binfmts.h | |
32495 | --- linux-2.6.29.6/include/linux/binfmts.h 2009-07-02 19:41:20.000000000 -0400 | |
32496 | +++ linux-2.6.29.6/include/linux/binfmts.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32497 | @@ -79,6 +79,7 @@ struct linux_binfmt { |
32498 | int (*load_binary)(struct linux_binprm *, struct pt_regs * regs); | |
32499 | int (*load_shlib)(struct file *); | |
32500 | int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit); | |
32501 | + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags); | |
32502 | unsigned long min_coredump; /* minimal dump size */ | |
32503 | int hasvdso; | |
32504 | }; | |
de855c5d AM |
32505 | diff -urNp linux-2.6.29.6/include/linux/cache.h linux-2.6.29.6/include/linux/cache.h |
32506 | --- linux-2.6.29.6/include/linux/cache.h 2009-07-02 19:41:20.000000000 -0400 | |
32507 | +++ linux-2.6.29.6/include/linux/cache.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32508 | @@ -16,6 +16,10 @@ |
32509 | #define __read_mostly | |
32510 | #endif | |
32511 | ||
32512 | +#ifndef __read_only | |
32513 | +#define __read_only __read_mostly | |
32514 | +#endif | |
32515 | + | |
32516 | #ifndef ____cacheline_aligned | |
32517 | #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES))) | |
32518 | #endif | |
de855c5d AM |
32519 | diff -urNp linux-2.6.29.6/include/linux/capability.h linux-2.6.29.6/include/linux/capability.h |
32520 | --- linux-2.6.29.6/include/linux/capability.h 2009-07-02 19:41:20.000000000 -0400 | |
32521 | +++ linux-2.6.29.6/include/linux/capability.h 2009-07-09 22:13:39.000000000 -0400 | |
32522 | @@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff | |
2380c486 JR |
32523 | (security_real_capable_noaudit((t), (cap)) == 0) |
32524 | ||
32525 | extern int capable(int cap); | |
32526 | +int capable_nolog(int cap); | |
32527 | ||
32528 | /* audit system wants to get cap info from files as well */ | |
32529 | struct dentry; | |
de855c5d AM |
32530 | diff -urNp linux-2.6.29.6/include/linux/cpumask.h linux-2.6.29.6/include/linux/cpumask.h |
32531 | --- linux-2.6.29.6/include/linux/cpumask.h 2009-07-02 19:41:20.000000000 -0400 | |
32532 | +++ linux-2.6.29.6/include/linux/cpumask.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32533 | @@ -142,7 +142,6 @@ |
32534 | #include <linux/bitmap.h> | |
32535 | ||
32536 | typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; | |
32537 | -extern cpumask_t _unused_cpumask_arg_; | |
32538 | ||
32539 | #ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | |
32540 | #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst)) | |
de855c5d AM |
32541 | diff -urNp linux-2.6.29.6/include/linux/elf.h linux-2.6.29.6/include/linux/elf.h |
32542 | --- linux-2.6.29.6/include/linux/elf.h 2009-07-02 19:41:20.000000000 -0400 | |
32543 | +++ linux-2.6.29.6/include/linux/elf.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32544 | @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword; |
32545 | #define PT_GNU_EH_FRAME 0x6474e550 | |
32546 | ||
32547 | #define PT_GNU_STACK (PT_LOOS + 0x474e551) | |
32548 | +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) | |
32549 | + | |
32550 | +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580) | |
32551 | + | |
32552 | +/* Constants for the e_flags field */ | |
32553 | +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */ | |
32554 | +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */ | |
32555 | +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */ | |
32556 | +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */ | |
32557 | +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */ | |
32558 | +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */ | |
32559 | ||
32560 | /* These constants define the different elf file types */ | |
32561 | #define ET_NONE 0 | |
32562 | @@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword; | |
32563 | #define DT_DEBUG 21 | |
32564 | #define DT_TEXTREL 22 | |
32565 | #define DT_JMPREL 23 | |
32566 | +#define DT_FLAGS 30 | |
32567 | + #define DF_TEXTREL 0x00000004 | |
32568 | #define DT_ENCODING 32 | |
32569 | #define OLD_DT_LOOS 0x60000000 | |
32570 | #define DT_LOOS 0x6000000d | |
32571 | @@ -230,6 +243,19 @@ typedef struct elf64_hdr { | |
32572 | #define PF_W 0x2 | |
32573 | #define PF_X 0x1 | |
32574 | ||
32575 | +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */ | |
32576 | +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */ | |
32577 | +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */ | |
32578 | +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */ | |
32579 | +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */ | |
32580 | +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */ | |
32581 | +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */ | |
32582 | +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */ | |
32583 | +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */ | |
32584 | +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */ | |
32585 | +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */ | |
32586 | +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */ | |
32587 | + | |
32588 | typedef struct elf32_phdr{ | |
32589 | Elf32_Word p_type; | |
32590 | Elf32_Off p_offset; | |
32591 | @@ -322,6 +348,8 @@ typedef struct elf64_shdr { | |
32592 | #define EI_OSABI 7 | |
32593 | #define EI_PAD 8 | |
32594 | ||
32595 | +#define EI_PAX 14 | |
32596 | + | |
32597 | #define ELFMAG0 0x7f /* EI_MAG */ | |
32598 | #define ELFMAG1 'E' | |
32599 | #define ELFMAG2 'L' | |
32600 | @@ -385,6 +413,7 @@ extern Elf32_Dyn _DYNAMIC []; | |
32601 | #define elf_phdr elf32_phdr | |
32602 | #define elf_note elf32_note | |
32603 | #define elf_addr_t Elf32_Off | |
32604 | +#define elf_dyn Elf32_Dyn | |
32605 | ||
32606 | #else | |
32607 | ||
32608 | @@ -393,6 +422,7 @@ extern Elf64_Dyn _DYNAMIC []; | |
32609 | #define elf_phdr elf64_phdr | |
32610 | #define elf_note elf64_note | |
32611 | #define elf_addr_t Elf64_Off | |
32612 | +#define elf_dyn Elf64_Dyn | |
32613 | ||
32614 | #endif | |
32615 | ||
de855c5d AM |
32616 | diff -urNp linux-2.6.29.6/include/linux/fs_struct.h linux-2.6.29.6/include/linux/fs_struct.h |
32617 | --- linux-2.6.29.6/include/linux/fs_struct.h 2009-07-02 19:41:20.000000000 -0400 | |
32618 | +++ linux-2.6.29.6/include/linux/fs_struct.h 2009-07-09 22:13:39.000000000 -0400 | |
32619 | @@ -4,7 +4,7 @@ | |
32620 | #include <linux/path.h> | |
32621 | ||
32622 | struct fs_struct { | |
32623 | - int users; | |
32624 | + atomic_t users; | |
32625 | rwlock_t lock; | |
32626 | int umask; | |
32627 | int in_exec; | |
32628 | diff -urNp linux-2.6.29.6/include/linux/genhd.h linux-2.6.29.6/include/linux/genhd.h | |
32629 | --- linux-2.6.29.6/include/linux/genhd.h 2009-07-02 19:41:20.000000000 -0400 | |
32630 | +++ linux-2.6.29.6/include/linux/genhd.h 2009-07-09 22:13:39.000000000 -0400 | |
32631 | @@ -159,7 +159,7 @@ struct gendisk { | |
32632 | ||
32633 | struct timer_rand_state *random; | |
32634 | ||
32635 | - atomic_t sync_io; /* RAID */ | |
32636 | + atomic_unchecked_t sync_io; /* RAID */ | |
32637 | struct work_struct async_notify; | |
32638 | #ifdef CONFIG_BLK_DEV_INTEGRITY | |
32639 | struct blk_integrity *integrity; | |
32640 | diff -urNp linux-2.6.29.6/include/linux/gracl.h linux-2.6.29.6/include/linux/gracl.h | |
32641 | --- linux-2.6.29.6/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500 | |
32642 | +++ linux-2.6.29.6/include/linux/gracl.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32643 | @@ -0,0 +1,318 @@ |
32644 | +#ifndef GR_ACL_H | |
32645 | +#define GR_ACL_H | |
32646 | + | |
32647 | +#include <linux/grdefs.h> | |
32648 | +#include <linux/resource.h> | |
32649 | +#include <linux/capability.h> | |
32650 | +#include <linux/dcache.h> | |
32651 | +#include <asm/resource.h> | |
32652 | + | |
32653 | +/* Major status information */ | |
32654 | + | |
32655 | +#define GR_VERSION "grsecurity 2.1.14" | |
32656 | +#define GRSECURITY_VERSION 0x2114 | |
32657 | + | |
32658 | +enum { | |
32659 | + GR_SHUTDOWN = 0, | |
32660 | + GR_ENABLE = 1, | |
32661 | + GR_SPROLE = 2, | |
32662 | + GR_RELOAD = 3, | |
32663 | + GR_SEGVMOD = 4, | |
32664 | + GR_STATUS = 5, | |
32665 | + GR_UNSPROLE = 6, | |
32666 | + GR_PASSSET = 7, | |
32667 | + GR_SPROLEPAM = 8, | |
32668 | +}; | |
32669 | + | |
32670 | +/* Password setup definitions | |
32671 | + * kernel/grhash.c */ | |
32672 | +enum { | |
32673 | + GR_PW_LEN = 128, | |
32674 | + GR_SALT_LEN = 16, | |
32675 | + GR_SHA_LEN = 32, | |
32676 | +}; | |
32677 | + | |
32678 | +enum { | |
32679 | + GR_SPROLE_LEN = 64, | |
32680 | +}; | |
32681 | + | |
32682 | +#define GR_NLIMITS 32 | |
32683 | + | |
32684 | +/* Begin Data Structures */ | |
32685 | + | |
32686 | +struct sprole_pw { | |
32687 | + unsigned char *rolename; | |
32688 | + unsigned char salt[GR_SALT_LEN]; | |
32689 | + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */ | |
32690 | +}; | |
32691 | + | |
32692 | +struct name_entry { | |
32693 | + __u32 key; | |
32694 | + ino_t inode; | |
32695 | + dev_t device; | |
32696 | + char *name; | |
32697 | + __u16 len; | |
32698 | + __u8 deleted; | |
32699 | + struct name_entry *prev; | |
32700 | + struct name_entry *next; | |
32701 | +}; | |
32702 | + | |
32703 | +struct inodev_entry { | |
32704 | + struct name_entry *nentry; | |
32705 | + struct inodev_entry *prev; | |
32706 | + struct inodev_entry *next; | |
32707 | +}; | |
32708 | + | |
32709 | +struct acl_role_db { | |
32710 | + struct acl_role_label **r_hash; | |
32711 | + __u32 r_size; | |
32712 | +}; | |
32713 | + | |
32714 | +struct inodev_db { | |
32715 | + struct inodev_entry **i_hash; | |
32716 | + __u32 i_size; | |
32717 | +}; | |
32718 | + | |
32719 | +struct name_db { | |
32720 | + struct name_entry **n_hash; | |
32721 | + __u32 n_size; | |
32722 | +}; | |
32723 | + | |
32724 | +struct crash_uid { | |
32725 | + uid_t uid; | |
32726 | + unsigned long expires; | |
32727 | +}; | |
32728 | + | |
32729 | +struct gr_hash_struct { | |
32730 | + void **table; | |
32731 | + void **nametable; | |
32732 | + void *first; | |
32733 | + __u32 table_size; | |
32734 | + __u32 used_size; | |
32735 | + int type; | |
32736 | +}; | |
32737 | + | |
32738 | +/* Userspace Grsecurity ACL data structures */ | |
32739 | + | |
32740 | +struct acl_subject_label { | |
32741 | + char *filename; | |
32742 | + ino_t inode; | |
32743 | + dev_t device; | |
32744 | + __u32 mode; | |
32745 | + kernel_cap_t cap_mask; | |
32746 | + kernel_cap_t cap_lower; | |
32747 | + | |
32748 | + struct rlimit res[GR_NLIMITS]; | |
32749 | + __u32 resmask; | |
32750 | + | |
32751 | + __u8 user_trans_type; | |
32752 | + __u8 group_trans_type; | |
32753 | + uid_t *user_transitions; | |
32754 | + gid_t *group_transitions; | |
32755 | + __u16 user_trans_num; | |
32756 | + __u16 group_trans_num; | |
32757 | + | |
32758 | + __u32 ip_proto[8]; | |
32759 | + __u32 ip_type; | |
32760 | + struct acl_ip_label **ips; | |
32761 | + __u32 ip_num; | |
32762 | + __u32 inaddr_any_override; | |
32763 | + | |
32764 | + __u32 crashes; | |
32765 | + unsigned long expires; | |
32766 | + | |
32767 | + struct acl_subject_label *parent_subject; | |
32768 | + struct gr_hash_struct *hash; | |
32769 | + struct acl_subject_label *prev; | |
32770 | + struct acl_subject_label *next; | |
32771 | + | |
32772 | + struct acl_object_label **obj_hash; | |
32773 | + __u32 obj_hash_size; | |
32774 | + __u16 pax_flags; | |
32775 | +}; | |
32776 | + | |
32777 | +struct role_allowed_ip { | |
32778 | + __u32 addr; | |
32779 | + __u32 netmask; | |
32780 | + | |
32781 | + struct role_allowed_ip *prev; | |
32782 | + struct role_allowed_ip *next; | |
32783 | +}; | |
32784 | + | |
32785 | +struct role_transition { | |
32786 | + char *rolename; | |
32787 | + | |
32788 | + struct role_transition *prev; | |
32789 | + struct role_transition *next; | |
32790 | +}; | |
32791 | + | |
32792 | +struct acl_role_label { | |
32793 | + char *rolename; | |
32794 | + uid_t uidgid; | |
32795 | + __u16 roletype; | |
32796 | + | |
32797 | + __u16 auth_attempts; | |
32798 | + unsigned long expires; | |
32799 | + | |
32800 | + struct acl_subject_label *root_label; | |
32801 | + struct gr_hash_struct *hash; | |
32802 | + | |
32803 | + struct acl_role_label *prev; | |
32804 | + struct acl_role_label *next; | |
32805 | + | |
32806 | + struct role_transition *transitions; | |
32807 | + struct role_allowed_ip *allowed_ips; | |
32808 | + uid_t *domain_children; | |
32809 | + __u16 domain_child_num; | |
32810 | + | |
32811 | + struct acl_subject_label **subj_hash; | |
32812 | + __u32 subj_hash_size; | |
32813 | +}; | |
32814 | + | |
32815 | +struct user_acl_role_db { | |
32816 | + struct acl_role_label **r_table; | |
32817 | + __u32 num_pointers; /* Number of allocations to track */ | |
32818 | + __u32 num_roles; /* Number of roles */ | |
32819 | + __u32 num_domain_children; /* Number of domain children */ | |
32820 | + __u32 num_subjects; /* Number of subjects */ | |
32821 | + __u32 num_objects; /* Number of objects */ | |
32822 | +}; | |
32823 | + | |
32824 | +struct acl_object_label { | |
32825 | + char *filename; | |
32826 | + ino_t inode; | |
32827 | + dev_t device; | |
32828 | + __u32 mode; | |
32829 | + | |
32830 | + struct acl_subject_label *nested; | |
32831 | + struct acl_object_label *globbed; | |
32832 | + | |
32833 | + /* next two structures not used */ | |
32834 | + | |
32835 | + struct acl_object_label *prev; | |
32836 | + struct acl_object_label *next; | |
32837 | +}; | |
32838 | + | |
32839 | +struct acl_ip_label { | |
32840 | + char *iface; | |
32841 | + __u32 addr; | |
32842 | + __u32 netmask; | |
32843 | + __u16 low, high; | |
32844 | + __u8 mode; | |
32845 | + __u32 type; | |
32846 | + __u32 proto[8]; | |
32847 | + | |
32848 | + /* next two structures not used */ | |
32849 | + | |
32850 | + struct acl_ip_label *prev; | |
32851 | + struct acl_ip_label *next; | |
32852 | +}; | |
32853 | + | |
32854 | +struct gr_arg { | |
32855 | + struct user_acl_role_db role_db; | |
32856 | + unsigned char pw[GR_PW_LEN]; | |
32857 | + unsigned char salt[GR_SALT_LEN]; | |
32858 | + unsigned char sum[GR_SHA_LEN]; | |
32859 | + unsigned char sp_role[GR_SPROLE_LEN]; | |
32860 | + struct sprole_pw *sprole_pws; | |
32861 | + dev_t segv_device; | |
32862 | + ino_t segv_inode; | |
32863 | + uid_t segv_uid; | |
32864 | + __u16 num_sprole_pws; | |
32865 | + __u16 mode; | |
32866 | +}; | |
32867 | + | |
32868 | +struct gr_arg_wrapper { | |
32869 | + struct gr_arg *arg; | |
32870 | + __u32 version; | |
32871 | + __u32 size; | |
32872 | +}; | |
32873 | + | |
32874 | +struct subject_map { | |
32875 | + struct acl_subject_label *user; | |
32876 | + struct acl_subject_label *kernel; | |
32877 | + struct subject_map *prev; | |
32878 | + struct subject_map *next; | |
32879 | +}; | |
32880 | + | |
32881 | +struct acl_subj_map_db { | |
32882 | + struct subject_map **s_hash; | |
32883 | + __u32 s_size; | |
32884 | +}; | |
32885 | + | |
32886 | +/* End Data Structures Section */ | |
32887 | + | |
32888 | +/* Hash functions generated by empirical testing by Brad Spengler | |
32889 | + Makes good use of the low bits of the inode. Generally 0-1 times | |
32890 | + in loop for successful match. 0-3 for unsuccessful match. | |
32891 | + Shift/add algorithm with modulus of table size and an XOR*/ | |
32892 | + | |
32893 | +static __inline__ unsigned int | |
32894 | +rhash(const uid_t uid, const __u16 type, const unsigned int sz) | |
32895 | +{ | |
32896 | + return (((uid << type) + (uid ^ type)) % sz); | |
32897 | +} | |
32898 | + | |
32899 | + static __inline__ unsigned int | |
32900 | +shash(const struct acl_subject_label *userp, const unsigned int sz) | |
32901 | +{ | |
32902 | + return ((const unsigned long)userp % sz); | |
32903 | +} | |
32904 | + | |
32905 | +static __inline__ unsigned int | |
32906 | +fhash(const ino_t ino, const dev_t dev, const unsigned int sz) | |
32907 | +{ | |
32908 | + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz); | |
32909 | +} | |
32910 | + | |
32911 | +static __inline__ unsigned int | |
32912 | +nhash(const char *name, const __u16 len, const unsigned int sz) | |
32913 | +{ | |
32914 | + return full_name_hash(name, len) % sz; | |
32915 | +} | |
32916 | + | |
32917 | +#define FOR_EACH_ROLE_START(role,iter) \ | |
32918 | + role = NULL; \ | |
32919 | + iter = 0; \ | |
32920 | + while (iter < acl_role_set.r_size) { \ | |
32921 | + if (role == NULL) \ | |
32922 | + role = acl_role_set.r_hash[iter]; \ | |
32923 | + if (role == NULL) { \ | |
32924 | + iter++; \ | |
32925 | + continue; \ | |
32926 | + } | |
32927 | + | |
32928 | +#define FOR_EACH_ROLE_END(role,iter) \ | |
32929 | + role = role->next; \ | |
32930 | + if (role == NULL) \ | |
32931 | + iter++; \ | |
32932 | + } | |
32933 | + | |
32934 | +#define FOR_EACH_SUBJECT_START(role,subj,iter) \ | |
32935 | + subj = NULL; \ | |
32936 | + iter = 0; \ | |
32937 | + while (iter < role->subj_hash_size) { \ | |
32938 | + if (subj == NULL) \ | |
32939 | + subj = role->subj_hash[iter]; \ | |
32940 | + if (subj == NULL) { \ | |
32941 | + iter++; \ | |
32942 | + continue; \ | |
32943 | + } | |
32944 | + | |
32945 | +#define FOR_EACH_SUBJECT_END(subj,iter) \ | |
32946 | + subj = subj->next; \ | |
32947 | + if (subj == NULL) \ | |
32948 | + iter++; \ | |
32949 | + } | |
32950 | + | |
32951 | + | |
32952 | +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \ | |
32953 | + subj = role->hash->first; \ | |
32954 | + while (subj != NULL) { | |
32955 | + | |
32956 | +#define FOR_EACH_NESTED_SUBJECT_END(subj) \ | |
32957 | + subj = subj->next; \ | |
32958 | + } | |
32959 | + | |
32960 | +#endif | |
32961 | + | |
de855c5d AM |
32962 | diff -urNp linux-2.6.29.6/include/linux/gralloc.h linux-2.6.29.6/include/linux/gralloc.h |
32963 | --- linux-2.6.29.6/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500 | |
32964 | +++ linux-2.6.29.6/include/linux/gralloc.h 2009-07-09 22:13:39.000000000 -0400 | |
32965 | @@ -0,0 +1,9 @@ | |
2380c486 JR |
32966 | +#ifndef __GRALLOC_H |
32967 | +#define __GRALLOC_H | |
32968 | + | |
32969 | +void acl_free_all(void); | |
32970 | +int acl_alloc_stack_init(unsigned long size); | |
32971 | +void *acl_alloc(unsigned long len); | |
de855c5d | 32972 | +void *acl_alloc_num(unsigned long num, unsigned long len); |
2380c486 JR |
32973 | + |
32974 | +#endif | |
de855c5d AM |
32975 | diff -urNp linux-2.6.29.6/include/linux/grdefs.h linux-2.6.29.6/include/linux/grdefs.h |
32976 | --- linux-2.6.29.6/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500 | |
32977 | +++ linux-2.6.29.6/include/linux/grdefs.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
32978 | @@ -0,0 +1,136 @@ |
32979 | +#ifndef GRDEFS_H | |
32980 | +#define GRDEFS_H | |
32981 | + | |
32982 | +/* Begin grsecurity status declarations */ | |
32983 | + | |
32984 | +enum { | |
32985 | + GR_READY = 0x01, | |
32986 | + GR_STATUS_INIT = 0x00 // disabled state | |
32987 | +}; | |
32988 | + | |
32989 | +/* Begin ACL declarations */ | |
32990 | + | |
32991 | +/* Role flags */ | |
32992 | + | |
32993 | +enum { | |
32994 | + GR_ROLE_USER = 0x0001, | |
32995 | + GR_ROLE_GROUP = 0x0002, | |
32996 | + GR_ROLE_DEFAULT = 0x0004, | |
32997 | + GR_ROLE_SPECIAL = 0x0008, | |
32998 | + GR_ROLE_AUTH = 0x0010, | |
32999 | + GR_ROLE_NOPW = 0x0020, | |
33000 | + GR_ROLE_GOD = 0x0040, | |
33001 | + GR_ROLE_LEARN = 0x0080, | |
33002 | + GR_ROLE_TPE = 0x0100, | |
33003 | + GR_ROLE_DOMAIN = 0x0200, | |
33004 | + GR_ROLE_PAM = 0x0400 | |
33005 | +}; | |
33006 | + | |
33007 | +/* ACL Subject and Object mode flags */ | |
33008 | +enum { | |
33009 | + GR_DELETED = 0x80000000 | |
33010 | +}; | |
33011 | + | |
33012 | +/* ACL Object-only mode flags */ | |
33013 | +enum { | |
33014 | + GR_READ = 0x00000001, | |
33015 | + GR_APPEND = 0x00000002, | |
33016 | + GR_WRITE = 0x00000004, | |
33017 | + GR_EXEC = 0x00000008, | |
33018 | + GR_FIND = 0x00000010, | |
33019 | + GR_INHERIT = 0x00000020, | |
33020 | + GR_SETID = 0x00000040, | |
33021 | + GR_CREATE = 0x00000080, | |
33022 | + GR_DELETE = 0x00000100, | |
33023 | + GR_LINK = 0x00000200, | |
33024 | + GR_AUDIT_READ = 0x00000400, | |
33025 | + GR_AUDIT_APPEND = 0x00000800, | |
33026 | + GR_AUDIT_WRITE = 0x00001000, | |
33027 | + GR_AUDIT_EXEC = 0x00002000, | |
33028 | + GR_AUDIT_FIND = 0x00004000, | |
33029 | + GR_AUDIT_INHERIT= 0x00008000, | |
33030 | + GR_AUDIT_SETID = 0x00010000, | |
33031 | + GR_AUDIT_CREATE = 0x00020000, | |
33032 | + GR_AUDIT_DELETE = 0x00040000, | |
33033 | + GR_AUDIT_LINK = 0x00080000, | |
33034 | + GR_PTRACERD = 0x00100000, | |
33035 | + GR_NOPTRACE = 0x00200000, | |
33036 | + GR_SUPPRESS = 0x00400000, | |
33037 | + GR_NOLEARN = 0x00800000 | |
33038 | +}; | |
33039 | + | |
33040 | +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \ | |
33041 | + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \ | |
33042 | + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK) | |
33043 | + | |
33044 | +/* ACL subject-only mode flags */ | |
33045 | +enum { | |
33046 | + GR_KILL = 0x00000001, | |
33047 | + GR_VIEW = 0x00000002, | |
33048 | + GR_PROTECTED = 0x00000004, | |
33049 | + GR_LEARN = 0x00000008, | |
33050 | + GR_OVERRIDE = 0x00000010, | |
33051 | + /* just a placeholder, this mode is only used in userspace */ | |
33052 | + GR_DUMMY = 0x00000020, | |
33053 | + GR_PROTSHM = 0x00000040, | |
33054 | + GR_KILLPROC = 0x00000080, | |
33055 | + GR_KILLIPPROC = 0x00000100, | |
33056 | + /* just a placeholder, this mode is only used in userspace */ | |
33057 | + GR_NOTROJAN = 0x00000200, | |
33058 | + GR_PROTPROCFD = 0x00000400, | |
33059 | + GR_PROCACCT = 0x00000800, | |
33060 | + GR_RELAXPTRACE = 0x00001000, | |
33061 | + GR_NESTED = 0x00002000, | |
33062 | + GR_INHERITLEARN = 0x00004000, | |
33063 | + GR_PROCFIND = 0x00008000, | |
33064 | + GR_POVERRIDE = 0x00010000, | |
33065 | + GR_KERNELAUTH = 0x00020000, | |
33066 | +}; | |
33067 | + | |
33068 | +enum { | |
33069 | + GR_PAX_ENABLE_SEGMEXEC = 0x0001, | |
33070 | + GR_PAX_ENABLE_PAGEEXEC = 0x0002, | |
33071 | + GR_PAX_ENABLE_MPROTECT = 0x0004, | |
33072 | + GR_PAX_ENABLE_RANDMMAP = 0x0008, | |
33073 | + GR_PAX_ENABLE_EMUTRAMP = 0x0010, | |
33074 | + GR_PAX_DISABLE_SEGMEXEC = 0x0100, | |
33075 | + GR_PAX_DISABLE_PAGEEXEC = 0x0200, | |
33076 | + GR_PAX_DISABLE_MPROTECT = 0x0400, | |
33077 | + GR_PAX_DISABLE_RANDMMAP = 0x0800, | |
33078 | + GR_PAX_DISABLE_EMUTRAMP = 0x1000, | |
33079 | +}; | |
33080 | + | |
33081 | +enum { | |
33082 | + GR_ID_USER = 0x01, | |
33083 | + GR_ID_GROUP = 0x02, | |
33084 | +}; | |
33085 | + | |
33086 | +enum { | |
33087 | + GR_ID_ALLOW = 0x01, | |
33088 | + GR_ID_DENY = 0x02, | |
33089 | +}; | |
33090 | + | |
33091 | +#define GR_CRASH_RES 31 | |
33092 | +#define GR_UIDTABLE_MAX 500 | |
33093 | + | |
33094 | +/* begin resource learning section */ | |
33095 | +enum { | |
33096 | + GR_RLIM_CPU_BUMP = 60, | |
33097 | + GR_RLIM_FSIZE_BUMP = 50000, | |
33098 | + GR_RLIM_DATA_BUMP = 10000, | |
33099 | + GR_RLIM_STACK_BUMP = 1000, | |
33100 | + GR_RLIM_CORE_BUMP = 10000, | |
33101 | + GR_RLIM_RSS_BUMP = 500000, | |
33102 | + GR_RLIM_NPROC_BUMP = 1, | |
33103 | + GR_RLIM_NOFILE_BUMP = 5, | |
33104 | + GR_RLIM_MEMLOCK_BUMP = 50000, | |
33105 | + GR_RLIM_AS_BUMP = 500000, | |
33106 | + GR_RLIM_LOCKS_BUMP = 2, | |
33107 | + GR_RLIM_SIGPENDING_BUMP = 5, | |
33108 | + GR_RLIM_MSGQUEUE_BUMP = 10000, | |
33109 | + GR_RLIM_NICE_BUMP = 1, | |
33110 | + GR_RLIM_RTPRIO_BUMP = 1, | |
33111 | + GR_RLIM_RTTIME_BUMP = 1000000 | |
33112 | +}; | |
33113 | + | |
33114 | +#endif | |
de855c5d AM |
33115 | diff -urNp linux-2.6.29.6/include/linux/grinternal.h linux-2.6.29.6/include/linux/grinternal.h |
33116 | --- linux-2.6.29.6/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500 | |
33117 | +++ linux-2.6.29.6/include/linux/grinternal.h 2009-07-09 22:13:39.000000000 -0400 | |
33118 | @@ -0,0 +1,211 @@ | |
2380c486 JR |
33119 | +#ifndef __GRINTERNAL_H |
33120 | +#define __GRINTERNAL_H | |
33121 | + | |
33122 | +#ifdef CONFIG_GRKERNSEC | |
33123 | + | |
33124 | +#include <linux/fs.h> | |
33125 | +#include <linux/gracl.h> | |
33126 | +#include <linux/grdefs.h> | |
33127 | +#include <linux/grmsg.h> | |
33128 | + | |
de855c5d AM |
33129 | +void gr_add_learn_entry(const char *fmt, ...) |
33130 | + __attribute__ ((format (printf, 1, 2))); | |
2380c486 JR |
33131 | +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode, |
33132 | + const struct vfsmount *mnt); | |
33133 | +__u32 gr_check_create(const struct dentry *new_dentry, | |
33134 | + const struct dentry *parent, | |
33135 | + const struct vfsmount *mnt, const __u32 mode); | |
33136 | +int gr_check_protected_task(const struct task_struct *task); | |
33137 | +__u32 to_gr_audit(const __u32 reqmode); | |
33138 | +int gr_set_acls(const int type); | |
33139 | + | |
33140 | +int gr_acl_is_enabled(void); | |
33141 | +char gr_roletype_to_char(void); | |
33142 | + | |
33143 | +void gr_handle_alertkill(struct task_struct *task); | |
33144 | +char *gr_to_filename(const struct dentry *dentry, | |
33145 | + const struct vfsmount *mnt); | |
33146 | +char *gr_to_filename1(const struct dentry *dentry, | |
33147 | + const struct vfsmount *mnt); | |
33148 | +char *gr_to_filename2(const struct dentry *dentry, | |
33149 | + const struct vfsmount *mnt); | |
33150 | +char *gr_to_filename3(const struct dentry *dentry, | |
33151 | + const struct vfsmount *mnt); | |
33152 | + | |
33153 | +extern int grsec_enable_link; | |
33154 | +extern int grsec_enable_fifo; | |
33155 | +extern int grsec_enable_execve; | |
33156 | +extern int grsec_enable_shm; | |
33157 | +extern int grsec_enable_execlog; | |
33158 | +extern int grsec_enable_signal; | |
33159 | +extern int grsec_enable_forkfail; | |
33160 | +extern int grsec_enable_time; | |
33161 | +extern int grsec_enable_chroot_shmat; | |
33162 | +extern int grsec_enable_chroot_findtask; | |
33163 | +extern int grsec_enable_chroot_mount; | |
33164 | +extern int grsec_enable_chroot_double; | |
33165 | +extern int grsec_enable_chroot_pivot; | |
33166 | +extern int grsec_enable_chroot_chdir; | |
33167 | +extern int grsec_enable_chroot_chmod; | |
33168 | +extern int grsec_enable_chroot_mknod; | |
33169 | +extern int grsec_enable_chroot_fchdir; | |
33170 | +extern int grsec_enable_chroot_nice; | |
33171 | +extern int grsec_enable_chroot_execlog; | |
33172 | +extern int grsec_enable_chroot_caps; | |
33173 | +extern int grsec_enable_chroot_sysctl; | |
33174 | +extern int grsec_enable_chroot_unix; | |
33175 | +extern int grsec_enable_tpe; | |
33176 | +extern int grsec_tpe_gid; | |
33177 | +extern int grsec_enable_tpe_all; | |
33178 | +extern int grsec_enable_sidcaps; | |
33179 | +extern int grsec_enable_socket_all; | |
33180 | +extern int grsec_socket_all_gid; | |
33181 | +extern int grsec_enable_socket_client; | |
33182 | +extern int grsec_socket_client_gid; | |
33183 | +extern int grsec_enable_socket_server; | |
33184 | +extern int grsec_socket_server_gid; | |
33185 | +extern int grsec_audit_gid; | |
33186 | +extern int grsec_enable_group; | |
33187 | +extern int grsec_enable_audit_ipc; | |
33188 | +extern int grsec_enable_audit_textrel; | |
33189 | +extern int grsec_enable_mount; | |
33190 | +extern int grsec_enable_chdir; | |
33191 | +extern int grsec_resource_logging; | |
33192 | +extern int grsec_lock; | |
33193 | + | |
33194 | +extern spinlock_t grsec_alert_lock; | |
33195 | +extern unsigned long grsec_alert_wtime; | |
33196 | +extern unsigned long grsec_alert_fyet; | |
33197 | + | |
33198 | +extern spinlock_t grsec_audit_lock; | |
33199 | + | |
33200 | +extern rwlock_t grsec_exec_file_lock; | |
33201 | + | |
33202 | +#define gr_task_fullpath(tsk) (tsk->exec_file ? \ | |
33203 | + gr_to_filename2(tsk->exec_file->f_path.dentry, \ | |
33204 | + tsk->exec_file->f_vfsmnt) : "/") | |
33205 | + | |
33206 | +#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \ | |
33207 | + gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \ | |
33208 | + tsk->parent->exec_file->f_vfsmnt) : "/") | |
33209 | + | |
33210 | +#define gr_task_fullpath0(tsk) (tsk->exec_file ? \ | |
33211 | + gr_to_filename(tsk->exec_file->f_path.dentry, \ | |
33212 | + tsk->exec_file->f_vfsmnt) : "/") | |
33213 | + | |
33214 | +#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \ | |
33215 | + gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \ | |
33216 | + tsk->parent->exec_file->f_vfsmnt) : "/") | |
33217 | + | |
33218 | +#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \ | |
33219 | + ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \ | |
33220 | + tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \ | |
33221 | + (tsk_a->fs->root.dentry->d_inode->i_ino != \ | |
33222 | + tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino))) | |
33223 | + | |
33224 | +#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \ | |
33225 | + (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \ | |
33226 | + tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \ | |
33227 | + (tsk_a->fs->root.dentry->d_inode->i_ino == \ | |
33228 | + tsk_b->fs->root.dentry->d_inode->i_ino)) | |
33229 | + | |
33230 | +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), task->comm, \ | |
33231 | + task->pid, cred->uid, \ | |
33232 | + cred->euid, cred->gid, cred->egid, \ | |
33233 | + gr_parent_task_fullpath(task), \ | |
33234 | + task->parent->comm, task->parent->pid, \ | |
33235 | + pcred->uid, pcred->euid, \ | |
33236 | + pcred->gid, pcred->egid | |
33237 | + | |
33238 | +#define GR_CHROOT_CAPS {{ \ | |
33239 | + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \ | |
33240 | + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \ | |
33241 | + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \ | |
33242 | + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \ | |
33243 | + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \ | |
33244 | + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }} | |
33245 | + | |
33246 | +#define security_learn(normal_msg,args...) \ | |
33247 | +({ \ | |
33248 | + read_lock(&grsec_exec_file_lock); \ | |
33249 | + gr_add_learn_entry(normal_msg "\n", ## args); \ | |
33250 | + read_unlock(&grsec_exec_file_lock); \ | |
33251 | +}) | |
33252 | + | |
33253 | +enum { | |
33254 | + GR_DO_AUDIT, | |
33255 | + GR_DONT_AUDIT, | |
33256 | + GR_DONT_AUDIT_GOOD | |
33257 | +}; | |
33258 | + | |
33259 | +enum { | |
33260 | + GR_TTYSNIFF, | |
33261 | + GR_RBAC, | |
33262 | + GR_RBAC_STR, | |
33263 | + GR_STR_RBAC, | |
33264 | + GR_RBAC_MODE2, | |
33265 | + GR_RBAC_MODE3, | |
33266 | + GR_FILENAME, | |
33267 | + GR_SYSCTL_HIDDEN, | |
33268 | + GR_NOARGS, | |
33269 | + GR_ONE_INT, | |
33270 | + GR_ONE_INT_TWO_STR, | |
33271 | + GR_ONE_STR, | |
33272 | + GR_STR_INT, | |
33273 | + GR_TWO_INT, | |
33274 | + GR_THREE_INT, | |
33275 | + GR_FIVE_INT_TWO_STR, | |
33276 | + GR_TWO_STR, | |
33277 | + GR_THREE_STR, | |
33278 | + GR_FOUR_STR, | |
33279 | + GR_STR_FILENAME, | |
33280 | + GR_FILENAME_STR, | |
33281 | + GR_FILENAME_TWO_INT, | |
33282 | + GR_FILENAME_TWO_INT_STR, | |
33283 | + GR_TEXTREL, | |
33284 | + GR_PTRACE, | |
33285 | + GR_RESOURCE, | |
33286 | + GR_CAP, | |
33287 | + GR_SIG, | |
33288 | + GR_CRASH1, | |
33289 | + GR_CRASH2, | |
33290 | + GR_PSACCT | |
33291 | +}; | |
33292 | + | |
33293 | +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str) | |
33294 | +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task) | |
33295 | +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt) | |
33296 | +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str) | |
33297 | +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt) | |
33298 | +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2) | |
33299 | +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3) | |
33300 | +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt) | |
33301 | +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS) | |
33302 | +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num) | |
33303 | +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2) | |
33304 | +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str) | |
33305 | +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num) | |
33306 | +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2) | |
33307 | +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3) | |
33308 | +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2) | |
33309 | +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2) | |
33310 | +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3) | |
33311 | +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4) | |
33312 | +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt) | |
33313 | +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str) | |
33314 | +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2) | |
33315 | +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str) | |
33316 | +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2) | |
33317 | +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task) | |
33318 | +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2) | |
33319 | +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str) | |
33320 | +#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num) | |
33321 | +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong) | |
33322 | +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1) | |
33323 | +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) | |
33324 | + | |
33325 | +void gr_log_varargs(int audit, const char *msg, int argtypes, ...); | |
33326 | + | |
33327 | +#endif | |
33328 | + | |
33329 | +#endif | |
de855c5d AM |
33330 | diff -urNp linux-2.6.29.6/include/linux/grmsg.h linux-2.6.29.6/include/linux/grmsg.h |
33331 | --- linux-2.6.29.6/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500 | |
33332 | +++ linux-2.6.29.6/include/linux/grmsg.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33333 | @@ -0,0 +1,108 @@ |
33334 | +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u" | |
33335 | +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u" | |
33336 | +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by " | |
33337 | +#define GR_STOPMOD_MSG "denied modification of module state by " | |
33338 | +#define GR_IOPERM_MSG "denied use of ioperm() by " | |
33339 | +#define GR_IOPL_MSG "denied use of iopl() by " | |
33340 | +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by " | |
33341 | +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by " | |
33342 | +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by " | |
33343 | +#define GR_KMEM_MSG "denied write of /dev/kmem by " | |
33344 | +#define GR_PORT_OPEN_MSG "denied open of /dev/port by " | |
33345 | +#define GR_MEM_WRITE_MSG "denied write of /dev/mem by " | |
33346 | +#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by " | |
33347 | +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by " | |
33348 | +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%u.%u.%u.%u" | |
33349 | +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%u.%u.%u.%u" | |
33350 | +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by " | |
33351 | +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by " | |
33352 | +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by " | |
33353 | +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by " | |
33354 | +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by " | |
33355 | +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by " | |
33356 | +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by " | |
33357 | +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against " | |
33358 | +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by " | |
33359 | +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by " | |
33360 | +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by " | |
33361 | +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by " | |
33362 | +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for " | |
33363 | +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by " | |
33364 | +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by " | |
33365 | +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by " | |
33366 | +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by " | |
33367 | +#define GR_NPROC_MSG "denied overstep of process limit by " | |
33368 | +#define GR_EXEC_ACL_MSG "%s execution of %.950s by " | |
33369 | +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by " | |
33370 | +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds" | |
33371 | +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds" | |
33372 | +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by " | |
33373 | +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by " | |
33374 | +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by " | |
33375 | +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by " | |
33376 | +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by " | |
33377 | +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by " | |
33378 | +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by " | |
33379 | +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by " | |
33380 | +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by " | |
33381 | +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by " | |
33382 | +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by " | |
33383 | +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by " | |
33384 | +#define GR_INITF_ACL_MSG "init_variables() failed %s by " | |
33385 | +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader" | |
33386 | +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by " | |
33387 | +#define GR_SHUTS_ACL_MSG "shutdown auth success for " | |
33388 | +#define GR_SHUTF_ACL_MSG "shutdown auth failure for " | |
33389 | +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for " | |
33390 | +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for " | |
33391 | +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for " | |
33392 | +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for " | |
33393 | +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by " | |
33394 | +#define GR_ENABLEF_ACL_MSG "unable to load %s for " | |
33395 | +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system" | |
33396 | +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by " | |
33397 | +#define GR_RELOADF_ACL_MSG "failed reload of %s for " | |
33398 | +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for " | |
33399 | +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by " | |
33400 | +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by " | |
33401 | +#define GR_SPROLEF_ACL_MSG "special role %s failure for " | |
33402 | +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for " | |
33403 | +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by " | |
33404 | +#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for " | |
33405 | +#define GR_INVMODE_ACL_MSG "invalid mode %d by " | |
33406 | +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by " | |
33407 | +#define GR_FAILFORK_MSG "failed fork with errno %d by " | |
33408 | +#define GR_NICE_CHROOT_MSG "denied priority change by " | |
33409 | +#define GR_UNISIGLOG_MSG "signal %d sent to " | |
33410 | +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by " | |
33411 | +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by " | |
33412 | +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by " | |
33413 | +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by " | |
33414 | +#define GR_TIME_MSG "time set by " | |
33415 | +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by " | |
33416 | +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by " | |
33417 | +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by " | |
33418 | +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by " | |
33419 | +#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by " | |
33420 | +#define GR_BIND_MSG "denied bind() by " | |
33421 | +#define GR_CONNECT_MSG "denied connect() by " | |
33422 | +#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by " | |
33423 | +#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by " | |
33424 | +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%u.%u.%u.%u\t%u\t%u\t%u\t%u\t%u.%u.%u.%u" | |
33425 | +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process " | |
33426 | +#define GR_CAP_ACL_MSG "use of %s denied for " | |
33427 | +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for " | |
33428 | +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for " | |
33429 | +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by " | |
33430 | +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by " | |
33431 | +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by " | |
33432 | +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by " | |
33433 | +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by " | |
33434 | +#define GR_MSGQ_AUDIT_MSG "message queue created by " | |
33435 | +#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by " | |
33436 | +#define GR_SEM_AUDIT_MSG "semaphore created by " | |
33437 | +#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by " | |
33438 | +#define GR_SHM_AUDIT_MSG "shared memory of size %d created by " | |
33439 | +#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by " | |
33440 | +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for " | |
33441 | +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by " | |
de855c5d AM |
33442 | diff -urNp linux-2.6.29.6/include/linux/grsecurity.h linux-2.6.29.6/include/linux/grsecurity.h |
33443 | --- linux-2.6.29.6/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500 | |
33444 | +++ linux-2.6.29.6/include/linux/grsecurity.h 2009-07-09 23:21:34.000000000 -0400 | |
33445 | @@ -0,0 +1,201 @@ | |
2380c486 JR |
33446 | +#ifndef GR_SECURITY_H |
33447 | +#define GR_SECURITY_H | |
33448 | +#include <linux/fs.h> | |
33449 | +#include <linux/binfmts.h> | |
33450 | +#include <linux/gracl.h> | |
33451 | + | |
33452 | +/* notify of brain-dead configs */ | |
33453 | +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC) | |
33454 | +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled." | |
33455 | +#endif | |
33456 | +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS) | |
33457 | +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled." | |
33458 | +#endif | |
33459 | +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS) | |
33460 | +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled." | |
33461 | +#endif | |
33462 | +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP) | |
33463 | +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled." | |
33464 | +#endif | |
33465 | +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR) | |
33466 | +#error "CONFIG_PAX enabled, but no PaX options are enabled." | |
33467 | +#endif | |
33468 | + | |
33469 | +void gr_handle_brute_attach(struct task_struct *p); | |
33470 | +void gr_handle_brute_check(void); | |
33471 | + | |
33472 | +char gr_roletype_to_char(void); | |
33473 | + | |
33474 | +int gr_check_user_change(int real, int effective, int fs); | |
33475 | +int gr_check_group_change(int real, int effective, int fs); | |
33476 | + | |
33477 | +void gr_del_task_from_ip_table(struct task_struct *p); | |
33478 | + | |
33479 | +int gr_pid_is_chrooted(struct task_struct *p); | |
33480 | +int gr_handle_chroot_nice(void); | |
33481 | +int gr_handle_chroot_sysctl(const int op); | |
33482 | +int gr_handle_chroot_setpriority(struct task_struct *p, | |
33483 | + const int niceval); | |
33484 | +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt); | |
33485 | +int gr_handle_chroot_chroot(const struct dentry *dentry, | |
33486 | + const struct vfsmount *mnt); | |
33487 | +int gr_handle_chroot_caps(struct path *path); | |
33488 | +void gr_handle_chroot_chdir(struct path *path); | |
33489 | +int gr_handle_chroot_chmod(const struct dentry *dentry, | |
33490 | + const struct vfsmount *mnt, const int mode); | |
33491 | +int gr_handle_chroot_mknod(const struct dentry *dentry, | |
33492 | + const struct vfsmount *mnt, const int mode); | |
33493 | +int gr_handle_chroot_mount(const struct dentry *dentry, | |
33494 | + const struct vfsmount *mnt, | |
33495 | + const char *dev_name); | |
33496 | +int gr_handle_chroot_pivot(void); | |
33497 | +int gr_handle_chroot_unix(const pid_t pid); | |
33498 | + | |
33499 | +int gr_handle_rawio(const struct inode *inode); | |
33500 | +int gr_handle_nproc(void); | |
33501 | + | |
33502 | +void gr_handle_ioperm(void); | |
33503 | +void gr_handle_iopl(void); | |
33504 | + | |
33505 | +int gr_tpe_allow(const struct file *file); | |
33506 | + | |
33507 | +int gr_random_pid(void); | |
33508 | + | |
33509 | +void gr_log_forkfail(const int retval); | |
33510 | +void gr_log_timechange(void); | |
33511 | +void gr_log_signal(const int sig, const struct task_struct *t); | |
33512 | +void gr_log_chdir(const struct dentry *dentry, | |
33513 | + const struct vfsmount *mnt); | |
33514 | +void gr_log_chroot_exec(const struct dentry *dentry, | |
33515 | + const struct vfsmount *mnt); | |
33516 | +void gr_handle_exec_args(struct linux_binprm *bprm, char **argv); | |
33517 | +void gr_log_remount(const char *devname, const int retval); | |
33518 | +void gr_log_unmount(const char *devname, const int retval); | |
33519 | +void gr_log_mount(const char *from, const char *to, const int retval); | |
33520 | +void gr_log_msgget(const int ret, const int msgflg); | |
33521 | +void gr_log_msgrm(const uid_t uid, const uid_t cuid); | |
33522 | +void gr_log_semget(const int err, const int semflg); | |
33523 | +void gr_log_semrm(const uid_t uid, const uid_t cuid); | |
33524 | +void gr_log_shmget(const int err, const int shmflg, const size_t size); | |
33525 | +void gr_log_shmrm(const uid_t uid, const uid_t cuid); | |
33526 | +void gr_log_textrel(struct vm_area_struct *vma); | |
33527 | + | |
33528 | +int gr_handle_follow_link(const struct inode *parent, | |
33529 | + const struct inode *inode, | |
33530 | + const struct dentry *dentry, | |
33531 | + const struct vfsmount *mnt); | |
33532 | +int gr_handle_fifo(const struct dentry *dentry, | |
33533 | + const struct vfsmount *mnt, | |
33534 | + const struct dentry *dir, const int flag, | |
33535 | + const int acc_mode); | |
33536 | +int gr_handle_hardlink(const struct dentry *dentry, | |
33537 | + const struct vfsmount *mnt, | |
33538 | + struct inode *inode, | |
33539 | + const int mode, const char *to); | |
33540 | + | |
33541 | +int gr_is_capable(const int cap); | |
33542 | +int gr_is_capable_nolog(const int cap); | |
33543 | +void gr_learn_resource(const struct task_struct *task, const int limit, | |
33544 | + const unsigned long wanted, const int gt); | |
33545 | +void gr_copy_label(struct task_struct *tsk); | |
33546 | +void gr_handle_crash(struct task_struct *task, const int sig); | |
33547 | +int gr_handle_signal(const struct task_struct *p, const int sig); | |
33548 | +int gr_check_crash_uid(const uid_t uid); | |
33549 | +int gr_check_protected_task(const struct task_struct *task); | |
33550 | +int gr_acl_handle_mmap(const struct file *file, | |
33551 | + const unsigned long prot); | |
33552 | +int gr_acl_handle_mprotect(const struct file *file, | |
33553 | + const unsigned long prot); | |
33554 | +int gr_check_hidden_task(const struct task_struct *tsk); | |
33555 | +__u32 gr_acl_handle_truncate(const struct dentry *dentry, | |
33556 | + const struct vfsmount *mnt); | |
33557 | +__u32 gr_acl_handle_utime(const struct dentry *dentry, | |
33558 | + const struct vfsmount *mnt); | |
33559 | +__u32 gr_acl_handle_access(const struct dentry *dentry, | |
33560 | + const struct vfsmount *mnt, const int fmode); | |
33561 | +__u32 gr_acl_handle_fchmod(const struct dentry *dentry, | |
33562 | + const struct vfsmount *mnt, mode_t mode); | |
33563 | +__u32 gr_acl_handle_chmod(const struct dentry *dentry, | |
33564 | + const struct vfsmount *mnt, mode_t mode); | |
33565 | +__u32 gr_acl_handle_chown(const struct dentry *dentry, | |
33566 | + const struct vfsmount *mnt); | |
33567 | +int gr_handle_ptrace(struct task_struct *task, const long request); | |
33568 | +int gr_handle_proc_ptrace(struct task_struct *task); | |
33569 | +__u32 gr_acl_handle_execve(const struct dentry *dentry, | |
33570 | + const struct vfsmount *mnt); | |
33571 | +int gr_check_crash_exec(const struct file *filp); | |
33572 | +int gr_acl_is_enabled(void); | |
33573 | +void gr_set_kernel_label(struct task_struct *task); | |
33574 | +void gr_set_role_label(struct task_struct *task, const uid_t uid, | |
33575 | + const gid_t gid); | |
33576 | +int gr_set_proc_label(const struct dentry *dentry, | |
de855c5d AM |
33577 | + const struct vfsmount *mnt, |
33578 | + const int unsafe_share); | |
2380c486 | 33579 | +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry, |
de855c5d | 33580 | + const struct vfsmount *mnt); |
2380c486 JR |
33581 | +__u32 gr_acl_handle_open(const struct dentry *dentry, |
33582 | + const struct vfsmount *mnt, const int fmode); | |
33583 | +__u32 gr_acl_handle_creat(const struct dentry *dentry, | |
33584 | + const struct dentry *p_dentry, | |
33585 | + const struct vfsmount *p_mnt, const int fmode, | |
33586 | + const int imode); | |
33587 | +void gr_handle_create(const struct dentry *dentry, | |
33588 | + const struct vfsmount *mnt); | |
33589 | +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry, | |
33590 | + const struct dentry *parent_dentry, | |
33591 | + const struct vfsmount *parent_mnt, | |
33592 | + const int mode); | |
33593 | +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry, | |
33594 | + const struct dentry *parent_dentry, | |
33595 | + const struct vfsmount *parent_mnt); | |
33596 | +__u32 gr_acl_handle_rmdir(const struct dentry *dentry, | |
33597 | + const struct vfsmount *mnt); | |
33598 | +void gr_handle_delete(const ino_t ino, const dev_t dev); | |
33599 | +__u32 gr_acl_handle_unlink(const struct dentry *dentry, | |
33600 | + const struct vfsmount *mnt); | |
33601 | +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry, | |
33602 | + const struct dentry *parent_dentry, | |
33603 | + const struct vfsmount *parent_mnt, | |
33604 | + const char *from); | |
33605 | +__u32 gr_acl_handle_link(const struct dentry *new_dentry, | |
33606 | + const struct dentry *parent_dentry, | |
33607 | + const struct vfsmount *parent_mnt, | |
33608 | + const struct dentry *old_dentry, | |
33609 | + const struct vfsmount *old_mnt, const char *to); | |
33610 | +int gr_acl_handle_rename(struct dentry *new_dentry, | |
33611 | + struct dentry *parent_dentry, | |
33612 | + const struct vfsmount *parent_mnt, | |
33613 | + struct dentry *old_dentry, | |
33614 | + struct inode *old_parent_inode, | |
33615 | + struct vfsmount *old_mnt, const char *newname); | |
33616 | +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir, | |
33617 | + struct dentry *old_dentry, | |
33618 | + struct dentry *new_dentry, | |
33619 | + struct vfsmount *mnt, const __u8 replace); | |
33620 | +__u32 gr_check_link(const struct dentry *new_dentry, | |
33621 | + const struct dentry *parent_dentry, | |
33622 | + const struct vfsmount *parent_mnt, | |
33623 | + const struct dentry *old_dentry, | |
33624 | + const struct vfsmount *old_mnt); | |
33625 | +int gr_acl_handle_filldir(const struct file *file, const char *name, | |
33626 | + const unsigned int namelen, const ino_t ino); | |
33627 | + | |
33628 | +__u32 gr_acl_handle_unix(const struct dentry *dentry, | |
33629 | + const struct vfsmount *mnt); | |
33630 | +void gr_acl_handle_exit(void); | |
33631 | +void gr_acl_handle_psacct(struct task_struct *task, const long code); | |
33632 | +int gr_acl_handle_procpidmem(const struct task_struct *task); | |
33633 | + | |
33634 | +#ifdef CONFIG_GRKERNSEC | |
33635 | +void gr_handle_mem_write(void); | |
33636 | +void gr_handle_kmem_write(void); | |
33637 | +void gr_handle_open_port(void); | |
33638 | +int gr_handle_mem_mmap(const unsigned long offset, | |
33639 | + struct vm_area_struct *vma); | |
33640 | + | |
33641 | +extern int grsec_enable_dmesg; | |
33642 | +extern int grsec_enable_randsrc; | |
33643 | +extern int grsec_enable_shm; | |
33644 | +#endif | |
33645 | + | |
33646 | +#endif | |
de855c5d AM |
33647 | diff -urNp linux-2.6.29.6/include/linux/highmem.h linux-2.6.29.6/include/linux/highmem.h |
33648 | --- linux-2.6.29.6/include/linux/highmem.h 2009-07-02 19:41:20.000000000 -0400 | |
33649 | +++ linux-2.6.29.6/include/linux/highmem.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33650 | @@ -124,6 +124,18 @@ static inline void clear_highpage(struct |
33651 | kunmap_atomic(kaddr, KM_USER0); | |
33652 | } | |
33653 | ||
33654 | +static inline void sanitize_highpage(struct page *page) | |
33655 | +{ | |
33656 | + void *kaddr; | |
33657 | + unsigned long flags; | |
33658 | + | |
33659 | + local_irq_save(flags); | |
33660 | + kaddr = kmap_atomic(page, KM_CLEARPAGE); | |
33661 | + clear_page(kaddr); | |
33662 | + kunmap_atomic(kaddr, KM_CLEARPAGE); | |
33663 | + local_irq_restore(flags); | |
33664 | +} | |
33665 | + | |
33666 | static inline void zero_user_segments(struct page *page, | |
33667 | unsigned start1, unsigned end1, | |
33668 | unsigned start2, unsigned end2) | |
de855c5d AM |
33669 | diff -urNp linux-2.6.29.6/include/linux/jbd2.h linux-2.6.29.6/include/linux/jbd2.h |
33670 | --- linux-2.6.29.6/include/linux/jbd2.h 2009-07-02 19:41:20.000000000 -0400 | |
33671 | +++ linux-2.6.29.6/include/linux/jbd2.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33672 | @@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug; |
33673 | } \ | |
33674 | } while (0) | |
33675 | #else | |
33676 | -#define jbd_debug(f, a...) /**/ | |
33677 | +#define jbd_debug(f, a...) do {} while (0) | |
33678 | #endif | |
33679 | ||
33680 | static inline void *jbd2_alloc(size_t size, gfp_t flags) | |
de855c5d AM |
33681 | diff -urNp linux-2.6.29.6/include/linux/jbd.h linux-2.6.29.6/include/linux/jbd.h |
33682 | --- linux-2.6.29.6/include/linux/jbd.h 2009-07-02 19:41:20.000000000 -0400 | |
33683 | +++ linux-2.6.29.6/include/linux/jbd.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33684 | @@ -66,7 +66,7 @@ extern u8 journal_enable_debug; |
33685 | } \ | |
33686 | } while (0) | |
33687 | #else | |
33688 | -#define jbd_debug(f, a...) /**/ | |
33689 | +#define jbd_debug(f, a...) do {} while (0) | |
33690 | #endif | |
33691 | ||
33692 | static inline void *jbd_alloc(size_t size, gfp_t flags) | |
de855c5d AM |
33693 | diff -urNp linux-2.6.29.6/include/linux/kvm_host.h linux-2.6.29.6/include/linux/kvm_host.h |
33694 | --- linux-2.6.29.6/include/linux/kvm_host.h 2009-07-02 19:41:20.000000000 -0400 | |
33695 | +++ linux-2.6.29.6/include/linux/kvm_host.h 2009-07-09 22:13:39.000000000 -0400 | |
33696 | @@ -155,7 +155,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc | |
2380c486 JR |
33697 | void vcpu_load(struct kvm_vcpu *vcpu); |
33698 | void vcpu_put(struct kvm_vcpu *vcpu); | |
33699 | ||
33700 | -int kvm_init(void *opaque, unsigned int vcpu_size, | |
33701 | +int kvm_init(const void *opaque, unsigned int vcpu_size, | |
33702 | struct module *module); | |
33703 | void kvm_exit(void); | |
33704 | ||
de855c5d | 33705 | @@ -263,7 +263,7 @@ int kvm_arch_vcpu_ioctl_debug_guest(stru |
2380c486 JR |
33706 | struct kvm_debug_guest *dbg); |
33707 | int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); | |
33708 | ||
33709 | -int kvm_arch_init(void *opaque); | |
33710 | +int kvm_arch_init(const void *opaque); | |
33711 | void kvm_arch_exit(void); | |
33712 | ||
33713 | int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu); | |
de855c5d AM |
33714 | diff -urNp linux-2.6.29.6/include/linux/libata.h linux-2.6.29.6/include/linux/libata.h |
33715 | --- linux-2.6.29.6/include/linux/libata.h 2009-07-02 19:41:20.000000000 -0400 | |
33716 | +++ linux-2.6.29.6/include/linux/libata.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33717 | @@ -64,11 +64,11 @@ |
33718 | #ifdef ATA_VERBOSE_DEBUG | |
33719 | #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args) | |
33720 | #else | |
33721 | -#define VPRINTK(fmt, args...) | |
33722 | +#define VPRINTK(fmt, args...) do {} while (0) | |
33723 | #endif /* ATA_VERBOSE_DEBUG */ | |
33724 | #else | |
33725 | -#define DPRINTK(fmt, args...) | |
33726 | -#define VPRINTK(fmt, args...) | |
33727 | +#define DPRINTK(fmt, args...) do {} while (0) | |
33728 | +#define VPRINTK(fmt, args...) do {} while (0) | |
33729 | #endif /* ATA_DEBUG */ | |
33730 | ||
33731 | #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args) | |
de855c5d AM |
33732 | diff -urNp linux-2.6.29.6/include/linux/mm.h linux-2.6.29.6/include/linux/mm.h |
33733 | --- linux-2.6.29.6/include/linux/mm.h 2009-07-02 19:41:20.000000000 -0400 | |
33734 | +++ linux-2.6.29.6/include/linux/mm.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33735 | @@ -39,6 +39,7 @@ extern unsigned long mmap_min_addr; |
33736 | #include <asm/page.h> | |
33737 | #include <asm/pgtable.h> | |
33738 | #include <asm/processor.h> | |
33739 | +#include <asm/mman.h> | |
33740 | ||
33741 | #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) | |
33742 | ||
33743 | @@ -105,6 +106,10 @@ extern unsigned int kobjsize(const void | |
33744 | #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */ | |
33745 | #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */ | |
33746 | ||
33747 | +#ifdef CONFIG_PAX_PAGEEXEC | |
33748 | +#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */ | |
33749 | +#endif | |
33750 | + | |
33751 | #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */ | |
33752 | #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS | |
33753 | #endif | |
de855c5d | 33754 | @@ -899,6 +904,8 @@ struct shrinker { |
2380c486 JR |
33755 | extern void register_shrinker(struct shrinker *); |
33756 | extern void unregister_shrinker(struct shrinker *); | |
33757 | ||
33758 | +pgprot_t vm_get_page_prot(unsigned long vm_flags); | |
33759 | + | |
33760 | int vma_wants_writenotify(struct vm_area_struct *vma); | |
33761 | ||
33762 | extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl); | |
de855c5d | 33763 | @@ -1170,6 +1177,7 @@ out: |
2380c486 JR |
33764 | } |
33765 | ||
33766 | extern int do_munmap(struct mm_struct *, unsigned long, size_t); | |
33767 | +extern int __do_munmap(struct mm_struct *, unsigned long, size_t); | |
33768 | ||
33769 | extern unsigned long do_brk(unsigned long, unsigned long); | |
33770 | ||
de855c5d | 33771 | @@ -1223,6 +1231,10 @@ extern struct vm_area_struct * find_vma( |
2380c486 JR |
33772 | extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr, |
33773 | struct vm_area_struct **pprev); | |
33774 | ||
33775 | +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma); | |
33776 | +extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma); | |
33777 | +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl); | |
33778 | + | |
33779 | /* Look up the first VMA which intersects the interval start_addr..end_addr-1, | |
33780 | NULL if none. Assume start_addr < end_addr. */ | |
33781 | static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr) | |
de855c5d | 33782 | @@ -1239,7 +1251,6 @@ static inline unsigned long vma_pages(st |
2380c486 JR |
33783 | return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; |
33784 | } | |
33785 | ||
33786 | -pgprot_t vm_get_page_prot(unsigned long vm_flags); | |
33787 | struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr); | |
33788 | int remap_pfn_range(struct vm_area_struct *, unsigned long addr, | |
33789 | unsigned long pfn, unsigned long size, pgprot_t); | |
de855c5d | 33790 | @@ -1331,5 +1342,12 @@ void vmemmap_populate_print_last(void); |
2380c486 JR |
33791 | extern void *alloc_locked_buffer(size_t size); |
33792 | extern void free_locked_buffer(void *buffer, size_t size); | |
33793 | extern void release_locked_buffer(void *buffer, size_t size); | |
33794 | + | |
33795 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
33796 | +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot); | |
33797 | +#else | |
33798 | +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {} | |
33799 | +#endif | |
33800 | + | |
33801 | #endif /* __KERNEL__ */ | |
33802 | #endif /* _LINUX_MM_H */ | |
de855c5d AM |
33803 | diff -urNp linux-2.6.29.6/include/linux/mm_types.h linux-2.6.29.6/include/linux/mm_types.h |
33804 | --- linux-2.6.29.6/include/linux/mm_types.h 2009-07-02 19:41:20.000000000 -0400 | |
33805 | +++ linux-2.6.29.6/include/linux/mm_types.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33806 | @@ -174,6 +174,8 @@ struct vm_area_struct { |
33807 | #ifdef CONFIG_NUMA | |
33808 | struct mempolicy *vm_policy; /* NUMA policy for the VMA */ | |
33809 | #endif | |
33810 | + | |
33811 | + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */ | |
33812 | }; | |
33813 | ||
33814 | struct core_thread { | |
33815 | @@ -274,6 +276,24 @@ struct mm_struct { | |
33816 | #ifdef CONFIG_MMU_NOTIFIER | |
33817 | struct mmu_notifier_mm *mmu_notifier_mm; | |
33818 | #endif | |
33819 | + | |
33820 | +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
33821 | + unsigned long pax_flags; | |
33822 | +#endif | |
33823 | + | |
33824 | +#ifdef CONFIG_PAX_DLRESOLVE | |
33825 | + unsigned long call_dl_resolve; | |
33826 | +#endif | |
33827 | + | |
33828 | +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT) | |
33829 | + unsigned long call_syscall; | |
33830 | +#endif | |
33831 | + | |
33832 | +#ifdef CONFIG_PAX_ASLR | |
33833 | + unsigned long delta_mmap; /* randomized offset */ | |
33834 | + unsigned long delta_stack; /* randomized offset */ | |
33835 | +#endif | |
33836 | + | |
33837 | }; | |
33838 | ||
33839 | /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */ | |
de855c5d AM |
33840 | diff -urNp linux-2.6.29.6/include/linux/module.h linux-2.6.29.6/include/linux/module.h |
33841 | --- linux-2.6.29.6/include/linux/module.h 2009-07-02 19:41:20.000000000 -0400 | |
33842 | +++ linux-2.6.29.6/include/linux/module.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33843 | @@ -278,16 +278,16 @@ struct module |
33844 | int (*init)(void); | |
33845 | ||
33846 | /* If this is non-NULL, vfree after init() returns */ | |
33847 | - void *module_init; | |
33848 | + void *module_init_rx, *module_init_rw; | |
33849 | ||
33850 | /* Here is the actual code + data, vfree'd on unload. */ | |
33851 | - void *module_core; | |
33852 | + void *module_core_rx, *module_core_rw; | |
33853 | ||
33854 | /* Here are the sizes of the init and core sections */ | |
33855 | - unsigned int init_size, core_size; | |
33856 | + unsigned int init_size_rw, core_size_rw; | |
33857 | ||
33858 | /* The size of the executable code in each section. */ | |
33859 | - unsigned int init_text_size, core_text_size; | |
33860 | + unsigned int init_size_rx, core_size_rx; | |
33861 | ||
33862 | /* Arch-specific module values */ | |
33863 | struct mod_arch_specific arch; | |
33864 | @@ -363,16 +363,46 @@ struct module *module_text_address(unsig | |
33865 | struct module *__module_text_address(unsigned long addr); | |
33866 | int is_module_address(unsigned long addr); | |
33867 | ||
33868 | +static inline int within_module_range(unsigned long addr, void *start, unsigned long size) | |
33869 | +{ | |
33870 | + | |
33871 | +#ifdef CONFIG_PAX_KERNEXEC | |
33872 | + if (ktla_ktva(addr) >= (unsigned long)start && | |
33873 | + ktla_ktva(addr) < (unsigned long)start + size) | |
33874 | + return 1; | |
33875 | +#endif | |
33876 | + | |
33877 | + return ((void *)addr >= start && (void *)addr < start + size); | |
33878 | +} | |
33879 | + | |
33880 | +static inline int within_module_core_rx(unsigned long addr, struct module *mod) | |
33881 | +{ | |
33882 | + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx); | |
33883 | +} | |
33884 | + | |
33885 | +static inline int within_module_core_rw(unsigned long addr, struct module *mod) | |
33886 | +{ | |
33887 | + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw); | |
33888 | +} | |
33889 | + | |
33890 | +static inline int within_module_init_rx(unsigned long addr, struct module *mod) | |
33891 | +{ | |
33892 | + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx); | |
33893 | +} | |
33894 | + | |
33895 | +static inline int within_module_init_rw(unsigned long addr, struct module *mod) | |
33896 | +{ | |
33897 | + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw); | |
33898 | +} | |
33899 | + | |
33900 | static inline int within_module_core(unsigned long addr, struct module *mod) | |
33901 | { | |
33902 | - return (unsigned long)mod->module_core <= addr && | |
33903 | - addr < (unsigned long)mod->module_core + mod->core_size; | |
33904 | + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod); | |
33905 | } | |
33906 | ||
33907 | static inline int within_module_init(unsigned long addr, struct module *mod) | |
33908 | { | |
33909 | - return (unsigned long)mod->module_init <= addr && | |
33910 | - addr < (unsigned long)mod->module_init + mod->init_size; | |
33911 | + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod); | |
33912 | } | |
33913 | ||
33914 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if | |
33915 | @@ -396,7 +426,11 @@ void symbol_put_addr(void *addr); | |
33916 | static inline local_t *__module_ref_addr(struct module *mod, int cpu) | |
33917 | { | |
33918 | #ifdef CONFIG_SMP | |
33919 | +#ifdef CONFIG_X86_32 | |
33920 | + return (local_t *) (mod->refptr + __per_cpu_offset[cpu]); | |
33921 | +#else | |
33922 | return (local_t *) (mod->refptr + per_cpu_offset(cpu)); | |
33923 | +#endif | |
33924 | #else | |
33925 | return &mod->ref; | |
33926 | #endif | |
de855c5d AM |
33927 | diff -urNp linux-2.6.29.6/include/linux/moduleloader.h linux-2.6.29.6/include/linux/moduleloader.h |
33928 | --- linux-2.6.29.6/include/linux/moduleloader.h 2009-07-02 19:41:20.000000000 -0400 | |
33929 | +++ linux-2.6.29.6/include/linux/moduleloader.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33930 | @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st |
33931 | sections. Returns NULL on failure. */ | |
33932 | void *module_alloc(unsigned long size); | |
33933 | ||
33934 | +#ifdef CONFIG_PAX_KERNEXEC | |
33935 | +void *module_alloc_exec(unsigned long size); | |
33936 | +#else | |
33937 | +#define module_alloc_exec(x) module_alloc(x) | |
33938 | +#endif | |
33939 | + | |
33940 | /* Free memory returned from module_alloc. */ | |
33941 | void module_free(struct module *mod, void *module_region); | |
33942 | ||
33943 | +#ifdef CONFIG_PAX_KERNEXEC | |
33944 | +void module_free_exec(struct module *mod, void *module_region); | |
33945 | +#else | |
33946 | +#define module_free_exec(x, y) module_free(x, y) | |
33947 | +#endif | |
33948 | + | |
33949 | /* Apply the given relocation to the (simplified) ELF. Return -error | |
33950 | or 0. */ | |
33951 | int apply_relocate(Elf_Shdr *sechdrs, | |
de855c5d AM |
33952 | diff -urNp linux-2.6.29.6/include/linux/namei.h linux-2.6.29.6/include/linux/namei.h |
33953 | --- linux-2.6.29.6/include/linux/namei.h 2009-07-02 19:41:20.000000000 -0400 | |
33954 | +++ linux-2.6.29.6/include/linux/namei.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33955 | @@ -21,7 +21,7 @@ struct nameidata { |
33956 | unsigned int flags; | |
33957 | int last_type; | |
33958 | unsigned depth; | |
33959 | - char *saved_names[MAX_NESTED_LINKS + 1]; | |
33960 | + const char *saved_names[MAX_NESTED_LINKS + 1]; | |
33961 | ||
33962 | /* Intent data */ | |
33963 | union { | |
33964 | @@ -84,12 +84,12 @@ extern int follow_up(struct vfsmount **, | |
33965 | extern struct dentry *lock_rename(struct dentry *, struct dentry *); | |
33966 | extern void unlock_rename(struct dentry *, struct dentry *); | |
33967 | ||
33968 | -static inline void nd_set_link(struct nameidata *nd, char *path) | |
33969 | +static inline void nd_set_link(struct nameidata *nd, const char *path) | |
33970 | { | |
33971 | nd->saved_names[nd->depth] = path; | |
33972 | } | |
33973 | ||
33974 | -static inline char *nd_get_link(struct nameidata *nd) | |
33975 | +static inline const char *nd_get_link(struct nameidata *nd) | |
33976 | { | |
33977 | return nd->saved_names[nd->depth]; | |
33978 | } | |
de855c5d AM |
33979 | diff -urNp linux-2.6.29.6/include/linux/nodemask.h linux-2.6.29.6/include/linux/nodemask.h |
33980 | --- linux-2.6.29.6/include/linux/nodemask.h 2009-07-02 19:41:20.000000000 -0400 | |
33981 | +++ linux-2.6.29.6/include/linux/nodemask.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
33982 | @@ -442,11 +442,11 @@ static inline int num_node_state(enum no |
33983 | ||
33984 | #define any_online_node(mask) \ | |
33985 | ({ \ | |
33986 | - int node; \ | |
33987 | - for_each_node_mask(node, (mask)) \ | |
33988 | - if (node_online(node)) \ | |
33989 | + int __node; \ | |
33990 | + for_each_node_mask(__node, (mask)) \ | |
33991 | + if (node_online(__node)) \ | |
33992 | break; \ | |
33993 | - node; \ | |
33994 | + __node; \ | |
33995 | }) | |
33996 | ||
33997 | #define num_online_nodes() num_node_state(N_ONLINE) | |
de855c5d AM |
33998 | diff -urNp linux-2.6.29.6/include/linux/oprofile.h linux-2.6.29.6/include/linux/oprofile.h |
33999 | --- linux-2.6.29.6/include/linux/oprofile.h 2009-07-02 19:41:20.000000000 -0400 | |
34000 | +++ linux-2.6.29.6/include/linux/oprofile.h 2009-07-09 22:13:39.000000000 -0400 | |
34001 | @@ -128,7 +128,7 @@ int oprofilefs_create_ro_ulong(struct su | |
34002 | ||
34003 | /** Create a file for read-only access to an atomic_t. */ | |
34004 | int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, | |
34005 | - char const * name, atomic_t * val); | |
34006 | + char const * name, atomic_unchecked_t * val); | |
34007 | ||
34008 | /** create a directory */ | |
34009 | struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root, | |
34010 | diff -urNp linux-2.6.29.6/include/linux/percpu.h linux-2.6.29.6/include/linux/percpu.h | |
34011 | --- linux-2.6.29.6/include/linux/percpu.h 2009-07-02 19:41:20.000000000 -0400 | |
34012 | +++ linux-2.6.29.6/include/linux/percpu.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34013 | @@ -50,7 +50,7 @@ |
34014 | #endif | |
34015 | ||
34016 | #define PERCPU_ENOUGH_ROOM \ | |
34017 | - (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE) | |
34018 | + ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)) | |
34019 | #endif /* PERCPU_ENOUGH_ROOM */ | |
34020 | ||
34021 | /* | |
de855c5d AM |
34022 | diff -urNp linux-2.6.29.6/include/linux/personality.h linux-2.6.29.6/include/linux/personality.h |
34023 | --- linux-2.6.29.6/include/linux/personality.h 2009-07-02 19:41:20.000000000 -0400 | |
34024 | +++ linux-2.6.29.6/include/linux/personality.h 2009-07-10 05:44:42.000000000 -0400 | |
34025 | @@ -40,7 +40,7 @@ enum { | |
34026 | * Security-relevant compatibility flags that must be | |
34027 | * cleared upon setuid or setgid exec: | |
34028 | */ | |
34029 | -#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE) | |
34030 | +#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE|ADDR_COMPAT_LAYOUT|MMAP_PAGE_ZERO) | |
34031 | ||
34032 | /* | |
34033 | * Personality types. | |
34034 | diff -urNp linux-2.6.29.6/include/linux/poison.h linux-2.6.29.6/include/linux/poison.h | |
34035 | --- linux-2.6.29.6/include/linux/poison.h 2009-07-02 19:41:20.000000000 -0400 | |
34036 | +++ linux-2.6.29.6/include/linux/poison.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34037 | @@ -7,8 +7,8 @@ |
34038 | * under normal circumstances, used to verify that nobody uses | |
34039 | * non-initialized list entries. | |
34040 | */ | |
34041 | -#define LIST_POISON1 ((void *) 0x00100100) | |
34042 | -#define LIST_POISON2 ((void *) 0x00200200) | |
34043 | +#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL) | |
34044 | +#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL) | |
34045 | ||
34046 | /********** include/linux/timer.h **********/ | |
34047 | /* | |
de855c5d AM |
34048 | diff -urNp linux-2.6.29.6/include/linux/proc_fs.h linux-2.6.29.6/include/linux/proc_fs.h |
34049 | --- linux-2.6.29.6/include/linux/proc_fs.h 2009-07-02 19:41:20.000000000 -0400 | |
34050 | +++ linux-2.6.29.6/include/linux/proc_fs.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34051 | @@ -174,6 +174,19 @@ static inline struct proc_dir_entry *pro |
34052 | return proc_create_data(name, mode, parent, proc_fops, NULL); | |
34053 | } | |
34054 | ||
34055 | +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode, | |
34056 | + struct proc_dir_entry *parent, const struct file_operations *proc_fops) | |
34057 | +{ | |
34058 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
34059 | + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL); | |
34060 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
34061 | + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL); | |
34062 | +#else | |
34063 | + return proc_create_data(name, mode, parent, proc_fops, NULL); | |
34064 | +#endif | |
34065 | +} | |
34066 | + | |
34067 | + | |
34068 | static inline struct proc_dir_entry *create_proc_read_entry(const char *name, | |
34069 | mode_t mode, struct proc_dir_entry *base, | |
34070 | read_proc_t *read_proc, void * data) | |
de855c5d AM |
34071 | diff -urNp linux-2.6.29.6/include/linux/raid/md_k.h linux-2.6.29.6/include/linux/raid/md_k.h |
34072 | --- linux-2.6.29.6/include/linux/raid/md_k.h 2009-07-02 19:41:20.000000000 -0400 | |
34073 | +++ linux-2.6.29.6/include/linux/raid/md_k.h 2009-07-09 22:13:39.000000000 -0400 | |
34074 | @@ -293,7 +293,7 @@ static inline void rdev_dec_pending(mdk_ | |
2380c486 JR |
34075 | |
34076 | static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors) | |
34077 | { | |
de855c5d AM |
34078 | - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io); |
34079 | + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io); | |
2380c486 JR |
34080 | } |
34081 | ||
34082 | struct mdk_personality | |
de855c5d AM |
34083 | diff -urNp linux-2.6.29.6/include/linux/random.h linux-2.6.29.6/include/linux/random.h |
34084 | --- linux-2.6.29.6/include/linux/random.h 2009-07-02 19:41:20.000000000 -0400 | |
34085 | +++ linux-2.6.29.6/include/linux/random.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34086 | @@ -74,6 +74,11 @@ unsigned long randomize_range(unsigned l |
34087 | u32 random32(void); | |
34088 | void srandom32(u32 seed); | |
34089 | ||
34090 | +static inline unsigned long pax_get_random_long(void) | |
34091 | +{ | |
34092 | + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0); | |
34093 | +} | |
34094 | + | |
34095 | #endif /* __KERNEL___ */ | |
34096 | ||
34097 | #endif /* _LINUX_RANDOM_H */ | |
de855c5d AM |
34098 | diff -urNp linux-2.6.29.6/include/linux/reiserfs_fs_sb.h linux-2.6.29.6/include/linux/reiserfs_fs_sb.h |
34099 | --- linux-2.6.29.6/include/linux/reiserfs_fs_sb.h 2009-07-02 19:41:20.000000000 -0400 | |
34100 | +++ linux-2.6.29.6/include/linux/reiserfs_fs_sb.h 2009-07-09 22:13:39.000000000 -0400 | |
34101 | @@ -374,7 +374,7 @@ struct reiserfs_sb_info { | |
34102 | /* Comment? -Hans */ | |
34103 | wait_queue_head_t s_wait; | |
34104 | /* To be obsoleted soon by per buffer seals.. -Hans */ | |
34105 | - atomic_t s_generation_counter; // increased by one every time the | |
34106 | + atomic_unchecked_t s_generation_counter; // increased by one every time the | |
34107 | // tree gets re-balanced | |
34108 | unsigned long s_properties; /* File system properties. Currently holds | |
34109 | on-disk FS format */ | |
34110 | diff -urNp linux-2.6.29.6/include/linux/sched.h linux-2.6.29.6/include/linux/sched.h | |
34111 | --- linux-2.6.29.6/include/linux/sched.h 2009-07-02 19:41:20.000000000 -0400 | |
34112 | +++ linux-2.6.29.6/include/linux/sched.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34113 | @@ -97,6 +97,7 @@ struct futex_pi_state; |
34114 | struct robust_list_head; | |
34115 | struct bio; | |
34116 | struct bts_tracer; | |
34117 | +struct linux_binprm; | |
34118 | ||
34119 | /* | |
34120 | * List of flags we want to share for kernel threads, | |
de855c5d | 34121 | @@ -606,6 +607,15 @@ struct signal_struct { |
2380c486 JR |
34122 | unsigned audit_tty; |
34123 | struct tty_audit_buf *tty_audit_buf; | |
34124 | #endif | |
34125 | + | |
34126 | +#ifdef CONFIG_GRKERNSEC | |
34127 | + u32 curr_ip; | |
34128 | + u32 gr_saddr; | |
34129 | + u32 gr_daddr; | |
34130 | + u16 gr_sport; | |
34131 | + u16 gr_dport; | |
34132 | + u8 used_accept:1; | |
34133 | +#endif | |
34134 | }; | |
34135 | ||
34136 | /* Context switch must be unlocked if interrupts are to be enabled */ | |
de855c5d | 34137 | @@ -1114,7 +1124,7 @@ struct sched_rt_entity { |
2380c486 JR |
34138 | |
34139 | struct task_struct { | |
34140 | volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ | |
34141 | - void *stack; | |
34142 | + struct thread_info *stack; | |
34143 | atomic_t usage; | |
34144 | unsigned int flags; /* per process flags, defined below */ | |
34145 | unsigned int ptrace; | |
de855c5d | 34146 | @@ -1179,10 +1189,9 @@ struct task_struct { |
2380c486 JR |
34147 | pid_t pid; |
34148 | pid_t tgid; | |
34149 | ||
34150 | -#ifdef CONFIG_CC_STACKPROTECTOR | |
34151 | /* Canary value for the -fstack-protector gcc feature */ | |
34152 | unsigned long stack_canary; | |
34153 | -#endif | |
34154 | + | |
34155 | /* | |
34156 | * pointers to (original) parent process, youngest child, younger sibling, | |
34157 | * older sibling, respectively. (p->father can be replaced with | |
de855c5d | 34158 | @@ -1223,8 +1232,8 @@ struct task_struct { |
2380c486 JR |
34159 | struct list_head thread_group; |
34160 | ||
34161 | struct completion *vfork_done; /* for vfork() */ | |
34162 | - int __user *set_child_tid; /* CLONE_CHILD_SETTID */ | |
34163 | - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ | |
34164 | + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */ | |
34165 | + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ | |
34166 | ||
34167 | cputime_t utime, stime, utimescaled, stimescaled; | |
34168 | cputime_t gtime; | |
de855c5d | 34169 | @@ -1418,8 +1427,66 @@ struct task_struct { |
2380c486 JR |
34170 | /* state flags for use by tracers */ |
34171 | unsigned long trace; | |
34172 | #endif | |
34173 | + | |
34174 | +#ifdef CONFIG_GRKERNSEC | |
34175 | + /* grsecurity */ | |
34176 | + struct acl_subject_label *acl; | |
34177 | + struct acl_role_label *role; | |
34178 | + struct file *exec_file; | |
34179 | + u16 acl_role_id; | |
34180 | + u8 acl_sp_role; | |
34181 | + u8 is_writable; | |
34182 | + u8 brute; | |
34183 | +#endif | |
34184 | + | |
34185 | }; | |
34186 | ||
34187 | +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */ | |
34188 | +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */ | |
34189 | +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */ | |
34190 | +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */ | |
34191 | +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */ | |
34192 | +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */ | |
34193 | + | |
34194 | +#ifdef CONFIG_PAX_SOFTMODE | |
34195 | +extern unsigned int pax_softmode; | |
34196 | +#endif | |
34197 | + | |
34198 | +extern int pax_check_flags(unsigned long *); | |
34199 | + | |
34200 | +/* if tsk != current then task_lock must be held on it */ | |
34201 | +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR) | |
34202 | +static inline unsigned long pax_get_flags(struct task_struct *tsk) | |
34203 | +{ | |
34204 | + if (likely(tsk->mm)) | |
34205 | + return tsk->mm->pax_flags; | |
34206 | + else | |
34207 | + return 0UL; | |
34208 | +} | |
34209 | + | |
34210 | +/* if tsk != current then task_lock must be held on it */ | |
34211 | +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags) | |
34212 | +{ | |
34213 | + if (likely(tsk->mm)) { | |
34214 | + tsk->mm->pax_flags = flags; | |
34215 | + return 0; | |
34216 | + } | |
34217 | + return -EINVAL; | |
34218 | +} | |
34219 | +#endif | |
34220 | + | |
34221 | +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS | |
34222 | +extern void pax_set_initial_flags(struct linux_binprm *bprm); | |
34223 | +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS) | |
34224 | +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm); | |
34225 | +#endif | |
34226 | + | |
34227 | +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp); | |
34228 | +void pax_report_insns(void *pc, void *sp); | |
34229 | +void pax_report_refcount_overflow(struct pt_regs *regs); | |
de855c5d AM |
34230 | +void pax_report_leak_to_user(const void *ptr, unsigned long len); |
34231 | +void pax_report_overflow_from_user(const void *ptr, unsigned long len); | |
2380c486 JR |
34232 | + |
34233 | /* Future-safe accessor for struct task_struct's cpus_allowed. */ | |
34234 | #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed) | |
34235 | ||
de855c5d | 34236 | @@ -1961,7 +2028,7 @@ extern void __cleanup_sighand(struct sig |
2380c486 JR |
34237 | extern void exit_itimers(struct signal_struct *); |
34238 | extern void flush_itimer_signals(void); | |
34239 | ||
34240 | -extern NORET_TYPE void do_group_exit(int); | |
34241 | +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET; | |
34242 | ||
34243 | extern void daemonize(const char *, ...); | |
34244 | extern int allow_signal(int); | |
de855c5d | 34245 | @@ -2066,8 +2133,8 @@ static inline void unlock_task_sighand(s |
2380c486 JR |
34246 | |
34247 | #ifndef __HAVE_THREAD_FUNCTIONS | |
34248 | ||
34249 | -#define task_thread_info(task) ((struct thread_info *)(task)->stack) | |
34250 | -#define task_stack_page(task) ((task)->stack) | |
34251 | +#define task_thread_info(task) ((task)->stack) | |
34252 | +#define task_stack_page(task) ((void *)(task)->stack) | |
34253 | ||
34254 | static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) | |
34255 | { | |
de855c5d AM |
34256 | diff -urNp linux-2.6.29.6/include/linux/screen_info.h linux-2.6.29.6/include/linux/screen_info.h |
34257 | --- linux-2.6.29.6/include/linux/screen_info.h 2009-07-02 19:41:20.000000000 -0400 | |
34258 | +++ linux-2.6.29.6/include/linux/screen_info.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34259 | @@ -42,7 +42,8 @@ struct screen_info { |
34260 | __u16 pages; /* 0x32 */ | |
34261 | __u16 vesa_attributes; /* 0x34 */ | |
34262 | __u32 capabilities; /* 0x36 */ | |
34263 | - __u8 _reserved[6]; /* 0x3a */ | |
34264 | + __u16 vesapm_size; /* 0x3a */ | |
34265 | + __u8 _reserved[4]; /* 0x3c */ | |
34266 | } __attribute__((packed)); | |
34267 | ||
34268 | #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */ | |
de855c5d AM |
34269 | diff -urNp linux-2.6.29.6/include/linux/security.h linux-2.6.29.6/include/linux/security.h |
34270 | --- linux-2.6.29.6/include/linux/security.h 2009-07-02 19:41:20.000000000 -0400 | |
34271 | +++ linux-2.6.29.6/include/linux/security.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34272 | @@ -32,6 +32,7 @@ |
34273 | #include <linux/sched.h> | |
34274 | #include <linux/key.h> | |
34275 | #include <linux/xfrm.h> | |
34276 | +#include <linux/grsecurity.h> | |
34277 | #include <net/flow.h> | |
34278 | ||
34279 | /* Maximum number of letters for an LSM name string */ | |
de855c5d AM |
34280 | diff -urNp linux-2.6.29.6/include/linux/shm.h linux-2.6.29.6/include/linux/shm.h |
34281 | --- linux-2.6.29.6/include/linux/shm.h 2009-07-02 19:41:20.000000000 -0400 | |
34282 | +++ linux-2.6.29.6/include/linux/shm.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34283 | @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke |
34284 | pid_t shm_cprid; | |
34285 | pid_t shm_lprid; | |
34286 | struct user_struct *mlock_user; | |
34287 | +#ifdef CONFIG_GRKERNSEC | |
34288 | + time_t shm_createtime; | |
34289 | + pid_t shm_lapid; | |
34290 | +#endif | |
34291 | }; | |
34292 | ||
34293 | /* shm_mode upper byte flags */ | |
de855c5d AM |
34294 | diff -urNp linux-2.6.29.6/include/linux/slab.h linux-2.6.29.6/include/linux/slab.h |
34295 | --- linux-2.6.29.6/include/linux/slab.h 2009-07-02 19:41:20.000000000 -0400 | |
34296 | +++ linux-2.6.29.6/include/linux/slab.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34297 | @@ -73,10 +73,9 @@ |
34298 | * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can. | |
34299 | * Both make kfree a no-op. | |
34300 | */ | |
34301 | -#define ZERO_SIZE_PTR ((void *)16) | |
34302 | +#define ZERO_SIZE_PTR ((void *)-1024L) | |
34303 | ||
34304 | -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \ | |
34305 | - (unsigned long)ZERO_SIZE_PTR) | |
34306 | +#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR) | |
34307 | ||
34308 | /* | |
34309 | * struct kmem_cache related prototypes | |
de855c5d AM |
34310 | @@ -129,6 +128,7 @@ void * __must_check krealloc(const void |
34311 | void kfree(const void *); | |
34312 | void kzfree(const void *); | |
34313 | size_t ksize(const void *); | |
34314 | +void check_object_size(const void *ptr, unsigned long n, bool to); | |
34315 | ||
34316 | /* | |
34317 | * Allocator specific definitions. These are mainly used to establish optimized | |
34318 | @@ -317,4 +317,35 @@ static inline void *kzalloc_node(size_t | |
34319 | return kmalloc_node(size, flags | __GFP_ZERO, node); | |
34320 | } | |
34321 | ||
34322 | +#define kmalloc(x,y) \ | |
34323 | + ({ \ | |
34324 | + void *___retval; \ | |
34325 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34326 | + if (likely(___x <= ULONG_MAX)) \ | |
34327 | + ___retval = kmalloc((size_t)___x, y); \ | |
34328 | + else \ | |
34329 | + ___retval = NULL; \ | |
34330 | + ___retval; \ | |
34331 | + }) | |
34332 | +#define kmalloc_node(x,y,z) \ | |
34333 | + ({ \ | |
34334 | + void *___retval; \ | |
34335 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34336 | + if (likely(___x <= ULONG_MAX)) \ | |
34337 | + ___retval = kmalloc_node((size_t)___x, y, z); \ | |
34338 | + else \ | |
34339 | + ___retval = NULL; \ | |
34340 | + ___retval; \ | |
34341 | + }) | |
34342 | +#define kzalloc(x,y) \ | |
34343 | + ({ \ | |
34344 | + void *___retval; \ | |
34345 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34346 | + if (likely(___x <= ULONG_MAX)) \ | |
34347 | + ___retval = kzalloc((size_t)___x, y); \ | |
34348 | + else \ | |
34349 | + ___retval = NULL; \ | |
34350 | + ___retval; \ | |
34351 | + }) | |
34352 | + | |
34353 | #endif /* _LINUX_SLAB_H */ | |
34354 | diff -urNp linux-2.6.29.6/include/linux/slub_def.h linux-2.6.29.6/include/linux/slub_def.h | |
34355 | --- linux-2.6.29.6/include/linux/slub_def.h 2009-07-02 19:41:20.000000000 -0400 | |
34356 | +++ linux-2.6.29.6/include/linux/slub_def.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34357 | @@ -85,7 +85,7 @@ struct kmem_cache { |
34358 | struct kmem_cache_order_objects max; | |
34359 | struct kmem_cache_order_objects min; | |
34360 | gfp_t allocflags; /* gfp flags to use on each alloc */ | |
34361 | - int refcount; /* Refcount for slab cache destroy */ | |
34362 | + atomic_t refcount; /* Refcount for slab cache destroy */ | |
34363 | void (*ctor)(void *); | |
34364 | int inuse; /* Offset to metadata */ | |
34365 | int align; /* Alignment */ | |
de855c5d AM |
34366 | diff -urNp linux-2.6.29.6/include/linux/sysctl.h linux-2.6.29.6/include/linux/sysctl.h |
34367 | --- linux-2.6.29.6/include/linux/sysctl.h 2009-07-02 19:41:20.000000000 -0400 | |
34368 | +++ linux-2.6.29.6/include/linux/sysctl.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34369 | @@ -165,7 +165,11 @@ enum |
34370 | KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */ | |
34371 | }; | |
34372 | ||
34373 | - | |
34374 | +#ifdef CONFIG_PAX_SOFTMODE | |
34375 | +enum { | |
34376 | + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */ | |
34377 | +}; | |
34378 | +#endif | |
34379 | ||
34380 | /* CTL_VM names: */ | |
34381 | enum | |
de855c5d AM |
34382 | diff -urNp linux-2.6.29.6/include/linux/thread_info.h linux-2.6.29.6/include/linux/thread_info.h |
34383 | --- linux-2.6.29.6/include/linux/thread_info.h 2009-07-02 19:41:20.000000000 -0400 | |
34384 | +++ linux-2.6.29.6/include/linux/thread_info.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34385 | @@ -23,7 +23,7 @@ struct restart_block { |
34386 | }; | |
34387 | /* For futex_wait */ | |
34388 | struct { | |
34389 | - u32 *uaddr; | |
34390 | + u32 __user *uaddr; | |
34391 | u32 val; | |
34392 | u32 flags; | |
34393 | u32 bitset; | |
de855c5d AM |
34394 | diff -urNp linux-2.6.29.6/include/linux/tty_ldisc.h linux-2.6.29.6/include/linux/tty_ldisc.h |
34395 | --- linux-2.6.29.6/include/linux/tty_ldisc.h 2009-07-02 19:41:20.000000000 -0400 | |
34396 | +++ linux-2.6.29.6/include/linux/tty_ldisc.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34397 | @@ -139,12 +139,12 @@ struct tty_ldisc_ops { |
34398 | ||
34399 | struct module *owner; | |
34400 | ||
34401 | - int refcount; | |
34402 | + atomic_t refcount; | |
34403 | }; | |
34404 | ||
34405 | struct tty_ldisc { | |
34406 | struct tty_ldisc_ops *ops; | |
34407 | - int refcount; | |
34408 | + atomic_t refcount; | |
34409 | }; | |
34410 | ||
34411 | #define TTY_LDISC_MAGIC 0x5403 | |
de855c5d AM |
34412 | diff -urNp linux-2.6.29.6/include/linux/types.h linux-2.6.29.6/include/linux/types.h |
34413 | --- linux-2.6.29.6/include/linux/types.h 2009-07-02 19:41:20.000000000 -0400 | |
34414 | +++ linux-2.6.29.6/include/linux/types.h 2009-07-09 22:13:39.000000000 -0400 | |
34415 | @@ -198,10 +198,26 @@ typedef struct { | |
34416 | volatile int counter; | |
34417 | } atomic_t; | |
34418 | ||
34419 | +#ifdef CONFIG_PAX_REFCOUNT | |
34420 | +typedef struct { | |
34421 | + volatile int counter; | |
34422 | +} atomic_unchecked_t; | |
34423 | +#else | |
34424 | +typedef atomic_t atomic_unchecked_t; | |
34425 | +#endif | |
34426 | + | |
34427 | #ifdef CONFIG_64BIT | |
34428 | typedef struct { | |
34429 | volatile long counter; | |
34430 | } atomic64_t; | |
34431 | + | |
34432 | +#ifdef CONFIG_PAX_REFCOUNT | |
34433 | +typedef struct { | |
34434 | + volatile long counter; | |
34435 | +} atomic64_unchecked_t; | |
34436 | +#else | |
34437 | +typedef atomic64_t atomic64_unchecked_t; | |
34438 | +#endif | |
34439 | #endif | |
34440 | ||
34441 | struct ustat { | |
34442 | diff -urNp linux-2.6.29.6/include/linux/uaccess.h linux-2.6.29.6/include/linux/uaccess.h | |
34443 | --- linux-2.6.29.6/include/linux/uaccess.h 2009-07-02 19:41:20.000000000 -0400 | |
34444 | +++ linux-2.6.29.6/include/linux/uaccess.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34445 | @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_ |
34446 | long ret; \ | |
34447 | mm_segment_t old_fs = get_fs(); \ | |
34448 | \ | |
34449 | - set_fs(KERNEL_DS); \ | |
34450 | pagefault_disable(); \ | |
34451 | + set_fs(KERNEL_DS); \ | |
34452 | ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \ | |
34453 | - pagefault_enable(); \ | |
34454 | set_fs(old_fs); \ | |
34455 | + pagefault_enable(); \ | |
34456 | ret; \ | |
34457 | }) | |
34458 | ||
de855c5d AM |
34459 | diff -urNp linux-2.6.29.6/include/linux/vmalloc.h linux-2.6.29.6/include/linux/vmalloc.h |
34460 | --- linux-2.6.29.6/include/linux/vmalloc.h 2009-07-02 19:41:20.000000000 -0400 | |
34461 | +++ linux-2.6.29.6/include/linux/vmalloc.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34462 | @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining |
34463 | #define VM_MAP 0x00000004 /* vmap()ed pages */ | |
34464 | #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */ | |
34465 | #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */ | |
34466 | + | |
34467 | +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
34468 | +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */ | |
34469 | +#endif | |
34470 | + | |
34471 | /* bits [20..32] reserved for arch specific ioremap internals */ | |
34472 | ||
34473 | /* | |
de855c5d AM |
34474 | @@ -111,4 +116,75 @@ extern long vwrite(char *buf, char *addr |
34475 | extern rwlock_t vmlist_lock; | |
34476 | extern struct vm_struct *vmlist; | |
34477 | ||
34478 | +#define vmalloc(x) \ | |
34479 | + ({ \ | |
34480 | + void *___retval; \ | |
34481 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34482 | + if (likely(___x <= ULONG_MAX)) \ | |
34483 | + ___retval = vmalloc((unsigned long)___x); \ | |
34484 | + else \ | |
34485 | + ___retval = NULL; \ | |
34486 | + ___retval; \ | |
34487 | + }) | |
34488 | +#define __vmalloc(x,y,z) \ | |
34489 | + ({ \ | |
34490 | + void *___retval; \ | |
34491 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34492 | + if (likely(___x <= ULONG_MAX)) \ | |
34493 | + ___retval = __vmalloc((unsigned long)___x, y, z); \ | |
34494 | + else \ | |
34495 | + ___retval = NULL; \ | |
34496 | + ___retval; \ | |
34497 | + }) | |
34498 | +#define vmalloc_user(x) \ | |
34499 | + ({ \ | |
34500 | + void *___retval; \ | |
34501 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34502 | + if (likely(___x <= ULONG_MAX)) \ | |
34503 | + ___retval = vmalloc_user((unsigned long)___x); \ | |
34504 | + else \ | |
34505 | + ___retval = NULL; \ | |
34506 | + ___retval; \ | |
34507 | + }) | |
34508 | +#define vmalloc_exec(x) \ | |
34509 | + ({ \ | |
34510 | + void *___retval; \ | |
34511 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34512 | + if (likely(___x <= ULONG_MAX)) \ | |
34513 | + ___retval = vmalloc_exec((unsigned long)___x); \ | |
34514 | + else \ | |
34515 | + ___retval = NULL; \ | |
34516 | + ___retval; \ | |
34517 | + }) | |
34518 | +#define vmalloc_node(x,y) \ | |
34519 | + ({ \ | |
34520 | + void *___retval; \ | |
34521 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34522 | + if (likely(___x <= ULONG_MAX)) \ | |
34523 | + ___retval = vmalloc_node((unsigned long)___x,y); \ | |
34524 | + else \ | |
34525 | + ___retval = NULL; \ | |
34526 | + ___retval; \ | |
34527 | + }) | |
34528 | +#define vmalloc_32(x) \ | |
34529 | + ({ \ | |
34530 | + void *___retval; \ | |
34531 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34532 | + if (likely(___x <= ULONG_MAX)) \ | |
34533 | + ___retval = vmalloc_32((unsigned long)___x); \ | |
34534 | + else \ | |
34535 | + ___retval = NULL; \ | |
34536 | + ___retval; \ | |
34537 | + }) | |
34538 | +#define vmalloc_32_user(x) \ | |
34539 | + ({ \ | |
34540 | + void *___retval; \ | |
34541 | + intoverflow_t ___x = (intoverflow_t)x; \ | |
34542 | + if (likely(___x <= ULONG_MAX)) \ | |
34543 | + ___retval = vmalloc_32_user((unsigned long)___x); \ | |
34544 | + else \ | |
34545 | + ___retval = NULL; \ | |
34546 | + ___retval; \ | |
34547 | + }) | |
34548 | + | |
34549 | #endif /* _LINUX_VMALLOC_H */ | |
34550 | diff -urNp linux-2.6.29.6/include/net/sctp/sctp.h linux-2.6.29.6/include/net/sctp/sctp.h | |
34551 | --- linux-2.6.29.6/include/net/sctp/sctp.h 2009-07-02 19:41:20.000000000 -0400 | |
34552 | +++ linux-2.6.29.6/include/net/sctp/sctp.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34553 | @@ -310,8 +310,8 @@ extern int sctp_debug_flag; |
34554 | ||
34555 | #else /* SCTP_DEBUG */ | |
34556 | ||
34557 | -#define SCTP_DEBUG_PRINTK(whatever...) | |
34558 | -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) | |
34559 | +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0) | |
34560 | +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0) | |
34561 | #define SCTP_ENABLE_DEBUG | |
34562 | #define SCTP_DISABLE_DEBUG | |
34563 | #define SCTP_ASSERT(expr, str, func) | |
de855c5d AM |
34564 | diff -urNp linux-2.6.29.6/include/sound/core.h linux-2.6.29.6/include/sound/core.h |
34565 | --- linux-2.6.29.6/include/sound/core.h 2009-07-02 19:41:20.000000000 -0400 | |
34566 | +++ linux-2.6.29.6/include/sound/core.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34567 | @@ -427,7 +427,7 @@ static inline int __snd_bug_on(int cond) |
34568 | */ | |
34569 | #define snd_printdd(format, args...) snd_printk(format, ##args) | |
34570 | #else | |
34571 | -#define snd_printdd(format, args...) /* nothing */ | |
34572 | +#define snd_printdd(format, args...) do {} while (0) | |
34573 | #endif | |
34574 | ||
34575 | ||
de855c5d AM |
34576 | diff -urNp linux-2.6.29.6/include/video/uvesafb.h linux-2.6.29.6/include/video/uvesafb.h |
34577 | --- linux-2.6.29.6/include/video/uvesafb.h 2009-07-02 19:41:20.000000000 -0400 | |
34578 | +++ linux-2.6.29.6/include/video/uvesafb.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34579 | @@ -177,6 +177,7 @@ struct uvesafb_par { |
34580 | u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */ | |
34581 | u8 pmi_setpal; /* PMI for palette changes */ | |
34582 | u16 *pmi_base; /* protected mode interface location */ | |
34583 | + u8 *pmi_code; /* protected mode code location */ | |
34584 | void *pmi_start; | |
34585 | void *pmi_pal; | |
34586 | u8 *vbe_state_orig; /* | |
de855c5d AM |
34587 | diff -urNp linux-2.6.29.6/init/do_mounts.c linux-2.6.29.6/init/do_mounts.c |
34588 | --- linux-2.6.29.6/init/do_mounts.c 2009-07-02 19:41:20.000000000 -0400 | |
34589 | +++ linux-2.6.29.6/init/do_mounts.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34590 | @@ -215,11 +215,11 @@ static void __init get_fs_names(char *pa |
34591 | ||
34592 | static int __init do_mount_root(char *name, char *fs, int flags, void *data) | |
34593 | { | |
34594 | - int err = sys_mount(name, "/root", fs, flags, data); | |
34595 | + int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data); | |
34596 | if (err) | |
34597 | return err; | |
34598 | ||
34599 | - sys_chdir("/root"); | |
34600 | + sys_chdir((char __user *)"/root"); | |
34601 | ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev; | |
34602 | printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", | |
34603 | current->fs->pwd.mnt->mnt_sb->s_type->name, | |
34604 | @@ -309,18 +309,18 @@ void __init change_floppy(char *fmt, ... | |
34605 | va_start(args, fmt); | |
34606 | vsprintf(buf, fmt, args); | |
34607 | va_end(args); | |
34608 | - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); | |
34609 | + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0); | |
34610 | if (fd >= 0) { | |
34611 | sys_ioctl(fd, FDEJECT, 0); | |
34612 | sys_close(fd); | |
34613 | } | |
34614 | printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); | |
34615 | - fd = sys_open("/dev/console", O_RDWR, 0); | |
34616 | + fd = sys_open((char __user *)"/dev/console", O_RDWR, 0); | |
34617 | if (fd >= 0) { | |
34618 | sys_ioctl(fd, TCGETS, (long)&termios); | |
34619 | termios.c_lflag &= ~ICANON; | |
34620 | sys_ioctl(fd, TCSETSF, (long)&termios); | |
34621 | - sys_read(fd, &c, 1); | |
34622 | + sys_read(fd, (char __user *)&c, 1); | |
34623 | termios.c_lflag |= ICANON; | |
34624 | sys_ioctl(fd, TCSETSF, (long)&termios); | |
34625 | sys_close(fd); | |
34626 | @@ -413,7 +413,7 @@ void __init prepare_namespace(void) | |
34627 | ||
34628 | mount_root(); | |
34629 | out: | |
34630 | - sys_mount(".", "/", NULL, MS_MOVE, NULL); | |
34631 | - sys_chroot("."); | |
34632 | + sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL); | |
34633 | + sys_chroot((char __user *)"."); | |
34634 | } | |
34635 | ||
de855c5d AM |
34636 | diff -urNp linux-2.6.29.6/init/do_mounts.h linux-2.6.29.6/init/do_mounts.h |
34637 | --- linux-2.6.29.6/init/do_mounts.h 2009-07-02 19:41:20.000000000 -0400 | |
34638 | +++ linux-2.6.29.6/init/do_mounts.h 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34639 | @@ -14,15 +14,15 @@ extern int root_mountflags; |
34640 | ||
34641 | static inline int create_dev(char *name, dev_t dev) | |
34642 | { | |
34643 | - sys_unlink(name); | |
34644 | - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev)); | |
34645 | + sys_unlink((char __user *)name); | |
34646 | + return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev)); | |
34647 | } | |
34648 | ||
34649 | #if BITS_PER_LONG == 32 | |
34650 | static inline u32 bstat(char *name) | |
34651 | { | |
34652 | struct stat64 stat; | |
34653 | - if (sys_stat64(name, &stat) != 0) | |
34654 | + if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0) | |
34655 | return 0; | |
34656 | if (!S_ISBLK(stat.st_mode)) | |
34657 | return 0; | |
de855c5d AM |
34658 | diff -urNp linux-2.6.29.6/init/do_mounts_initrd.c linux-2.6.29.6/init/do_mounts_initrd.c |
34659 | --- linux-2.6.29.6/init/do_mounts_initrd.c 2009-07-02 19:41:20.000000000 -0400 | |
34660 | +++ linux-2.6.29.6/init/do_mounts_initrd.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34661 | @@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel |
34662 | sys_close(old_fd);sys_close(root_fd); | |
34663 | sys_close(0);sys_close(1);sys_close(2); | |
34664 | sys_setsid(); | |
34665 | - (void) sys_open("/dev/console",O_RDWR,0); | |
34666 | + (void) sys_open((const char __user *)"/dev/console",O_RDWR,0); | |
34667 | (void) sys_dup(0); | |
34668 | (void) sys_dup(0); | |
34669 | return kernel_execve(shell, argv, envp_init); | |
34670 | @@ -47,13 +47,13 @@ static void __init handle_initrd(void) | |
34671 | create_dev("/dev/root.old", Root_RAM0); | |
34672 | /* mount initrd on rootfs' /root */ | |
34673 | mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); | |
34674 | - sys_mkdir("/old", 0700); | |
34675 | - root_fd = sys_open("/", 0, 0); | |
34676 | - old_fd = sys_open("/old", 0, 0); | |
34677 | + sys_mkdir((const char __user *)"/old", 0700); | |
34678 | + root_fd = sys_open((const char __user *)"/", 0, 0); | |
34679 | + old_fd = sys_open((const char __user *)"/old", 0, 0); | |
34680 | /* move initrd over / and chdir/chroot in initrd root */ | |
34681 | - sys_chdir("/root"); | |
34682 | - sys_mount(".", "/", NULL, MS_MOVE, NULL); | |
34683 | - sys_chroot("."); | |
34684 | + sys_chdir((const char __user *)"/root"); | |
34685 | + sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL); | |
34686 | + sys_chroot((const char __user *)"."); | |
34687 | ||
34688 | /* | |
34689 | * In case that a resume from disk is carried out by linuxrc or one of | |
34690 | @@ -70,15 +70,15 @@ static void __init handle_initrd(void) | |
34691 | ||
34692 | /* move initrd to rootfs' /old */ | |
34693 | sys_fchdir(old_fd); | |
34694 | - sys_mount("/", ".", NULL, MS_MOVE, NULL); | |
34695 | + sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL); | |
34696 | /* switch root and cwd back to / of rootfs */ | |
34697 | sys_fchdir(root_fd); | |
34698 | - sys_chroot("."); | |
34699 | + sys_chroot((const char __user *)"."); | |
34700 | sys_close(old_fd); | |
34701 | sys_close(root_fd); | |
34702 | ||
34703 | if (new_decode_dev(real_root_dev) == Root_RAM0) { | |
34704 | - sys_chdir("/old"); | |
34705 | + sys_chdir((const char __user *)"/old"); | |
34706 | return; | |
34707 | } | |
34708 | ||
34709 | @@ -86,17 +86,17 @@ static void __init handle_initrd(void) | |
34710 | mount_root(); | |
34711 | ||
34712 | printk(KERN_NOTICE "Trying to move old root to /initrd ... "); | |
34713 | - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); | |
34714 | + error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL); | |
34715 | if (!error) | |
34716 | printk("okay\n"); | |
34717 | else { | |
34718 | - int fd = sys_open("/dev/root.old", O_RDWR, 0); | |
34719 | + int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0); | |
34720 | if (error == -ENOENT) | |
34721 | printk("/initrd does not exist. Ignored.\n"); | |
34722 | else | |
34723 | printk("failed\n"); | |
34724 | printk(KERN_NOTICE "Unmounting old root\n"); | |
34725 | - sys_umount("/old", MNT_DETACH); | |
34726 | + sys_umount((char __user *)"/old", MNT_DETACH); | |
34727 | printk(KERN_NOTICE "Trying to free ramdisk memory ... "); | |
34728 | if (fd < 0) { | |
34729 | error = fd; | |
34730 | @@ -119,11 +119,11 @@ int __init initrd_load(void) | |
34731 | * mounted in the normal path. | |
34732 | */ | |
34733 | if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) { | |
34734 | - sys_unlink("/initrd.image"); | |
34735 | + sys_unlink((const char __user *)"/initrd.image"); | |
34736 | handle_initrd(); | |
34737 | return 1; | |
34738 | } | |
34739 | } | |
34740 | - sys_unlink("/initrd.image"); | |
34741 | + sys_unlink((const char __user *)"/initrd.image"); | |
34742 | return 0; | |
34743 | } | |
de855c5d AM |
34744 | diff -urNp linux-2.6.29.6/init/do_mounts_md.c linux-2.6.29.6/init/do_mounts_md.c |
34745 | --- linux-2.6.29.6/init/do_mounts_md.c 2009-07-02 19:41:20.000000000 -0400 | |
34746 | +++ linux-2.6.29.6/init/do_mounts_md.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34747 | @@ -171,7 +171,7 @@ static void __init md_setup_drive(void) |
34748 | partitioned ? "_d" : "", minor, | |
34749 | md_setup_args[ent].device_names); | |
34750 | ||
34751 | - fd = sys_open(name, 0, 0); | |
34752 | + fd = sys_open((char __user *)name, 0, 0); | |
34753 | if (fd < 0) { | |
34754 | printk(KERN_ERR "md: open failed - cannot start " | |
34755 | "array %s\n", name); | |
34756 | @@ -234,7 +234,7 @@ static void __init md_setup_drive(void) | |
34757 | * array without it | |
34758 | */ | |
34759 | sys_close(fd); | |
34760 | - fd = sys_open(name, 0, 0); | |
34761 | + fd = sys_open((char __user *)name, 0, 0); | |
34762 | sys_ioctl(fd, BLKRRPART, 0); | |
34763 | } | |
34764 | sys_close(fd); | |
34765 | @@ -284,7 +284,7 @@ static void __init autodetect_raid(void) | |
34766 | ||
34767 | wait_for_device_probe(); | |
34768 | ||
34769 | - fd = sys_open("/dev/md0", 0, 0); | |
34770 | + fd = sys_open((char __user *)"/dev/md0", 0, 0); | |
34771 | if (fd >= 0) { | |
34772 | sys_ioctl(fd, RAID_AUTORUN, raid_autopart); | |
34773 | sys_close(fd); | |
de855c5d AM |
34774 | diff -urNp linux-2.6.29.6/init/initramfs.c linux-2.6.29.6/init/initramfs.c |
34775 | --- linux-2.6.29.6/init/initramfs.c 2009-07-02 19:41:20.000000000 -0400 | |
34776 | +++ linux-2.6.29.6/init/initramfs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34777 | @@ -276,7 +276,7 @@ static int __init maybe_link(void) |
34778 | if (nlink >= 2) { | |
34779 | char *old = find_link(major, minor, ino, mode, collected); | |
34780 | if (old) | |
34781 | - return (sys_link(old, collected) < 0) ? -1 : 1; | |
34782 | + return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1; | |
34783 | } | |
34784 | return 0; | |
34785 | } | |
34786 | @@ -285,11 +285,11 @@ static void __init clean_path(char *path | |
34787 | { | |
34788 | struct stat st; | |
34789 | ||
34790 | - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) { | |
34791 | + if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) { | |
34792 | if (S_ISDIR(st.st_mode)) | |
34793 | - sys_rmdir(path); | |
34794 | + sys_rmdir((char __user *)path); | |
34795 | else | |
34796 | - sys_unlink(path); | |
34797 | + sys_unlink((char __user *)path); | |
34798 | } | |
34799 | } | |
34800 | ||
34801 | @@ -312,7 +312,7 @@ static int __init do_name(void) | |
34802 | int openflags = O_WRONLY|O_CREAT; | |
34803 | if (ml != 1) | |
34804 | openflags |= O_TRUNC; | |
34805 | - wfd = sys_open(collected, openflags, mode); | |
34806 | + wfd = sys_open((char __user *)collected, openflags, mode); | |
34807 | ||
34808 | if (wfd >= 0) { | |
34809 | sys_fchown(wfd, uid, gid); | |
34810 | @@ -323,16 +323,16 @@ static int __init do_name(void) | |
34811 | } | |
34812 | } | |
34813 | } else if (S_ISDIR(mode)) { | |
34814 | - sys_mkdir(collected, mode); | |
34815 | - sys_chown(collected, uid, gid); | |
34816 | - sys_chmod(collected, mode); | |
34817 | + sys_mkdir((char __user *)collected, mode); | |
34818 | + sys_chown((char __user *)collected, uid, gid); | |
34819 | + sys_chmod((char __user *)collected, mode); | |
34820 | dir_add(collected, mtime); | |
34821 | } else if (S_ISBLK(mode) || S_ISCHR(mode) || | |
34822 | S_ISFIFO(mode) || S_ISSOCK(mode)) { | |
34823 | if (maybe_link() == 0) { | |
34824 | - sys_mknod(collected, mode, rdev); | |
34825 | - sys_chown(collected, uid, gid); | |
34826 | - sys_chmod(collected, mode); | |
34827 | + sys_mknod((char __user *)collected, mode, rdev); | |
34828 | + sys_chown((char __user *)collected, uid, gid); | |
34829 | + sys_chmod((char __user *)collected, mode); | |
34830 | do_utime(collected, mtime); | |
34831 | } | |
34832 | } | |
34833 | @@ -342,7 +342,7 @@ static int __init do_name(void) | |
34834 | static int __init do_copy(void) | |
34835 | { | |
34836 | if (count >= body_len) { | |
34837 | - sys_write(wfd, victim, body_len); | |
34838 | + sys_write(wfd, (char __user *)victim, body_len); | |
34839 | sys_close(wfd); | |
34840 | do_utime(vcollected, mtime); | |
34841 | kfree(vcollected); | |
34842 | @@ -350,7 +350,7 @@ static int __init do_copy(void) | |
34843 | state = SkipIt; | |
34844 | return 0; | |
34845 | } else { | |
34846 | - sys_write(wfd, victim, count); | |
34847 | + sys_write(wfd, (char __user *)victim, count); | |
34848 | body_len -= count; | |
34849 | eat(count); | |
34850 | return 1; | |
34851 | @@ -361,8 +361,8 @@ static int __init do_symlink(void) | |
34852 | { | |
34853 | collected[N_ALIGN(name_len) + body_len] = '\0'; | |
34854 | clean_path(collected, 0); | |
34855 | - sys_symlink(collected + N_ALIGN(name_len), collected); | |
34856 | - sys_lchown(collected, uid, gid); | |
34857 | + sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected); | |
34858 | + sys_lchown((char __user *)collected, uid, gid); | |
34859 | do_utime(collected, mtime); | |
34860 | state = SkipIt; | |
34861 | next_state = Reset; | |
de855c5d AM |
34862 | diff -urNp linux-2.6.29.6/init/Kconfig linux-2.6.29.6/init/Kconfig |
34863 | --- linux-2.6.29.6/init/Kconfig 2009-07-02 19:41:20.000000000 -0400 | |
34864 | +++ linux-2.6.29.6/init/Kconfig 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34865 | @@ -712,6 +712,7 @@ config SYSCTL_SYSCALL |
34866 | config KALLSYMS | |
34867 | bool "Load all symbols for debugging/ksymoops" if EMBEDDED | |
34868 | default y | |
34869 | + depends on !GRKERNSEC_HIDESYM | |
34870 | help | |
34871 | Say Y here to let the kernel print out symbolic crash information and | |
34872 | symbolic stack backtraces. This increases the size of the kernel | |
de855c5d AM |
34873 | @@ -887,7 +888,7 @@ config SLUB_DEBUG |
34874 | ||
34875 | config COMPAT_BRK | |
34876 | bool "Disable heap randomization" | |
34877 | - default y | |
34878 | + default n | |
34879 | help | |
34880 | Randomizing heap placement makes heap exploits harder, but it | |
34881 | also breaks ancient binaries (including anything libc5 based). | |
2380c486 JR |
34882 | @@ -960,9 +961,9 @@ config HAVE_GENERIC_DMA_COHERENT |
34883 | ||
34884 | config SLABINFO | |
34885 | bool | |
34886 | - depends on PROC_FS | |
34887 | + depends on PROC_FS && !GRKERNSEC_PROC_ADD | |
34888 | depends on SLAB || SLUB_DEBUG | |
34889 | - default y | |
34890 | + default n | |
34891 | ||
34892 | config RT_MUTEXES | |
34893 | boolean | |
de855c5d AM |
34894 | diff -urNp linux-2.6.29.6/init/main.c linux-2.6.29.6/init/main.c |
34895 | --- linux-2.6.29.6/init/main.c 2009-07-02 19:41:20.000000000 -0400 | |
34896 | +++ linux-2.6.29.6/init/main.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34897 | @@ -96,6 +96,7 @@ static inline void mark_rodata_ro(void) |
34898 | #ifdef CONFIG_TC | |
34899 | extern void tc_init(void); | |
34900 | #endif | |
34901 | +extern void grsecurity_init(void); | |
34902 | ||
34903 | enum system_states system_state __read_mostly; | |
34904 | EXPORT_SYMBOL(system_state); | |
34905 | @@ -182,6 +183,40 @@ static int __init set_reset_devices(char | |
34906 | ||
34907 | __setup("reset_devices", set_reset_devices); | |
34908 | ||
34909 | +#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32) | |
34910 | +static int __init setup_pax_nouderef(char *str) | |
34911 | +{ | |
34912 | + unsigned int cpu; | |
34913 | + | |
34914 | +#ifdef CONFIG_PAX_KERNEXEC | |
34915 | + unsigned long cr0; | |
34916 | + | |
34917 | + pax_open_kernel(cr0); | |
34918 | +#endif | |
34919 | + | |
34920 | + for (cpu = 0; cpu < NR_CPUS; cpu++) | |
34921 | + get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300; | |
34922 | + | |
34923 | +#ifdef CONFIG_PAX_KERNEXEC | |
34924 | + pax_close_kernel(cr0); | |
34925 | +#endif | |
34926 | + | |
34927 | + return 1; | |
34928 | +} | |
34929 | +__setup("pax_nouderef", setup_pax_nouderef); | |
34930 | +#endif | |
34931 | + | |
34932 | +#ifdef CONFIG_PAX_SOFTMODE | |
34933 | +unsigned int pax_softmode; | |
34934 | + | |
34935 | +static int __init setup_pax_softmode(char *str) | |
34936 | +{ | |
34937 | + get_option(&str, &pax_softmode); | |
34938 | + return 1; | |
34939 | +} | |
34940 | +__setup("pax_softmode=", setup_pax_softmode); | |
34941 | +#endif | |
34942 | + | |
34943 | static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; | |
34944 | char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; | |
34945 | static const char *panic_later, *panic_param; | |
34946 | @@ -375,7 +410,7 @@ static void __init setup_nr_cpu_ids(void | |
34947 | } | |
34948 | ||
34949 | #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA | |
34950 | -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; | |
34951 | +unsigned long __per_cpu_offset[NR_CPUS] __read_only; | |
34952 | ||
34953 | EXPORT_SYMBOL(__per_cpu_offset); | |
34954 | ||
34955 | @@ -694,6 +729,7 @@ int do_one_initcall(initcall_t fn) | |
34956 | { | |
34957 | int count = preempt_count(); | |
34958 | ktime_t calltime, delta, rettime; | |
34959 | + const char *msg1 = "", *msg2 = ""; | |
34960 | char msgbuf[64]; | |
34961 | struct boot_trace_call call; | |
34962 | struct boot_trace_ret ret; | |
34963 | @@ -724,15 +760,15 @@ int do_one_initcall(initcall_t fn) | |
34964 | sprintf(msgbuf, "error code %d ", ret.result); | |
34965 | ||
34966 | if (preempt_count() != count) { | |
34967 | - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf)); | |
34968 | + msg1 = " preemption imbalance"; | |
34969 | preempt_count() = count; | |
34970 | } | |
34971 | if (irqs_disabled()) { | |
34972 | - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf)); | |
34973 | + msg2 = " disabled interrupts"; | |
34974 | local_irq_enable(); | |
34975 | } | |
34976 | - if (msgbuf[0]) { | |
34977 | - printk("initcall %pF returned with %s\n", fn, msgbuf); | |
34978 | + if (msgbuf[0] || *msg1 || *msg2) { | |
34979 | + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2); | |
34980 | } | |
34981 | ||
34982 | return ret.result; | |
34983 | @@ -873,6 +909,8 @@ static int __init kernel_init(void * unu | |
34984 | prepare_namespace(); | |
34985 | } | |
34986 | ||
34987 | + grsecurity_init(); | |
34988 | + | |
34989 | /* | |
34990 | * Ok, we have completed the initial bootup, and | |
34991 | * we're essentially up and running. Get rid of the | |
de855c5d AM |
34992 | diff -urNp linux-2.6.29.6/init/noinitramfs.c linux-2.6.29.6/init/noinitramfs.c |
34993 | --- linux-2.6.29.6/init/noinitramfs.c 2009-07-02 19:41:20.000000000 -0400 | |
34994 | +++ linux-2.6.29.6/init/noinitramfs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
34995 | @@ -29,7 +29,7 @@ static int __init default_rootfs(void) |
34996 | { | |
34997 | int err; | |
34998 | ||
34999 | - err = sys_mkdir("/dev", 0755); | |
35000 | + err = sys_mkdir((const char __user *)"/dev", 0755); | |
35001 | if (err < 0) | |
35002 | goto out; | |
35003 | ||
35004 | @@ -39,7 +39,7 @@ static int __init default_rootfs(void) | |
35005 | if (err < 0) | |
35006 | goto out; | |
35007 | ||
35008 | - err = sys_mkdir("/root", 0700); | |
35009 | + err = sys_mkdir((const char __user *)"/root", 0700); | |
35010 | if (err < 0) | |
35011 | goto out; | |
35012 | ||
de855c5d AM |
35013 | diff -urNp linux-2.6.29.6/ipc/ipc_sysctl.c linux-2.6.29.6/ipc/ipc_sysctl.c |
35014 | --- linux-2.6.29.6/ipc/ipc_sysctl.c 2009-07-02 19:41:20.000000000 -0400 | |
35015 | +++ linux-2.6.29.6/ipc/ipc_sysctl.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35016 | @@ -267,7 +267,7 @@ static struct ctl_table ipc_kern_table[] |
35017 | .extra1 = &zero, | |
35018 | .extra2 = &one, | |
35019 | }, | |
35020 | - {} | |
35021 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
35022 | }; | |
35023 | ||
35024 | static struct ctl_table ipc_root_table[] = { | |
35025 | @@ -277,7 +277,7 @@ static struct ctl_table ipc_root_table[] | |
35026 | .mode = 0555, | |
35027 | .child = ipc_kern_table, | |
35028 | }, | |
35029 | - {} | |
35030 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
35031 | }; | |
35032 | ||
35033 | static int __init ipc_sysctl_init(void) | |
de855c5d AM |
35034 | diff -urNp linux-2.6.29.6/ipc/mqueue.c linux-2.6.29.6/ipc/mqueue.c |
35035 | --- linux-2.6.29.6/ipc/mqueue.c 2009-07-02 19:41:20.000000000 -0400 | |
35036 | +++ linux-2.6.29.6/ipc/mqueue.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35037 | @@ -151,6 +151,7 @@ static struct inode *mqueue_get_inode(st |
35038 | mq_bytes = (mq_msg_tblsz + | |
35039 | (info->attr.mq_maxmsg * info->attr.mq_msgsize)); | |
35040 | ||
35041 | + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1); | |
35042 | spin_lock(&mq_lock); | |
35043 | if (u->mq_bytes + mq_bytes < u->mq_bytes || | |
35044 | u->mq_bytes + mq_bytes > | |
de855c5d AM |
35045 | diff -urNp linux-2.6.29.6/ipc/msg.c linux-2.6.29.6/ipc/msg.c |
35046 | --- linux-2.6.29.6/ipc/msg.c 2009-07-02 19:41:20.000000000 -0400 | |
35047 | +++ linux-2.6.29.6/ipc/msg.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35048 | @@ -314,6 +314,7 @@ SYSCALL_DEFINE2(msgget, key_t, key, int, |
35049 | struct ipc_namespace *ns; | |
35050 | struct ipc_ops msg_ops; | |
35051 | struct ipc_params msg_params; | |
35052 | + long err; | |
35053 | ||
35054 | ns = current->nsproxy->ipc_ns; | |
35055 | ||
35056 | @@ -324,7 +325,11 @@ SYSCALL_DEFINE2(msgget, key_t, key, int, | |
35057 | msg_params.key = key; | |
35058 | msg_params.flg = msgflg; | |
35059 | ||
35060 | - return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params); | |
35061 | + err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params); | |
35062 | + | |
35063 | + gr_log_msgget(err, msgflg); | |
35064 | + | |
35065 | + return err; | |
35066 | } | |
35067 | ||
35068 | static inline unsigned long | |
35069 | @@ -434,6 +439,7 @@ static int msgctl_down(struct ipc_namesp | |
35070 | ||
35071 | switch (cmd) { | |
35072 | case IPC_RMID: | |
35073 | + gr_log_msgrm(ipcp->uid, ipcp->cuid); | |
35074 | freeque(ns, ipcp); | |
35075 | goto out_up; | |
35076 | case IPC_SET: | |
de855c5d AM |
35077 | diff -urNp linux-2.6.29.6/ipc/sem.c linux-2.6.29.6/ipc/sem.c |
35078 | --- linux-2.6.29.6/ipc/sem.c 2009-07-02 19:41:20.000000000 -0400 | |
35079 | +++ linux-2.6.29.6/ipc/sem.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35080 | @@ -313,6 +313,7 @@ SYSCALL_DEFINE3(semget, key_t, key, int, |
35081 | struct ipc_namespace *ns; | |
35082 | struct ipc_ops sem_ops; | |
35083 | struct ipc_params sem_params; | |
35084 | + long err; | |
35085 | ||
35086 | ns = current->nsproxy->ipc_ns; | |
35087 | ||
35088 | @@ -327,7 +328,11 @@ SYSCALL_DEFINE3(semget, key_t, key, int, | |
35089 | sem_params.flg = semflg; | |
35090 | sem_params.u.nsems = nsems; | |
35091 | ||
35092 | - return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params); | |
35093 | + err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params); | |
35094 | + | |
35095 | + gr_log_semget(err, semflg); | |
35096 | + | |
35097 | + return err; | |
35098 | } | |
35099 | ||
35100 | /* | |
35101 | @@ -870,6 +875,7 @@ static int semctl_down(struct ipc_namesp | |
35102 | ||
35103 | switch(cmd){ | |
35104 | case IPC_RMID: | |
35105 | + gr_log_semrm(ipcp->uid, ipcp->cuid); | |
35106 | freeary(ns, ipcp); | |
35107 | goto out_up; | |
35108 | case IPC_SET: | |
de855c5d AM |
35109 | diff -urNp linux-2.6.29.6/ipc/shm.c linux-2.6.29.6/ipc/shm.c |
35110 | --- linux-2.6.29.6/ipc/shm.c 2009-07-02 19:41:20.000000000 -0400 | |
35111 | +++ linux-2.6.29.6/ipc/shm.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35112 | @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name |
35113 | static int sysvipc_shm_proc_show(struct seq_file *s, void *it); | |
35114 | #endif | |
35115 | ||
35116 | +#ifdef CONFIG_GRKERNSEC | |
35117 | +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid, | |
35118 | + const time_t shm_createtime, const uid_t cuid, | |
35119 | + const int shmid); | |
35120 | +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid, | |
35121 | + const time_t shm_createtime); | |
35122 | +#endif | |
35123 | + | |
35124 | void shm_init_ns(struct ipc_namespace *ns) | |
35125 | { | |
35126 | ns->shm_ctlmax = SHMMAX; | |
35127 | @@ -87,6 +95,8 @@ static void do_shm_rmid(struct ipc_names | |
35128 | struct shmid_kernel *shp; | |
35129 | shp = container_of(ipcp, struct shmid_kernel, shm_perm); | |
35130 | ||
35131 | + gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid); | |
35132 | + | |
35133 | if (shp->shm_nattch){ | |
35134 | shp->shm_perm.mode |= SHM_DEST; | |
35135 | /* Do not find it any more */ | |
35136 | @@ -394,6 +404,14 @@ static int newseg(struct ipc_namespace * | |
35137 | shp->shm_lprid = 0; | |
35138 | shp->shm_atim = shp->shm_dtim = 0; | |
35139 | shp->shm_ctim = get_seconds(); | |
35140 | +#ifdef CONFIG_GRKERNSEC | |
35141 | + { | |
35142 | + struct timespec timeval; | |
35143 | + do_posix_clock_monotonic_gettime(&timeval); | |
35144 | + | |
35145 | + shp->shm_createtime = timeval.tv_sec; | |
35146 | + } | |
35147 | +#endif | |
35148 | shp->shm_segsz = size; | |
35149 | shp->shm_nattch = 0; | |
35150 | shp->shm_file = file; | |
35151 | @@ -447,6 +465,7 @@ SYSCALL_DEFINE3(shmget, key_t, key, size | |
35152 | struct ipc_namespace *ns; | |
35153 | struct ipc_ops shm_ops; | |
35154 | struct ipc_params shm_params; | |
35155 | + long err; | |
35156 | ||
35157 | ns = current->nsproxy->ipc_ns; | |
35158 | ||
35159 | @@ -458,7 +477,11 @@ SYSCALL_DEFINE3(shmget, key_t, key, size | |
35160 | shm_params.flg = shmflg; | |
35161 | shm_params.u.size = size; | |
35162 | ||
35163 | - return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params); | |
35164 | + err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params); | |
35165 | + | |
35166 | + gr_log_shmget(err, shmflg, size); | |
35167 | + | |
35168 | + return err; | |
35169 | } | |
35170 | ||
35171 | static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version) | |
35172 | @@ -873,9 +896,21 @@ long do_shmat(int shmid, char __user *sh | |
35173 | if (err) | |
35174 | goto out_unlock; | |
35175 | ||
35176 | +#ifdef CONFIG_GRKERNSEC | |
35177 | + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime, | |
35178 | + shp->shm_perm.cuid, shmid) || | |
35179 | + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) { | |
35180 | + err = -EACCES; | |
35181 | + goto out_unlock; | |
35182 | + } | |
35183 | +#endif | |
35184 | + | |
35185 | path.dentry = dget(shp->shm_file->f_path.dentry); | |
35186 | path.mnt = shp->shm_file->f_path.mnt; | |
35187 | shp->shm_nattch++; | |
35188 | +#ifdef CONFIG_GRKERNSEC | |
35189 | + shp->shm_lapid = current->pid; | |
35190 | +#endif | |
35191 | size = i_size_read(path.dentry->d_inode); | |
35192 | shm_unlock(shp); | |
35193 | ||
de855c5d AM |
35194 | diff -urNp linux-2.6.29.6/kernel/acct.c linux-2.6.29.6/kernel/acct.c |
35195 | --- linux-2.6.29.6/kernel/acct.c 2009-07-02 19:41:20.000000000 -0400 | |
35196 | +++ linux-2.6.29.6/kernel/acct.c 2009-07-09 22:13:39.000000000 -0400 | |
35197 | @@ -574,7 +574,7 @@ static void do_acct_process(struct bsd_a | |
2380c486 JR |
35198 | */ |
35199 | flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; | |
35200 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; | |
35201 | - file->f_op->write(file, (char *)&ac, | |
35202 | + file->f_op->write(file, (char __user *)&ac, | |
35203 | sizeof(acct_t), &file->f_pos); | |
35204 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; | |
35205 | set_fs(fs); | |
de855c5d AM |
35206 | diff -urNp linux-2.6.29.6/kernel/capability.c linux-2.6.29.6/kernel/capability.c |
35207 | --- linux-2.6.29.6/kernel/capability.c 2009-07-02 19:41:20.000000000 -0400 | |
35208 | +++ linux-2.6.29.6/kernel/capability.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35209 | @@ -306,10 +306,21 @@ int capable(int cap) |
35210 | BUG(); | |
35211 | } | |
35212 | ||
35213 | - if (security_capable(cap) == 0) { | |
35214 | + if (security_capable(cap) == 0 && gr_is_capable(cap)) { | |
35215 | current->flags |= PF_SUPERPRIV; | |
35216 | return 1; | |
35217 | } | |
35218 | return 0; | |
35219 | } | |
35220 | + | |
35221 | +int capable_nolog(int cap) | |
35222 | +{ | |
35223 | + if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) { | |
35224 | + current->flags |= PF_SUPERPRIV; | |
35225 | + return 1; | |
35226 | + } | |
35227 | + return 0; | |
35228 | +} | |
35229 | + | |
35230 | EXPORT_SYMBOL(capable); | |
35231 | +EXPORT_SYMBOL(capable_nolog); | |
de855c5d AM |
35232 | diff -urNp linux-2.6.29.6/kernel/configs.c linux-2.6.29.6/kernel/configs.c |
35233 | --- linux-2.6.29.6/kernel/configs.c 2009-07-02 19:41:20.000000000 -0400 | |
35234 | +++ linux-2.6.29.6/kernel/configs.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35235 | @@ -73,8 +73,19 @@ static int __init ikconfig_init(void) |
35236 | struct proc_dir_entry *entry; | |
35237 | ||
35238 | /* create the current config file */ | |
35239 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
35240 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
35241 | + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL, | |
35242 | + &ikconfig_file_ops); | |
35243 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
35244 | + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL, | |
35245 | + &ikconfig_file_ops); | |
35246 | +#endif | |
35247 | +#else | |
35248 | entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL, | |
35249 | &ikconfig_file_ops); | |
35250 | +#endif | |
35251 | + | |
35252 | if (!entry) | |
35253 | return -ENOMEM; | |
35254 | ||
de855c5d AM |
35255 | diff -urNp linux-2.6.29.6/kernel/cpu.c linux-2.6.29.6/kernel/cpu.c |
35256 | --- linux-2.6.29.6/kernel/cpu.c 2009-07-02 19:41:20.000000000 -0400 | |
35257 | +++ linux-2.6.29.6/kernel/cpu.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35258 | @@ -19,7 +19,7 @@ |
35259 | /* Serializes the updates to cpu_online_mask, cpu_present_mask */ | |
35260 | static DEFINE_MUTEX(cpu_add_remove_lock); | |
35261 | ||
35262 | -static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain); | |
35263 | +static RAW_NOTIFIER_HEAD(cpu_chain); | |
35264 | ||
35265 | /* If set, cpu_up and cpu_down will return -EBUSY and do nothing. | |
35266 | * Should always be manipulated under cpu_add_remove_lock | |
de855c5d AM |
35267 | diff -urNp linux-2.6.29.6/kernel/cred.c linux-2.6.29.6/kernel/cred.c |
35268 | --- linux-2.6.29.6/kernel/cred.c 2009-07-02 19:41:20.000000000 -0400 | |
35269 | +++ linux-2.6.29.6/kernel/cred.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35270 | @@ -366,6 +366,8 @@ int commit_creds(struct cred *new) |
35271 | ||
35272 | get_cred(new); /* we will require a ref for the subj creds too */ | |
35273 | ||
35274 | + gr_set_role_label(task, new->uid, new->gid); | |
35275 | + | |
35276 | /* dumpability changes */ | |
35277 | if (old->euid != new->euid || | |
35278 | old->egid != new->egid || | |
de855c5d AM |
35279 | diff -urNp linux-2.6.29.6/kernel/exit.c linux-2.6.29.6/kernel/exit.c |
35280 | --- linux-2.6.29.6/kernel/exit.c 2009-07-02 19:41:20.000000000 -0400 | |
35281 | +++ linux-2.6.29.6/kernel/exit.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35282 | @@ -59,6 +59,10 @@ DEFINE_TRACE(sched_process_free); |
35283 | DEFINE_TRACE(sched_process_exit); | |
35284 | DEFINE_TRACE(sched_process_wait); | |
35285 | ||
35286 | +#ifdef CONFIG_GRKERNSEC | |
35287 | +extern rwlock_t grsec_exec_file_lock; | |
35288 | +#endif | |
35289 | + | |
35290 | static void exit_mm(struct task_struct * tsk); | |
35291 | ||
35292 | static inline int task_detached(struct task_struct *p) | |
35293 | @@ -172,6 +176,8 @@ void release_task(struct task_struct * p | |
35294 | struct task_struct *leader; | |
35295 | int zap_leader; | |
35296 | repeat: | |
35297 | + gr_del_task_from_ip_table(p); | |
35298 | + | |
35299 | tracehook_prepare_release_task(p); | |
35300 | /* don't need to get the RCU readlock here - the process is dead and | |
35301 | * can't be modifying its own credentials */ | |
35302 | @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void) | |
35303 | { | |
35304 | write_lock_irq(&tasklist_lock); | |
35305 | ||
35306 | +#ifdef CONFIG_GRKERNSEC | |
35307 | + write_lock(&grsec_exec_file_lock); | |
35308 | + if (current->exec_file) { | |
35309 | + fput(current->exec_file); | |
35310 | + current->exec_file = NULL; | |
35311 | + } | |
35312 | + write_unlock(&grsec_exec_file_lock); | |
35313 | +#endif | |
35314 | + | |
35315 | ptrace_unlink(current); | |
35316 | /* Reparent to init */ | |
35317 | current->real_parent = current->parent = kthreadd_task; | |
35318 | list_move_tail(¤t->sibling, ¤t->real_parent->children); | |
35319 | ||
35320 | + gr_set_kernel_label(current); | |
35321 | + | |
35322 | /* Set the exit signal to SIGCHLD so we signal init on exit */ | |
35323 | current->exit_signal = SIGCHLD; | |
35324 | ||
de855c5d | 35325 | @@ -435,6 +452,17 @@ void daemonize(const char *name, ...) |
2380c486 JR |
35326 | vsnprintf(current->comm, sizeof(current->comm), name, args); |
35327 | va_end(args); | |
35328 | ||
35329 | +#ifdef CONFIG_GRKERNSEC | |
35330 | + write_lock(&grsec_exec_file_lock); | |
35331 | + if (current->exec_file) { | |
35332 | + fput(current->exec_file); | |
35333 | + current->exec_file = NULL; | |
35334 | + } | |
35335 | + write_unlock(&grsec_exec_file_lock); | |
35336 | +#endif | |
35337 | + | |
35338 | + gr_set_kernel_label(current); | |
35339 | + | |
35340 | /* | |
35341 | * If we were started as result of loading a module, close all of the | |
35342 | * user space pages. We don't need them, and if we didn't close them | |
de855c5d | 35343 | @@ -1034,6 +1062,9 @@ NORET_TYPE void do_exit(long code) |
2380c486 JR |
35344 | tsk->exit_code = code; |
35345 | taskstats_exit(tsk, group_dead); | |
35346 | ||
35347 | + gr_acl_handle_psacct(tsk, code); | |
35348 | + gr_acl_handle_exit(); | |
35349 | + | |
35350 | exit_mm(tsk); | |
35351 | ||
35352 | if (group_dead) | |
de855c5d | 35353 | @@ -1238,7 +1269,7 @@ static int wait_task_zombie(struct task_ |
2380c486 JR |
35354 | |
35355 | if (unlikely(options & WNOWAIT)) { | |
35356 | int exit_code = p->exit_code; | |
35357 | - int why, status; | |
35358 | + int why; | |
35359 | ||
35360 | get_task_struct(p); | |
35361 | read_unlock(&tasklist_lock); | |
de855c5d AM |
35362 | diff -urNp linux-2.6.29.6/kernel/fork.c linux-2.6.29.6/kernel/fork.c |
35363 | --- linux-2.6.29.6/kernel/fork.c 2009-07-02 19:41:20.000000000 -0400 | |
35364 | +++ linux-2.6.29.6/kernel/fork.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35365 | @@ -239,7 +239,7 @@ static struct task_struct *dup_task_stru |
35366 | setup_thread_stack(tsk, orig); | |
35367 | ||
35368 | #ifdef CONFIG_CC_STACKPROTECTOR | |
35369 | - tsk->stack_canary = get_random_int(); | |
35370 | + tsk->stack_canary = pax_get_random_long(); | |
35371 | #endif | |
35372 | ||
35373 | /* One for us, one for whoever does the "release_task()" (usually parent) */ | |
35374 | @@ -276,8 +276,8 @@ static int dup_mmap(struct mm_struct *mm | |
35375 | mm->locked_vm = 0; | |
35376 | mm->mmap = NULL; | |
35377 | mm->mmap_cache = NULL; | |
35378 | - mm->free_area_cache = oldmm->mmap_base; | |
35379 | - mm->cached_hole_size = ~0UL; | |
35380 | + mm->free_area_cache = oldmm->free_area_cache; | |
35381 | + mm->cached_hole_size = oldmm->cached_hole_size; | |
35382 | mm->map_count = 0; | |
35383 | cpus_clear(mm->cpu_vm_mask); | |
35384 | mm->mm_rb = RB_ROOT; | |
35385 | @@ -314,6 +314,7 @@ static int dup_mmap(struct mm_struct *mm | |
35386 | tmp->vm_flags &= ~VM_LOCKED; | |
35387 | tmp->vm_mm = mm; | |
35388 | tmp->vm_next = NULL; | |
35389 | + tmp->vm_mirror = NULL; | |
35390 | anon_vma_link(tmp); | |
35391 | file = tmp->vm_file; | |
35392 | if (file) { | |
35393 | @@ -361,6 +362,31 @@ static int dup_mmap(struct mm_struct *mm | |
35394 | if (retval) | |
35395 | goto out; | |
35396 | } | |
35397 | + | |
35398 | +#ifdef CONFIG_PAX_SEGMEXEC | |
35399 | + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) { | |
35400 | + struct vm_area_struct *mpnt_m; | |
35401 | + | |
35402 | + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) { | |
35403 | + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm); | |
35404 | + | |
35405 | + if (!mpnt->vm_mirror) | |
35406 | + continue; | |
35407 | + | |
35408 | + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) { | |
35409 | + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt); | |
35410 | + mpnt->vm_mirror = mpnt_m; | |
35411 | + } else { | |
35412 | + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm); | |
35413 | + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror; | |
35414 | + mpnt_m->vm_mirror->vm_mirror = mpnt_m; | |
35415 | + mpnt->vm_mirror->vm_mirror = mpnt; | |
35416 | + } | |
35417 | + } | |
35418 | + BUG_ON(mpnt_m); | |
35419 | + } | |
35420 | +#endif | |
35421 | + | |
35422 | /* a new mm has just been created */ | |
35423 | arch_dup_mmap(oldmm, mm); | |
35424 | retval = 0; | |
35425 | @@ -541,9 +567,11 @@ void mm_release(struct task_struct *tsk, | |
35426 | #ifdef CONFIG_FUTEX | |
35427 | if (unlikely(tsk->robust_list)) | |
35428 | exit_robust_list(tsk); | |
35429 | + tsk->robust_list = NULL; | |
35430 | #ifdef CONFIG_COMPAT | |
35431 | if (unlikely(tsk->compat_robust_list)) | |
35432 | compat_exit_robust_list(tsk); | |
35433 | + tsk->compat_robust_list = NULL; | |
35434 | #endif | |
35435 | #endif | |
35436 | ||
35437 | @@ -565,7 +593,7 @@ void mm_release(struct task_struct *tsk, | |
35438 | if (tsk->clear_child_tid | |
35439 | && !(tsk->flags & PF_SIGNALED) | |
35440 | && atomic_read(&mm->mm_users) > 1) { | |
35441 | - u32 __user * tidptr = tsk->clear_child_tid; | |
35442 | + pid_t __user * tidptr = tsk->clear_child_tid; | |
35443 | tsk->clear_child_tid = NULL; | |
35444 | ||
35445 | /* | |
35446 | @@ -573,7 +601,7 @@ void mm_release(struct task_struct *tsk, | |
35447 | * not set up a proper pointer then tough luck. | |
35448 | */ | |
35449 | put_user(0, tidptr); | |
35450 | - sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0); | |
35451 | + sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0); | |
35452 | } | |
35453 | } | |
35454 | ||
de855c5d AM |
35455 | @@ -686,7 +714,7 @@ static int copy_fs(unsigned long clone_f |
35456 | write_unlock(&fs->lock); | |
35457 | return -EAGAIN; | |
35458 | } | |
35459 | - fs->users++; | |
35460 | + atomic_inc(&fs->users); | |
35461 | write_unlock(&fs->lock); | |
35462 | return 0; | |
35463 | } | |
35464 | @@ -978,6 +1006,9 @@ static struct task_struct *copy_process( | |
35465 | DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled); | |
35466 | #endif | |
2380c486 | 35467 | retval = -EAGAIN; |
de855c5d | 35468 | + |
2380c486 | 35469 | + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0); |
de855c5d | 35470 | + |
2380c486 JR |
35471 | if (atomic_read(&p->real_cred->user->processes) >= |
35472 | p->signal->rlim[RLIMIT_NPROC].rlim_cur) { | |
35473 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && | |
de855c5d | 35474 | @@ -1138,6 +1169,8 @@ static struct task_struct *copy_process( |
2380c486 JR |
35475 | goto bad_fork_free_graph; |
35476 | } | |
35477 | ||
35478 | + gr_copy_label(p); | |
35479 | + | |
35480 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | |
35481 | /* | |
35482 | * Clear TID on mm_release()? | |
de855c5d | 35483 | @@ -1306,6 +1339,8 @@ bad_fork_cleanup_count: |
2380c486 JR |
35484 | bad_fork_free: |
35485 | free_task(p); | |
35486 | fork_out: | |
35487 | + gr_log_forkfail(retval); | |
35488 | + | |
35489 | return ERR_PTR(retval); | |
35490 | } | |
35491 | ||
de855c5d | 35492 | @@ -1399,6 +1434,8 @@ long do_fork(unsigned long clone_flags, |
2380c486 JR |
35493 | if (clone_flags & CLONE_PARENT_SETTID) |
35494 | put_user(nr, parent_tidptr); | |
35495 | ||
35496 | + gr_handle_brute_check(); | |
35497 | + | |
35498 | if (clone_flags & CLONE_VFORK) { | |
35499 | p->vfork_done = &vfork; | |
35500 | init_completion(&vfork); | |
de855c5d AM |
35501 | @@ -1530,7 +1567,7 @@ static int unshare_fs(unsigned long unsh |
35502 | return 0; | |
35503 | ||
35504 | /* don't need lock here; in the worst case we'll do useless copy */ | |
35505 | - if (fs->users == 1) | |
35506 | + if (atomic_read(&fs->users) == 1) | |
35507 | return 0; | |
35508 | ||
35509 | *new_fsp = copy_fs_struct(fs); | |
35510 | @@ -1653,7 +1690,7 @@ SYSCALL_DEFINE1(unshare, unsigned long, | |
35511 | fs = current->fs; | |
35512 | write_lock(&fs->lock); | |
35513 | current->fs = new_fs; | |
35514 | - if (--fs->users) | |
35515 | + if (atomic_dec_return(&fs->users)) | |
35516 | new_fs = NULL; | |
35517 | else | |
35518 | new_fs = fs; | |
35519 | diff -urNp linux-2.6.29.6/kernel/futex.c linux-2.6.29.6/kernel/futex.c | |
35520 | --- linux-2.6.29.6/kernel/futex.c 2009-07-02 19:41:20.000000000 -0400 | |
35521 | +++ linux-2.6.29.6/kernel/futex.c 2009-07-09 22:13:39.000000000 -0400 | |
35522 | @@ -213,6 +213,11 @@ get_futex_key(u32 __user *uaddr, int fsh | |
2380c486 JR |
35523 | struct page *page; |
35524 | int err; | |
35525 | ||
35526 | +#ifdef CONFIG_PAX_SEGMEXEC | |
35527 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE) | |
35528 | + return -EFAULT; | |
35529 | +#endif | |
35530 | + | |
35531 | /* | |
35532 | * The futex address must be "naturally" aligned. | |
35533 | */ | |
de855c5d | 35534 | @@ -1306,7 +1311,7 @@ retry: |
2380c486 JR |
35535 | |
35536 | restart = ¤t_thread_info()->restart_block; | |
35537 | restart->fn = futex_wait_restart; | |
35538 | - restart->futex.uaddr = (u32 *)uaddr; | |
35539 | + restart->futex.uaddr = uaddr; | |
35540 | restart->futex.val = val; | |
35541 | restart->futex.time = abs_time->tv64; | |
35542 | restart->futex.bitset = bitset; | |
de855c5d | 35543 | @@ -1848,7 +1853,7 @@ retry: |
2380c486 JR |
35544 | */ |
35545 | static inline int fetch_robust_entry(struct robust_list __user **entry, | |
35546 | struct robust_list __user * __user *head, | |
35547 | - int *pi) | |
35548 | + unsigned int *pi) | |
35549 | { | |
35550 | unsigned long uentry; | |
35551 | ||
de855c5d AM |
35552 | diff -urNp linux-2.6.29.6/kernel/irq/handle.c linux-2.6.29.6/kernel/irq/handle.c |
35553 | --- linux-2.6.29.6/kernel/irq/handle.c 2009-07-02 19:41:20.000000000 -0400 | |
35554 | +++ linux-2.6.29.6/kernel/irq/handle.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35555 | @@ -222,7 +222,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach |
35556 | .depth = 1, | |
35557 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), | |
35558 | #ifdef CONFIG_SMP | |
35559 | - .affinity = CPU_MASK_ALL | |
35560 | + .affinity = CPU_MASK_ALL, | |
35561 | + .cpu = 0, | |
35562 | #endif | |
35563 | } | |
35564 | }; | |
de855c5d AM |
35565 | diff -urNp linux-2.6.29.6/kernel/kallsyms.c linux-2.6.29.6/kernel/kallsyms.c |
35566 | --- linux-2.6.29.6/kernel/kallsyms.c 2009-07-02 19:41:20.000000000 -0400 | |
35567 | +++ linux-2.6.29.6/kernel/kallsyms.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35568 | @@ -62,6 +62,18 @@ static inline int is_kernel_text(unsigne |
35569 | ||
35570 | static inline int is_kernel(unsigned long addr) | |
35571 | { | |
35572 | + | |
35573 | +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES) | |
35574 | + if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) && | |
35575 | + ktla_ktva(addr) < (unsigned long)MODULES_END) | |
35576 | + return 0; | |
35577 | +#endif | |
35578 | + | |
35579 | +#ifdef CONFIG_X86_32 | |
35580 | + if (is_kernel_inittext(addr)) | |
35581 | + return 1; | |
35582 | +#endif | |
35583 | + | |
35584 | if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end) | |
35585 | return 1; | |
35586 | return in_gate_area_no_task(addr); | |
35587 | @@ -372,7 +384,6 @@ static unsigned long get_ksymbol_core(st | |
35588 | ||
35589 | static void reset_iter(struct kallsym_iter *iter, loff_t new_pos) | |
35590 | { | |
35591 | - iter->name[0] = '\0'; | |
35592 | iter->nameoff = get_symbol_offset(new_pos); | |
35593 | iter->pos = new_pos; | |
35594 | } | |
35595 | @@ -456,7 +467,7 @@ static int kallsyms_open(struct inode *i | |
35596 | struct kallsym_iter *iter; | |
35597 | int ret; | |
35598 | ||
35599 | - iter = kmalloc(sizeof(*iter), GFP_KERNEL); | |
35600 | + iter = kzalloc(sizeof(*iter), GFP_KERNEL); | |
35601 | if (!iter) | |
35602 | return -ENOMEM; | |
35603 | reset_iter(iter, 0); | |
35604 | @@ -478,7 +489,15 @@ static const struct file_operations kall | |
35605 | ||
35606 | static int __init kallsyms_init(void) | |
35607 | { | |
35608 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
35609 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
35610 | + proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations); | |
35611 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
35612 | + proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations); | |
35613 | +#endif | |
35614 | +#else | |
35615 | proc_create("kallsyms", 0444, NULL, &kallsyms_operations); | |
35616 | +#endif | |
35617 | return 0; | |
35618 | } | |
35619 | __initcall(kallsyms_init); | |
de855c5d AM |
35620 | diff -urNp linux-2.6.29.6/kernel/kmod.c linux-2.6.29.6/kernel/kmod.c |
35621 | --- linux-2.6.29.6/kernel/kmod.c 2009-07-02 19:41:20.000000000 -0400 | |
35622 | +++ linux-2.6.29.6/kernel/kmod.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35623 | @@ -108,7 +108,7 @@ int request_module(const char *fmt, ...) |
35624 | return -ENOMEM; | |
35625 | } | |
35626 | ||
35627 | - ret = call_usermodehelper(modprobe_path, argv, envp, 1); | |
35628 | + ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC); | |
35629 | atomic_dec(&kmod_concurrent); | |
35630 | return ret; | |
35631 | } | |
de855c5d AM |
35632 | diff -urNp linux-2.6.29.6/kernel/kprobes.c linux-2.6.29.6/kernel/kprobes.c |
35633 | --- linux-2.6.29.6/kernel/kprobes.c 2009-07-02 19:41:20.000000000 -0400 | |
35634 | +++ linux-2.6.29.6/kernel/kprobes.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35635 | @@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_ |
35636 | * kernel image and loaded module images reside. This is required | |
35637 | * so x86_64 can correctly handle the %rip-relative fixups. | |
35638 | */ | |
35639 | - kip->insns = module_alloc(PAGE_SIZE); | |
35640 | + kip->insns = module_alloc_exec(PAGE_SIZE); | |
35641 | if (!kip->insns) { | |
35642 | kfree(kip); | |
35643 | return NULL; | |
35644 | @@ -224,7 +224,7 @@ static int __kprobes collect_one_slot(st | |
35645 | hlist_add_head(&kip->hlist, | |
35646 | &kprobe_insn_pages); | |
35647 | } else { | |
35648 | - module_free(NULL, kip->insns); | |
35649 | + module_free_exec(NULL, kip->insns); | |
35650 | kfree(kip); | |
35651 | } | |
35652 | return 1; | |
de855c5d AM |
35653 | diff -urNp linux-2.6.29.6/kernel/lockdep.c linux-2.6.29.6/kernel/lockdep.c |
35654 | --- linux-2.6.29.6/kernel/lockdep.c 2009-07-02 19:41:20.000000000 -0400 | |
35655 | +++ linux-2.6.29.6/kernel/lockdep.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35656 | @@ -631,6 +631,10 @@ static int static_obj(void *obj) |
35657 | int i; | |
35658 | #endif | |
35659 | ||
35660 | +#ifdef CONFIG_PAX_KERNEXEC | |
35661 | + start = (unsigned long )&_data; | |
35662 | +#endif | |
35663 | + | |
35664 | /* | |
35665 | * static variable? | |
35666 | */ | |
35667 | @@ -642,9 +646,12 @@ static int static_obj(void *obj) | |
35668 | * percpu var? | |
35669 | */ | |
35670 | for_each_possible_cpu(i) { | |
35671 | +#ifdef CONFIG_X86_32 | |
35672 | + start = per_cpu_offset(i); | |
35673 | +#else | |
35674 | start = (unsigned long) &__per_cpu_start + per_cpu_offset(i); | |
35675 | - end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM | |
35676 | - + per_cpu_offset(i); | |
35677 | +#endif | |
35678 | + end = start + PERCPU_ENOUGH_ROOM; | |
35679 | ||
35680 | if ((addr >= start) && (addr < end)) | |
35681 | return 1; | |
de855c5d AM |
35682 | diff -urNp linux-2.6.29.6/kernel/module.c linux-2.6.29.6/kernel/module.c |
35683 | --- linux-2.6.29.6/kernel/module.c 2009-07-02 19:41:20.000000000 -0400 | |
35684 | +++ linux-2.6.29.6/kernel/module.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
35685 | @@ -46,6 +46,11 @@ |
35686 | #include <linux/rculist.h> | |
35687 | #include <asm/uaccess.h> | |
35688 | #include <asm/cacheflush.h> | |
35689 | + | |
35690 | +#ifdef CONFIG_PAX_KERNEXEC | |
35691 | +#include <asm/desc.h> | |
35692 | +#endif | |
35693 | + | |
35694 | #include <linux/license.h> | |
35695 | #include <asm/sections.h> | |
35696 | #include <linux/tracepoint.h> | |
35697 | @@ -76,7 +81,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq | |
35698 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | |
35699 | ||
35700 | /* Bounds of module allocation, for speeding __module_text_address */ | |
35701 | -static unsigned long module_addr_min = -1UL, module_addr_max = 0; | |
35702 | +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0; | |
35703 | +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0; | |
35704 | + | |
35705 | +extern int gr_check_modstop(void); | |
35706 | ||
35707 | int register_module_notifier(struct notifier_block * nb) | |
35708 | { | |
35709 | @@ -245,7 +253,7 @@ static bool each_symbol(bool (*fn)(const | |
35710 | return true; | |
35711 | ||
35712 | list_for_each_entry_rcu(mod, &modules, list) { | |
35713 | - struct symsearch arr[] = { | |
35714 | + struct symsearch modarr[] = { | |
35715 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, | |
35716 | NOT_GPL_ONLY, false }, | |
35717 | { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, | |
35718 | @@ -267,7 +275,7 @@ static bool each_symbol(bool (*fn)(const | |
35719 | #endif | |
35720 | }; | |
35721 | ||
35722 | - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) | |
35723 | + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data)) | |
35724 | return true; | |
35725 | } | |
35726 | return false; | |
35727 | @@ -403,6 +411,8 @@ static inline unsigned int block_size(in | |
35728 | return val; | |
35729 | } | |
35730 | ||
35731 | +EXPORT_SYMBOL(__per_cpu_start); | |
35732 | + | |
35733 | static void *percpu_modalloc(unsigned long size, unsigned long align, | |
35734 | const char *name) | |
35735 | { | |
35736 | @@ -410,7 +420,7 @@ static void *percpu_modalloc(unsigned lo | |
35737 | unsigned int i; | |
35738 | void *ptr; | |
35739 | ||
35740 | - if (align > PAGE_SIZE) { | |
35741 | + if (align-1 >= PAGE_SIZE) { | |
35742 | printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", | |
35743 | name, align, PAGE_SIZE); | |
35744 | align = PAGE_SIZE; | |
35745 | @@ -492,7 +502,11 @@ static void percpu_modcopy(void *pcpudes | |
35746 | int cpu; | |
35747 | ||
35748 | for_each_possible_cpu(cpu) | |
35749 | +#ifdef CONFIG_X86_32 | |
35750 | + memcpy(pcpudest + __per_cpu_offset[cpu], from, size); | |
35751 | +#else | |
35752 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); | |
35753 | +#endif | |
35754 | } | |
35755 | ||
35756 | static int percpu_modinit(void) | |
35757 | @@ -751,6 +765,9 @@ SYSCALL_DEFINE2(delete_module, const cha | |
35758 | char name[MODULE_NAME_LEN]; | |
35759 | int ret, forced = 0; | |
35760 | ||
35761 | + if (gr_check_modstop()) | |
35762 | + return -EPERM; | |
35763 | + | |
35764 | if (!capable(CAP_SYS_MODULE)) | |
35765 | return -EPERM; | |
35766 | ||
35767 | @@ -1458,10 +1475,11 @@ static void free_module(struct module *m | |
35768 | module_unload_free(mod); | |
35769 | ||
35770 | /* release any pointers to mcount in this module */ | |
35771 | - ftrace_release(mod->module_core, mod->core_size); | |
35772 | + ftrace_release(mod->module_core_rx, mod->core_size_rx); | |
35773 | ||
35774 | /* This may be NULL, but that's OK */ | |
35775 | - module_free(mod, mod->module_init); | |
35776 | + module_free(mod, mod->module_init_rw); | |
35777 | + module_free_exec(mod, mod->module_init_rx); | |
35778 | kfree(mod->args); | |
35779 | if (mod->percpu) | |
35780 | percpu_modfree(mod->percpu); | |
35781 | @@ -1470,10 +1488,12 @@ static void free_module(struct module *m | |
35782 | percpu_modfree(mod->refptr); | |
35783 | #endif | |
35784 | /* Free lock-classes: */ | |
35785 | - lockdep_free_key_range(mod->module_core, mod->core_size); | |
35786 | + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx); | |
35787 | + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw); | |
35788 | ||
35789 | /* Finally, free the core (containing the module structure) */ | |
35790 | - module_free(mod, mod->module_core); | |
35791 | + module_free_exec(mod, mod->module_core_rx); | |
35792 | + module_free(mod, mod->module_core_rw); | |
35793 | } | |
35794 | ||
35795 | void *__symbol_get(const char *symbol) | |
35796 | @@ -1539,10 +1559,14 @@ static int simplify_symbols(Elf_Shdr *se | |
35797 | struct module *mod) | |
35798 | { | |
35799 | Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; | |
35800 | - unsigned long secbase; | |
35801 | + unsigned long secbase, symbol; | |
35802 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | |
35803 | int ret = 0; | |
35804 | ||
35805 | +#ifdef CONFIG_PAX_KERNEXEC | |
35806 | + unsigned long cr0; | |
35807 | +#endif | |
35808 | + | |
35809 | for (i = 1; i < n; i++) { | |
35810 | switch (sym[i].st_shndx) { | |
35811 | case SHN_COMMON: | |
35812 | @@ -1561,10 +1585,19 @@ static int simplify_symbols(Elf_Shdr *se | |
35813 | break; | |
35814 | ||
35815 | case SHN_UNDEF: | |
35816 | - sym[i].st_value | |
35817 | - = resolve_symbol(sechdrs, versindex, | |
35818 | + symbol = resolve_symbol(sechdrs, versindex, | |
35819 | strtab + sym[i].st_name, mod); | |
35820 | ||
35821 | +#ifdef CONFIG_PAX_KERNEXEC | |
35822 | + pax_open_kernel(cr0); | |
35823 | +#endif | |
35824 | + | |
35825 | + sym[i].st_value = symbol; | |
35826 | + | |
35827 | +#ifdef CONFIG_PAX_KERNEXEC | |
35828 | + pax_close_kernel(cr0); | |
35829 | +#endif | |
35830 | + | |
35831 | /* Ok if resolved. */ | |
35832 | if (!IS_ERR_VALUE(sym[i].st_value)) | |
35833 | break; | |
35834 | @@ -1579,11 +1612,27 @@ static int simplify_symbols(Elf_Shdr *se | |
35835 | ||
35836 | default: | |
35837 | /* Divert to percpu allocation if a percpu var. */ | |
35838 | - if (sym[i].st_shndx == pcpuindex) | |
35839 | + if (sym[i].st_shndx == pcpuindex) { | |
35840 | + | |
35841 | +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) | |
35842 | + secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start; | |
35843 | +#else | |
35844 | secbase = (unsigned long)mod->percpu; | |
35845 | - else | |
35846 | +#endif | |
35847 | + | |
35848 | + } else | |
35849 | secbase = sechdrs[sym[i].st_shndx].sh_addr; | |
35850 | + | |
35851 | +#ifdef CONFIG_PAX_KERNEXEC | |
35852 | + pax_open_kernel(cr0); | |
35853 | +#endif | |
35854 | + | |
35855 | sym[i].st_value += secbase; | |
35856 | + | |
35857 | +#ifdef CONFIG_PAX_KERNEXEC | |
35858 | + pax_close_kernel(cr0); | |
35859 | +#endif | |
35860 | + | |
35861 | break; | |
35862 | } | |
35863 | } | |
35864 | @@ -1645,11 +1694,12 @@ static void layout_sections(struct modul | |
35865 | || strncmp(secstrings + s->sh_name, | |
35866 | ".init", 5) == 0) | |
35867 | continue; | |
35868 | - s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | |
35869 | + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC)) | |
35870 | + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i); | |
35871 | + else | |
35872 | + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i); | |
35873 | DEBUGP("\t%s\n", secstrings + s->sh_name); | |
35874 | } | |
35875 | - if (m == 0) | |
35876 | - mod->core_text_size = mod->core_size; | |
35877 | } | |
35878 | ||
35879 | DEBUGP("Init section allocation order:\n"); | |
35880 | @@ -1663,12 +1713,13 @@ static void layout_sections(struct modul | |
35881 | || strncmp(secstrings + s->sh_name, | |
35882 | ".init", 5) != 0) | |
35883 | continue; | |
35884 | - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | |
35885 | - | INIT_OFFSET_MASK); | |
35886 | + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC)) | |
35887 | + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i); | |
35888 | + else | |
35889 | + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i); | |
35890 | + s->sh_entsize |= INIT_OFFSET_MASK; | |
35891 | DEBUGP("\t%s\n", secstrings + s->sh_name); | |
35892 | } | |
35893 | - if (m == 0) | |
35894 | - mod->init_text_size = mod->init_size; | |
35895 | } | |
35896 | } | |
35897 | ||
35898 | @@ -1808,14 +1859,31 @@ static void add_kallsyms(struct module * | |
35899 | { | |
35900 | unsigned int i; | |
35901 | ||
35902 | +#ifdef CONFIG_PAX_KERNEXEC | |
35903 | + unsigned long cr0; | |
35904 | +#endif | |
35905 | + | |
35906 | mod->symtab = (void *)sechdrs[symindex].sh_addr; | |
35907 | mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | |
35908 | mod->strtab = (void *)sechdrs[strindex].sh_addr; | |
35909 | ||
35910 | /* Set types up while we still have access to sections. */ | |
35911 | - for (i = 0; i < mod->num_symtab; i++) | |
35912 | - mod->symtab[i].st_info | |
35913 | - = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); | |
35914 | + | |
35915 | + for (i = 0; i < mod->num_symtab; i++) { | |
35916 | + char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); | |
35917 | + | |
35918 | +#ifdef CONFIG_PAX_KERNEXEC | |
35919 | + pax_open_kernel(cr0); | |
35920 | +#endif | |
35921 | + | |
35922 | + mod->symtab[i].st_info = type; | |
35923 | + | |
35924 | +#ifdef CONFIG_PAX_KERNEXEC | |
35925 | + pax_close_kernel(cr0); | |
35926 | +#endif | |
35927 | + | |
35928 | + } | |
35929 | + | |
35930 | } | |
35931 | #else | |
35932 | static inline void add_kallsyms(struct module *mod, | |
35933 | @@ -1842,16 +1910,30 @@ static void dynamic_printk_setup(struct | |
35934 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | |
35935 | } | |
35936 | ||
35937 | -static void *module_alloc_update_bounds(unsigned long size) | |
35938 | +static void *module_alloc_update_bounds_rw(unsigned long size) | |
35939 | { | |
35940 | void *ret = module_alloc(size); | |
35941 | ||
35942 | if (ret) { | |
35943 | /* Update module bounds. */ | |
35944 | - if ((unsigned long)ret < module_addr_min) | |
35945 | - module_addr_min = (unsigned long)ret; | |
35946 | - if ((unsigned long)ret + size > module_addr_max) | |
35947 | - module_addr_max = (unsigned long)ret + size; | |
35948 | + if ((unsigned long)ret < module_addr_min_rw) | |
35949 | + module_addr_min_rw = (unsigned long)ret; | |
35950 | + if ((unsigned long)ret + size > module_addr_max_rw) | |
35951 | + module_addr_max_rw = (unsigned long)ret + size; | |
35952 | + } | |
35953 | + return ret; | |
35954 | +} | |
35955 | + | |
35956 | +static void *module_alloc_update_bounds_rx(unsigned long size) | |
35957 | +{ | |
35958 | + void *ret = module_alloc_exec(size); | |
35959 | + | |
35960 | + if (ret) { | |
35961 | + /* Update module bounds. */ | |
35962 | + if ((unsigned long)ret < module_addr_min_rx) | |
35963 | + module_addr_min_rx = (unsigned long)ret; | |
35964 | + if ((unsigned long)ret + size > module_addr_max_rx) | |
35965 | + module_addr_max_rx = (unsigned long)ret + size; | |
35966 | } | |
35967 | return ret; | |
35968 | } | |
35969 | @@ -1878,6 +1960,10 @@ static noinline struct module *load_modu | |
35970 | unsigned long *mseg; | |
35971 | mm_segment_t old_fs; | |
35972 | ||
35973 | +#ifdef CONFIG_PAX_KERNEXEC | |
35974 | + unsigned long cr0; | |
35975 | +#endif | |
35976 | + | |
35977 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | |
35978 | umod, len, uargs); | |
35979 | if (len < sizeof(*hdr)) | |
35980 | @@ -2034,22 +2120,57 @@ static noinline struct module *load_modu | |
35981 | layout_sections(mod, hdr, sechdrs, secstrings); | |
35982 | ||
35983 | /* Do the allocs. */ | |
35984 | - ptr = module_alloc_update_bounds(mod->core_size); | |
35985 | + ptr = module_alloc_update_bounds_rw(mod->core_size_rw); | |
35986 | if (!ptr) { | |
35987 | err = -ENOMEM; | |
35988 | goto free_percpu; | |
35989 | } | |
35990 | - memset(ptr, 0, mod->core_size); | |
35991 | - mod->module_core = ptr; | |
35992 | + memset(ptr, 0, mod->core_size_rw); | |
35993 | + mod->module_core_rw = ptr; | |
35994 | + | |
35995 | + ptr = module_alloc_update_bounds_rw(mod->init_size_rw); | |
35996 | + if (!ptr && mod->init_size_rw) { | |
35997 | + err = -ENOMEM; | |
35998 | + goto free_core_rw; | |
35999 | + } | |
36000 | + memset(ptr, 0, mod->init_size_rw); | |
36001 | + mod->module_init_rw = ptr; | |
36002 | + | |
36003 | + ptr = module_alloc_update_bounds_rx(mod->core_size_rx); | |
36004 | + if (!ptr) { | |
36005 | + err = -ENOMEM; | |
36006 | + goto free_init_rw; | |
36007 | + } | |
36008 | + | |
36009 | +#ifdef CONFIG_PAX_KERNEXEC | |
36010 | + pax_open_kernel(cr0); | |
36011 | +#endif | |
36012 | + | |
36013 | + memset(ptr, 0, mod->core_size_rx); | |
36014 | ||
36015 | - ptr = module_alloc_update_bounds(mod->init_size); | |
36016 | - if (!ptr && mod->init_size) { | |
36017 | +#ifdef CONFIG_PAX_KERNEXEC | |
36018 | + pax_close_kernel(cr0); | |
36019 | +#endif | |
36020 | + | |
36021 | + mod->module_core_rx = ptr; | |
36022 | + | |
36023 | + ptr = module_alloc_update_bounds_rx(mod->init_size_rx); | |
36024 | + if (!ptr && mod->init_size_rx) { | |
36025 | err = -ENOMEM; | |
36026 | - goto free_core; | |
36027 | + goto free_core_rx; | |
36028 | } | |
36029 | - memset(ptr, 0, mod->init_size); | |
36030 | - mod->module_init = ptr; | |
36031 | ||
36032 | +#ifdef CONFIG_PAX_KERNEXEC | |
36033 | + pax_open_kernel(cr0); | |
36034 | +#endif | |
36035 | + | |
36036 | + memset(ptr, 0, mod->init_size_rx); | |
36037 | + | |
36038 | +#ifdef CONFIG_PAX_KERNEXEC | |
36039 | + pax_close_kernel(cr0); | |
36040 | +#endif | |
36041 | + | |
36042 | + mod->module_init_rx = ptr; | |
36043 | /* Transfer each section which specifies SHF_ALLOC */ | |
36044 | DEBUGP("final section addresses:\n"); | |
36045 | for (i = 0; i < hdr->e_shnum; i++) { | |
36046 | @@ -2058,17 +2179,41 @@ static noinline struct module *load_modu | |
36047 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | |
36048 | continue; | |
36049 | ||
36050 | - if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) | |
36051 | - dest = mod->module_init | |
36052 | - + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | |
36053 | - else | |
36054 | - dest = mod->module_core + sechdrs[i].sh_entsize; | |
36055 | + if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) { | |
36056 | + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC)) | |
36057 | + dest = mod->module_init_rw | |
36058 | + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | |
36059 | + else | |
36060 | + dest = mod->module_init_rx | |
36061 | + + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | |
36062 | + } else { | |
36063 | + if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC)) | |
36064 | + dest = mod->module_core_rw + sechdrs[i].sh_entsize; | |
36065 | + else | |
36066 | + dest = mod->module_core_rx + sechdrs[i].sh_entsize; | |
36067 | + } | |
36068 | ||
36069 | - if (sechdrs[i].sh_type != SHT_NOBITS) | |
36070 | - memcpy(dest, (void *)sechdrs[i].sh_addr, | |
36071 | - sechdrs[i].sh_size); | |
36072 | + if (sechdrs[i].sh_type != SHT_NOBITS) { | |
36073 | + | |
36074 | +#ifdef CONFIG_PAX_KERNEXEC | |
36075 | + if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) { | |
36076 | + pax_open_kernel(cr0); | |
36077 | + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size); | |
36078 | + pax_close_kernel(cr0); | |
36079 | + } else | |
36080 | +#endif | |
36081 | + | |
36082 | + memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size); | |
36083 | + } | |
36084 | /* Update sh_addr to point to copy in image. */ | |
36085 | - sechdrs[i].sh_addr = (unsigned long)dest; | |
36086 | + | |
36087 | +#ifdef CONFIG_PAX_KERNEXEC | |
36088 | + if (sechdrs[i].sh_flags & SHF_EXECINSTR) | |
36089 | + sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest); | |
36090 | + else | |
36091 | +#endif | |
36092 | + | |
36093 | + sechdrs[i].sh_addr = (unsigned long)dest; | |
36094 | DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); | |
36095 | } | |
36096 | /* Module has been moved. */ | |
36097 | @@ -2079,7 +2224,7 @@ static noinline struct module *load_modu | |
36098 | mod->name); | |
36099 | if (!mod->refptr) { | |
36100 | err = -ENOMEM; | |
36101 | - goto free_init; | |
36102 | + goto free_init_rx; | |
36103 | } | |
36104 | #endif | |
36105 | /* Now we've moved module, initialize linked lists, etc. */ | |
36106 | @@ -2176,8 +2321,8 @@ static noinline struct module *load_modu | |
36107 | ||
36108 | /* Now do relocations. */ | |
36109 | for (i = 1; i < hdr->e_shnum; i++) { | |
36110 | - const char *strtab = (char *)sechdrs[strindex].sh_addr; | |
36111 | unsigned int info = sechdrs[i].sh_info; | |
36112 | + strtab = (char *)sechdrs[strindex].sh_addr; | |
36113 | ||
36114 | /* Not a valid relocation section? */ | |
36115 | if (info >= hdr->e_shnum) | |
36116 | @@ -2239,12 +2384,12 @@ static noinline struct module *load_modu | |
36117 | * Do it before processing of module parameters, so the module | |
36118 | * can provide parameter accessor functions of its own. | |
36119 | */ | |
36120 | - if (mod->module_init) | |
36121 | - flush_icache_range((unsigned long)mod->module_init, | |
36122 | - (unsigned long)mod->module_init | |
36123 | - + mod->init_size); | |
36124 | - flush_icache_range((unsigned long)mod->module_core, | |
36125 | - (unsigned long)mod->module_core + mod->core_size); | |
36126 | + if (mod->module_init_rx) | |
36127 | + flush_icache_range((unsigned long)mod->module_init_rx, | |
36128 | + (unsigned long)mod->module_init_rx | |
36129 | + + mod->init_size_rx); | |
36130 | + flush_icache_range((unsigned long)mod->module_core_rx, | |
36131 | + (unsigned long)mod->module_core_rx + mod->core_size_rx); | |
36132 | ||
36133 | set_fs(old_fs); | |
36134 | ||
36135 | @@ -2285,16 +2430,20 @@ static noinline struct module *load_modu | |
36136 | cleanup: | |
36137 | kobject_del(&mod->mkobj.kobj); | |
36138 | kobject_put(&mod->mkobj.kobj); | |
36139 | - ftrace_release(mod->module_core, mod->core_size); | |
36140 | + ftrace_release(mod->module_core_rx, mod->core_size_rx); | |
36141 | free_unload: | |
36142 | module_unload_free(mod); | |
36143 | - free_init: | |
36144 | + free_init_rx: | |
36145 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | |
36146 | percpu_modfree(mod->refptr); | |
36147 | #endif | |
36148 | - module_free(mod, mod->module_init); | |
36149 | - free_core: | |
36150 | - module_free(mod, mod->module_core); | |
36151 | + module_free_exec(mod, mod->module_init_rx); | |
36152 | + free_core_rx: | |
36153 | + module_free_exec(mod, mod->module_core_rx); | |
36154 | + free_init_rw: | |
36155 | + module_free(mod, mod->module_init_rw); | |
36156 | + free_core_rw: | |
36157 | + module_free(mod, mod->module_core_rw); | |
36158 | /* mod will be freed with core. Don't access it beyond this line! */ | |
36159 | free_percpu: | |
36160 | if (percpu) | |
36161 | @@ -2319,6 +2468,9 @@ SYSCALL_DEFINE3(init_module, void __user | |
36162 | struct module *mod; | |
36163 | int ret = 0; | |
36164 | ||
36165 | + if (gr_check_modstop()) | |
36166 | + return -EPERM; | |
36167 | + | |
36168 | /* Must have permission */ | |
36169 | if (!capable(CAP_SYS_MODULE)) | |
36170 | return -EPERM; | |
36171 | @@ -2375,20 +2527,17 @@ SYSCALL_DEFINE3(init_module, void __user | |
36172 | mutex_lock(&module_mutex); | |
36173 | /* Drop initial reference. */ | |
36174 | module_put(mod); | |
36175 | - module_free(mod, mod->module_init); | |
36176 | - mod->module_init = NULL; | |
36177 | - mod->init_size = 0; | |
36178 | - mod->init_text_size = 0; | |
36179 | + module_free(mod, mod->module_init_rw); | |
36180 | + module_free_exec(mod, mod->module_init_rx); | |
36181 | + mod->module_init_rw = NULL; | |
36182 | + mod->module_init_rx = NULL; | |
36183 | + mod->init_size_rw = 0; | |
36184 | + mod->init_size_rx = 0; | |
36185 | mutex_unlock(&module_mutex); | |
36186 | ||
36187 | return 0; | |
36188 | } | |
36189 | ||
36190 | -static inline int within(unsigned long addr, void *start, unsigned long size) | |
36191 | -{ | |
36192 | - return ((void *)addr >= start && (void *)addr < start + size); | |
36193 | -} | |
36194 | - | |
36195 | #ifdef CONFIG_KALLSYMS | |
36196 | /* | |
36197 | * This ignores the intensely annoying "mapping symbols" found | |
36198 | @@ -2409,10 +2558,16 @@ static const char *get_ksymbol(struct mo | |
36199 | unsigned long nextval; | |
36200 | ||
36201 | /* At worse, next value is at end of module */ | |
36202 | - if (within_module_init(addr, mod)) | |
36203 | - nextval = (unsigned long)mod->module_init+mod->init_text_size; | |
36204 | + if (within_module_init_rx(addr, mod)) | |
36205 | + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx; | |
36206 | + else if (within_module_init_rw(addr, mod)) | |
36207 | + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw; | |
36208 | + else if (within_module_core_rx(addr, mod)) | |
36209 | + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx; | |
36210 | + else if (within_module_core_rw(addr, mod)) | |
36211 | + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw; | |
36212 | else | |
36213 | - nextval = (unsigned long)mod->module_core+mod->core_text_size; | |
36214 | + return NULL; | |
36215 | ||
36216 | /* Scan for closest preceeding symbol, and next symbol. (ELF | |
36217 | starts real symbols at 1). */ | |
36218 | @@ -2639,7 +2794,7 @@ static int m_show(struct seq_file *m, vo | |
36219 | char buf[8]; | |
36220 | ||
36221 | seq_printf(m, "%s %u", | |
36222 | - mod->name, mod->init_size + mod->core_size); | |
36223 | + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw); | |
36224 | print_unload_info(m, mod); | |
36225 | ||
36226 | /* Informative for users. */ | |
36227 | @@ -2648,7 +2803,7 @@ static int m_show(struct seq_file *m, vo | |
36228 | mod->state == MODULE_STATE_COMING ? "Loading": | |
36229 | "Live"); | |
36230 | /* Used by oprofile and other similar tools. */ | |
36231 | - seq_printf(m, " 0x%p", mod->module_core); | |
36232 | + seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw); | |
36233 | ||
36234 | /* Taints info */ | |
36235 | if (mod->taints) | |
36236 | @@ -2741,12 +2896,15 @@ __notrace_funcgraph struct module *__mod | |
36237 | { | |
36238 | struct module *mod; | |
36239 | ||
36240 | - if (addr < module_addr_min || addr > module_addr_max) | |
36241 | +#ifdef CONFIG_X86_32 | |
36242 | + addr = ktla_ktva(addr); | |
36243 | +#endif | |
36244 | + | |
36245 | + if (addr < module_addr_min_rx || addr > module_addr_max_rx) | |
36246 | return NULL; | |
36247 | ||
36248 | list_for_each_entry_rcu(mod, &modules, list) | |
36249 | - if (within(addr, mod->module_init, mod->init_text_size) | |
36250 | - || within(addr, mod->module_core, mod->core_text_size)) | |
36251 | + if (within_module_init_rx(addr, mod) || within_module_core_rx(addr, mod)) | |
36252 | return mod; | |
36253 | return NULL; | |
36254 | } | |
de855c5d AM |
36255 | diff -urNp linux-2.6.29.6/kernel/mutex.c linux-2.6.29.6/kernel/mutex.c |
36256 | --- linux-2.6.29.6/kernel/mutex.c 2009-07-02 19:41:20.000000000 -0400 | |
36257 | +++ linux-2.6.29.6/kernel/mutex.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
36258 | @@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou |
36259 | * | |
36260 | * This function is similar to (but not equivalent to) down(). | |
36261 | */ | |
36262 | -void inline __sched mutex_lock(struct mutex *lock) | |
36263 | +inline void __sched mutex_lock(struct mutex *lock) | |
36264 | { | |
36265 | might_sleep(); | |
36266 | /* | |
de855c5d AM |
36267 | diff -urNp linux-2.6.29.6/kernel/panic.c linux-2.6.29.6/kernel/panic.c |
36268 | --- linux-2.6.29.6/kernel/panic.c 2009-07-02 19:41:20.000000000 -0400 | |
36269 | +++ linux-2.6.29.6/kernel/panic.c 2009-07-09 22:20:50.000000000 -0400 | |
36270 | @@ -361,7 +361,8 @@ EXPORT_SYMBOL(warn_slowpath); | |
2380c486 JR |
36271 | */ |
36272 | void __stack_chk_fail(void) | |
36273 | { | |
de855c5d | 36274 | - panic("stack-protector: Kernel stack is corrupted"); |
2380c486 | 36275 | + dump_stack(); |
de855c5d | 36276 | + panic("stack-protector: Kernel stack is corrupted in: %pS\n", __builtin_return_address(0)); |
2380c486 JR |
36277 | } |
36278 | EXPORT_SYMBOL(__stack_chk_fail); | |
de855c5d AM |
36279 | #endif |
36280 | diff -urNp linux-2.6.29.6/kernel/pid.c linux-2.6.29.6/kernel/pid.c | |
36281 | --- linux-2.6.29.6/kernel/pid.c 2009-07-02 19:41:20.000000000 -0400 | |
36282 | +++ linux-2.6.29.6/kernel/pid.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
36283 | @@ -33,6 +33,7 @@ |
36284 | #include <linux/rculist.h> | |
36285 | #include <linux/bootmem.h> | |
36286 | #include <linux/hash.h> | |
36287 | +#include <linux/security.h> | |
36288 | #include <linux/pid_namespace.h> | |
36289 | #include <linux/init_task.h> | |
36290 | #include <linux/syscalls.h> | |
36291 | @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT | |
36292 | ||
36293 | int pid_max = PID_MAX_DEFAULT; | |
36294 | ||
36295 | -#define RESERVED_PIDS 300 | |
36296 | +#define RESERVED_PIDS 500 | |
36297 | ||
36298 | int pid_max_min = RESERVED_PIDS + 1; | |
36299 | int pid_max_max = PID_MAX_LIMIT; | |
36300 | @@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task); | |
36301 | struct task_struct *find_task_by_pid_type_ns(int type, int nr, | |
36302 | struct pid_namespace *ns) | |
36303 | { | |
36304 | - return pid_task(find_pid_ns(nr, ns), type); | |
36305 | + struct task_struct *task; | |
36306 | + | |
36307 | + task = pid_task(find_pid_ns(nr, ns), type); | |
36308 | + | |
36309 | + if (gr_pid_is_chrooted(task)) | |
36310 | + return NULL; | |
36311 | + | |
36312 | + return task; | |
36313 | } | |
36314 | ||
36315 | EXPORT_SYMBOL(find_task_by_pid_type_ns); | |
de855c5d AM |
36316 | diff -urNp linux-2.6.29.6/kernel/posix-cpu-timers.c linux-2.6.29.6/kernel/posix-cpu-timers.c |
36317 | --- linux-2.6.29.6/kernel/posix-cpu-timers.c 2009-07-02 19:41:20.000000000 -0400 | |
36318 | +++ linux-2.6.29.6/kernel/posix-cpu-timers.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
36319 | @@ -6,6 +6,7 @@ |
36320 | #include <linux/posix-timers.h> | |
36321 | #include <linux/errno.h> | |
36322 | #include <linux/math64.h> | |
36323 | +#include <linux/security.h> | |
36324 | #include <asm/uaccess.h> | |
36325 | #include <linux/kernel_stat.h> | |
36326 | ||
de855c5d | 36327 | @@ -1040,6 +1041,7 @@ static void check_thread_timers(struct t |
2380c486 JR |
36328 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
36329 | return; | |
36330 | } | |
36331 | + gr_learn_resource(tsk, RLIMIT_RTTIME, tsk->rt.timeout, 1); | |
36332 | if (tsk->rt.timeout > DIV_ROUND_UP(*soft, USEC_PER_SEC/HZ)) { | |
36333 | /* | |
36334 | * At the soft limit, send a SIGXCPU every second. | |
de855c5d | 36335 | @@ -1195,6 +1197,7 @@ static void check_process_timers(struct |
2380c486 JR |
36336 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
36337 | return; | |
36338 | } | |
36339 | + gr_learn_resource(tsk, RLIMIT_CPU, psecs, 0); | |
36340 | if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) { | |
36341 | /* | |
36342 | * At the soft limit, send a SIGXCPU every second. | |
de855c5d | 36343 | @@ -1419,17 +1422,17 @@ void run_posix_cpu_timers(struct task_st |
2380c486 JR |
36344 | * timer call will interfere. |
36345 | */ | |
36346 | list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) { | |
36347 | - int firing; | |
36348 | + int __firing; | |
36349 | spin_lock(&timer->it_lock); | |
36350 | list_del_init(&timer->it.cpu.entry); | |
36351 | - firing = timer->it.cpu.firing; | |
36352 | + __firing = timer->it.cpu.firing; | |
36353 | timer->it.cpu.firing = 0; | |
36354 | /* | |
36355 | * The firing flag is -1 if we collided with a reset | |
36356 | * of the timer, which already reported this | |
36357 | * almost-firing as an overrun. So don't generate an event. | |
36358 | */ | |
36359 | - if (likely(firing >= 0)) { | |
36360 | + if (likely(__firing >= 0)) { | |
36361 | cpu_timer_fire(timer); | |
36362 | } | |
36363 | spin_unlock(&timer->it_lock); | |
de855c5d AM |
36364 | diff -urNp linux-2.6.29.6/kernel/power/poweroff.c linux-2.6.29.6/kernel/power/poweroff.c |
36365 | --- linux-2.6.29.6/kernel/power/poweroff.c 2009-07-02 19:41:20.000000000 -0400 | |
36366 | +++ linux-2.6.29.6/kernel/power/poweroff.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
36367 | @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof |
36368 | .enable_mask = SYSRQ_ENABLE_BOOT, | |
36369 | }; | |
36370 | ||
36371 | -static int pm_sysrq_init(void) | |
36372 | +static int __init pm_sysrq_init(void) | |
36373 | { | |
36374 | register_sysrq_key('o', &sysrq_poweroff_op); | |
36375 | return 0; | |
de855c5d AM |
36376 | diff -urNp linux-2.6.29.6/kernel/printk.c linux-2.6.29.6/kernel/printk.c |
36377 | --- linux-2.6.29.6/kernel/printk.c 2009-07-02 19:41:20.000000000 -0400 | |
36378 | +++ linux-2.6.29.6/kernel/printk.c 2009-07-09 22:13:39.000000000 -0400 | |
2380c486 JR |
36379 | @@ -253,6 +253,11 @@ int do_syslog(int type, char __user *buf |
36380 | char c; | |
36381 | int error = 0; | |
36382 | ||
36383 | +#ifdef CONFIG_GRKERNSEC_DMESG | |
36384 | + if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN)) | |
36385 | + return -EPERM; | |
36386 | +#endif | |
36387 | + | |
36388 | error = security_syslog(type); | |
36389 | if (error) | |
36390 | return error; | |
de855c5d AM |
36391 | diff -urNp linux-2.6.29.6/kernel/ptrace.c linux-2.6.29.6/kernel/ptrace.c |
36392 | --- linux-2.6.29.6/kernel/ptrace.c 2009-07-02 19:41:20.000000000 -0400 | |
36393 | +++ linux-2.6.29.6/kernel/ptrace.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36394 | @@ -149,7 +149,7 @@ int __ptrace_may_access(struct task_stru |
36395 | cred->gid != tcred->egid || | |
36396 | cred->gid != tcred->sgid || | |
36397 | cred->gid != tcred->gid) && | |
36398 | - !capable(CAP_SYS_PTRACE)) { | |
36399 | + !capable_nolog(CAP_SYS_PTRACE)) { | |
36400 | rcu_read_unlock(); | |
36401 | return -EPERM; | |
36402 | } | |
36403 | @@ -157,7 +157,7 @@ int __ptrace_may_access(struct task_stru | |
36404 | smp_rmb(); | |
36405 | if (task->mm) | |
36406 | dumpable = get_dumpable(task->mm); | |
36407 | - if (!dumpable && !capable(CAP_SYS_PTRACE)) | |
36408 | + if (!dumpable && !capable_nolog(CAP_SYS_PTRACE)) | |
36409 | return -EPERM; | |
36410 | ||
36411 | return security_ptrace_may_access(task, mode); | |
36412 | @@ -221,7 +221,7 @@ repeat: | |
36413 | ||
36414 | /* Go */ | |
36415 | task->ptrace |= PT_PTRACED; | |
36416 | - if (capable(CAP_SYS_PTRACE)) | |
36417 | + if (capable_nolog(CAP_SYS_PTRACE)) | |
36418 | task->ptrace |= PT_PTRACE_CAP; | |
36419 | ||
36420 | __ptrace_link(task, current); | |
de855c5d | 36421 | @@ -612,6 +612,11 @@ SYSCALL_DEFINE4(ptrace, long, request, l |
2380c486 JR |
36422 | if (ret < 0) |
36423 | goto out_put_task_struct; | |
36424 | ||
36425 | + if (gr_handle_ptrace(child, request)) { | |
36426 | + ret = -EPERM; | |
36427 | + goto out_put_task_struct; | |
36428 | + } | |
36429 | + | |
36430 | ret = arch_ptrace(child, request, addr, data); | |
36431 | if (ret < 0) | |
36432 | goto out_put_task_struct; | |
de855c5d AM |
36433 | diff -urNp linux-2.6.29.6/kernel/relay.c linux-2.6.29.6/kernel/relay.c |
36434 | --- linux-2.6.29.6/kernel/relay.c 2009-07-02 19:41:20.000000000 -0400 | |
36435 | +++ linux-2.6.29.6/kernel/relay.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36436 | @@ -1292,7 +1292,7 @@ static int subbuf_splice_actor(struct fi |
36437 | return 0; | |
36438 | ||
36439 | ret = *nonpad_ret = splice_to_pipe(pipe, &spd); | |
36440 | - if (ret < 0 || ret < total_len) | |
36441 | + if ((int)ret < 0 || ret < total_len) | |
36442 | return ret; | |
36443 | ||
36444 | if (read_start + ret == nonpad_end) | |
de855c5d AM |
36445 | diff -urNp linux-2.6.29.6/kernel/resource.c linux-2.6.29.6/kernel/resource.c |
36446 | --- linux-2.6.29.6/kernel/resource.c 2009-07-02 19:41:20.000000000 -0400 | |
36447 | +++ linux-2.6.29.6/kernel/resource.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36448 | @@ -132,8 +132,18 @@ static const struct file_operations proc |
36449 | ||
36450 | static int __init ioresources_init(void) | |
36451 | { | |
36452 | +#ifdef CONFIG_GRKERNSEC_PROC_ADD | |
36453 | +#ifdef CONFIG_GRKERNSEC_PROC_USER | |
36454 | + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations); | |
36455 | + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations); | |
36456 | +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP) | |
36457 | + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations); | |
36458 | + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations); | |
36459 | +#endif | |
36460 | +#else | |
36461 | proc_create("ioports", 0, NULL, &proc_ioports_operations); | |
36462 | proc_create("iomem", 0, NULL, &proc_iomem_operations); | |
36463 | +#endif | |
36464 | return 0; | |
36465 | } | |
36466 | __initcall(ioresources_init); | |
de855c5d AM |
36467 | diff -urNp linux-2.6.29.6/kernel/sched.c linux-2.6.29.6/kernel/sched.c |
36468 | --- linux-2.6.29.6/kernel/sched.c 2009-07-02 19:41:20.000000000 -0400 | |
36469 | +++ linux-2.6.29.6/kernel/sched.c 2009-07-09 22:13:40.000000000 -0400 | |
36470 | @@ -5175,6 +5175,8 @@ int can_nice(const struct task_struct *p | |
2380c486 JR |
36471 | /* convert nice value [19,-20] to rlimit style value [1,40] */ |
36472 | int nice_rlim = 20 - nice; | |
36473 | ||
36474 | + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1); | |
36475 | + | |
36476 | return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur || | |
36477 | capable(CAP_SYS_NICE)); | |
36478 | } | |
de855c5d | 36479 | @@ -5208,7 +5210,8 @@ SYSCALL_DEFINE1(nice, int, increment) |
2380c486 JR |
36480 | if (nice > 19) |
36481 | nice = 19; | |
36482 | ||
36483 | - if (increment < 0 && !can_nice(current, nice)) | |
de855c5d AM |
36484 | + if (increment < 0 && (!can_nice(current, nice) || |
36485 | + gr_handle_chroot_nice())) | |
36486 | return -EPERM; | |
2380c486 JR |
36487 | |
36488 | retval = security_task_setnice(current, nice); | |
de855c5d | 36489 | @@ -5350,6 +5353,8 @@ recheck: |
2380c486 JR |
36490 | if (rt_policy(policy)) { |
36491 | unsigned long rlim_rtprio; | |
36492 | ||
36493 | + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1); | |
36494 | + | |
36495 | if (!lock_task_sighand(p, &flags)) | |
36496 | return -ESRCH; | |
36497 | rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur; | |
de855c5d | 36498 | @@ -6497,7 +6502,7 @@ static struct ctl_table sd_ctl_dir[] = { |
2380c486 JR |
36499 | .procname = "sched_domain", |
36500 | .mode = 0555, | |
36501 | }, | |
36502 | - {0, }, | |
36503 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
36504 | }; | |
36505 | ||
36506 | static struct ctl_table sd_ctl_root[] = { | |
de855c5d | 36507 | @@ -6507,7 +6512,7 @@ static struct ctl_table sd_ctl_root[] = |
2380c486 JR |
36508 | .mode = 0555, |
36509 | .child = sd_ctl_dir, | |
36510 | }, | |
36511 | - {0, }, | |
36512 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
36513 | }; | |
36514 | ||
36515 | static struct ctl_table *sd_alloc_ctl_entry(int n) | |
de855c5d AM |
36516 | diff -urNp linux-2.6.29.6/kernel/signal.c linux-2.6.29.6/kernel/signal.c |
36517 | --- linux-2.6.29.6/kernel/signal.c 2009-07-02 19:41:20.000000000 -0400 | |
36518 | +++ linux-2.6.29.6/kernel/signal.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36519 | @@ -198,6 +198,9 @@ static struct sigqueue *__sigqueue_alloc |
36520 | */ | |
36521 | user = get_uid(__task_cred(t)->user); | |
36522 | atomic_inc(&user->sigpending); | |
36523 | + | |
36524 | + if (!override_rlimit) | |
36525 | + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1); | |
36526 | if (override_rlimit || | |
36527 | atomic_read(&user->sigpending) <= | |
36528 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) | |
de855c5d AM |
36529 | @@ -611,6 +614,9 @@ static int check_kill_permission(int sig |
36530 | } | |
2380c486 | 36531 | } |
de855c5d | 36532 | |
2380c486 JR |
36533 | + if (gr_handle_signal(t, sig)) |
36534 | + return -EPERM; | |
36535 | + | |
36536 | return security_task_kill(t, info, sig, 0); | |
36537 | } | |
36538 | ||
36539 | @@ -903,8 +909,8 @@ static void print_fatal_signal(struct pt | |
36540 | for (i = 0; i < 16; i++) { | |
36541 | unsigned char insn; | |
36542 | ||
36543 | - __get_user(insn, (unsigned char *)(regs->ip + i)); | |
36544 | - printk("%02x ", insn); | |
36545 | + if (!get_user(insn, (unsigned char __user *)(regs->ip + i))) | |
36546 | + printk("%02x ", insn); | |
36547 | } | |
36548 | } | |
36549 | #endif | |
36550 | @@ -929,7 +935,7 @@ __group_send_sig_info(int sig, struct si | |
36551 | return send_signal(sig, info, p, 1); | |
36552 | } | |
36553 | ||
36554 | -static int | |
36555 | +int | |
36556 | specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t) | |
36557 | { | |
36558 | return send_signal(sig, info, t, 0); | |
36559 | @@ -969,6 +975,9 @@ force_sig_info(int sig, struct siginfo * | |
36560 | ret = specific_send_sig_info(sig, info, t); | |
36561 | spin_unlock_irqrestore(&t->sighand->siglock, flags); | |
36562 | ||
36563 | + gr_log_signal(sig, t); | |
36564 | + gr_handle_crash(t, sig); | |
36565 | + | |
36566 | return ret; | |
36567 | } | |
36568 | ||
36569 | @@ -1043,6 +1052,8 @@ int group_send_sig_info(int sig, struct | |
36570 | ret = __group_send_sig_info(sig, info, p); | |
36571 | unlock_task_sighand(p, &flags); | |
36572 | } | |
36573 | + if (!ret) | |
36574 | + gr_log_signal(sig, p); | |
36575 | } | |
36576 | ||
36577 | return ret; | |
de855c5d AM |
36578 | diff -urNp linux-2.6.29.6/kernel/softirq.c linux-2.6.29.6/kernel/softirq.c |
36579 | --- linux-2.6.29.6/kernel/softirq.c 2009-07-02 19:41:20.000000000 -0400 | |
36580 | +++ linux-2.6.29.6/kernel/softirq.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36581 | @@ -450,9 +450,9 @@ void tasklet_kill(struct tasklet_struct |
36582 | printk("Attempt to kill tasklet from interrupt\n"); | |
36583 | ||
36584 | while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) { | |
36585 | - do | |
36586 | + do { | |
36587 | yield(); | |
36588 | - while (test_bit(TASKLET_STATE_SCHED, &t->state)); | |
36589 | + } while (test_bit(TASKLET_STATE_SCHED, &t->state)); | |
36590 | } | |
36591 | tasklet_unlock_wait(t); | |
36592 | clear_bit(TASKLET_STATE_SCHED, &t->state); | |
de855c5d AM |
36593 | diff -urNp linux-2.6.29.6/kernel/sys.c linux-2.6.29.6/kernel/sys.c |
36594 | --- linux-2.6.29.6/kernel/sys.c 2009-07-02 19:41:20.000000000 -0400 | |
36595 | +++ linux-2.6.29.6/kernel/sys.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36596 | @@ -131,6 +131,12 @@ static int set_one_prio(struct task_stru |
36597 | error = -EACCES; | |
36598 | goto out; | |
36599 | } | |
36600 | + | |
36601 | + if (gr_handle_chroot_setpriority(p, niceval)) { | |
36602 | + error = -EACCES; | |
36603 | + goto out; | |
36604 | + } | |
36605 | + | |
36606 | no_nice = security_task_setnice(p, niceval); | |
36607 | if (no_nice) { | |
36608 | error = no_nice; | |
36609 | @@ -503,6 +509,7 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g | |
36610 | else | |
36611 | goto error; | |
36612 | } | |
36613 | + | |
36614 | if (egid != (gid_t) -1) { | |
36615 | if (old->gid == egid || | |
36616 | old->egid == egid || | |
36617 | @@ -513,6 +520,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g | |
36618 | goto error; | |
36619 | } | |
36620 | ||
36621 | + if (gr_check_group_change(new->gid, new->egid, -1)) | |
36622 | + goto error; | |
36623 | + | |
36624 | if (rgid != (gid_t) -1 || | |
36625 | (egid != (gid_t) -1 && egid != old->gid)) | |
36626 | new->sgid = new->egid; | |
36627 | @@ -546,6 +556,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid) | |
36628 | goto error; | |
36629 | ||
36630 | retval = -EPERM; | |
36631 | + | |
36632 | + if (gr_check_group_change(gid, gid, gid)) | |
36633 | + goto error; | |
36634 | + | |
36635 | if (capable(CAP_SETGID)) | |
36636 | new->gid = new->egid = new->sgid = new->fsgid = gid; | |
36637 | else if (gid == old->gid || gid == old->sgid) | |
36638 | @@ -636,6 +650,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u | |
36639 | goto error; | |
36640 | } | |
36641 | ||
36642 | + if (gr_check_user_change(new->uid, new->euid, -1)) | |
36643 | + goto error; | |
36644 | + | |
36645 | if (new->uid != old->uid) { | |
36646 | retval = set_user(new); | |
36647 | if (retval < 0) | |
36648 | @@ -684,6 +701,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid) | |
36649 | goto error; | |
36650 | ||
36651 | retval = -EPERM; | |
36652 | + | |
36653 | + if (gr_check_crash_uid(uid)) | |
36654 | + goto error; | |
36655 | + if (gr_check_user_change(uid, uid, uid)) | |
36656 | + goto error; | |
36657 | + | |
36658 | if (capable(CAP_SETUID)) { | |
36659 | new->suid = new->uid = uid; | |
36660 | if (uid != old->uid) { | |
36661 | @@ -741,6 +764,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, | |
36662 | goto error; | |
36663 | } | |
36664 | ||
36665 | + if (gr_check_user_change(ruid, euid, -1)) | |
36666 | + goto error; | |
36667 | + | |
36668 | if (ruid != (uid_t) -1) { | |
36669 | new->uid = ruid; | |
36670 | if (ruid != old->uid) { | |
36671 | @@ -809,6 +835,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, | |
36672 | goto error; | |
36673 | } | |
36674 | ||
36675 | + if (gr_check_group_change(rgid, egid, -1)) | |
36676 | + goto error; | |
36677 | + | |
36678 | if (rgid != (gid_t) -1) | |
36679 | new->gid = rgid; | |
36680 | if (egid != (gid_t) -1) | |
36681 | @@ -858,6 +887,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid) | |
36682 | if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0) | |
36683 | goto error; | |
36684 | ||
36685 | + if (gr_check_user_change(-1, -1, uid)) | |
36686 | + goto error; | |
36687 | + | |
36688 | if (uid == old->uid || uid == old->euid || | |
36689 | uid == old->suid || uid == old->fsuid || | |
36690 | capable(CAP_SETUID)) { | |
36691 | @@ -898,6 +930,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid) | |
36692 | if (gid == old->gid || gid == old->egid || | |
36693 | gid == old->sgid || gid == old->fsgid || | |
36694 | capable(CAP_SETGID)) { | |
36695 | + if (gr_check_group_change(-1, -1, gid)) | |
36696 | + goto error; | |
36697 | + | |
36698 | if (gid != old_fsgid) { | |
36699 | new->fsgid = gid; | |
36700 | goto change_okay; | |
36701 | @@ -974,7 +1009,10 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid | |
36702 | write_lock_irq(&tasklist_lock); | |
36703 | ||
36704 | err = -ESRCH; | |
36705 | - p = find_task_by_vpid(pid); | |
36706 | + /* grsec: replaced find_task_by_vpid with equivalent call which | |
36707 | + lacks the chroot restriction | |
36708 | + */ | |
36709 | + p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID); | |
36710 | if (!p) | |
36711 | goto out; | |
36712 | ||
36713 | @@ -1732,7 +1770,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi | |
36714 | error = get_dumpable(me->mm); | |
36715 | break; | |
36716 | case PR_SET_DUMPABLE: | |
36717 | - if (arg2 < 0 || arg2 > 1) { | |
36718 | + if (arg2 > 1) { | |
36719 | error = -EINVAL; | |
36720 | break; | |
36721 | } | |
de855c5d AM |
36722 | diff -urNp linux-2.6.29.6/kernel/sysctl.c linux-2.6.29.6/kernel/sysctl.c |
36723 | --- linux-2.6.29.6/kernel/sysctl.c 2009-07-02 19:41:20.000000000 -0400 | |
36724 | +++ linux-2.6.29.6/kernel/sysctl.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36725 | @@ -61,6 +61,13 @@ |
36726 | static int deprecated_sysctl_warning(struct __sysctl_args *args); | |
36727 | ||
36728 | #if defined(CONFIG_SYSCTL) | |
36729 | +#include <linux/grsecurity.h> | |
36730 | +#include <linux/grinternal.h> | |
36731 | + | |
36732 | +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op); | |
36733 | +extern int gr_handle_sysctl_mod(const char *dirname, const char *name, | |
36734 | + const int op); | |
36735 | +extern int gr_handle_chroot_sysctl(const int op); | |
36736 | ||
36737 | /* External variables not in a header file. */ | |
36738 | extern int C_A_D; | |
de855c5d | 36739 | @@ -155,6 +162,7 @@ static int proc_do_cad_pid(struct ctl_ta |
2380c486 JR |
36740 | static int proc_taint(struct ctl_table *table, int write, struct file *filp, |
36741 | void __user *buffer, size_t *lenp, loff_t *ppos); | |
36742 | #endif | |
36743 | +extern ctl_table grsecurity_table[]; | |
36744 | ||
36745 | static struct ctl_table root_table[]; | |
36746 | static struct ctl_table_root sysctl_table_root; | |
de855c5d | 36747 | @@ -187,6 +195,21 @@ extern struct ctl_table epoll_table[]; |
2380c486 JR |
36748 | int sysctl_legacy_va_layout; |
36749 | #endif | |
36750 | ||
36751 | +#ifdef CONFIG_PAX_SOFTMODE | |
36752 | +static ctl_table pax_table[] = { | |
36753 | + { | |
36754 | + .ctl_name = CTL_UNNUMBERED, | |
36755 | + .procname = "softmode", | |
36756 | + .data = &pax_softmode, | |
36757 | + .maxlen = sizeof(unsigned int), | |
36758 | + .mode = 0600, | |
36759 | + .proc_handler = &proc_dointvec, | |
36760 | + }, | |
36761 | + | |
36762 | + { .ctl_name = 0 } | |
36763 | +}; | |
36764 | +#endif | |
36765 | + | |
36766 | extern int prove_locking; | |
36767 | extern int lock_stat; | |
36768 | ||
de855c5d | 36769 | @@ -897,6 +920,25 @@ static struct ctl_table kern_table[] = { |
2380c486 JR |
36770 | .proc_handler = &scan_unevictable_handler, |
36771 | }, | |
36772 | #endif | |
36773 | + | |
36774 | +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP) | |
36775 | + { | |
36776 | + .ctl_name = CTL_UNNUMBERED, | |
36777 | + .procname = "grsecurity", | |
36778 | + .mode = 0500, | |
36779 | + .child = grsecurity_table, | |
36780 | + }, | |
36781 | +#endif | |
36782 | + | |
36783 | +#ifdef CONFIG_PAX_SOFTMODE | |
36784 | + { | |
36785 | + .ctl_name = CTL_UNNUMBERED, | |
36786 | + .procname = "pax", | |
36787 | + .mode = 0500, | |
36788 | + .child = pax_table, | |
36789 | + }, | |
36790 | +#endif | |
36791 | + | |
36792 | /* | |
36793 | * NOTE: do not add new entries to this table unless you have read | |
36794 | * Documentation/sysctl/ctl_unnumbered.txt | |
de855c5d | 36795 | @@ -1634,6 +1676,8 @@ static int do_sysctl_strategy(struct ctl |
2380c486 JR |
36796 | return 0; |
36797 | } | |
36798 | ||
36799 | +static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op); | |
36800 | + | |
36801 | static int parse_table(int __user *name, int nlen, | |
36802 | void __user *oldval, size_t __user *oldlenp, | |
36803 | void __user *newval, size_t newlen, | |
de855c5d | 36804 | @@ -1652,7 +1696,7 @@ repeat: |
2380c486 JR |
36805 | if (n == table->ctl_name) { |
36806 | int error; | |
36807 | if (table->child) { | |
36808 | - if (sysctl_perm(root, table, MAY_EXEC)) | |
36809 | + if (sysctl_perm_nochk(root, table, MAY_EXEC)) | |
36810 | return -EPERM; | |
36811 | name++; | |
36812 | nlen--; | |
de855c5d | 36813 | @@ -1737,6 +1781,33 @@ int sysctl_perm(struct ctl_table_root *r |
2380c486 JR |
36814 | int error; |
36815 | int mode; | |
36816 | ||
36817 | + if (table->parent != NULL && table->parent->procname != NULL && | |
36818 | + table->procname != NULL && | |
36819 | + gr_handle_sysctl_mod(table->parent->procname, table->procname, op)) | |
36820 | + return -EACCES; | |
36821 | + if (gr_handle_chroot_sysctl(op)) | |
36822 | + return -EACCES; | |
36823 | + error = gr_handle_sysctl(table, op); | |
36824 | + if (error) | |
36825 | + return error; | |
36826 | + | |
36827 | + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); | |
36828 | + if (error) | |
36829 | + return error; | |
36830 | + | |
36831 | + if (root->permissions) | |
36832 | + mode = root->permissions(root, current->nsproxy, table); | |
36833 | + else | |
36834 | + mode = table->mode; | |
36835 | + | |
36836 | + return test_perm(mode, op); | |
36837 | +} | |
36838 | + | |
36839 | +int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op) | |
36840 | +{ | |
36841 | + int error; | |
36842 | + int mode; | |
36843 | + | |
36844 | error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); | |
36845 | if (error) | |
36846 | return error; | |
de855c5d AM |
36847 | diff -urNp linux-2.6.29.6/kernel/taskstats.c linux-2.6.29.6/kernel/taskstats.c |
36848 | --- linux-2.6.29.6/kernel/taskstats.c 2009-07-02 19:41:20.000000000 -0400 | |
36849 | +++ linux-2.6.29.6/kernel/taskstats.c 2009-07-10 05:28:01.000000000 -0400 | |
36850 | @@ -26,9 +26,12 @@ | |
36851 | #include <linux/cgroup.h> | |
36852 | #include <linux/fs.h> | |
36853 | #include <linux/file.h> | |
36854 | +#include <linux/grsecurity.h> | |
36855 | #include <net/genetlink.h> | |
36856 | #include <asm/atomic.h> | |
36857 | ||
36858 | +extern int gr_is_taskstats_denied(int pid); | |
36859 | + | |
36860 | /* | |
36861 | * Maximum length of a cpumask that can be specified in | |
36862 | * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute | |
36863 | @@ -433,6 +436,9 @@ static int taskstats_user_cmd(struct sk_ | |
36864 | size_t size; | |
36865 | cpumask_var_t mask; | |
36866 | ||
36867 | + if (gr_is_taskstats_denied(current->pid)) | |
36868 | + return -EACCES; | |
36869 | + | |
36870 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | |
36871 | return -ENOMEM; | |
36872 | ||
36873 | diff -urNp linux-2.6.29.6/kernel/time/tick-broadcast.c linux-2.6.29.6/kernel/time/tick-broadcast.c | |
36874 | --- linux-2.6.29.6/kernel/time/tick-broadcast.c 2009-07-02 19:41:20.000000000 -0400 | |
36875 | +++ linux-2.6.29.6/kernel/time/tick-broadcast.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36876 | @@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl |
36877 | * then clear the broadcast bit. | |
36878 | */ | |
36879 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) { | |
36880 | - int cpu = smp_processor_id(); | |
36881 | + cpu = smp_processor_id(); | |
36882 | ||
36883 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); | |
36884 | tick_broadcast_clear_oneshot(cpu); | |
de855c5d AM |
36885 | diff -urNp linux-2.6.29.6/kernel/time.c linux-2.6.29.6/kernel/time.c |
36886 | --- linux-2.6.29.6/kernel/time.c 2009-07-02 19:41:20.000000000 -0400 | |
36887 | +++ linux-2.6.29.6/kernel/time.c 2009-07-09 22:13:40.000000000 -0400 | |
3f74aa08 | 36888 | @@ -94,6 +94,9 @@ SYSCALL_DEFINE1(stime, time_t __user *, |
2380c486 JR |
36889 | return err; |
36890 | ||
de855c5d | 36891 | do_settimeofday(&tv); |
2380c486 JR |
36892 | + |
36893 | + gr_log_timechange(); | |
36894 | + | |
36895 | return 0; | |
36896 | } | |
36897 | ||
36898 | @@ -202,6 +205,8 @@ SYSCALL_DEFINE2(settimeofday, struct tim | |
36899 | return -EFAULT; | |
36900 | } | |
36901 | ||
36902 | + gr_log_timechange(); | |
36903 | + | |
36904 | return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL); | |
36905 | } | |
36906 | ||
36907 | @@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time); | |
36908 | * Avoid unnecessary multiplications/divisions in the | |
36909 | * two most common HZ cases: | |
36910 | */ | |
36911 | -unsigned int inline jiffies_to_msecs(const unsigned long j) | |
36912 | +inline unsigned int jiffies_to_msecs(const unsigned long j) | |
36913 | { | |
36914 | #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) | |
36915 | return (MSEC_PER_SEC / HZ) * j; | |
36916 | @@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(con | |
36917 | } | |
36918 | EXPORT_SYMBOL(jiffies_to_msecs); | |
36919 | ||
36920 | -unsigned int inline jiffies_to_usecs(const unsigned long j) | |
36921 | +inline unsigned int jiffies_to_usecs(const unsigned long j) | |
36922 | { | |
36923 | #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ) | |
36924 | return (USEC_PER_SEC / HZ) * j; | |
de855c5d AM |
36925 | diff -urNp linux-2.6.29.6/kernel/trace/trace.c linux-2.6.29.6/kernel/trace/trace.c |
36926 | --- linux-2.6.29.6/kernel/trace/trace.c 2009-07-02 19:41:20.000000000 -0400 | |
36927 | +++ linux-2.6.29.6/kernel/trace/trace.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36928 | @@ -442,7 +442,7 @@ trace_seq_path(struct trace_seq *s, stru |
36929 | return 0; | |
36930 | p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); | |
36931 | if (!IS_ERR(p)) { | |
36932 | - p = mangle_path(s->buffer + s->len, p, "\n"); | |
36933 | + p = mangle_path(s->buffer + s->len, p, "\n\\"); | |
36934 | if (p) { | |
36935 | s->len = p - s->buffer; | |
36936 | return 1; | |
de855c5d AM |
36937 | diff -urNp linux-2.6.29.6/kernel/utsname_sysctl.c linux-2.6.29.6/kernel/utsname_sysctl.c |
36938 | --- linux-2.6.29.6/kernel/utsname_sysctl.c 2009-07-02 19:41:20.000000000 -0400 | |
36939 | +++ linux-2.6.29.6/kernel/utsname_sysctl.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36940 | @@ -123,7 +123,7 @@ static struct ctl_table uts_kern_table[] |
36941 | .proc_handler = proc_do_uts_string, | |
36942 | .strategy = sysctl_uts_string, | |
36943 | }, | |
36944 | - {} | |
36945 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
36946 | }; | |
36947 | ||
36948 | static struct ctl_table uts_root_table[] = { | |
36949 | @@ -133,7 +133,7 @@ static struct ctl_table uts_root_table[] | |
36950 | .mode = 0555, | |
36951 | .child = uts_kern_table, | |
36952 | }, | |
36953 | - {} | |
36954 | + { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } | |
36955 | }; | |
36956 | ||
36957 | static int __init utsname_sysctl_init(void) | |
de855c5d AM |
36958 | diff -urNp linux-2.6.29.6/lib/Kconfig.debug linux-2.6.29.6/lib/Kconfig.debug |
36959 | --- linux-2.6.29.6/lib/Kconfig.debug 2009-07-02 19:41:20.000000000 -0400 | |
36960 | +++ linux-2.6.29.6/lib/Kconfig.debug 2009-07-09 22:13:40.000000000 -0400 | |
36961 | @@ -783,7 +783,7 @@ config LATENCYTOP | |
36962 | select STACKTRACE | |
36963 | select SCHEDSTATS | |
36964 | select SCHED_DEBUG | |
36965 | - depends on HAVE_LATENCYTOP_SUPPORT | |
36966 | + depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM | |
36967 | help | |
36968 | Enable this option if you want to use the LatencyTOP tool | |
36969 | to find out which userspace is blocking on what kernel operations. | |
36970 | diff -urNp linux-2.6.29.6/lib/parser.c linux-2.6.29.6/lib/parser.c | |
36971 | --- linux-2.6.29.6/lib/parser.c 2009-07-02 19:41:20.000000000 -0400 | |
36972 | +++ linux-2.6.29.6/lib/parser.c 2009-07-09 22:13:40.000000000 -0400 | |
36973 | @@ -126,7 +126,7 @@ static int match_number(substring_t *s, | |
36974 | char *buf; | |
36975 | int ret; | |
36976 | ||
36977 | - buf = kmalloc(s->to - s->from + 1, GFP_KERNEL); | |
36978 | + buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL); | |
36979 | if (!buf) | |
36980 | return -ENOMEM; | |
36981 | memcpy(buf, s->from, s->to - s->from); | |
36982 | diff -urNp linux-2.6.29.6/lib/radix-tree.c linux-2.6.29.6/lib/radix-tree.c | |
36983 | --- linux-2.6.29.6/lib/radix-tree.c 2009-07-02 19:41:20.000000000 -0400 | |
36984 | +++ linux-2.6.29.6/lib/radix-tree.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
36985 | @@ -81,7 +81,7 @@ struct radix_tree_preload { |
36986 | int nr; | |
36987 | struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH]; | |
36988 | }; | |
36989 | -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, }; | |
36990 | +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads); | |
36991 | ||
36992 | static inline gfp_t root_gfp_mask(struct radix_tree_root *root) | |
36993 | { | |
de855c5d AM |
36994 | diff -urNp linux-2.6.29.6/lib/random32.c linux-2.6.29.6/lib/random32.c |
36995 | --- linux-2.6.29.6/lib/random32.c 2009-07-02 19:41:20.000000000 -0400 | |
36996 | +++ linux-2.6.29.6/lib/random32.c 2009-07-09 22:13:40.000000000 -0400 | |
36997 | @@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state * | |
36998 | */ | |
36999 | static inline u32 __seed(u32 x, u32 m) | |
37000 | { | |
37001 | - return (x < m) ? x + m : x; | |
37002 | + return (x <= m) ? x + m + 1 : x; | |
37003 | } | |
37004 | ||
37005 | /** | |
37006 | diff -urNp linux-2.6.29.6/localversion-grsec linux-2.6.29.6/localversion-grsec | |
37007 | --- linux-2.6.29.6/localversion-grsec 1969-12-31 19:00:00.000000000 -0500 | |
37008 | +++ linux-2.6.29.6/localversion-grsec 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37009 | @@ -0,0 +1 @@ |
37010 | +-grsec | |
de855c5d AM |
37011 | diff -urNp linux-2.6.29.6/Makefile linux-2.6.29.6/Makefile |
37012 | --- linux-2.6.29.6/Makefile 2009-07-02 19:41:20.000000000 -0400 | |
37013 | +++ linux-2.6.29.6/Makefile 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37014 | @@ -226,7 +226,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" |
37015 | ||
37016 | HOSTCC = gcc | |
37017 | HOSTCXX = g++ | |
37018 | -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer | |
37019 | +HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer | |
37020 | HOSTCXXFLAGS = -O2 | |
37021 | ||
37022 | # Decide whether to build built-in, modular, or both. | |
37023 | @@ -636,7 +636,7 @@ export mod_strip_cmd | |
37024 | ||
37025 | ||
37026 | ifeq ($(KBUILD_EXTMOD),) | |
37027 | -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ | |
37028 | +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/ | |
37029 | ||
37030 | vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ | |
37031 | $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ | |
de855c5d AM |
37032 | diff -urNp linux-2.6.29.6/mm/filemap.c linux-2.6.29.6/mm/filemap.c |
37033 | --- linux-2.6.29.6/mm/filemap.c 2009-07-02 19:41:20.000000000 -0400 | |
37034 | +++ linux-2.6.29.6/mm/filemap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37035 | @@ -1615,7 +1615,7 @@ int generic_file_mmap(struct file * file |
37036 | struct address_space *mapping = file->f_mapping; | |
37037 | ||
37038 | if (!mapping->a_ops->readpage) | |
37039 | - return -ENOEXEC; | |
37040 | + return -ENODEV; | |
37041 | file_accessed(file); | |
37042 | vma->vm_ops = &generic_file_vm_ops; | |
37043 | vma->vm_flags |= VM_CAN_NONLINEAR; | |
37044 | @@ -1976,6 +1976,7 @@ inline int generic_write_checks(struct f | |
37045 | *pos = i_size_read(inode); | |
37046 | ||
37047 | if (limit != RLIM_INFINITY) { | |
37048 | + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0); | |
37049 | if (*pos >= limit) { | |
37050 | send_sig(SIGXFSZ, current, 0); | |
37051 | return -EFBIG; | |
de855c5d AM |
37052 | diff -urNp linux-2.6.29.6/mm/fremap.c linux-2.6.29.6/mm/fremap.c |
37053 | --- linux-2.6.29.6/mm/fremap.c 2009-07-02 19:41:20.000000000 -0400 | |
37054 | +++ linux-2.6.29.6/mm/fremap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37055 | @@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign |
37056 | retry: | |
37057 | vma = find_vma(mm, start); | |
37058 | ||
37059 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37060 | + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) | |
37061 | + goto out; | |
37062 | +#endif | |
37063 | + | |
37064 | /* | |
37065 | * Make sure the vma is shared, that it supports prefaulting, | |
37066 | * and that the remapped range is valid and fully within | |
de855c5d AM |
37067 | diff -urNp linux-2.6.29.6/mm/hugetlb.c linux-2.6.29.6/mm/hugetlb.c |
37068 | --- linux-2.6.29.6/mm/hugetlb.c 2009-07-02 19:41:20.000000000 -0400 | |
37069 | +++ linux-2.6.29.6/mm/hugetlb.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37070 | @@ -1864,6 +1864,26 @@ static int unmap_ref_private(struct mm_s |
37071 | return 1; | |
37072 | } | |
37073 | ||
37074 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37075 | +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m) | |
37076 | +{ | |
37077 | + struct mm_struct *mm = vma->vm_mm; | |
37078 | + struct vm_area_struct *vma_m; | |
37079 | + unsigned long address_m; | |
37080 | + pte_t *ptep_m; | |
37081 | + | |
37082 | + vma_m = pax_find_mirror_vma(vma); | |
37083 | + if (!vma_m) | |
37084 | + return; | |
37085 | + | |
37086 | + BUG_ON(address >= SEGMEXEC_TASK_SIZE); | |
37087 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37088 | + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK); | |
37089 | + get_page(page_m); | |
37090 | + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0)); | |
37091 | +} | |
37092 | +#endif | |
37093 | + | |
37094 | static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, | |
37095 | unsigned long address, pte_t *ptep, pte_t pte, | |
37096 | struct page *pagecache_page) | |
37097 | @@ -1935,6 +1955,11 @@ retry_avoidcopy: | |
37098 | huge_ptep_clear_flush(vma, address, ptep); | |
37099 | set_huge_pte_at(mm, address, ptep, | |
37100 | make_huge_pte(vma, new_page, 1)); | |
37101 | + | |
37102 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37103 | + pax_mirror_huge_pte(vma, address, new_page); | |
37104 | +#endif | |
37105 | + | |
37106 | /* Make the old page be freed below */ | |
37107 | new_page = old_page; | |
37108 | } | |
37109 | @@ -2044,6 +2069,10 @@ retry: | |
37110 | && (vma->vm_flags & VM_SHARED))); | |
37111 | set_huge_pte_at(mm, address, ptep, new_pte); | |
37112 | ||
37113 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37114 | + pax_mirror_huge_pte(vma, address, page); | |
37115 | +#endif | |
37116 | + | |
37117 | if (write_access && !(vma->vm_flags & VM_SHARED)) { | |
37118 | /* Optimization, do the COW without a second fault */ | |
37119 | ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page); | |
37120 | @@ -2072,6 +2101,28 @@ int hugetlb_fault(struct mm_struct *mm, | |
37121 | static DEFINE_MUTEX(hugetlb_instantiation_mutex); | |
37122 | struct hstate *h = hstate_vma(vma); | |
37123 | ||
37124 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37125 | + struct vm_area_struct *vma_m; | |
37126 | + | |
37127 | + vma_m = pax_find_mirror_vma(vma); | |
37128 | + if (vma_m) { | |
37129 | + unsigned long address_m; | |
37130 | + | |
37131 | + if (vma->vm_start > vma_m->vm_start) { | |
37132 | + address_m = address; | |
37133 | + address -= SEGMEXEC_TASK_SIZE; | |
37134 | + vma = vma_m; | |
37135 | + h = hstate_vma(vma); | |
37136 | + } else | |
37137 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37138 | + | |
37139 | + if (!huge_pte_alloc(mm, address_m, huge_page_size(h))) | |
37140 | + return VM_FAULT_OOM; | |
37141 | + address_m &= HPAGE_MASK; | |
37142 | + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL); | |
37143 | + } | |
37144 | +#endif | |
37145 | + | |
37146 | ptep = huge_pte_alloc(mm, address, huge_page_size(h)); | |
37147 | if (!ptep) | |
37148 | return VM_FAULT_OOM; | |
de855c5d AM |
37149 | diff -urNp linux-2.6.29.6/mm/madvise.c linux-2.6.29.6/mm/madvise.c |
37150 | --- linux-2.6.29.6/mm/madvise.c 2009-07-02 19:41:20.000000000 -0400 | |
37151 | +++ linux-2.6.29.6/mm/madvise.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37152 | @@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a |
37153 | pgoff_t pgoff; | |
37154 | int new_flags = vma->vm_flags; | |
37155 | ||
37156 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37157 | + struct vm_area_struct *vma_m; | |
37158 | +#endif | |
37159 | + | |
37160 | switch (behavior) { | |
37161 | case MADV_NORMAL: | |
37162 | new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ; | |
37163 | @@ -92,6 +96,13 @@ success: | |
37164 | /* | |
37165 | * vm_flags is protected by the mmap_sem held in write mode. | |
37166 | */ | |
37167 | + | |
37168 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37169 | + vma_m = pax_find_mirror_vma(vma); | |
37170 | + if (vma_m) | |
37171 | + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT); | |
37172 | +#endif | |
37173 | + | |
37174 | vma->vm_flags = new_flags; | |
37175 | ||
37176 | out: | |
de855c5d | 37177 | @@ -244,6 +255,17 @@ madvise_vma(struct vm_area_struct *vma, |
2380c486 JR |
37178 | |
37179 | case MADV_DONTNEED: | |
37180 | error = madvise_dontneed(vma, prev, start, end); | |
37181 | + | |
37182 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37183 | + if (!error) { | |
37184 | + struct vm_area_struct *vma_m, *prev_m; | |
37185 | + | |
37186 | + vma_m = pax_find_mirror_vma(vma); | |
37187 | + if (vma_m) | |
37188 | + error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE); | |
37189 | + } | |
37190 | +#endif | |
37191 | + | |
37192 | break; | |
37193 | ||
37194 | default: | |
de855c5d | 37195 | @@ -316,6 +338,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, |
2380c486 JR |
37196 | if (end < start) |
37197 | goto out; | |
37198 | ||
37199 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37200 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) { | |
37201 | + if (end > SEGMEXEC_TASK_SIZE) | |
37202 | + goto out; | |
37203 | + } else | |
37204 | +#endif | |
37205 | + | |
37206 | + if (end > TASK_SIZE) | |
37207 | + goto out; | |
37208 | + | |
37209 | error = 0; | |
37210 | if (end == start) | |
37211 | goto out; | |
de855c5d AM |
37212 | diff -urNp linux-2.6.29.6/mm/memory.c linux-2.6.29.6/mm/memory.c |
37213 | --- linux-2.6.29.6/mm/memory.c 2009-07-02 19:41:20.000000000 -0400 | |
37214 | +++ linux-2.6.29.6/mm/memory.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37215 | @@ -47,6 +47,7 @@ |
37216 | #include <linux/pagemap.h> | |
37217 | #include <linux/rmap.h> | |
37218 | #include <linux/module.h> | |
37219 | +#include <linux/security.h> | |
37220 | #include <linux/delayacct.h> | |
37221 | #include <linux/init.h> | |
37222 | #include <linux/writeback.h> | |
37223 | @@ -1222,11 +1223,11 @@ int __get_user_pages(struct task_struct | |
37224 | vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE); | |
37225 | i = 0; | |
37226 | ||
37227 | - do { | |
37228 | + while (len) { | |
37229 | struct vm_area_struct *vma; | |
37230 | unsigned int foll_flags; | |
37231 | ||
37232 | - vma = find_extend_vma(mm, start); | |
37233 | + vma = find_vma(mm, start); | |
37234 | if (!vma && in_gate_area(tsk, start)) { | |
37235 | unsigned long pg = start & PAGE_MASK; | |
37236 | struct vm_area_struct *gate_vma = get_gate_vma(tsk); | |
37237 | @@ -1268,7 +1269,7 @@ int __get_user_pages(struct task_struct | |
37238 | continue; | |
37239 | } | |
37240 | ||
37241 | - if (!vma || | |
37242 | + if (!vma || start < vma->vm_start || | |
37243 | (vma->vm_flags & (VM_IO | VM_PFNMAP)) || | |
37244 | (!ignore && !(vm_flags & vma->vm_flags))) | |
37245 | return i ? : -EFAULT; | |
37246 | @@ -1351,7 +1352,7 @@ int __get_user_pages(struct task_struct | |
37247 | start += PAGE_SIZE; | |
37248 | len--; | |
37249 | } while (len && start < vma->vm_end); | |
37250 | - } while (len); | |
37251 | + } | |
37252 | return i; | |
37253 | } | |
37254 | ||
de855c5d | 37255 | @@ -1869,6 +1870,186 @@ static inline void cow_user_page(struct |
2380c486 JR |
37256 | copy_user_highpage(dst, src, va, vma); |
37257 | } | |
37258 | ||
37259 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37260 | +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd) | |
37261 | +{ | |
37262 | + struct mm_struct *mm = vma->vm_mm; | |
37263 | + spinlock_t *ptl; | |
37264 | + pte_t *pte, entry; | |
37265 | + | |
37266 | + pte = pte_offset_map_lock(mm, pmd, address, &ptl); | |
37267 | + entry = *pte; | |
37268 | + if (!pte_present(entry)) { | |
37269 | + if (!pte_none(entry)) { | |
37270 | + BUG_ON(pte_file(entry)); | |
37271 | + free_swap_and_cache(pte_to_swp_entry(entry)); | |
37272 | + pte_clear_not_present_full(mm, address, pte, 0); | |
37273 | + } | |
37274 | + } else { | |
37275 | + struct page *page; | |
37276 | + | |
37277 | + flush_cache_page(vma, address, pte_pfn(entry)); | |
37278 | + entry = ptep_clear_flush(vma, address, pte); | |
37279 | + BUG_ON(pte_dirty(entry)); | |
37280 | + page = vm_normal_page(vma, address, entry); | |
37281 | + if (page) { | |
37282 | + update_hiwater_rss(mm); | |
37283 | + if (PageAnon(page)) | |
37284 | + dec_mm_counter(mm, anon_rss); | |
37285 | + else | |
37286 | + dec_mm_counter(mm, file_rss); | |
37287 | + page_remove_rmap(page); | |
37288 | + page_cache_release(page); | |
37289 | + } | |
37290 | + } | |
37291 | + pte_unmap_unlock(pte, ptl); | |
37292 | +} | |
37293 | + | |
37294 | +/* PaX: if vma is mirrored, synchronize the mirror's PTE | |
37295 | + * | |
37296 | + * the ptl of the lower mapped page is held on entry and is not released on exit | |
37297 | + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc) | |
37298 | + */ | |
37299 | +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl) | |
37300 | +{ | |
37301 | + struct mm_struct *mm = vma->vm_mm; | |
37302 | + unsigned long address_m; | |
37303 | + spinlock_t *ptl_m; | |
37304 | + struct vm_area_struct *vma_m; | |
37305 | + pmd_t *pmd_m; | |
37306 | + pte_t *pte_m, entry_m; | |
37307 | + | |
37308 | + BUG_ON(!page_m || !PageAnon(page_m)); | |
37309 | + | |
37310 | + vma_m = pax_find_mirror_vma(vma); | |
37311 | + if (!vma_m) | |
37312 | + return; | |
37313 | + | |
37314 | + BUG_ON(!PageLocked(page_m)); | |
37315 | + BUG_ON(address >= SEGMEXEC_TASK_SIZE); | |
37316 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37317 | + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m); | |
37318 | + pte_m = pte_offset_map_nested(pmd_m, address_m); | |
37319 | + ptl_m = pte_lockptr(mm, pmd_m); | |
37320 | + if (ptl != ptl_m) { | |
37321 | + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING); | |
37322 | + if (!pte_none(*pte_m)) | |
37323 | + goto out; | |
37324 | + } | |
37325 | + | |
37326 | + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot); | |
37327 | + page_cache_get(page_m); | |
37328 | + page_add_anon_rmap(page_m, vma_m, address_m); | |
37329 | + inc_mm_counter(mm, anon_rss); | |
37330 | + set_pte_at(mm, address_m, pte_m, entry_m); | |
37331 | + update_mmu_cache(vma_m, address_m, entry_m); | |
37332 | +out: | |
37333 | + if (ptl != ptl_m) | |
37334 | + spin_unlock(ptl_m); | |
37335 | + pte_unmap_nested(pte_m); | |
37336 | + unlock_page(page_m); | |
37337 | +} | |
37338 | + | |
37339 | +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl) | |
37340 | +{ | |
37341 | + struct mm_struct *mm = vma->vm_mm; | |
37342 | + unsigned long address_m; | |
37343 | + spinlock_t *ptl_m; | |
37344 | + struct vm_area_struct *vma_m; | |
37345 | + pmd_t *pmd_m; | |
37346 | + pte_t *pte_m, entry_m; | |
37347 | + | |
37348 | + BUG_ON(!page_m || PageAnon(page_m)); | |
37349 | + | |
37350 | + vma_m = pax_find_mirror_vma(vma); | |
37351 | + if (!vma_m) | |
37352 | + return; | |
37353 | + | |
37354 | + BUG_ON(address >= SEGMEXEC_TASK_SIZE); | |
37355 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37356 | + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m); | |
37357 | + pte_m = pte_offset_map_nested(pmd_m, address_m); | |
37358 | + ptl_m = pte_lockptr(mm, pmd_m); | |
37359 | + if (ptl != ptl_m) { | |
37360 | + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING); | |
37361 | + if (!pte_none(*pte_m)) | |
37362 | + goto out; | |
37363 | + } | |
37364 | + | |
37365 | + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot); | |
37366 | + page_cache_get(page_m); | |
37367 | + page_add_file_rmap(page_m); | |
37368 | + inc_mm_counter(mm, file_rss); | |
37369 | + set_pte_at(mm, address_m, pte_m, entry_m); | |
37370 | + update_mmu_cache(vma_m, address_m, entry_m); | |
37371 | +out: | |
37372 | + if (ptl != ptl_m) | |
37373 | + spin_unlock(ptl_m); | |
37374 | + pte_unmap_nested(pte_m); | |
37375 | +} | |
37376 | + | |
37377 | +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl) | |
37378 | +{ | |
37379 | + struct mm_struct *mm = vma->vm_mm; | |
37380 | + unsigned long address_m; | |
37381 | + spinlock_t *ptl_m; | |
37382 | + struct vm_area_struct *vma_m; | |
37383 | + pmd_t *pmd_m; | |
37384 | + pte_t *pte_m, entry_m; | |
37385 | + | |
37386 | + vma_m = pax_find_mirror_vma(vma); | |
37387 | + if (!vma_m) | |
37388 | + return; | |
37389 | + | |
37390 | + BUG_ON(address >= SEGMEXEC_TASK_SIZE); | |
37391 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37392 | + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m); | |
37393 | + pte_m = pte_offset_map_nested(pmd_m, address_m); | |
37394 | + ptl_m = pte_lockptr(mm, pmd_m); | |
37395 | + if (ptl != ptl_m) { | |
37396 | + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING); | |
37397 | + if (!pte_none(*pte_m)) | |
37398 | + goto out; | |
37399 | + } | |
37400 | + | |
37401 | + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot); | |
37402 | + set_pte_at(mm, address_m, pte_m, entry_m); | |
37403 | +out: | |
37404 | + if (ptl != ptl_m) | |
37405 | + spin_unlock(ptl_m); | |
37406 | + pte_unmap_nested(pte_m); | |
37407 | +} | |
37408 | + | |
37409 | +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl) | |
37410 | +{ | |
37411 | + struct page *page_m; | |
37412 | + pte_t entry; | |
37413 | + | |
37414 | + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC)) | |
37415 | + goto out; | |
37416 | + | |
37417 | + entry = *pte; | |
37418 | + page_m = vm_normal_page(vma, address, entry); | |
37419 | + if (!page_m) | |
37420 | + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl); | |
37421 | + else if (PageAnon(page_m)) { | |
37422 | + if (pax_find_mirror_vma(vma)) { | |
37423 | + pte_unmap_unlock(pte, ptl); | |
37424 | + lock_page(page_m); | |
37425 | + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl); | |
37426 | + if (pte_same(entry, *pte)) | |
37427 | + pax_mirror_anon_pte(vma, address, page_m, ptl); | |
37428 | + else | |
37429 | + unlock_page(page_m); | |
37430 | + } | |
37431 | + } else | |
37432 | + pax_mirror_file_pte(vma, address, page_m, ptl); | |
37433 | + | |
37434 | +out: | |
37435 | + pte_unmap_unlock(pte, ptl); | |
37436 | +} | |
37437 | +#endif | |
37438 | + | |
37439 | /* | |
37440 | * This routine handles present pages, when users try to write | |
37441 | * to a shared page. It is done by copying the page to a new address | |
de855c5d | 37442 | @@ -2041,6 +2222,12 @@ gotten: |
2380c486 JR |
37443 | */ |
37444 | page_table = pte_offset_map_lock(mm, pmd, address, &ptl); | |
37445 | if (likely(pte_same(*page_table, orig_pte))) { | |
37446 | + | |
37447 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37448 | + if (pax_find_mirror_vma(vma)) | |
37449 | + BUG_ON(!trylock_page(new_page)); | |
37450 | +#endif | |
37451 | + | |
37452 | if (old_page) { | |
37453 | if (!PageAnon(old_page)) { | |
37454 | dec_mm_counter(mm, file_rss); | |
de855c5d | 37455 | @@ -2087,6 +2274,10 @@ gotten: |
2380c486 JR |
37456 | page_remove_rmap(old_page); |
37457 | } | |
37458 | ||
37459 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37460 | + pax_mirror_anon_pte(vma, address, new_page, ptl); | |
37461 | +#endif | |
37462 | + | |
37463 | /* Free the old page.. */ | |
37464 | new_page = old_page; | |
37465 | ret |= VM_FAULT_WRITE; | |
de855c5d | 37466 | @@ -2368,6 +2559,7 @@ int vmtruncate(struct inode * inode, lof |
2380c486 JR |
37467 | unsigned long limit; |
37468 | ||
37469 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; | |
37470 | + gr_learn_resource(current, RLIMIT_FSIZE, offset, 1); | |
37471 | if (limit != RLIM_INFINITY && offset > limit) | |
37472 | goto out_sig; | |
37473 | if (offset > inode->i_sb->s_maxbytes) | |
de855c5d | 37474 | @@ -2533,6 +2725,11 @@ static int do_swap_page(struct mm_struct |
2380c486 JR |
37475 | swap_free(entry); |
37476 | if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page)) | |
37477 | try_to_free_swap(page); | |
37478 | + | |
37479 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37480 | + if (write_access || !pax_find_mirror_vma(vma)) | |
37481 | +#endif | |
37482 | + | |
37483 | unlock_page(page); | |
37484 | ||
37485 | if (write_access) { | |
de855c5d | 37486 | @@ -2544,6 +2741,11 @@ static int do_swap_page(struct mm_struct |
2380c486 JR |
37487 | |
37488 | /* No need to invalidate - it was non-present before */ | |
37489 | update_mmu_cache(vma, address, pte); | |
37490 | + | |
37491 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37492 | + pax_mirror_anon_pte(vma, address, page, ptl); | |
37493 | +#endif | |
37494 | + | |
37495 | unlock: | |
37496 | pte_unmap_unlock(page_table, ptl); | |
37497 | out: | |
de855c5d | 37498 | @@ -2588,12 +2790,23 @@ static int do_anonymous_page(struct mm_s |
2380c486 JR |
37499 | page_table = pte_offset_map_lock(mm, pmd, address, &ptl); |
37500 | if (!pte_none(*page_table)) | |
37501 | goto release; | |
37502 | + | |
37503 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37504 | + if (pax_find_mirror_vma(vma)) | |
37505 | + BUG_ON(!trylock_page(page)); | |
37506 | +#endif | |
37507 | + | |
37508 | inc_mm_counter(mm, anon_rss); | |
37509 | page_add_new_anon_rmap(page, vma, address); | |
37510 | set_pte_at(mm, address, page_table, entry); | |
37511 | ||
37512 | /* No need to invalidate - it was non-present before */ | |
37513 | update_mmu_cache(vma, address, entry); | |
37514 | + | |
37515 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37516 | + pax_mirror_anon_pte(vma, address, page, ptl); | |
37517 | +#endif | |
37518 | + | |
37519 | unlock: | |
37520 | pte_unmap_unlock(page_table, ptl); | |
37521 | return 0; | |
de855c5d | 37522 | @@ -2730,6 +2943,12 @@ static int __do_fault(struct mm_struct * |
2380c486 JR |
37523 | */ |
37524 | /* Only go through if we didn't race with anybody else... */ | |
37525 | if (likely(pte_same(*page_table, orig_pte))) { | |
37526 | + | |
37527 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37528 | + if (anon && pax_find_mirror_vma(vma)) | |
37529 | + BUG_ON(!trylock_page(page)); | |
37530 | +#endif | |
37531 | + | |
37532 | flush_icache_page(vma, page); | |
37533 | entry = mk_pte(page, vma->vm_page_prot); | |
37534 | if (flags & FAULT_FLAG_WRITE) | |
de855c5d | 37535 | @@ -2749,6 +2968,14 @@ static int __do_fault(struct mm_struct * |
2380c486 JR |
37536 | |
37537 | /* no need to invalidate: a not-present page won't be cached */ | |
37538 | update_mmu_cache(vma, address, entry); | |
37539 | + | |
37540 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37541 | + if (anon) | |
37542 | + pax_mirror_anon_pte(vma, address, page, ptl); | |
37543 | + else | |
37544 | + pax_mirror_file_pte(vma, address, page, ptl); | |
37545 | +#endif | |
37546 | + | |
37547 | } else { | |
37548 | if (charged) | |
37549 | mem_cgroup_uncharge_page(page); | |
de855c5d | 37550 | @@ -2897,6 +3124,12 @@ static inline int handle_pte_fault(struc |
2380c486 JR |
37551 | if (write_access) |
37552 | flush_tlb_page(vma, address); | |
37553 | } | |
37554 | + | |
37555 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37556 | + pax_mirror_pte(vma, address, pte, pmd, ptl); | |
37557 | + return 0; | |
37558 | +#endif | |
37559 | + | |
37560 | unlock: | |
37561 | pte_unmap_unlock(pte, ptl); | |
37562 | return 0; | |
de855c5d | 37563 | @@ -2913,6 +3146,10 @@ int handle_mm_fault(struct mm_struct *mm |
2380c486 JR |
37564 | pmd_t *pmd; |
37565 | pte_t *pte; | |
37566 | ||
37567 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37568 | + struct vm_area_struct *vma_m; | |
37569 | +#endif | |
37570 | + | |
37571 | __set_current_state(TASK_RUNNING); | |
37572 | ||
37573 | count_vm_event(PGFAULT); | |
de855c5d | 37574 | @@ -2920,6 +3157,34 @@ int handle_mm_fault(struct mm_struct *mm |
2380c486 JR |
37575 | if (unlikely(is_vm_hugetlb_page(vma))) |
37576 | return hugetlb_fault(mm, vma, address, write_access); | |
37577 | ||
37578 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37579 | + vma_m = pax_find_mirror_vma(vma); | |
37580 | + if (vma_m) { | |
37581 | + unsigned long address_m; | |
37582 | + pgd_t *pgd_m; | |
37583 | + pud_t *pud_m; | |
37584 | + pmd_t *pmd_m; | |
37585 | + | |
37586 | + if (vma->vm_start > vma_m->vm_start) { | |
37587 | + address_m = address; | |
37588 | + address -= SEGMEXEC_TASK_SIZE; | |
37589 | + vma = vma_m; | |
37590 | + } else | |
37591 | + address_m = address + SEGMEXEC_TASK_SIZE; | |
37592 | + | |
37593 | + pgd_m = pgd_offset(mm, address_m); | |
37594 | + pud_m = pud_alloc(mm, pgd_m, address_m); | |
37595 | + if (!pud_m) | |
37596 | + return VM_FAULT_OOM; | |
37597 | + pmd_m = pmd_alloc(mm, pud_m, address_m); | |
37598 | + if (!pmd_m) | |
37599 | + return VM_FAULT_OOM; | |
37600 | + if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m)) | |
37601 | + return VM_FAULT_OOM; | |
37602 | + pax_unmap_mirror_pte(vma_m, address_m, pmd_m); | |
37603 | + } | |
37604 | +#endif | |
37605 | + | |
37606 | pgd = pgd_offset(mm, address); | |
37607 | pud = pud_alloc(mm, pgd, address); | |
37608 | if (!pud) | |
de855c5d | 37609 | @@ -3017,7 +3282,7 @@ static int __init gate_vma_init(void) |
2380c486 JR |
37610 | gate_vma.vm_start = FIXADDR_USER_START; |
37611 | gate_vma.vm_end = FIXADDR_USER_END; | |
37612 | gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC; | |
37613 | - gate_vma.vm_page_prot = __P101; | |
37614 | + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags); | |
37615 | /* | |
37616 | * Make sure the vDSO gets into every core dump. | |
37617 | * Dumping its contents makes post-mortem fully interpretable later | |
de855c5d AM |
37618 | diff -urNp linux-2.6.29.6/mm/mempolicy.c linux-2.6.29.6/mm/mempolicy.c |
37619 | --- linux-2.6.29.6/mm/mempolicy.c 2009-07-02 19:41:20.000000000 -0400 | |
37620 | +++ linux-2.6.29.6/mm/mempolicy.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37621 | @@ -551,6 +551,10 @@ static int mbind_range(struct vm_area_st |
37622 | struct vm_area_struct *next; | |
37623 | int err; | |
37624 | ||
37625 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37626 | + struct vm_area_struct *vma_m; | |
37627 | +#endif | |
37628 | + | |
37629 | err = 0; | |
37630 | for (; vma && vma->vm_start < end; vma = next) { | |
37631 | next = vma->vm_next; | |
37632 | @@ -562,6 +566,16 @@ static int mbind_range(struct vm_area_st | |
37633 | err = policy_vma(vma, new); | |
37634 | if (err) | |
37635 | break; | |
37636 | + | |
37637 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37638 | + vma_m = pax_find_mirror_vma(vma); | |
37639 | + if (vma_m) { | |
37640 | + err = policy_vma(vma_m, new); | |
37641 | + if (err) | |
37642 | + break; | |
37643 | + } | |
37644 | +#endif | |
37645 | + | |
37646 | } | |
37647 | return err; | |
37648 | } | |
37649 | @@ -954,6 +968,17 @@ static long do_mbind(unsigned long start | |
37650 | ||
37651 | if (end < start) | |
37652 | return -EINVAL; | |
37653 | + | |
37654 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37655 | + if (mm->pax_flags & MF_PAX_SEGMEXEC) { | |
37656 | + if (end > SEGMEXEC_TASK_SIZE) | |
37657 | + return -EINVAL; | |
37658 | + } else | |
37659 | +#endif | |
37660 | + | |
37661 | + if (end > TASK_SIZE) | |
37662 | + return -EINVAL; | |
37663 | + | |
37664 | if (end == start) | |
37665 | return 0; | |
37666 | ||
37667 | @@ -2290,7 +2315,7 @@ int show_numa_map(struct seq_file *m, vo | |
37668 | ||
37669 | if (file) { | |
37670 | seq_printf(m, " file="); | |
37671 | - seq_path(m, &file->f_path, "\n\t= "); | |
37672 | + seq_path(m, &file->f_path, "\n\t\\= "); | |
37673 | } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { | |
37674 | seq_printf(m, " heap"); | |
37675 | } else if (vma->vm_start <= mm->start_stack && | |
de855c5d AM |
37676 | diff -urNp linux-2.6.29.6/mm/mlock.c linux-2.6.29.6/mm/mlock.c |
37677 | --- linux-2.6.29.6/mm/mlock.c 2009-07-02 19:41:20.000000000 -0400 | |
37678 | +++ linux-2.6.29.6/mm/mlock.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37679 | @@ -13,6 +13,7 @@ |
37680 | #include <linux/pagemap.h> | |
37681 | #include <linux/mempolicy.h> | |
37682 | #include <linux/syscalls.h> | |
37683 | +#include <linux/security.h> | |
37684 | #include <linux/sched.h> | |
37685 | #include <linux/module.h> | |
37686 | #include <linux/rmap.h> | |
37687 | @@ -453,6 +454,17 @@ static int do_mlock(unsigned long start, | |
37688 | return -EINVAL; | |
37689 | if (end == start) | |
37690 | return 0; | |
37691 | + | |
37692 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37693 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) { | |
37694 | + if (end > SEGMEXEC_TASK_SIZE) | |
37695 | + return -EINVAL; | |
37696 | + } else | |
37697 | +#endif | |
37698 | + | |
37699 | + if (end > TASK_SIZE) | |
37700 | + return -EINVAL; | |
37701 | + | |
37702 | vma = find_vma_prev(current->mm, start, &prev); | |
37703 | if (!vma || vma->vm_start > start) | |
37704 | return -ENOMEM; | |
37705 | @@ -512,6 +524,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st | |
37706 | lock_limit >>= PAGE_SHIFT; | |
37707 | ||
37708 | /* check against resource limits */ | |
37709 | + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1); | |
37710 | if ((locked <= lock_limit) || capable(CAP_IPC_LOCK)) | |
37711 | error = do_mlock(start, len, 1); | |
37712 | up_write(¤t->mm->mmap_sem); | |
37713 | @@ -533,10 +546,10 @@ SYSCALL_DEFINE2(munlock, unsigned long, | |
37714 | static int do_mlockall(int flags) | |
37715 | { | |
37716 | struct vm_area_struct * vma, * prev = NULL; | |
37717 | - unsigned int def_flags = 0; | |
37718 | + unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED; | |
37719 | ||
37720 | if (flags & MCL_FUTURE) | |
37721 | - def_flags = VM_LOCKED; | |
37722 | + def_flags |= VM_LOCKED; | |
37723 | current->mm->def_flags = def_flags; | |
37724 | if (flags == MCL_FUTURE) | |
37725 | goto out; | |
37726 | @@ -544,6 +557,12 @@ static int do_mlockall(int flags) | |
37727 | for (vma = current->mm->mmap; vma ; vma = prev->vm_next) { | |
37728 | unsigned int newflags; | |
37729 | ||
37730 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37731 | + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) | |
37732 | + break; | |
37733 | +#endif | |
37734 | + | |
37735 | + BUG_ON(vma->vm_end > TASK_SIZE); | |
37736 | newflags = vma->vm_flags | VM_LOCKED; | |
37737 | if (!(flags & MCL_CURRENT)) | |
37738 | newflags &= ~VM_LOCKED; | |
de855c5d AM |
37739 | @@ -575,6 +594,7 @@ SYSCALL_DEFINE1(mlockall, int, flags) |
37740 | lock_limit >>= PAGE_SHIFT; | |
37741 | ||
2380c486 | 37742 | ret = -ENOMEM; |
3f74aa08 | 37743 | + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1); |
2380c486 | 37744 | if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) || |
3f74aa08 AM |
37745 | capable(CAP_IPC_LOCK)) |
37746 | ret = do_mlockall(flags); | |
de855c5d AM |
37747 | diff -urNp linux-2.6.29.6/mm/mmap.c linux-2.6.29.6/mm/mmap.c |
37748 | --- linux-2.6.29.6/mm/mmap.c 2009-07-02 19:41:20.000000000 -0400 | |
37749 | +++ linux-2.6.29.6/mm/mmap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
37750 | @@ -43,6 +43,16 @@ |
37751 | #define arch_rebalance_pgtables(addr, len) (addr) | |
37752 | #endif | |
37753 | ||
37754 | +static inline void verify_mm_writelocked(struct mm_struct *mm) | |
37755 | +{ | |
37756 | +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX) | |
37757 | + if (unlikely(down_read_trylock(&mm->mmap_sem))) { | |
37758 | + up_read(&mm->mmap_sem); | |
37759 | + BUG(); | |
37760 | + } | |
37761 | +#endif | |
37762 | +} | |
37763 | + | |
37764 | static void unmap_region(struct mm_struct *mm, | |
37765 | struct vm_area_struct *vma, struct vm_area_struct *prev, | |
37766 | unsigned long start, unsigned long end); | |
de855c5d | 37767 | @@ -68,16 +78,25 @@ static void unmap_region(struct mm_struc |
2380c486 JR |
37768 | * x: (no) no x: (no) yes x: (no) yes x: (yes) yes |
37769 | * | |
37770 | */ | |
37771 | -pgprot_t protection_map[16] = { | |
37772 | +pgprot_t protection_map[16] __read_only = { | |
37773 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, | |
37774 | __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 | |
37775 | }; | |
37776 | ||
37777 | pgprot_t vm_get_page_prot(unsigned long vm_flags) | |
37778 | { | |
37779 | - return __pgprot(pgprot_val(protection_map[vm_flags & | |
37780 | + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags & | |
37781 | (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) | | |
37782 | pgprot_val(arch_vm_get_page_prot(vm_flags))); | |
37783 | + | |
37784 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32) | |
37785 | + if (!nx_enabled && | |
37786 | + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC && | |
37787 | + (vm_flags & (VM_READ | VM_WRITE))) | |
37788 | + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot))))); | |
37789 | +#endif | |
37790 | + | |
37791 | + return prot; | |
37792 | } | |
37793 | EXPORT_SYMBOL(vm_get_page_prot); | |
37794 | ||
de855c5d | 37795 | @@ -229,6 +248,7 @@ static struct vm_area_struct *remove_vma |
2380c486 JR |
37796 | struct vm_area_struct *next = vma->vm_next; |
37797 | ||
37798 | might_sleep(); | |
37799 | + BUG_ON(vma->vm_mirror); | |
37800 | if (vma->vm_ops && vma->vm_ops->close) | |
37801 | vma->vm_ops->close(vma); | |
37802 | if (vma->vm_file) { | |
de855c5d | 37803 | @@ -265,6 +285,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) |
2380c486 JR |
37804 | * not page aligned -Ram Gupta |
37805 | */ | |
37806 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | |
37807 | + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1); | |
37808 | if (rlim < RLIM_INFINITY && (brk - mm->start_brk) + | |
37809 | (mm->end_data - mm->start_data) > rlim) | |
37810 | goto out; | |
de855c5d | 37811 | @@ -694,6 +715,12 @@ static int |
2380c486 JR |
37812 | can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, |
37813 | struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff) | |
37814 | { | |
37815 | + | |
37816 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37817 | + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE) | |
37818 | + return 0; | |
37819 | +#endif | |
37820 | + | |
37821 | if (is_mergeable_vma(vma, file, vm_flags) && | |
37822 | is_mergeable_anon_vma(anon_vma, vma->anon_vma)) { | |
37823 | if (vma->vm_pgoff == vm_pgoff) | |
de855c5d | 37824 | @@ -713,6 +740,12 @@ static int |
2380c486 JR |
37825 | can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, |
37826 | struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff) | |
37827 | { | |
37828 | + | |
37829 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37830 | + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE) | |
37831 | + return 0; | |
37832 | +#endif | |
37833 | + | |
37834 | if (is_mergeable_vma(vma, file, vm_flags) && | |
37835 | is_mergeable_anon_vma(anon_vma, vma->anon_vma)) { | |
37836 | pgoff_t vm_pglen; | |
de855c5d | 37837 | @@ -755,12 +788,19 @@ can_vma_merge_after(struct vm_area_struc |
2380c486 JR |
37838 | struct vm_area_struct *vma_merge(struct mm_struct *mm, |
37839 | struct vm_area_struct *prev, unsigned long addr, | |
37840 | unsigned long end, unsigned long vm_flags, | |
37841 | - struct anon_vma *anon_vma, struct file *file, | |
37842 | + struct anon_vma *anon_vma, struct file *file, | |
37843 | pgoff_t pgoff, struct mempolicy *policy) | |
37844 | { | |
37845 | pgoff_t pglen = (end - addr) >> PAGE_SHIFT; | |
37846 | struct vm_area_struct *area, *next; | |
37847 | ||
37848 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37849 | + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE; | |
37850 | + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL; | |
37851 | + | |
37852 | + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end); | |
37853 | +#endif | |
37854 | + | |
37855 | /* | |
37856 | * We later require that vma->vm_flags == vm_flags, | |
37857 | * so this tests vma->vm_flags & VM_SPECIAL, too. | |
de855c5d | 37858 | @@ -776,6 +816,15 @@ struct vm_area_struct *vma_merge(struct |
2380c486 JR |
37859 | if (next && next->vm_end == end) /* cases 6, 7, 8 */ |
37860 | next = next->vm_next; | |
37861 | ||
37862 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37863 | + if (prev) | |
37864 | + prev_m = pax_find_mirror_vma(prev); | |
37865 | + if (area) | |
37866 | + area_m = pax_find_mirror_vma(area); | |
37867 | + if (next) | |
37868 | + next_m = pax_find_mirror_vma(next); | |
37869 | +#endif | |
37870 | + | |
37871 | /* | |
37872 | * Can it merge with the predecessor? | |
37873 | */ | |
de855c5d | 37874 | @@ -795,9 +844,24 @@ struct vm_area_struct *vma_merge(struct |
2380c486 JR |
37875 | /* cases 1, 6 */ |
37876 | vma_adjust(prev, prev->vm_start, | |
37877 | next->vm_end, prev->vm_pgoff, NULL); | |
37878 | - } else /* cases 2, 5, 7 */ | |
37879 | + | |
37880 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37881 | + if (prev_m) | |
37882 | + vma_adjust(prev_m, prev_m->vm_start, | |
37883 | + next_m->vm_end, prev_m->vm_pgoff, NULL); | |
37884 | +#endif | |
37885 | + | |
37886 | + } else { /* cases 2, 5, 7 */ | |
37887 | vma_adjust(prev, prev->vm_start, | |
37888 | end, prev->vm_pgoff, NULL); | |
37889 | + | |
37890 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37891 | + if (prev_m) | |
37892 | + vma_adjust(prev_m, prev_m->vm_start, | |
37893 | + end_m, prev_m->vm_pgoff, NULL); | |
37894 | +#endif | |
37895 | + | |
37896 | + } | |
37897 | return prev; | |
37898 | } | |
37899 | ||
de855c5d | 37900 | @@ -808,12 +872,27 @@ struct vm_area_struct *vma_merge(struct |
2380c486 JR |
37901 | mpol_equal(policy, vma_policy(next)) && |
37902 | can_vma_merge_before(next, vm_flags, | |
37903 | anon_vma, file, pgoff+pglen)) { | |
37904 | - if (prev && addr < prev->vm_end) /* case 4 */ | |
37905 | + if (prev && addr < prev->vm_end) { /* case 4 */ | |
37906 | vma_adjust(prev, prev->vm_start, | |
37907 | addr, prev->vm_pgoff, NULL); | |
37908 | - else /* cases 3, 8 */ | |
37909 | + | |
37910 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37911 | + if (prev_m) | |
37912 | + vma_adjust(prev_m, prev_m->vm_start, | |
37913 | + addr_m, prev_m->vm_pgoff, NULL); | |
37914 | +#endif | |
37915 | + | |
37916 | + } else { /* cases 3, 8 */ | |
37917 | vma_adjust(area, addr, next->vm_end, | |
37918 | next->vm_pgoff - pglen, NULL); | |
37919 | + | |
37920 | +#ifdef CONFIG_PAX_SEGMEXEC | |
37921 | + if (area_m) | |
37922 | + vma_adjust(area_m, addr_m, next_m->vm_end, | |
37923 | + next_m->vm_pgoff - pglen, NULL); | |
37924 | +#endif | |
37925 | + | |
37926 | + } | |
37927 | return area; | |
37928 | } | |
37929 | ||
de855c5d | 37930 | @@ -888,14 +967,11 @@ none: |
2380c486 JR |
37931 | void vm_stat_account(struct mm_struct *mm, unsigned long flags, |
37932 | struct file *file, long pages) | |
37933 | { | |
37934 | - const unsigned long stack_flags | |
37935 | - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN); | |
37936 | - | |
37937 | if (file) { | |
37938 | mm->shared_vm += pages; | |
37939 | if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC) | |
37940 | mm->exec_vm += pages; | |
37941 | - } else if (flags & stack_flags) | |
37942 | + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN)) | |
37943 | mm->stack_vm += pages; | |
37944 | if (flags & (VM_RESERVED|VM_IO)) | |
37945 | mm->reserved_vm += pages; | |
de855c5d | 37946 | @@ -922,7 +998,7 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
37947 | * (the exception is when the underlying filesystem is noexec |
37948 | * mounted, in which case we dont add PROT_EXEC.) | |
37949 | */ | |
37950 | - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC)) | |
37951 | + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC)) | |
37952 | if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC))) | |
37953 | prot |= PROT_EXEC; | |
37954 | ||
de855c5d | 37955 | @@ -932,15 +1008,15 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
37956 | if (!(flags & MAP_FIXED)) |
37957 | addr = round_hint_to_min(addr); | |
37958 | ||
37959 | - error = arch_mmap_check(addr, len, flags); | |
37960 | - if (error) | |
37961 | - return error; | |
37962 | - | |
37963 | /* Careful about overflows.. */ | |
37964 | len = PAGE_ALIGN(len); | |
37965 | if (!len || len > TASK_SIZE) | |
37966 | return -ENOMEM; | |
37967 | ||
37968 | + error = arch_mmap_check(addr, len, flags); | |
37969 | + if (error) | |
37970 | + return error; | |
37971 | + | |
37972 | /* offset overflow? */ | |
37973 | if ((pgoff + (len >> PAGE_SHIFT)) < pgoff) | |
37974 | return -EOVERFLOW; | |
de855c5d | 37975 | @@ -952,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
37976 | /* Obtain the address to map to. we verify (or select) it and ensure |
37977 | * that it represents a valid section of the address space. | |
37978 | */ | |
37979 | - addr = get_unmapped_area(file, addr, len, pgoff, flags); | |
37980 | + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0)); | |
37981 | if (addr & ~PAGE_MASK) | |
37982 | return addr; | |
37983 | ||
de855c5d | 37984 | @@ -963,6 +1039,26 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
37985 | vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) | |
37986 | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; | |
37987 | ||
37988 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
37989 | + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
37990 | + | |
37991 | +#ifdef CONFIG_PAX_MPROTECT | |
37992 | + if (mm->pax_flags & MF_PAX_MPROTECT) { | |
37993 | + if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC) | |
37994 | + vm_flags &= ~(VM_EXEC | VM_MAYEXEC); | |
37995 | + else | |
37996 | + vm_flags &= ~(VM_WRITE | VM_MAYWRITE); | |
37997 | + } | |
37998 | +#endif | |
37999 | + | |
38000 | + } | |
38001 | +#endif | |
38002 | + | |
38003 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32) | |
38004 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file) | |
38005 | + vm_flags &= ~VM_PAGEEXEC; | |
38006 | +#endif | |
38007 | + | |
38008 | if (flags & MAP_LOCKED) { | |
38009 | if (!can_do_mlock()) | |
38010 | return -EPERM; | |
de855c5d | 38011 | @@ -976,6 +1072,7 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
38012 | locked += mm->locked_vm; |
38013 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | |
38014 | lock_limit >>= PAGE_SHIFT; | |
38015 | + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1); | |
38016 | if (locked > lock_limit && !capable(CAP_IPC_LOCK)) | |
38017 | return -EAGAIN; | |
38018 | } | |
de855c5d | 38019 | @@ -1046,6 +1143,9 @@ unsigned long do_mmap_pgoff(struct file |
2380c486 JR |
38020 | if (error) |
38021 | return error; | |
38022 | ||
38023 | + if (!gr_acl_handle_mmap(file, prot)) | |
38024 | + return -EACCES; | |
38025 | + | |
38026 | return mmap_region(file, addr, len, flags, vm_flags, pgoff); | |
38027 | } | |
38028 | EXPORT_SYMBOL(do_mmap_pgoff); | |
de855c5d | 38029 | @@ -1058,10 +1158,10 @@ EXPORT_SYMBOL(do_mmap_pgoff); |
2380c486 JR |
38030 | */ |
38031 | int vma_wants_writenotify(struct vm_area_struct *vma) | |
38032 | { | |
38033 | - unsigned int vm_flags = vma->vm_flags; | |
38034 | + unsigned long vm_flags = vma->vm_flags; | |
38035 | ||
38036 | /* If it was private or non-writable, the write bit is already clear */ | |
38037 | - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED))) | |
38038 | + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED)) | |
38039 | return 0; | |
38040 | ||
38041 | /* The backer wishes to know when pages are first written to? */ | |
de855c5d | 38042 | @@ -1110,14 +1210,24 @@ unsigned long mmap_region(struct file *f |
2380c486 JR |
38043 | unsigned long charged = 0; |
38044 | struct inode *inode = file ? file->f_path.dentry->d_inode : NULL; | |
38045 | ||
38046 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38047 | + struct vm_area_struct *vma_m = NULL; | |
38048 | +#endif | |
38049 | + | |
38050 | + /* | |
38051 | + * mm->mmap_sem is required to protect against another thread | |
38052 | + * changing the mappings in case we sleep. | |
38053 | + */ | |
38054 | + verify_mm_writelocked(mm); | |
38055 | + | |
38056 | /* Clear old maps */ | |
38057 | error = -ENOMEM; | |
38058 | -munmap_back: | |
38059 | vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent); | |
38060 | if (vma && vma->vm_start < addr + len) { | |
38061 | if (do_munmap(mm, addr, len)) | |
38062 | return -ENOMEM; | |
38063 | - goto munmap_back; | |
38064 | + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent); | |
38065 | + BUG_ON(vma && vma->vm_start < addr + len); | |
38066 | } | |
38067 | ||
38068 | /* Check against address space limit. */ | |
de855c5d | 38069 | @@ -1166,6 +1276,16 @@ munmap_back: |
2380c486 JR |
38070 | goto unacct_error; |
38071 | } | |
38072 | ||
38073 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38074 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) { | |
38075 | + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
38076 | + if (!vma_m) { | |
38077 | + error = -ENOMEM; | |
38078 | + goto free_vma; | |
38079 | + } | |
38080 | + } | |
38081 | +#endif | |
38082 | + | |
38083 | vma->vm_mm = mm; | |
38084 | vma->vm_start = addr; | |
38085 | vma->vm_end = addr + len; | |
de855c5d | 38086 | @@ -1188,6 +1308,19 @@ munmap_back: |
2380c486 JR |
38087 | error = file->f_op->mmap(file, vma); |
38088 | if (error) | |
38089 | goto unmap_and_free_vma; | |
38090 | + | |
38091 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38092 | + if (vma_m && (vm_flags & VM_EXECUTABLE)) | |
38093 | + added_exe_file_vma(mm); | |
38094 | +#endif | |
38095 | + | |
38096 | +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32) | |
38097 | + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) { | |
38098 | + vma->vm_flags |= VM_PAGEEXEC; | |
38099 | + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
38100 | + } | |
38101 | +#endif | |
38102 | + | |
38103 | if (vm_flags & VM_EXECUTABLE) | |
38104 | added_exe_file_vma(mm); | |
38105 | } else if (vm_flags & VM_SHARED) { | |
de855c5d | 38106 | @@ -1211,12 +1344,18 @@ munmap_back: |
2380c486 JR |
38107 | vma_link(mm, vma, prev, rb_link, rb_parent); |
38108 | file = vma->vm_file; | |
38109 | ||
38110 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38111 | + if (vma_m) | |
38112 | + pax_mirror_vma(vma_m, vma); | |
38113 | +#endif | |
2380c486 JR |
38114 | + |
38115 | /* Once vma denies write, undo our temporary denial count */ | |
38116 | if (correct_wcount) | |
38117 | atomic_inc(&inode->i_writecount); | |
de855c5d AM |
38118 | out: |
38119 | mm->total_vm += len >> PAGE_SHIFT; | |
2380c486 JR |
38120 | vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT); |
38121 | + track_exec_limit(mm, addr, addr + len, vm_flags); | |
38122 | if (vm_flags & VM_LOCKED) { | |
38123 | /* | |
38124 | * makes pages present; downgrades, drops, reacquires mmap_sem | |
de855c5d | 38125 | @@ -1239,6 +1378,12 @@ unmap_and_free_vma: |
2380c486 JR |
38126 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); |
38127 | charged = 0; | |
38128 | free_vma: | |
38129 | + | |
38130 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38131 | + if (vma_m) | |
38132 | + kmem_cache_free(vm_area_cachep, vma_m); | |
38133 | +#endif | |
38134 | + | |
38135 | kmem_cache_free(vm_area_cachep, vma); | |
38136 | unacct_error: | |
38137 | if (charged) | |
de855c5d | 38138 | @@ -1272,6 +1417,10 @@ arch_get_unmapped_area(struct file *filp |
2380c486 JR |
38139 | if (flags & MAP_FIXED) |
38140 | return addr; | |
38141 | ||
38142 | +#ifdef CONFIG_PAX_RANDMMAP | |
38143 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
38144 | +#endif | |
38145 | + | |
38146 | if (addr) { | |
38147 | addr = PAGE_ALIGN(addr); | |
38148 | vma = find_vma(mm, addr); | |
de855c5d | 38149 | @@ -1280,10 +1429,10 @@ arch_get_unmapped_area(struct file *filp |
2380c486 JR |
38150 | return addr; |
38151 | } | |
38152 | if (len > mm->cached_hole_size) { | |
38153 | - start_addr = addr = mm->free_area_cache; | |
38154 | + start_addr = addr = mm->free_area_cache; | |
38155 | } else { | |
38156 | - start_addr = addr = TASK_UNMAPPED_BASE; | |
38157 | - mm->cached_hole_size = 0; | |
38158 | + start_addr = addr = mm->mmap_base; | |
38159 | + mm->cached_hole_size = 0; | |
38160 | } | |
38161 | ||
38162 | full_search: | |
de855c5d | 38163 | @@ -1294,9 +1443,8 @@ full_search: |
2380c486 JR |
38164 | * Start a new search - just in case we missed |
38165 | * some holes. | |
38166 | */ | |
38167 | - if (start_addr != TASK_UNMAPPED_BASE) { | |
38168 | - addr = TASK_UNMAPPED_BASE; | |
38169 | - start_addr = addr; | |
38170 | + if (start_addr != mm->mmap_base) { | |
38171 | + start_addr = addr = mm->mmap_base; | |
38172 | mm->cached_hole_size = 0; | |
38173 | goto full_search; | |
38174 | } | |
de855c5d | 38175 | @@ -1318,10 +1466,16 @@ full_search: |
2380c486 JR |
38176 | |
38177 | void arch_unmap_area(struct mm_struct *mm, unsigned long addr) | |
38178 | { | |
38179 | + | |
38180 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38181 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr) | |
38182 | + return; | |
38183 | +#endif | |
38184 | + | |
38185 | /* | |
38186 | * Is this a new hole at the lowest possible address? | |
38187 | */ | |
38188 | - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) { | |
38189 | + if (addr >= mm->mmap_base && addr < mm->free_area_cache) { | |
38190 | mm->free_area_cache = addr; | |
38191 | mm->cached_hole_size = ~0UL; | |
38192 | } | |
de855c5d | 38193 | @@ -1339,7 +1493,7 @@ arch_get_unmapped_area_topdown(struct fi |
2380c486 JR |
38194 | { |
38195 | struct vm_area_struct *vma; | |
38196 | struct mm_struct *mm = current->mm; | |
38197 | - unsigned long addr = addr0; | |
38198 | + unsigned long base = mm->mmap_base, addr = addr0; | |
38199 | ||
38200 | /* requested length too big for entire address space */ | |
38201 | if (len > TASK_SIZE) | |
de855c5d | 38202 | @@ -1348,6 +1502,10 @@ arch_get_unmapped_area_topdown(struct fi |
2380c486 JR |
38203 | if (flags & MAP_FIXED) |
38204 | return addr; | |
38205 | ||
38206 | +#ifdef CONFIG_PAX_RANDMMAP | |
38207 | + if (!(mm->pax_flags & MF_PAX_RANDMMAP)) | |
38208 | +#endif | |
38209 | + | |
38210 | /* requesting a specific address */ | |
38211 | if (addr) { | |
38212 | addr = PAGE_ALIGN(addr); | |
de855c5d | 38213 | @@ -1405,13 +1563,21 @@ bottomup: |
2380c486 JR |
38214 | * can happen with large stack limits and large mmap() |
38215 | * allocations. | |
38216 | */ | |
38217 | + mm->mmap_base = TASK_UNMAPPED_BASE; | |
38218 | + | |
38219 | +#ifdef CONFIG_PAX_RANDMMAP | |
38220 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
38221 | + mm->mmap_base += mm->delta_mmap; | |
38222 | +#endif | |
38223 | + | |
38224 | + mm->free_area_cache = mm->mmap_base; | |
38225 | mm->cached_hole_size = ~0UL; | |
38226 | - mm->free_area_cache = TASK_UNMAPPED_BASE; | |
38227 | addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags); | |
38228 | /* | |
38229 | * Restore the topdown base: | |
38230 | */ | |
38231 | - mm->free_area_cache = mm->mmap_base; | |
38232 | + mm->mmap_base = base; | |
38233 | + mm->free_area_cache = base; | |
38234 | mm->cached_hole_size = ~0UL; | |
38235 | ||
38236 | return addr; | |
de855c5d | 38237 | @@ -1420,6 +1586,12 @@ bottomup: |
2380c486 JR |
38238 | |
38239 | void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr) | |
38240 | { | |
38241 | + | |
38242 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38243 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr) | |
38244 | + return; | |
38245 | +#endif | |
38246 | + | |
38247 | /* | |
38248 | * Is this a new hole at the highest possible address? | |
38249 | */ | |
de855c5d | 38250 | @@ -1427,8 +1599,10 @@ void arch_unmap_area_topdown(struct mm_s |
2380c486 JR |
38251 | mm->free_area_cache = addr; |
38252 | ||
38253 | /* dont allow allocations above current base */ | |
38254 | - if (mm->free_area_cache > mm->mmap_base) | |
38255 | + if (mm->free_area_cache > mm->mmap_base) { | |
38256 | mm->free_area_cache = mm->mmap_base; | |
38257 | + mm->cached_hole_size = ~0UL; | |
38258 | + } | |
38259 | } | |
38260 | ||
38261 | unsigned long | |
de855c5d | 38262 | @@ -1528,6 +1702,27 @@ out: |
2380c486 JR |
38263 | return prev ? prev->vm_next : vma; |
38264 | } | |
38265 | ||
38266 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38267 | +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma) | |
38268 | +{ | |
38269 | + struct vm_area_struct *vma_m; | |
38270 | + | |
38271 | + BUG_ON(!vma || vma->vm_start >= vma->vm_end); | |
38272 | + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) { | |
38273 | + BUG_ON(vma->vm_mirror); | |
38274 | + return NULL; | |
38275 | + } | |
38276 | + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end); | |
38277 | + vma_m = vma->vm_mirror; | |
38278 | + BUG_ON(!vma_m || vma_m->vm_mirror != vma); | |
38279 | + BUG_ON(vma->vm_file != vma_m->vm_file); | |
38280 | + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start); | |
38281 | + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma); | |
38282 | + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED)); | |
38283 | + return vma_m; | |
38284 | +} | |
38285 | +#endif | |
38286 | + | |
38287 | /* | |
38288 | * Verify that the stack growth is acceptable and | |
38289 | * update accounting. This is shared with both the | |
de855c5d | 38290 | @@ -1544,6 +1739,7 @@ static int acct_stack_growth(struct vm_a |
2380c486 JR |
38291 | return -ENOMEM; |
38292 | ||
38293 | /* Stack limit test */ | |
38294 | + gr_learn_resource(current, RLIMIT_STACK, size, 1); | |
38295 | if (size > rlim[RLIMIT_STACK].rlim_cur) | |
38296 | return -ENOMEM; | |
38297 | ||
de855c5d | 38298 | @@ -1553,6 +1749,7 @@ static int acct_stack_growth(struct vm_a |
2380c486 JR |
38299 | unsigned long limit; |
38300 | locked = mm->locked_vm + grow; | |
38301 | limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT; | |
38302 | + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1); | |
38303 | if (locked > limit && !capable(CAP_IPC_LOCK)) | |
38304 | return -ENOMEM; | |
38305 | } | |
de855c5d | 38306 | @@ -1588,35 +1785,40 @@ static |
2380c486 JR |
38307 | #endif |
38308 | int expand_upwards(struct vm_area_struct *vma, unsigned long address) | |
38309 | { | |
38310 | - int error; | |
38311 | + int error, locknext; | |
38312 | ||
38313 | if (!(vma->vm_flags & VM_GROWSUP)) | |
38314 | return -EFAULT; | |
38315 | ||
38316 | + /* Also guard against wrapping around to address 0. */ | |
38317 | + if (address < PAGE_ALIGN(address+1)) | |
38318 | + address = PAGE_ALIGN(address+1); | |
38319 | + else | |
38320 | + return -ENOMEM; | |
38321 | + | |
38322 | /* | |
38323 | * We must make sure the anon_vma is allocated | |
38324 | * so that the anon_vma locking is not a noop. | |
38325 | */ | |
38326 | if (unlikely(anon_vma_prepare(vma))) | |
38327 | return -ENOMEM; | |
38328 | + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN); | |
38329 | + if (locknext && unlikely(anon_vma_prepare(vma->vm_next))) | |
38330 | + return -ENOMEM; | |
38331 | anon_vma_lock(vma); | |
38332 | + if (locknext) | |
38333 | + anon_vma_lock(vma->vm_next); | |
38334 | ||
38335 | /* | |
38336 | * vma->vm_start/vm_end cannot change under us because the caller | |
38337 | * is required to hold the mmap_sem in read mode. We need the | |
38338 | - * anon_vma lock to serialize against concurrent expand_stacks. | |
38339 | - * Also guard against wrapping around to address 0. | |
38340 | + * anon_vma locks to serialize against concurrent expand_stacks | |
38341 | + * and expand_upwards. | |
38342 | */ | |
38343 | - if (address < PAGE_ALIGN(address+4)) | |
38344 | - address = PAGE_ALIGN(address+4); | |
38345 | - else { | |
38346 | - anon_vma_unlock(vma); | |
38347 | - return -ENOMEM; | |
38348 | - } | |
38349 | error = 0; | |
38350 | ||
38351 | /* Somebody else might have raced and expanded it already */ | |
38352 | - if (address > vma->vm_end) { | |
38353 | + if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) { | |
38354 | unsigned long size, grow; | |
38355 | ||
38356 | size = address - vma->vm_start; | |
de855c5d | 38357 | @@ -1626,6 +1828,8 @@ int expand_upwards(struct vm_area_struct |
2380c486 JR |
38358 | if (!error) |
38359 | vma->vm_end = address; | |
38360 | } | |
38361 | + if (locknext) | |
38362 | + anon_vma_unlock(vma->vm_next); | |
38363 | anon_vma_unlock(vma); | |
38364 | return error; | |
38365 | } | |
de855c5d | 38366 | @@ -1637,7 +1841,8 @@ int expand_upwards(struct vm_area_struct |
2380c486 JR |
38367 | static int expand_downwards(struct vm_area_struct *vma, |
38368 | unsigned long address) | |
38369 | { | |
38370 | - int error; | |
38371 | + int error, lockprev = 0; | |
38372 | + struct vm_area_struct *prev = NULL; | |
38373 | ||
38374 | /* | |
38375 | * We must make sure the anon_vma is allocated | |
de855c5d | 38376 | @@ -1651,6 +1856,15 @@ static int expand_downwards(struct vm_ar |
2380c486 JR |
38377 | if (error) |
38378 | return error; | |
38379 | ||
38380 | +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64) | |
38381 | + find_vma_prev(vma->vm_mm, address, &prev); | |
38382 | + lockprev = prev && (prev->vm_flags & VM_GROWSUP); | |
38383 | +#endif | |
38384 | + if (lockprev && unlikely(anon_vma_prepare(prev))) | |
38385 | + return -ENOMEM; | |
38386 | + if (lockprev) | |
38387 | + anon_vma_lock(prev); | |
38388 | + | |
38389 | anon_vma_lock(vma); | |
38390 | ||
38391 | /* | |
de855c5d | 38392 | @@ -1660,9 +1874,15 @@ static int expand_downwards(struct vm_ar |
2380c486 JR |
38393 | */ |
38394 | ||
38395 | /* Somebody else might have raced and expanded it already */ | |
38396 | - if (address < vma->vm_start) { | |
38397 | + if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) { | |
38398 | unsigned long size, grow; | |
38399 | ||
38400 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38401 | + struct vm_area_struct *vma_m; | |
38402 | + | |
38403 | + vma_m = pax_find_mirror_vma(vma); | |
38404 | +#endif | |
38405 | + | |
38406 | size = vma->vm_end - address; | |
38407 | grow = (vma->vm_start - address) >> PAGE_SHIFT; | |
38408 | ||
de855c5d | 38409 | @@ -1670,9 +1890,20 @@ static int expand_downwards(struct vm_ar |
2380c486 JR |
38410 | if (!error) { |
38411 | vma->vm_start = address; | |
38412 | vma->vm_pgoff -= grow; | |
38413 | + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags); | |
38414 | + | |
38415 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38416 | + if (vma_m) { | |
38417 | + vma_m->vm_start -= grow << PAGE_SHIFT; | |
38418 | + vma_m->vm_pgoff -= grow; | |
38419 | + } | |
38420 | +#endif | |
38421 | + | |
38422 | } | |
38423 | } | |
38424 | anon_vma_unlock(vma); | |
38425 | + if (lockprev) | |
38426 | + anon_vma_unlock(prev); | |
38427 | return error; | |
38428 | } | |
38429 | ||
de855c5d | 38430 | @@ -1748,6 +1979,13 @@ static void remove_vma_list(struct mm_st |
2380c486 JR |
38431 | do { |
38432 | long nrpages = vma_pages(vma); | |
38433 | ||
38434 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38435 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) { | |
38436 | + vma = remove_vma(vma); | |
38437 | + continue; | |
38438 | + } | |
38439 | +#endif | |
38440 | + | |
de855c5d | 38441 | mm->total_vm -= nrpages; |
2380c486 | 38442 | vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages); |
de855c5d AM |
38443 | vma = remove_vma(vma); |
38444 | @@ -1792,6 +2030,16 @@ detach_vmas_to_be_unmapped(struct mm_str | |
2380c486 JR |
38445 | |
38446 | insertion_point = (prev ? &prev->vm_next : &mm->mmap); | |
38447 | do { | |
38448 | + | |
38449 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38450 | + if (vma->vm_mirror) { | |
38451 | + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma); | |
38452 | + vma->vm_mirror->vm_mirror = NULL; | |
38453 | + vma->vm_mirror->vm_flags &= ~VM_EXEC; | |
38454 | + vma->vm_mirror = NULL; | |
38455 | + } | |
38456 | +#endif | |
38457 | + | |
38458 | rb_erase(&vma->vm_rb, &mm->mm_rb); | |
38459 | mm->map_count--; | |
38460 | tail_vma = vma; | |
de855c5d | 38461 | @@ -1811,6 +2059,108 @@ detach_vmas_to_be_unmapped(struct mm_str |
2380c486 JR |
38462 | * Split a vma into two pieces at address 'addr', a new vma is allocated |
38463 | * either for the first part or the tail. | |
38464 | */ | |
38465 | + | |
38466 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38467 | +int split_vma(struct mm_struct * mm, struct vm_area_struct * vma, | |
38468 | + unsigned long addr, int new_below) | |
38469 | +{ | |
38470 | + struct mempolicy *pol; | |
38471 | + struct vm_area_struct *new, *vma_m, *new_m = NULL; | |
38472 | + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE; | |
38473 | + | |
38474 | + if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK)) | |
38475 | + return -EINVAL; | |
38476 | + | |
38477 | + vma_m = pax_find_mirror_vma(vma); | |
38478 | + if (vma_m) { | |
38479 | + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE); | |
38480 | + if (mm->map_count >= sysctl_max_map_count-1) | |
38481 | + return -ENOMEM; | |
38482 | + } else if (mm->map_count >= sysctl_max_map_count) | |
38483 | + return -ENOMEM; | |
38484 | + | |
38485 | + new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); | |
38486 | + if (!new) | |
38487 | + return -ENOMEM; | |
38488 | + | |
38489 | + if (vma_m) { | |
38490 | + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); | |
38491 | + if (!new_m) { | |
38492 | + kmem_cache_free(vm_area_cachep, new); | |
38493 | + return -ENOMEM; | |
38494 | + } | |
38495 | + } | |
38496 | + | |
38497 | + /* most fields are the same, copy all, and then fixup */ | |
38498 | + *new = *vma; | |
38499 | + | |
38500 | + if (new_below) | |
38501 | + new->vm_end = addr; | |
38502 | + else { | |
38503 | + new->vm_start = addr; | |
38504 | + new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT); | |
38505 | + } | |
38506 | + | |
38507 | + if (vma_m) { | |
38508 | + *new_m = *vma_m; | |
38509 | + new_m->vm_mirror = new; | |
38510 | + new->vm_mirror = new_m; | |
38511 | + | |
38512 | + if (new_below) | |
38513 | + new_m->vm_end = addr_m; | |
38514 | + else { | |
38515 | + new_m->vm_start = addr_m; | |
38516 | + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT); | |
38517 | + } | |
38518 | + } | |
38519 | + | |
38520 | + pol = mpol_dup(vma_policy(vma)); | |
38521 | + if (IS_ERR(pol)) { | |
38522 | + if (new_m) | |
38523 | + kmem_cache_free(vm_area_cachep, new_m); | |
38524 | + kmem_cache_free(vm_area_cachep, new); | |
38525 | + return PTR_ERR(pol); | |
38526 | + } | |
38527 | + vma_set_policy(new, pol); | |
38528 | + | |
38529 | + if (new->vm_file) { | |
38530 | + get_file(new->vm_file); | |
38531 | + if (vma->vm_flags & VM_EXECUTABLE) | |
38532 | + added_exe_file_vma(mm); | |
38533 | + } | |
38534 | + | |
38535 | + if (new->vm_ops && new->vm_ops->open) | |
38536 | + new->vm_ops->open(new); | |
38537 | + | |
38538 | + if (new_below) | |
38539 | + vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff + | |
38540 | + ((addr - new->vm_start) >> PAGE_SHIFT), new); | |
38541 | + else | |
38542 | + vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new); | |
38543 | + | |
38544 | + if (vma_m) { | |
38545 | + mpol_get(pol); | |
38546 | + vma_set_policy(new_m, pol); | |
38547 | + | |
38548 | + if (new_m->vm_file) { | |
38549 | + get_file(new_m->vm_file); | |
38550 | + if (vma_m->vm_flags & VM_EXECUTABLE) | |
38551 | + added_exe_file_vma(mm); | |
38552 | + } | |
38553 | + | |
38554 | + if (new_m->vm_ops && new_m->vm_ops->open) | |
38555 | + new_m->vm_ops->open(new_m); | |
38556 | + | |
38557 | + if (new_below) | |
38558 | + vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff + | |
38559 | + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m); | |
38560 | + else | |
38561 | + vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m); | |
38562 | + } | |
38563 | + | |
38564 | + return 0; | |
38565 | +} | |
38566 | +#else | |
38567 | int split_vma(struct mm_struct * mm, struct vm_area_struct * vma, | |
38568 | unsigned long addr, int new_below) | |
38569 | { | |
de855c5d | 38570 | @@ -1862,17 +2212,37 @@ int split_vma(struct mm_struct * mm, str |
2380c486 JR |
38571 | |
38572 | return 0; | |
38573 | } | |
38574 | +#endif | |
38575 | ||
38576 | /* Munmap is split into 2 main parts -- this part which finds | |
38577 | * what needs doing, and the areas themselves, which do the | |
38578 | * work. This now handles partial unmappings. | |
38579 | * Jeremy Fitzhardinge <jeremy@goop.org> | |
38580 | */ | |
38581 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38582 | int do_munmap(struct mm_struct *mm, unsigned long start, size_t len) | |
38583 | { | |
38584 | + int ret = __do_munmap(mm, start, len); | |
38585 | + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC)) | |
38586 | + return ret; | |
38587 | + | |
38588 | + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len); | |
38589 | +} | |
38590 | + | |
38591 | +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len) | |
38592 | +#else | |
38593 | +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len) | |
38594 | +#endif | |
38595 | +{ | |
38596 | unsigned long end; | |
38597 | struct vm_area_struct *vma, *prev, *last; | |
38598 | ||
38599 | + /* | |
38600 | + * mm->mmap_sem is required to protect against another thread | |
38601 | + * changing the mappings in case we sleep. | |
38602 | + */ | |
38603 | + verify_mm_writelocked(mm); | |
38604 | + | |
38605 | if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start) | |
38606 | return -EINVAL; | |
38607 | ||
de855c5d | 38608 | @@ -1936,6 +2306,8 @@ int do_munmap(struct mm_struct *mm, unsi |
2380c486 JR |
38609 | /* Fix up all other VM information */ |
38610 | remove_vma_list(mm, vma); | |
38611 | ||
38612 | + track_exec_limit(mm, start, end, 0UL); | |
38613 | + | |
38614 | return 0; | |
38615 | } | |
38616 | ||
de855c5d | 38617 | @@ -1948,22 +2320,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a |
2380c486 JR |
38618 | |
38619 | profile_munmap(addr); | |
38620 | ||
38621 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38622 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && | |
38623 | + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len)) | |
38624 | + return -EINVAL; | |
38625 | +#endif | |
38626 | + | |
38627 | down_write(&mm->mmap_sem); | |
38628 | ret = do_munmap(mm, addr, len); | |
38629 | up_write(&mm->mmap_sem); | |
38630 | return ret; | |
38631 | } | |
38632 | ||
38633 | -static inline void verify_mm_writelocked(struct mm_struct *mm) | |
38634 | -{ | |
38635 | -#ifdef CONFIG_DEBUG_VM | |
38636 | - if (unlikely(down_read_trylock(&mm->mmap_sem))) { | |
38637 | - WARN_ON(1); | |
38638 | - up_read(&mm->mmap_sem); | |
38639 | - } | |
38640 | -#endif | |
38641 | -} | |
38642 | - | |
38643 | /* | |
38644 | * this is really a simplified "do_mmap". it only handles | |
38645 | * anonymous maps. eventually we may be able to do some | |
de855c5d | 38646 | @@ -1977,6 +2345,11 @@ unsigned long do_brk(unsigned long addr, |
2380c486 JR |
38647 | struct rb_node ** rb_link, * rb_parent; |
38648 | pgoff_t pgoff = addr >> PAGE_SHIFT; | |
38649 | int error; | |
38650 | + unsigned long charged; | |
38651 | + | |
38652 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38653 | + struct vm_area_struct *vma_m = NULL; | |
38654 | +#endif | |
38655 | ||
38656 | len = PAGE_ALIGN(len); | |
38657 | if (!len) | |
de855c5d | 38658 | @@ -1994,19 +2367,34 @@ unsigned long do_brk(unsigned long addr, |
2380c486 JR |
38659 | |
38660 | flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; | |
38661 | ||
38662 | +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) | |
38663 | + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) { | |
38664 | + flags &= ~VM_EXEC; | |
38665 | + | |
38666 | +#ifdef CONFIG_PAX_MPROTECT | |
38667 | + if (mm->pax_flags & MF_PAX_MPROTECT) | |
38668 | + flags &= ~VM_MAYEXEC; | |
38669 | +#endif | |
38670 | + | |
38671 | + } | |
38672 | +#endif | |
38673 | + | |
38674 | error = arch_mmap_check(addr, len, flags); | |
38675 | if (error) | |
38676 | return error; | |
38677 | ||
38678 | + charged = len >> PAGE_SHIFT; | |
38679 | + | |
38680 | /* | |
38681 | * mlock MCL_FUTURE? | |
38682 | */ | |
38683 | if (mm->def_flags & VM_LOCKED) { | |
38684 | unsigned long locked, lock_limit; | |
38685 | - locked = len >> PAGE_SHIFT; | |
38686 | + locked = charged; | |
38687 | locked += mm->locked_vm; | |
38688 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | |
38689 | lock_limit >>= PAGE_SHIFT; | |
38690 | + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1); | |
38691 | if (locked > lock_limit && !capable(CAP_IPC_LOCK)) | |
38692 | return -EAGAIN; | |
de855c5d AM |
38693 | } |
38694 | @@ -2020,22 +2408,22 @@ unsigned long do_brk(unsigned long addr, | |
2380c486 JR |
38695 | /* |
38696 | * Clear old maps. this also does some error checking for us | |
38697 | */ | |
38698 | - munmap_back: | |
38699 | vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent); | |
38700 | if (vma && vma->vm_start < addr + len) { | |
38701 | if (do_munmap(mm, addr, len)) | |
38702 | return -ENOMEM; | |
38703 | - goto munmap_back; | |
38704 | + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent); | |
38705 | + BUG_ON(vma && vma->vm_start < addr + len); | |
38706 | } | |
38707 | ||
38708 | /* Check against address space limits *after* clearing old maps... */ | |
38709 | - if (!may_expand_vm(mm, len >> PAGE_SHIFT)) | |
38710 | + if (!may_expand_vm(mm, charged)) | |
38711 | return -ENOMEM; | |
38712 | ||
38713 | if (mm->map_count > sysctl_max_map_count) | |
38714 | return -ENOMEM; | |
38715 | ||
de855c5d AM |
38716 | - if (security_vm_enough_memory(len >> PAGE_SHIFT)) |
38717 | + if (security_vm_enough_memory(charged)) | |
2380c486 JR |
38718 | return -ENOMEM; |
38719 | ||
38720 | /* Can we just expand an old private anonymous mapping? */ | |
de855c5d | 38721 | @@ -2049,10 +2437,21 @@ unsigned long do_brk(unsigned long addr, |
2380c486 JR |
38722 | */ |
38723 | vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
38724 | if (!vma) { | |
38725 | - vm_unacct_memory(len >> PAGE_SHIFT); | |
38726 | + vm_unacct_memory(charged); | |
38727 | return -ENOMEM; | |
38728 | } | |
38729 | ||
38730 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38731 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) { | |
38732 | + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
38733 | + if (!vma_m) { | |
38734 | + kmem_cache_free(vm_area_cachep, vma); | |
38735 | + vm_unacct_memory(charged); | |
38736 | + return -ENOMEM; | |
38737 | + } | |
38738 | + } | |
38739 | +#endif | |
38740 | + | |
38741 | vma->vm_mm = mm; | |
38742 | vma->vm_start = addr; | |
38743 | vma->vm_end = addr + len; | |
de855c5d AM |
38744 | @@ -2061,11 +2460,12 @@ unsigned long do_brk(unsigned long addr, |
38745 | vma->vm_page_prot = vm_get_page_prot(flags); | |
2380c486 JR |
38746 | vma_link(mm, vma, prev, rb_link, rb_parent); |
38747 | out: | |
de855c5d AM |
38748 | - mm->total_vm += len >> PAGE_SHIFT; |
38749 | + mm->total_vm += charged; | |
2380c486 JR |
38750 | if (flags & VM_LOCKED) { |
38751 | if (!mlock_vma_pages_range(vma, addr, addr + len)) | |
de855c5d AM |
38752 | - mm->locked_vm += (len >> PAGE_SHIFT); |
38753 | + mm->locked_vm += charged; | |
2380c486 JR |
38754 | } |
38755 | + track_exec_limit(mm, addr, addr + len, flags); | |
38756 | return addr; | |
38757 | } | |
38758 | ||
de855c5d | 38759 | @@ -2111,8 +2511,10 @@ void exit_mmap(struct mm_struct *mm) |
2380c486 JR |
38760 | * Walk the list again, actually closing and freeing it, |
38761 | * with preemption enabled, without holding any MM locks. | |
38762 | */ | |
38763 | - while (vma) | |
38764 | + while (vma) { | |
38765 | + vma->vm_mirror = NULL; | |
38766 | vma = remove_vma(vma); | |
38767 | + } | |
38768 | ||
38769 | BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT); | |
38770 | } | |
de855c5d | 38771 | @@ -2126,6 +2528,10 @@ int insert_vm_struct(struct mm_struct * |
2380c486 JR |
38772 | struct vm_area_struct * __vma, * prev; |
38773 | struct rb_node ** rb_link, * rb_parent; | |
38774 | ||
38775 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38776 | + struct vm_area_struct *vma_m = NULL; | |
38777 | +#endif | |
38778 | + | |
38779 | /* | |
38780 | * The vm_pgoff of a purely anonymous vma should be irrelevant | |
38781 | * until its first write fault, when page's anon_vma and index | |
de855c5d AM |
38782 | @@ -2148,7 +2554,22 @@ int insert_vm_struct(struct mm_struct * |
38783 | if ((vma->vm_flags & VM_ACCOUNT) && | |
38784 | security_vm_enough_memory_mm(mm, vma_pages(vma))) | |
2380c486 JR |
38785 | return -ENOMEM; |
38786 | + | |
38787 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38788 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) { | |
38789 | + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
38790 | + if (!vma_m) | |
38791 | + return -ENOMEM; | |
38792 | + } | |
38793 | +#endif | |
38794 | + | |
38795 | vma_link(mm, vma, prev, rb_link, rb_parent); | |
38796 | + | |
38797 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38798 | + if (vma_m) | |
38799 | + pax_mirror_vma(vma_m, vma); | |
38800 | +#endif | |
38801 | + | |
38802 | return 0; | |
38803 | } | |
38804 | ||
de855c5d | 38805 | @@ -2166,6 +2587,8 @@ struct vm_area_struct *copy_vma(struct v |
2380c486 JR |
38806 | struct rb_node **rb_link, *rb_parent; |
38807 | struct mempolicy *pol; | |
38808 | ||
38809 | + BUG_ON(vma->vm_mirror); | |
38810 | + | |
38811 | /* | |
38812 | * If anonymous vma has not yet been faulted, update new pgoff | |
38813 | * to match new location, to increase its chance of merging. | |
de855c5d | 38814 | @@ -2209,6 +2632,35 @@ struct vm_area_struct *copy_vma(struct v |
2380c486 JR |
38815 | return new_vma; |
38816 | } | |
38817 | ||
38818 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38819 | +void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma) | |
38820 | +{ | |
38821 | + struct vm_area_struct *prev_m; | |
38822 | + struct rb_node **rb_link_m, *rb_parent_m; | |
38823 | + struct mempolicy *pol_m; | |
38824 | + | |
38825 | + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)); | |
38826 | + BUG_ON(vma->vm_mirror || vma_m->vm_mirror); | |
38827 | + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m))); | |
38828 | + *vma_m = *vma; | |
38829 | + pol_m = vma_policy(vma_m); | |
38830 | + mpol_get(pol_m); | |
38831 | + vma_set_policy(vma_m, pol_m); | |
38832 | + vma_m->vm_start += SEGMEXEC_TASK_SIZE; | |
38833 | + vma_m->vm_end += SEGMEXEC_TASK_SIZE; | |
38834 | + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED); | |
38835 | + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags); | |
38836 | + if (vma_m->vm_file) | |
38837 | + get_file(vma_m->vm_file); | |
38838 | + if (vma_m->vm_ops && vma_m->vm_ops->open) | |
38839 | + vma_m->vm_ops->open(vma_m); | |
38840 | + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m); | |
38841 | + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m); | |
38842 | + vma_m->vm_mirror = vma; | |
38843 | + vma->vm_mirror = vma_m; | |
38844 | +} | |
38845 | +#endif | |
38846 | + | |
38847 | /* | |
38848 | * Return true if the calling process may expand its vm space by the passed | |
38849 | * number of pages | |
de855c5d | 38850 | @@ -2219,7 +2671,7 @@ int may_expand_vm(struct mm_struct *mm, |
2380c486 JR |
38851 | unsigned long lim; |
38852 | ||
38853 | lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT; | |
38854 | - | |
38855 | + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1); | |
38856 | if (cur + npages > lim) | |
38857 | return 0; | |
de855c5d AM |
38858 | return 1; |
38859 | @@ -2288,6 +2740,15 @@ int install_special_mapping(struct mm_st | |
2380c486 JR |
38860 | vma->vm_start = addr; |
38861 | vma->vm_end = addr + len; | |
38862 | ||
38863 | +#ifdef CONFIG_PAX_MPROTECT | |
38864 | + if (mm->pax_flags & MF_PAX_MPROTECT) { | |
38865 | + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC) | |
38866 | + vm_flags &= ~(VM_EXEC | VM_MAYEXEC); | |
38867 | + else | |
38868 | + vm_flags &= ~(VM_WRITE | VM_MAYWRITE); | |
38869 | + } | |
38870 | +#endif | |
38871 | + | |
38872 | vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND; | |
38873 | vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | |
38874 | ||
de855c5d AM |
38875 | diff -urNp linux-2.6.29.6/mm/mprotect.c linux-2.6.29.6/mm/mprotect.c |
38876 | --- linux-2.6.29.6/mm/mprotect.c 2009-07-02 19:41:20.000000000 -0400 | |
38877 | +++ linux-2.6.29.6/mm/mprotect.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
38878 | @@ -23,10 +23,16 @@ |
38879 | #include <linux/swapops.h> | |
38880 | #include <linux/mmu_notifier.h> | |
38881 | #include <linux/migrate.h> | |
38882 | + | |
38883 | +#ifdef CONFIG_PAX_MPROTECT | |
38884 | +#include <linux/elf.h> | |
38885 | +#endif | |
38886 | + | |
38887 | #include <asm/uaccess.h> | |
38888 | #include <asm/pgtable.h> | |
38889 | #include <asm/cacheflush.h> | |
38890 | #include <asm/tlbflush.h> | |
38891 | +#include <asm/mmu_context.h> | |
38892 | ||
38893 | #ifndef pgprot_modify | |
38894 | static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) | |
38895 | @@ -131,6 +137,48 @@ static void change_protection(struct vm_ | |
38896 | flush_tlb_range(vma, start, end); | |
38897 | } | |
38898 | ||
38899 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
38900 | +/* called while holding the mmap semaphor for writing except stack expansion */ | |
38901 | +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) | |
38902 | +{ | |
38903 | + unsigned long oldlimit, newlimit = 0UL; | |
38904 | + | |
38905 | + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled) | |
38906 | + return; | |
38907 | + | |
38908 | + spin_lock(&mm->page_table_lock); | |
38909 | + oldlimit = mm->context.user_cs_limit; | |
38910 | + if ((prot & VM_EXEC) && oldlimit < end) | |
38911 | + /* USER_CS limit moved up */ | |
38912 | + newlimit = end; | |
38913 | + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end) | |
38914 | + /* USER_CS limit moved down */ | |
38915 | + newlimit = start; | |
38916 | + | |
38917 | + if (newlimit) { | |
38918 | + mm->context.user_cs_limit = newlimit; | |
38919 | + | |
38920 | +#ifdef CONFIG_SMP | |
38921 | + wmb(); | |
38922 | + cpus_clear(mm->context.cpu_user_cs_mask); | |
38923 | + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask); | |
38924 | +#endif | |
38925 | + | |
38926 | + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id()); | |
38927 | + } | |
38928 | + spin_unlock(&mm->page_table_lock); | |
38929 | + if (newlimit == end) { | |
38930 | + struct vm_area_struct *vma = find_vma(mm, oldlimit); | |
38931 | + | |
38932 | + for (; vma && vma->vm_start < end; vma = vma->vm_next) | |
38933 | + if (is_vm_hugetlb_page(vma)) | |
38934 | + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot); | |
38935 | + else | |
38936 | + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma)); | |
38937 | + } | |
38938 | +} | |
38939 | +#endif | |
38940 | + | |
38941 | int | |
38942 | mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, | |
38943 | unsigned long start, unsigned long end, unsigned long newflags) | |
38944 | @@ -143,6 +191,14 @@ mprotect_fixup(struct vm_area_struct *vm | |
38945 | int error; | |
38946 | int dirty_accountable = 0; | |
38947 | ||
38948 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38949 | + struct vm_area_struct *vma_m = NULL; | |
38950 | + unsigned long start_m, end_m; | |
38951 | + | |
38952 | + start_m = start + SEGMEXEC_TASK_SIZE; | |
38953 | + end_m = end + SEGMEXEC_TASK_SIZE; | |
38954 | +#endif | |
38955 | + | |
38956 | if (newflags == oldflags) { | |
38957 | *pprev = vma; | |
38958 | return 0; | |
38959 | @@ -164,6 +220,38 @@ mprotect_fixup(struct vm_area_struct *vm | |
38960 | } | |
38961 | } | |
38962 | ||
38963 | +#ifdef CONFIG_PAX_SEGMEXEC | |
38964 | + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) { | |
38965 | + if (start != vma->vm_start) { | |
38966 | + error = split_vma(mm, vma, start, 1); | |
38967 | + if (error) | |
38968 | + goto fail; | |
38969 | + BUG_ON(!*pprev || (*pprev)->vm_next == vma); | |
38970 | + *pprev = (*pprev)->vm_next; | |
38971 | + } | |
38972 | + | |
38973 | + if (end != vma->vm_end) { | |
38974 | + error = split_vma(mm, vma, end, 0); | |
38975 | + if (error) | |
38976 | + goto fail; | |
38977 | + } | |
38978 | + | |
38979 | + if (pax_find_mirror_vma(vma)) { | |
38980 | + error = __do_munmap(mm, start_m, end_m - start_m); | |
38981 | + if (error) | |
38982 | + goto fail; | |
38983 | + } else { | |
38984 | + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | |
38985 | + if (!vma_m) { | |
38986 | + error = -ENOMEM; | |
38987 | + goto fail; | |
38988 | + } | |
38989 | + vma->vm_flags = newflags; | |
38990 | + pax_mirror_vma(vma_m, vma); | |
38991 | + } | |
38992 | + } | |
38993 | +#endif | |
38994 | + | |
38995 | /* | |
38996 | * First try to merge with previous and/or next vma. | |
38997 | */ | |
38998 | @@ -195,8 +283,14 @@ success: | |
38999 | * held in write mode. | |
39000 | */ | |
39001 | vma->vm_flags = newflags; | |
39002 | + | |
39003 | +#ifdef CONFIG_PAX_MPROTECT | |
39004 | + if (current->binfmt && current->binfmt->handle_mprotect) | |
39005 | + current->binfmt->handle_mprotect(vma, newflags); | |
39006 | +#endif | |
39007 | + | |
39008 | vma->vm_page_prot = pgprot_modify(vma->vm_page_prot, | |
39009 | - vm_get_page_prot(newflags)); | |
39010 | + vm_get_page_prot(vma->vm_flags)); | |
39011 | ||
39012 | if (vma_wants_writenotify(vma)) { | |
39013 | vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED); | |
39014 | @@ -237,6 +331,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, | |
39015 | end = start + len; | |
39016 | if (end <= start) | |
39017 | return -ENOMEM; | |
39018 | + | |
39019 | +#ifdef CONFIG_PAX_SEGMEXEC | |
39020 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) { | |
39021 | + if (end > SEGMEXEC_TASK_SIZE) | |
39022 | + return -EINVAL; | |
39023 | + } else | |
39024 | +#endif | |
39025 | + | |
39026 | + if (end > TASK_SIZE) | |
39027 | + return -EINVAL; | |
39028 | + | |
39029 | if (!arch_validate_prot(prot)) | |
39030 | return -EINVAL; | |
39031 | ||
39032 | @@ -244,7 +349,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, | |
39033 | /* | |
39034 | * Does the application expect PROT_READ to imply PROT_EXEC: | |
39035 | */ | |
39036 | - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC)) | |
39037 | + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC)) | |
39038 | prot |= PROT_EXEC; | |
39039 | ||
39040 | vm_flags = calc_vm_prot_bits(prot); | |
39041 | @@ -276,6 +381,16 @@ SYSCALL_DEFINE3(mprotect, unsigned long, | |
39042 | if (start > vma->vm_start) | |
39043 | prev = vma; | |
39044 | ||
39045 | + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) { | |
39046 | + error = -EACCES; | |
39047 | + goto out; | |
39048 | + } | |
39049 | + | |
39050 | +#ifdef CONFIG_PAX_MPROTECT | |
39051 | + if (current->binfmt && current->binfmt->handle_mprotect) | |
39052 | + current->binfmt->handle_mprotect(vma, vm_flags); | |
39053 | +#endif | |
39054 | + | |
39055 | for (nstart = start ; ; ) { | |
39056 | unsigned long newflags; | |
39057 | ||
39058 | @@ -299,6 +414,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, | |
39059 | error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); | |
39060 | if (error) | |
39061 | goto out; | |
39062 | + | |
39063 | + track_exec_limit(current->mm, nstart, tmp, vm_flags); | |
39064 | + | |
39065 | nstart = tmp; | |
39066 | ||
39067 | if (nstart < prev->vm_end) | |
de855c5d AM |
39068 | diff -urNp linux-2.6.29.6/mm/mremap.c linux-2.6.29.6/mm/mremap.c |
39069 | --- linux-2.6.29.6/mm/mremap.c 2009-07-02 19:41:20.000000000 -0400 | |
39070 | +++ linux-2.6.29.6/mm/mremap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39071 | @@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str |
39072 | continue; | |
39073 | pte = ptep_clear_flush(vma, old_addr, old_pte); | |
39074 | pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr); | |
39075 | + | |
39076 | +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT | |
39077 | + if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC) | |
39078 | + pte = pte_exprotect(pte); | |
39079 | +#endif | |
39080 | + | |
39081 | set_pte_at(mm, new_addr, new_pte, pte); | |
39082 | } | |
39083 | ||
39084 | @@ -262,6 +268,7 @@ unsigned long do_mremap(unsigned long ad | |
39085 | struct vm_area_struct *vma; | |
39086 | unsigned long ret = -EINVAL; | |
39087 | unsigned long charged = 0; | |
39088 | + unsigned long pax_task_size = TASK_SIZE; | |
39089 | ||
39090 | if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) | |
39091 | goto out; | |
39092 | @@ -280,6 +287,15 @@ unsigned long do_mremap(unsigned long ad | |
39093 | if (!new_len) | |
39094 | goto out; | |
39095 | ||
39096 | +#ifdef CONFIG_PAX_SEGMEXEC | |
39097 | + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) | |
39098 | + pax_task_size = SEGMEXEC_TASK_SIZE; | |
39099 | +#endif | |
39100 | + | |
39101 | + if (new_len > pax_task_size || addr > pax_task_size-new_len || | |
39102 | + old_len > pax_task_size || addr > pax_task_size-old_len) | |
39103 | + goto out; | |
39104 | + | |
39105 | /* new_addr is only valid if MREMAP_FIXED is specified */ | |
39106 | if (flags & MREMAP_FIXED) { | |
39107 | if (new_addr & ~PAGE_MASK) | |
39108 | @@ -287,16 +303,13 @@ unsigned long do_mremap(unsigned long ad | |
39109 | if (!(flags & MREMAP_MAYMOVE)) | |
39110 | goto out; | |
39111 | ||
39112 | - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) | |
39113 | + if (new_addr > pax_task_size - new_len) | |
39114 | goto out; | |
39115 | ||
39116 | /* Check if the location we're moving into overlaps the | |
39117 | * old location at all, and fail if it does. | |
39118 | */ | |
39119 | - if ((new_addr <= addr) && (new_addr+new_len) > addr) | |
39120 | - goto out; | |
39121 | - | |
39122 | - if ((addr <= new_addr) && (addr+old_len) > new_addr) | |
39123 | + if (addr + old_len > new_addr && new_addr + new_len > addr) | |
39124 | goto out; | |
39125 | ||
39126 | ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1); | |
39127 | @@ -334,6 +347,14 @@ unsigned long do_mremap(unsigned long ad | |
39128 | ret = -EINVAL; | |
39129 | goto out; | |
39130 | } | |
39131 | + | |
39132 | +#ifdef CONFIG_PAX_SEGMEXEC | |
39133 | + if (pax_find_mirror_vma(vma)) { | |
39134 | + ret = -EINVAL; | |
39135 | + goto out; | |
39136 | + } | |
39137 | +#endif | |
39138 | + | |
39139 | /* We can't remap across vm area boundaries */ | |
39140 | if (old_len > vma->vm_end - addr) | |
39141 | goto out; | |
39142 | @@ -367,7 +388,7 @@ unsigned long do_mremap(unsigned long ad | |
39143 | if (old_len == vma->vm_end - addr && | |
39144 | !((flags & MREMAP_FIXED) && (addr != new_addr)) && | |
39145 | (old_len != new_len || !(flags & MREMAP_MAYMOVE))) { | |
39146 | - unsigned long max_addr = TASK_SIZE; | |
39147 | + unsigned long max_addr = pax_task_size; | |
39148 | if (vma->vm_next) | |
39149 | max_addr = vma->vm_next->vm_start; | |
39150 | /* can we just expand the current mapping? */ | |
39151 | @@ -385,6 +406,7 @@ unsigned long do_mremap(unsigned long ad | |
39152 | addr + new_len); | |
39153 | } | |
39154 | ret = addr; | |
39155 | + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags); | |
39156 | goto out; | |
39157 | } | |
39158 | } | |
39159 | @@ -395,8 +417,8 @@ unsigned long do_mremap(unsigned long ad | |
39160 | */ | |
39161 | ret = -ENOMEM; | |
39162 | if (flags & MREMAP_MAYMOVE) { | |
39163 | + unsigned long map_flags = 0; | |
39164 | if (!(flags & MREMAP_FIXED)) { | |
39165 | - unsigned long map_flags = 0; | |
39166 | if (vma->vm_flags & VM_MAYSHARE) | |
39167 | map_flags |= MAP_SHARED; | |
39168 | ||
39169 | @@ -411,7 +433,12 @@ unsigned long do_mremap(unsigned long ad | |
39170 | if (ret) | |
39171 | goto out; | |
39172 | } | |
39173 | + map_flags = vma->vm_flags; | |
39174 | ret = move_vma(vma, addr, old_len, new_len, new_addr); | |
39175 | + if (!(ret & ~PAGE_MASK)) { | |
39176 | + track_exec_limit(current->mm, addr, addr + old_len, 0UL); | |
39177 | + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags); | |
39178 | + } | |
39179 | } | |
39180 | out: | |
39181 | if (ret & ~PAGE_MASK) | |
de855c5d AM |
39182 | diff -urNp linux-2.6.29.6/mm/nommu.c linux-2.6.29.6/mm/nommu.c |
39183 | --- linux-2.6.29.6/mm/nommu.c 2009-07-02 19:41:20.000000000 -0400 | |
39184 | +++ linux-2.6.29.6/mm/nommu.c 2009-07-09 22:13:40.000000000 -0400 | |
39185 | @@ -770,15 +770,6 @@ struct vm_area_struct *find_vma(struct m | |
2380c486 JR |
39186 | EXPORT_SYMBOL(find_vma); |
39187 | ||
39188 | /* | |
39189 | - * find a VMA | |
39190 | - * - we don't extend stack VMAs under NOMMU conditions | |
39191 | - */ | |
39192 | -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr) | |
39193 | -{ | |
39194 | - return find_vma(mm, addr); | |
39195 | -} | |
39196 | - | |
39197 | -/* | |
39198 | * expand a stack to a given address | |
39199 | * - not supported under NOMMU conditions | |
39200 | */ | |
de855c5d AM |
39201 | diff -urNp linux-2.6.29.6/mm/page_alloc.c linux-2.6.29.6/mm/page_alloc.c |
39202 | --- linux-2.6.29.6/mm/page_alloc.c 2009-07-02 19:41:20.000000000 -0400 | |
39203 | +++ linux-2.6.29.6/mm/page_alloc.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39204 | @@ -549,6 +549,10 @@ static void __free_pages_ok(struct page |
39205 | int i; | |
39206 | int bad = 0; | |
39207 | ||
39208 | +#ifdef CONFIG_PAX_MEMORY_SANITIZE | |
39209 | + unsigned long index = 1UL << order; | |
39210 | +#endif | |
39211 | + | |
39212 | for (i = 0 ; i < (1 << order) ; ++i) | |
39213 | bad += free_pages_check(page + i); | |
39214 | if (bad) | |
39215 | @@ -559,6 +563,12 @@ static void __free_pages_ok(struct page | |
39216 | debug_check_no_obj_freed(page_address(page), | |
39217 | PAGE_SIZE << order); | |
39218 | } | |
39219 | + | |
39220 | +#ifdef CONFIG_PAX_MEMORY_SANITIZE | |
39221 | + for (; index; --index) | |
39222 | + sanitize_highpage(page + index - 1); | |
39223 | +#endif | |
39224 | + | |
39225 | arch_free_page(page, order); | |
39226 | kernel_map_pages(page, 1 << order, 0); | |
39227 | ||
39228 | @@ -647,8 +657,10 @@ static int prep_new_page(struct page *pa | |
39229 | arch_alloc_page(page, order); | |
39230 | kernel_map_pages(page, 1 << order, 1); | |
39231 | ||
39232 | +#ifndef CONFIG_PAX_MEMORY_SANITIZE | |
39233 | if (gfp_flags & __GFP_ZERO) | |
39234 | prep_zero_page(page, order, gfp_flags); | |
39235 | +#endif | |
39236 | ||
39237 | if (order && (gfp_flags & __GFP_COMP)) | |
39238 | prep_compound_page(page, order); | |
39239 | @@ -1009,6 +1021,11 @@ static void free_hot_cold_page(struct pa | |
39240 | debug_check_no_locks_freed(page_address(page), PAGE_SIZE); | |
39241 | debug_check_no_obj_freed(page_address(page), PAGE_SIZE); | |
39242 | } | |
39243 | + | |
39244 | +#ifdef CONFIG_PAX_MEMORY_SANITIZE | |
39245 | + sanitize_highpage(page); | |
39246 | +#endif | |
39247 | + | |
39248 | arch_free_page(page, 0); | |
39249 | kernel_map_pages(page, 1, 0); | |
39250 | ||
de855c5d AM |
39251 | diff -urNp linux-2.6.29.6/mm/rmap.c linux-2.6.29.6/mm/rmap.c |
39252 | --- linux-2.6.29.6/mm/rmap.c 2009-07-02 19:41:20.000000000 -0400 | |
39253 | +++ linux-2.6.29.6/mm/rmap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39254 | @@ -103,6 +103,10 @@ int anon_vma_prepare(struct vm_area_stru |
39255 | struct mm_struct *mm = vma->vm_mm; | |
39256 | struct anon_vma *allocated; | |
39257 | ||
39258 | +#ifdef CONFIG_PAX_SEGMEXEC | |
39259 | + struct vm_area_struct *vma_m; | |
39260 | +#endif | |
39261 | + | |
39262 | anon_vma = find_mergeable_anon_vma(vma); | |
39263 | allocated = NULL; | |
39264 | if (!anon_vma) { | |
39265 | @@ -116,6 +120,15 @@ int anon_vma_prepare(struct vm_area_stru | |
39266 | /* page_table_lock to protect against threads */ | |
39267 | spin_lock(&mm->page_table_lock); | |
39268 | if (likely(!vma->anon_vma)) { | |
39269 | + | |
39270 | +#ifdef CONFIG_PAX_SEGMEXEC | |
39271 | + vma_m = pax_find_mirror_vma(vma); | |
39272 | + if (vma_m) { | |
39273 | + vma_m->anon_vma = anon_vma; | |
39274 | + __anon_vma_link(vma_m); | |
39275 | + } | |
39276 | +#endif | |
39277 | + | |
39278 | vma->anon_vma = anon_vma; | |
39279 | list_add_tail(&vma->anon_vma_node, &anon_vma->head); | |
39280 | allocated = NULL; | |
de855c5d AM |
39281 | diff -urNp linux-2.6.29.6/mm/shmem.c linux-2.6.29.6/mm/shmem.c |
39282 | --- linux-2.6.29.6/mm/shmem.c 2009-07-02 19:41:20.000000000 -0400 | |
39283 | +++ linux-2.6.29.6/mm/shmem.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39284 | @@ -29,7 +29,7 @@ |
39285 | #include <linux/module.h> | |
39286 | #include <linux/swap.h> | |
39287 | ||
39288 | -static struct vfsmount *shm_mnt; | |
39289 | +struct vfsmount *shm_mnt; | |
39290 | ||
39291 | #ifdef CONFIG_SHMEM | |
39292 | /* | |
de855c5d AM |
39293 | diff -urNp linux-2.6.29.6/mm/slab.c linux-2.6.29.6/mm/slab.c |
39294 | --- linux-2.6.29.6/mm/slab.c 2009-07-02 19:41:20.000000000 -0400 | |
39295 | +++ linux-2.6.29.6/mm/slab.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39296 | @@ -305,7 +305,7 @@ struct kmem_list3 { |
39297 | * Need this for bootstrapping a per node allocator. | |
39298 | */ | |
39299 | #define NUM_INIT_LISTS (3 * MAX_NUMNODES) | |
39300 | -struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS]; | |
39301 | +struct kmem_list3 initkmem_list3[NUM_INIT_LISTS]; | |
39302 | #define CACHE_CACHE 0 | |
39303 | #define SIZE_AC MAX_NUMNODES | |
39304 | #define SIZE_L3 (2 * MAX_NUMNODES) | |
de855c5d AM |
39305 | @@ -628,7 +628,7 @@ static inline void *index_to_obj(struct |
39306 | * reciprocal_divide(offset, cache->reciprocal_buffer_size) | |
39307 | */ | |
39308 | static inline unsigned int obj_to_index(const struct kmem_cache *cache, | |
39309 | - const struct slab *slab, void *obj) | |
39310 | + const struct slab *slab, const void *obj) | |
39311 | { | |
39312 | u32 offset = (obj - slab->s_mem); | |
39313 | return reciprocal_divide(offset, cache->reciprocal_buffer_size); | |
2380c486 JR |
39314 | @@ -654,14 +654,14 @@ struct cache_names { |
39315 | static struct cache_names __initdata cache_names[] = { | |
39316 | #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" }, | |
39317 | #include <linux/kmalloc_sizes.h> | |
39318 | - {NULL,} | |
39319 | + {NULL, NULL} | |
39320 | #undef CACHE | |
39321 | }; | |
39322 | ||
39323 | static struct arraycache_init initarray_cache __initdata = | |
39324 | - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; | |
39325 | + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} }; | |
39326 | static struct arraycache_init initarray_generic = | |
39327 | - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; | |
39328 | + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} }; | |
39329 | ||
39330 | /* internal cache of cache description objs */ | |
39331 | static struct kmem_cache cache_cache = { | |
de855c5d | 39332 | @@ -4428,15 +4428,60 @@ static const struct file_operations proc |
2380c486 JR |
39333 | |
39334 | static int __init slab_proc_init(void) | |
39335 | { | |
39336 | +#if !defined(CONFIG_GRKERNSEC_PROC_ADD) | |
39337 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); | |
39338 | #ifdef CONFIG_DEBUG_SLAB_LEAK | |
39339 | proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); | |
39340 | #endif | |
39341 | +#endif | |
39342 | return 0; | |
39343 | } | |
39344 | module_init(slab_proc_init); | |
de855c5d AM |
39345 | #endif |
39346 | ||
39347 | +void check_object_size(const void *ptr, unsigned long n, bool to) | |
39348 | +{ | |
39349 | + | |
39350 | +#ifdef CONFIG_PAX_USERCOPY | |
39351 | + struct kmem_cache *cachep; | |
39352 | + struct slab *slabp; | |
39353 | + struct page *page; | |
39354 | + unsigned int objnr; | |
39355 | + unsigned long offset; | |
39356 | + | |
39357 | + if (!n) | |
39358 | + return; | |
39359 | + | |
39360 | + if (ZERO_OR_NULL_PTR(ptr)) | |
39361 | + goto report; | |
39362 | + | |
39363 | + if (!virt_addr_valid(ptr)) | |
39364 | + return; | |
39365 | + | |
39366 | + page = virt_to_head_page(ptr); | |
39367 | + | |
39368 | + if (!PageSlab(page)) | |
39369 | + /* TODO: check for stack based ptr */ | |
39370 | + return; | |
39371 | + | |
39372 | + cachep = page_get_cache(page); | |
39373 | + slabp = page_get_slab(page); | |
39374 | + objnr = obj_to_index(cachep, slabp, ptr); | |
39375 | + BUG_ON(objnr >= cachep->num); | |
39376 | + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep); | |
39377 | + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset) | |
39378 | + return; | |
39379 | + | |
39380 | +report: | |
39381 | + if (to) | |
39382 | + pax_report_leak_to_user(ptr, n); | |
39383 | + else | |
39384 | + pax_report_overflow_from_user(ptr, n); | |
39385 | +#endif | |
39386 | + | |
39387 | +} | |
39388 | +EXPORT_SYMBOL(check_object_size); | |
39389 | + | |
39390 | /** | |
39391 | * ksize - get the actual amount of memory allocated for a given object | |
39392 | * @objp: Pointer to the object | |
39393 | diff -urNp linux-2.6.29.6/mm/slob.c linux-2.6.29.6/mm/slob.c | |
39394 | --- linux-2.6.29.6/mm/slob.c 2009-07-02 19:41:20.000000000 -0400 | |
39395 | +++ linux-2.6.29.6/mm/slob.c 2009-07-09 22:13:40.000000000 -0400 | |
39396 | @@ -29,7 +29,7 @@ | |
39397 | * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls | |
39398 | * alloc_pages() directly, allocating compound pages so the page order | |
39399 | * does not have to be separately tracked, and also stores the exact | |
39400 | - * allocation size in page->private so that it can be used to accurately | |
39401 | + * allocation size in slob_page->size so that it can be used to accurately | |
39402 | * provide ksize(). These objects are detected in kfree() because slob_page() | |
39403 | * is false for them. | |
39404 | * | |
39405 | @@ -58,6 +58,7 @@ | |
39406 | */ | |
39407 | ||
39408 | #include <linux/kernel.h> | |
39409 | +#include <linux/sched.h> | |
39410 | #include <linux/slab.h> | |
39411 | #include <linux/mm.h> | |
39412 | #include <linux/cache.h> | |
39413 | @@ -97,7 +98,8 @@ struct slob_page { | |
39414 | unsigned long flags; /* mandatory */ | |
39415 | atomic_t _count; /* mandatory */ | |
39416 | slobidx_t units; /* free units left in page */ | |
39417 | - unsigned long pad[2]; | |
39418 | + unsigned long pad[1]; | |
39419 | + unsigned long size; /* size when >=PAGE_SIZE */ | |
39420 | slob_t *free; /* first free slob_t in page */ | |
39421 | struct list_head list; /* linked list of free pages */ | |
39422 | }; | |
39423 | @@ -130,7 +132,7 @@ static LIST_HEAD(free_slob_large); | |
39424 | */ | |
39425 | static inline int slob_page(struct slob_page *sp) | |
39426 | { | |
39427 | - return PageSlobPage((struct page *)sp); | |
39428 | + return PageSlobPage((struct page *)sp) && !sp->size; | |
39429 | } | |
39430 | ||
39431 | static inline void set_slob_page(struct slob_page *sp) | |
39432 | @@ -200,7 +202,7 @@ static void set_slob(slob_t *s, slobidx_ | |
39433 | /* | |
39434 | * Return the size of a slob block. | |
39435 | */ | |
39436 | -static slobidx_t slob_units(slob_t *s) | |
39437 | +static slobidx_t slob_units(const slob_t *s) | |
39438 | { | |
39439 | if (s->units > 0) | |
39440 | return s->units; | |
39441 | @@ -210,7 +212,7 @@ static slobidx_t slob_units(slob_t *s) | |
39442 | /* | |
39443 | * Return the next free slob block pointer after this one. | |
39444 | */ | |
39445 | -static slob_t *slob_next(slob_t *s) | |
39446 | +static slob_t *slob_next(const slob_t *s) | |
39447 | { | |
39448 | slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK); | |
39449 | slobidx_t next; | |
39450 | @@ -225,7 +227,7 @@ static slob_t *slob_next(slob_t *s) | |
39451 | /* | |
39452 | * Returns true if s is the last free block in its page. | |
39453 | */ | |
39454 | -static int slob_last(slob_t *s) | |
39455 | +static int slob_last(const slob_t *s) | |
39456 | { | |
39457 | return !((unsigned long)slob_next(s) & ~PAGE_MASK); | |
39458 | } | |
39459 | @@ -244,6 +246,7 @@ static void *slob_new_page(gfp_t gfp, in | |
39460 | if (!page) | |
39461 | return NULL; | |
39462 | ||
39463 | + set_slob_page(page); | |
39464 | return page_address(page); | |
39465 | } | |
39466 | ||
39467 | @@ -353,11 +356,11 @@ static void *slob_alloc(size_t size, gfp | |
39468 | if (!b) | |
39469 | return 0; | |
39470 | sp = (struct slob_page *)virt_to_page(b); | |
39471 | - set_slob_page(sp); | |
39472 | ||
39473 | spin_lock_irqsave(&slob_lock, flags); | |
39474 | sp->units = SLOB_UNITS(PAGE_SIZE); | |
39475 | sp->free = b; | |
39476 | + sp->size = 0; | |
39477 | INIT_LIST_HEAD(&sp->list); | |
39478 | set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE)); | |
39479 | set_slob_page_free(sp, slob_list); | |
39480 | @@ -459,10 +462,9 @@ out: | |
39481 | #define ARCH_SLAB_MINALIGN __alignof__(unsigned long) | |
39482 | #endif | |
39483 | ||
39484 | -void *__kmalloc_node(size_t size, gfp_t gfp, int node) | |
39485 | +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align) | |
39486 | { | |
39487 | - unsigned int *m; | |
39488 | - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); | |
39489 | + slob_t *m; | |
39490 | ||
39491 | if (size < PAGE_SIZE - align) { | |
39492 | if (!size) | |
39493 | @@ -471,20 +473,30 @@ void *__kmalloc_node(size_t size, gfp_t | |
39494 | m = slob_alloc(size + align, gfp, align, node); | |
39495 | if (!m) | |
39496 | return NULL; | |
39497 | - *m = size; | |
39498 | + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT); | |
39499 | + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT); | |
39500 | + m[0].units = size; | |
39501 | + m[1].units = align; | |
39502 | return (void *)m + align; | |
39503 | } else { | |
39504 | void *ret; | |
39505 | ||
39506 | ret = slob_new_page(gfp | __GFP_COMP, get_order(size), node); | |
39507 | if (ret) { | |
39508 | - struct page *page; | |
39509 | - page = virt_to_page(ret); | |
39510 | - page->private = size; | |
39511 | + struct slob_page *sp; | |
39512 | + sp = (struct slob_page *)virt_to_head_page(ret); | |
39513 | + sp->size = size; | |
39514 | } | |
39515 | return ret; | |
39516 | } | |
39517 | } | |
39518 | + | |
39519 | +void *__kmalloc_node(size_t size, gfp_t gfp, int node) | |
39520 | +{ | |
39521 | + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); | |
39522 | + | |
39523 | + return __kmalloc_node_align(size, gfp, node, align); | |
39524 | +} | |
39525 | EXPORT_SYMBOL(__kmalloc_node); | |
39526 | ||
39527 | void kfree(const void *block) | |
39528 | @@ -497,13 +509,81 @@ void kfree(const void *block) | |
39529 | sp = (struct slob_page *)virt_to_page(block); | |
39530 | if (slob_page(sp)) { | |
39531 | int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); | |
39532 | - unsigned int *m = (unsigned int *)(block - align); | |
39533 | - slob_free(m, *m + align); | |
39534 | - } else | |
39535 | + slob_t *m = (slob_t *)(block - align); | |
39536 | + slob_free(m, m[0].units + align); | |
39537 | + } else { | |
39538 | + clear_slob_page(sp); | |
39539 | + free_slob_page(sp); | |
39540 | + sp->size = 0; | |
39541 | put_page(&sp->page); | |
39542 | + } | |
39543 | } | |
39544 | EXPORT_SYMBOL(kfree); | |
39545 | ||
39546 | +void check_object_size(const void *ptr, unsigned long n, bool to) | |
39547 | +{ | |
39548 | + | |
39549 | +#ifdef CONFIG_PAX_USERCOPY | |
39550 | + struct slob_page *sp; | |
39551 | + const slob_t *free; | |
39552 | + const void *base; | |
39553 | + | |
39554 | + if (!n) | |
39555 | + return; | |
39556 | + | |
39557 | + if (ZERO_OR_NULL_PTR(ptr)) | |
39558 | + goto report; | |
39559 | + | |
39560 | + if (!virt_addr_valid(ptr)) | |
39561 | + return; | |
39562 | + | |
39563 | + sp = (struct slob_page *)virt_to_head_page(ptr); | |
39564 | + if (!PageSlobPage((struct page*)sp)) | |
39565 | + return; | |
39566 | + | |
39567 | + if (sp->size) { | |
39568 | + base = page_address(&sp->page); | |
39569 | + if (base <= ptr && n <= sp->size - (ptr - base)) | |
39570 | + return; | |
39571 | + goto report; | |
39572 | + } | |
39573 | + | |
39574 | + /* some tricky double walking to find the chunk */ | |
39575 | + base = (void *)((unsigned long)ptr & PAGE_MASK); | |
39576 | + free = sp->free; | |
39577 | + | |
39578 | + while (!slob_last(free) && (void *)free <= ptr) { | |
39579 | + base = free + slob_units(free); | |
39580 | + free = slob_next(free); | |
39581 | + } | |
39582 | + | |
39583 | + while (base < (void *)free) { | |
39584 | + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units; | |
39585 | + int size = SLOB_UNIT * SLOB_UNITS(m + align); | |
39586 | + int offset; | |
39587 | + | |
39588 | + if (ptr < base + align) | |
39589 | + goto report; | |
39590 | + | |
39591 | + offset = ptr - base - align; | |
39592 | + if (offset < m) { | |
39593 | + if (n <= m - offset) | |
39594 | + return; | |
39595 | + goto report; | |
39596 | + } | |
39597 | + base += size; | |
39598 | + } | |
39599 | + | |
39600 | +report: | |
39601 | + if (to) | |
39602 | + pax_report_leak_to_user(ptr, n); | |
39603 | + else | |
39604 | + pax_report_overflow_from_user(ptr, n); | |
39605 | +#endif | |
39606 | + | |
39607 | +} | |
39608 | +EXPORT_SYMBOL(check_object_size); | |
39609 | + | |
39610 | /* can't use ksize for kmem_cache_alloc memory, only kmalloc */ | |
39611 | size_t ksize(const void *block) | |
39612 | { | |
39613 | @@ -516,10 +596,10 @@ size_t ksize(const void *block) | |
39614 | sp = (struct slob_page *)virt_to_page(block); | |
39615 | if (slob_page(sp)) { | |
39616 | int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); | |
39617 | - unsigned int *m = (unsigned int *)(block - align); | |
39618 | - return SLOB_UNITS(*m) * SLOB_UNIT; | |
39619 | + slob_t *m = (slob_t *)(block - align); | |
39620 | + return SLOB_UNITS(m[0].units) * SLOB_UNIT; | |
39621 | } else | |
39622 | - return sp->page.private; | |
39623 | + return sp->size; | |
39624 | } | |
39625 | EXPORT_SYMBOL(ksize); | |
39626 | ||
39627 | @@ -570,10 +650,19 @@ void *kmem_cache_alloc_node(struct kmem_ | |
39628 | { | |
39629 | void *b; | |
39630 | ||
39631 | +#ifdef CONFIG_PAX_USERCOPY | |
39632 | + b = __kmalloc_node_align(c->size, flags, node, c->align); | |
39633 | +#else | |
39634 | if (c->size < PAGE_SIZE) | |
39635 | b = slob_alloc(c->size, flags, c->align, node); | |
39636 | - else | |
39637 | + else { | |
39638 | + struct slob_page *sp; | |
39639 | + | |
39640 | b = slob_new_page(flags, get_order(c->size), node); | |
39641 | + sp = (struct slob_page *)virt_to_head_page(b); | |
39642 | + sp->size = c->size; | |
39643 | + } | |
39644 | +#endif | |
39645 | ||
39646 | if (c->ctor) | |
39647 | c->ctor(b); | |
39648 | @@ -584,10 +673,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node); | |
39649 | ||
39650 | static void __kmem_cache_free(void *b, int size) | |
39651 | { | |
39652 | - if (size < PAGE_SIZE) | |
39653 | + struct slob_page *sp = (struct slob_page *)virt_to_head_page(b); | |
39654 | + | |
39655 | + if (slob_page(sp)) | |
39656 | slob_free(b, size); | |
39657 | - else | |
39658 | + else { | |
39659 | + clear_slob_page(sp); | |
39660 | + free_slob_page(sp); | |
39661 | + sp->size = 0; | |
39662 | free_pages((unsigned long)b, get_order(size)); | |
39663 | + } | |
39664 | } | |
39665 | ||
39666 | static void kmem_rcu_free(struct rcu_head *head) | |
39667 | @@ -600,14 +695,23 @@ static void kmem_rcu_free(struct rcu_hea | |
39668 | ||
39669 | void kmem_cache_free(struct kmem_cache *c, void *b) | |
39670 | { | |
39671 | + int size = c->size; | |
39672 | + | |
39673 | +#ifdef CONFIG_PAX_USERCOPY | |
39674 | + if (size + c->align < PAGE_SIZE) { | |
39675 | + size += c->align; | |
39676 | + b -= c->align; | |
39677 | + } | |
39678 | +#endif | |
39679 | + | |
39680 | if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) { | |
39681 | struct slob_rcu *slob_rcu; | |
39682 | - slob_rcu = b + (c->size - sizeof(struct slob_rcu)); | |
39683 | + slob_rcu = b + (size - sizeof(struct slob_rcu)); | |
39684 | INIT_RCU_HEAD(&slob_rcu->head); | |
39685 | - slob_rcu->size = c->size; | |
39686 | + slob_rcu->size = size; | |
39687 | call_rcu(&slob_rcu->head, kmem_rcu_free); | |
39688 | } else { | |
39689 | - __kmem_cache_free(b, c->size); | |
39690 | + __kmem_cache_free(b, size); | |
39691 | } | |
39692 | } | |
39693 | EXPORT_SYMBOL(kmem_cache_free); | |
39694 | diff -urNp linux-2.6.29.6/mm/slub.c linux-2.6.29.6/mm/slub.c | |
39695 | --- linux-2.6.29.6/mm/slub.c 2009-07-02 19:41:20.000000000 -0400 | |
39696 | +++ linux-2.6.29.6/mm/slub.c 2009-07-09 22:13:40.000000000 -0400 | |
39697 | @@ -1786,7 +1786,7 @@ static int slub_min_objects; | |
39698 | * Merge control. If this is set then no merging of slab caches will occur. | |
39699 | * (Could be removed. This was introduced to pacify the merge skeptics.) | |
39700 | */ | |
39701 | -static int slub_nomerge; | |
39702 | +static int slub_nomerge = 1; | |
39703 | ||
39704 | /* | |
39705 | * Calculate the order of allocation given an slab object size. | |
39706 | @@ -2322,7 +2322,7 @@ static int kmem_cache_open(struct kmem_c | |
2380c486 JR |
39707 | if (!calculate_sizes(s, -1)) |
39708 | goto error; | |
39709 | ||
39710 | - s->refcount = 1; | |
39711 | + atomic_set(&s->refcount, 1); | |
39712 | #ifdef CONFIG_NUMA | |
39713 | s->remote_node_defrag_ratio = 1000; | |
39714 | #endif | |
de855c5d | 39715 | @@ -2459,8 +2459,7 @@ static inline int kmem_cache_close(struc |
2380c486 JR |
39716 | void kmem_cache_destroy(struct kmem_cache *s) |
39717 | { | |
39718 | down_write(&slub_lock); | |
39719 | - s->refcount--; | |
39720 | - if (!s->refcount) { | |
39721 | + if (atomic_dec_and_test(&s->refcount)) { | |
39722 | list_del(&s->list); | |
39723 | up_write(&slub_lock); | |
39724 | if (kmem_cache_close(s)) { | |
de855c5d AM |
39725 | @@ -2702,6 +2701,44 @@ void *__kmalloc_node(size_t size, gfp_t |
39726 | EXPORT_SYMBOL(__kmalloc_node); | |
39727 | #endif | |
39728 | ||
39729 | +void check_object_size(const void *ptr, unsigned long n, bool to) | |
39730 | +{ | |
39731 | + | |
39732 | +#ifdef CONFIG_PAX_USERCOPY | |
39733 | + struct page *page; | |
39734 | + struct kmem_cache *s; | |
39735 | + unsigned long offset; | |
39736 | + | |
39737 | + if (!n) | |
39738 | + return; | |
39739 | + | |
39740 | + if (ZERO_OR_NULL_PTR(ptr)) | |
39741 | + goto report; | |
39742 | + | |
39743 | + if (!virt_addr_valid(ptr)) | |
39744 | + return; | |
39745 | + | |
39746 | + page = get_object_page(ptr); | |
39747 | + | |
39748 | + if (!page) | |
39749 | + /* TODO: check for stack based ptr */ | |
39750 | + return; | |
39751 | + | |
39752 | + s = page->slab; | |
39753 | + offset = (ptr - page_address(page)) % s->size; | |
39754 | + if (offset <= s->objsize && n <= s->objsize - offset) | |
39755 | + return; | |
39756 | + | |
39757 | +report: | |
39758 | + if (to) | |
39759 | + pax_report_leak_to_user(ptr, n); | |
39760 | + else | |
39761 | + pax_report_overflow_from_user(ptr, n); | |
39762 | +#endif | |
39763 | + | |
39764 | +} | |
39765 | +EXPORT_SYMBOL(check_object_size); | |
39766 | + | |
39767 | size_t ksize(const void *object) | |
39768 | { | |
39769 | struct page *page; | |
39770 | @@ -2970,7 +3007,7 @@ void __init kmem_cache_init(void) | |
2380c486 JR |
39771 | */ |
39772 | create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node", | |
39773 | sizeof(struct kmem_cache_node), GFP_KERNEL); | |
39774 | - kmalloc_caches[0].refcount = -1; | |
39775 | + atomic_set(&kmalloc_caches[0].refcount, -1); | |
39776 | caches++; | |
39777 | ||
39778 | hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI); | |
de855c5d | 39779 | @@ -3060,7 +3097,7 @@ static int slab_unmergeable(struct kmem_ |
2380c486 JR |
39780 | /* |
39781 | * We may have set a slab to be unmergeable during bootstrap. | |
39782 | */ | |
39783 | - if (s->refcount < 0) | |
39784 | + if (atomic_read(&s->refcount) < 0) | |
39785 | return 1; | |
39786 | ||
39787 | return 0; | |
de855c5d | 39788 | @@ -3117,7 +3154,7 @@ struct kmem_cache *kmem_cache_create(con |
2380c486 JR |
39789 | if (s) { |
39790 | int cpu; | |
39791 | ||
39792 | - s->refcount++; | |
39793 | + atomic_inc(&s->refcount); | |
39794 | /* | |
39795 | * Adjust the object sizes so that we clear | |
39796 | * the complete object on kzalloc. | |
de855c5d | 39797 | @@ -3136,7 +3173,7 @@ struct kmem_cache *kmem_cache_create(con |
2380c486 JR |
39798 | |
39799 | if (sysfs_slab_alias(s, name)) { | |
39800 | down_write(&slub_lock); | |
39801 | - s->refcount--; | |
39802 | + atomic_dec(&s->refcount); | |
39803 | up_write(&slub_lock); | |
39804 | goto err; | |
39805 | } | |
de855c5d | 39806 | @@ -3852,7 +3889,7 @@ SLAB_ATTR_RO(ctor); |
2380c486 JR |
39807 | |
39808 | static ssize_t aliases_show(struct kmem_cache *s, char *buf) | |
39809 | { | |
39810 | - return sprintf(buf, "%d\n", s->refcount - 1); | |
39811 | + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1); | |
39812 | } | |
39813 | SLAB_ATTR_RO(aliases); | |
39814 | ||
de855c5d | 39815 | @@ -4530,7 +4567,9 @@ static const struct file_operations proc |
2380c486 JR |
39816 | |
39817 | static int __init slab_proc_init(void) | |
39818 | { | |
39819 | +#if !defined(CONFIG_GRKERNSEC_PROC_ADD) | |
39820 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); | |
39821 | +#endif | |
39822 | return 0; | |
39823 | } | |
39824 | module_init(slab_proc_init); | |
de855c5d AM |
39825 | diff -urNp linux-2.6.29.6/mm/util.c linux-2.6.29.6/mm/util.c |
39826 | --- linux-2.6.29.6/mm/util.c 2009-07-02 19:41:20.000000000 -0400 | |
39827 | +++ linux-2.6.29.6/mm/util.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39828 | @@ -187,6 +187,12 @@ EXPORT_SYMBOL(strndup_user); |
39829 | void arch_pick_mmap_layout(struct mm_struct *mm) | |
39830 | { | |
39831 | mm->mmap_base = TASK_UNMAPPED_BASE; | |
39832 | + | |
39833 | +#ifdef CONFIG_PAX_RANDMMAP | |
39834 | + if (mm->pax_flags & MF_PAX_RANDMMAP) | |
39835 | + mm->mmap_base += mm->delta_mmap; | |
39836 | +#endif | |
39837 | + | |
39838 | mm->get_unmapped_area = arch_get_unmapped_area; | |
39839 | mm->unmap_area = arch_unmap_area; | |
39840 | } | |
de855c5d AM |
39841 | diff -urNp linux-2.6.29.6/mm/vmalloc.c linux-2.6.29.6/mm/vmalloc.c |
39842 | --- linux-2.6.29.6/mm/vmalloc.c 2009-07-02 19:41:20.000000000 -0400 | |
39843 | +++ linux-2.6.29.6/mm/vmalloc.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
39844 | @@ -90,6 +90,11 @@ static int vmap_pte_range(pmd_t *pmd, un |
39845 | unsigned long end, pgprot_t prot, struct page **pages, int *nr) | |
39846 | { | |
39847 | pte_t *pte; | |
39848 | + int ret = -ENOMEM; | |
39849 | + | |
39850 | +#ifdef CONFIG_PAX_KERNEXEC | |
39851 | + unsigned long cr0; | |
39852 | +#endif | |
39853 | ||
39854 | /* | |
39855 | * nr is a running index into the array which helps higher level | |
39856 | @@ -99,17 +104,33 @@ static int vmap_pte_range(pmd_t *pmd, un | |
39857 | pte = pte_alloc_kernel(pmd, addr); | |
39858 | if (!pte) | |
39859 | return -ENOMEM; | |
39860 | + | |
39861 | +#ifdef CONFIG_PAX_KERNEXEC | |
39862 | + pax_open_kernel(cr0); | |
39863 | +#endif | |
39864 | + | |
39865 | do { | |
39866 | struct page *page = pages[*nr]; | |
39867 | ||
39868 | - if (WARN_ON(!pte_none(*pte))) | |
39869 | - return -EBUSY; | |
39870 | - if (WARN_ON(!page)) | |
39871 | - return -ENOMEM; | |
39872 | + if (WARN_ON(!pte_none(*pte))) { | |
39873 | + ret = -EBUSY; | |
39874 | + goto out; | |
39875 | + } | |
39876 | + if (WARN_ON(!page)) { | |
39877 | + ret = -ENOMEM; | |
39878 | + goto out; | |
39879 | + } | |
39880 | set_pte_at(&init_mm, addr, pte, mk_pte(page, prot)); | |
39881 | (*nr)++; | |
39882 | } while (pte++, addr += PAGE_SIZE, addr != end); | |
39883 | - return 0; | |
39884 | + ret = 0; | |
39885 | +out: | |
39886 | + | |
39887 | +#ifdef CONFIG_PAX_KERNEXEC | |
39888 | + pax_close_kernel(cr0); | |
39889 | +#endif | |
39890 | + | |
39891 | + return ret; | |
39892 | } | |
39893 | ||
39894 | static int vmap_pmd_range(pud_t *pud, unsigned long addr, | |
39895 | @@ -1056,6 +1077,16 @@ static struct vm_struct *__get_vm_area_n | |
39896 | unsigned long align = 1; | |
39897 | ||
39898 | BUG_ON(in_interrupt()); | |
39899 | + | |
39900 | +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
39901 | + if (flags & VM_KERNEXEC) { | |
39902 | + if (start != VMALLOC_START || end != VMALLOC_END) | |
39903 | + return NULL; | |
39904 | + start = (unsigned long)MODULES_VADDR; | |
39905 | + end = (unsigned long)MODULES_END; | |
39906 | + } | |
39907 | +#endif | |
39908 | + | |
39909 | if (flags & VM_IOREMAP) { | |
39910 | int bit = fls(size); | |
39911 | ||
39912 | @@ -1289,6 +1320,11 @@ void *vmap(struct page **pages, unsigned | |
39913 | if (count > num_physpages) | |
39914 | return NULL; | |
39915 | ||
39916 | +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
39917 | + if (!(pgprot_val(prot) & _PAGE_NX)) | |
39918 | + flags |= VM_KERNEXEC; | |
39919 | +#endif | |
39920 | + | |
39921 | area = get_vm_area_caller((count << PAGE_SHIFT), flags, | |
39922 | __builtin_return_address(0)); | |
39923 | if (!area) | |
39924 | @@ -1385,6 +1421,13 @@ static void *__vmalloc_node(unsigned lon | |
39925 | if (!size || (size >> PAGE_SHIFT) > num_physpages) | |
39926 | return NULL; | |
39927 | ||
39928 | +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC) | |
39929 | + if (!(pgprot_val(prot) & _PAGE_NX)) | |
39930 | + area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END, | |
39931 | + node, gfp_mask, caller); | |
39932 | + else | |
39933 | +#endif | |
39934 | + | |
39935 | area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END, | |
39936 | node, gfp_mask, caller); | |
39937 | ||
de855c5d AM |
39938 | @@ -1394,6 +1437,7 @@ static void *__vmalloc_node(unsigned lon |
39939 | return __vmalloc_area_node(area, gfp_mask, prot, node, caller); | |
39940 | } | |
2380c486 | 39941 | |
de855c5d AM |
39942 | +#undef __vmalloc |
39943 | void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) | |
39944 | { | |
39945 | return __vmalloc_node(size, gfp_mask, prot, -1, | |
39946 | @@ -1410,6 +1454,7 @@ EXPORT_SYMBOL(__vmalloc); | |
39947 | * For tight control over page level allocator and protection flags | |
39948 | * use __vmalloc() instead. | |
39949 | */ | |
39950 | +#undef vmalloc | |
39951 | void *vmalloc(unsigned long size) | |
39952 | { | |
39953 | return __vmalloc_node(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL, | |
39954 | @@ -1424,6 +1469,7 @@ EXPORT_SYMBOL(vmalloc); | |
39955 | * The resulting memory area is zeroed so it can be mapped to userspace | |
39956 | * without leaking data. | |
39957 | */ | |
39958 | +#undef vmalloc_user | |
39959 | void *vmalloc_user(unsigned long size) | |
39960 | { | |
39961 | struct vm_struct *area; | |
39962 | @@ -1450,6 +1496,7 @@ EXPORT_SYMBOL(vmalloc_user); | |
39963 | * For tight control over page level allocator and protection flags | |
39964 | * use __vmalloc() instead. | |
39965 | */ | |
39966 | +#undef vmalloc_node | |
39967 | void *vmalloc_node(unsigned long size, int node) | |
39968 | { | |
39969 | return __vmalloc_node(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL, | |
39970 | @@ -1472,10 +1519,10 @@ EXPORT_SYMBOL(vmalloc_node); | |
39971 | * For tight control over page level allocator and protection flags | |
39972 | * use __vmalloc() instead. | |
39973 | */ | |
39974 | - | |
39975 | +#undef vmalloc_exec | |
2380c486 JR |
39976 | void *vmalloc_exec(unsigned long size) |
39977 | { | |
39978 | - return __vmalloc_node(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC, | |
39979 | + return __vmalloc_node(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC, | |
39980 | -1, __builtin_return_address(0)); | |
39981 | } | |
39982 | ||
de855c5d AM |
39983 | @@ -1494,6 +1541,7 @@ void *vmalloc_exec(unsigned long size) |
39984 | * Allocate enough 32bit PA addressable pages to cover @size from the | |
39985 | * page level allocator and map them into contiguous kernel virtual space. | |
39986 | */ | |
39987 | +#undef vmalloc_32 | |
39988 | void *vmalloc_32(unsigned long size) | |
39989 | { | |
39990 | return __vmalloc_node(size, GFP_VMALLOC32, PAGE_KERNEL, | |
39991 | @@ -1508,6 +1556,7 @@ EXPORT_SYMBOL(vmalloc_32); | |
39992 | * The resulting memory area is 32bit addressable and zeroed so it can be | |
39993 | * mapped to userspace without leaking data. | |
39994 | */ | |
39995 | +#undef vmalloc_32_user | |
39996 | void *vmalloc_32_user(unsigned long size) | |
39997 | { | |
39998 | struct vm_struct *area; | |
39999 | diff -urNp linux-2.6.29.6/net/atm/atm_misc.c linux-2.6.29.6/net/atm/atm_misc.c | |
40000 | --- linux-2.6.29.6/net/atm/atm_misc.c 2009-07-02 19:41:20.000000000 -0400 | |
40001 | +++ linux-2.6.29.6/net/atm/atm_misc.c 2009-07-09 22:13:40.000000000 -0400 | |
40002 | @@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int t | |
40003 | if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf) | |
40004 | return 1; | |
40005 | atm_return(vcc,truesize); | |
40006 | - atomic_inc(&vcc->stats->rx_drop); | |
40007 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
40008 | return 0; | |
40009 | } | |
40010 | ||
40011 | @@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct | |
40012 | } | |
40013 | } | |
40014 | atm_return(vcc,guess); | |
40015 | - atomic_inc(&vcc->stats->rx_drop); | |
40016 | + atomic_inc_unchecked(&vcc->stats->rx_drop); | |
40017 | return NULL; | |
40018 | } | |
40019 | ||
40020 | diff -urNp linux-2.6.29.6/net/atm/resources.c linux-2.6.29.6/net/atm/resources.c | |
40021 | --- linux-2.6.29.6/net/atm/resources.c 2009-07-02 19:41:20.000000000 -0400 | |
40022 | +++ linux-2.6.29.6/net/atm/resources.c 2009-07-09 22:13:40.000000000 -0400 | |
40023 | @@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_ | |
40024 | static void subtract_aal_stats(struct k_atm_aal_stats *from, | |
40025 | struct atm_aal_stats *to) | |
40026 | { | |
40027 | -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i) | |
40028 | +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i) | |
40029 | __AAL_STAT_ITEMS | |
40030 | #undef __HANDLE_ITEM | |
40031 | } | |
40032 | diff -urNp linux-2.6.29.6/net/bridge/br_stp_if.c linux-2.6.29.6/net/bridge/br_stp_if.c | |
40033 | --- linux-2.6.29.6/net/bridge/br_stp_if.c 2009-07-02 19:41:20.000000000 -0400 | |
40034 | +++ linux-2.6.29.6/net/bridge/br_stp_if.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40035 | @@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg |
40036 | char *envp[] = { NULL }; | |
40037 | ||
40038 | if (br->stp_enabled == BR_USER_STP) { | |
40039 | - r = call_usermodehelper(BR_STP_PROG, argv, envp, 1); | |
40040 | + r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC); | |
40041 | printk(KERN_INFO "%s: userspace STP stopped, return code %d\n", | |
40042 | br->dev->name, r); | |
40043 | ||
de855c5d AM |
40044 | diff -urNp linux-2.6.29.6/net/core/flow.c linux-2.6.29.6/net/core/flow.c |
40045 | --- linux-2.6.29.6/net/core/flow.c 2009-07-02 19:41:20.000000000 -0400 | |
40046 | +++ linux-2.6.29.6/net/core/flow.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40047 | @@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT( |
40048 | ||
40049 | static u32 flow_hash_shift; | |
40050 | #define flow_hash_size (1 << flow_hash_shift) | |
40051 | -static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL }; | |
40052 | +static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables); | |
40053 | ||
40054 | #define flow_table(cpu) (per_cpu(flow_tables, cpu)) | |
40055 | ||
40056 | @@ -52,7 +52,7 @@ struct flow_percpu_info { | |
40057 | u32 hash_rnd; | |
40058 | int count; | |
40059 | }; | |
40060 | -static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 }; | |
40061 | +static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info); | |
40062 | ||
40063 | #define flow_hash_rnd_recalc(cpu) \ | |
40064 | (per_cpu(flow_hash_info, cpu).hash_rnd_recalc) | |
40065 | @@ -69,7 +69,7 @@ struct flow_flush_info { | |
40066 | atomic_t cpuleft; | |
40067 | struct completion completion; | |
40068 | }; | |
40069 | -static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL }; | |
40070 | +static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets); | |
40071 | ||
40072 | #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu)) | |
40073 | ||
de855c5d AM |
40074 | diff -urNp linux-2.6.29.6/net/dccp/ccids/ccid3.c linux-2.6.29.6/net/dccp/ccids/ccid3.c |
40075 | --- linux-2.6.29.6/net/dccp/ccids/ccid3.c 2009-07-02 19:41:20.000000000 -0400 | |
40076 | +++ linux-2.6.29.6/net/dccp/ccids/ccid3.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40077 | @@ -43,7 +43,7 @@ |
40078 | static int ccid3_debug; | |
40079 | #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a) | |
40080 | #else | |
40081 | -#define ccid3_pr_debug(format, a...) | |
40082 | +#define ccid3_pr_debug(format, a...) do {} while (0) | |
40083 | #endif | |
40084 | ||
40085 | /* | |
de855c5d AM |
40086 | diff -urNp linux-2.6.29.6/net/dccp/dccp.h linux-2.6.29.6/net/dccp/dccp.h |
40087 | --- linux-2.6.29.6/net/dccp/dccp.h 2009-07-02 19:41:20.000000000 -0400 | |
40088 | +++ linux-2.6.29.6/net/dccp/dccp.h 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40089 | @@ -43,8 +43,8 @@ extern int dccp_debug; |
40090 | #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a) | |
40091 | #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a) | |
40092 | #else | |
40093 | -#define dccp_pr_debug(format, a...) | |
40094 | -#define dccp_pr_debug_cat(format, a...) | |
40095 | +#define dccp_pr_debug(format, a...) do {} while (0) | |
40096 | +#define dccp_pr_debug_cat(format, a...) do {} while (0) | |
40097 | #endif | |
40098 | ||
40099 | extern struct inet_hashinfo dccp_hashinfo; | |
de855c5d AM |
40100 | diff -urNp linux-2.6.29.6/net/ipv4/inet_connection_sock.c linux-2.6.29.6/net/ipv4/inet_connection_sock.c |
40101 | --- linux-2.6.29.6/net/ipv4/inet_connection_sock.c 2009-07-02 19:41:20.000000000 -0400 | |
40102 | +++ linux-2.6.29.6/net/ipv4/inet_connection_sock.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40103 | @@ -15,6 +15,7 @@ |
40104 | ||
40105 | #include <linux/module.h> | |
40106 | #include <linux/jhash.h> | |
40107 | +#include <linux/security.h> | |
40108 | ||
40109 | #include <net/inet_connection_sock.h> | |
40110 | #include <net/inet_hashtables.h> | |
de855c5d AM |
40111 | diff -urNp linux-2.6.29.6/net/ipv4/inet_hashtables.c linux-2.6.29.6/net/ipv4/inet_hashtables.c |
40112 | --- linux-2.6.29.6/net/ipv4/inet_hashtables.c 2009-07-02 19:41:20.000000000 -0400 | |
40113 | +++ linux-2.6.29.6/net/ipv4/inet_hashtables.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 | 40114 | @@ -18,11 +18,14 @@ |
de855c5d | 40115 | #include <linux/sched.h> |
2380c486 JR |
40116 | #include <linux/slab.h> |
40117 | #include <linux/wait.h> | |
40118 | +#include <linux/security.h> | |
40119 | ||
40120 | #include <net/inet_connection_sock.h> | |
40121 | #include <net/inet_hashtables.h> | |
2380c486 JR |
40122 | #include <net/ip.h> |
40123 | ||
40124 | +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet); | |
40125 | + | |
40126 | /* | |
40127 | * Allocate and initialize a new local port bind bucket. | |
40128 | * The bindhash mutex for snum's hash chain must be held here. | |
40129 | @@ -481,6 +484,8 @@ ok: | |
40130 | } | |
40131 | spin_unlock(&head->lock); | |
40132 | ||
40133 | + gr_update_task_in_ip_table(current, inet_sk(sk)); | |
40134 | + | |
40135 | if (tw) { | |
40136 | inet_twsk_deschedule(tw, death_row); | |
40137 | inet_twsk_put(tw); | |
de855c5d AM |
40138 | diff -urNp linux-2.6.29.6/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.29.6/net/ipv4/netfilter/nf_nat_snmp_basic.c |
40139 | --- linux-2.6.29.6/net/ipv4/netfilter/nf_nat_snmp_basic.c 2009-07-02 19:41:20.000000000 -0400 | |
40140 | +++ linux-2.6.29.6/net/ipv4/netfilter/nf_nat_snmp_basic.c 2009-07-09 22:13:40.000000000 -0400 | |
40141 | @@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode( | |
40142 | ||
40143 | *len = 0; | |
40144 | ||
40145 | - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC); | |
40146 | + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC); | |
40147 | if (*octets == NULL) { | |
40148 | if (net_ratelimit()) | |
40149 | printk("OOM in bsalg (%d)\n", __LINE__); | |
40150 | diff -urNp linux-2.6.29.6/net/ipv4/tcp_ipv4.c linux-2.6.29.6/net/ipv4/tcp_ipv4.c | |
40151 | --- linux-2.6.29.6/net/ipv4/tcp_ipv4.c 2009-07-02 19:41:20.000000000 -0400 | |
40152 | +++ linux-2.6.29.6/net/ipv4/tcp_ipv4.c 2009-07-09 22:13:40.000000000 -0400 | |
40153 | @@ -1512,6 +1512,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc | |
40154 | return 0; | |
2380c486 | 40155 | |
de855c5d AM |
40156 | reset: |
40157 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40158 | + if (!skb->dev || (skb->dev->flags & IFF_LOOPBACK)) | |
40159 | +#endif | |
40160 | tcp_v4_send_reset(rsk, skb); | |
40161 | discard: | |
40162 | kfree_skb(skb); | |
40163 | @@ -1620,6 +1623,9 @@ no_tcp_socket: | |
40164 | bad_packet: | |
40165 | TCP_INC_STATS_BH(net, TCP_MIB_INERRS); | |
40166 | } else { | |
40167 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40168 | + if (skb->dev->flags & IFF_LOOPBACK) | |
40169 | +#endif | |
40170 | tcp_v4_send_reset(NULL, skb); | |
40171 | } | |
2380c486 | 40172 | |
de855c5d AM |
40173 | diff -urNp linux-2.6.29.6/net/ipv4/tcp_minisocks.c linux-2.6.29.6/net/ipv4/tcp_minisocks.c |
40174 | --- linux-2.6.29.6/net/ipv4/tcp_minisocks.c 2009-07-02 19:41:20.000000000 -0400 | |
40175 | +++ linux-2.6.29.6/net/ipv4/tcp_minisocks.c 2009-07-09 22:13:40.000000000 -0400 | |
40176 | @@ -695,8 +695,11 @@ listen_overflow: | |
40177 | ||
40178 | embryonic_reset: | |
40179 | NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS); | |
40180 | + | |
40181 | +#ifndef CONFIG_GRKERNSEC_BLACKHOLE | |
40182 | if (!(flg & TCP_FLAG_RST)) | |
40183 | req->rsk_ops->send_reset(sk, skb); | |
40184 | +#endif | |
40185 | ||
40186 | inet_csk_reqsk_queue_drop(sk, req, prev); | |
40187 | return NULL; | |
40188 | diff -urNp linux-2.6.29.6/net/ipv4/udp.c linux-2.6.29.6/net/ipv4/udp.c | |
40189 | --- linux-2.6.29.6/net/ipv4/udp.c 2009-07-02 19:41:20.000000000 -0400 | |
40190 | +++ linux-2.6.29.6/net/ipv4/udp.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40191 | @@ -86,6 +86,7 @@ |
40192 | #include <linux/types.h> | |
40193 | #include <linux/fcntl.h> | |
40194 | #include <linux/module.h> | |
40195 | +#include <linux/security.h> | |
40196 | #include <linux/socket.h> | |
40197 | #include <linux/sockios.h> | |
40198 | #include <linux/igmp.h> | |
40199 | @@ -369,6 +370,9 @@ found: | |
40200 | return s; | |
40201 | } | |
40202 | ||
40203 | +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb); | |
40204 | +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr); | |
40205 | + | |
40206 | /* | |
40207 | * This routine is called by the ICMP module when it gets some | |
40208 | * sort of error condition. If err < 0 then the socket should | |
40209 | @@ -630,9 +634,18 @@ int udp_sendmsg(struct kiocb *iocb, stru | |
40210 | dport = usin->sin_port; | |
40211 | if (dport == 0) | |
40212 | return -EINVAL; | |
40213 | + | |
40214 | + err = gr_search_udp_sendmsg(sk, usin); | |
40215 | + if (err) | |
40216 | + return err; | |
40217 | } else { | |
40218 | if (sk->sk_state != TCP_ESTABLISHED) | |
40219 | return -EDESTADDRREQ; | |
40220 | + | |
40221 | + err = gr_search_udp_sendmsg(sk, NULL); | |
40222 | + if (err) | |
40223 | + return err; | |
40224 | + | |
40225 | daddr = inet->daddr; | |
40226 | dport = inet->dport; | |
40227 | /* Open fast path for connected socket. | |
40228 | @@ -898,6 +911,10 @@ try_again: | |
40229 | if (!skb) | |
40230 | goto out; | |
40231 | ||
40232 | + err = gr_search_udp_recvmsg(sk, skb); | |
40233 | + if (err) | |
40234 | + goto out_free; | |
40235 | + | |
40236 | ulen = skb->len - sizeof(struct udphdr); | |
40237 | copied = len; | |
40238 | if (copied > ulen) | |
de855c5d AM |
40239 | @@ -1288,6 +1305,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, |
40240 | goto csum_error; | |
40241 | ||
40242 | UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE); | |
40243 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40244 | + if (skb->dev->flags & IFF_LOOPBACK) | |
40245 | +#endif | |
40246 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); | |
40247 | ||
40248 | /* | |
40249 | diff -urNp linux-2.6.29.6/net/ipv6/exthdrs.c linux-2.6.29.6/net/ipv6/exthdrs.c | |
40250 | --- linux-2.6.29.6/net/ipv6/exthdrs.c 2009-07-02 19:41:20.000000000 -0400 | |
40251 | +++ linux-2.6.29.6/net/ipv6/exthdrs.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40252 | @@ -630,7 +630,7 @@ static struct tlvtype_proc tlvprochopopt |
40253 | .type = IPV6_TLV_JUMBO, | |
40254 | .func = ipv6_hop_jumbo, | |
40255 | }, | |
40256 | - { -1, } | |
40257 | + { -1, NULL } | |
40258 | }; | |
40259 | ||
40260 | int ipv6_parse_hopopts(struct sk_buff *skb) | |
de855c5d AM |
40261 | diff -urNp linux-2.6.29.6/net/ipv6/raw.c linux-2.6.29.6/net/ipv6/raw.c |
40262 | --- linux-2.6.29.6/net/ipv6/raw.c 2009-07-02 19:41:20.000000000 -0400 | |
40263 | +++ linux-2.6.29.6/net/ipv6/raw.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40264 | @@ -600,7 +600,7 @@ out: |
40265 | return err; | |
40266 | } | |
40267 | ||
40268 | -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, | |
40269 | +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length, | |
40270 | struct flowi *fl, struct rt6_info *rt, | |
40271 | unsigned int flags) | |
40272 | { | |
de855c5d AM |
40273 | diff -urNp linux-2.6.29.6/net/ipv6/tcp_ipv6.c linux-2.6.29.6/net/ipv6/tcp_ipv6.c |
40274 | --- linux-2.6.29.6/net/ipv6/tcp_ipv6.c 2009-07-02 19:41:20.000000000 -0400 | |
40275 | +++ linux-2.6.29.6/net/ipv6/tcp_ipv6.c 2009-07-09 22:13:40.000000000 -0400 | |
40276 | @@ -1576,6 +1576,9 @@ static int tcp_v6_do_rcv(struct sock *sk | |
40277 | return 0; | |
40278 | ||
40279 | reset: | |
40280 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40281 | + if (!skb->dev || (skb->dev->flags & IFF_LOOPBACK)) | |
40282 | +#endif | |
40283 | tcp_v6_send_reset(sk, skb); | |
40284 | discard: | |
40285 | if (opt_skb) | |
40286 | @@ -1699,6 +1702,9 @@ no_tcp_socket: | |
40287 | bad_packet: | |
40288 | TCP_INC_STATS_BH(net, TCP_MIB_INERRS); | |
40289 | } else { | |
40290 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40291 | + if (skb->dev->flags & IFF_LOOPBACK) | |
40292 | +#endif | |
40293 | tcp_v6_send_reset(NULL, skb); | |
40294 | } | |
40295 | ||
40296 | diff -urNp linux-2.6.29.6/net/ipv6/udp.c linux-2.6.29.6/net/ipv6/udp.c | |
40297 | --- linux-2.6.29.6/net/ipv6/udp.c 2009-07-02 19:41:20.000000000 -0400 | |
40298 | +++ linux-2.6.29.6/net/ipv6/udp.c 2009-07-09 22:13:40.000000000 -0400 | |
40299 | @@ -558,6 +558,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, | |
40300 | UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, | |
40301 | proto == IPPROTO_UDPLITE); | |
40302 | ||
40303 | +#ifdef CONFIG_GRKERNSEC_BLACKHOLE | |
40304 | + if (skb->dev->flags & IFF_LOOPBACK) | |
40305 | +#endif | |
40306 | icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev); | |
40307 | ||
40308 | kfree_skb(skb); | |
40309 | diff -urNp linux-2.6.29.6/net/mac80211/ieee80211_i.h linux-2.6.29.6/net/mac80211/ieee80211_i.h | |
40310 | --- linux-2.6.29.6/net/mac80211/ieee80211_i.h 2009-07-02 19:41:20.000000000 -0400 | |
40311 | +++ linux-2.6.29.6/net/mac80211/ieee80211_i.h 2009-07-09 22:13:40.000000000 -0400 | |
40312 | @@ -562,7 +562,7 @@ struct ieee80211_local { | |
40313 | unsigned long queue_stop_reasons[IEEE80211_MAX_QUEUES]; | |
40314 | spinlock_t queue_stop_reason_lock; | |
40315 | struct net_device *mdev; /* wmaster# - "master" 802.11 device */ | |
40316 | - int open_count; | |
40317 | + atomic_t open_count; | |
40318 | int monitors, cooked_mntrs; | |
40319 | /* number of interfaces with corresponding FIF_ flags */ | |
40320 | int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss; | |
40321 | diff -urNp linux-2.6.29.6/net/mac80211/iface.c linux-2.6.29.6/net/mac80211/iface.c | |
40322 | --- linux-2.6.29.6/net/mac80211/iface.c 2009-07-02 19:41:20.000000000 -0400 | |
40323 | +++ linux-2.6.29.6/net/mac80211/iface.c 2009-07-09 22:13:40.000000000 -0400 | |
40324 | @@ -146,7 +146,7 @@ static int ieee80211_open(struct net_dev | |
40325 | break; | |
40326 | } | |
40327 | ||
40328 | - if (local->open_count == 0) { | |
40329 | + if (atomic_read(&local->open_count) == 0) { | |
40330 | res = 0; | |
40331 | if (local->ops->start) | |
40332 | res = local->ops->start(local_to_hw(local)); | |
40333 | @@ -182,7 +182,7 @@ static int ieee80211_open(struct net_dev | |
40334 | * Validate the MAC address for this device. | |
40335 | */ | |
40336 | if (!is_valid_ether_addr(dev->dev_addr)) { | |
40337 | - if (!local->open_count && local->ops->stop) | |
40338 | + if (!atomic_read(&local->open_count) && local->ops->stop) | |
40339 | local->ops->stop(local_to_hw(local)); | |
40340 | return -EADDRNOTAVAIL; | |
40341 | } | |
40342 | @@ -267,7 +267,7 @@ static int ieee80211_open(struct net_dev | |
40343 | } | |
40344 | } | |
40345 | ||
40346 | - if (local->open_count == 0) { | |
40347 | + if (atomic_read(&local->open_count) == 0) { | |
40348 | res = dev_open(local->mdev); | |
40349 | WARN_ON(res); | |
40350 | if (res) | |
40351 | @@ -287,7 +287,7 @@ static int ieee80211_open(struct net_dev | |
40352 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
40353 | atomic_inc(&local->iff_promiscs); | |
40354 | ||
40355 | - local->open_count++; | |
40356 | + atomic_inc(&local->open_count); | |
40357 | if (hw_reconf_flags) { | |
40358 | ieee80211_hw_config(local, hw_reconf_flags); | |
40359 | /* | |
40360 | @@ -316,7 +316,7 @@ static int ieee80211_open(struct net_dev | |
40361 | err_del_interface: | |
40362 | local->ops->remove_interface(local_to_hw(local), &conf); | |
40363 | err_stop: | |
40364 | - if (!local->open_count && local->ops->stop) | |
40365 | + if (!atomic_read(&local->open_count) && local->ops->stop) | |
40366 | local->ops->stop(local_to_hw(local)); | |
40367 | err_del_bss: | |
40368 | sdata->bss = NULL; | |
40369 | @@ -401,7 +401,7 @@ static int ieee80211_stop(struct net_dev | |
40370 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | |
40371 | } | |
40372 | ||
40373 | - local->open_count--; | |
40374 | + atomic_dec(&local->open_count); | |
40375 | ||
40376 | switch (sdata->vif.type) { | |
40377 | case NL80211_IFTYPE_AP_VLAN: | |
40378 | @@ -514,7 +514,7 @@ static int ieee80211_stop(struct net_dev | |
40379 | ||
40380 | sdata->bss = NULL; | |
40381 | ||
40382 | - if (local->open_count == 0) { | |
40383 | + if (atomic_read(&local->open_count) == 0) { | |
40384 | if (netif_running(local->mdev)) | |
40385 | dev_close(local->mdev); | |
40386 | ||
40387 | diff -urNp linux-2.6.29.6/net/mac80211/main.c linux-2.6.29.6/net/mac80211/main.c | |
40388 | --- linux-2.6.29.6/net/mac80211/main.c 2009-07-02 19:41:20.000000000 -0400 | |
40389 | +++ linux-2.6.29.6/net/mac80211/main.c 2009-07-09 22:13:40.000000000 -0400 | |
40390 | @@ -233,7 +233,7 @@ int ieee80211_hw_config(struct ieee80211 | |
40391 | local->hw.conf.power_level = power; | |
40392 | } | |
40393 | ||
40394 | - if (changed && local->open_count) { | |
40395 | + if (changed && atomic_read(&local->open_count)) { | |
40396 | ret = local->ops->config(local_to_hw(local), changed); | |
40397 | /* | |
40398 | * Goal: | |
40399 | diff -urNp linux-2.6.29.6/net/mac80211/rate.c linux-2.6.29.6/net/mac80211/rate.c | |
40400 | --- linux-2.6.29.6/net/mac80211/rate.c 2009-07-02 19:41:20.000000000 -0400 | |
40401 | +++ linux-2.6.29.6/net/mac80211/rate.c 2009-07-09 22:13:40.000000000 -0400 | |
40402 | @@ -256,7 +256,7 @@ int ieee80211_init_rate_ctrl_alg(struct | |
40403 | struct rate_control_ref *ref, *old; | |
40404 | ||
40405 | ASSERT_RTNL(); | |
40406 | - if (local->open_count || netif_running(local->mdev)) | |
40407 | + if (atomic_read(&local->open_count) || netif_running(local->mdev)) | |
40408 | return -EBUSY; | |
40409 | ||
40410 | ref = rate_control_alloc(name, local); | |
40411 | diff -urNp linux-2.6.29.6/net/sctp/socket.c linux-2.6.29.6/net/sctp/socket.c | |
40412 | --- linux-2.6.29.6/net/sctp/socket.c 2009-07-02 19:41:20.000000000 -0400 | |
40413 | +++ linux-2.6.29.6/net/sctp/socket.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40414 | @@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc |
40415 | struct sctp_sndrcvinfo *sinfo; | |
40416 | struct sctp_initmsg *sinit; | |
40417 | sctp_assoc_t associd = 0; | |
40418 | - sctp_cmsgs_t cmsgs = { NULL }; | |
40419 | + sctp_cmsgs_t cmsgs = { NULL, NULL }; | |
40420 | int err; | |
40421 | sctp_scope_t scope; | |
40422 | long timeo; | |
40423 | @@ -5756,7 +5756,6 @@ pp_found: | |
40424 | */ | |
40425 | int reuse = sk->sk_reuse; | |
40426 | struct sock *sk2; | |
40427 | - struct hlist_node *node; | |
40428 | ||
40429 | SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n"); | |
40430 | if (pp->fastreuse && sk->sk_reuse && | |
de855c5d AM |
40431 | diff -urNp linux-2.6.29.6/net/socket.c linux-2.6.29.6/net/socket.c |
40432 | --- linux-2.6.29.6/net/socket.c 2009-07-02 19:41:20.000000000 -0400 | |
40433 | +++ linux-2.6.29.6/net/socket.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40434 | @@ -86,6 +86,7 @@ |
40435 | #include <linux/audit.h> | |
40436 | #include <linux/wireless.h> | |
40437 | #include <linux/nsproxy.h> | |
40438 | +#include <linux/in.h> | |
40439 | ||
40440 | #include <asm/uaccess.h> | |
40441 | #include <asm/unistd.h> | |
40442 | @@ -96,6 +97,21 @@ | |
40443 | #include <net/sock.h> | |
40444 | #include <linux/netfilter.h> | |
40445 | ||
40446 | +extern void gr_attach_curr_ip(const struct sock *sk); | |
40447 | +extern int gr_handle_sock_all(const int family, const int type, | |
40448 | + const int protocol); | |
40449 | +extern int gr_handle_sock_server(const struct sockaddr *sck); | |
40450 | +extern int gr_handle_sock_server_other(const struct socket *sck); | |
40451 | +extern int gr_handle_sock_client(const struct sockaddr *sck); | |
40452 | +extern int gr_search_connect(struct socket * sock, | |
40453 | + struct sockaddr_in * addr); | |
40454 | +extern int gr_search_bind(struct socket * sock, | |
40455 | + struct sockaddr_in * addr); | |
40456 | +extern int gr_search_listen(struct socket * sock); | |
40457 | +extern int gr_search_accept(struct socket * sock); | |
40458 | +extern int gr_search_socket(const int domain, const int type, | |
40459 | + const int protocol); | |
40460 | + | |
40461 | static int sock_no_open(struct inode *irrelevant, struct file *dontcare); | |
40462 | static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, | |
40463 | unsigned long nr_segs, loff_t pos); | |
40464 | @@ -299,7 +315,7 @@ static int sockfs_get_sb(struct file_sys | |
40465 | mnt); | |
40466 | } | |
40467 | ||
40468 | -static struct vfsmount *sock_mnt __read_mostly; | |
40469 | +struct vfsmount *sock_mnt __read_mostly; | |
40470 | ||
40471 | static struct file_system_type sock_fs_type = { | |
40472 | .name = "sockfs", | |
40473 | @@ -1234,6 +1250,16 @@ SYSCALL_DEFINE3(socket, int, family, int | |
40474 | if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) | |
40475 | flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; | |
40476 | ||
40477 | + if(!gr_search_socket(family, type, protocol)) { | |
40478 | + retval = -EACCES; | |
40479 | + goto out; | |
40480 | + } | |
40481 | + | |
40482 | + if (gr_handle_sock_all(family, type, protocol)) { | |
40483 | + retval = -EACCES; | |
40484 | + goto out; | |
40485 | + } | |
40486 | + | |
40487 | retval = sock_create(family, type, protocol, &sock); | |
40488 | if (retval < 0) | |
40489 | goto out; | |
40490 | @@ -1366,6 +1392,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so | |
40491 | if (sock) { | |
40492 | err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address); | |
40493 | if (err >= 0) { | |
40494 | + if (gr_handle_sock_server((struct sockaddr *)&address)) { | |
40495 | + err = -EACCES; | |
40496 | + goto error; | |
40497 | + } | |
40498 | + err = gr_search_bind(sock, (struct sockaddr_in *)&address); | |
40499 | + if (err) | |
40500 | + goto error; | |
40501 | + | |
40502 | err = security_socket_bind(sock, | |
40503 | (struct sockaddr *)&address, | |
40504 | addrlen); | |
40505 | @@ -1374,6 +1408,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so | |
40506 | (struct sockaddr *) | |
40507 | &address, addrlen); | |
40508 | } | |
40509 | +error: | |
40510 | fput_light(sock->file, fput_needed); | |
40511 | } | |
40512 | return err; | |
40513 | @@ -1397,10 +1432,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba | |
40514 | if ((unsigned)backlog > somaxconn) | |
40515 | backlog = somaxconn; | |
40516 | ||
40517 | + if (gr_handle_sock_server_other(sock)) { | |
40518 | + err = -EPERM; | |
40519 | + goto error; | |
40520 | + } | |
40521 | + | |
40522 | + err = gr_search_listen(sock); | |
40523 | + if (err) | |
40524 | + goto error; | |
40525 | + | |
40526 | err = security_socket_listen(sock, backlog); | |
40527 | if (!err) | |
40528 | err = sock->ops->listen(sock, backlog); | |
40529 | ||
40530 | +error: | |
40531 | fput_light(sock->file, fput_needed); | |
40532 | } | |
40533 | return err; | |
40534 | @@ -1443,6 +1488,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct | |
40535 | newsock->type = sock->type; | |
40536 | newsock->ops = sock->ops; | |
40537 | ||
40538 | + if (gr_handle_sock_server_other(sock)) { | |
40539 | + err = -EPERM; | |
40540 | + sock_release(newsock); | |
40541 | + goto out_put; | |
40542 | + } | |
40543 | + | |
40544 | + err = gr_search_accept(sock); | |
40545 | + if (err) { | |
40546 | + sock_release(newsock); | |
40547 | + goto out_put; | |
40548 | + } | |
40549 | + | |
40550 | /* | |
40551 | * We don't need try_module_get here, as the listening socket (sock) | |
40552 | * has the protocol module (sock->ops->owner) held. | |
40553 | @@ -1486,6 +1543,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct | |
40554 | err = newfd; | |
40555 | ||
40556 | security_socket_post_accept(sock, newsock); | |
40557 | + gr_attach_curr_ip(newsock->sk); | |
40558 | ||
40559 | out_put: | |
40560 | fput_light(sock->file, fput_needed); | |
40561 | @@ -1524,6 +1582,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct | |
40562 | int, addrlen) | |
40563 | { | |
40564 | struct socket *sock; | |
40565 | + struct sockaddr *sck; | |
40566 | struct sockaddr_storage address; | |
40567 | int err, fput_needed; | |
40568 | ||
40569 | @@ -1534,6 +1593,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct | |
40570 | if (err < 0) | |
40571 | goto out_put; | |
40572 | ||
40573 | + sck = (struct sockaddr *)&address; | |
40574 | + | |
40575 | + if (gr_handle_sock_client(sck)) { | |
40576 | + err = -EACCES; | |
40577 | + goto out_put; | |
40578 | + } | |
40579 | + | |
40580 | + err = gr_search_connect(sock, (struct sockaddr_in *)sck); | |
40581 | + if (err) | |
40582 | + goto out_put; | |
40583 | + | |
40584 | err = | |
40585 | security_socket_connect(sock, (struct sockaddr *)&address, addrlen); | |
40586 | if (err) | |
de855c5d AM |
40587 | diff -urNp linux-2.6.29.6/net/unix/af_unix.c linux-2.6.29.6/net/unix/af_unix.c |
40588 | --- linux-2.6.29.6/net/unix/af_unix.c 2009-07-02 19:41:20.000000000 -0400 | |
40589 | +++ linux-2.6.29.6/net/unix/af_unix.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40590 | @@ -734,6 +734,12 @@ static struct sock *unix_find_other(stru |
40591 | err = -ECONNREFUSED; | |
40592 | if (!S_ISSOCK(inode->i_mode)) | |
40593 | goto put_fail; | |
40594 | + | |
40595 | + if (!gr_acl_handle_unix(path.dentry, path.mnt)) { | |
40596 | + err = -EACCES; | |
40597 | + goto put_fail; | |
40598 | + } | |
40599 | + | |
40600 | u = unix_find_socket_byinode(net, inode); | |
40601 | if (!u) | |
40602 | goto put_fail; | |
40603 | @@ -754,6 +760,13 @@ static struct sock *unix_find_other(stru | |
40604 | if (u) { | |
40605 | struct dentry *dentry; | |
40606 | dentry = unix_sk(u)->dentry; | |
40607 | + | |
40608 | + if (!gr_handle_chroot_unix(u->sk_peercred.pid)) { | |
40609 | + err = -EPERM; | |
40610 | + sock_put(u); | |
40611 | + goto fail; | |
40612 | + } | |
40613 | + | |
40614 | if (dentry) | |
40615 | touch_atime(unix_sk(u)->mnt, dentry); | |
40616 | } else | |
40617 | @@ -839,11 +852,18 @@ static int unix_bind(struct socket *sock | |
40618 | err = security_path_mknod(&nd.path, dentry, mode, 0); | |
40619 | if (err) | |
40620 | goto out_mknod_drop_write; | |
40621 | + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) { | |
40622 | + err = -EACCES; | |
40623 | + goto out_mknod_drop_write; | |
40624 | + } | |
40625 | err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); | |
40626 | out_mknod_drop_write: | |
40627 | mnt_drop_write(nd.path.mnt); | |
40628 | if (err) | |
40629 | goto out_mknod_dput; | |
40630 | + | |
40631 | + gr_handle_create(dentry, nd.path.mnt); | |
40632 | + | |
40633 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); | |
40634 | dput(nd.path.dentry); | |
40635 | nd.path.dentry = dentry; | |
40636 | @@ -861,6 +881,10 @@ out_mknod_drop_write: | |
40637 | goto out_unlock; | |
40638 | } | |
40639 | ||
40640 | +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX | |
40641 | + sk->sk_peercred.pid = current->pid; | |
40642 | +#endif | |
40643 | + | |
40644 | list = &unix_socket_table[addr->hash]; | |
40645 | } else { | |
40646 | list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)]; | |
de855c5d AM |
40647 | diff -urNp linux-2.6.29.6/scripts/mod/modpost.c linux-2.6.29.6/scripts/mod/modpost.c |
40648 | --- linux-2.6.29.6/scripts/mod/modpost.c 2009-07-02 19:41:20.000000000 -0400 | |
40649 | +++ linux-2.6.29.6/scripts/mod/modpost.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40650 | @@ -830,6 +830,7 @@ enum mismatch { |
40651 | INIT_TO_EXIT, | |
40652 | EXIT_TO_INIT, | |
40653 | EXPORT_TO_INIT_EXIT, | |
40654 | + DATA_TO_TEXT | |
40655 | }; | |
40656 | ||
40657 | struct sectioncheck { | |
40658 | @@ -891,6 +892,12 @@ const struct sectioncheck sectioncheck[] | |
40659 | .fromsec = { "__ksymtab*", NULL }, | |
40660 | .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, | |
40661 | .mismatch = EXPORT_TO_INIT_EXIT | |
40662 | +}, | |
40663 | +/* Do not reference code from writable data */ | |
40664 | +{ | |
40665 | + .fromsec = { DATA_SECTIONS, NULL }, | |
40666 | + .tosec = { TEXT_SECTIONS, NULL }, | |
40667 | + .mismatch = DATA_TO_TEXT | |
40668 | } | |
40669 | }; | |
40670 | ||
40671 | @@ -1249,6 +1256,14 @@ static void report_sec_mismatch(const ch | |
40672 | "Fix this by removing the %sannotation of %s " | |
40673 | "or drop the export.\n", | |
40674 | tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); | |
40675 | + case DATA_TO_TEXT: | |
40676 | +/* | |
40677 | + fprintf(stderr, | |
40678 | + "The variable %s references\n" | |
40679 | + "the %s %s%s%s\n" | |
40680 | + fromsym, to, sec2annotation(tosec), tosym, to_p); | |
40681 | +*/ | |
40682 | + break; | |
40683 | case NO_MISMATCH: | |
40684 | /* To get warnings on missing members */ | |
40685 | break; | |
de855c5d AM |
40686 | diff -urNp linux-2.6.29.6/scripts/pnmtologo.c linux-2.6.29.6/scripts/pnmtologo.c |
40687 | --- linux-2.6.29.6/scripts/pnmtologo.c 2009-07-02 19:41:20.000000000 -0400 | |
40688 | +++ linux-2.6.29.6/scripts/pnmtologo.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
40689 | @@ -237,14 +237,14 @@ static void write_header(void) |
40690 | fprintf(out, " * Linux logo %s\n", logoname); | |
40691 | fputs(" */\n\n", out); | |
40692 | fputs("#include <linux/linux_logo.h>\n\n", out); | |
40693 | - fprintf(out, "static unsigned char %s_data[] __initdata = {\n", | |
40694 | + fprintf(out, "static unsigned char %s_data[] = {\n", | |
40695 | logoname); | |
40696 | } | |
40697 | ||
40698 | static void write_footer(void) | |
40699 | { | |
40700 | fputs("\n};\n\n", out); | |
40701 | - fprintf(out, "struct linux_logo %s __initdata = {\n", logoname); | |
40702 | + fprintf(out, "struct linux_logo %s = {\n", logoname); | |
40703 | fprintf(out, " .type\t= %s,\n", logo_types[logo_type]); | |
40704 | fprintf(out, " .width\t= %d,\n", logo_width); | |
40705 | fprintf(out, " .height\t= %d,\n", logo_height); | |
40706 | @@ -374,7 +374,7 @@ static void write_logo_clut224(void) | |
40707 | fputs("\n};\n\n", out); | |
40708 | ||
40709 | /* write logo clut */ | |
40710 | - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n", | |
40711 | + fprintf(out, "static unsigned char %s_clut[] = {\n", | |
40712 | logoname); | |
40713 | write_hex_cnt = 0; | |
40714 | for (i = 0; i < logo_clutsize; i++) { | |
de855c5d AM |
40715 | diff -urNp linux-2.6.29.6/security/commoncap.c linux-2.6.29.6/security/commoncap.c |
40716 | --- linux-2.6.29.6/security/commoncap.c 2009-07-02 19:41:20.000000000 -0400 | |
40717 | +++ linux-2.6.29.6/security/commoncap.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 | 40718 | @@ -28,9 +28,11 @@ |
3f74aa08 | 40719 | #include <linux/prctl.h> |
2380c486 | 40720 | #include <linux/securebits.h> |
2380c486 JR |
40721 | |
40722 | +extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk); | |
40723 | + | |
40724 | int cap_netlink_send(struct sock *sk, struct sk_buff *skb) | |
40725 | { | |
de855c5d | 40726 | - NETLINK_CB(skb).eff_cap = current_cap(); |
3f74aa08 | 40727 | + NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk); |
2380c486 JR |
40728 | return 0; |
40729 | } | |
40730 | ||
de855c5d AM |
40731 | diff -urNp linux-2.6.29.6/security/Kconfig linux-2.6.29.6/security/Kconfig |
40732 | --- linux-2.6.29.6/security/Kconfig 2009-07-02 19:41:20.000000000 -0400 | |
40733 | +++ linux-2.6.29.6/security/Kconfig 2009-07-10 07:23:12.000000000 -0400 | |
40734 | @@ -4,6 +4,481 @@ | |
2380c486 JR |
40735 | |
40736 | menu "Security options" | |
40737 | ||
40738 | +source grsecurity/Kconfig | |
40739 | + | |
40740 | +menu "PaX" | |
40741 | + | |
40742 | +config PAX | |
40743 | + bool "Enable various PaX features" | |
40744 | + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86) | |
40745 | + help | |
40746 | + This allows you to enable various PaX features. PaX adds | |
40747 | + intrusion prevention mechanisms to the kernel that reduce | |
40748 | + the risks posed by exploitable memory corruption bugs. | |
40749 | + | |
40750 | +menu "PaX Control" | |
40751 | + depends on PAX | |
40752 | + | |
40753 | +config PAX_SOFTMODE | |
40754 | + bool 'Support soft mode' | |
40755 | + help | |
40756 | + Enabling this option will allow you to run PaX in soft mode, that | |
40757 | + is, PaX features will not be enforced by default, only on executables | |
40758 | + marked explicitly. You must also enable PT_PAX_FLAGS support as it | |
40759 | + is the only way to mark executables for soft mode use. | |
40760 | + | |
40761 | + Soft mode can be activated by using the "pax_softmode=1" kernel command | |
40762 | + line option on boot. Furthermore you can control various PaX features | |
40763 | + at runtime via the entries in /proc/sys/kernel/pax. | |
40764 | + | |
40765 | +config PAX_EI_PAX | |
40766 | + bool 'Use legacy ELF header marking' | |
40767 | + help | |
40768 | + Enabling this option will allow you to control PaX features on | |
40769 | + a per executable basis via the 'chpax' utility available at | |
40770 | + http://pax.grsecurity.net/. The control flags will be read from | |
40771 | + an otherwise reserved part of the ELF header. This marking has | |
40772 | + numerous drawbacks (no support for soft-mode, toolchain does not | |
40773 | + know about the non-standard use of the ELF header) therefore it | |
40774 | + has been deprecated in favour of PT_PAX_FLAGS support. | |
40775 | + | |
40776 | + If you have applications not marked by the PT_PAX_FLAGS ELF | |
40777 | + program header then you MUST enable this option otherwise they | |
40778 | + will not get any protection. | |
40779 | + | |
40780 | + Note that if you enable PT_PAX_FLAGS marking support as well, | |
40781 | + the PT_PAX_FLAG marks will override the legacy EI_PAX marks. | |
40782 | + | |
40783 | +config PAX_PT_PAX_FLAGS | |
40784 | + bool 'Use ELF program header marking' | |
40785 | + help | |
40786 | + Enabling this option will allow you to control PaX features on | |
40787 | + a per executable basis via the 'paxctl' utility available at | |
40788 | + http://pax.grsecurity.net/. The control flags will be read from | |
40789 | + a PaX specific ELF program header (PT_PAX_FLAGS). This marking | |
40790 | + has the benefits of supporting both soft mode and being fully | |
40791 | + integrated into the toolchain (the binutils patch is available | |
40792 | + from http://pax.grsecurity.net). | |
40793 | + | |
40794 | + If you have applications not marked by the PT_PAX_FLAGS ELF | |
40795 | + program header then you MUST enable the EI_PAX marking support | |
40796 | + otherwise they will not get any protection. | |
40797 | + | |
40798 | + Note that if you enable the legacy EI_PAX marking support as well, | |
40799 | + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks. | |
40800 | + | |
40801 | +choice | |
40802 | + prompt 'MAC system integration' | |
40803 | + default PAX_HAVE_ACL_FLAGS | |
40804 | + help | |
40805 | + Mandatory Access Control systems have the option of controlling | |
40806 | + PaX flags on a per executable basis, choose the method supported | |
40807 | + by your particular system. | |
40808 | + | |
40809 | + - "none": if your MAC system does not interact with PaX, | |
40810 | + - "direct": if your MAC system defines pax_set_initial_flags() itself, | |
40811 | + - "hook": if your MAC system uses the pax_set_initial_flags_func callback. | |
40812 | + | |
40813 | + NOTE: this option is for developers/integrators only. | |
40814 | + | |
40815 | + config PAX_NO_ACL_FLAGS | |
40816 | + bool 'none' | |
40817 | + | |
40818 | + config PAX_HAVE_ACL_FLAGS | |
40819 | + bool 'direct' | |
40820 | + | |
40821 | + config PAX_HOOK_ACL_FLAGS | |
40822 | + bool 'hook' | |
40823 | +endchoice | |
40824 | + | |
40825 | +endmenu | |
40826 | + | |
40827 | +menu "Non-executable pages" | |
40828 | + depends on PAX | |
40829 | + | |
40830 | +config PAX_NOEXEC | |
40831 | + bool "Enforce non-executable pages" | |
40832 | + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86) | |
40833 | + help | |
40834 | + By design some architectures do not allow for protecting memory | |
40835 | + pages against execution or even if they do, Linux does not make | |
40836 | + use of this feature. In practice this means that if a page is | |
40837 | + readable (such as the stack or heap) it is also executable. | |
40838 | + | |
40839 | + There is a well known exploit technique that makes use of this | |
40840 | + fact and a common programming mistake where an attacker can | |
40841 | + introduce code of his choice somewhere in the attacked program's | |
40842 | + memory (typically the stack or the heap) and then execute it. | |
40843 | + | |
40844 | + If the attacked program was running with different (typically | |
40845 | + higher) privileges than that of the attacker, then he can elevate | |
40846 | + his own privilege level (e.g. get a root shell, write to files for | |
40847 | + which he does not have write access to, etc). | |
40848 | + | |
40849 | + Enabling this option will let you choose from various features | |
40850 | + that prevent the injection and execution of 'foreign' code in | |
40851 | + a program. | |
40852 | + | |
40853 | + This will also break programs that rely on the old behaviour and | |
40854 | + expect that dynamically allocated memory via the malloc() family | |
40855 | + of functions is executable (which it is not). Notable examples | |
40856 | + are the XFree86 4.x server, the java runtime and wine. | |
40857 | + | |
40858 | +config PAX_PAGEEXEC | |
40859 | + bool "Paging based non-executable pages" | |
40860 | + depends on !COMPAT_VDSO && PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7) | |
40861 | + help | |
40862 | + This implementation is based on the paging feature of the CPU. | |
40863 | + On i386 without hardware non-executable bit support there is a | |
40864 | + variable but usually low performance impact, however on Intel's | |
40865 | + P4 core based CPUs it is very high so you should not enable this | |
40866 | + for kernels meant to be used on such CPUs. | |
40867 | + | |
40868 | + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386 | |
40869 | + with hardware non-executable bit support there is no performance | |
40870 | + impact, on ppc the impact is negligible. | |
40871 | + | |
40872 | + Note that several architectures require various emulations due to | |
40873 | + badly designed userland ABIs, this will cause a performance impact | |
40874 | + but will disappear as soon as userland is fixed (e.g., ppc users | |
40875 | + can make use of the secure-plt feature found in binutils). | |
40876 | + | |
40877 | +config PAX_SEGMEXEC | |
40878 | + bool "Segmentation based non-executable pages" | |
40879 | + depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32 | |
40880 | + help | |
40881 | + This implementation is based on the segmentation feature of the | |
40882 | + CPU and has a very small performance impact, however applications | |
40883 | + will be limited to a 1.5 GB address space instead of the normal | |
40884 | + 3 GB. | |
40885 | + | |
40886 | +config PAX_EMUTRAMP | |
40887 | + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86) | |
40888 | + default y if PARISC || PPC32 | |
40889 | + help | |
40890 | + There are some programs and libraries that for one reason or | |
40891 | + another attempt to execute special small code snippets from | |
40892 | + non-executable memory pages. Most notable examples are the | |
40893 | + signal handler return code generated by the kernel itself and | |
40894 | + the GCC trampolines. | |
40895 | + | |
40896 | + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then | |
40897 | + such programs will no longer work under your kernel. | |
40898 | + | |
40899 | + As a remedy you can say Y here and use the 'chpax' or 'paxctl' | |
40900 | + utilities to enable trampoline emulation for the affected programs | |
40901 | + yet still have the protection provided by the non-executable pages. | |
40902 | + | |
40903 | + On parisc and ppc you MUST enable this option and EMUSIGRT as | |
40904 | + well, otherwise your system will not even boot. | |
40905 | + | |
40906 | + Alternatively you can say N here and use the 'chpax' or 'paxctl' | |
40907 | + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC | |
40908 | + for the affected files. | |
40909 | + | |
40910 | + NOTE: enabling this feature *may* open up a loophole in the | |
40911 | + protection provided by non-executable pages that an attacker | |
40912 | + could abuse. Therefore the best solution is to not have any | |
40913 | + files on your system that would require this option. This can | |
40914 | + be achieved by not using libc5 (which relies on the kernel | |
40915 | + signal handler return code) and not using or rewriting programs | |
40916 | + that make use of the nested function implementation of GCC. | |
40917 | + Skilled users can just fix GCC itself so that it implements | |
40918 | + nested function calls in a way that does not interfere with PaX. | |
40919 | + | |
40920 | +config PAX_EMUSIGRT | |
40921 | + bool "Automatically emulate sigreturn trampolines" | |
40922 | + depends on PAX_EMUTRAMP && (PARISC || PPC32) | |
40923 | + default y | |
40924 | + help | |
40925 | + Enabling this option will have the kernel automatically detect | |
40926 | + and emulate signal return trampolines executing on the stack | |
40927 | + that would otherwise lead to task termination. | |
40928 | + | |
40929 | + This solution is intended as a temporary one for users with | |
40930 | + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17, | |
40931 | + Modula-3 runtime, etc) or executables linked to such, basically | |
40932 | + everything that does not specify its own SA_RESTORER function in | |
40933 | + normal executable memory like glibc 2.1+ does. | |
40934 | + | |
40935 | + On parisc and ppc you MUST enable this option, otherwise your | |
40936 | + system will not even boot. | |
40937 | + | |
40938 | + NOTE: this feature cannot be disabled on a per executable basis | |
40939 | + and since it *does* open up a loophole in the protection provided | |
40940 | + by non-executable pages, the best solution is to not have any | |
40941 | + files on your system that would require this option. | |
40942 | + | |
40943 | +config PAX_MPROTECT | |
40944 | + bool "Restrict mprotect()" | |
40945 | + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64 | |
40946 | + help | |
40947 | + Enabling this option will prevent programs from | |
40948 | + - changing the executable status of memory pages that were | |
40949 | + not originally created as executable, | |
40950 | + - making read-only executable pages writable again, | |
40951 | + - creating executable pages from anonymous memory. | |
40952 | + | |
40953 | + You should say Y here to complete the protection provided by | |
40954 | + the enforcement of non-executable pages. | |
40955 | + | |
40956 | + NOTE: you can use the 'chpax' or 'paxctl' utilities to control | |
40957 | + this feature on a per file basis. | |
40958 | + | |
40959 | +config PAX_NOELFRELOCS | |
40960 | + bool "Disallow ELF text relocations" | |
40961 | + depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86) | |
40962 | + help | |
40963 | + Non-executable pages and mprotect() restrictions are effective | |
40964 | + in preventing the introduction of new executable code into an | |
40965 | + attacked task's address space. There remain only two venues | |
40966 | + for this kind of attack: if the attacker can execute already | |
40967 | + existing code in the attacked task then he can either have it | |
40968 | + create and mmap() a file containing his code or have it mmap() | |
40969 | + an already existing ELF library that does not have position | |
40970 | + independent code in it and use mprotect() on it to make it | |
40971 | + writable and copy his code there. While protecting against | |
40972 | + the former approach is beyond PaX, the latter can be prevented | |
40973 | + by having only PIC ELF libraries on one's system (which do not | |
40974 | + need to relocate their code). If you are sure this is your case, | |
40975 | + then enable this option otherwise be careful as you may not even | |
40976 | + be able to boot or log on your system (for example, some PAM | |
40977 | + modules are erroneously compiled as non-PIC by default). | |
40978 | + | |
40979 | + NOTE: if you are using dynamic ELF executables (as suggested | |
40980 | + when using ASLR) then you must have made sure that you linked | |
40981 | + your files using the PIC version of crt1 (the et_dyn.tar.gz package | |
40982 | + referenced there has already been updated to support this). | |
40983 | + | |
40984 | +config PAX_ETEXECRELOCS | |
40985 | + bool "Allow ELF ET_EXEC text relocations" | |
40986 | + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC) | |
40987 | + default y | |
40988 | + help | |
40989 | + On some architectures there are incorrectly created applications | |
40990 | + that require text relocations and would not work without enabling | |
40991 | + this option. If you are an alpha, ia64 or parisc user, you should | |
40992 | + enable this option and disable it once you have made sure that | |
40993 | + none of your applications need it. | |
40994 | + | |
40995 | +config PAX_EMUPLT | |
40996 | + bool "Automatically emulate ELF PLT" | |
40997 | + depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64) | |
40998 | + default y | |
40999 | + help | |
41000 | + Enabling this option will have the kernel automatically detect | |
41001 | + and emulate the Procedure Linkage Table entries in ELF files. | |
41002 | + On some architectures such entries are in writable memory, and | |
41003 | + become non-executable leading to task termination. Therefore | |
41004 | + it is mandatory that you enable this option on alpha, parisc, | |
41005 | + ppc (if secure-plt is not used throughout in userland), sparc | |
41006 | + and sparc64, otherwise your system would not even boot. | |
41007 | + | |
41008 | + NOTE: this feature *does* open up a loophole in the protection | |
41009 | + provided by the non-executable pages, therefore the proper | |
41010 | + solution is to modify the toolchain to produce a PLT that does | |
41011 | + not need to be writable. | |
41012 | + | |
41013 | +config PAX_DLRESOLVE | |
41014 | + bool | |
41015 | + depends on PAX_EMUPLT && (SPARC32 || SPARC64) | |
41016 | + default y | |
41017 | + | |
41018 | +config PAX_SYSCALL | |
41019 | + bool | |
41020 | + depends on PAX_PAGEEXEC && PPC32 | |
41021 | + default y | |
41022 | + | |
41023 | +config PAX_KERNEXEC | |
41024 | + bool "Enforce non-executable kernel pages" | |
41025 | + depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT | |
41026 | + help | |
41027 | + This is the kernel land equivalent of PAGEEXEC and MPROTECT, | |
41028 | + that is, enabling this option will make it harder to inject | |
41029 | + and execute 'foreign' code in kernel memory itself. | |
41030 | + | |
41031 | +endmenu | |
41032 | + | |
41033 | +menu "Address Space Layout Randomization" | |
41034 | + depends on PAX | |
41035 | + | |
41036 | +config PAX_ASLR | |
41037 | + bool "Address Space Layout Randomization" | |
41038 | + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS | |
41039 | + help | |
41040 | + Many if not most exploit techniques rely on the knowledge of | |
41041 | + certain addresses in the attacked program. The following options | |
41042 | + will allow the kernel to apply a certain amount of randomization | |
41043 | + to specific parts of the program thereby forcing an attacker to | |
41044 | + guess them in most cases. Any failed guess will most likely crash | |
41045 | + the attacked program which allows the kernel to detect such attempts | |
41046 | + and react on them. PaX itself provides no reaction mechanisms, | |
41047 | + instead it is strongly encouraged that you make use of Nergal's | |
41048 | + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's | |
41049 | + (http://www.grsecurity.net/) built-in crash detection features or | |
41050 | + develop one yourself. | |
41051 | + | |
41052 | + By saying Y here you can choose to randomize the following areas: | |
41053 | + - top of the task's kernel stack | |
41054 | + - top of the task's userland stack | |
41055 | + - base address for mmap() requests that do not specify one | |
41056 | + (this includes all libraries) | |
41057 | + - base address of the main executable | |
41058 | + | |
41059 | + It is strongly recommended to say Y here as address space layout | |
41060 | + randomization has negligible impact on performance yet it provides | |
41061 | + a very effective protection. | |
41062 | + | |
41063 | + NOTE: you can use the 'chpax' or 'paxctl' utilities to control | |
41064 | + this feature on a per file basis. | |
41065 | + | |
41066 | +config PAX_RANDKSTACK | |
41067 | + bool "Randomize kernel stack base" | |
41068 | + depends on PAX_ASLR && X86_TSC && X86_32 | |
41069 | + help | |
41070 | + By saying Y here the kernel will randomize every task's kernel | |
41071 | + stack on every system call. This will not only force an attacker | |
41072 | + to guess it but also prevent him from making use of possible | |
41073 | + leaked information about it. | |
41074 | + | |
41075 | + Since the kernel stack is a rather scarce resource, randomization | |
41076 | + may cause unexpected stack overflows, therefore you should very | |
41077 | + carefully test your system. Note that once enabled in the kernel | |
41078 | + configuration, this feature cannot be disabled on a per file basis. | |
41079 | + | |
41080 | +config PAX_RANDUSTACK | |
41081 | + bool "Randomize user stack base" | |
41082 | + depends on PAX_ASLR | |
41083 | + help | |
41084 | + By saying Y here the kernel will randomize every task's userland | |
41085 | + stack. The randomization is done in two steps where the second | |
41086 | + one may apply a big amount of shift to the top of the stack and | |
41087 | + cause problems for programs that want to use lots of memory (more | |
41088 | + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is). | |
41089 | + For this reason the second step can be controlled by 'chpax' or | |
41090 | + 'paxctl' on a per file basis. | |
41091 | + | |
41092 | +config PAX_RANDMMAP | |
41093 | + bool "Randomize mmap() base" | |
41094 | + depends on PAX_ASLR | |
41095 | + help | |
41096 | + By saying Y here the kernel will use a randomized base address for | |
41097 | + mmap() requests that do not specify one themselves. As a result | |
41098 | + all dynamically loaded libraries will appear at random addresses | |
41099 | + and therefore be harder to exploit by a technique where an attacker | |
41100 | + attempts to execute library code for his purposes (e.g. spawn a | |
41101 | + shell from an exploited program that is running at an elevated | |
41102 | + privilege level). | |
41103 | + | |
41104 | + Furthermore, if a program is relinked as a dynamic ELF file, its | |
41105 | + base address will be randomized as well, completing the full | |
41106 | + randomization of the address space layout. Attacking such programs | |
41107 | + becomes a guess game. You can find an example of doing this at | |
41108 | + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at | |
41109 | + http://www.grsecurity.net/grsec-gcc-specs.tar.gz . | |
41110 | + | |
41111 | + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this | |
41112 | + feature on a per file basis. | |
41113 | + | |
41114 | +endmenu | |
41115 | + | |
41116 | +menu "Miscellaneous hardening features" | |
41117 | + | |
41118 | +config PAX_MEMORY_SANITIZE | |
41119 | + bool "Sanitize all freed memory" | |
41120 | + help | |
41121 | + By saying Y here the kernel will erase memory pages as soon as they | |
41122 | + are freed. This in turn reduces the lifetime of data stored in the | |
41123 | + pages, making it less likely that sensitive information such as | |
41124 | + passwords, cryptographic secrets, etc stay in memory for too long. | |
41125 | + | |
41126 | + This is especially useful for programs whose runtime is short, long | |
41127 | + lived processes and the kernel itself benefit from this as long as | |
41128 | + they operate on whole memory pages and ensure timely freeing of pages | |
41129 | + that may hold sensitive information. | |
41130 | + | |
41131 | + The tradeoff is performance impact, on a single CPU system kernel | |
41132 | + compilation sees a 3% slowdown, other systems and workloads may vary | |
41133 | + and you are advised to test this feature on your expected workload | |
41134 | + before deploying it. | |
41135 | + | |
41136 | + Note that this feature does not protect data stored in live pages, | |
41137 | + e.g., process memory swapped to disk may stay there for a long time. | |
41138 | + | |
41139 | +config PAX_MEMORY_UDEREF | |
41140 | + bool "Prevent invalid userland pointer dereference" | |
41141 | + depends on X86_32 && !COMPAT_VDSO && !UML_X86 | |
41142 | + help | |
41143 | + By saying Y here the kernel will be prevented from dereferencing | |
41144 | + userland pointers in contexts where the kernel expects only kernel | |
41145 | + pointers. This is both a useful runtime debugging feature and a | |
41146 | + security measure that prevents exploiting a class of kernel bugs. | |
41147 | + | |
41148 | + The tradeoff is that some virtualization solutions may experience | |
41149 | + a huge slowdown and therefore you should not enable this feature | |
41150 | + for kernels meant to run in such environments. Whether a given VM | |
41151 | + solution is affected or not is best determined by simply trying it | |
41152 | + out, the performance impact will be obvious right on boot as this | |
41153 | + mechanism engages from very early on. A good rule of thumb is that | |
41154 | + VMs running on CPUs without hardware virtualization support (i.e., | |
41155 | + the majority of IA-32 CPUs) will likely experience the slowdown. | |
41156 | + | |
41157 | +config PAX_REFCOUNT | |
41158 | + bool "Prevent various kernel object reference counter overflows" | |
de855c5d | 41159 | + depends on GRKERNSEC && X86 |
2380c486 JR |
41160 | + help |
41161 | + By saying Y here the kernel will detect and prevent overflowing | |
41162 | + various (but not all) kinds of object reference counters. Such | |
41163 | + overflows can normally occur due to bugs only and are often, if | |
41164 | + not always, exploitable. | |
41165 | + | |
41166 | + The tradeoff is that data structures protected by an overflowed | |
41167 | + refcount will never be freed and therefore will leak memory. Note | |
41168 | + that this leak also happens even without this protection but in | |
41169 | + that case the overflow can eventually trigger the freeing of the | |
41170 | + data structure while it is still being used elsewhere, resulting | |
41171 | + in the exploitable situation that this feature prevents. | |
41172 | + | |
41173 | + Since this has a negligible performance impact, you should enable | |
41174 | + this feature. | |
de855c5d AM |
41175 | + |
41176 | +config PAX_USERCOPY | |
41177 | + bool "Bounds check heap object copies between kernel and userland" | |
41178 | + depends on X86 | |
41179 | + depends on GRKERNSEC && (SLAB || SLUB || SLOB) | |
41180 | + help | |
41181 | + By saying Y here the kernel will enforce the size of heap objects | |
41182 | + when they are copied in either direction between the kernel and | |
41183 | + userland, even if only a part of the heap object is copied. | |
41184 | + | |
41185 | + Specifically, this checking prevents information leaking from the | |
41186 | + kernel heap during kernel to userland copies (if the kernel heap | |
41187 | + object is otherwise fully initialized) and prevents kernel heap | |
41188 | + overflows during userland to kernel copies. | |
41189 | + | |
41190 | + Note that the current implementation provides the strictest checks | |
41191 | + for the SLUB allocator. | |
41192 | + | |
41193 | +config PAX_SECURE_VSYSCALL | |
41194 | + bool "Harden vsyscall against exploitation" | |
41195 | + depends on X86_64 | |
41196 | + default y | |
41197 | + help | |
41198 | + By saying Y here, the kernel will make the vsyscall mapping | |
41199 | + non-executable and redirect users of the fixed-address | |
41200 | + vsyscall mapping to a more secure vDSO. This removes the | |
41201 | + vsyscall mappings as targets of exploitation, particularly in | |
41202 | + abusing them to easily transition from interrupt to process | |
41203 | + context. | |
41204 | + | |
41205 | + You should enable this feature if the kernel being built is | |
41206 | + not being used as a guest within VMWare ESX Server, as we have | |
41207 | + been informed that this feature is incompatible with their | |
41208 | + product. | |
2380c486 JR |
41209 | +endmenu |
41210 | + | |
41211 | +endmenu | |
41212 | + | |
41213 | config KEYS | |
41214 | bool "Enable access key retention support" | |
41215 | help | |
de855c5d AM |
41216 | diff -urNp linux-2.6.29.6/sound/core/oss/pcm_oss.c linux-2.6.29.6/sound/core/oss/pcm_oss.c |
41217 | --- linux-2.6.29.6/sound/core/oss/pcm_oss.c 2009-07-02 19:41:20.000000000 -0400 | |
41218 | +++ linux-2.6.29.6/sound/core/oss/pcm_oss.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41219 | @@ -2929,8 +2929,8 @@ static void snd_pcm_oss_proc_done(struct |
41220 | } | |
41221 | } | |
41222 | #else /* !CONFIG_SND_VERBOSE_PROCFS */ | |
41223 | -#define snd_pcm_oss_proc_init(pcm) | |
41224 | -#define snd_pcm_oss_proc_done(pcm) | |
41225 | +#define snd_pcm_oss_proc_init(pcm) do {} while (0) | |
41226 | +#define snd_pcm_oss_proc_done(pcm) do {} while (0) | |
41227 | #endif /* CONFIG_SND_VERBOSE_PROCFS */ | |
41228 | ||
41229 | /* | |
de855c5d AM |
41230 | diff -urNp linux-2.6.29.6/sound/core/seq/seq_lock.h linux-2.6.29.6/sound/core/seq/seq_lock.h |
41231 | --- linux-2.6.29.6/sound/core/seq/seq_lock.h 2009-07-02 19:41:20.000000000 -0400 | |
41232 | +++ linux-2.6.29.6/sound/core/seq/seq_lock.h 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41233 | @@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo |
41234 | #else /* SMP || CONFIG_SND_DEBUG */ | |
41235 | ||
41236 | typedef spinlock_t snd_use_lock_t; /* dummy */ | |
41237 | -#define snd_use_lock_init(lockp) /**/ | |
41238 | -#define snd_use_lock_use(lockp) /**/ | |
41239 | -#define snd_use_lock_free(lockp) /**/ | |
41240 | -#define snd_use_lock_sync(lockp) /**/ | |
41241 | +#define snd_use_lock_init(lockp) do {} while (0) | |
41242 | +#define snd_use_lock_use(lockp) do {} while (0) | |
41243 | +#define snd_use_lock_free(lockp) do {} while (0) | |
41244 | +#define snd_use_lock_sync(lockp) do {} while (0) | |
41245 | ||
41246 | #endif /* SMP || CONFIG_SND_DEBUG */ | |
41247 | ||
de855c5d AM |
41248 | diff -urNp linux-2.6.29.6/sound/pci/ac97/ac97_patch.c linux-2.6.29.6/sound/pci/ac97/ac97_patch.c |
41249 | --- linux-2.6.29.6/sound/pci/ac97/ac97_patch.c 2009-07-02 19:41:20.000000000 -0400 | |
41250 | +++ linux-2.6.29.6/sound/pci/ac97/ac97_patch.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41251 | @@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a |
41252 | { AC97_VIDEO, 0x9f1f }, | |
41253 | { AC97_AUX, 0x9f1f }, | |
41254 | { AC97_PCM, 0x9f1f }, | |
41255 | - { } /* terminator */ | |
41256 | + { 0, 0 } /* terminator */ | |
41257 | }; | |
41258 | ||
41259 | static int patch_ad1819(struct snd_ac97 * ac97) | |
41260 | @@ -3873,7 +3873,7 @@ static struct snd_ac97_res_table lm4550_ | |
41261 | { AC97_AUX, 0x1f1f }, | |
41262 | { AC97_PCM, 0x1f1f }, | |
41263 | { AC97_REC_GAIN, 0x0f0f }, | |
41264 | - { } /* terminator */ | |
41265 | + { 0, 0 } /* terminator */ | |
41266 | }; | |
41267 | ||
41268 | static int patch_lm4550(struct snd_ac97 *ac97) | |
de855c5d AM |
41269 | diff -urNp linux-2.6.29.6/sound/pci/ens1370.c linux-2.6.29.6/sound/pci/ens1370.c |
41270 | --- linux-2.6.29.6/sound/pci/ens1370.c 2009-07-02 19:41:20.000000000 -0400 | |
41271 | +++ linux-2.6.29.6/sound/pci/ens1370.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41272 | @@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci |
41273 | { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */ | |
41274 | { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */ | |
41275 | #endif | |
41276 | - { 0, } | |
41277 | + { 0, 0, 0, 0, 0, 0, 0 } | |
41278 | }; | |
41279 | ||
41280 | MODULE_DEVICE_TABLE(pci, snd_audiopci_ids); | |
de855c5d AM |
41281 | diff -urNp linux-2.6.29.6/sound/pci/intel8x0.c linux-2.6.29.6/sound/pci/intel8x0.c |
41282 | --- linux-2.6.29.6/sound/pci/intel8x0.c 2009-07-02 19:41:20.000000000 -0400 | |
41283 | +++ linux-2.6.29.6/sound/pci/intel8x0.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41284 | @@ -443,7 +443,7 @@ static struct pci_device_id snd_intel8x0 |
41285 | { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ | |
41286 | { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */ | |
41287 | { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ | |
41288 | - { 0, } | |
41289 | + { 0, 0, 0, 0, 0, 0, 0 } | |
41290 | }; | |
41291 | ||
41292 | MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids); | |
41293 | @@ -2088,7 +2088,7 @@ static struct ac97_quirk ac97_quirks[] _ | |
41294 | .type = AC97_TUNE_HP_ONLY | |
41295 | }, | |
41296 | #endif | |
41297 | - { } /* terminator */ | |
41298 | + { 0, 0, 0, 0, NULL, 0 } /* terminator */ | |
41299 | }; | |
41300 | ||
41301 | static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock, | |
de855c5d AM |
41302 | diff -urNp linux-2.6.29.6/sound/pci/intel8x0m.c linux-2.6.29.6/sound/pci/intel8x0m.c |
41303 | --- linux-2.6.29.6/sound/pci/intel8x0m.c 2009-07-02 19:41:20.000000000 -0400 | |
41304 | +++ linux-2.6.29.6/sound/pci/intel8x0m.c 2009-07-09 22:13:40.000000000 -0400 | |
2380c486 JR |
41305 | @@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0 |
41306 | { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ | |
41307 | { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ | |
41308 | #endif | |
41309 | - { 0, } | |
41310 | + { 0, 0, 0, 0, 0, 0, 0 } | |
41311 | }; | |
41312 | ||
41313 | MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids); | |
41314 | @@ -1258,7 +1258,7 @@ static struct shortname_table { | |
41315 | { 0x5455, "ALi M5455" }, | |
41316 | { 0x746d, "AMD AMD8111" }, | |
41317 | #endif | |
41318 | - { 0 }, | |
41319 | + { 0, NULL }, | |
41320 | }; | |
41321 | ||
41322 | static int __devinit snd_intel8x0m_probe(struct pci_dev *pci, | |
de855c5d AM |
41323 | diff -urNp linux-2.6.29.6/virt/kvm/kvm_main.c linux-2.6.29.6/virt/kvm/kvm_main.c |
41324 | --- linux-2.6.29.6/virt/kvm/kvm_main.c 2009-07-02 19:41:20.000000000 -0400 | |
41325 | +++ linux-2.6.29.6/virt/kvm/kvm_main.c 2009-07-09 22:13:40.000000000 -0400 | |
41326 | @@ -2059,6 +2059,9 @@ static struct miscdevice kvm_dev = { | |
2380c486 JR |
41327 | KVM_MINOR, |
41328 | "kvm", | |
41329 | &kvm_chardev_ops, | |
41330 | + {NULL, NULL}, | |
41331 | + NULL, | |
41332 | + NULL | |
41333 | }; | |
41334 | ||
41335 | static void hardware_enable(void *junk) | |
de855c5d | 41336 | @@ -2290,7 +2293,7 @@ static void kvm_sched_out(struct preempt |
2380c486 JR |
41337 | kvm_arch_vcpu_put(vcpu); |
41338 | } | |
41339 | ||
41340 | -int kvm_init(void *opaque, unsigned int vcpu_size, | |
41341 | +int kvm_init(const void *opaque, unsigned int vcpu_size, | |
41342 | struct module *module) | |
41343 | { | |
41344 | int r; |